adding xpfe file locations to be a provider of the nsDirectoryService.

r=dveditz@netscape.com
This commit is contained in:
dougt%netscape.com 2000-05-11 21:06:17 +00:00
Родитель ec0f7330b9
Коммит 7d28c5f26a
2 изменённых файлов: 315 добавлений и 115 удалений

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsFileSpec.h" #include "nsFileSpec.h"
#include "nsIFileLocator.h" #include "nsIFileLocator.h"
#include "nsIDirectoryService.h"
#ifdef XP_MAC #ifdef XP_MAC
#include <Types.h> #include <Types.h>
@ -50,12 +51,43 @@ public:
NS_IMETHOD ForgetProfileDir(); NS_IMETHOD ForgetProfileDir();
protected: protected:
virtual ~nsFileLocator(); virtual ~nsFileLocator();
}; };
// SEE ALSO:
// mozilla/base/public/nsSpecialSystemDirectory.h
class nsFileLocationProvider : public nsIDirectoryServiceProvider
//=============================================================================
{
public:
nsFileLocationProvider();
NS_DECL_ISUPPORTS
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
protected:
virtual ~nsFileLocationProvider();
};
//
//
//
//
//
// Talk to dougt@netscape.com before adding any more locations to this file!!
//
//
//
//
//
//
//
//======================================================================================== //========================================================================================
class NS_APPSHELL nsSpecialFileSpec : public nsFileSpec class NS_APPSHELL nsSpecialFileSpec : public nsFileSpec
@ -130,4 +162,5 @@ private:
}; // class NS_APPSHELL nsSpecialFileSpec }; // class NS_APPSHELL nsSpecialFileSpec
#endif // _NSFILELOCATIONS_H_ #endif // _NSFILELOCATIONS_H_

Просмотреть файл

