1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsPrefMigration_h___
39 #define nsPrefMigration_h___
43 #include "nsIFactory.h"
44 #include "nsISupports.h"
45 #include "nsFileSpec.h"
46 #include "nsIPrefBranch.h"
47 #include "nsIServiceManager.h"
49 #include "nsIDOMWindowInternal.h"
50 #include "nsIFileSpec.h"
51 #include "nsPrefMigrationCIDs.h"
52 #include "nsIPrefMigration.h"
53 #include "nsVoidArray.h"
54 #include "nsILocalFile.h"
56 #define MIGRATION_SUCCESS 0
57 #define MIGRATION_RETRY 1
58 #define MIGRATION_CANCEL 2
59 #define MIGRATION_CREATE_NEW 3
65 #if defined(XP_MACOSX)
66 #define IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x "%s Rules"
69 #if defined(XP_UNIX) && !defined(XP_MACOSX)
70 #define NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
73 class nsPrefConverter
: public nsIPrefConverter
76 NS_DEFINE_STATIC_CID_ACCESSOR(NS_PREFCONVERTER_CID
)
79 virtual ~nsPrefConverter();
82 NS_DECL_NSIPREFCONVERTER
84 nsresult
GetPlatformCharset(nsCString
& aCharset
);
87 class nsPrefMigration
: public nsIPrefMigration
90 NS_DEFINE_STATIC_CID_ACCESSOR(NS_PREFMIGRATION_CID
)
92 static nsPrefMigration
*GetInstance();
95 virtual ~nsPrefMigration();
99 NS_DECL_NSIPREFMIGRATION
101 // todo try to move this to private. We need this because we need to call this
104 nsVoidArray mProfilesToMigrate
;
105 nsresult
ProcessPrefsCallback(const char* oldProfilePathStr
, const char * newProfilePathStr
);
106 void WaitForThread();
112 static nsPrefMigration
* mInstance
;
114 nsresult
ConvertPersistentStringToFileSpec(const char *str
, nsIFileSpec
*path
);
115 nsresult
CreateNewUser5Tree(nsIFileSpec
* oldProfilePath
,
116 nsIFileSpec
* newProfilePath
);
118 nsresult
GetDirFromPref(nsIFileSpec
* oldProfilePath
,
119 nsIFileSpec
* newProfilePath
,
120 const char* newDirName
,
122 nsIFileSpec
* newPath
,
123 nsIFileSpec
* oldPath
);
125 nsresult
GetSizes(nsFileSpec inputPath
,
127 PRUint32
* sizeTotal
);
129 nsresult
ComputeSpaceRequirements(PRInt64 DriveArray
[],
130 PRUint32 SpaceReqArray
[],
132 PRUint32 SpaceNeeded
);
134 nsresult
DoTheCopy(nsIFileSpec
*oldPath
,
135 nsIFileSpec
*newPath
,
137 nsresult
DoTheCopy(nsIFileSpec
*oldPath
,
138 nsIFileSpec
*newPath
,
139 const char *fileOrDirName
,
140 PRBool isDirectory
= PR_FALSE
);
142 nsresult
DoTheCopyAndRename(nsIFileSpec
*oldPath
,
143 nsIFileSpec
*newPath
,
145 PRBool needToRenameFiles
,
147 const char *newName
);
148 nsresult
DoTheCopyAndRename(nsIFileSpec
*aPath
,
150 const char *aOldName
,
151 const char *aNewName
);
152 nsresult
CopyFilesByPattern(nsIFileSpec
* oldPathSpec
,
153 nsIFileSpec
* newPathSpec
,
154 const char *pattern
);
157 #ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
158 nsresult
CopyAndRenameNewsrcFiles(nsIFileSpec
*newPath
);
159 #endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
161 nsresult
DoSpecialUpdates(nsIFileSpec
* profilePath
);
162 nsresult
Rename4xFileAfterMigration(nsIFileSpec
*profilePath
, const char *oldFileName
, const char *newFileName
);
163 #ifdef IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x
164 nsresult
RenameAndMove4xImapFilterFile(nsIFileSpec
*profilePath
, const char *hostname
);
165 nsresult
RenameAndMove4xImapFilterFiles(nsIFileSpec
*profilePath
);
166 #endif /* IMAP_MAIL_FILTER_FILE_NAME_FORMAT_IN_4x */
167 nsresult
RenameAndMove4xPopStateFile(nsIFileSpec
*profilePath
);
168 nsresult
RenameAndMove4xPopFilterFile(nsIFileSpec
*profilePath
);
169 nsresult
RenameAndMove4xPopFile(nsIFileSpec
* profilePath
, const char *fileNameIn4x
, const char *fileNameIn5x
);
171 nsresult
DetermineOldPath(nsIFileSpec
*profilePath
, const char *oldPathName
, const char *oldPathEntityName
, nsIFileSpec
*oldPath
);
172 nsresult
SetPremigratedFilePref(const char *pref_name
, nsIFileSpec
*filePath
);
173 #ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES
174 nsresult
GetPremigratedFilePref(const char *pref_name
, nsIFileSpec
**filePath
);
175 #endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */
177 nsresult
getPrefService();
179 nsCOMPtr
<nsIPrefBranch
> m_prefBranch
;
180 nsCOMPtr
<nsILocalFile
> m_prefsFile
;
181 nsCOMPtr
<nsIDOMWindowInternal
> m_parentWindow
;
182 nsCOMPtr
<nsIDOMWindow
> mPMProgressWindow
;
185 #endif /* nsPrefMigration_h___ */