if (NS_FAILED(rv) || !locator) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv; if (!locator) return NS_ERROR_FAILURE;
nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,                       PRBool* profileDirSet,                       nsCString & profileURLStr){    nsresult rv;	char* cmdResult = nsnull;	nsFileSpec currProfileDirSpec;#ifdef DEBUG_profile    printf("Profile Manager : Command Line Options : Begin\n");#endif     // check for command line arguments for profile manager    //	    // -P command line option works this way:    // apprunner -P profilename     // runs the app using the profile <profilename>     // remembers profile for next time    rv = cmdLineArgs->GetCmdLineValue(PROFILE_CMD_LINE_ARG, &cmdResult);    if (NS_SUCCEEDED(rv))        {            if (cmdResult) {                char* currProfileName = cmdResult;#ifdef DEBUG_profile                printf("ProfileName : %s\n", cmdResult);#endif /* DEBUG_profile */                                GetProfileDir(currProfileName, &currProfileDirSpec);			                if (NS_SUCCEEDED(rv)){                    *profileDirSet = PR_TRUE;                }            }        }  	// -CreateProfile command line option works this way:	// apprunner -CreateProfile profilename 	// creates a new profile named <profilename> and sets the directory to your CWD 	// runs app using that profile 	// remembers profile for next time 	//                         - OR -	// apprunner -CreateProfile "profilename profiledir" 	// creates a new profile named <profilename> and sets the directory to <profiledir> 	// runs app using that profile 	// remembers profile for next time    rv = cmdLineArgs->GetCmdLineValue(CREATE_PROFILE_CMD_LINE_ARG, &cmdResult);    if (NS_SUCCEEDED(rv))        {            if (cmdResult) {                char* currProfileName = strtok(cmdResult, " ");                char* currProfileDirString = strtok(NULL, " ");			                if (currProfileDirString)                    currProfileDirSpec = currProfileDirString;                else                    {                        // No directory name provided. Get File Locator                        NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);			if (NS_FAILED(rv) || !locator)				return NS_ERROR_FAILURE;				                        // Get current profile, make the new one a sibling...                        nsCOMPtr <nsIFileSpec> spec;                        rv = locator->GetFileLocation(nsSpecialFileSpec::App_UserProfileDirectory50, getter_AddRefs(spec));                        if (NS_FAILED(rv) || !spec)                            return NS_ERROR_FAILURE;                        spec->GetFileSpec(&currProfileDirSpec);                        currProfileDirSpec.SetLeafName(currProfileName);                        rv = locator->ForgetProfileDir();                    }#ifdef DEBUG_profile                printf("profileName & profileDir are: %s\n", cmdResult);#endif                SetProfileDir(currProfileName, currProfileDirSpec);                *profileDirSet = PR_TRUE;			            }        }    // Start Profile Manager    rv = cmdLineArgs->GetCmdLineValue(PROFILE_MANAGER_CMD_LINE_ARG, &cmdResult);    if (NS_SUCCEEDED(rv))        {		            if (cmdResult) {                profileURLStr = PROFILE_MANAGER_URL;            }        }	// Start Profile Wizard    rv = cmdLineArgs->GetCmdLineValue(PROFILE_WIZARD_CMD_LINE_ARG, &cmdResult);    if (NS_SUCCEEDED(rv))        {		            if (cmdResult) {                profileURLStr = PROFILE_WIZARD_URL;            }        }	// Start Migaration activity    rv = cmdLineArgs->GetCmdLineValue(INSTALLER_CMD_LINE_ARG, &cmdResult);    if (NS_SUCCEEDED(rv))        {		            if (cmdResult) {                rv = MigrateProfileInfo();                if (NS_FAILED(rv)) return rv;                PRInt32 num4xProfiles = 0;                rv = Get4xProfileCount(&num4xProfiles);                if (NS_FAILED(rv)) return rv;                				PRInt32 numProfiles = 0;				GetProfileCount(&numProfiles);                if (num4xProfiles == 0 && numProfiles == 0) {                    profileURLStr = PROFILE_WIZARD_URL;                }#ifdef AUTOMATICALLY_MIGRATE_IF_ONLY_ONE_PROFILE                else if (num4xProfiles == 1) {                    MigrateAllProfiles();                }                else if (num4xProfiles > 1) {#else		else {#endif /* AUTOMATICALLY_MIGRATE_IF_ONLY_ONE_PROFILE */                    profileURLStr = PROFILE_MANAGER_URL;                }            }        }#ifdef DEBUG_profile    printf("Profile Manager : Command Line Options : End\n");#endif    return NS_OK;}