40 #include "nsIBrowserProfileMigrator.h"
41 #include "nsIComponentManager.h"
42 #include "nsIDOMWindowInternal.h"
43 #include "nsILocalFile.h"
44 #include "nsIObserverService.h"
45 #include "nsIProperties.h"
46 #include "nsIServiceManager.h"
47 #include "nsISupportsPrimitives.h"
48 #include "nsISupportsArray.h"
49 #include "nsIToolkitProfile.h"
50 #include "nsIToolkitProfileService.h"
51 #include "nsIWindowWatcher.h"
55 #include "nsComponentManagerUtils.h"
56 #include "nsDirectoryServiceDefs.h"
57 #include "nsServiceManagerUtils.h"
60 #include "nsStringAPI.h"
61 #include "nsUnicharUtils.h"
64 #include "nsIWindowsRegKey.h"
65 #include "nsILocalFileWin.h"
70 #include "nsAutoPtr.h"
74 #define MAXPATHLEN PATH_MAX
75 #elif defined(_MAX_PATH)
76 #define MAXPATHLEN _MAX_PATH
77 #elif defined(CCHMAXPATH)
78 #define MAXPATHLEN CCHMAXPATH
80 #define MAXPATHLEN 1024
87 #define MIGRATION_WIZARD_FE_URL "chrome://browser/content/migration/migration.xul"
88 #define MIGRATION_WIZARD_FE_FEATURES "chrome,dialog,modal,centerscreen,titlebar"
91 nsProfileMigrator::Migrate(nsIProfileStartup* aStartup)
96 nsCOMPtr<nsIBrowserProfileMigrator> bpm;
99 if (NS_FAILED(rv))
return rv;
103 contractID.Append(key);
105 bpm = do_CreateInstance(contractID.get());
106 if (!bpm)
return NS_ERROR_FAILURE;
110 bpm->GetSourceExists(&sourceExists);
118 return NS_ERROR_FAILURE;
122 nsCOMPtr<nsISupportsCString> cstr
123 (do_CreateInstance(
"@mozilla.org/supports-cstring;1"));
124 if (!cstr)
return NS_ERROR_OUT_OF_MEMORY;
129 nsCOMPtr<nsIWindowWatcher>
ww(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
130 nsCOMPtr<nsISupportsArray> params =
131 do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID);
132 if (!ww || !params)
return NS_ERROR_FAILURE;
134 params->AppendElement(cstr);
135 params->AppendElement(bpm);
136 params->AppendElement(aStartup);
138 nsCOMPtr<nsIDOMWindow> migrateWizard;
139 return ww->OpenWindow(nsnull,
144 getter_AddRefs(migrateWizard));
148 nsProfileMigrator::Import()
153 return NS_ERROR_FAILURE;
163 #define INTERNAL_NAME_FIREBIRD "firebird"
164 #define INTERNAL_NAME_FIREFOX "firefox"
165 #define INTERNAL_NAME_PHOENIX "phoenix"
166 #define INTERNAL_NAME_IEXPLORE "iexplore"
167 #define INTERNAL_NAME_MOZILLA_SUITE "apprunner"
168 #define INTERNAL_NAME_SEAMONKEY "seamonkey"
169 #define INTERNAL_NAME_DOGBERT "netscape"
170 #define INTERNAL_NAME_OPERA "opera"
175 nsCOMPtr<nsIBrowserProfileMigrator>& bpm)
179 nsCOMPtr<nsIWindowsRegKey> regKey =
180 do_CreateInstance(
"@mozilla.org/windows-registry-key;1");
182 return NS_ERROR_FAILURE;
184 NS_NAMED_LITERAL_STRING(kCommandKey,
185 "SOFTWARE\\Classes\\HTTP\\shell\\open\\command");
187 if (NS_FAILED(regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
189 return NS_ERROR_FAILURE;
192 if (NS_FAILED(regKey->ReadStringValue(EmptyString(), value)))
193 return NS_ERROR_FAILURE;
195 PRInt32 len = value.Find(NS_LITERAL_STRING(
".exe"), CaseInsensitiveCompare);
197 return NS_ERROR_FAILURE;
204 if (value.get()[1] !=
':') {
209 const nsDependentSubstring filePath(Substring(value, start, len));
233 nsCOMPtr<nsILocalFile> lf;
234 NS_NewLocalFile(filePath, PR_TRUE, getter_AddRefs(lf));
236 return NS_ERROR_FAILURE;
238 nsCOMPtr<nsILocalFileWin> lfw = do_QueryInterface(lf);
240 return NS_ERROR_FAILURE;
242 nsAutoString internalName;
243 if (NS_FAILED(lfw->GetVersionInfoField(
"InternalName", internalName)))
244 return NS_ERROR_FAILURE;
246 if (internalName.LowerCaseEqualsLiteral(INTERNAL_NAME_IEXPLORE)) {
250 if (internalName.LowerCaseEqualsLiteral(INTERNAL_NAME_MOZILLA_SUITE) ||
251 internalName.LowerCaseEqualsLiteral(INTERNAL_NAME_SEAMONKEY)) {
255 if (internalName.LowerCaseEqualsLiteral(INTERNAL_NAME_DOGBERT)) {
259 if (internalName.LowerCaseEqualsLiteral(INTERNAL_NAME_OPERA)) {
265 if (internalName.LowerCaseEqualsLiteral(INTERNAL_NAME_FIREBIRD) ||
266 internalName.LowerCaseEqualsLiteral(INTERNAL_NAME_FIREFOX) ||
267 internalName.LowerCaseEqualsLiteral(INTERNAL_NAME_PHOENIX)) {
272 PRBool exists = PR_FALSE;
273 #define CHECK_MIGRATOR(browser) do {\
274 bpm = do_CreateInstance(NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX browser);\
276 bpm->GetSourceExists(&exists);\
282 #if defined(XP_MACOSX)
290 #undef CHECK_MIGRATOR
292 return NS_ERROR_FAILURE;
300 nsCOMPtr<nsIToolkitProfileService> profileSvc
301 (do_GetService(NS_PROFILESERVICE_CONTRACTID));
302 NS_ENSURE_TRUE(profileSvc, NS_ERROR_FAILURE);
304 nsCOMPtr<nsIProperties> dirService
305 (do_GetService(
"@mozilla.org/file/directory_service;1"));
306 NS_ENSURE_TRUE(dirService, NS_ERROR_FAILURE);
308 nsCOMPtr<nsILocalFile> regFile;
310 rv = dirService->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile),
311 getter_AddRefs(regFile));
312 NS_ENSURE_SUCCESS(rv, PR_FALSE);
313 regFile->AppendNative(aAppName);
314 regFile->AppendNative(NS_LITERAL_CSTRING(
"registry.dat"));
315 #elif defined(XP_MACOSX)
316 rv = dirService->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile),
317 getter_AddRefs(regFile));
318 NS_ENSURE_SUCCESS(rv, PR_FALSE);
319 regFile->AppendNative(aAppName);
320 regFile->AppendNative(NS_LITERAL_CSTRING(
"Application Registry"));
321 #elif defined(XP_OS2)
322 rv = dirService->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile),
323 getter_AddRefs(regFile));
324 NS_ENSURE_SUCCESS(rv, PR_FALSE);
325 regFile->AppendNative(aAppName);
326 regFile->AppendNative(NS_LITERAL_CSTRING(
"registry.dat"));
327 #elif defined(XP_BEOS)
328 rv = dirService->Get(NS_BEOS_SETTINGS_DIR, NS_GET_IID(nsILocalFile),
329 getter_AddRefs(regFile));
330 NS_ENSURE_SUCCESS(rv, PR_FALSE);
331 regFile->AppendNative(aAppName);
332 regFile->AppendNative(NS_LITERAL_CSTRING(
"appreg"));
334 rv = dirService->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile),
335 getter_AddRefs(regFile));
336 NS_ENSURE_SUCCESS(rv, PR_FALSE);
337 nsCAutoString dotAppName;
338 ToLowerCase(aAppName, dotAppName);
339 dotAppName.Insert(
'.', 0);
341 regFile->AppendNative(dotAppName);
342 regFile->AppendNative(NS_LITERAL_CSTRING(
"appreg"));
346 rv = regFile->GetNativePath(path);
347 NS_ENSURE_SUCCESS(rv, PR_FALSE);
349 if (NR_StartupRegistry())
352 PRBool migrated = PR_FALSE;
355 REGENUM enumstate = 0;
356 char profileName[MAXREGNAMELEN];
358 if (NR_RegOpen(path.get(), ®))
361 if (NR_RegGetKey(reg, ROOTKEY_COMMON,
"Profiles", &profiles))
364 while (!NR_RegEnumSubkeys(reg, profiles, &enumstate,
365 profileName, MAXREGNAMELEN, REGENUM_CHILDREN)) {
366 #ifdef DEBUG_bsmedberg
367 printf(
"Found profile %s.\n", profileName);
371 if (NR_RegGetKey(reg, profiles, profileName, &profile)) {
372 NS_ERROR(
"Could not get the key that was enumerated.");
377 if (NR_RegGetEntryString(reg, profile,
"directory",
381 nsCOMPtr<nsILocalFile> profileFile
382 (do_CreateInstance(
"@mozilla.org/file/local;1"));
386 #if defined (XP_MACOSX)
387 rv = profileFile->SetPersistentDescriptor(nsDependentCString(profilePath));
389 NS_ConvertUTF8toUTF16 widePath(profilePath);
390 rv = profileFile->InitWithPath(widePath);
392 if (NS_FAILED(rv))
continue;
394 nsCOMPtr<nsIToolkitProfile> tprofile;
395 profileSvc->CreateProfile(profileFile, nsnull,
396 nsDependentCString(profileName),
397 getter_AddRefs(tprofile));
404 NR_ShutdownRegistry();
#define MIGRATION_WIZARD_FE_FEATURES
#define CHECK_MIGRATOR(browser)
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
nsresult GetDefaultBrowserMigratorKey(nsACString &key, nsCOMPtr< nsIBrowserProfileMigrator > &bpm)
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
PRBool ImportRegistryProfiles(const nsACString &aAppName)
#define NS_BROWSERPROFILEMIGRATOR_CONTRACTID_PREFIX
#define MIGRATION_WIZARD_FE_URL