2000-07-16 18:20:33 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2001-07-31 23:05:34 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code,
|
|
|
|
* released March 31, 1998.
|
2000-07-16 18:20:33 +04:00
|
|
|
*
|
2001-07-31 23:05:34 +04:00
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
2000-07-16 18:20:33 +04:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 2000 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2001-07-31 23:05:34 +04:00
|
|
|
* Contributor(s):
|
2000-07-16 18:20:33 +04:00
|
|
|
* Conrad Carlen <conrad@ingress.com>
|
|
|
|
*/
|
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"
|
2000-07-16 18:20:33 +04:00
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC) /* || defined(XP_MACOSX) REMIND HACKING FOR MACOS X!!! */
|
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>
|
|
|
|
#elif defined(XP_PC)
|
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
|
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC) /* || defined(XP_MACOSX) REMIND HACKING FOR MACOS X!!! */
|
2001-01-19 01:51:57 +03:00
|
|
|
#define APP_REGISTRY_NAME "Application Registry"
|
|
|
|
#elif defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
#define APP_REGISTRY_NAME "registry.dat"
|
|
|
|
#else
|
|
|
|
#define APP_REGISTRY_NAME "appreg"
|
2001-07-31 23:05:34 +04:00
|
|
|
#endif
|
2001-01-19 01:51:57 +03:00
|
|
|
|
|
|
|
// define default product directory
|
|
|
|
#if defined(XP_WIN) || defined(XP_MAC) || defined(XP_OS2) || defined(XP_BEOS)
|
|
|
|
#define DEFAULT_PRODUCT_DIR "Mozilla"
|
|
|
|
#elif defined (XP_UNIX)
|
|
|
|
#define DEFAULT_PRODUCT_DIR ".mozilla"
|
|
|
|
#endif
|
|
|
|
|
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
|
2001-01-19 01:51:57 +03:00
|
|
|
|
2000-07-16 18:20:33 +04:00
|
|
|
#if XP_MAC
|
|
|
|
#define DEFAULTS_DIR_NAME "Defaults"
|
|
|
|
#define DEFAULTS_PREF_DIR_NAME "Pref"
|
|
|
|
#define DEFAULTS_PROFILE_DIR_NAME "Profile"
|
|
|
|
#define RES_DIR_NAME "Res"
|
|
|
|
#define CHROME_DIR_NAME "Chrome"
|
2000-09-29 02:52:51 +04:00
|
|
|
#define PLUGINS_DIR_NAME "Plug-ins"
|
2001-07-31 23:05:34 +04:00
|
|
|
#define SEARCH_DIR_NAME "Search Plugins"
|
2000-07-16 18:20:33 +04:00
|
|
|
#else
|
|
|
|
#define DEFAULTS_DIR_NAME "defaults"
|
|
|
|
#define DEFAULTS_PREF_DIR_NAME "pref"
|
|
|
|
#define DEFAULTS_PROFILE_DIR_NAME "profile"
|
|
|
|
#define RES_DIR_NAME "res"
|
|
|
|
#define CHROME_DIR_NAME "chrome"
|
|
|
|
#define PLUGINS_DIR_NAME "plugins"
|
2001-07-31 23:05:34 +04:00
|
|
|
#define SEARCH_DIR_NAME "searchplugins"
|
2000-07-16 18:20:33 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsAppFileLocationProvider::Constructor/Destructor
|
2001-07-31 23:05:34 +04:00
|
|
|
//*****************************************************************************
|
2000-07-16 18:20:33 +04:00
|
|
|
|
|
|
|
nsAppFileLocationProvider::nsAppFileLocationProvider()
|
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, 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;
|
|
|
|
*persistant = PR_TRUE;
|
|
|
|
|
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))
|
|
|
|
rv = localFile->Append(APP_REGISTRY_NAME);
|
|
|
|
}
|
|
|
|
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))
|
|
|
|
rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME);
|
|
|
|
}
|
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)) {
|
|
|
|
rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = localFile->AppendRelativePath(DEFAULTS_PREF_DIR_NAME);
|
|
|
|
}
|
|
|
|
}
|
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)) {
|
|
|
|
rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = localFile->AppendRelativePath(DEFAULTS_PROFILE_DIR_NAME);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
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))
|
|
|
|
rv = localFile->AppendRelativePath(RES_DIR_NAME);
|
|
|
|
}
|
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))
|
|
|
|
rv = localFile->AppendRelativePath(CHROME_DIR_NAME);
|
|
|
|
}
|
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))
|
|
|
|
rv = localFile->AppendRelativePath(PLUGINS_DIR_NAME);
|
|
|
|
}
|
2001-11-26 18:54:38 +03:00
|
|
|
else if (nsCRT::strcmp(prop, NS_ENV_PLUGINS_DIR) == 0)
|
|
|
|
{
|
|
|
|
const char *pathVar = PR_GetEnv("MOZ_PLUGIN_PATH");
|
|
|
|
if (pathVar)
|
|
|
|
rv = NS_NewLocalFile(pathVar, PR_TRUE, getter_AddRefs(localFile));
|
|
|
|
}
|
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))
|
|
|
|
rv = localFile->AppendRelativePath(SEARCH_DIR_NAME);
|
|
|
|
}
|
2001-09-19 11:43:41 +04:00
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------------------------
|
2001-01-19 01:51:57 +03:00
|
|
|
NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFile)
|
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
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC) /* || defined(XP_MACOSX) REMIND HACKING FOR MACOS X!!! */
|
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;
|
2001-06-14 05:24:22 +04:00
|
|
|
OSErr err;
|
|
|
|
long response;
|
|
|
|
err = ::Gestalt(gestaltSystemVersion, &response);
|
|
|
|
const char *prop = (!err && response >= 0x00001000) ? NS_MAC_USER_LIB_DIR : NS_MAC_DOCUMENTS_DIR;
|
|
|
|
rv = directoryService->Get(prop, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
|
2000-09-21 17:45:31 +04:00
|
|
|
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;
|
2000-07-20 22:55:28 +04:00
|
|
|
#elif defined(XP_PC)
|
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;
|
|
|
|
rv = directoryService->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
|
|
|
|
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)
|
2000-09-21 17:45:31 +04:00
|
|
|
rv = NS_NewLocalFile(PR_GetEnv("HOME"), PR_TRUE, getter_AddRefs(localDir));
|
|
|
|
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';
|
2000-09-21 17:45:31 +04:00
|
|
|
rv = NS_NewLocalFile(path, PR_TRUE, getter_AddRefs(localDir));
|
|
|
|
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
|
|
|
|
|
|
|
|
rv = localDir->AppendRelativePath(DEFAULT_PRODUCT_DIR);
|
2000-09-21 17:45:31 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = localDir->Exists(&exists);
|
|
|
|
if (NS_SUCCEEDED(rv) && !exists)
|
2001-01-19 01:51:57 +03:00
|
|
|
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
NS_METHOD nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsILocalFile **aLocalFile)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2001-01-19 01:51:57 +03:00
|
|
|
rv = GetProductDirectory(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
|
|
|
|
2001-10-27 11:38:18 +04:00
|
|
|
#if defined(XP_MAC) || defined(XP_MACOSX) || defined(XP_OS2) || defined(XP_PC)
|
2000-09-21 17:45:31 +04:00
|
|
|
// These 3 platforms share this part of the path - do them as one
|
2001-04-18 06:51:24 +04:00
|
|
|
rv = localDir->AppendRelativePath("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
|
|
|
|
|
|
|
|
/**
|
|
|
|
* aKeyList is a list of properties which are provided by aProvider
|
|
|
|
* They do not need to be publicly defined keys.
|
|
|
|
*/
|
|
|
|
nsAppDirectoryEnumerator(nsIDirectoryServiceProvider *aProvider,
|
|
|
|
const char* aKeyList[],
|
|
|
|
PRInt32 aNumKeys) :
|
|
|
|
mProvider(aProvider),
|
|
|
|
mKeyList(aKeyList),
|
|
|
|
mCurrentIndex(0), mMaxIndex(aNumKeys)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD HasMoreElements(PRBool *result)
|
|
|
|
{
|
2001-11-26 18:54:38 +03:00
|
|
|
while (!mNext && (mCurrentIndex < mMaxIndex))
|
|
|
|
{
|
|
|
|
PRBool dontCare;
|
|
|
|
(void)mProvider->GetFile(mKeyList[mCurrentIndex++], &dontCare, getter_AddRefs(mNext));
|
|
|
|
}
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
2002-02-03 10:05:10 +03:00
|
|
|
virtual ~nsAppDirectoryEnumerator()
|
2001-11-02 18:29:57 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIDirectoryServiceProvider *mProvider;
|
|
|
|
const char** mKeyList;
|
|
|
|
PRInt32 mCurrentIndex, mMaxIndex;
|
2001-11-26 18:54:38 +03:00
|
|
|
nsCOMPtr<nsIFile> mNext;
|
2001-11-02 18:29:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsAppDirectoryEnumerator, nsISimpleEnumerator)
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2001-11-26 18:54:38 +03:00
|
|
|
#ifdef XP_MAC
|
2001-11-02 18:29:57 +03:00
|
|
|
static const char* keys[] = { NS_APP_PLUGINS_DIR };
|
2001-11-26 18:54:38 +03:00
|
|
|
#else
|
|
|
|
static const char* keys[] = { NS_ENV_PLUGINS_DIR, NS_APP_PLUGINS_DIR };
|
|
|
|
#endif
|
2001-11-02 18:29:57 +03:00
|
|
|
|
|
|
|
*_retval = new nsAppDirectoryEnumerator(this, keys, sizeof(keys) / sizeof(keys[0]));
|
|
|
|
NS_IF_ADDREF(*_retval);
|
|
|
|
rv = *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|