First check-in, not yet part of build. This lib is being used to solve bug #48981, but has other uses.

This commit is contained in:
ccarlen%netscape.com 2000-09-14 13:35:28 +00:00
Родитель fa7f4ce180
Коммит 0d1006dc68
14 изменённых файлов: 533 добавлений и 0 удалений

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

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

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

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

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

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

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

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

@ -0,0 +1,41 @@
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH =../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
EXPORTS = \
nsMPFileLocProvider.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,27 @@
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..
EXPORTS = \
nsMPFileLocProvider.h \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -0,0 +1,81 @@
/* -*- 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.org code.
*
* 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>
*/
// Interfaces Needed
#include "nsIDirectoryService.h"
#include "nsILocalFile.h"
#include "nsString.h"
// Forward Declarations
class nsIAtom;
// --------------------------------------------------------------------------------------
// nsMPFileLocProvider - The MP stands for "MonoProfile" This nsIDirectoryServiceProvider
// can be used in place of the profile mgr for applications which don't need to manage
// distinct user profiles. It provides the same file locations the the profile mgr does.
// --------------------------------------------------------------------------------------
class nsMPFileLocProvider: public nsIDirectoryServiceProvider
{
NS_DECL_ISUPPORTS
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
public:
nsMPFileLocProvider();
virtual ~nsMPFileLocProvider();
/*
Initialize: Must be called after constructor.
profileParentDir -> The directory that is the parent dir of our profile folder.
profileDirName -> The leaf name of our profile folder.
*/
virtual nsresult Initialize(nsIFile* profileParentDir, const char *profileDirName);
protected:
// Atoms for file locations
static nsIAtom* sApp_PrefsDirectory50;
static nsIAtom* sApp_PreferencesFile50;
static nsIAtom* sApp_UserProfileDirectory50;
static nsIAtom* sApp_UserChromeDirectory;
static nsIAtom* sApp_LocalStore50;
static nsIAtom* sApp_History50;
static nsIAtom* sApp_UsersPanels50;
static nsIAtom* sApp_UsersMimeTypes50;
static nsIAtom* sApp_BookmarksFile50;
static nsIAtom* sApp_SearchFile50;
static nsIAtom* sApp_MailDirectory50;
static nsIAtom* sApp_ImapMailDirectory50;
static nsIAtom* sApp_NewsDirectory50;
static nsIAtom* sApp_MessengerFolderCache50;
nsresult InitProfileDir(nsIFile* profileParentDir,
const char *profileDirName,
nsIFile **profileDir);
PRBool mInitialized;
nsCOMPtr<nsIFile> mProfileDir;
};

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

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

@ -0,0 +1,39 @@
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = mpfilelocprovider
LIBRARY_NAME = mpfilelocprovider_s
CPPSRCS = nsMPFileLocProvider.cpp
# we don't want the shared lib
override NO_SHARED_LIB=1
override NO_STATIC_LIB=
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,37 @@
#!nmake
#
# 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.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
DEPTH=..\..\..
LIBRARY_NAME=mpfilelocprovider_s
CPP_OBJS= \
.\$(OBJDIR)\nsMPFileLocProvider.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
include <$(DEPTH)\config\config.mak>
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib

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

