nsAppFileLocationProvider.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* -*- 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 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.
*
* Contributor(s):
* 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 ***** */
#include "nsAppFileLocationProvider.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIAtom.h"
#include "nsILocalFile.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsISimpleEnumerator.h"
#include "prenv.h"
#include "nsCRT.h"
#include <Folders.h>
#include <Script.h>
#include <Processes.h>
#include <Gestalt.h>
#include "nsILocalFileMac.h"
#define INCL_DOSPROCESS
#define INCL_DOSMODULEMGR
#include <os2.h>
#include <windows.h>
#include <shlobj.h>
#include <unistd.h>
#include <stdlib.h>
#include <storage/FindDirectory.h>
#endif
// WARNING: These hard coded names need to go away. They need to
// come from localizable resources
#else
#endif
// define default product directory
#ifdef XP_MAC
#else
#endif
// Locally defined keys used by nsAppDirectoryEnumerator
#define NS_USER_PLUGINS_DIR "UserPlugins"
#define NS_MACOSX_USER_PLUGIN_DIR "OSXUserPlugins"
#define NS_MACOSX_LOCAL_PLUGIN_DIR "OSXLocalPlugins"
#define NS_MAC_CLASSIC_PLUGIN_DIR "MacSysPlugins"
#endif
#if defined(XP_MAC)
#else
#endif
//*****************************************************************************
// nsAppFileLocationProvider::Constructor/Destructor
//*****************************************************************************
{
}
//*****************************************************************************
// nsAppFileLocationProvider::nsISupports
//*****************************************************************************
NS_IMPL_THREADSAFE_ISUPPORTS2(nsAppFileLocationProvider, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2)
//*****************************************************************************
// nsAppFileLocationProvider::nsIDirectoryServiceProvider
//*****************************************************************************
{
*persistant = PR_TRUE;
short foundVRefNum;
long foundDirID;
#endif
{
}
{
if (NS_SUCCEEDED(rv))
}
{
if (NS_SUCCEEDED(rv))
}
{
if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv))
}
}
{
if (NS_SUCCEEDED(rv)) {
if (NS_SUCCEEDED(rv))
}
}
{
}
{
if (NS_SUCCEEDED(rv))
}
{
if (NS_SUCCEEDED(rv))
}
{
if (NS_SUCCEEDED(rv))
}
{
if (!(::FindFolder(kUserDomain,
if (NS_SUCCEEDED(rv))
}
}
{
if (!(::FindFolder(kLocalDomain,
if (NS_SUCCEEDED(rv))
}
}
{
if (!(::FindFolder(kOnAppropriateDisk,
if (NS_SUCCEEDED(rv))
}
}
#else
{
NS_ERROR("Don't use nsAppFileLocationProvider::GetFile(NS_ENV_PLUGINS_DIR, ...). "
"Use nsAppFileLocationProvider::GetFiles(...).");
if (pathVar)
}
{
if (NS_SUCCEEDED(rv))
}
#endif
{
if (NS_SUCCEEDED(rv))
}
{
// This is cloned so that embeddors will have a hook to override
// with their own cleanup dir. See bugzilla bug #105087
#ifdef XP_MAC
if (NS_SUCCEEDED(rv))
#endif
}
return rv;
}
{
if (!mMozBinDirectory)
{
// 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
return rv;
rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mMozBinDirectory));
rv = directoryService->Get(NS_OS_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mMozBinDirectory));
return rv;
}
}
return rv;
if (!lfile)
return NS_ERROR_FAILURE;
return NS_OK;
}
//----------------------------------------------------------------------------------------
// GetProductDirectory - Gets the directory which contains the application data folder
//
// UNIX : ~/.mozilla/
// WIN : <Application Data folder on user's machine>\Mozilla
// Mac : :Documents:Mozilla:
//----------------------------------------------------------------------------------------
{
#if defined(XP_MAC)
long response;
if (err) return NS_ERROR_FAILURE;
if (!localDir) return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv))
{
// On some Win95 machines, NS_WIN_APPDATA_DIR does not exist - revert to NS_WIN_WINDOWS_DIR
}
/* Major hack attack, should sort out the environment stuff!!! */
rv = NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), PR_TRUE, getter_AddRefs(localDir));
char path[MAXPATHLEN];
// Need enough space to add the trailing backslash
return NS_ERROR_FAILURE;
#else
#endif
*aLocalFile = localDir;
return rv;
}
//----------------------------------------------------------------------------------------
// GetDefaultUserProfileRoot - Gets the directory which contains each user profile dir
//
// UNIX : ~/.mozilla/
// WIN : <Application Data folder on user's machine>\Mozilla\Profiles
// Mac : :Documents:Mozilla:Profiles:
//----------------------------------------------------------------------------------------
{
// These 3 platforms share this part of the path - do them as one
#endif
*aLocalFile = localDir;
return rv;
}
//*****************************************************************************
// nsAppFileLocationProvider::nsIDirectoryServiceProvider2
//*****************************************************************************
class nsAppDirectoryEnumerator : public nsISimpleEnumerator
{
public:
/**
* aKeyList is a null-terminated list of properties which are provided by aProvider
* They do not need to be publicly defined keys.
*/
const char* aKeyList[]) :
{
}
{
while (!mNext && *mCurrentKey)
{
// Don't return a file which does not exist.
}
return NS_OK;
}
{
if (!hasMore)
return NS_ERROR_FAILURE;
}
// Virtual destructor since subclass nsPathsDirectoryEnumerator
// does not re-implement Release()
virtual ~nsAppDirectoryEnumerator()
{
}
protected:
const char** mCurrentKey;
};
/* nsPathsDirectoryEnumerator and PATH_SEPARATOR
* are not used on MacOS/X. */
#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.
*/
const char* aKeyList[]) :
{
}
{
if (mEndPath)
{
if (*mEndPath == PATH_SEPARATOR)
++mEndPath;
// Don't return a "file" (directory) which does not exist.
if (localFile &&
}
if (mNext)
else
return NS_OK;
}
protected:
const char *mEndPath;
};
{
{
static const char* osXKeys[] = { NS_APP_PLUGINS_DIR, NS_MACOSX_USER_PLUGIN_DIR, NS_MACOSX_LOCAL_PLUGIN_DIR, nsnull };
static const char** keys;
if (!keys) {
long response;
}
#else
static const char nullstr = 0;
}
#endif
}
return rv;
}