2000-07-16 18:20:33 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-04-18 18:21:17 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-07-16 18:20:33 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* 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
|
|
|
|
* http://www.mozilla.org/MPL/
|
2000-07-16 18:20:33 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* 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.
|
2000-07-16 18:20:33 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2000
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-07-16 18:20:33 +04:00
|
|
|
*
|
2001-07-31 23:05:34 +04:00
|
|
|
* Contributor(s):
|
2004-04-18 18:21:17 +04:00
|
|
|
* Conrad Carlen <conrad@ingress.com>
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2000-07-16 18:20:33 +04:00
|
|
|
#include "nsAppFileLocationProvider.h"
|
2000-08-10 08:39:30 +04:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2000-07-16 18:20:33 +04:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsILocalFile.h"
|
2000-07-19 23:58:35 +04:00
|
|
|
#include "nsString.h"
|
2000-07-16 18:20:33 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2001-11-02 18:29:57 +03:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2001-11-26 18:54:38 +03:00
|
|
|
#include "prenv.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2000-07-16 18:20:33 +04:00
|
|
|
|
2006-11-16 12:10:09 +03:00
|
|
|
#if defined(XP_MACOSX)
|
2000-07-16 18:20:33 +04:00
|
|
|
#include <Folders.h>
|
|
|
|
#include <Script.h>
|
2000-07-20 01:47:08 +04:00
|
|
|
#include <Processes.h>
|
2001-06-14 05:24:22 +04:00
|
|
|
#include <Gestalt.h>
|
2000-07-20 01:47:08 +04:00
|
|
|
#include "nsILocalFileMac.h"
|
2001-10-27 11:38:18 +04:00
|
|
|
#elif defined(XP_OS2)
|
2000-07-20 22:55:28 +04:00
|
|
|
#define INCL_DOSPROCESS
|
|
|
|
#define INCL_DOSMODULEMGR
|
|
|
|
#include <os2.h>
|
2003-04-03 02:45:08 +04:00
|
|
|
#elif defined(XP_WIN)
|
2000-07-19 23:58:35 +04:00
|
|
|
#include <windows.h>
|
|
|
|
#include <shlobj.h>
|
2000-07-20 01:20:35 +04:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/param.h>
|
2000-07-26 10:22:37 +04:00
|
|
|
#elif defined(XP_BEOS)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <kernel/image.h>
|
|
|
|
#include <storage/FindDirectory.h>
|
2000-07-16 18:20:33 +04:00
|
|
|
#endif
|
2000-09-21 17:45:31 +04:00
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2000-07-16 18:20:33 +04:00
|
|
|
// WARNING: These hard coded names need to go away. They need to
|
|
|
|
// come from localizable resources
|
|
|
|
|
2006-11-16 12:10:09 +03:00
|
|
|
#if defined(XP_MACOSX)
|
2002-04-27 09:33:09 +04:00
|
|
|
#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("Application Registry")
|
|
|
|
#define ESSENTIAL_FILES NS_LITERAL_CSTRING("Essential Files")
|
2001-01-19 01:51:57 +03:00
|
|
|
#elif defined(XP_WIN) || defined(XP_OS2)
|
2002-04-27 09:33:09 +04:00
|
|
|
#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("registry.dat")
|
2001-01-19 01:51:57 +03:00
|
|
|
#else
|
2002-04-27 09:33:09 +04:00
|
|
|
#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("appreg")
|
2001-07-31 23:05:34 +04:00
|
|
|
#endif
|
2001-01-19 01:51:57 +03:00
|
|
|
|
|
|
|
// define default product directory
|
2003-07-01 22:32:49 +04:00
|
|
|
#define DEFAULT_PRODUCT_DIR NS_LITERAL_CSTRING(MOZ_USER_DIR)
|
2001-01-19 01:51:57 +03:00
|
|
|
|
2001-11-26 18:54:38 +03:00
|
|
|
// Locally defined keys used by nsAppDirectoryEnumerator
|
|
|
|
#define NS_ENV_PLUGINS_DIR "EnvPlugins" // env var MOZ_PLUGIN_PATH
|
2002-03-07 18:24:40 +03:00
|
|
|
#define NS_USER_PLUGINS_DIR "UserPlugins"
|
2001-01-19 01:51:57 +03:00
|
|
|
|
2006-11-16 12:10:09 +03:00
|
|
|
#ifdef XP_MACOSX
|
2002-06-14 16:30:44 +04:00
|
|
|
#define NS_MACOSX_USER_PLUGIN_DIR "OSXUserPlugins"
|
|
|
|
#define NS_MACOSX_LOCAL_PLUGIN_DIR "OSXLocalPlugins"
|
|
|
|
#define NS_MAC_CLASSIC_PLUGIN_DIR "MacSysPlugins"
|
2008-10-10 19:54:33 +04:00
|
|
|
#elif XP_UNIX
|
|
|
|
#define NS_SYSTEM_PLUGINS_DIR "SysPlugins"
|
2002-06-14 16:30:44 +04:00
|
|
|
#endif
|
|
|
|
|
2002-04-27 09:33:09 +04:00
|
|
|
#define DEFAULTS_DIR_NAME NS_LITERAL_CSTRING("defaults")
|
|
|
|
#define DEFAULTS_PREF_DIR_NAME NS_LITERAL_CSTRING("pref")
|
|
|
|
#define DEFAULTS_PROFILE_DIR_NAME NS_LITERAL_CSTRING("profile")
|
|
|
|
#define RES_DIR_NAME NS_LITERAL_CSTRING("res")
|
|
|
|
#define CHROME_DIR_NAME NS_LITERAL_CSTRING("chrome")
|
|
|
|
#define PLUGINS_DIR_NAME NS_LITERAL_CSTRING("plugins")
|
|
|
|
#define SEARCH_DIR_NAME NS_LITERAL_CSTRING("searchplugins")
|
2000-07-16 18:20:33 +04:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsAppFileLocationProvider::Constructor/Destructor
|
2001-07-31 23:05:34 +04:00
|
|
|
//*****************************************************************************
|
2000-07-16 18:20:33 +04:00
|
|
|
|
|
|
|
nsAppFileLocationProvider::nsAppFileLocationProvider()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsAppFileLocationProvider::nsISupports
|
2001-07-31 23:05:34 +04:00
|
|
|
//*****************************************************************************
|
2000-07-16 18:20:33 +04:00
|
|
|
|
2001-11-02 18:29:57 +03:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS2(nsAppFileLocationProvider, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2)
|
2000-07-16 18:20:33 +04:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsAppFileLocationProvider::nsIDirectoryServiceProvider
|
2001-07-31 23:05:34 +04:00
|
|
|
//*****************************************************************************
|
2000-07-16 18:20:33 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-11-26 00:57:13 +03:00
|
|
|
nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistent, nsIFile **_retval)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2000-07-16 18:20:33 +04:00
|
|
|
|
2001-11-02 18:29:57 +03:00
|
|
|
NS_ENSURE_ARG(prop);
|
2001-07-31 23:05:34 +04:00
|
|
|
*_retval = nsnull;
|
2005-11-26 00:57:13 +03:00
|
|
|
*persistent = PR_TRUE;
|
2002-06-14 16:30:44 +04:00
|
|
|
|
2006-11-16 12:10:09 +03:00
|
|
|
#ifdef XP_MACOSX
|
2002-06-14 16:30:44 +04:00
|
|
|
short foundVRefNum;
|
|
|
|
long foundDirID;
|
|
|
|
FSSpec fileSpec;
|
|
|
|
nsCOMPtr<nsILocalFileMac> macFile;
|
|
|
|
#endif
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2001-01-19 01:51:57 +03:00
|
|
|
if (nsCRT::strcmp(prop, NS_APP_APPLICATION_REGISTRY_DIR) == 0)
|
|
|
|
{
|
|
|
|
rv = GetProductDirectory(getter_AddRefs(localFile));
|
|
|
|
}
|
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_APPLICATION_REGISTRY_FILE) == 0)
|
|
|
|
{
|
|
|
|
rv = GetProductDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendNative(APP_REGISTRY_NAME);
|
2001-01-19 01:51:57 +03:00
|
|
|
}
|
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_DEFAULTS_50_DIR) == 0)
|
2000-07-16 18:20:33 +04:00
|
|
|
{
|
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME);
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
2001-01-19 01:51:57 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_PREF_DEFAULTS_50_DIR) == 0)
|
2000-07-16 18:20:33 +04:00
|
|
|
{
|
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME);
|
2000-07-16 18:20:33 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(DEFAULTS_PREF_DIR_NAME);
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
|
|
|
}
|
2001-02-06 18:41:37 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_50_DIR) == 0 ||
|
|
|
|
nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR) == 0)
|
2000-07-16 18:20:33 +04:00
|
|
|
{
|
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME);
|
2000-07-16 18:20:33 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(DEFAULTS_PROFILE_DIR_NAME);
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
|
|
|
}
|
2001-01-19 01:51:57 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_USER_PROFILES_ROOT_DIR) == 0)
|
2000-07-16 18:20:33 +04:00
|
|
|
{
|
2001-07-31 23:05:34 +04:00
|
|
|
rv = GetDefaultUserProfileRoot(getter_AddRefs(localFile));
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
2005-04-27 15:56:40 +04:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_USER_PROFILES_LOCAL_ROOT_DIR) == 0)
|
|
|
|
{
|
|
|
|
rv = GetDefaultUserProfileRoot(getter_AddRefs(localFile), PR_TRUE);
|
|
|
|
}
|
2001-01-19 01:51:57 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_RES_DIR) == 0)
|
2000-07-16 18:20:33 +04:00
|
|
|
{
|
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(RES_DIR_NAME);
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
2001-01-19 01:51:57 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_CHROME_DIR) == 0)
|
2000-07-16 18:20:33 +04:00
|
|
|
{
|
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(CHROME_DIR_NAME);
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
2001-01-19 01:51:57 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR) == 0)
|
2000-07-16 18:20:33 +04:00
|
|
|
{
|
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(PLUGINS_DIR_NAME);
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
2006-11-16 12:10:09 +03:00
|
|
|
#ifdef XP_MACOSX
|
2002-06-14 16:30:44 +04:00
|
|
|
else if (nsCRT::strcmp(prop, NS_MACOSX_USER_PLUGIN_DIR) == 0)
|
|
|
|
{
|
|
|
|
if (!(::FindFolder(kUserDomain,
|
|
|
|
kInternetPlugInFolderType,
|
|
|
|
kDontCreateFolder, &foundVRefNum, &foundDirID)) &&
|
|
|
|
!(::FSMakeFSSpec(foundVRefNum, foundDirID, "\p", &fileSpec))) {
|
|
|
|
rv = NS_NewLocalFileWithFSSpec(&fileSpec, PR_TRUE, getter_AddRefs(macFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
localFile = macFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsCRT::strcmp(prop, NS_MACOSX_LOCAL_PLUGIN_DIR) == 0)
|
|
|
|
{
|
|
|
|
if (!(::FindFolder(kLocalDomain,
|
|
|
|
kInternetPlugInFolderType,
|
|
|
|
kDontCreateFolder, &foundVRefNum, &foundDirID)) &&
|
|
|
|
!(::FSMakeFSSpec(foundVRefNum, foundDirID, "\p", &fileSpec))) {
|
|
|
|
rv = NS_NewLocalFileWithFSSpec(&fileSpec, PR_TRUE, getter_AddRefs(macFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
localFile = macFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsCRT::strcmp(prop, NS_MAC_CLASSIC_PLUGIN_DIR) == 0)
|
|
|
|
{
|
|
|
|
if (!(::FindFolder(kOnAppropriateDisk,
|
|
|
|
kInternetPlugInFolderType,
|
|
|
|
kDontCreateFolder, &foundVRefNum, &foundDirID)) &&
|
|
|
|
!(::FSMakeFSSpec(foundVRefNum, foundDirID, "\p", &fileSpec))) {
|
|
|
|
rv = NS_NewLocalFileWithFSSpec(&fileSpec, PR_TRUE, getter_AddRefs(macFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
localFile = macFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2001-11-26 18:54:38 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_ENV_PLUGINS_DIR) == 0)
|
|
|
|
{
|
2002-10-25 17:08:44 +04:00
|
|
|
NS_ERROR("Don't use nsAppFileLocationProvider::GetFile(NS_ENV_PLUGINS_DIR, ...). "
|
|
|
|
"Use nsAppFileLocationProvider::GetFiles(...).");
|
2001-11-26 18:54:38 +03:00
|
|
|
const char *pathVar = PR_GetEnv("MOZ_PLUGIN_PATH");
|
2006-03-19 05:52:30 +03:00
|
|
|
if (pathVar && *pathVar)
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(pathVar), PR_TRUE, getter_AddRefs(localFile));
|
2001-11-26 18:54:38 +03:00
|
|
|
}
|
2002-03-07 18:24:40 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_USER_PLUGINS_DIR) == 0)
|
|
|
|
{
|
|
|
|
rv = GetProductDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(PLUGINS_DIR_NAME);
|
2002-03-07 18:24:40 +03:00
|
|
|
}
|
2008-10-10 19:54:33 +04:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
else if (nsCRT::strcmp(prop, NS_SYSTEM_PLUGINS_DIR) == 0) {
|
|
|
|
static const char *const sysLPlgDir = "/usr/lib/mozilla/plugins";
|
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(sysLPlgDir),
|
|
|
|
PR_FALSE, getter_AddRefs(localFile));
|
|
|
|
}
|
|
|
|
#endif
|
2002-06-14 16:30:44 +04:00
|
|
|
#endif
|
2001-01-19 01:51:57 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_SEARCH_DIR) == 0)
|
2000-07-16 18:20:33 +04:00
|
|
|
{
|
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localFile->AppendRelativeNativePath(SEARCH_DIR_NAME);
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
2005-06-29 19:55:57 +04:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_USER_SEARCH_DIR) == 0)
|
|
|
|
{
|
|
|
|
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, _retval);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = (*_retval)->AppendNative(SEARCH_DIR_NAME);
|
|
|
|
}
|
2002-04-03 03:56:43 +04:00
|
|
|
else if (nsCRT::strcmp(prop, NS_APP_INSTALL_CLEANUP_DIR) == 0)
|
|
|
|
{
|
|
|
|
// This is cloned so that embeddors will have a hook to override
|
|
|
|
// with their own cleanup dir. See bugzilla bug #105087
|
|
|
|
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
if (localFile && NS_SUCCEEDED(rv))
|
|
|
|
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval);
|
|
|
|
|
|
|
|
return rv;
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD nsAppFileLocationProvider::CloneMozBinDirectory(nsILocalFile **aLocalFile)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLocalFile);
|
2001-01-19 01:51:57 +03:00
|
|
|
nsresult rv;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2001-01-19 01:51:57 +03:00
|
|
|
if (!mMozBinDirectory)
|
2001-07-31 23:05:34 +04:00
|
|
|
{
|
2001-01-19 01:51:57 +03:00
|
|
|
// Get the mozilla bin directory
|
|
|
|
// 1. Check the directory service first for NS_XPCOM_CURRENT_PROCESS_DIR
|
|
|
|
// This will be set if a directory was passed to NS_InitXPCOM
|
|
|
|
// 2. If that doesn't work, set it to be the current process directory
|
2001-07-31 23:05:34 +04:00
|
|
|
nsCOMPtr<nsIProperties>
|
|
|
|
directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
|
2001-01-19 01:51:57 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2001-01-19 01:51:57 +03:00
|
|
|
rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mMozBinDirectory));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
rv = directoryService->Get(NS_OS_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mMozBinDirectory));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2000-07-16 18:20:33 +04:00
|
|
|
nsCOMPtr<nsIFile> aFile;
|
2001-01-19 01:51:57 +03:00
|
|
|
rv = mMozBinDirectory->Clone(getter_AddRefs(aFile));
|
2000-07-19 23:58:35 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-07-16 18:20:33 +04:00
|
|
|
|
2000-07-19 23:58:35 +04:00
|
|
|
nsCOMPtr<nsILocalFile> lfile = do_QueryInterface (aFile);
|
|
|
|
if (!lfile)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2000-07-19 23:58:35 +04:00
|
|
|
NS_IF_ADDREF(*aLocalFile = lfile);
|
|
|
|
return NS_OK;
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
2001-01-19 01:51:57 +03:00
|
|
|
// GetProductDirectory - Gets the directory which contains the application data folder
|
2000-07-16 18:20:33 +04:00
|
|
|
//
|
|
|
|
// UNIX : ~/.mozilla/
|
2001-07-31 23:05:34 +04:00
|
|
|
// WIN : <Application Data folder on user's machine>\Mozilla
|
2001-01-19 01:51:57 +03:00
|
|
|
// Mac : :Documents:Mozilla:
|
2000-07-16 18:20:33 +04:00
|
|
|
//----------------------------------------------------------------------------------------
|
2005-04-27 15:56:40 +04:00
|
|
|
NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFile, PRBool aLocal)
|
2000-07-16 18:20:33 +04:00
|
|
|
{
|
2000-09-21 17:45:31 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aLocalFile);
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2000-09-21 17:45:31 +04:00
|
|
|
nsresult rv;
|
|
|
|
PRBool exists;
|
|
|
|
nsCOMPtr<nsILocalFile> localDir;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2006-11-16 12:10:09 +03:00
|
|
|
#if defined(XP_MACOSX)
|
2002-09-25 16:23:39 +04:00
|
|
|
FSRef fsRef;
|
2005-04-27 15:56:40 +04:00
|
|
|
OSType folderType = aLocal ? kCachedDataFolderType : kDomainLibraryFolderType;
|
|
|
|
OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
|
2002-09-25 16:23:39 +04:00
|
|
|
if (err) return NS_ERROR_FAILURE;
|
2004-05-23 00:02:43 +04:00
|
|
|
NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localDir));
|
2002-09-25 16:23:39 +04:00
|
|
|
if (!localDir) return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsILocalFileMac> localDirMac(do_QueryInterface(localDir));
|
|
|
|
rv = localDirMac->InitWithFSRef(&fsRef);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-07-20 22:55:28 +04:00
|
|
|
#elif defined(XP_OS2)
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsIProperties> directoryService =
|
|
|
|
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-11-01 23:04:59 +03:00
|
|
|
rv = directoryService->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2003-04-03 02:45:08 +04:00
|
|
|
#elif defined(XP_WIN)
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsIProperties> directoryService =
|
|
|
|
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2005-04-27 15:56:40 +04:00
|
|
|
const char* prop = aLocal ? NS_WIN_LOCAL_APPDATA_DIR : NS_WIN_APPDATA_DIR;
|
|
|
|
rv = directoryService->Get(prop, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = localDir->Exists(&exists);
|
|
|
|
if (NS_FAILED(rv) || !exists)
|
|
|
|
{
|
|
|
|
// On some Win95 machines, NS_WIN_APPDATA_DIR does not exist - revert to NS_WIN_WINDOWS_DIR
|
|
|
|
localDir = nsnull;
|
|
|
|
rv = directoryService->Get(NS_WIN_WINDOWS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-07-16 18:20:33 +04:00
|
|
|
#elif defined(XP_UNIX)
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), PR_TRUE, getter_AddRefs(localDir));
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-07-16 18:20:33 +04:00
|
|
|
#elif defined(XP_BEOS)
|
|
|
|
char path[MAXPATHLEN];
|
|
|
|
find_directory(B_USER_SETTINGS_DIRECTORY, 0, 0, path, MAXPATHLEN);
|
|
|
|
// Need enough space to add the trailing backslash
|
|
|
|
int len = strlen(path);
|
|
|
|
if (len > MAXPATHLEN-2)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
path[len] = '/';
|
|
|
|
path[len+1] = '\0';
|
2002-04-27 09:33:09 +04:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(path), PR_TRUE, getter_AddRefs(localDir));
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-01-19 01:51:57 +03:00
|
|
|
#else
|
|
|
|
#error dont_know_how_to_get_product_dir_on_your_platform
|
|
|
|
#endif
|
|
|
|
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR);
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = localDir->Exists(&exists);
|
2005-01-31 00:33:47 +03:00
|
|
|
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && !exists)
|
2003-11-19 04:30:16 +03:00
|
|
|
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
2005-01-31 00:33:47 +03:00
|
|
|
|
2001-01-19 01:51:57 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
*aLocalFile = localDir;
|
|
|
|
NS_ADDREF(*aLocalFile);
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
return rv;
|
2001-01-19 01:51:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
// GetDefaultUserProfileRoot - Gets the directory which contains each user profile dir
|
|
|
|
//
|
|
|
|
// UNIX : ~/.mozilla/
|
2001-07-31 23:05:34 +04:00
|
|
|
// WIN : <Application Data folder on user's machine>\Mozilla\Profiles
|
2001-04-18 06:51:24 +04:00
|
|
|
// Mac : :Documents:Mozilla:Profiles:
|
2001-01-19 01:51:57 +03:00
|
|
|
//----------------------------------------------------------------------------------------
|
2005-04-27 15:56:40 +04:00
|
|
|
NS_METHOD nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsILocalFile **aLocalFile, PRBool aLocal)
|
2001-01-19 01:51:57 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLocalFile);
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2001-01-19 01:51:57 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsILocalFile> localDir;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
2005-04-27 15:56:40 +04:00
|
|
|
rv = GetProductDirectory(getter_AddRefs(localDir), aLocal);
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-07-16 18:20:33 +04:00
|
|
|
|
2006-11-16 12:10:09 +03:00
|
|
|
#if defined(XP_MACOSX) || defined(XP_OS2) || defined(XP_WIN)
|
2000-09-21 17:45:31 +04:00
|
|
|
// These 3 platforms share this part of the path - do them as one
|
2002-05-08 03:07:19 +04:00
|
|
|
rv = localDir->AppendRelativeNativePath(NS_LITERAL_CSTRING("Profiles"));
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
PRBool exists;
|
2000-09-21 17:45:31 +04:00
|
|
|
rv = localDir->Exists(&exists);
|
|
|
|
if (NS_SUCCEEDED(rv) && !exists)
|
|
|
|
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-07-16 18:20:33 +04:00
|
|
|
#endif
|
|
|
|
|
2000-09-21 17:45:31 +04:00
|
|
|
*aLocalFile = localDir;
|
|
|
|
NS_ADDREF(*aLocalFile);
|
2000-07-16 18:20:33 +04:00
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
return rv;
|
2000-07-16 18:20:33 +04:00
|
|
|
}
|
|
|
|
|
2001-11-02 18:29:57 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsAppFileLocationProvider::nsIDirectoryServiceProvider2
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
class nsAppDirectoryEnumerator : public nsISimpleEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
/**
|
2002-06-14 16:30:44 +04:00
|
|
|
* aKeyList is a null-terminated list of properties which are provided by aProvider
|
2001-11-02 18:29:57 +03:00
|
|
|
* They do not need to be publicly defined keys.
|
|
|
|
*/
|
|
|
|
nsAppDirectoryEnumerator(nsIDirectoryServiceProvider *aProvider,
|
2002-06-14 16:30:44 +04:00
|
|
|
const char* aKeyList[]) :
|
2001-11-02 18:29:57 +03:00
|
|
|
mProvider(aProvider),
|
2002-06-14 16:30:44 +04:00
|
|
|
mCurrentKey(aKeyList)
|
2001-11-02 18:29:57 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD HasMoreElements(PRBool *result)
|
|
|
|
{
|
2002-06-14 16:30:44 +04:00
|
|
|
while (!mNext && *mCurrentKey)
|
2001-11-26 18:54:38 +03:00
|
|
|
{
|
|
|
|
PRBool dontCare;
|
2002-09-25 16:23:39 +04:00
|
|
|
nsCOMPtr<nsIFile> testFile;
|
|
|
|
(void)mProvider->GetFile(*mCurrentKey++, &dontCare, getter_AddRefs(testFile));
|
|
|
|
// Don't return a file which does not exist.
|
|
|
|
PRBool exists;
|
|
|
|
if (testFile && NS_SUCCEEDED(testFile->Exists(&exists)) && exists)
|
|
|
|
mNext = testFile;
|
2001-11-26 18:54:38 +03:00
|
|
|
}
|
|
|
|
*result = mNext != nsnull;
|
2001-11-02 18:29:57 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetNext(nsISupports **result)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
|
|
|
*result = nsnull;
|
|
|
|
|
|
|
|
PRBool hasMore;
|
|
|
|
HasMoreElements(&hasMore);
|
|
|
|
if (!hasMore)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-11-26 18:54:38 +03:00
|
|
|
|
|
|
|
*result = mNext;
|
|
|
|
NS_IF_ADDREF(*result);
|
|
|
|
mNext = nsnull;
|
|
|
|
|
2001-11-02 18:29:57 +03:00
|
|
|
return *result ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2004-01-22 04:01:19 +03:00
|
|
|
// Virtual destructor since subclass nsPathsDirectoryEnumerator
|
|
|
|
// does not re-implement Release()
|
|
|
|
|
2002-02-03 10:05:10 +03:00
|
|
|
virtual ~nsAppDirectoryEnumerator()
|
2001-11-02 18:29:57 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIDirectoryServiceProvider *mProvider;
|
2002-06-14 16:30:44 +04:00
|
|
|
const char** mCurrentKey;
|
2001-11-26 18:54:38 +03:00
|
|
|
nsCOMPtr<nsIFile> mNext;
|
2001-11-02 18:29:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsAppDirectoryEnumerator, nsISimpleEnumerator)
|
|
|
|
|
2002-10-25 17:08:44 +04:00
|
|
|
/* nsPathsDirectoryEnumerator and PATH_SEPARATOR
|
|
|
|
* are not used on MacOS/X. */
|
|
|
|
|
2008-10-08 04:21:13 +04:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2) /* Win32 and OS/2 */
|
2002-10-25 17:08:44 +04:00
|
|
|
#define PATH_SEPARATOR ';'
|
|
|
|
#else /*if defined(XP_UNIX) || defined(XP_BEOS)*/
|
|
|
|
#define PATH_SEPARATOR ':'
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class nsPathsDirectoryEnumerator : public nsAppDirectoryEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* aKeyList is a null-terminated list.
|
|
|
|
* The first element is a path list.
|
|
|
|
* The remainder are properties provided by aProvider.
|
|
|
|
* They do not need to be publicly defined keys.
|
|
|
|
*/
|
|
|
|
nsPathsDirectoryEnumerator(nsIDirectoryServiceProvider *aProvider,
|
|
|
|
const char* aKeyList[]) :
|
|
|
|
nsAppDirectoryEnumerator(aProvider, aKeyList+1),
|
|
|
|
mEndPath(aKeyList[0])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD HasMoreElements(PRBool *result)
|
|
|
|
{
|
|
|
|
if (mEndPath)
|
|
|
|
while (!mNext && *mEndPath)
|
|
|
|
{
|
|
|
|
const char *pathVar = mEndPath;
|
2007-02-21 22:45:48 +03:00
|
|
|
|
|
|
|
// skip PATH_SEPARATORs at the begining of the mEndPath
|
|
|
|
while (*pathVar == PATH_SEPARATOR) pathVar++;
|
|
|
|
|
2002-10-25 17:08:44 +04:00
|
|
|
do { ++mEndPath; } while (*mEndPath && *mEndPath != PATH_SEPARATOR);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
|
|
|
NS_NewNativeLocalFile(Substring(pathVar, mEndPath),
|
|
|
|
PR_TRUE,
|
|
|
|
getter_AddRefs(localFile));
|
|
|
|
if (*mEndPath == PATH_SEPARATOR)
|
|
|
|
++mEndPath;
|
|
|
|
// Don't return a "file" (directory) which does not exist.
|
|
|
|
PRBool exists;
|
|
|
|
if (localFile &&
|
|
|
|
NS_SUCCEEDED(localFile->Exists(&exists)) &&
|
|
|
|
exists)
|
|
|
|
mNext = localFile;
|
|
|
|
}
|
|
|
|
if (mNext)
|
|
|
|
*result = PR_TRUE;
|
|
|
|
else
|
|
|
|
nsAppDirectoryEnumerator::HasMoreElements(result);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const char *mEndPath;
|
|
|
|
};
|
|
|
|
|
2001-11-02 18:29:57 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppFileLocationProvider::GetFiles(const char *prop, nsISimpleEnumerator **_retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = nsnull;
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (!nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR_LIST))
|
|
|
|
{
|
2006-11-16 12:10:09 +03:00
|
|
|
#ifdef XP_MACOSX
|
2002-06-14 16:30:44 +04:00
|
|
|
static const char* osXKeys[] = { NS_APP_PLUGINS_DIR, NS_MACOSX_USER_PLUGIN_DIR, NS_MACOSX_LOCAL_PLUGIN_DIR, nsnull };
|
|
|
|
static const char* os9Keys[] = { NS_APP_PLUGINS_DIR, NS_MAC_CLASSIC_PLUGIN_DIR, nsnull };
|
|
|
|
static const char** keys;
|
|
|
|
|
|
|
|
if (!keys) {
|
|
|
|
OSErr err;
|
|
|
|
long response;
|
|
|
|
err = ::Gestalt(gestaltSystemVersion, &response);
|
|
|
|
keys = (!err && response >= 0x00001000) ? osXKeys : os9Keys;
|
|
|
|
}
|
2001-11-02 18:29:57 +03:00
|
|
|
|
2002-06-14 16:30:44 +04:00
|
|
|
*_retval = new nsAppDirectoryEnumerator(this, keys);
|
2008-10-10 19:54:33 +04:00
|
|
|
#else
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
static const char* keys[] = { nsnull, NS_USER_PLUGINS_DIR, NS_APP_PLUGINS_DIR, NS_SYSTEM_PLUGINS_DIR, nsnull };
|
2002-10-25 17:08:44 +04:00
|
|
|
#else
|
|
|
|
static const char* keys[] = { nsnull, NS_USER_PLUGINS_DIR, NS_APP_PLUGINS_DIR, nsnull };
|
2008-10-10 19:54:33 +04:00
|
|
|
#endif
|
2002-10-25 17:08:44 +04:00
|
|
|
if (!keys[0] && !(keys[0] = PR_GetEnv("MOZ_PLUGIN_PATH"))) {
|
|
|
|
static const char nullstr = 0;
|
|
|
|
keys[0] = &nullstr;
|
|
|
|
}
|
|
|
|
*_retval = new nsPathsDirectoryEnumerator(this, keys);
|
|
|
|
#endif
|
2001-11-02 18:29:57 +03:00
|
|
|
NS_IF_ADDREF(*_retval);
|
|
|
|
rv = *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2005-06-29 19:55:57 +04:00
|
|
|
if (!nsCRT::strcmp(prop, NS_APP_SEARCH_DIR_LIST))
|
|
|
|
{
|
|
|
|
static const char* keys[] = { nsnull, NS_APP_SEARCH_DIR, NS_APP_USER_SEARCH_DIR, nsnull };
|
|
|
|
if (!keys[0] && !(keys[0] = PR_GetEnv("MOZ_SEARCH_ENGINE_PATH"))) {
|
|
|
|
static const char nullstr = 0;
|
|
|
|
keys[0] = &nullstr;
|
|
|
|
}
|
|
|
|
*_retval = new nsPathsDirectoryEnumerator(this, keys);
|
|
|
|
NS_IF_ADDREF(*_retval);
|
|
|
|
rv = *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-11-02 18:29:57 +03:00
|
|
|
return rv;
|
|
|
|
}
|