1999-07-06 09:48:12 +04:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2004-04-17 18:37:35 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-07-06 09:48:12 +04:00
|
|
|
*
|
2004-04-17 18:37:35 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
1999-07-06 09:48:12 +04:00
|
|
|
*
|
2004-04-17 18:37:35 +04: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
|
|
|
*
|
2004-04-17 18:37:35 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
1999-07-06 09:48:12 +04:00
|
|
|
*
|
2004-04-17 18:37:35 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Daniel Veditz <dveditz@netscape.com>
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
2003-06-19 03:19:11 +04:00
|
|
|
#include "nsLocalFile.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"
|
|
|
|
|
2003-04-03 02:45:08 +04:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
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-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()
|
|
|
|
//------------------------------------------------------------------------
|
2004-04-25 22:37:44 +04:00
|
|
|
PR_PUBLIC_API(nsresult) XPI_Init( const char* aProgramDir,
|
|
|
|
const char* aLogName,
|
|
|
|
pfnXPIProgress progressCB )
|
1999-07-06 09:48:12 +04:00
|
|
|
{
|
1999-08-01 00:28:58 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-08-11 07:53:03 +04:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
// Initialize XPCOM and AutoRegister() its components
|
|
|
|
//--------------------------------------------------------------------
|
2004-04-25 22:37:44 +04:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
2000-04-05 09:47:39 +04:00
|
|
|
|
2003-03-24 17:35:35 +03:00
|
|
|
#ifdef XP_OS2_EMX
|
|
|
|
char componentPath[MAX_PATH];
|
|
|
|
_getcwd2(componentPath, MAX_PATH);
|
|
|
|
int len = strlen(componentPath);
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
if (componentPath[i] == '/') {
|
|
|
|
componentPath[i] = '\\';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2000-01-25 23:44:55 +03:00
|
|
|
char componentPath[MAX_PATH];
|
|
|
|
getcwd(componentPath, MAX_PATH);
|
2003-03-24 17:35:35 +03:00
|
|
|
#endif
|
2000-01-25 23:44:55 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> file;
|
2003-03-24 17:35:35 +03:00
|
|
|
rv = NS_NewNativeLocalFile(nsDependentCString(componentPath), PR_TRUE, getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
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");
|
|
|
|
|
2004-04-25 22:37:44 +04:00
|
|
|
#if defined(XP_UNIX)
|
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.
|
|
|
|
//--------------------------------------------------------------------
|
2004-11-01 21:50:36 +03:00
|
|
|
rv = CallCreateInstance(kSoftwareUpdateCID, &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);
|
2000-04-25 18:43:58 +04:00
|
|
|
nsCOMPtr<nsILocalFile> iDirSpec;
|
|
|
|
|
2004-04-25 22:37:44 +04:00
|
|
|
if (aProgramDir)
|
|
|
|
{
|
2002-04-27 09:33:09 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(aProgramDir), PR_TRUE, getter_AddRefs(iDirSpec));
|
2004-04-25 22:37:44 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIProperties> directoryService =
|
|
|
|
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
|
|
|
|
|
|
|
directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile),
|
|
|
|
getter_AddRefs(iDirSpec));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
const char* aFile,
|
|
|
|
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
|
|
|
|
2000-02-15 04:32:12 +03:00
|
|
|
gInstallStatus = -322; // unique stub error code
|
2000-04-21 22:58:41 +04:00
|
|
|
|
2004-04-25 22:37:44 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(aFile), PR_TRUE, getter_AddRefs(iFile));
|
1999-07-06 09:48:12 +04:00
|
|
|
|
|
|
|
if (iFile && gXPI)
|
2000-09-21 03:12:03 +04:00
|
|
|
rv = gXPI->InstallJar( iFile,
|
2003-03-15 04:04:32 +03:00
|
|
|
nsnull,
|
2001-06-30 15:02:25 +04:00
|
|
|
args.get(),
|
2002-12-17 03:59:42 +03:00
|
|
|
nsnull,
|
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
|
|
|
}
|