nsresult errorCode; errorCode = pPrefMigrator->GetError();
rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key);
nsProfile::MigrateProfile(const PRUnichar* profileName, PRBool showProgressAsModalWindow){    NS_ENSURE_ARG_POINTER(profileName);       nsresult rv = NS_OK;#if defined(DEBUG_profile)    printf("Inside Migrate Profile routine.\n" );#endif    nsCOMPtr<nsIFile> oldProfDir;        nsCOMPtr<nsIFile> newProfDir;     rv = GetProfileDir(profileName, getter_AddRefs(oldProfDir));    if (NS_FAILED(rv)) return rv;       rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, getter_AddRefs(newProfDir));    if (NS_FAILED(rv)) return rv;    rv = newProfDir->AppendUnicode(profileName);    if (NS_FAILED(rv)) return rv;        // This is unfortunate: There is no CreateUniqueUnicode    nsXPIDLCString suggestedName;    rv = newProfDir->GetLeafName(getter_Copies(suggestedName));    if (NS_FAILED(rv)) return rv;    rv = newProfDir->CreateUnique(suggestedName, nsIFile::DIRECTORY_TYPE, 0775);    if (NS_FAILED(rv)) return rv;        // always create level indirection when migrating    rv = AddLevelOfIndirection(newProfDir);    if (NS_FAILED(rv)) return rv;    // Call migration service to do the work.    nsCOMPtr <nsIPrefMigration> pPrefMigrator;    rv = nsComponentManager::CreateInstance(kPrefMigrationCID,                                             nsnull,                                            NS_GET_IID(nsIPrefMigration),                                            getter_AddRefs(pPrefMigrator));    if (NS_FAILED(rv)) return rv;    if (!pPrefMigrator) return NS_ERROR_FAILURE;            nsCOMPtr<nsILocalFile> oldProfDirLocal(do_QueryInterface(oldProfDir, &rv));    if (NS_FAILED(rv)) return rv;        nsCOMPtr<nsILocalFile> newProfDirLocal(do_QueryInterface(newProfDir, &rv));    if (NS_FAILED(rv)) return rv;            nsXPIDLCString oldProfDirStr;    nsXPIDLCString newProfDirStr;    rv = oldProfDirLocal->GetPersistentDescriptor(getter_Copies(oldProfDirStr));    if (NS_FAILED(rv)) return rv;    rv = newProfDirLocal->GetPersistentDescriptor(getter_Copies(newProfDirStr));    if (NS_FAILED(rv)) return rv;    // you can do this a bunch of times.    rv = pPrefMigrator->AddProfilePaths(oldProfDirStr, newProfDirStr);      rv = pPrefMigrator->ProcessPrefs(showProgressAsModalWindow);    if (NS_FAILED(rv)) return rv;    // check for diskspace errors      nsresult errorCode;       errorCode = pPrefMigrator->GetError();    // In either of the cases below we have to return error to make    // app understand that migration has failed.    if (errorCode == CREATE_NEW)    {        PRInt32 numProfiles = 0;        ShowProfileWizard();        // When the automigration process fails because of disk space error,        // we present user a create profile wizard if the user chooses to create a         // a profile then. But then the user may click on cancel on that dialog...        // So, if the user clicks on cancel, the number of profiles should be         // ZERO at the point for the user who failed to automigrate single 4x profile.        // On such condition, set mDiskSpaceErrorQuitCalled to allow user to quit the app.        // If the user is presented with profilemanager dialog with multiple 4x profiles        // to migrate, value of mDiskSpaceErrorQuitCalled does not matter as it gets ignored..        // If a single profile needs automigration and no confirmation         // is needed for that operation mAutomigrate is set to false.         if (!mAutomigrate)        {            GetProfileCount(&numProfiles);            if (numProfiles == 0)                mDiskSpaceErrorQuitCalled = PR_TRUE;        }        mOutofDiskSpace = PR_TRUE;        return NS_ERROR_FAILURE;    }    else if (errorCode == CANCEL)     {        // When the automigration process fails because of disk space error,        // user may choose to simply quit the app from the dialog presented         // by pref-migrator. So, set mDiskSpaceErrorQuitCalled to allow user         // to quit the app in such a case.        // If the user is presented with profilemanager dialog with multiple 4x profiles        // to migrate, value of mDiskSpaceErrorQuitCalled does not matter as it gets ignored..        // If a single profile needs automigration and no confirmation         // is needed for that operation mAutomigrate is set to false.         if (!mAutomigrate)            mDiskSpaceErrorQuitCalled = PR_TRUE;        ForgetCurrentProfile();        mOutofDiskSpace = PR_TRUE;        return NS_ERROR_FAILURE;    }    else if (errorCode != SUCCESS)     {        return NS_ERROR_FAILURE;    }    // Copy the default 5.0 profile files into the migrated profile    // Get profile defaults folder..    nsCOMPtr<nsIFile> profDefaultsDir;    rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(profDefaultsDir));    if (NS_FAILED(rv)) return rv;    // Copy panels.rdf, localstore.rdf & mimeTypes.rdf files    // This is a hack. Once the localFileSpec implementation    // is complete, this will be removed.	rv = CopyDefaultFile(profDefaultsDir, newProfDir, LOCALSTORE_RDF_FILE);	if (NS_FAILED(rv)) return rv;	rv = CopyDefaultFile(profDefaultsDir, newProfDir, PANELS_RDF_FILE);	if (NS_FAILED(rv)) return rv;	rv = CopyDefaultFile(profDefaultsDir, newProfDir, MIMETYPES_RDF_FILE);	NS_ASSERTION(NS_SUCCEEDED(rv), "failed to copy default mimeTypes.rdf file");    // hack finish.	    rv = SetProfileDir(profileName, newProfDir);    if (NS_FAILED(rv)) return rv;    gProfileDataAccess->mNumProfiles++;    gProfileDataAccess->mNumOldProfiles--;    gProfileDataAccess->mProfileDataChanged = PR_TRUE;    gProfileDataAccess->UpdateRegistry(nsnull);    return rv;}