Bug 62418 - mozilla starts without warning when profile dir is missing. r=racham@netscape.com,sr=sspitzer@netscape.com

This commit is contained in:
ccarlen%netscape.com 2001-04-27 14:40:21 +00:00
Родитель 3f56a22520
Коммит a3a44ebd54
5 изменённых файлов: 77 добавлений и 100 удалений

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsIProfile.idl"
interface nsICmdLineService;
interface nsIFile;
[scriptable, uuid(2f977d42-5485-11d4-87e2-0010a4e75ef2)]
interface nsIProfileInternal : nsIProfile {
@ -53,16 +54,9 @@ interface nsIProfileInternal : nsIProfile {
void migrateAllProfiles();
void migrateProfile(in wstring profileName, in boolean showProgressAsModalWindow);
void forgetCurrentProfile();
/**
* The following 3 methods are deprecated. DO NOT USE THEM.
*/
boolean isCurrentProfileAvailable();
[noscript] void getProfileDir(in wstring profileName,
out nsIFile profileDir);
[noscript] void getCurrentProfileDir(out nsIFile profileDir);
nsIFile getProfileDir(in wstring profileName);
attribute boolean automigrate;
readonly attribute nsIFile defaultProfileParentDir;
readonly attribute wstring firstProfile;
@ -73,8 +67,14 @@ interface nsIProfileInternal : nsIProfile {
in wstring regName,
in wstring regEmail,
in wstring regOption);
[noscript] string isRegStringSet(in wstring profileName);
[noscript] string isRegStringSet(in wstring profileName);
/**
* The remaining methods are deprecated. DO NOT USE THEM.
*/
boolean isCurrentProfileAvailable();
[noscript] void getCurrentProfileDir(out nsIFile profileDir);
};
#endif /* nsIProfileInternal_h__ */

Просмотреть файл

@ -187,6 +187,25 @@ function onStart()
ioService.offline = offlineState.checked;
try {
var dirExists;
try {
var profileDir = profile.getProfileDir(profilename);
dirExists = profileDir.exists();
}
catch (e) {
dirExists = false;
}
if (dirExists == false) {
var brandName = gBrandBundle.getString("brandShortName");
var alertString = gProfileManagerBundle.getFormattedString("profDirMissing", [brandName, profilename]);
alertString = alertString.replace(/\s*<html:br\/>/g,"\n");
alert(alertString);
return;
}
profile.startApprunner(profilename);
ExitApp();
}

Просмотреть файл

@ -1,4 +1,4 @@
# LOCALIZATION NOTE: Do not translate <html:br/>
migratebeforerename=The profile you selected was created with a previous version of Netscape and must be copied and converted to a %brandShortName% profile before it can be renamed.<html:br/><html:br/> Do you want to convert this profile?<html:br/><html:br/>
migratebeforedelete=The profile you selected was created with a previous version of Netscape. %brandShortName% can remove this profile from the list of profiles that it maintains but you must remove it from your system using the version of Netscape that created it, or by hand.<html:br/><html:br/> Do you want to remove this profile from the list of profiles?<html:br/><html:br/>
migratebeforestart=The profile you selected was created with a previous version of Netscape and must be copied and converted before you can use it with %brandShortName%.<html:br/><html:br/> Your original 4.x profile will not be altered. <html:br/><html:br/> Do you want to copy and convert this profile?
@ -27,3 +27,4 @@ invalidCharB="<html:br/><html:br/>Please choose a different name for the profile
profileExists=A profile with this name already exists. Please choose another name.
profileExistsTitle=Profile Exists
profDirMissing=%S cannot use the profile "%S" because the directory containing the profile cannot be found.<html:br/><html:br/> Please choose another profile or create a new one.

Просмотреть файл

@ -452,7 +452,19 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
if (NS_FAILED(rv)) return rv;
// Will get set in call to SetCurrentProfile() below
}
else if (numProfiles > 1)
else if (numProfiles == 1)
{
// Make sure the profile dir exists. If not, we need the UI
nsCOMPtr<nsIFile> curProfileDir;
PRBool exists;
rv = GetCurrentProfileDir(getter_AddRefs(curProfileDir));
if (NS_SUCCEEDED(rv))
rv = curProfileDir->Exists(&exists);
if (NS_FAILED(rv) || !exists)
profileURLStr = PROFILE_MANAGER_URL;
}
else
profileURLStr = PROFILE_SELECTION_URL;
}
@ -823,8 +835,9 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
// Sets the given profile to be a current profile
NS_IMETHODIMP nsProfile::GetProfileDir(const PRUnichar *profileName, nsIFile **profileDir)
{
NS_ENSURE_ARG_POINTER(profileName);
NS_ENSURE_ARG(profileName);
NS_ENSURE_ARG_POINTER(profileDir);
*profileDir = nsnull;
nsresult rv = NS_OK;
@ -841,94 +854,32 @@ NS_IMETHODIMP nsProfile::GetProfileDir(const PRUnichar *profileName, nsIFile **p
return NS_ERROR_FAILURE;
nsCOMPtr<nsILocalFile>aProfileDir;
(void)aProfile->GetResolvedProfileDir(getter_AddRefs(aProfileDir));
// Set this to be a current profile only if it is a 5.0 profile
if (aProfile->isMigrated)
rv = aProfile->GetResolvedProfileDir(getter_AddRefs(aProfileDir));
if (NS_SUCCEEDED(rv) && aProfileDir)
{
gProfileDataAccess->SetCurrentProfile(profileName);
PRBool exists = PR_FALSE;
if (aProfileDir)
{
rv = aProfileDir->Exists(&exists);
if (NS_FAILED(rv)) return rv;
#ifdef XP_MAC
if (exists)
{
PRBool inTrash;
nsCOMPtr<nsIFile> trashFolder;
PRBool exists;
rv = aProfileDir->Exists(&exists);
if (NS_FAILED(rv)) return rv;
if (exists) {
PRBool inTrash;
nsCOMPtr<nsIFile> trashFolder;
rv = NS_GetSpecialDirectory(NS_MAC_TRASH_DIR, getter_AddRefs(trashFolder));
if (NS_FAILED(rv)) return rv;
rv = trashFolder->Contains(aProfileDir, PR_TRUE, &inTrash);
if (NS_FAILED(rv)) return rv;
if (inTrash)
aProfileDir = nsnull; // Reset it - we'll make a new one
}
#endif
rv = NS_GetSpecialDirectory(NS_MAC_TRASH_DIR, getter_AddRefs(trashFolder));
if (NS_FAILED(rv)) return rv;
rv = trashFolder->Contains(aProfileDir, PR_TRUE, &inTrash);
if (NS_FAILED(rv)) return rv;
if (inTrash) {
aProfileDir = nsnull;
rv = NS_ERROR_FILE_NOT_FOUND;
}
}
if (!aProfileDir || !exists)
{
// NEEDS IMPROVEMENT: Here we are creating a new profile dir for a missing one and
// we're not even telling the user about this!! What if they moved it, had it on a ZIP
// drive which is not mounted, etc. 4.x at least used to prompt the user to find it.
if (!aProfileDir) {
// Create the directory in the default location
// Since we're copying to default location - make it unique
nsCOMPtr<nsIFile> tempFile;
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, getter_AddRefs(tempFile));
if (NS_FAILED(rv)) return rv;
aProfileDir = do_QueryInterface(tempFile, &rv);
if (NS_FAILED(rv)) return rv;
aProfileDir->AppendUnicode(profileName);
nsXPIDLCString suggestedName;
rv = aProfileDir->GetLeafName(getter_Copies(suggestedName));
if (NS_FAILED(rv)) return rv;
rv = aProfileDir->CreateUnique(suggestedName, nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
}
else if (!exists) {
// Simply create the directory where the file specifies
// We have a valid file spec in a given location - don't CreateUnique
rv = aProfileDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
}
// creating a new profile, add the indirection
rv = AddLevelOfIndirection(aProfileDir);
if (NS_FAILED(rv)) return rv;
// since we might be changing the location of
// profile dir, reset it in the registry.
// see bug #56002 for details
rv = SetProfileDir(profileName, aProfileDir);
if (NS_FAILED(rv)) return rv;
// update the registry
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
gProfileDataAccess->UpdateRegistry(nsnull);
// Copy contents from defaults folder.
nsCOMPtr<nsIFile> profDefaultsDir;
rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(profDefaultsDir));
if (NS_FAILED(rv)) return rv;
rv = profDefaultsDir->Exists(&exists);
if (NS_SUCCEEDED(rv) && exists)
rv = RecursiveCopy(profDefaultsDir, aProfileDir);
}
}
*profileDir = aProfileDir;
NS_ADDREF(*profileDir);
delete aProfile;
#endif
*profileDir = aProfileDir;
NS_IF_ADDREF(*profileDir);
}
delete aProfile;
return rv;
}
NS_IMETHODIMP nsProfile::GetDefaultProfileParentDir(nsIFile **aDefaultProfileParentDir)
@ -992,10 +943,15 @@ nsProfile::SetCurrentProfile(const PRUnichar * aCurrentProfile)
NS_ENSURE_ARG(aCurrentProfile);
nsresult rv;
nsCOMPtr<nsIFile> profileDir;
PRBool exists;
rv = ProfileExists(aCurrentProfile, &exists);
// Ensure that the profile exists and its directory too.
rv = GetProfileDir(aCurrentProfile, getter_AddRefs(profileDir));
if (NS_FAILED(rv)) return rv;
if (!exists) return NS_ERROR_FAILURE;
rv = profileDir->Exists(&exists);
if (NS_FAILED(rv)) return rv;
if (!exists) return NS_ERROR_FILE_NOT_FOUND;
PRBool isSwitch;

Просмотреть файл

@ -1266,8 +1266,9 @@ nsresult ProfileStruct::GetResolvedProfileDir(nsILocalFile **aDirectory)
{
*aDirectory = resolvedLocation;
NS_ADDREF(*aDirectory);
return NS_OK;
}
return NS_OK;
return NS_ERROR_FAILURE;
}
nsresult ProfileStruct::SetResolvedProfileDir(nsILocalFile *aDirectory)