Back to index

lightning-sunbird  0.9+nobinonly
nsPrefMigration.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsPrefMigration_h___
00039 #define nsPrefMigration_h___
00040 
00041 
00042 #include "nscore.h"
00043 #include "nsIFactory.h"
00044 #include "nsISupports.h"
00045 #include "nsFileSpec.h"
00046 #include "nsIPref.h"
00047 #include "nsIServiceManager.h"
00048 #include "nsCOMPtr.h"
00049 #include "nsIDOMWindowInternal.h"
00050 #include "nsIFileSpec.h"
00051 #include "nsPrefMigrationCIDs.h"
00052 #include "nsIPrefMigration.h"
00053 #include "nsVoidArray.h"
00054 #include "nsILocalFile.h"
00055 
00056 #define MIGRATION_SUCCESS    0
00057 #define MIGRATION_RETRY      1
00058 #define MIGRATION_CANCEL     2
00059 #define MIGRATION_CREATE_NEW 3
00060 
00061 #define MAX_DRIVES 4
00062 
00063 //Interfaces Needed
00064 
00065 #if defined(XP_MAC) || defined(XP_MACOSX)
00066 #define IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x "%s Rules" 
00067 #endif
00068 
00069 #if defined(XP_UNIX) && !defined(XP_MACOSX)
00070 #define NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
00071 #endif
00072 
00073 class nsPrefConverter: public nsIPrefConverter
00074 {
00075     public:
00076       NS_DEFINE_STATIC_CID_ACCESSOR(NS_PREFCONVERTER_CID) 
00077 
00078       nsPrefConverter();
00079       virtual ~nsPrefConverter();
00080 
00081       NS_DECL_ISUPPORTS
00082       NS_DECL_NSIPREFCONVERTER
00083 
00084       nsresult GetPlatformCharset(nsCString& aCharset);
00085 };
00086 
00087 class nsPrefMigration: public nsIPrefMigration
00088 {
00089     public:
00090       NS_DEFINE_STATIC_CID_ACCESSOR(NS_PREFMIGRATION_CID) 
00091 
00092       static nsPrefMigration *GetInstance();
00093 
00094       nsPrefMigration();
00095       virtual ~nsPrefMigration();
00096 
00097       NS_DECL_ISUPPORTS
00098 
00099       NS_DECL_NSIPREFMIGRATION
00100 
00101       // todo try to move this to private.  We need this because we need to call this
00102       // from a thread.
00103 
00104       nsVoidArray mProfilesToMigrate;
00105       nsresult ProcessPrefsCallback(const char* oldProfilePathStr, const char * newProfilePathStr);
00106       void WaitForThread();
00107 
00108       nsresult mErrorCode;
00109 
00110     private:
00111       
00112       static nsPrefMigration* mInstance;
00113        
00114       nsresult ConvertPersistentStringToFileSpec(const char *str, nsIFileSpec *path);
00115       nsresult CreateNewUser5Tree(nsIFileSpec* oldProfilePath, 
00116                                   nsIFileSpec* newProfilePath);
00117 
00118       nsresult GetDirFromPref(nsIFileSpec* oldProfilePath,
00119                               nsIFileSpec* newProfilePath, 
00120                               const char* newDirName,
00121                               const char* pref, 
00122                               nsIFileSpec* newPath, 
00123                               nsIFileSpec* oldPath);
00124 
00125       nsresult GetSizes(nsFileSpec inputPath,
00126                         PRBool readSubdirs,
00127                         PRUint32* sizeTotal);
00128 
00129       nsresult ComputeSpaceRequirements(PRInt64 DriveArray[], 
00130                                         PRUint32 SpaceReqArray[], 
00131                                         PRInt64 Drive, 
00132                                         PRUint32 SpaceNeeded);
00133 
00134       nsresult DoTheCopy(nsIFileSpec *oldPath, 
00135                          nsIFileSpec *newPath,
00136                          PRBool readSubdirs); 
00137       nsresult DoTheCopy(nsIFileSpec *oldPath,
00138                          nsIFileSpec *newPath,
00139                          const char *fileOrDirName,
00140                          PRBool isDirectory = PR_FALSE);
00141 
00142       nsresult DoTheCopyAndRename(nsIFileSpec *oldPath, 
00143                               nsIFileSpec *newPath,
00144                               PRBool readSubdirs,
00145                               PRBool needToRenameFiles,
00146                               const char *oldName,
00147                               const char *newName); 
00148       nsresult DoTheCopyAndRename(nsIFileSpec *aPath, 
00149                               PRBool aReadSubdirs,
00150                               const char *aOldName,
00151                               const char *aNewName);
00152       nsresult CopyFilesByPattern(nsIFileSpec * oldPathSpec,
00153                               nsIFileSpec * newPathSpec,
00154                               const char *pattern);
00155 
00156 
00157 #ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
00158       nsresult CopyAndRenameNewsrcFiles(nsIFileSpec *newPath);
00159 #endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
00160 
00161       nsresult DoSpecialUpdates(nsIFileSpec * profilePath);
00162       nsresult Rename4xFileAfterMigration(nsIFileSpec *profilePath, const char *oldFileName, const char *newFileName);
00163 #ifdef IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x
00164       nsresult RenameAndMove4xImapFilterFile(nsIFileSpec *profilePath, const char *hostname);
00165       nsresult RenameAndMove4xImapFilterFiles(nsIFileSpec *profilePath);
00166 #endif /* IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x */
00167       nsresult RenameAndMove4xPopStateFile(nsIFileSpec *profilePath);
00168       nsresult RenameAndMove4xPopFilterFile(nsIFileSpec *profilePath);
00169       nsresult RenameAndMove4xPopFile(nsIFileSpec * profilePath, const char *fileNameIn4x, const char *fileNameIn5x);
00170   
00171       nsresult DetermineOldPath(nsIFileSpec *profilePath, const char *oldPathName, const char *oldPathEntityName, nsIFileSpec *oldPath);
00172       nsresult SetPremigratedFilePref(const char *pref_name, nsIFileSpec *filePath);
00173 #ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
00174       nsresult GetPremigratedFilePref(const char *pref_name, nsIFileSpec **filePath);
00175 #endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
00176 
00177       nsresult getPrefService();
00178 
00179       nsCOMPtr<nsIPref>         m_prefs;
00180       nsCOMPtr<nsILocalFile>     m_prefsFile; 
00181       nsCOMPtr<nsIDOMWindowInternal>    m_parentWindow;
00182       nsCOMPtr<nsIDOMWindow>    mPMProgressWindow;
00183 };
00184 
00185 #endif /* nsPrefMigration_h___ */