rv = profileSvc->CreateProfile(nsnull, nsDependentCString(arg), getter_AddRefs(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; }  rv = profileSvc->CreateProfile(lf, nsDependentCSubstring(arg, delim), getter_AddRefs(profile)); } else { rv = profileSvc->CreateProfile(nsnull, nsDependentCString(arg), getter_AddRefs(profile)); }
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);    return NS_LockProfilePath(lf, 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 = NS_GetFileFromPath(arg, getter_AddRefs(lf));    NS_ENSURE_SUCCESS(rv, rv);    return NS_LockProfilePath(lf, 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;    rv = profileSvc->CreateProfile(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);    return rv;  }  PRUint32 count;  rv = profileSvc->GetProfileCount(&count);  NS_ENSURE_SUCCESS(rv, rv);  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)) {      rv = profile->Lock(aResult);      if (NS_SUCCEEDED(rv))        return NS_OK;    }    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                                            NS_LITERAL_CSTRING("default"),                                            getter_AddRefs(profile));    if (NS_SUCCEEDED(rv)) {      profileSvc->Flush();      rv = profile->Lock(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) {      rv = profile->Lock(aResult);      if (NS_SUCCEEDED(rv))        return NS_OK;    }  }  return ShowProfileManager(profileSvc, aNative);}