/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* IBM Corp.
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsLocalFile.h"
#include "nsDebug.h"
#include "nsStaticAtom.h"
#if defined(XP_MAC)
#include <Folders.h>
#include <Files.h>
#include <Memory.h>
#include <Processes.h>
#include <Gestalt.h>
#include <windows.h>
#include <shlobj.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "prenv.h"
#ifdef XP_MACOSX
#include <CoreServices/CoreServices.h>
#include <Folders.h>
#include <Files.h>
#include <Memory.h>
#include <Processes.h>
#include <Gestalt.h>
#include <CFURL.h>
#include <InternetConfig.h>
#endif
#include <FindDirectory.h>
#include <Path.h>
#include <unistd.h>
#include <stdlib.h>
#include <OS.h>
#include <image.h>
#include "prenv.h"
#endif
#include "SpecialSystemDirectory.h"
#include "nsAppFileLocationProvider.h"
#if defined(XP_MAC)
#else
#endif
// define home directory
// For Windows platform, We are choosing Appdata folder as HOME
#if defined (XP_WIN)
#endif
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// Set the component registry location:
if (!mService)
return NS_ERROR_FAILURE;
if (dirService)
{
dirService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(aLocalFile));
if (aLocalFile)
{
*aFile = aLocalFile;
return NS_OK;
}
}
return NS_ERROR_OUT_OF_MEMORY;
#ifdef XP_WIN
// chop of the executable name by finding the rightmost backslash
if (lastSlash)
return NS_OK;
}
// get info for the the current process to determine the directory
// its located in
// initialize ProcessInfoRec before calling
// GetProcessInformation() or die horribly.
if (!err)
{
// create an FSSpec from the volume and dirid of the app.
if (localFileMac)
{
return NS_OK;
}
}
# ifdef MOZ_DEFAULT_VBOX_XPCOM_HOME
if (NS_SUCCEEDED(rv))
# else
// Works even if we're not bundled.
{
{
if (parentURL)
{
// Pass PR_TRUE for the "resolveAgainstBase" arg to CFURLGetFileSystemRepresentation.
// This will resolve the relative portion of the CFURL against it base, giving a full
// path, which CFURLCopyFileSystemPath doesn't do.
{
#ifdef DEBUG_conrad
#endif
if (NS_SUCCEEDED(rv))
}
}
}
}
#endif
if (*aFile)
return NS_OK;
// In the absence of a good way to get the executable directory let
// us try this for unix:
// - if VBOX_XPCOM_HOME is defined, that is it
// - else give the current directory
char buf[MAXPATHLEN];
#if 0 /* we need .so location. */
// Actually we have a way on linux.
static volatile bool fPathSet = false;
static char szPath[MAXPATHLEN];
if (!fPathSet)
{
buf2[0] = '\0';
/*
* Env.var. VBOX_XPCOM_HOME first.
*/
if (psz)
{
{
}
}
/*
* The dynamic loader.
*/
if (!buf2[0])
{
{
buf2[0] = '\0';
}
}
/*
* Executable location.
*/
if (!buf2[0])
{
char buf[MAXPATHLEN];
{
buf2[0] = '\0';
}
}
/*
* Copy to static buffer on success.
*/
if (buf2[0])
{
if (p)
{
p[p == buf2] = '\0';
#ifdef DEBUG
#endif
fPathSet = true;
}
}
}
if (fPathSet)
{
return NS_OK;
}
#endif
// The MOZ_DEFAULT_VBOX_XPCOM_HOME variable can be set at configure time with
// a --with-default-mozilla-five-home=foo autoconf flag.
//
// The idea here is to allow for builds that have a default VBOX_XPCOM_HOME
// regardless of the environment. This makes it easier to write apps that
// embed mozilla without having to worry about setting up the environment
//
// We do this py putenv()ing the default value into the environment. Note that
// we only do this if it is not already set.
#ifdef MOZ_DEFAULT_VBOX_XPCOM_HOME
{
}
#endif
if (moz5)
{
return NS_OK;
}
}
#if defined(DEBUG)
if(!moz5 && firstWarning) {
// Warn that VBOX_XPCOM_HOME not set, once.
printf("Warning: VBOX_XPCOM_HOME not set.\n");
}
#endif /* DEBUG */
// Fall back to current directory.
{
return NS_OK;
}
char buffer[CCHMAXPATH];
return NS_OK;
if (moz5)
{
return NS_OK;
}
else
{
static char buf[MAXPATHLEN];
char *p;
*buf = 0;
{
{
*p = 0;
return NS_OK;
}
}
}
#endif
NS_ERROR("unable to get current process directory");
return NS_ERROR_FAILURE;
} // GetCurrentProcessDirectory()
#if defined (XP_MACOSX)
#endif
{
}
{
if (!mService)
{
mService = new nsDirectoryService();
if (!mService)
return NS_ERROR_OUT_OF_MEMORY;
}
}
#if defined (XP_MACOSX)
#endif
};
{
// Let the list hold the only reference to the provider.
if (!defaultProvider)
return NS_ERROR_OUT_OF_MEMORY;
// AppendElement returns PR_TRUE for success.
return rv;
}
{
return PR_TRUE;
}
{
// clear the global
}
NS_IMPL_THREADSAFE_ISUPPORTS4(nsDirectoryService, nsIProperties, nsIDirectoryService, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2)
{
return NS_ERROR_FAILURE;
return NS_OK;
}
{
return NS_ERROR_NOT_IMPLEMENTED;
}
struct FileData
{
const char* property;
};
{
{
// Not all providers implement this iface
if (prov2)
{
return PR_FALSE;
}
}
}
else
{
if (!prov)
return PR_FALSE;
return PR_FALSE;
}
return PR_TRUE;
}
{
if (value)
{
}
// it is not one of our defaults, lets check any providers
{
if (fileData.persistent)
{
}
return rv;
}
{
if (fileData.persistent)
{
}
return rv;
}
return NS_ERROR_FAILURE;
}
{
return NS_ERROR_FAILURE;
if (ourFile)
{
return NS_OK;
}
return NS_ERROR_FAILURE;
}
{
return rv;
if (value)
{
}
return rv;
}
{
if (!prov)
return NS_ERROR_FAILURE;
if (!mProviders)
return NS_ERROR_NOT_INITIALIZED;
// AppendElement returns PR_TRUE for success.
}
{
if (!prov)
return NS_ERROR_FAILURE;
if (!mProviders)
return NS_ERROR_NOT_INITIALIZED;
// RemoveElement returns PR_TRUE for success.
}
// DO NOT ADD ANY LOCATIONS TO THIS FUNCTION UNTIL YOU TALK TO: dougt@netscape.com.
// This is meant to be a place of xpcom or system specific file locations, not
// application specific locations. If you need the later, register a callback for
// your application.
{
*persistent = PR_TRUE;
// check to see if it is one of our defaults
{
}
{
if (!localFile)
return NS_ERROR_FAILURE;
}
{
if (!localFile)
return NS_ERROR_FAILURE;
}
// Unless otherwise set, the core pieces of the GRE exist
// in the current process directory.
{
}
// the GRE components directory is relative to the GRE directory
// by default; applications may override this behavior in special
// cases
{
if (localFile)
}
{
if (localFile)
}
{
}
{
}
{
}
{
}
#if defined(XP_MACOSX)
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
if (localMacFile)
{
{
{
}
::ICStop(icInstance);
}
{
// We got an error getting the DL folder from IC so try finding the user's Desktop folder
}
}
// Don't cache the DL directory as the user may change it while we're running.
// Negligible perf hit as this directory is only requested for downloads
*persistent = PR_FALSE;
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
#endif
#ifdef DEBUG_dougt
#endif
return rv;
}
{
return NS_ERROR_FAILURE;
}