1999-07-06 09:48:12 +04:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-07-06 09:48:12 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-07-06 09:48:12 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code,
|
|
|
|
* released March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 06:43:54 +03:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
1999-07-06 09:48:12 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Contributor(s):
|
1999-07-06 09:48:12 +04:00
|
|
|
* Daniel Veditz <dveditz@netscape.com>
|
2000-01-11 23:49:15 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
1999-07-06 09:48:12 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xpistub.h"
|
|
|
|
|
2001-09-07 01:13:11 +04:00
|
|
|
#include "nsIComponentManager.h"
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsIComponentRegistrar.h"
|
1999-07-06 09:48:12 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsSpecialSystemDirectory.h"
|
2000-01-25 00:28:28 +03:00
|
|
|
#include "nsILocalFile.h"
|
1999-07-06 09:48:12 +04:00
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nspr.h"
|
|
|
|
|
|
|
|
#include "nsStubNotifier.h"
|
|
|
|
|
|
|
|
#include "nsISoftwareUpdate.h"
|
|
|
|
#include "nsSoftwareUpdateIIDs.h"
|
1999-09-01 08:29:49 +04:00
|
|
|
#include "nsPIXPIStubHook.h"
|
1999-07-06 09:48:12 +04:00
|
|
|
|
1999-08-01 00:28:58 +04:00
|
|
|
#include "plstr.h"
|
|
|
|
|
1999-08-11 06:50:52 +04:00
|
|
|
#ifdef XP_PC
|
2000-05-02 02:30:13 +04:00
|
|
|
#if defined(XP_OS2)
|
|
|
|
#include <stdlib.h>
|
|
|
|
#define MAX_PATH _MAX_PATH
|
|
|
|
#else
|
2000-01-25 23:44:55 +03:00
|
|
|
#include <windows.h>
|
2000-04-04 02:58:34 +04:00
|
|
|
#endif
|
2000-05-17 02:47:31 +04:00
|
|
|
#ifndef XP_OS2_EMX
|
|
|
|
#include <direct.h>
|
|
|
|
#endif /*emx*/
|
1999-09-18 08:56:44 +04:00
|
|
|
#define COMPONENT_REG "component.reg"
|
1999-08-11 06:50:52 +04:00
|
|
|
#endif
|
|
|
|
|
1999-09-18 03:11:31 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#define COMPONENT_REG "\pComponent Registry"
|
|
|
|
#include "MoreFilesExtras.h"
|
2000-01-25 00:28:28 +03:00
|
|
|
#include "nsLocalFileMac.h"
|
|
|
|
#include "nsILocalFileMac.h"
|
1999-09-18 03:11:31 +04:00
|
|
|
#endif
|
1999-07-06 09:48:12 +04:00
|
|
|
|
1999-12-24 02:25:33 +03:00
|
|
|
#ifdef XP_UNIX
|
2000-04-06 03:43:49 +04:00
|
|
|
#include <unistd.h>
|
1999-12-24 02:25:33 +03:00
|
|
|
#define COMPONENT_REG "component.reg"
|
|
|
|
#endif
|
1999-07-06 09:48:12 +04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// globals
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
2000-05-05 10:23:11 +04:00
|
|
|
static nsIXPIListener *gListener = 0;
|
1999-07-06 09:48:12 +04:00
|
|
|
static nsISoftwareUpdate *gXPI = 0;
|
1999-08-11 04:31:15 +04:00
|
|
|
static nsIServiceManager *gServiceMgr = 0;
|
1999-07-06 09:48:12 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID);
|
|
|
|
|
1999-10-10 01:37:21 +04:00
|
|
|
PRInt32 gInstallStatus;
|
|
|
|
|
1999-07-06 09:48:12 +04:00
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// XPI_Init()
|
|
|
|
//------------------------------------------------------------------------
|
1999-08-11 04:31:15 +04:00
|
|
|
PR_PUBLIC_API(nsresult) XPI_Init(
|
|
|
|
#ifdef XP_MAC
|
1999-09-10 12:21:51 +04:00
|
|
|
const FSSpec& aXPIStubDir,
|
|
|
|
const FSSpec& aProgramDir,
|
1999-08-11 04:31:15 +04:00
|
|
|
#else
|
1999-09-10 12:21:51 +04:00
|
|
|
const char* aProgramDir,
|
1999-08-11 04:31:15 +04:00
|
|
|
#endif
|
2000-07-11 03:15:46 +04:00
|
|
|
const char* aLogName,
|
1999-10-10 01:37:21 +04:00
|
|
|
pfnXPIProgress progressCB )
|
1999-07-06 09:48:12 +04:00
|
|
|
{
|
1999-08-01 00:28:58 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFileSpec> nsIfsDirectory;
|
|
|
|
nsFileSpec nsfsDirectory;
|
1999-09-18 08:56:44 +04:00
|
|
|
nsFileSpec nsfsRegFile;
|
1999-08-01 00:28:58 +04:00
|
|
|
|
1999-08-11 07:53:03 +04:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// Initialize XPCOM and AutoRegister() its components
|
|
|
|
//--------------------------------------------------------------------
|
1999-09-18 03:11:31 +04:00
|
|
|
#ifdef XP_MAC
|
2002-01-08 01:22:12 +03:00
|
|
|
nsCOMPtr<nsILocalFileMac> binDir;
|
|
|
|
rv = NS_NewLocalFileWithFSSpec((FSSpec*)&aXPIStubDir, PR_FALSE, getter_AddRefs(binDir));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = NS_InitXPCOM2(&gServiceMgr, binDir, nsnull);
|
|
|
|
|
2000-05-02 04:55:36 +04:00
|
|
|
// binDir is contaminated now. Need compDir to pass to AutoRegister.
|
2002-01-08 01:22:12 +03:00
|
|
|
nsCOMPtr<nsILocalFileMac> compDir;
|
|
|
|
rv = NS_NewLocalFileWithFSSpec((FSSpec*)&aXPIStubDir, PR_FALSE, getter_AddRefs(compDir));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-01-25 23:44:55 +03:00
|
|
|
#elif defined(XP_PC)
|
2000-04-05 09:47:39 +04:00
|
|
|
|
2000-01-25 23:44:55 +03:00
|
|
|
char componentPath[MAX_PATH];
|
|
|
|
getcwd(componentPath, MAX_PATH);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> file;
|
2002-04-27 09:33:09 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(componentPath), PR_TRUE, getter_AddRefs(file));
|
2000-01-25 00:28:28 +03:00
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
rv = NS_InitXPCOM2(&gServiceMgr, file, nsnull);
|
2000-01-25 23:44:55 +03:00
|
|
|
|
|
|
|
#elif defined(XP_UNIX)
|
2000-04-05 09:47:39 +04:00
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
rv = NS_InitXPCOM2(&gServiceMgr, nsnull, nsnull);
|
2000-01-25 23:44:55 +03:00
|
|
|
|
2000-04-05 09:47:39 +04:00
|
|
|
char cwd[1024];
|
|
|
|
char compDirPath[1024];
|
|
|
|
|
|
|
|
memset(cwd, 0, 1024);
|
|
|
|
memset(compDirPath, 0, 1024);
|
|
|
|
getcwd(cwd, 1024);
|
|
|
|
sprintf(compDirPath, "%s/components", cwd);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> compDir;
|
2002-04-27 09:33:09 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(compDirPath), PR_TRUE, getter_AddRefs(compDir));
|
2000-04-05 09:47:39 +04:00
|
|
|
|
1999-09-18 03:11:31 +04:00
|
|
|
#else
|
2000-04-05 09:47:39 +04:00
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
rv = NS_InitXPCOM2(&gServiceMgr, NULL, NULL);
|
2000-04-05 09:47:39 +04:00
|
|
|
|
1999-09-18 03:11:31 +04:00
|
|
|
#endif
|
1999-08-01 00:28:58 +04:00
|
|
|
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(rv))
|
1999-08-11 07:53:03 +04:00
|
|
|
return rv;
|
|
|
|
|
2002-01-30 00:22:13 +03:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(gServiceMgr);
|
|
|
|
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
|
|
|
|
2000-05-02 04:55:36 +04:00
|
|
|
#if defined(XP_UNIX) || defined(XP_MAC)
|
2002-01-30 00:22:13 +03:00
|
|
|
rv = registrar->AutoRegister(compDir);
|
2000-04-05 09:47:39 +04:00
|
|
|
#else
|
2002-01-30 00:22:13 +03:00
|
|
|
rv = registrar->AutoRegister(nsnull);
|
2000-04-05 09:47:39 +04:00
|
|
|
#endif
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(rv))
|
2000-02-09 06:42:08 +03:00
|
|
|
return rv;
|
|
|
|
|
1999-08-11 07:53:03 +04:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// 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,
|
2000-01-11 23:49:15 +03:00
|
|
|
NS_GET_IID(nsISoftwareUpdate),
|
1999-08-11 07:53:03 +04:00
|
|
|
(void**) &gXPI);
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(rv))
|
1999-08-11 07:53:03 +04:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// Override XPInstall's natural assumption that the current executable
|
|
|
|
// is Mozilla. Use the given directory as the "Program" folder.
|
|
|
|
//--------------------------------------------------------------------
|
1999-09-01 08:29:49 +04:00
|
|
|
nsCOMPtr<nsPIXPIStubHook> hook = do_QueryInterface(gXPI);
|
1999-09-10 12:21:51 +04:00
|
|
|
nsFileSpec dirSpec( aProgramDir );
|
2000-04-25 18:43:58 +04:00
|
|
|
nsCOMPtr<nsILocalFile> iDirSpec;
|
|
|
|
|
2000-04-21 22:58:41 +04:00
|
|
|
#if XP_MAC
|
2000-04-25 18:43:58 +04:00
|
|
|
nsCOMPtr<nsILocalFileMac> iMacDirSpec;
|
2000-07-13 03:31:31 +04:00
|
|
|
NS_NewLocalFileWithFSSpec((FSSpec *)&aProgramDir, PR_TRUE, getter_AddRefs(iMacDirSpec));
|
2000-04-25 18:43:58 +04:00
|
|
|
iDirSpec = do_QueryInterface(iMacDirSpec);
|
2000-04-21 22:58:41 +04:00
|
|
|
#else
|
2002-04-27 09:33:09 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(aProgramDir), PR_TRUE, getter_AddRefs(iDirSpec));
|
2000-04-21 22:58:41 +04:00
|
|
|
#endif
|
1999-08-11 07:53:03 +04:00
|
|
|
|
|
|
|
if (hook && iDirSpec)
|
2000-07-12 07:42:35 +04:00
|
|
|
{
|
|
|
|
rv = hook->StubInitialize( iDirSpec, aLogName );
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-08-11 07:53:03 +04:00
|
|
|
else
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// Save the install wizard's callbacks as a nsIXPINotifer for later
|
|
|
|
//--------------------------------------------------------------------
|
2000-05-05 10:23:11 +04:00
|
|
|
nsStubListener* stub = new nsStubListener( progressCB );
|
1999-08-11 07:53:03 +04:00
|
|
|
if (!stub)
|
1999-07-06 09:48:12 +04:00
|
|
|
{
|
1999-08-11 07:53:03 +04:00
|
|
|
gXPI->Release();
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-05-05 10:23:11 +04:00
|
|
|
rv = stub->QueryInterface(NS_GET_IID(nsIXPIListener), (void**)&gListener);
|
1999-07-06 09:48:12 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// XPI_Exit()
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
PR_PUBLIC_API(void) XPI_Exit()
|
|
|
|
{
|
2000-05-05 10:23:11 +04:00
|
|
|
if (gListener)
|
|
|
|
gListener->Release();
|
1999-07-06 09:48:12 +04:00
|
|
|
|
|
|
|
if (gXPI)
|
|
|
|
gXPI->Release();
|
|
|
|
|
1999-08-11 04:31:15 +04:00
|
|
|
NS_ShutdownXPCOM(gServiceMgr);
|
|
|
|
|
1999-07-06 09:48:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// XPI_Install()
|
|
|
|
//------------------------------------------------------------------------
|
1999-10-10 01:37:21 +04:00
|
|
|
PR_PUBLIC_API(PRInt32) XPI_Install(
|
1999-08-11 04:31:15 +04:00
|
|
|
#ifdef XP_MAC
|
1999-07-06 09:48:12 +04:00
|
|
|
const FSSpec& aFile,
|
1999-08-11 04:31:15 +04:00
|
|
|
#else
|
|
|
|
const char* aFile,
|
1999-07-06 09:48:12 +04:00
|
|
|
#endif
|
1999-08-11 04:31:15 +04:00
|
|
|
const char* aArgs,
|
|
|
|
long aFlags )
|
1999-07-06 09:48:12 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_NULL_POINTER;
|
2000-04-18 09:46:08 +04:00
|
|
|
nsString args; args.AssignWithConversion(aArgs);
|
2000-04-21 22:58:41 +04:00
|
|
|
nsCOMPtr<nsILocalFile> iFile;
|
1999-07-06 09:48:12 +04:00
|
|
|
nsFileSpec file(aFile);
|
1999-07-12 19:20:54 +04:00
|
|
|
nsFileURL URL(file);
|
2000-04-18 09:46:08 +04:00
|
|
|
nsString URLstr; URLstr.AssignWithConversion(URL.GetURLString());
|
1999-07-06 09:48:12 +04:00
|
|
|
|
2000-02-15 04:32:12 +03:00
|
|
|
gInstallStatus = -322; // unique stub error code
|
2000-04-21 22:58:41 +04:00
|
|
|
|
|
|
|
#if XP_MAC
|
2000-04-25 18:43:58 +04:00
|
|
|
nsCOMPtr<nsILocalFileMac> iMacFile;
|
2000-07-13 03:31:31 +04:00
|
|
|
NS_NewLocalFileWithFSSpec((FSSpec *)&aFile, PR_TRUE, getter_AddRefs(iMacFile));
|
2000-04-25 18:43:58 +04:00
|
|
|
iFile = do_QueryInterface(iMacFile);
|
2000-04-21 22:58:41 +04:00
|
|
|
#else
|
2002-04-27 09:33:09 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(aFile), PR_TRUE, getter_AddRefs(iFile));
|
2000-04-21 22:58:41 +04:00
|
|
|
#endif
|
1999-07-06 09:48:12 +04:00
|
|
|
|
|
|
|
if (iFile && gXPI)
|
2000-09-21 03:12:03 +04:00
|
|
|
rv = gXPI->InstallJar( iFile,
|
2001-06-30 15:02:25 +04:00
|
|
|
URLstr.get(),
|
|
|
|
args.get(),
|
2000-09-21 03:12:03 +04:00
|
|
|
(aFlags | XPI_NO_NEW_THREAD),
|
|
|
|
gListener );
|
1999-07-06 09:48:12 +04:00
|
|
|
|
1999-10-10 01:37:21 +04:00
|
|
|
return gInstallStatus;
|
1999-07-06 09:48:12 +04:00
|
|
|
}
|