} }
}
static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ){  nsresult rv;#ifdef DEBUG_warren//  _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF);#endif#ifndef XP_MAC  // Unbuffer debug output (necessary for automated QA performance scripts).  setbuf( stdout, 0 );#endif#if defined(FREEBSD)  // Disable all SIGFPE's on FreeBSD, as it has non-IEEE-conformant fp  // trap behavior that trips up on floating-point tests performed by  // the JS engine.  See bugzilla bug 9967 details.  fpsetmask(0);#endif  NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID,                  &rv);  if (NS_OK == rv) {    // XXX: What if this fails?    rv = eventQService->CreateThreadEventQueue();  }  // Setup an autoreg obserer, so that we can update a progress  // string in the splash screen  nsCOMPtr<nsIObserverService> obsService = do_GetService(NS_OBSERVERSERVICE_PROGID);  if (obsService)  {    nsCOMPtr<nsIObserver> splashScreenObserver = do_QueryInterface(nativeApp);    if (splashScreenObserver)    {      obsService->AddObserver(splashScreenObserver, NS_ConvertASCIItoUCS2(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID).GetUnicode());    }  }  // Create and register a directory service provider  nsAppFileLocationProvider* appFileLocProvider;  appFileLocProvider = new nsAppFileLocationProvider;  if (!appFileLocProvider) {    NS_ASSERTION(PR_FALSE, "Could not create nsAppFileLocationProvider\n");    return NS_ERROR_OUT_OF_MEMORY;  }  NS_WITH_SERVICE(nsIDirectoryService, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv);  if (!directoryService) {    NS_ASSERTION(PR_FALSE, "failed to get directory service");    return rv;  }  // RegisterProvider will AddRef it and own it - notice we have not AddRef'd it  rv = directoryService->RegisterProvider(appFileLocProvider);  if (NS_FAILED(rv)) {    NS_ASSERTION(PR_FALSE, "Could not register directory service provider\n");    return rv;  }  //----------------------------------------------------------------  // XPInstall needs to clean up after any updates that couldn't  // be completed because components were in use. This must be done  // **BEFORE** any other libraries are loaded!  //  // Will also check to see if AutoReg is required due to version  // change or installation of new components. If for some reason  // XPInstall can't be loaded we assume Autoreg is required.  //  // (scoped in a block to force release of COMPtr)  //----------------------------------------------------------------  PRBool needAutoreg = PR_TRUE;  {    nsCOMPtr<nsISoftwareUpdate> su = do_GetService(kSoftUpdateCID,&rv);    if (NS_SUCCEEDED(rv))    {      su->StartupTasks( &needAutoreg );    }  }//  nsServiceManager::UnregisterService(kSoftUpdateCID);#if XP_MAC  stTSMCloser  tsmCloser;  rv = InitializeMacCommandLine( argc, argv);  NS_ASSERTION(NS_SUCCEEDED(rv), "Initializing AppleEvents failed");#endif  // XXX: This call will be replaced by a registry initialization...  NS_SetupRegistry_1( needAutoreg );  // remove the nativeApp as an XPCOM autoreg observer  if (obsService)  {    nsCOMPtr<nsIObserver> splashScreenObserver = do_QueryInterface(nativeApp);    if (splashScreenObserver)    {      obsService->RemoveObserver(splashScreenObserver, NS_ConvertASCIItoUCS2(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID).GetUnicode());    }  }  // Start up the core services:    // Initialize the cmd line service  NS_WITH_SERVICE(nsICmdLineService, cmdLineArgs, kCmdLineServiceCID, &rv);  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get command line service");  if (NS_FAILED(rv)) {    NS_ASSERTION(PR_FALSE, "Could not obtain CmdLine processing service\n");    return rv;  }  rv = cmdLineArgs->Initialize(argc, argv);  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to initialize command line args");  if (rv  == NS_ERROR_INVALID_ARG) {    PrintUsage();    return rv;  }  CheckForNewChrome();  // Create the Application Shell instance...  NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get the appshell service");  if (NS_FAILED(rv)) {    // See if platform supports nsINativeAppSupport.    nsCOMPtr<nsINativeAppSupport> nativeAppSupport = do_QueryInterface( nativeApp );    if ( nativeAppSupport ) {        // Use that interface to remove splash screen.        nativeAppSupport->HideSplashScreen();    } else {        // See if platform supports nsISplashScreen, instead.        nsCOMPtr<nsISplashScreen> splashScreen = do_QueryInterface( nativeApp );        if ( splashScreen ) {            splashScreen->Hide();        }    }    // Release argument object.    NS_IF_RELEASE( nativeApp );    return rv;  }  rv = appShell->Initialize( cmdLineArgs, nativeApp );  // We are done with the native app (or splash screen) object here;  // the app shell owns it now.  NS_IF_RELEASE( nativeApp );  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to initialize appshell");  if ( NS_FAILED(rv) ) return rv;  NS_WITH_SERVICE(nsIProfile, profileMgr, kProfileCID, &rv);  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get profile manager");  if ( NS_FAILED(rv) ) return rv;  rv = profileMgr->StartupWithArgs(cmdLineArgs);  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;  }  // rjc: now must explicitly call appshell's CreateHiddenWindow() function AFTER profile manager.  //      if the profile manager ever switches to using nsIDOMWindow stuff, this might have to change  appShell->CreateHiddenWindow();	// Enumerate AppShellComponenets	appShell->EnumerateAndInitializeComponents();		// This will go away once Components are handling there own commandlines	// if we have no command line arguments, we need to heed the	// "general.startup.*" prefs	// if we had no command line arguments, argc == 1.#ifdef XP_MAC	// if we do no command line args on the mac, it says argc is 0, and not 1	rv = DoCommandLines( cmdLineArgs, ((argc == 1) || (argc == 0)) );#else	rv = DoCommandLines( cmdLineArgs, (argc == 1) );#endif /* XP_MAC */    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to process command line");	if ( NS_FAILED(rv) )    return rv;  // Make sure there exists at least 1 window.  rv = Ensure1Window( cmdLineArgs );  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to Ensure1Window");  if (NS_FAILED(rv)) return rv;  // Fire up the walletService. Why the heck is this here?  NS_WITH_SERVICE(nsIWalletService, walletService, kWalletServiceCID, &rv);  if (NS_SUCCEEDED(rv))  {    // this is a no-op. What is going on?    walletService->WALLET_FetchFromNetCenter();  }	InitCachePrefs();	  // Start main event loop  rv = appShell->Run();  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to run appshell");  /*   * Shut down the Shell instance...  This is done even if the Run(...)   * method returned an error.   */  (void) appShell->Shutdown();  return rv;}