char *dummy;
const char *dummy;
SelectProfile(nsIProfileLock* *aResult, nsINativeAppSupport* aNative,              PRBool* aStartOffline){  nsresult rv;  ArgResult ar;  const char* arg;  *aResult = nsnull;  *aStartOffline = PR_FALSE;  arg = PR_GetEnv("XRE_START_OFFLINE");  if ((arg && *arg) || CheckArg("offline"))    *aStartOffline = PR_TRUE;  arg = PR_GetEnv("XRE_PROFILE_PATH");  if (arg && *arg) {    nsCOMPtr<nsILocalFile> lf;    rv = NS_NewNativeLocalFile(nsDependentCString(arg), PR_TRUE,                               getter_AddRefs(lf));    NS_ENSURE_SUCCESS(rv, rv);    nsCOMPtr<nsILocalFile> localDir;    arg = PR_GetEnv("XRE_PROFILE_LOCAL_PATH");    if (arg && *arg) {      rv = NS_NewNativeLocalFile(nsDependentCString(arg), PR_TRUE,                                 getter_AddRefs(localDir));      NS_ENSURE_SUCCESS(rv, rv);    } else {      localDir = lf;    }    // Clear out flags that we handled (or should have handled!) last startup.    char *dummy;    CheckArg("p", &dummy);    CheckArg("profile", &dummy);    CheckArg("profilemanager", &dummy);    return NS_LockProfilePath(lf, localDir, nsnull, aResult);  }  if (CheckArg("migration"))    gDoMigration = PR_TRUE;  ar = CheckArg("profile", &arg);  if (ar == ARG_BAD) {    PR_fprintf(PR_STDERR, "Error: argument -profile requires a path\n");    return NS_ERROR_FAILURE;  }  if (ar) {    nsCOMPtr<nsILocalFile> lf;    rv = XRE_GetFileFromPath(arg, getter_AddRefs(lf));    NS_ENSURE_SUCCESS(rv, rv);    nsCOMPtr<nsIProfileUnlocker> unlocker;    // If a profile path is specified directory on the command line, then    // assume that the temp directory is the same as the given directory.    rv = NS_LockProfilePath(lf, lf, getter_AddRefs(unlocker), aResult);    if (NS_SUCCEEDED(rv))      return rv;    return ProfileLockedDialog(lf, lf, unlocker, aNative, aResult);  }  nsCOMPtr<nsIToolkitProfileService> profileSvc;  rv = NS_NewToolkitProfileService(getter_AddRefs(profileSvc));  NS_ENSURE_SUCCESS(rv, rv);  ar = CheckArg("createprofile", &arg);  if (ar == ARG_BAD) {    PR_fprintf(PR_STDERR, "Error: argument -createprofile requires a profile name\n");    return NS_ERROR_FAILURE;  }  if (ar) {    nsCOMPtr<nsIToolkitProfile> profile;    const char* delim = strchr(arg, ' ');    if (delim) {      nsCOMPtr<nsILocalFile> lf;      rv = NS_NewNativeLocalFile(nsDependentCString(delim + 1),                                   PR_TRUE, getter_AddRefs(lf));      if (NS_FAILED(rv)) {        PR_fprintf(PR_STDERR, "Error: profile path not valid.");        return rv;      }            // As with -profile, assume that the given path will be used for both the      // main profile directory and the temp profile directory.      rv = profileSvc->CreateProfile(lf, lf, nsDependentCSubstring(arg, delim),                                     getter_AddRefs(profile));    } else {      rv = profileSvc->CreateProfile(nsnull, nsnull, nsDependentCString(arg),                                     getter_AddRefs(profile));    }    if (NS_SUCCEEDED(rv)) {      rv = NS_ERROR_ABORT;      PR_fprintf(PR_STDERR, "Success: created profile '%s'\n", arg);    }    profileSvc->Flush();    // XXXben need to ensure prefs.js exists here so the tinderboxes will    //        not go orange.    nsCOMPtr<nsILocalFile> prefsJSFile;    profile->GetRootDir(getter_AddRefs(prefsJSFile));    prefsJSFile->AppendNative(NS_LITERAL_CSTRING("prefs.js"));    PRBool exists;    prefsJSFile->Exists(&exists);    if (!exists)      prefsJSFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);    // XXXdarin perhaps 0600 would be better?    return rv;  }  PRUint32 count;  rv = profileSvc->GetProfileCount(&count);  NS_ENSURE_SUCCESS(rv, rv);  if (gAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR) {    arg = PR_GetEnv("XRE_IMPORT_PROFILES");    if (!count && (!arg || !*arg)) {      return ImportProfiles(profileSvc, aNative);    }  }  ar = CheckArg("p", &arg);  if (ar == ARG_BAD) {    return ShowProfileManager(profileSvc, aNative);  }  if (ar) {    nsCOMPtr<nsIToolkitProfile> profile;    rv = profileSvc->GetProfileByName(nsDependentCString(arg),                                      getter_AddRefs(profile));    if (NS_SUCCEEDED(rv)) {      nsCOMPtr<nsIProfileUnlocker> unlocker;      rv = profile->Lock(nsnull, aResult);      if (NS_SUCCEEDED(rv))        return NS_OK;      nsCOMPtr<nsILocalFile> profileDir;      rv = profile->GetRootDir(getter_AddRefs(profileDir));      NS_ENSURE_SUCCESS(rv, rv);      nsCOMPtr<nsILocalFile> profileLocalDir;      rv = profile->GetLocalDir(getter_AddRefs(profileLocalDir));      NS_ENSURE_SUCCESS(rv, rv);      return ProfileLockedDialog(profileDir, profileLocalDir, unlocker,                                 aNative, aResult);    }    return ShowProfileManager(profileSvc, aNative);  }  if (CheckArg("profilemanager")) {    return ShowProfileManager(profileSvc, aNative);  }  if (!count) {    gDoMigration = PR_TRUE;    // create a default profile    nsCOMPtr<nsIToolkitProfile> profile;    nsresult rv = profileSvc->CreateProfile(nsnull, // choose a default dir for us                                            nsnull, // choose a default dir for us                                            NS_LITERAL_CSTRING("default"),                                            getter_AddRefs(profile));    if (NS_SUCCEEDED(rv)) {      profileSvc->Flush();      rv = profile->Lock(nsnull, aResult);      if (NS_SUCCEEDED(rv))        return NS_OK;    }  }  PRBool useDefault = PR_TRUE;  if (count > 1)    profileSvc->GetStartWithLastProfile(&useDefault);  if (useDefault) {    nsCOMPtr<nsIToolkitProfile> profile;    // GetSelectedProfile will auto-select the only profile if there's just one    profileSvc->GetSelectedProfile(getter_AddRefs(profile));    if (profile) {      nsCOMPtr<nsIProfileUnlocker> unlocker;      rv = profile->Lock(getter_AddRefs(unlocker), aResult);      if (NS_SUCCEEDED(rv))        return NS_OK;      nsCOMPtr<nsILocalFile> profileDir;      rv = profile->GetRootDir(getter_AddRefs(profileDir));      NS_ENSURE_SUCCESS(rv, rv);      nsCOMPtr<nsILocalFile> profileLocalDir;      rv = profile->GetRootDir(getter_AddRefs(profileLocalDir));      NS_ENSURE_SUCCESS(rv, rv);      return ProfileLockedDialog(profileDir, profileLocalDir, unlocker,                                 aNative, aResult);    }  }  return ShowProfileManager(profileSvc, aNative);}