changes to get pref-migrator (think apprunner -installer) on UNIX.
use the NS_DEFINE_STATIC_IID_ACCESSOR and NS_DEFINE_STATIC_CID_ACCESSOR macros. fix a bunch of warnings. rewrite to use #defines. remove unused variables. use MAXPATHLEN instead of _MAX_PATH. when setting a 4.x pref (example "mail.directory") to a new 5.0 value, create a "premigration" pref with the old value. (example "premigration.mail.directory").
This commit is contained in:
Родитель
ba6575ef35
Коммит
e08a5a5296
|
@ -313,6 +313,10 @@ profile/Makefile
|
|||
profile/src/Makefile
|
||||
profile/public/Makefile
|
||||
profile/resources/Makefile
|
||||
profile/pref-migrator/Makefile
|
||||
profile/pref-migrator/public/Makefile
|
||||
profile/pref-migrator/src/Makefile
|
||||
profile/pref-migrator/resources/Makefile
|
||||
profile/defaults/Makefile
|
||||
profile/idlservices/Makefile
|
||||
rdf/Makefile
|
||||
|
|
|
@ -22,7 +22,7 @@ VPATH = @srcdir@
|
|||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src resources defaults idlservices
|
||||
DIRS = public src resources defaults idlservices pref-migrator
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
class nsIPrefMigration : public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsIID& IID() { static nsIID iid = NS_IPrefMigration_IID; return iid; }
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPrefMigration_IID)
|
||||
|
||||
//NS_IMETHOD Startup() = 0;
|
||||
//NS_IMETHOD Shutdown()= 0;
|
||||
|
@ -40,7 +40,7 @@ class nsPrefMigrationFactory : public nsIFactory
|
|||
public:
|
||||
|
||||
nsPrefMigrationFactory();
|
||||
~nsPrefMigrationFactory();
|
||||
virtual ~nsPrefMigrationFactory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef nsPrefMigrationIIDs_h___
|
||||
#define nsPrefMigrationIIDs_h___
|
||||
|
||||
#define NS_IPrefMigration_IID { 0xc29db6a1, 0xd195, 0x11d2, 0xbc, 0xf1, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}
|
||||
|
||||
#define NS_PrefMigration_CID { 0xc29db6a2, 0xd195, 0x11d2, 0xbc, 0xf1, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}
|
||||
|
||||
#define NS_PrefMigrationFactory_CID { 0xc29db6a3, 0xd195, 0x11d2, 0xbc, 0xf1, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}
|
||||
|
||||
#define NS_IPrefMigrationFactory_IID { 0xc29db6a4, 0xd195, 0x11d2, 0xbc, 0xf1, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}
|
||||
|
||||
#endif /* nsPrefMigrationIIDs_h___ */
|
|
@ -29,6 +29,7 @@
|
|||
#include "prmem.h"
|
||||
#include "prefapi.h"
|
||||
#include "plstr.h"
|
||||
#include "prprf.h"
|
||||
|
||||
/* Network */
|
||||
|
||||
|
@ -37,6 +38,22 @@
|
|||
#include "nsPrefMigration.h"
|
||||
#include "nsPMProgressDlg.h"
|
||||
|
||||
/* who's going to win the file name battle? */
|
||||
#if defined(XP_UNIX)
|
||||
#define PREF_FILE_NAME_IN_4x "preferences.js"
|
||||
#elif defined(XP_MAC)
|
||||
#define PREF_FILE_NAME_IN_4x "Netscape Preferences"
|
||||
#elif defined(XP_PC)
|
||||
#define PREF_FILE_NAME_IN_4x "prefs.js"
|
||||
#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
|
||||
|
||||
/* and the winner is: Windows */
|
||||
#define PREF_FILE_NAME_IN_5x "prefs.js"
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
* Globals
|
||||
*-----------------------------------------------------------------*/
|
||||
|
@ -115,15 +132,10 @@ nsPrefMigration::ProcessPrefs(char* oldProfilePathStr, char* newProfilePathStr,
|
|||
PRUint32 totalMailSize = 0,
|
||||
totalNewsSize = 0,
|
||||
totalProfileSize = 0,
|
||||
totalRequired = 0,
|
||||
totalSize = 0,
|
||||
numberOfMailFiles = 0,
|
||||
numberOfNewsFiles = 0,
|
||||
numberOfProfileFiles = 0;
|
||||
totalRequired = 0;
|
||||
|
||||
PRInt32 oldDirLength = 0,
|
||||
serverType = 0,
|
||||
nameLength = _MAX_PATH;
|
||||
PRInt32 serverType = 0,
|
||||
nameLength = MAXPATHLEN;
|
||||
|
||||
PRBool hasIMAP = PR_FALSE;
|
||||
|
||||
|
@ -132,63 +144,63 @@ nsPrefMigration::ProcessPrefs(char* oldProfilePathStr, char* newProfilePathStr,
|
|||
#endif
|
||||
|
||||
|
||||
if((newPOPMailPathStr = (char*) PR_MALLOC(_MAX_PATH)) == NULL)
|
||||
if((newPOPMailPathStr = (char*) PR_MALLOC(MAXPATHLEN)) == NULL)
|
||||
{
|
||||
PR_Free(newPOPMailPathStr);
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if((newIMAPMailPathStr = (char*) PR_MALLOC(_MAX_PATH)) == NULL)
|
||||
if((newIMAPMailPathStr = (char*) PR_MALLOC(MAXPATHLEN)) == NULL)
|
||||
{
|
||||
PR_Free(newIMAPMailPathStr);
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if((newIMAPLocalMailPathStr = (char*) PR_MALLOC(_MAX_PATH)) == NULL)
|
||||
if((newIMAPLocalMailPathStr = (char*) PR_MALLOC(MAXPATHLEN)) == NULL)
|
||||
{
|
||||
PR_Free(newIMAPLocalMailPathStr);
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if((newNewsPathStr = (char*) PR_MALLOC(_MAX_PATH)) == NULL)
|
||||
if((newNewsPathStr = (char*) PR_MALLOC(MAXPATHLEN)) == NULL)
|
||||
{
|
||||
PR_Free(newNewsPathStr);
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if((oldPOPMailPathStr = (char*) PR_MALLOC(_MAX_PATH)) == NULL)
|
||||
if((oldPOPMailPathStr = (char*) PR_MALLOC(MAXPATHLEN)) == NULL)
|
||||
{
|
||||
PR_Free(oldPOPMailPathStr);
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if((oldIMAPMailPathStr = (char*) PR_MALLOC(_MAX_PATH)) == NULL)
|
||||
if((oldIMAPMailPathStr = (char*) PR_MALLOC(MAXPATHLEN)) == NULL)
|
||||
{
|
||||
PR_Free(oldIMAPMailPathStr);
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if((oldIMAPLocalMailPathStr = (char*) PR_MALLOC(_MAX_PATH)) == NULL)
|
||||
if((oldIMAPLocalMailPathStr = (char*) PR_MALLOC(MAXPATHLEN)) == NULL)
|
||||
{
|
||||
PR_Free(oldIMAPLocalMailPathStr);
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if((oldNewsPathStr = (char*) PR_MALLOC(_MAX_PATH)) == NULL)
|
||||
if((oldNewsPathStr = (char*) PR_MALLOC(MAXPATHLEN)) == NULL)
|
||||
{
|
||||
PR_Free(oldNewsPathStr);
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if((popServerName = (char*) PR_MALLOC(_MAX_PATH)) == NULL)
|
||||
if((popServerName = (char*) PR_MALLOC(MAXPATHLEN)) == NULL)
|
||||
{
|
||||
PR_Free(popServerName);
|
||||
*aResult = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -476,9 +488,13 @@ nsPrefMigration::ProcessPrefs(char* oldProfilePathStr, char* newProfilePathStr,
|
|||
nsresult
|
||||
nsPrefMigration::CreateNewUser5Tree(char* oldProfilePath, char* newProfilePath)
|
||||
{
|
||||
|
||||
char* prefsFile;
|
||||
|
||||
|
||||
NS_ASSERTION((PL_strlen(PREF_FILE_NAME_IN_4x) > 0), "don't know how to migrate your platform");
|
||||
if (PL_strlen(PREF_FILE_NAME_IN_4x) > 0) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
/* Copy the old prefs.js file to the new profile directory for modification and reading */
|
||||
if ((prefsFile = (char*) PR_MALLOC(PL_strlen(oldProfilePath) + 32)) == NULL)
|
||||
{
|
||||
|
@ -487,11 +503,7 @@ nsPrefMigration::CreateNewUser5Tree(char* oldProfilePath, char* newProfilePath)
|
|||
}
|
||||
|
||||
nsFileSpec oldPrefsFile(oldProfilePath);
|
||||
#ifdef XP_PC
|
||||
oldPrefsFile += "prefs.js";
|
||||
#else
|
||||
oldPrefsFile += "Netscape Preferences";
|
||||
#endif
|
||||
oldPrefsFile += PREF_FILE_NAME_IN_4x;
|
||||
|
||||
nsFileSpec newPrefsFile(newProfilePath);
|
||||
|
||||
|
@ -501,12 +513,9 @@ nsPrefMigration::CreateNewUser5Tree(char* oldProfilePath, char* newProfilePath)
|
|||
}
|
||||
|
||||
oldPrefsFile.Copy(newPrefsFile);
|
||||
#ifdef XP_MAC
|
||||
newPrefsFile += "Netscape Preferences";
|
||||
newPrefsFile.Rename("prefs.js"); /* Rename the file for the Mac only */
|
||||
#else
|
||||
newPrefsFile += "prefs.js";
|
||||
#endif
|
||||
|
||||
newPrefsFile += PREF_FILE_NAME_IN_4x;
|
||||
newPrefsFile.Rename(PREF_FILE_NAME_IN_5x);
|
||||
|
||||
PREF_Init(newPrefsFile);
|
||||
|
||||
|
@ -532,7 +541,7 @@ nsPrefMigration::ComputeMailPath(nsFileSpec oldPath, nsFileSpec *newPath)
|
|||
const char *localMailString="Local Mail"; /* string used for new IMAP dirs */
|
||||
const char *mail = "Mail";
|
||||
|
||||
int nameLength = _MAX_PATH;
|
||||
int nameLength = MAXPATHLEN;
|
||||
char *serverType, *popServerName, *mailPath;
|
||||
|
||||
PREF_GetCharPref("mail.server.type", serverType, &nameLength);
|
||||
|
@ -575,7 +584,7 @@ nsPrefMigration::ComputeMailPath(nsFileSpec oldPath, nsFileSpec *newPath)
|
|||
nsresult
|
||||
nsPrefMigration::GetDirFromPref(char* newProfilePath, char* pref, char* newPath, char* oldPath)
|
||||
{
|
||||
int oldDirLength = _MAX_PATH;
|
||||
int oldDirLength = MAXPATHLEN;
|
||||
PRInt32 foundPref;
|
||||
|
||||
|
||||
|
@ -584,6 +593,16 @@ nsPrefMigration::GetDirFromPref(char* newProfilePath, char* pref, char* newPath,
|
|||
{
|
||||
PL_strcpy(newPath, oldPath);
|
||||
PL_strcat(newPath, "5");
|
||||
|
||||
// save off the old pref, prefixed with "premigration"
|
||||
// for example, we need the old "mail.directory" pref whe migrating
|
||||
// the copies and folder prefs.
|
||||
char *premigration_pref = nsnull;
|
||||
premigration_pref = PR_smprintf("premigration.%s", pref);
|
||||
if (!premigration_pref) return NS_ERROR_FAILURE;
|
||||
PREF_SetCharPref (premigration_pref, oldPath);
|
||||
PR_FREEIF(premigration_pref);
|
||||
|
||||
PREF_SetCharPref (pref, newPath);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -606,7 +625,6 @@ nsPrefMigration::GetDirFromPref(char* newProfilePath, char* pref, char* newPath,
|
|||
nsresult
|
||||
nsPrefMigration::GetSizes(nsFileSpec inputPath, PRBool readSubdirs, PRUint32 *sizeTotal)
|
||||
{
|
||||
int i = 0;
|
||||
char* folderName;
|
||||
nsAutoString fileOrDirNameStr;
|
||||
PRInt32 len;
|
||||
|
@ -711,7 +729,6 @@ nsPrefMigration::CheckForSpace(nsFileSpec newProfilePath, PRFloat64 requiredSpac
|
|||
nsresult
|
||||
nsPrefMigration::DoTheCopy(nsFileSpec oldPath, nsFileSpec newPath, PRBool readSubdirs)
|
||||
{
|
||||
int i = 0;
|
||||
char* folderName;
|
||||
nsAutoString fileOrDirNameStr;
|
||||
|
||||
|
@ -761,13 +778,13 @@ nsPrefMigration::DoSpecialUpdates(nsFileSpec profilePath)
|
|||
const char *headerString="# Mozilla User Preferences ";
|
||||
|
||||
nsFileSpec fs(profilePath);
|
||||
fs += "prefs.js";
|
||||
|
||||
fs += PREF_FILE_NAME_IN_5x;
|
||||
|
||||
nsOutputFileStream fsStream(fs, (PR_WRONLY | PR_CREATE_FILE | PR_APPEND));
|
||||
|
||||
if (!fsStream.is_open())
|
||||
{
|
||||
return -1;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
fsStream << headerString << nsEndl ;
|
||||
|
|
|
@ -13,9 +13,10 @@
|
|||
class nsPrefMigration: public nsIPrefMigration
|
||||
{
|
||||
public:
|
||||
static const nsIID& IID() { static nsIID iid = NS_PrefMigration_CID; return iid; }
|
||||
nsPrefMigration();
|
||||
~nsPrefMigration();
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR(NS_PrefMigration_CID)
|
||||
|
||||
nsPrefMigration();
|
||||
virtual ~nsPrefMigration();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ nsPrefMigrationFactory::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
NS_IMPL_ADDREF(nsPrefMigrationFactory);
|
||||
NS_IMPL_RELEASE(nsPrefMigrationFactory);
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* The PrefMigration CreateInstance Method
|
||||
/* The PrefMigration CreateInstance Method */
|
||||
/*------------------------------------------------------------------------*/
|
||||
NS_IMETHODIMP
|
||||
nsPrefMigrationFactory::CreateInstance(nsISupports *aOuter,
|
||||
|
|
Загрузка…
Ссылка в новой задаче