nsCOMPtr<nsINativeAppSupport> nativeApp;
nsCOMPtr<nsINativeAppSupport> nativeAppSupport;
static nsresult InitializeProfileService(nsICmdLineService *cmdLineArgs){    nsresult rv;    PRBool standaloneApp = PR_FALSE;     nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));    if (NS_FAILED(rv)) return rv;     rv = prefs->GetBoolPref(STANDALONE_APP_PREF, &standaloneApp);     if (NS_SUCCEEDED(rv) && standaloneApp)     {         nsMPFileLocProvider *fileLocProvider = new nsMPFileLocProvider;         NS_ENSURE_TRUE(fileLocProvider, NS_ERROR_OUT_OF_MEMORY);         // Specify the dir that standalone app will use for its "profile" dir         nsCOMPtr<nsIFile> parentDir;         PRBool exists = PR_FALSE;#ifdef XP_OS2        rv = NS_GetSpecialDirectory(NS_OS2_HOME_DIR, getter_AddRefs(parentDir));               if (NS_SUCCEEDED(rv))          rv = parentDir->Exists(&exists);        if (NS_FAILED(rv) || !exists)          return rv;#elif defined(XP_PC)        rv = NS_GetSpecialDirectory(NS_WIN_APPDATA_DIR, getter_AddRefs(parentDir));         if (NS_SUCCEEDED(rv))          rv = parentDir->Exists(&exists);        if (NS_FAILED(rv) || !exists)          {            parentDir = nsnull;            rv = NS_GetSpecialDirectory(NS_WIN_WINDOWS_DIR, getter_AddRefs(parentDir));          }                if (NS_FAILED(rv))           return rv;#else      rv = NS_GetSpecialDirectory(NS_OS_HOME_DIR, getter_AddRefs(parentDir));             if (NS_SUCCEEDED(rv))        rv = parentDir->Exists(&exists);      if (NS_FAILED(rv) || !exists)        return rv;#endif        // Get standalone app dir name from prefs and initialize mpfilelocprovider        nsXPIDLCString appDir;        rv = prefs->CopyCharPref(STANDALONE_APP_DIR_PREF, getter_Copies(appDir));        if (NS_FAILED(rv) || (nsCRT::strlen(appDir) == 0))             return NS_ERROR_FAILURE;         rv = fileLocProvider->Initialize(parentDir, appDir);         if (NS_FAILED(rv)) return rv;         rv = prefs->ResetPrefs();         if (NS_FAILED(rv)) return rv;         rv = prefs->ReadConfigFile();         if (NS_FAILED(rv)) return rv;         rv = prefs->ReadUserPrefs(nsnull);         if (NS_FAILED(rv)) return rv;     }     else     {        rv = prefs->ReadConfigFile();         if (NS_FAILED(rv)) return rv;         nsCOMPtr<nsIProfileInternal> profileMgr(do_GetService(NS_PROFILE_CONTRACTID, &rv));        NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get profile manager");        if (NS_FAILED(rv)) return rv;        nsCOMPtr<nsINativeAppSupport> nativeApp;        PRBool serverMode = PR_FALSE;        GetNativeAppSupport(getter_AddRefs(nativeApp));        if (nativeApp)            nativeApp->GetIsServerMode(&serverMode);                    // If we are in server mode, profile mgr cannot show UI        rv = profileMgr->StartupWithArgs(cmdLineArgs, !serverMode);        NS_ASSERTION(NS_SUCCEEDED(rv), "StartupWithArgs failed\n");        if (serverMode && rv == NS_ERROR_PROFILE_REQUIRES_INTERACTION) {            nativeApp->SetNeedsProfileUI(PR_TRUE);            rv = NS_OK;        }         else if (NS_FAILED(rv)) return rv;        // if we get here, and we don't have a current profile, return a failure so we will exit        // this can happen, if the user hits Cancel or Exit in the profile manager dialogs        nsXPIDLString currentProfileStr;        rv = profileMgr->GetCurrentProfile(getter_Copies(currentProfileStr));        if (NS_FAILED(rv) || !((const PRUnichar *)currentProfileStr) ||                            (nsCRT::strlen((const PRUnichar *)currentProfileStr) == 0)) {  	    return NS_ERROR_FAILURE;        }    }    return rv;}