From daae3f07ccfaea36e5e028b67e5eafa8aad319ba Mon Sep 17 00:00:00 2001 From: "dveditz%netscape.com" Date: Wed, 11 Aug 1999 03:53:03 +0000 Subject: [PATCH] allow install wizard to override program directory --- xpinstall/stub/xpistub.cpp | 71 +++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/xpinstall/stub/xpistub.cpp b/xpinstall/stub/xpistub.cpp index 294949a9c9ed..1dec3f3c9c24 100644 --- a/xpinstall/stub/xpistub.cpp +++ b/xpinstall/stub/xpistub.cpp @@ -37,6 +37,7 @@ #include "nsISoftwareUpdate.h" #include "nsSoftwareUpdateIIDs.h" +#include "nsPvtIXPIStubHook.h" #include "plstr.h" @@ -75,6 +76,9 @@ PR_PUBLIC_API(nsresult) XPI_Init( nsCOMPtr nsIfsDirectory; nsFileSpec nsfsDirectory; + //-------------------------------------------------------------------- + // Initialize XPCOM and AutoRegister() its components + //-------------------------------------------------------------------- rv = NS_InitXPCOM(&gServiceMgr); if (!NS_SUCCEEDED(rv)) return rv; @@ -107,28 +111,55 @@ PR_PUBLIC_API(nsresult) XPI_Init( #else rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, 0); #endif - if (NS_SUCCEEDED(rv)) + + if (!NS_SUCCEEDED(rv)) + return rv; + + + //-------------------------------------------------------------------- + // Get the SoftwareUpdate (XPInstall) service. + // + // Since AppShell is not started by XPIStub the XPI service is never + // registered with the service manager. We keep a local pointer to it + // so it stays alive througout. + //-------------------------------------------------------------------- + rv = nsComponentManager::CreateInstance(kSoftwareUpdateCID, + nsnull, + nsISoftwareUpdate::GetIID(), + (void**) &gXPI); + if (!NS_SUCCEEDED(rv)) + return rv; + + + //-------------------------------------------------------------------- + // Override XPInstall's natural assumption that the current executable + // is Mozilla. Use the given directory as the "Program" folder. + //-------------------------------------------------------------------- + nsCOMPtr hook = do_QueryInterface(gXPI); + nsFileSpec dirSpec( aDir ); + nsCOMPtr iDirSpec; + + NS_NewFileSpecWithSpec( dirSpec, getter_AddRefs(iDirSpec) ); + + if (hook && iDirSpec) + hook->SetProgramDirectory( iDirSpec ); + else + return NS_ERROR_NULL_POINTER; + + + //-------------------------------------------------------------------- + // Save the install wizard's callbacks as a nsIXPINotifer for later + //-------------------------------------------------------------------- + nsStubNotifier* stub = new nsStubNotifier( startCB, progressCB, finalCB ); + if (!stub) { - rv = nsComponentManager::CreateInstance(kSoftwareUpdateCID, - nsnull, - nsISoftwareUpdate::GetIID(), - (void**) &gXPI); - - if (NS_SUCCEEDED(rv)) - { - nsStubNotifier* stub = new nsStubNotifier( startCB, progressCB, finalCB ); - if (!stub) - { - gXPI->Release(); - rv = NS_ERROR_OUT_OF_MEMORY; - } - else - { - rv = stub->QueryInterface(nsIXPINotifier::GetIID(), (void**)&gNotifier); - } - } + gXPI->Release(); + rv = NS_ERROR_OUT_OF_MEMORY; + } + else + { + rv = stub->QueryInterface(nsIXPINotifier::GetIID(), (void**)&gNotifier); } - return rv; }