@ -60,10 +60,89 @@ static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
// Global variable for gProfileDir // Global variable for gProfileDir
static nsFileSpec* gProfileDir = nsnull; static nsFileSpec* gProfileDir = nsnull;
static PRInt32 gRegisteredWithDirService = PR_FALSE;
#ifdef XP_MAC #ifdef XP_MAC
#pragma export on #pragma export on
#endif #endif
struct DirectoryTable
{
char * directoryName; /* The formal directory name */
PRInt32 folderEnum; /* Directory ID */
};
struct DirectoryTable DirectoryTable[] =
{
// Preferences:
{"app.prefs.directory.3", nsSpecialFileSpec::App_PrefsDirectory30 },
{"app.prefs.directory.4", nsSpecialFileSpec::App_PrefsDirectory40 },
{"app.prefs.directory.5", nsSpecialFileSpec::App_PrefsDirectory50 },
{"app.pref.default.directory.5", nsSpecialFileSpec::App_PrefDefaultsFolder50 },
{"app.prefs.file.3", nsSpecialFileSpec::App_PreferencesFile30 },
{"app.prefs.file.4", nsSpecialFileSpec::App_PreferencesFile40 },
{"app.prefs.file.5", nsSpecialFileSpec::App_PreferencesFile50 },
// Profile:
{"app.profile.user.directory.3", nsSpecialFileSpec::App_UserProfileDirectory30 },
{"app.profile.user.directory.4", nsSpecialFileSpec::App_UserProfileDirectory40 },
{"app.profile.user.directory.5", nsSpecialFileSpec::App_UserProfileDirectory50 },
{"app.profile.default.user.directory.3",nsSpecialFileSpec::App_DefaultUserProfileRoot30 },
{"app.profile.default.user.directory.4",nsSpecialFileSpec::App_DefaultUserProfileRoot40 },
{"app.profile.default.user.directory.5",nsSpecialFileSpec::App_DefaultUserProfileRoot50 },
{"app.profile.defaults.directory.3", nsSpecialFileSpec::App_ProfileDefaultsFolder30 },
{"app.profile.defaults.directory.4", nsSpecialFileSpec::App_ProfileDefaultsFolder40 },
{"app.profile.defaults.directory.5", nsSpecialFileSpec::App_ProfileDefaultsFolder50 },
// Application Directories:
{"app.res.directory", nsSpecialFileSpec::App_ResDirectory },
{"app.defaults.directory", nsSpecialFileSpec::App_DefaultsFolder50 },
{"app.chrome.directory", nsSpecialFileSpec::App_ChromeDirectory },
{"app.chrome.user.directory", nsSpecialFileSpec::App_UserChromeDirectory },
{"app.plugins.directory", nsSpecialFileSpec::App_PluginsDirectory },
// Bookmarks:
{"app.bookmark.file.3", nsSpecialFileSpec::App_BookmarksFile30 },
{"app.bookmark.file.4", nsSpecialFileSpec::App_BookmarksFile40 },
{"app.bookmark.file.5", nsSpecialFileSpec::App_BookmarksFile50 },
// Search
{"app.search.file.5", nsSpecialFileSpec::App_SearchFile50 },
{"app.search.directory.5", nsSpecialFileSpec::App_SearchDirectory50 },
// Application Files:
{"app.registry.file.4", nsSpecialFileSpec::App_Registry40 },
{"app.registry.file.5", nsSpecialFileSpec::App_Registry50 },
{"app.local.store.file.5", nsSpecialFileSpec::App_LocalStore50 },
{"app.history.file.5", nsSpecialFileSpec::App_History50 },
{"app.user.panels.5", nsSpecialFileSpec::App_UsersPanels50 },
// MailNews:
{"app.mail.directory.5", nsSpecialFileSpec::App_MailDirectory50 },
{"app.mail.imap.directory.5", nsSpecialFileSpec::App_ImapMailDirectory50 },
{"app.mail.news.directory.5", nsSpecialFileSpec::App_NewsDirectory50 },
{"app.mail.messenger.cache.directory.5", nsSpecialFileSpec::App_MessengerFolderCache50 },
{"", 0 },
};
//======================================================================================== //========================================================================================
// Static functions that ain't nobody else's business. // Static functions that ain't nobody else's business.
//======================================================================================== //========================================================================================
@ -591,8 +670,14 @@ nsFileLocator::nsFileLocator()
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
}
if (gRegisteredWithDirService == 0)
{
PR_AtomicIncrement(&gRegisteredWithDirService);
new nsFileLocationProvider();
}
}
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
nsFileLocator::~nsFileLocator() nsFileLocator::~nsFileLocator()
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
@ -628,7 +713,89 @@ NS_IMETHODIMP nsFileLocator::ForgetProfileDir()
if (gProfileDir) { if (gProfileDir) {
delete gProfileDir; delete gProfileDir;
gProfileDir = nsnull; gProfileDir = nsnull;
nsresult rv;
NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv);
if (NS_FAILED(rv)) return rv;
directoryService->Undefine("app.profile.user.directory.5");
directoryService->Undefine("app.profile.default.user.directory.5");
directoryService->Undefine("app.profile.defaults.directory.5");
} }
return NS_OK; return NS_OK;
} }
nsFileLocationProvider::nsFileLocationProvider()
{
NS_INIT_REFCNT();
nsresult rv;
NS_WITH_SERVICE(nsIDirectoryService, dirService, NS_DIRECTORY_SERVICE_PROGID, &rv);
if (dirService)
dirService->RegisterProvider( NS_STATIC_CAST(nsIDirectoryServiceProvider*, this) );
}
nsFileLocationProvider::~nsFileLocationProvider()
{
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsFileLocationProvider, nsIDirectoryServiceProvider);
/* MapNameToEnum
* maps name from the directory table to its enum */
PRInt32
static MapNameToEnum(const char* name)
{
int i = 0;
if ( !name )
return -1;
while ( DirectoryTable[i].directoryName[0] != 0 )
{
if ( strcmp(DirectoryTable[i].directoryName, name) == 0 )
return DirectoryTable[i].folderEnum;
i++;
}
return -1;
}
NS_IMETHODIMP
nsFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*persistant = PR_TRUE;
nsFileSpec spec;
PRInt32 value = MapNameToEnum(prop);
if (value == -1)
return NS_ERROR_FAILURE;
nsCOMPtr<nsILocalFile> localFile;
nsresult res;
if (value < nsSpecialFileSpec::App_DirectoryBase)
{
nsSpecialSystemDirectory ssd = (nsSpecialSystemDirectory::SystemDirectories)value;
res = NS_FileSpecToIFile(&ssd, getter_AddRefs(localFile));
}
else
{
nsSpecialFileSpec sfs = (nsSpecialFileSpec::Type)value;
res = NS_FileSpecToIFile(&sfs, getter_AddRefs(localFile));
}
if (localFile && NS_SUCCEEDED(res))
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval);
return NS_ERROR_FAILURE;
}