NOT PART OF THE BUILD - forgot to add this yesterday
git-svn-id: svn://10.0.0.236/trunk@85159 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
58b7709f6a
commit
d74a48618d
305
mozilla/embedding/browser/powerplant/source/CAppFileLocationProvider.cpp
Executable file
305
mozilla/embedding/browser/powerplant/source/CAppFileLocationProvider.cpp
Executable file
@ -0,0 +1,305 @@
|
||||
/* -*- 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.
|
||||
*
|
||||
* 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 Netscape are
|
||||
* Copyright (C) 2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Conrad Carlen <ccarlen@netscape.com>
|
||||
*/
|
||||
|
||||
#include "CAppFileLocationProvider.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIChromeRegistry.h"
|
||||
|
||||
#include <Folders.h>
|
||||
#include <Script.h>
|
||||
#include <Processes.h>
|
||||
#include "nsILocalFileMac.h"
|
||||
|
||||
#include "ApplIDs.h"
|
||||
|
||||
static nsresult GetChromeLocale(PRUnichar** localeName);
|
||||
static char* GetResCString(PRInt32 stringIndex, Str255& buf);
|
||||
|
||||
// IDs
|
||||
|
||||
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
// CAppFileLocationProvider::Constructor/Destructor
|
||||
//*****************************************************************************
|
||||
|
||||
CAppFileLocationProvider::CAppFileLocationProvider(const char* productDirName)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
strncpy(mProductDirName, productDirName, sizeof(mProductDirName) - 1);
|
||||
mProductDirName[sizeof(mProductDirName) - 1] = '\0';
|
||||
}
|
||||
|
||||
CAppFileLocationProvider::~CAppFileLocationProvider()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
// CAppFileLocationProvider::nsISupports
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMPL_ISUPPORTS1(CAppFileLocationProvider, nsIDirectoryServiceProvider)
|
||||
|
||||
//*****************************************************************************
|
||||
// CAppFileLocationProvider::nsIDirectoryServiceProvider
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP
|
||||
CAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> localFile;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
Str255 strBuf;
|
||||
|
||||
*_retval = nsnull;
|
||||
*persistant = PR_TRUE;
|
||||
|
||||
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(GetResCString(str_AppRegistryName, strBuf));
|
||||
}
|
||||
else if (nsCRT::strcmp(prop, NS_APP_DEFAULTS_50_DIR) == 0)
|
||||
{
|
||||
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_DefaultsDirName, strBuf));
|
||||
}
|
||||
else if (nsCRT::strcmp(prop, NS_APP_PREF_DEFAULTS_50_DIR) == 0)
|
||||
{
|
||||
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_DefaultsDirName, strBuf));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_PrefDefaultsDirName, strBuf));
|
||||
}
|
||||
}
|
||||
else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_50_DIR) == 0)
|
||||
{
|
||||
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_DefaultsDirName, strBuf));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_ProfileDefaultsDirName, strBuf));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsXPIDLString localeName;
|
||||
rv = GetChromeLocale(getter_Copies(localeName));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendRelativeUnicodePath(localeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR) == 0)
|
||||
{
|
||||
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_DefaultsDirName, strBuf));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_ProfileDefaultsDirName, strBuf));
|
||||
}
|
||||
}
|
||||
else if (nsCRT::strcmp(prop, NS_APP_USER_PROFILES_ROOT_DIR) == 0)
|
||||
{
|
||||
rv = GetDefaultUserProfileRoot(getter_AddRefs(localFile));
|
||||
}
|
||||
else if (nsCRT::strcmp(prop, NS_APP_RES_DIR) == 0)
|
||||
{
|
||||
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_ResDirName, strBuf));
|
||||
}
|
||||
else if (nsCRT::strcmp(prop, NS_APP_CHROME_DIR) == 0)
|
||||
{
|
||||
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_ChromeDirName, strBuf));
|
||||
}
|
||||
else if (nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR) == 0)
|
||||
{
|
||||
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_PlugInsDirName, strBuf));
|
||||
}
|
||||
else if (nsCRT::strcmp(prop, NS_APP_SEARCH_DIR) == 0)
|
||||
{
|
||||
rv = CloneMozBinDirectory(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendRelativePath(GetResCString(str_SearchPlugInsDirName, strBuf));
|
||||
}
|
||||
|
||||
if (localFile && NS_SUCCEEDED(rv))
|
||||
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD CAppFileLocationProvider::CloneMozBinDirectory(nsILocalFile **aLocalFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aLocalFile);
|
||||
nsresult 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
|
||||
|
||||
NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFile> aFile;
|
||||
rv = mMozBinDirectory->Clone(getter_AddRefs(aFile));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> lfile = do_QueryInterface (aFile);
|
||||
if (!lfile)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_IF_ADDREF(*aLocalFile = lfile);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// GetProductDirectory - Gets the directory which contains the application data folder
|
||||
//
|
||||
// Mac : :Documents:Mozilla:
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_METHOD CAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aLocalFile);
|
||||
|
||||
nsresult rv;
|
||||
PRBool exists;
|
||||
nsCOMPtr<nsILocalFile> localDir;
|
||||
|
||||
NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = directoryService->Get(NS_MAC_DOCUMENTS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = localDir->AppendRelativePath(mProductDirName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = localDir->Exists(&exists);
|
||||
if (NS_SUCCEEDED(rv) && !exists)
|
||||
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aLocalFile = localDir;
|
||||
NS_ADDREF(*aLocalFile);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// GetDefaultUserProfileRoot - Gets the directory which contains each user profile dir
|
||||
//
|
||||
// Mac : :Documents:Mozilla:Profiles:
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_METHOD CAppFileLocationProvider::GetDefaultUserProfileRoot(nsILocalFile **aLocalFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aLocalFile);
|
||||
|
||||
nsresult rv;
|
||||
PRBool exists;
|
||||
nsCOMPtr<nsILocalFile> localDir;
|
||||
Str255 strBuf;
|
||||
|
||||
rv = GetProductDirectory(getter_AddRefs(localDir));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = localDir->AppendRelativePath(GetResCString(str_ProfilesRootDirName, strBuf));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = localDir->Exists(&exists);
|
||||
if (NS_SUCCEEDED(rv) && !exists)
|
||||
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aLocalFile = localDir;
|
||||
NS_ADDREF(*aLocalFile);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//****************************************************************************************
|
||||
// Static Routines
|
||||
//****************************************************************************************
|
||||
|
||||
static nsresult GetChromeLocale(PRUnichar** localeName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(localeName);
|
||||
|
||||
nsresult rv;
|
||||
*localeName = nsnull;
|
||||
nsCOMPtr<nsIChromeRegistry> chromeRegistry = do_GetService(kChromeRegistryCID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsString tmpstr; tmpstr.AssignWithConversion("navigator");
|
||||
rv = chromeRegistry->GetSelectedLocale(tmpstr.GetUnicode(), localeName);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static char* GetResCString(PRInt32 stringIndex, Str255& buf)
|
||||
{
|
||||
GetIndString(buf, STRx_FileLocProviderStrings, stringIndex);
|
||||
if (!buf[0]) {
|
||||
NS_ASSERTION(PR_FALSE, "Directory name resource is missing.");
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
// Because of different availability of Pascal to C conversion routines
|
||||
// in Carbon and not, just do it by hand.
|
||||
PRInt32 len = buf[0];
|
||||
nsCRT::memmove(buf, buf + 1, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
return (char *)buf;
|
||||
}
|
||||
51
mozilla/embedding/browser/powerplant/source/CAppFileLocationProvider.h
Executable file
51
mozilla/embedding/browser/powerplant/source/CAppFileLocationProvider.h
Executable file
@ -0,0 +1,51 @@
|
||||
/* -*- 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.
|
||||
*
|
||||
* 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 Netscape are
|
||||
* Copyright (C) 2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Conrad Carlen <conrad@ingress.com>
|
||||
*/
|
||||
|
||||
#include "nsIDirectoryService.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
class nsIFile;
|
||||
|
||||
//*****************************************************************************
|
||||
// class CAppFileLocationProvider
|
||||
//*****************************************************************************
|
||||
|
||||
class CAppFileLocationProvider : public nsIDirectoryServiceProvider
|
||||
{
|
||||
public:
|
||||
CAppFileLocationProvider(const char* productDirName);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
|
||||
|
||||
protected:
|
||||
virtual ~CAppFileLocationProvider();
|
||||
|
||||
NS_METHOD CloneMozBinDirectory(nsILocalFile **aLocalFile);
|
||||
NS_METHOD GetProductDirectory(nsILocalFile **aLocalFile);
|
||||
NS_METHOD GetDefaultUserProfileRoot(nsILocalFile **aLocalFile);
|
||||
|
||||
char mProductDirName[256];
|
||||
nsCOMPtr<nsILocalFile> mMozBinDirectory;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user