@ -0,0 +1,308 @@
/* -*- 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.org code.
*
* 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 "nsMPFileLocProvider.h"
#include "nsIAtom.h"
#include "nsILocalFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsISupportsUtils.h"
// Static Variables
nsIAtom* nsMPFileLocProvider::sApp_PrefsDirectory50;
nsIAtom* nsMPFileLocProvider::sApp_PreferencesFile50;
nsIAtom* nsMPFileLocProvider::sApp_UserProfileDirectory50;
nsIAtom* nsMPFileLocProvider::sApp_UserChromeDirectory;
nsIAtom* nsMPFileLocProvider::sApp_LocalStore50;
nsIAtom* nsMPFileLocProvider::sApp_History50;
nsIAtom* nsMPFileLocProvider::sApp_UsersPanels50;
nsIAtom* nsMPFileLocProvider::sApp_UsersMimeTypes50;
nsIAtom* nsMPFileLocProvider::sApp_BookmarksFile50;
nsIAtom* nsMPFileLocProvider::sApp_SearchFile50;
nsIAtom* nsMPFileLocProvider::sApp_MailDirectory50;
nsIAtom* nsMPFileLocProvider::sApp_ImapMailDirectory50;
nsIAtom* nsMPFileLocProvider::sApp_NewsDirectory50;
nsIAtom* nsMPFileLocProvider::sApp_MessengerFolderCache50;
//*****************************************************************************
// nsMPFileLocProvider::nsMPFileLocProvider
//*****************************************************************************
nsMPFileLocProvider::nsMPFileLocProvider() :
mInitialized(PR_FALSE)
{
NS_INIT_REFCNT();
}
nsMPFileLocProvider::~nsMPFileLocProvider()
{
NS_IF_RELEASE(sApp_PrefsDirectory50);
NS_IF_RELEASE(sApp_PreferencesFile50);
NS_IF_RELEASE(sApp_UserProfileDirectory50);
NS_IF_RELEASE(sApp_UserChromeDirectory);
NS_IF_RELEASE(sApp_LocalStore50);
NS_IF_RELEASE(sApp_History50);
NS_IF_RELEASE(sApp_UsersPanels50);
NS_IF_RELEASE(sApp_UsersMimeTypes50);
NS_IF_RELEASE(sApp_BookmarksFile50);
NS_IF_RELEASE(sApp_SearchFile50);
NS_IF_RELEASE(sApp_MailDirectory50);
NS_IF_RELEASE(sApp_ImapMailDirectory50);
NS_IF_RELEASE(sApp_NewsDirectory50);
NS_IF_RELEASE(sApp_MessengerFolderCache50);
}
nsresult nsMPFileLocProvider::Initialize(nsIFile* profileParentDir, const char *profileDirName)
{
nsresult rv;
if (mInitialized)
return NS_OK;
rv = InitProfileDir(profileParentDir, profileDirName, getter_AddRefs(mProfileDir));
if (NS_FAILED(rv)) return rv;
// Make our directory atoms
// Preferences:
sApp_PrefsDirectory50 = NS_NewAtom(NS_APP_PREFS_50_DIR);
sApp_PreferencesFile50 = NS_NewAtom(NS_APP_PREFS_50_FILE);
// Profile:
sApp_UserProfileDirectory50 = NS_NewAtom(NS_APP_USER_PROFILE_50_DIR);
// Application Directories:
sApp_UserChromeDirectory = NS_NewAtom(NS_APP_USER_CHROME_DIR);
// Aplication Files:
sApp_LocalStore50 = NS_NewAtom(NS_APP_LOCALSTORE_50_FILE);
sApp_History50 = NS_NewAtom(NS_APP_HISTORY_50_FILE);
sApp_UsersPanels50 = NS_NewAtom(NS_APP_USER_PANELS_50_FILE);
sApp_UsersMimeTypes50 = NS_NewAtom(NS_APP_USER_MIMETYPES_50_FILE);
// Bookmarks:
sApp_BookmarksFile50 = NS_NewAtom(NS_APP_BOOKMARKS_50_FILE);
// Search
sApp_SearchFile50 = NS_NewAtom(NS_APP_SEARCH_50_FILE);
// MailNews
sApp_MailDirectory50 = NS_NewAtom(NS_APP_MAIL_50_DIR);
sApp_ImapMailDirectory50 = NS_NewAtom(NS_APP_IMAP_MAIL_50_DIR);
sApp_NewsDirectory50 = NS_NewAtom(NS_APP_NEWS_50_DIR);
sApp_MessengerFolderCache50 = NS_NewAtom(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR);
NS_WITH_SERVICE(nsIDirectoryService, directoryService, NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
directoryService->RegisterProvider(this);
mInitialized = PR_TRUE;
return NS_OK;
}
//*****************************************************************************
// nsMPFileLocProvider::nsISupports
//*****************************************************************************
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMPFileLocProvider, nsIDirectoryServiceProvider)
// File Name Defines - Copied straight from nsProfile
#define PREFS_FILE_50_NAME "prefs.js"
#define USER_CHROME_DIR_50_NAME "chrome"
#define LOCAL_STORE_FILE_50_NAME "localstore.rdf"
#define HISTORY_FILE_50_NAME "history.dat"
#define PANELS_FILE_50_NAME "panels.rdf"
#define MIME_TYPES_FILE_50_NAME "mimeTypes.rdf"
#define BOOKMARKS_FILE_50_NAME "bookmarks.html"
#define SEARCH_FILE_50_NAME "search.rdf"
#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"
NS_IMETHODIMP
nsMPFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval)
{
nsCOMPtr<nsIFile> localFile;
nsresult rv = NS_ERROR_FAILURE;
*_retval = nsnull;
*persistant = PR_TRUE;
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
nsIAtom* inAtom = NS_NewAtom(prop);
NS_ENSURE_TRUE(inAtom, NS_ERROR_OUT_OF_MEMORY);
if (inAtom == sApp_PrefsDirectory50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
}
else if (inAtom == sApp_PreferencesFile50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(PREFS_FILE_50_NAME);
}
else if (inAtom == sApp_UserProfileDirectory50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
}
else if (inAtom == sApp_UserChromeDirectory)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(USER_CHROME_DIR_50_NAME);
}
else if (inAtom == sApp_LocalStore50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(LOCAL_STORE_FILE_50_NAME);
}
else if (inAtom == sApp_History50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(HISTORY_FILE_50_NAME);
}
else if (inAtom == sApp_UsersPanels50)
{
// Here we differ from nsFileLocator - It checks for the
// existance of this file and if it does not exist, copies
// it from the defaults folder to the profile folder. Since
// WE set up any profile folder, we'll make sure it's copied then.
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(PANELS_FILE_50_NAME);
}
else if (inAtom == sApp_UsersMimeTypes50)
{
// Here we differ from nsFileLocator - It checks for the
// existance of this file and if it does not exist, copies
// it from the defaults folder to the profile folder. Since
// WE set up any profile folder, we'll make sure it's copied then.
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(MIME_TYPES_FILE_50_NAME);
}
else if (inAtom == sApp_BookmarksFile50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(BOOKMARKS_FILE_50_NAME);
}
else if (inAtom == sApp_SearchFile50)
{
// Here we differ from nsFileLocator - It checks for the
// existance of this file and if it does not exist, copies
// it from the defaults folder to the profile folder. Since
// WE set up any profile folder, we'll make sure it's copied then.
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(SEARCH_FILE_50_NAME);
}
else if (inAtom == sApp_MailDirectory50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(MAIL_DIR_50_NAME);
}
else if (inAtom == sApp_ImapMailDirectory50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(IMAP_MAIL_DIR_50_NAME);
}
else if (inAtom == sApp_NewsDirectory50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(NEWS_DIR_50_NAME);
}
else if (inAtom == sApp_MessengerFolderCache50)
{
rv = mProfileDir->Clone(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
rv = localFile->Append(MSG_FOLDER_CACHE_DIR_50_NAME);
}
NS_RELEASE(inAtom);
if (localFile && NS_SUCCEEDED(rv))
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval);
return rv;
}
nsresult nsMPFileLocProvider::InitProfileDir(nsIFile *profileParentDir,
const char *profileDirName,
nsIFile **outProfileDir)
{
NS_ENSURE_ARG_POINTER(outProfileDir);
// Make sure our "Profile" folder exists
nsresult rv;
nsCOMPtr<nsIFile> profileDir;
rv = profileParentDir->Clone(getter_AddRefs(profileDir));
if (NS_FAILED(rv)) return rv;
rv = profileDir->Append(profileDirName);
if (NS_FAILED(rv)) return rv;
PRBool exists;
rv = profileDir->Exists(&exists);
if (NS_FAILED(rv)) return rv;
if (!exists)
{
nsCOMPtr<nsIFile> profDefaultsFolder;
rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(profDefaultsFolder));
if (NS_FAILED(rv))
{
rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, getter_AddRefs(profDefaultsFolder));
if (NS_FAILED(rv)) return rv;
}
rv = profDefaultsFolder->CopyTo(profileParentDir, profileDirName);
if (NS_FAILED(rv)) return rv;
}
if (NS_FAILED(rv)) return rv;
*outProfileDir = profileDir;
NS_ADDREF(*outProfileDir);
return NS_OK;
}