mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 14:46:02 +00:00
Bug #266027 --> unable to import data from netscape 4.x.
Move some code from the old profile manager and from the new migration code which knows how to do some of this stuff as well) into the import code so we don't depend on the obsolete profile manager. sr=bienvenu
This commit is contained in:
parent
ce7c07f3da
commit
afac31a3ea
@ -79,6 +79,7 @@ REQUIRES = xpcom \
|
||||
profile \
|
||||
prefmigr \
|
||||
unicharutil \
|
||||
libreg \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
@ -38,23 +38,41 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsComm4xProfile.h"
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsIProfileInternal.h"
|
||||
#include "nsILineInputStream.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "NSReg.h"
|
||||
|
||||
#if defined(XP_MACOSX)
|
||||
#define PREF_FILE_NAME_IN_4x "Netscape Preferences"
|
||||
#define OLDREG_NAME "Netscape Registry"
|
||||
#define OLDREG_DIR NS_MAC_PREFS_DIR
|
||||
#elif defined(XP_UNIX) && !defined(XP_MACOSX)
|
||||
#define PREF_FILE_NAME_IN_4x "preferences.js"
|
||||
#elif defined(XP_WIN) || defined(XP_OS2)
|
||||
#define PREF_FILE_NAME_IN_4x "prefs.js"
|
||||
#define OLDREG_NAME "nsreg.dat"
|
||||
#ifdef XP_WIN
|
||||
#define OLDREG_DIR NS_WIN_WINDOWS_DIR
|
||||
#else
|
||||
#define OLDREG_DIR NS_OS2_DIR
|
||||
#endif
|
||||
#else
|
||||
/* this will cause a failure at run time, as it should, since we don't know
|
||||
how to migrate platforms other than Mac, Windows and UNIX */
|
||||
#define PREF_FILE_NAME_IN_4x ""
|
||||
#endif
|
||||
|
||||
#ifndef MAXPATHLEN
|
||||
#ifdef _MAX_PATH
|
||||
#define MAXPATHLEN _MAX_PATH
|
||||
#elif defined(CCHMAXPATH)
|
||||
#define MAXPATHLEN CCHMAXPATH
|
||||
#else
|
||||
#define MAXPATHLEN 1024
|
||||
#endif
|
||||
#endif
|
||||
|
||||
nsComm4xProfile::nsComm4xProfile()
|
||||
{
|
||||
@ -69,31 +87,101 @@ NS_IMPL_ISUPPORTS1(nsComm4xProfile, nsIComm4xProfile)
|
||||
NS_IMETHODIMP
|
||||
nsComm4xProfile::GetProfileList(PRUint32 *length, PRUnichar ***profileNames)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIProfileInternal> profile (do_GetService(NS_PROFILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = profile->GetProfileListX(nsIProfileInternal::LIST_FOR_IMPORT, length, profileNames);
|
||||
return rv;
|
||||
nsresult rv;
|
||||
// on win/mac/os2, NS4x uses a registry to determine profile locations
|
||||
#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_OS2)
|
||||
|
||||
nsCOMPtr<nsIFile> regFile;
|
||||
rv = NS_GetSpecialDirectory(OLDREG_DIR, getter_AddRefs(regFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
regFile->AppendNative(NS_LITERAL_CSTRING(OLDREG_NAME));
|
||||
|
||||
nsCAutoString path;
|
||||
rv = regFile->GetNativePath(path);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (NR_StartupRegistry())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
HREG reg = nsnull;
|
||||
if (NR_RegOpen(path.get(), ®)) {
|
||||
NR_ShutdownRegistry();
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRInt32 numProfileEntries = 0;
|
||||
REGENUM enumstate = 0;
|
||||
PRInt32 localLength = 0;
|
||||
|
||||
char profileName[MAXREGNAMELEN];
|
||||
while (!NR_RegEnumSubkeys(reg, ROOTKEY_USERS, &enumstate,
|
||||
profileName, MAXREGNAMELEN, REGENUM_CHILDREN))
|
||||
numProfileEntries++;
|
||||
|
||||
// reset our enumerator
|
||||
enumstate = 0;
|
||||
|
||||
PRUnichar **outArray, **next;
|
||||
next = outArray = (PRUnichar **)nsMemory::Alloc(numProfileEntries * sizeof(PRUnichar *));
|
||||
if (!outArray)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
while (!NR_RegEnumSubkeys(reg, ROOTKEY_USERS, &enumstate,
|
||||
profileName, MAXREGNAMELEN, REGENUM_CHILDREN)) {
|
||||
*next = ToNewUnicode(NS_ConvertUTF8toUTF16(profileName));
|
||||
next++;
|
||||
localLength++;
|
||||
}
|
||||
|
||||
*profileNames = outArray;
|
||||
*length = localLength;
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_FAILURE;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define PREF_NAME "user_pref(\"mail.directory\", \""
|
||||
#define PREF_LENGTH 29
|
||||
#define PREF_END "\")"
|
||||
NS_IMETHODIMP
|
||||
nsComm4xProfile::GetMailDir(const PRUnichar *profileName, PRUnichar **_retval)
|
||||
nsComm4xProfile::GetMailDir(const PRUnichar *aProfile, PRUnichar **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
*_retval = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr <nsILocalFile> resolvedLocation;
|
||||
#if defined(XP_WIN) || defined(XP_OS2) || defined(XP_MACOSX)
|
||||
nsCOMPtr <nsILocalFile> resolvedLocation = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
// on macos, registry entries are UTF8 encoded
|
||||
NS_ConvertUTF16toUTF8 profileName(aProfile);
|
||||
|
||||
nsCOMPtr<nsIProfileInternal> profile (do_GetService(NS_PROFILE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = profile->GetOriginalProfileDir(profileName, getter_AddRefs(resolvedLocation));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsIFile> regFile;
|
||||
rv = NS_GetSpecialDirectory(OLDREG_DIR, getter_AddRefs(regFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
regFile->AppendNative(NS_LITERAL_CSTRING(OLDREG_NAME));
|
||||
|
||||
nsCAutoString path;
|
||||
rv = regFile->GetNativePath(path);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NR_StartupRegistry())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
HREG reg = nsnull;
|
||||
RKEY profile = nsnull;
|
||||
|
||||
if (NR_RegOpen(path.get(), ®))
|
||||
goto cleanup;
|
||||
|
||||
if (NR_RegGetKey(reg, ROOTKEY_USERS, profileName.get(), &profile))
|
||||
goto cleanup;
|
||||
|
||||
char profilePath[MAXPATHLEN];
|
||||
if (NR_RegGetEntryString(reg, profile, "ProfileLocation", profilePath, MAXPATHLEN))
|
||||
goto cleanup;
|
||||
|
||||
resolvedLocation->InitWithPath(NS_ConvertUTF8toUTF16(profilePath));
|
||||
if (resolvedLocation) {
|
||||
nsCOMPtr <nsIFile> file;
|
||||
rv = resolvedLocation->Clone(getter_AddRefs(file));
|
||||
@ -136,7 +224,15 @@ nsComm4xProfile::GetMailDir(const PRUnichar *profileName, PRUnichar **_retval)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (reg)
|
||||
NR_RegClose(reg);
|
||||
NR_ShutdownRegistry();
|
||||
return rv;
|
||||
#else
|
||||
return NS_ERROR_FAILURE;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult nsComm4xProfile::GetPrefValue(nsILocalFile *filePath, const char * prefName, const char * prefEnd, PRUnichar ** retval)
|
||||
|
Loading…
x
Reference in New Issue
Block a user