Back to index

lightning-sunbird  0.9+nobinonly
nsDogbertProfileMigrator.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 The Communicator 4.x Mail Migrator Code
00016  *
00017  * The Initial Developer of the Original Code is Scott MacGregor.
00018  * Portions created by the Initial Developer are Copyright (C) 2004
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *  Scott MacGregor <mscott@mozilla.org>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * 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 dogbertprofilemigrator___h___
00039 #define dogbertprofilemigrator___h___
00040 
00041 #include "nsIMailProfileMigrator.h"
00042 #include "nsILocalFile.h"
00043 #include "nsIObserverService.h"
00044 #include "nsISupportsArray.h"
00045 #include "nsNetscapeProfileMigratorBase.h"
00046 #include "nsString.h"
00047 #include "nsITimer.h"
00048 
00049 #include "nsIPref.h"
00050 
00051 class nsIFile;
00052 class nsIPrefBranch;
00053 class nsIPrefService;
00054 class nsIFileSpec;
00055 class nsFileSpec;
00056 
00057 // ripped off from nsPrefMigration, warts and all
00058 
00059 #define MIGRATION_SUCCESS    0
00060 #define MIGRATION_RETRY      1
00061 #define MIGRATION_CANCEL     2
00062 #define MIGRATION_CREATE_NEW 3
00063 
00064 #define MAX_DRIVES 4
00065 
00066 //Interfaces Needed
00067 
00068 #if defined(XP_MAC) || defined(XP_MACOSX)
00069 #define IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x "%s Rules" 
00070 #endif
00071 
00072 #if defined(XP_UNIX) && !defined(XP_MACOSX)
00073 #define NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
00074 #endif
00075 
00076 class nsPrefConverter
00077 {
00078 public:
00079   nsPrefConverter();
00080   virtual ~nsPrefConverter();
00081   nsresult ConvertPrefsToUTF8();
00082   nsresult GetPlatformCharset(nsCString& aCharset);
00083 };
00084 
00085 class nsDogbertProfileMigrator :   public nsNetscapeProfileMigratorBase, 
00086                                    public nsIMailProfileMigrator,
00087                                    public nsITimerCallback
00088 {
00089 public:
00090   NS_DECL_NSIMAILPROFILEMIGRATOR
00091   NS_DECL_ISUPPORTS
00092   NS_DECL_NSITIMERCALLBACK
00093 
00094   nsDogbertProfileMigrator();
00095   virtual ~nsDogbertProfileMigrator();
00096 
00097 protected:
00098   void GetSourceProfile(const PRUnichar* aProfile);
00099 
00100   nsresult CopyPreferences();
00101 
00102 private:
00103   nsCOMPtr<nsISupportsArray> mProfiles;
00104   nsCOMPtr<nsISupportsArray> mProfileLocations;
00105   nsCOMPtr<nsIObserverService> mObserverService;
00106   nsCOMPtr<nsITimer> mFileIOTimer;
00107 
00108   PRInt64 mMaxProgress;
00109   PRInt64 mCurrentProgress;
00110   
00111   nsCOMPtr<nsIPref> mPrefs;
00112   nsCOMPtr<nsILocalFile> m_prefsFile;
00113 protected:
00114   nsresult ProcessPrefsCallback(const char* oldProfilePathStr, const char * newProfilePathStr);
00115   nsresult ConvertPersistentStringToFileSpec(const char *str, nsIFileSpec *path);
00116   nsresult CreateNewUser5Tree(nsIFileSpec* oldProfilePath, 
00117                               nsIFileSpec* newProfilePath);
00118 
00119   nsresult GetDirFromPref(nsIFileSpec* oldProfilePath,
00120                           nsIFileSpec* newProfilePath, 
00121                           const char* newDirName,
00122                           const char* pref, 
00123                           nsIFileSpec* newPath, 
00124                           nsIFileSpec* oldPath);
00125 
00126   nsresult GetSizes(nsFileSpec inputPath,
00127                     PRBool readSubdirs,
00128                     PRUint32* sizeTotal);
00129 
00130   nsresult ComputeSpaceRequirements(PRInt64 DriveArray[], 
00131                                     PRUint32 SpaceReqArray[], 
00132                                     PRInt64 Drive, 
00133                                     PRUint32 SpaceNeeded);
00134 
00135   nsresult DoTheCopy(nsIFileSpec *oldPath, 
00136                      nsIFileSpec *newPath,
00137                      PRBool readSubdirs); 
00138   nsresult DoTheCopy(nsIFileSpec *oldPath,
00139                      nsIFileSpec *newPath,
00140                      const char *fileOrDirName,
00141                      PRBool isDirectory = PR_FALSE);
00142 
00143   nsresult DoTheCopyAndRename(nsIFileSpec *oldPath, 
00144                           nsIFileSpec *newPath,
00145                           PRBool readSubdirs,
00146                           PRBool needToRenameFiles,
00147                           const char *oldName,
00148                           const char *newName); 
00149   nsresult DoTheCopyAndRename(nsIFileSpec *aPath, 
00150                           PRBool aReadSubdirs,
00151                           const char *aOldName,
00152                           const char *aNewName);
00153   nsresult CopyFilesByPattern(nsIFileSpec * oldPathSpec,
00154                           nsIFileSpec * newPathSpec,
00155                           const char *pattern);
00156 
00157   nsresult AddFileCopyToList(nsFileSpec * aOldPath, nsFileSpec * aNewPath, const char * newFileName);
00158   void CopyNextFolder();
00159   void EndCopyFolders();
00160 
00161 #ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
00162   nsresult CopyAndRenameNewsrcFiles(nsIFileSpec *newPath);
00163 #endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
00164 
00165   nsresult DoSpecialUpdates(nsIFileSpec * profilePath);
00166   nsresult Rename4xFileAfterMigration(nsIFileSpec *profilePath, const char *oldFileName, const char *newFileName);
00167 #ifdef IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x
00168   nsresult RenameAndMove4xImapFilterFile(nsIFileSpec *profilePath, const char *hostname);
00169   nsresult RenameAndMove4xImapFilterFiles(nsIFileSpec *profilePath);
00170 #endif /* IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x */
00171   nsresult RenameAndMove4xPopStateFile(nsIFileSpec *profilePath);
00172   nsresult RenameAndMove4xPopFilterFile(nsIFileSpec *profilePath);
00173   nsresult RenameAndMove4xPopFile(nsIFileSpec * profilePath, const char *fileNameIn4x, const char *fileNameIn5x);
00174   
00175   nsresult DetermineOldPath(nsIFileSpec *profilePath, const char *oldPathName, const char *oldPathEntityName, nsIFileSpec *oldPath);
00176   nsresult SetPremigratedFilePref(const char *pref_name, nsIFileSpec *filePath);
00177 #ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
00178   nsresult GetPremigratedFilePref(const char *pref_name, nsIFileSpec **filePath);
00179 #endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
00180 };
00181 
00182 #endif