Bug 420459 Move mailnews-specific profe code. r=benjamin,Neil,sr=dmose,a1.9=beltzner
git-svn-id: svn://10.0.0.236/trunk@248011 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
670292513c
commit
8ef2551b9c
@ -1,3 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
@ -34,7 +35,6 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#include "nsMailDirProvider.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
@ -43,9 +43,28 @@
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsIChromeRegistry.h"
|
||||
#include "nsICategoryManager.h"
|
||||
|
||||
#define MAIL_DIR_50_NAME "Mail"
|
||||
#define IMAP_MAIL_DIR_50_NAME "ImapMail"
|
||||
#define NEWS_DIR_50_NAME "News"
|
||||
#define MSG_FOLDER_CACHE_DIR_50_NAME "panacea.dat"
|
||||
|
||||
nsresult
|
||||
nsMailDirProvider::EnsureDirectory(nsIFile *aDirectory)
|
||||
{
|
||||
PRBool exists;
|
||||
nsresult rv = aDirectory->Exists(&exists);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!exists)
|
||||
rv = aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsMailDirProvider,
|
||||
nsIDirectoryServiceProvider,
|
||||
nsIDirectoryServiceProvider2)
|
||||
@ -54,7 +73,49 @@ NS_IMETHODIMP
|
||||
nsMailDirProvider::GetFile(const char *aKey, PRBool *aPersist,
|
||||
nsIFile* *aResult)
|
||||
{
|
||||
// NOTE: This function can be reentrant through the NS_GetSpecialDirectory
|
||||
// call, so be careful not to cause infinite recursion.
|
||||
// i.e. the check for supported files must come first.
|
||||
const char* leafName = nsnull;
|
||||
PRBool isDirectory = PR_TRUE;
|
||||
|
||||
if (!strcmp(aKey, NS_APP_MAIL_50_DIR))
|
||||
leafName = MAIL_DIR_50_NAME;
|
||||
else if (!strcmp(aKey, NS_APP_IMAP_MAIL_50_DIR))
|
||||
leafName = IMAP_MAIL_DIR_50_NAME;
|
||||
else if (!strcmp(aKey, NS_APP_NEWS_50_DIR))
|
||||
leafName = NEWS_DIR_50_NAME;
|
||||
else if (!strcmp(aKey, NS_APP_MESSENGER_FOLDER_CACHE_50_FILE)) {
|
||||
isDirectory = PR_FALSE;
|
||||
leafName = MSG_FOLDER_CACHE_DIR_50_NAME;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIFile> parentDir;
|
||||
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
||||
getter_AddRefs(parentDir));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
rv = parentDir->Clone(getter_AddRefs(file));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsDependentCString leafStr(leafName);
|
||||
rv = file->AppendNative(leafStr);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
PRBool exists;
|
||||
if (isDirectory && NS_SUCCEEDED(file->Exists(&exists)) && !exists)
|
||||
rv = EnsureDirectory(file);
|
||||
|
||||
*aPersist = PR_TRUE;
|
||||
file.swap(*aResult);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -185,7 +246,8 @@ nsMailDirProvider::Register(nsIComponentManager* aCompMgr,
|
||||
|
||||
return catMan->AddCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY,
|
||||
"mail-directory-provider",
|
||||
NS_MAILDIRPROVIDER_CONTRACTID, PR_TRUE, PR_TRUE, nsnull);
|
||||
NS_MAILDIRPROVIDER_CONTRACTID, PR_TRUE,
|
||||
PR_TRUE, nsnull);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
@ -61,6 +62,8 @@ public:
|
||||
const nsModuleComponentInfo *aInfo);
|
||||
|
||||
private:
|
||||
nsresult EnsureDirectory(nsIFile *aDirectory);
|
||||
|
||||
class AppendingEnumerator : public nsISimpleEnumerator
|
||||
{
|
||||
public:
|
||||
|
||||
@ -49,9 +49,15 @@
|
||||
//=============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Files and directories that exist on a per- basis.
|
||||
// Files and directories that exist on a per-profile basis.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define NS_APP_MAIL_50_DIR "MailD"
|
||||
#define NS_APP_IMAP_MAIL_50_DIR "IMapMD"
|
||||
#define NS_APP_NEWS_50_DIR "NewsD"
|
||||
|
||||
#define NS_APP_MESSENGER_FOLDER_CACHE_50_FILE "MFCaF"
|
||||
|
||||
#define ISP_DIRECTORY_LIST "ISPDL"
|
||||
|
||||
#endif
|
||||
|
||||
@ -73,6 +73,7 @@
|
||||
#include "nsIMsgMailSession.h"
|
||||
#include "nsIDirectoryService.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#include "nsMsgFolderFlags.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsRDFCID.h"
|
||||
@ -860,7 +861,8 @@ NS_IMETHODIMP nsMsgAccountManager::GetFolderCache(nsIMsgFolderCache* *aFolderCac
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIFile> cacheFile;
|
||||
rv = NS_GetSpecialDirectory(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR, getter_AddRefs(cacheFile));
|
||||
rv = NS_GetSpecialDirectory(NS_APP_MESSENGER_FOLDER_CACHE_50_FILE,
|
||||
getter_AddRefs(cacheFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
m_msgFolderCache->Init(cacheFile);
|
||||
}
|
||||
|
||||
72
mozilla/mailnews/base/test/unit/test_nsMailDirProvider.js
Normal file
72
mozilla/mailnews/base/test/unit/test_nsMailDirProvider.js
Normal file
@ -0,0 +1,72 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* Test suite for nsMsgMailSession functions relating to listeners.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
const nsIFile = Components.interfaces.nsIFile;
|
||||
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
||||
|
||||
// Various functions common to the tests.
|
||||
const DirServiceTest = {
|
||||
|
||||
/*
|
||||
* makeDirectoryService
|
||||
*
|
||||
*/
|
||||
makeDirectoryService : function () {
|
||||
// Register our own provider for the profile directory.
|
||||
// It will simply return the current directory.
|
||||
const provider = {
|
||||
getFile : function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == NS_APP_USER_PROFILE_50_DIR) {
|
||||
var processDir = dirSvc.get("CurProcD", nsIFile);
|
||||
|
||||
processDir.append("mailtest");
|
||||
|
||||
if (!processDir.exists())
|
||||
processDir.create(nsIFile.DIRECTORY_TYPE, 0700);
|
||||
|
||||
return processDir;
|
||||
}
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
},
|
||||
|
||||
QueryInterface :
|
||||
XPCOMUtils.generateQI([Components.interfaces.nsIDirectoryServiceProvider])
|
||||
};
|
||||
|
||||
dirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
|
||||
.registerProvider(provider);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// If there's no location registered for the profile direcotry, register one
|
||||
var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties);
|
||||
try {
|
||||
var profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, nsIFile);
|
||||
} catch (e) { }
|
||||
|
||||
if (!profileDir) {
|
||||
DirServiceTest.makeDirectoryService();
|
||||
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, nsIFile);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
const items = [ { key: "MailD", value: "Mail" },
|
||||
{ key: "IMapMD", value: "ImapMail" },
|
||||
{ key: "NewsD", value: "News" },
|
||||
{ key: "MFCaF", value: "panacea.dat" } ];
|
||||
|
||||
items.forEach(function(item) {
|
||||
var dir = dirSvc.get(item.key, nsIFile);
|
||||
dump(profileDir.path + " " + dir.path + "\n");
|
||||
do_check_true(profileDir.equals(dir.parent));
|
||||
|
||||
do_check_eq(dir.leafName, item.value);
|
||||
});
|
||||
};
|
||||
@ -71,7 +71,7 @@
|
||||
#include "nsMsgFolderFlags.h"
|
||||
#include "nsISubscribableServer.h"
|
||||
#include "nsIDirectoryService.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsImapStringBundle.h"
|
||||
#include "plbase64.h"
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
#include "nsIPrompt.h"
|
||||
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#include "nsMsgUtils.h"
|
||||
|
||||
#include "nsMsgLocalCID.h"
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
#include "nsMsgUtils.h"
|
||||
|
||||
#include "nsIDirectoryService.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
|
||||
#define PREF_MAIL_ROOT_NONE "mail.root.none" // old - for backward compatibility only
|
||||
#define PREF_MAIL_ROOT_NONE_REL "mail.root.none-rel"
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIDirectoryService.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#include "prprf.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsMsgUtils.h"
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
#include "nsIRssIncomingServer.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
|
||||
nsRssService::nsRssService()
|
||||
{
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
#include "nsMsgNewsCID.h"
|
||||
#include "nsNNTPProtocol.h"
|
||||
#include "nsIDirectoryService.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#include "nsInt64.h"
|
||||
#include "nsMsgUtils.h"
|
||||
#include "nsIPrompt.h"
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
#include "nsIWindowMediator.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIMsgSearchSession.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsMailDirServiceDefs.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
@ -62,10 +62,6 @@
|
||||
#define BOOKMARKS_FILE_50_NAME NS_LITERAL_CSTRING("bookmarks.html")
|
||||
#define DOWNLOADS_FILE_50_NAME NS_LITERAL_CSTRING("downloads.rdf")
|
||||
#define SEARCH_FILE_50_NAME NS_LITERAL_CSTRING("search.rdf" )
|
||||
#define MAIL_DIR_50_NAME NS_LITERAL_CSTRING("Mail")
|
||||
#define IMAP_MAIL_DIR_50_NAME NS_LITERAL_CSTRING("ImapMail")
|
||||
#define NEWS_DIR_50_NAME NS_LITERAL_CSTRING("News")
|
||||
#define MSG_FOLDER_CACHE_DIR_50_NAME NS_LITERAL_CSTRING("panacea.dat")
|
||||
#define STORAGE_FILE_50_NAME NS_LITERAL_CSTRING("storage.sdb")
|
||||
|
||||
//*****************************************************************************
|
||||
@ -301,26 +297,6 @@ nsProfileDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFi
|
||||
rv = EnsureProfileFileExists(localFile, domainDir);
|
||||
}
|
||||
}
|
||||
else if (strcmp(prop, NS_APP_MAIL_50_DIR) == 0) {
|
||||
rv = domainDir->Clone(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendNative(MAIL_DIR_50_NAME);
|
||||
}
|
||||
else if (strcmp(prop, NS_APP_IMAP_MAIL_50_DIR) == 0) {
|
||||
rv = domainDir->Clone(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendNative(IMAP_MAIL_DIR_50_NAME);
|
||||
}
|
||||
else if (strcmp(prop, NS_APP_NEWS_50_DIR) == 0) {
|
||||
rv = domainDir->Clone(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendNative(NEWS_DIR_50_NAME);
|
||||
}
|
||||
else if (strcmp(prop, NS_APP_MESSENGER_FOLDER_CACHE_50_DIR) == 0) {
|
||||
rv = domainDir->Clone(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = localFile->AppendNative(MSG_FOLDER_CACHE_DIR_50_NAME);
|
||||
}
|
||||
else if (strcmp(prop, NS_APP_STORAGE_50_FILE) == 0) {
|
||||
rv = domainDir->Clone(getter_AddRefs(localFile));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
@ -513,10 +489,6 @@ nsProfileDirServiceProvider::UndefineFileLocations()
|
||||
(void) directoryService->Undefine(NS_APP_BOOKMARKS_50_FILE);
|
||||
(void) directoryService->Undefine(NS_APP_DOWNLOADS_50_FILE);
|
||||
(void) directoryService->Undefine(NS_APP_SEARCH_50_FILE);
|
||||
(void) directoryService->Undefine(NS_APP_MAIL_50_DIR);
|
||||
(void) directoryService->Undefine(NS_APP_IMAP_MAIL_50_DIR);
|
||||
(void) directoryService->Undefine(NS_APP_NEWS_50_DIR);
|
||||
(void) directoryService->Undefine(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -377,19 +377,6 @@ nsXREDirProvider::GetFile(const char* aProperty, PRBool* aPersistent,
|
||||
rv |= file->AppendNative(NS_LITERAL_CSTRING(PREF_OVERRIDE_DIRNAME));
|
||||
rv |= EnsureDirectoryExists(file);
|
||||
}
|
||||
// XXXbsmedberg move these defines into application-specific providers.
|
||||
else if (!strcmp(aProperty, NS_APP_MAIL_50_DIR)) {
|
||||
rv = file->AppendNative(NS_LITERAL_CSTRING("Mail"));
|
||||
}
|
||||
else if (!strcmp(aProperty, NS_APP_IMAP_MAIL_50_DIR)) {
|
||||
rv = file->AppendNative(NS_LITERAL_CSTRING("ImapMail"));
|
||||
}
|
||||
else if (!strcmp(aProperty, NS_APP_NEWS_50_DIR)) {
|
||||
rv = file->AppendNative(NS_LITERAL_CSTRING("News"));
|
||||
}
|
||||
else if (!strcmp(aProperty, NS_APP_MESSENGER_FOLDER_CACHE_50_DIR)) {
|
||||
rv = file->AppendNative(NS_LITERAL_CSTRING("panacea.dat"));
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(rv) || !file)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@ -117,11 +117,6 @@
|
||||
|
||||
#define NS_APP_SEARCH_50_FILE "SrchF"
|
||||
|
||||
#define NS_APP_MAIL_50_DIR "MailD"
|
||||
#define NS_APP_IMAP_MAIL_50_DIR "IMapMD"
|
||||
#define NS_APP_NEWS_50_DIR "NewsD"
|
||||
#define NS_APP_MESSENGER_FOLDER_CACHE_50_DIR "MFCaD"
|
||||
|
||||
#define NS_APP_INSTALL_CLEANUP_DIR "XPIClnupD" //location of xpicleanup.dat xpicleanup.exe
|
||||
|
||||
#define NS_APP_STORAGE_50_FILE "UStor" // sqlite database used as mozStorage profile db
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user