diff --git a/xpinstall/macbuild/xpinstall.mcp b/xpinstall/macbuild/xpinstall.mcp index dbea2a0b9f20..7e4f264a2f7b 100644 Binary files a/xpinstall/macbuild/xpinstall.mcp and b/xpinstall/macbuild/xpinstall.mcp differ diff --git a/xpinstall/public/nsIDOMInstall.h b/xpinstall/public/nsIDOMInstall.h index a5246ba2897f..57c00cff3eef 100644 --- a/xpinstall/public/nsIDOMInstall.h +++ b/xpinstall/public/nsIDOMInstall.h @@ -1,171 +1 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -/* AUTO-GENERATED. DO NOT EDIT!!! */ - -#ifndef nsIDOMInstall_h__ -#define nsIDOMInstall_h__ - -#include "nsISupports.h" -#include "nsString.h" -#include "nsIScriptContext.h" - -class nsIDOMInstallFolder; - -#define NS_IDOMINSTALL_IID \ - { 0x18c2f988, 0xb09f, 0x11d2, \ - {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} - -class nsIDOMInstall : public nsISupports { -public: - static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALL_IID; return iid; } - enum { - SUERR_BAD_PACKAGE_NAME = -200, - SUERR_UNEXPECTED_ERROR = -201, - SUERR_ACCESS_DENIED = -202, - SUERR_TOO_MANY_CERTIFICATES = -203, - SUERR_NO_INSTALLER_CERTIFICATE = -204, - SUERR_NO_CERTIFICATE = -205, - SUERR_NO_MATCHING_CERTIFICATE = -206, - SUERR_UNKNOWN_JAR_FILE = -207, - SUERR_INVALID_ARGUMENTS = -208, - SUERR_ILLEGAL_RELATIVE_PATH = -209, - SUERR_USER_CANCELLED = -210, - SUERR_INSTALL_NOT_STARTED = -211, - SUERR_SILENT_MODE_DENIED = -212, - SUERR_NO_SUCH_COMPONENT = -213, - SUERR_FILE_DOES_NOT_EXIST = -214, - SUERR_FILE_READ_ONLY = -215, - SUERR_FILE_IS_DIRECTORY = -216, - SUERR_NETWORK_FILE_IS_IN_USE = -217, - SUERR_APPLE_SINGLE_ERR = -218, - SUERR_INVALID_PATH_ERR = -219, - SUERR_PATCH_BAD_DIFF = -220, - SUERR_PATCH_BAD_CHECKSUM_TARGET = -221, - SUERR_PATCH_BAD_CHECKSUM_RESULT = -222, - SUERR_UNINSTALL_FAILED = -223, - SUERR_GESTALT_UNKNOWN_ERR = -5550, - SUERR_GESTALT_INVALID_ARGUMENT = -5551, - SU_SUCCESS = 0, - SU_REBOOT_NEEDED = 999, - SU_LIMITED_INSTALL = 0, - SU_FULL_INSTALL = 1, - SU_NO_STATUS_DLG = 2, - SU_NO_FINALIZE_DLG = 4, - SU_INSTALL_FILE_UNEXPECTED_MSG_ID = 0, - SU_DETAILS_REPLACE_FILE_MSG_ID = 1, - SU_DETAILS_INSTALL_FILE_MSG_ID = 2 - }; - - NS_IMETHOD GetUserPackageName(nsString& aUserPackageName)=0; - - NS_IMETHOD GetRegPackageName(nsString& aRegPackageName)=0; - - NS_IMETHOD AbortInstall()=0; - - NS_IMETHOD AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn)=0; - - NS_IMETHOD AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn)=0; - - NS_IMETHOD DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn)=0; - - NS_IMETHOD DeleteFile(nsIDOMInstallFolder* aFolder, const nsString& aRelativeFileName, PRInt32* aReturn)=0; - - NS_IMETHOD DiskSpaceAvailable(nsIDOMInstallFolder* aFolder, PRInt32* aReturn)=0; - - NS_IMETHOD Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn)=0; - - NS_IMETHOD FinalizeInstall(PRInt32* aReturn)=0; - - NS_IMETHOD Gestalt(const nsString& aSelector, PRInt32* aReturn)=0; - - NS_IMETHOD GetComponentFolder(const nsString& aRegName, const nsString& aSubdirectory, nsIDOMInstallFolder** aReturn)=0; - - NS_IMETHOD GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsIDOMInstallFolder** aReturn)=0; - - NS_IMETHOD GetLastError(PRInt32* aReturn)=0; - - NS_IMETHOD GetWinProfile(nsIDOMInstallFolder* aFolder, const nsString& aFile, PRInt32* aReturn)=0; - - NS_IMETHOD GetWinRegistry(PRInt32* aReturn)=0; - - NS_IMETHOD Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn)=0; - - NS_IMETHOD ResetError()=0; - - NS_IMETHOD SetPackageFolder(nsIDOMInstallFolder* aFolder)=0; - - NS_IMETHOD StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32 aFlags, PRInt32* aReturn)=0; - - NS_IMETHOD Uninstall(const nsString& aPackageName, PRInt32* aReturn)=0; -}; - - -#define NS_DECL_IDOMINSTALL \ - NS_IMETHOD GetUserPackageName(nsString& aUserPackageName); \ - NS_IMETHOD GetRegPackageName(nsString& aRegPackageName); \ - NS_IMETHOD AbortInstall(); \ - NS_IMETHOD AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn); \ - NS_IMETHOD AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn); \ - NS_IMETHOD DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn); \ - NS_IMETHOD DeleteFile(nsIDOMInstallFolder* aFolder, const nsString& aRelativeFileName, PRInt32* aReturn); \ - NS_IMETHOD DiskSpaceAvailable(nsIDOMInstallFolder* aFolder, PRInt32* aReturn); \ - NS_IMETHOD Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn); \ - NS_IMETHOD FinalizeInstall(PRInt32* aReturn); \ - NS_IMETHOD Gestalt(const nsString& aSelector, PRInt32* aReturn); \ - NS_IMETHOD GetComponentFolder(const nsString& aRegName, const nsString& aSubdirectory, nsIDOMInstallFolder** aReturn); \ - NS_IMETHOD GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsIDOMInstallFolder** aReturn); \ - NS_IMETHOD GetLastError(PRInt32* aReturn); \ - NS_IMETHOD GetWinProfile(nsIDOMInstallFolder* aFolder, const nsString& aFile, PRInt32* aReturn); \ - NS_IMETHOD GetWinRegistry(PRInt32* aReturn); \ - NS_IMETHOD Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn); \ - NS_IMETHOD ResetError(); \ - NS_IMETHOD SetPackageFolder(nsIDOMInstallFolder* aFolder); \ - NS_IMETHOD StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32 aFlags, PRInt32* aReturn); \ - NS_IMETHOD Uninstall(const nsString& aPackageName, PRInt32* aReturn); \ - - - -#define NS_FORWARD_IDOMINSTALL(_to) \ - NS_IMETHOD GetUserPackageName(nsString& aUserPackageName) { return _to##GetUserPackageName(aUserPackageName); } \ - NS_IMETHOD GetRegPackageName(nsString& aRegPackageName) { return _to##GetRegPackageName(aRegPackageName); } \ - NS_IMETHOD AbortInstall() { return _to##AbortInstall(); } \ - NS_IMETHOD AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn) { return _to##AddDirectory(aRegName, aVersion, aJarSource, aFolder, aSubdir, aForceMode, aReturn); } \ - NS_IMETHOD AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn) { return _to##AddSubcomponent(aRegName, aVersion, aJarSource, aFolder, aTargetName, aForceMode, aReturn); } \ - NS_IMETHOD DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn) { return _to##DeleteComponent(aRegistryName, aReturn); } \ - NS_IMETHOD DeleteFile(nsIDOMInstallFolder* aFolder, const nsString& aRelativeFileName, PRInt32* aReturn) { return _to##DeleteFile(aFolder, aRelativeFileName, aReturn); } \ - NS_IMETHOD DiskSpaceAvailable(nsIDOMInstallFolder* aFolder, PRInt32* aReturn) { return _to##DiskSpaceAvailable(aFolder, aReturn); } \ - NS_IMETHOD Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn) { return _to##Execute(aJarSource, aArgs, aReturn); } \ - NS_IMETHOD FinalizeInstall(PRInt32* aReturn) { return _to##FinalizeInstall(aReturn); } \ - NS_IMETHOD Gestalt(const nsString& aSelector, PRInt32* aReturn) { return _to##Gestalt(aSelector, aReturn); } \ - NS_IMETHOD GetComponentFolder(const nsString& aRegName, const nsString& aSubdirectory, nsIDOMInstallFolder** aReturn) { return _to##GetComponentFolder(aRegName, aSubdirectory, aReturn); } \ - NS_IMETHOD GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsIDOMInstallFolder** aReturn) { return _to##GetFolder(aTargetFolder, aSubdirectory, aReturn); } \ - NS_IMETHOD GetLastError(PRInt32* aReturn) { return _to##GetLastError(aReturn); } \ - NS_IMETHOD GetWinProfile(nsIDOMInstallFolder* aFolder, const nsString& aFile, PRInt32* aReturn) { return _to##GetWinProfile(aFolder, aFile, aReturn); } \ - NS_IMETHOD GetWinRegistry(PRInt32* aReturn) { return _to##GetWinRegistry(aReturn); } \ - NS_IMETHOD Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, nsIDOMInstallFolder* aFolder, const nsString& aTargetName, PRInt32* aReturn) { return _to##Patch(aRegName, aVersion, aJarSource, aFolder, aTargetName, aReturn); } \ - NS_IMETHOD ResetError() { return _to##ResetError(); } \ - NS_IMETHOD SetPackageFolder(nsIDOMInstallFolder* aFolder) { return _to##SetPackageFolder(aFolder); } \ - NS_IMETHOD StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32 aFlags, PRInt32* aReturn) { return _to##StartInstall(aUserPackageName, aPackageName, aVersion, aFlags, aReturn); } \ - NS_IMETHOD Uninstall(const nsString& aPackageName, PRInt32* aReturn) { return _to##Uninstall(aPackageName, aReturn); } \ - - -extern nsresult NS_InitInstallClass(nsIScriptContext *aContext, void **aPrototype); - -extern "C" NS_DOM nsresult NS_NewScriptInstall(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn); - -#endif // nsIDOMInstall_h__ +#error \ No newline at end of file diff --git a/xpinstall/public/nsIDOMInstallTriggerGlobal.h b/xpinstall/public/nsIDOMInstallTriggerGlobal.h index 59656d256b13..07946d065cfc 100644 --- a/xpinstall/public/nsIDOMInstallTriggerGlobal.h +++ b/xpinstall/public/nsIDOMInstallTriggerGlobal.h @@ -43,26 +43,50 @@ public: NS_IMETHOD UpdateEnabled(PRBool* aReturn)=0; NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn)=0; + NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn)=0; NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0; + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0; + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0; + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0; + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0; + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0; + NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0; NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0; + NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0; }; #define NS_DECL_IDOMINSTALLTRIGGERGLOBAL \ NS_IMETHOD UpdateEnabled(PRBool* aReturn); \ + NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn); \ NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn); \ NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \ + NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \ NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \ + NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \ #define NS_FORWARD_IDOMINSTALLTRIGGERGLOBAL(_to) \ NS_IMETHOD UpdateEnabled(PRBool* aReturn) { return _to##UpdateEnabled(aReturn); } \ + NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aFlags, aReturn); } \ NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aReturn); } \ NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, nsIDOMInstallVersion* aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \ + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \ + NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aMajor, aMinor, aRelease, aBuild, aReturn); } \ NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \ + NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \ extern nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype); diff --git a/xpinstall/public/nsIDOMInstallVersion.h b/xpinstall/public/nsIDOMInstallVersion.h index 813cb19320cb..531dbe59f709 100644 --- a/xpinstall/public/nsIDOMInstallVersion.h +++ b/xpinstall/public/nsIDOMInstallVersion.h @@ -62,6 +62,8 @@ public: NS_IMETHOD ToString(nsString& aReturn)=0; NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn)=0; + NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn)=0; + NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0; }; @@ -77,6 +79,8 @@ public: NS_IMETHOD Init(const nsString& aVersionString); \ NS_IMETHOD ToString(nsString& aReturn); \ NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn); \ + NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn); \ + NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \ @@ -92,6 +96,8 @@ public: NS_IMETHOD Init(const nsString& aVersionString) { return _to##Init(aVersionString); } \ NS_IMETHOD ToString(nsString& aReturn) { return _to##ToString(aReturn); } \ NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn) { return _to##CompareTo(aVersionObject, aReturn); } \ + NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn) { return _to##CompareTo(aString, aReturn); } \ + NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareTo(aMajor, aMinor, aRelease, aBuild, aReturn); } \ extern nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype); diff --git a/xpinstall/public/nsISoftwareUpdate.h b/xpinstall/public/nsISoftwareUpdate.h index 34dc246555c1..f05aeaf4c3e2 100644 --- a/xpinstall/public/nsISoftwareUpdate.h +++ b/xpinstall/public/nsISoftwareUpdate.h @@ -46,7 +46,7 @@ class nsISoftwareUpdate : public nsISupports NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISOFTWAREUPDATE_IID) NS_IMETHOD InstallJar(nsInstallInfo *installInfo) = 0; - + NS_IMETHOD InstallJar(const nsString& fromURL, const nsString& flags, const nsString& args) = 0; diff --git a/xpinstall/src/Makefile.in b/xpinstall/src/Makefile.in index cc6f5fbe170b..c6544fb39a85 100644 --- a/xpinstall/src/Makefile.in +++ b/xpinstall/src/Makefile.in @@ -42,7 +42,9 @@ CPPSRCS = \ nsInstallFile.cpp \ nsInstallFolder.cpp \ nsInstallPatch.cpp \ + nsInstallUninstall.cpp \ nsInstallTrigger.cpp \ + nsInstallResources.cpp \ nsJSInstall.cpp \ nsJSInstallTriggerGlobal.cpp\ nsSoftwareUpdateRun.cpp \ @@ -50,7 +52,6 @@ CPPSRCS = \ ScheduledTasks.cpp \ $(NULL) - INCLUDES += -I$(srcdir)/../public include $(topsrcdir)/config/rules.mk diff --git a/xpinstall/src/ScheduledTasks.cpp b/xpinstall/src/ScheduledTasks.cpp index 936592ecc73f..54728cd4245a 100644 --- a/xpinstall/src/ScheduledTasks.cpp +++ b/xpinstall/src/ScheduledTasks.cpp @@ -26,46 +26,103 @@ #include "nscore.h" #include "NSReg.h" #include "nsFileSpec.h" +#include "nsFileStream.h" +#include "nsInstall.h" // for error codes +#include "prmem.h" - - - -REGERR DeleteFileLater(const char * filename) +REGERR DeleteFileLater(nsFileSpec& filename) { - RKEY newkey; - REGERR result = -1; - HREG reg; - if ( REGERR_OK == NR_RegOpen("", ®) ) - { - if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) ) - { - result = NR_RegSetEntryString( reg, newkey, (char*)filename, "" ); - } - NR_RegClose(reg); + REGERR result = 0; + + filename.Delete(false); + + if (filename.Exists()) + { + RKEY newkey; + HREG reg; + if ( REGERR_OK == NR_RegOpen("", ®) ) + { + if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) ) + { + nsPersistentFileDescriptor savethis(filename); + char* buffer = nsnull; + nsOutputStringStream s(buffer); + s << savethis; + + result = NR_RegSetEntry( reg, newkey, "", REGTYPE_ENTRY_BYTES, buffer, strlen(buffer)); + if (result == REGERR_OK) + result = nsInstall::REBOOT_NEEDED; + } + + NR_RegClose(reg); + } } return result; } -REGERR ReplaceFileLater(const char *tmpfile, const char *target ) +REGERR ReplaceFileLater(nsFileSpec& tmpfile, nsFileSpec& target ) { - RKEY newkey; - REGERR err; - HREG reg; - - if ( REGERR_OK == NR_RegOpen("", ®) ) + REGERR result = 0; + + if (! target.Exists() ) { - err = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey); - if ( err == REGERR_OK ) - { - err = NR_RegSetEntryString( reg, newkey, (char*)tmpfile, (char*)target ); - } - NR_RegClose(reg); + // Now that we have move the existing file, we can move the mExtracedFile into place. + nsFileSpec parentofFinalFile; + + target.GetParent(parentofFinalFile); + result = tmpfile.Move(parentofFinalFile); + + char* leafName = target.GetLeafName(); + tmpfile.Rename(leafName); + nsCRT::free(leafName); } - return err; + else + { + RKEY newkey; + HREG reg; + + if ( REGERR_OK == NR_RegOpen("", ®) ) + { + result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey); + if ( result == REGERR_OK ) + { + nsPersistentFileDescriptor tempDesc(tmpfile); + nsPersistentFileDescriptor targDesc(target); + + char* tempBuffer = nsnull; + char* targBuffer = nsnull; + + nsOutputStringStream tempStream(tempBuffer); + nsOutputStringStream targStream(targBuffer); + + tempStream << tempDesc; + targStream << targDesc; + + result = NR_RegSetEntry( reg, newkey, tempBuffer, REGTYPE_ENTRY_BYTES, targBuffer, strlen(targBuffer)); + if (result == REGERR_OK) + result = nsInstall::REBOOT_NEEDED; + + } + + NR_RegClose(reg); + } + } + + return result; } +void DeleteScheduledFiles(void); +void ReplaceScheduledFiles(void); + +extern "C" void PerformScheduledTasks(void *data) +{ + DeleteScheduledFiles(); + ReplaceScheduledFiles(); +} + + void DeleteScheduledFiles(void) { HREG reg; @@ -78,11 +135,16 @@ void DeleteScheduledFiles(void) /* perform scheduled file deletions and replacements (PC only) */ if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY,&key)) { - char buf[MAXREGNAMELEN]; + char buf[MAXREGNAMELEN]; // what about the mac? FIX while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, buf, sizeof(buf), NULL )) { - nsFileSpec doomedFile(buf); + + nsPersistentFileDescriptor doomedDesc; + nsInputStringStream tempStream(buf); + tempStream >> doomedDesc; + + nsFileSpec doomedFile(doomedDesc); doomedFile.Delete(PR_FALSE); @@ -121,7 +183,13 @@ void ReplaceScheduledFiles(void) state = 0; while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL )) { - nsFileSpec replaceFile(tmpfile); + + + nsPersistentFileDescriptor doomedDesc; + nsInputStringStream tempStream(tmpfile); + tempStream >> doomedDesc; + + nsFileSpec replaceFile(doomedDesc); if (! replaceFile.Exists() ) { @@ -134,7 +202,12 @@ void ReplaceScheduledFiles(void) } else { - nsFileSpec targetFile(target); + nsPersistentFileDescriptor targetDesc; + nsInputStringStream anotherStream(target); + anotherStream >> targetDesc; + + nsFileSpec targetFile(targetDesc); + targetFile.Delete(PR_FALSE); if (!targetFile.Exists()) diff --git a/xpinstall/src/ScheduledTasks.h b/xpinstall/src/ScheduledTasks.h index ede56de20504..860d84c4f0c4 100644 --- a/xpinstall/src/ScheduledTasks.h +++ b/xpinstall/src/ScheduledTasks.h @@ -29,12 +29,14 @@ #include "NSReg.h" +#include "nsFileSpec.h" -REGERR DeleteFileLater(const char * filename); -REGERR ReplaceFileLater(const char *tmpfile, const char *target ); -void DeleteScheduledFiles(void); -void ReplaceScheduledFiles(void); +REGERR DeleteFileLater(nsFileSpec& filename); +REGERR ReplaceFileLater(nsFileSpec& tmpfile, nsFileSpec& target ); + + +extern "C" void PerformScheduledTasks(void *data); #endif \ No newline at end of file diff --git a/xpinstall/src/makefile.win b/xpinstall/src/makefile.win index 0eb277e8b2b7..ec10c9baf175 100644 --- a/xpinstall/src/makefile.win +++ b/xpinstall/src/makefile.win @@ -38,17 +38,21 @@ LCFLAGS = \ $(DEFINES) \ $(NULL) -LINCS= \ - -I$(XPDIST)\public\xpinstall \ - -I$(XPDIST)\public\jar \ - -I$(XPDIST)\public\libreg \ - -I$(XPDIST)\public\netlib \ - -I$(XPDIST)\public\xpcom \ - -I$(XPDIST)\public\pref \ - -I$(XPDIST)\public\js \ - -I$(XPDIST)\public\dom \ - -I$(XPDIST)\public\raptor \ - -I$(XPDIST)\public\nspr2 \ +LINCS= \ + -I$(PUBLIC)\libxpt \ + -I$(PUBLIC)\xptinfo \ + -I$(PUBLIC)\xptcall \ + -I$(PUBLIC)\xpinstall \ + -I$(PUBLIC)\jar \ + -I$(PUBLIC)\libreg \ + -I$(PUBLIC)\netlib \ + -I$(PUBLIC)\xpcom \ + -I$(PUBLIC)\pref \ + -I$(PUBLIC)\js \ + -I$(PUBLIC)\dom \ + -I$(PUBLIC)\raptor \ + -I$(PUBLIC)\nspr2 \ + -I$(PUBLIC)\zlib \ $(NULL) LLIBS = \ @@ -59,10 +63,11 @@ LLIBS = \ $(DIST)\lib\xppref32.lib \ $(DIST)\lib\js3250.lib \ $(DIST)\lib\jsdombase_s.lib \ - $(DIST)\lib\jsdomevents_s.lib \ + $(DIST)\lib\jsdomevents_s.lib \ $(DIST)\lib\raptorbase.lib \ + $(DIST)\lib\zlib.lib \ + $(DIST)\lib\plc3.lib \ $(LIBNSPR) \ - $(DIST)\lib\plc3.lib \ $(NULL) @@ -81,7 +86,9 @@ OBJS = \ .\$(OBJDIR)\nsInstallDelete.obj \ .\$(OBJDIR)\nsInstallExecute.obj \ .\$(OBJDIR)\nsInstallPatch.obj \ - .\$(OBJDIR)\ScheduledTasks.obj \ + .\$(OBJDIR)\nsInstallUninstall.obj \ + .\$(OBJDIR)\nsInstallResources.obj \ + .\$(OBJDIR)\ScheduledTasks.obj \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 972461bc9fec..3406b5ea4c46 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -32,8 +32,10 @@ #include "nsVector.h" #include "nsHashtable.h" #include "nsFileSpec.h" +#include "nsFileStream.h" #include "nsSpecialSystemDirectory.h" +#include "prtime.h" #include "prmem.h" #include "pratom.h" #include "prefapi.h" @@ -50,6 +52,7 @@ #include "nsInstallDelete.h" #include "nsInstallExecute.h" #include "nsInstallPatch.h" +#include "nsInstallUninstall.h" #ifdef XP_PC #define FILESEP "\\" @@ -74,6 +77,8 @@ nsInstallInfo::nsInstallInfo(const nsString& fromURL, const nsString& arguments) nsInstallInfo::nsInstallInfo(const nsString& fromURL, const nsString& arguments, const nsString& flags) { + mUIEventQueue = nsnull; + mFromURL = new nsString(fromURL); mArguments = new nsString(arguments); mFlags = new nsString(flags); @@ -84,7 +89,7 @@ nsInstallInfo::nsInstallInfo(const nsString& fromURL, const nsString& arguments, mMultipleTrigger = PR_FALSE; mFromURLs = nsnull; mLocalFiles = nsnull; - + MakeTempFile(fromURL, *mLocalFile); } @@ -148,13 +153,11 @@ nsInstallInfo::~nsInstallInfo() void nsInstallInfo::MakeTempFile(nsString aURL, nsString& tempFileString) { - // Checking to see if the url is local is a hack. I should see if - // netlib could do this for me: given a url, give me path on the users - // if it is local otherwise return null to indicate that I need to - // create a tempfile. + // Checking to see if the url is local + if (aURL.Compare(nsString("file://").GetUnicode(), false, 7) == 0) { - tempFileString = nsFileSpec(nsFileURL(aURL)).GetCString(); + tempFileString.SetString( nsprPath(nsFileURL(aURL)) ); } else { @@ -174,7 +177,7 @@ nsInstallInfo::MakeTempFile(nsString aURL, nsString& tempFileString) tempFile.MakeUnique(); - tempFileString = nsString(tempFile.GetCString()); + tempFileString.SetString( nsprPath( nsFilePath(tempFile) ) ); } } @@ -235,14 +238,19 @@ nsInstall::nsInstall() mUninstallPackage = PR_FALSE; mRegisterPackage = PR_FALSE; - mJarFileLocation = ""; - mInstallArguments = ""; + mJarFileLocation = ""; + mInstallArguments = ""; + + mLogStream = nsnull; } nsInstall::~nsInstall() { if (mVersionInfo != nsnull) delete mVersionInfo; + + if (mLogStream != nsnull) + delete mLogStream; } @@ -269,6 +277,13 @@ nsInstall::GetRegPackageName(nsString& aRegPackageName) PRInt32 nsInstall::AbortInstall() { + if (mLogStream) + { + nsString time; + GetTime(time); + *mLogStream << " Aborted Installation at " << nsAutoCString(time) << nsEndl << nsEndl; + } + nsInstallObject* ie; if (mInstalledFiles != nsnull) { @@ -315,6 +330,813 @@ nsInstall::AddDirectory(const nsString& aRegName, nsString* qualifiedRegName = nsnull; + if ( aRegName == "" || aRegName == "null") + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + nsString subdirectory(aSubdir); + + if (subdirectory != "") + { + subdirectory.Append("/"); + } + + PRBool bInstall; + + nsVector paths; + + result = ExtractDirEntries(aJarSource, &paths); + + PRInt32 pathsUpperBound = paths.GetUpperBound(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + for (int i=0; i< pathsUpperBound; i++) + { + nsInstallVersion* newVersion = new nsInstallVersion(); + + nsString *fullRegName = new nsString(*qualifiedRegName); + fullRegName->Append("/"); + fullRegName->Append(*(nsString *)paths[i]); + + char* fullRegNameCString = fullRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE) && (aVersion == "null") && + (VR_ValidateComponent(fullRegNameCString) == 0)) + { + VERSION versionStruct; + VR_GetVersion( fullRegNameCString, &versionStruct); + + //fix: when we have overloading! + nsInstallVersion* oldVer = new nsInstallVersion(); + oldVer->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + + newVersion->Init(aVersion); + + PRInt32 areTheyEqual; + newVersion->CompareTo(oldVer, &areTheyEqual); + delete newVersion; + + bInstall = ( areTheyEqual > 0 ); + + if (oldVer) + delete oldVer; + + } + else + { + // file doesn't exist or "forced" install + bInstall = PR_TRUE; + } + + delete [] fullRegNameCString; + + if (bInstall) + { + nsString *newJarSource = new nsString(aJarSource); + newJarSource->Append("/"); + newJarSource->Append(*(nsString *)paths[i]); + + nsString* newSubDir; + + if (subdirectory != "") + { + newSubDir = new nsString(subdirectory); + newSubDir->Append(*(nsString*)paths[i]); + } + else + { + newSubDir = new nsString(*(nsString*)paths[i]); + } + + ie = new nsInstallFile( this, + *fullRegName, + newVersion, + *newJarSource, + aFolder, + *newSubDir, + aForceMode, + &result); + delete fullRegName; + delete newJarSource; + delete newSubDir; + delete newVersion; + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + *aReturn = SaveError( result ); + return NS_OK; +} + +PRInt32 +nsInstall::AddDirectory(const nsString& aRegName, + nsIDOMInstallVersion* aVersion, + const nsString& aJarSource, + const nsString& aFolder, + const nsString& aSubdir, + PRBool aForceMode, + PRInt32* aReturn) +{ + nsInstallFile* ie = nsnull; + PRInt32 result; + nsString aVersionStr; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); + return NS_OK; + } + + result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + nsString* qualifiedRegName = nsnull; + + if ( aRegName == "" ) + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + nsString subdirectory(aSubdir); + + if (subdirectory != "") + { + subdirectory.Append("/"); + } + + aVersion->ToString(aVersionStr); + + PRBool bInstall; + + nsVector paths; + + result = ExtractDirEntries(aJarSource, &paths); + + PRInt32 pathsUpperBound = paths.GetUpperBound(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + for (int i=0; i< pathsUpperBound; i++) + { + nsInstallVersion* newVersion = new nsInstallVersion(); + + nsString *fullRegName = new nsString(*qualifiedRegName); + fullRegName->Append("/"); + fullRegName->Append(*(nsString *)paths[i]); + + char* fullRegNameCString = fullRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE) && (aVersionStr == "null") && + (VR_ValidateComponent(fullRegNameCString) == 0)) + { + VERSION versionStruct; + VR_GetVersion( fullRegNameCString, &versionStruct); + + //fix: when we have overloading! + nsInstallVersion* oldVer = new nsInstallVersion(); + oldVer->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + + newVersion->Init(aVersionStr); + + PRInt32 areTheyEqual; + newVersion->CompareTo(oldVer, &areTheyEqual); + delete newVersion; + + bInstall = ( areTheyEqual > 0 ); + + if (oldVer) + delete oldVer; + + } + else + { + // file doesn't exist or "forced" install + bInstall = PR_TRUE; + } + + delete [] fullRegNameCString; + + if (bInstall) + { + nsString *newJarSource = new nsString(aJarSource); + newJarSource->Append("/"); + newJarSource->Append(*(nsString *)paths[i]); + + nsString* newSubDir; + + if (subdirectory != "") + { + newSubDir = new nsString(subdirectory); + newSubDir->Append(*(nsString*)paths[i]); + } + else + { + newSubDir = new nsString(*(nsString*)paths[i]); + } + + ie = new nsInstallFile( this, + *fullRegName, + newVersion, + *newJarSource, + aFolder, + *newSubDir, + aForceMode, + &result); + delete fullRegName; + delete newJarSource; + delete newSubDir; + delete newVersion; + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + *aReturn = SaveError( result ); + return NS_OK; +} + +PRInt32 +nsInstall::AddDirectory(const nsString& aRegName, + const nsString& aVersion, + const nsString& aJarSource, + const nsString& aFolder, + const nsString& aSubdir, + PRInt32* aReturn) +{ + nsInstallFile* ie = nsnull; + PRInt32 result; + + // defaulting aForceMode to PR_FALSE; + PRBool aForceMode = PR_FALSE; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); + return NS_OK; + } + + result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + nsString* qualifiedRegName = nsnull; + + if ( aRegName == "" ) + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + nsString subdirectory(aSubdir); + + if (subdirectory != "") + { + subdirectory.Append("/"); + } + + PRBool bInstall; + + nsVector paths; + + result = ExtractDirEntries(aJarSource, &paths); + + PRInt32 pathsUpperBound = paths.GetUpperBound(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + for (int i=0; i< pathsUpperBound; i++) + { + nsInstallVersion* newVersion = new nsInstallVersion(); + + nsString *fullRegName = new nsString(*qualifiedRegName); + fullRegName->Append("/"); + fullRegName->Append(*(nsString *)paths[i]); + + char* fullRegNameCString = fullRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE) && (aVersion == "null") && + (VR_ValidateComponent(fullRegNameCString) == 0)) + { + VERSION versionStruct; + VR_GetVersion( fullRegNameCString, &versionStruct); + + //fix: when we have overloading! + nsInstallVersion* oldVer = new nsInstallVersion(); + oldVer->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + + newVersion->Init(aVersion); + + PRInt32 areTheyEqual; + newVersion->CompareTo(oldVer, &areTheyEqual); + delete newVersion; + + bInstall = ( areTheyEqual > 0 ); + + if (oldVer) + delete oldVer; + + } + else + { + // file doesn't exist or "forced" install + bInstall = PR_TRUE; + } + + delete [] fullRegNameCString; + + if (bInstall) + { + nsString *newJarSource = new nsString(aJarSource); + newJarSource->Append("/"); + newJarSource->Append(*(nsString *)paths[i]); + + nsString* newSubDir; + + if (subdirectory != "") + { + newSubDir = new nsString(subdirectory); + newSubDir->Append(*(nsString*)paths[i]); + } + else + { + newSubDir = new nsString(*(nsString*)paths[i]); + } + + ie = new nsInstallFile( this, + *fullRegName, + newVersion, + *newJarSource, + aFolder, + *newSubDir, + aForceMode, + &result); + delete fullRegName; + delete newJarSource; + delete newSubDir; + delete newVersion; + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + *aReturn = SaveError( result ); + return NS_OK; +} + +PRInt32 +nsInstall::AddDirectory(const nsString& aRegName, + nsIDOMInstallVersion* aVersion, + const nsString& aJarSource, + const nsString& aFolder, + const nsString& aSubdir, + PRInt32* aReturn) +{ + nsInstallFile* ie = nsnull; + PRInt32 result; + nsString aVersionStr; + + // defaulting aForceMode to PR_FALSE; + PRBool aForceMode = PR_FALSE; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); + return NS_OK; + } + + result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + nsString* qualifiedRegName = nsnull; + + if ( aRegName == "" ) + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + nsString subdirectory(aSubdir); + + if (subdirectory != "") + { + subdirectory.Append("/"); + } + + aVersion->ToString(aVersionStr); + + PRBool bInstall; + + nsVector paths; + + result = ExtractDirEntries(aJarSource, &paths); + + PRInt32 pathsUpperBound = paths.GetUpperBound(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + for (int i=0; i< pathsUpperBound; i++) + { + nsInstallVersion* newVersion = new nsInstallVersion(); + + nsString *fullRegName = new nsString(*qualifiedRegName); + fullRegName->Append("/"); + fullRegName->Append(*(nsString *)paths[i]); + + char* fullRegNameCString = fullRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE) && (aVersionStr == "null") && + (VR_ValidateComponent(fullRegNameCString) == 0)) + { + VERSION versionStruct; + VR_GetVersion( fullRegNameCString, &versionStruct); + + //fix: when we have overloading! + nsInstallVersion* oldVer = new nsInstallVersion(); + oldVer->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + + newVersion->Init(aVersionStr); + + PRInt32 areTheyEqual; + newVersion->CompareTo(oldVer, &areTheyEqual); + delete newVersion; + + bInstall = ( areTheyEqual > 0 ); + + if (oldVer) + delete oldVer; + + } + else + { + // file doesn't exist or "forced" install + bInstall = PR_TRUE; + } + + delete [] fullRegNameCString; + + if (bInstall) + { + nsString *newJarSource = new nsString(aJarSource); + newJarSource->Append("/"); + newJarSource->Append(*(nsString *)paths[i]); + + nsString* newSubDir; + + if (subdirectory != "") + { + newSubDir = new nsString(subdirectory); + newSubDir->Append(*(nsString*)paths[i]); + } + else + { + newSubDir = new nsString(*(nsString*)paths[i]); + } + + ie = new nsInstallFile( this, + *fullRegName, + newVersion, + *newJarSource, + aFolder, + *newSubDir, + aForceMode, + &result); + delete fullRegName; + delete newJarSource; + delete newSubDir; + delete newVersion; + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + *aReturn = SaveError( result ); + return NS_OK; +} + +PRInt32 +nsInstall::AddDirectory(const nsString& aRegName, + const nsString& aJarSource, + const nsString& aFolder, + const nsString& aSubdir, + PRInt32* aReturn) +{ + nsInstallFile* ie = nsnull; + PRInt32 result; + + // defaulting aForceMode to PR_FALSE; + PRBool aForceMode = PR_FALSE; + // defaulting aVersion to "null"; + nsString aVersion = "null"; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); + return NS_OK; + } + + result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + nsString* qualifiedRegName = nsnull; + + if ( aRegName == "" ) + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + nsString subdirectory(aSubdir); + + if (subdirectory != "") + { + subdirectory.Append("/"); + } + + PRBool bInstall; + + nsVector paths; + + result = ExtractDirEntries(aJarSource, &paths); + + PRInt32 pathsUpperBound = paths.GetUpperBound(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + for (int i=0; i< pathsUpperBound; i++) + { + nsInstallVersion* newVersion = new nsInstallVersion(); + + nsString *fullRegName = new nsString(*qualifiedRegName); + fullRegName->Append("/"); + fullRegName->Append(*(nsString *)paths[i]); + + char* fullRegNameCString = fullRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE) && (aVersion == "null") && + (VR_ValidateComponent(fullRegNameCString) == 0)) + { + VERSION versionStruct; + VR_GetVersion( fullRegNameCString, &versionStruct); + + //fix: when we have overloading! + nsInstallVersion* oldVer = new nsInstallVersion(); + oldVer->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + + newVersion->Init(aVersion); + + PRInt32 areTheyEqual; + newVersion->CompareTo(oldVer, &areTheyEqual); + delete newVersion; + + bInstall = ( areTheyEqual > 0 ); + + if (oldVer) + delete oldVer; + + } + else + { + // file doesn't exist or "forced" install + bInstall = PR_TRUE; + } + + delete [] fullRegNameCString; + + if (bInstall) + { + nsString *newJarSource = new nsString(aJarSource); + newJarSource->Append("/"); + newJarSource->Append(*(nsString *)paths[i]); + + nsString* newSubDir; + + if (subdirectory != "") + { + newSubDir = new nsString(subdirectory); + newSubDir->Append(*(nsString*)paths[i]); + } + else + { + newSubDir = new nsString(*(nsString*)paths[i]); + } + + ie = new nsInstallFile( this, + *fullRegName, + newVersion, + *newJarSource, + aFolder, + *newSubDir, + aForceMode, + &result); + delete fullRegName; + delete newJarSource; + delete newSubDir; + delete newVersion; + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + *aReturn = SaveError( result ); + return NS_OK; +} + +PRInt32 +nsInstall::AddDirectory(const nsString& aJarSource, + PRInt32* aReturn) +{ + nsInstallFile* ie = nsnull; + PRInt32 result; + + // defaulting aForceMode to PR_FALSE; + PRBool aForceMode = PR_FALSE; + // defaulting aVersion to "null"; + nsString aVersion = "null"; +// fix: aFolder should not default to "null". + nsString aFolder = "null"; + nsString aSubdir = ""; + nsString aRegName = ""; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError(nsInstall::INVALID_ARGUMENTS); + return NS_OK; + } + + result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + nsString* qualifiedRegName = nsnull; + if ( aRegName == "" ) { // Default subName = location in jar file @@ -442,7 +1264,6 @@ nsInstall::AddDirectory(const nsString& aRegName, delete qualifiedRegName; *aReturn = SaveError( result ); - return NS_OK; } @@ -561,6 +1382,588 @@ nsInstall::AddSubcomponent(const nsString& aRegName, return NS_OK; } +PRInt32 +nsInstall::AddSubcomponent(const nsString& aRegName, + nsIDOMInstallVersion* aVersion, + const nsString& aJarSource, + const nsString& aFolder, + const nsString& aTargetName, + PRBool aForceMode, + PRInt32* aReturn) +{ + nsInstallFile* ie; + nsString* qualifiedRegName = nsnull; + nsString aVersionStr; + + PRInt32 errcode = nsInstall::SUCCESS; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); + return NS_OK; + } + + PRInt32 result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + + if ( aRegName == "" ) + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + /* Check for existence of the newer version */ + + nsInstallVersion *newVersion = new nsInstallVersion(); + aVersion->ToString(aVersionStr); + newVersion->Init(aVersionStr); + + PRBool versionNewer = PR_FALSE; + char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE ) && (aVersionStr != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) + { + VERSION versionStruct; + + VR_GetVersion( qualifiedRegNameString, &versionStruct ); + + nsInstallVersion* oldVersion = new nsInstallVersion(); +// FIX. Once we move to XPConnect, we can have parameterized constructors. + oldVersion->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + PRInt32 areTheyEqual; + newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); + + if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) + versionNewer = PR_TRUE; + + if ( oldVersion ) + delete oldVersion; + } + else + { + versionNewer = PR_TRUE; + } + + + if (qualifiedRegNameString != nsnull) + delete [] qualifiedRegNameString; + + if (versionNewer) + { + ie = new nsInstallFile( this, + *qualifiedRegName, + newVersion, + aJarSource, + aFolder, + aTargetName, + aForceMode, + &errcode ); + + if (errcode == nsInstall::SUCCESS) + { + errcode = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + if (newVersion != nsnull) + delete newVersion; + + *aReturn = SaveError( errcode ); + return NS_OK; +} + +PRInt32 +nsInstall::AddSubcomponent(const nsString& aRegName, + const nsString& aVersion, + const nsString& aJarSource, + const nsString& aFolder, + const nsString& aTargetName, + PRInt32* aReturn) +{ + nsInstallFile* ie; + nsString* qualifiedRegName = nsnull; + PRBool aForceMode = PR_FALSE; + + PRInt32 errcode = nsInstall::SUCCESS; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); + return NS_OK; + } + + PRInt32 result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + + if ( aRegName == "" ) + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + /* Check for existence of the newer version */ + + nsInstallVersion *newVersion = new nsInstallVersion(); + newVersion->Init(aVersion); + + PRBool versionNewer = PR_FALSE; + char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE ) && (aVersion != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) + { + VERSION versionStruct; + + VR_GetVersion( qualifiedRegNameString, &versionStruct ); + + nsInstallVersion* oldVersion = new nsInstallVersion(); +// FIX. Once we move to XPConnect, we can have parameterized constructors. + oldVersion->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + PRInt32 areTheyEqual; + newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); + + if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) + versionNewer = PR_TRUE; + + if ( oldVersion ) + delete oldVersion; + } + else + { + versionNewer = PR_TRUE; + } + + + if (qualifiedRegNameString != nsnull) + delete [] qualifiedRegNameString; + + if (versionNewer) + { + ie = new nsInstallFile( this, + *qualifiedRegName, + newVersion, + aJarSource, + aFolder, + aTargetName, + aForceMode, + &errcode ); + + if (errcode == nsInstall::SUCCESS) + { + errcode = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + if (newVersion != nsnull) + delete newVersion; + + *aReturn = SaveError( errcode ); + return NS_OK; +} + +PRInt32 +nsInstall::AddSubcomponent(const nsString& aRegName, + nsIDOMInstallVersion* aVersion, + const nsString& aJarSource, + const nsString& aFolder, + const nsString& aTargetName, + PRInt32* aReturn) +{ + nsInstallFile* ie; + nsString* qualifiedRegName = nsnull; + PRBool aForceMode = PR_FALSE; + nsString aVersionStr; + + PRInt32 errcode = nsInstall::SUCCESS; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); + return NS_OK; + } + + PRInt32 result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + + if ( aRegName == "" ) + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + /* Check for existence of the newer version */ + + nsInstallVersion *newVersion = new nsInstallVersion(); + aVersion->ToString(aVersionStr); + newVersion->Init(aVersionStr); + + PRBool versionNewer = PR_FALSE; + char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE ) && (aVersionStr != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) + { + VERSION versionStruct; + + VR_GetVersion( qualifiedRegNameString, &versionStruct ); + + nsInstallVersion* oldVersion = new nsInstallVersion(); +// FIX. Once we move to XPConnect, we can have parameterized constructors. + oldVersion->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + PRInt32 areTheyEqual; + newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); + + if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) + versionNewer = PR_TRUE; + + if ( oldVersion ) + delete oldVersion; + } + else + { + versionNewer = PR_TRUE; + } + + + if (qualifiedRegNameString != nsnull) + delete [] qualifiedRegNameString; + + if (versionNewer) + { + ie = new nsInstallFile( this, + *qualifiedRegName, + newVersion, + aJarSource, + aFolder, + aTargetName, + aForceMode, + &errcode ); + + if (errcode == nsInstall::SUCCESS) + { + errcode = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + if (newVersion != nsnull) + delete newVersion; + + *aReturn = SaveError( errcode ); + return NS_OK; +} + +PRInt32 +nsInstall::AddSubcomponent(const nsString& aRegName, + const nsString& aJarSource, + const nsString& aFolder, + const nsString& aTargetName, + PRInt32* aReturn) +{ + nsInstallFile* ie; + nsString* qualifiedRegName = nsnull; + PRInt32 errcode = nsInstall::SUCCESS; + + // defaulting aForceMode to PR_FALSE and aVersion to "null" + PRBool aForceMode = PR_FALSE; + nsString aVersion = "null"; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); + return NS_OK; + } + + PRInt32 result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + + if ( aRegName == "" ) + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + /* Check for existence of the newer version */ + + nsInstallVersion *newVersion = new nsInstallVersion(); + newVersion->Init(aVersion); + + PRBool versionNewer = PR_FALSE; + char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE ) && (aVersion != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) + { + VERSION versionStruct; + + VR_GetVersion( qualifiedRegNameString, &versionStruct ); + + nsInstallVersion* oldVersion = new nsInstallVersion(); +// FIX. Once we move to XPConnect, we can have parameterized constructors. + oldVersion->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + PRInt32 areTheyEqual; + newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); + + if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) + versionNewer = PR_TRUE; + + if ( oldVersion ) + delete oldVersion; + } + else + { + versionNewer = PR_TRUE; + } + + + if (qualifiedRegNameString != nsnull) + delete [] qualifiedRegNameString; + + if (versionNewer) + { + ie = new nsInstallFile( this, + *qualifiedRegName, + newVersion, + aJarSource, + aFolder, + aTargetName, + aForceMode, + &errcode ); + + if (errcode == nsInstall::SUCCESS) + { + errcode = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + if (newVersion != nsnull) + delete newVersion; + + *aReturn = SaveError( errcode ); + return NS_OK; +} + +PRInt32 +nsInstall::AddSubcomponent(const nsString& aJarSource, + PRInt32* aReturn) +{ + nsInstallFile* ie; + nsString* qualifiedRegName = nsnull; + PRInt32 errcode = nsInstall::SUCCESS; + + // defaulting aRegName to "", aForceMode to PR_FALSE, and aVersion to "null" + nsString aTargetName = aJarSource; + nsString aRegName = ""; +// fix: aFolder should not default to "null". + nsString aFolder = "null"; + PRBool aForceMode = PR_FALSE; + nsString aVersion = "null"; + + if ( aJarSource == "null" || aFolder == "null") + { + *aReturn = SaveError( nsInstall::INVALID_ARGUMENTS ); + return NS_OK; + } + + PRInt32 result = SanityCheck(); + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + + if ( aRegName == "" ) + { + // Default subName = location in jar file + qualifiedRegName = GetQualifiedRegName( aJarSource ); + } + else + { + qualifiedRegName = GetQualifiedRegName( aRegName ); + } + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( BAD_PACKAGE_NAME ); + return NS_OK; + } + + /* Check for existence of the newer version */ + + nsInstallVersion *newVersion = new nsInstallVersion(); + newVersion->Init(aVersion); + + PRBool versionNewer = PR_FALSE; + char* qualifiedRegNameString = qualifiedRegName->ToNewCString(); + + if ( (aForceMode == PR_FALSE ) && (aVersion != "null") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) ) + { + VERSION versionStruct; + + VR_GetVersion( qualifiedRegNameString, &versionStruct ); + + nsInstallVersion* oldVersion = new nsInstallVersion(); +// FIX. Once we move to XPConnect, we can have parameterized constructors. + oldVersion->Init(versionStruct.major, + versionStruct.minor, + versionStruct.release, + versionStruct.build); + + PRInt32 areTheyEqual; + newVersion->CompareTo((nsInstallVersion*)oldVersion, &areTheyEqual); + + if ( areTheyEqual != nsIDOMInstallVersion::EQUAL ) + versionNewer = PR_TRUE; + + if ( oldVersion ) + delete oldVersion; + } + else + { + versionNewer = PR_TRUE; + } + + + if (qualifiedRegNameString != nsnull) + delete [] qualifiedRegNameString; + + if (versionNewer) + { + ie = new nsInstallFile( this, + *qualifiedRegName, + newVersion, + aJarSource, + aFolder, + aTargetName, + aForceMode, + &errcode ); + + if (errcode == nsInstall::SUCCESS) + { + errcode = ScheduleForInstall( ie ); + } + else + { + delete ie; + } + } + + if (qualifiedRegName != nsnull) + delete qualifiedRegName; + + if (newVersion != nsnull) + delete newVersion; + + *aReturn = SaveError( errcode ); + return NS_OK; +} + PRInt32 nsInstall::DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn) { @@ -647,7 +2050,29 @@ nsInstall::Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* a } *aReturn = SaveError(result); + return NS_OK; +} +PRInt32 +nsInstall::Execute(const nsString& aJarSource, PRInt32* aReturn) +{ + PRInt32 result = SanityCheck(); + nsString aArgs = ""; + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + nsInstallExecute* ie = new nsInstallExecute(this, aJarSource, aArgs, &result); + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ie ); + } + + *aReturn = SaveError(result); return NS_OK; } @@ -677,9 +2102,8 @@ nsInstall::FinalizeInstall(PRInt32* aReturn) if ( mUninstallPackage ) { - // The Version Registry is not real. FIX! - // - //VR_UninstallCreateNode( nsAutoCString(mRegistryPackageName), nsAutoCString(mUIName)); + VR_UninstallCreateNode( (char*)(const char*) nsAutoCString(mRegistryPackageName), + (char*)(const char*) nsAutoCString(mUIName)); } PRUint32 i=0; @@ -688,7 +2112,14 @@ nsInstall::FinalizeInstall(PRInt32* aReturn) ie = (nsInstallObject*)mInstalledFiles->Get(i); if (ie == NULL) continue; - + + char *objString = ie->toString(); + + if (mLogStream != nsnull) + *mLogStream << " " << objString << nsEndl; + + delete [] objString; + ie->Complete(); if (result != nsInstall::SUCCESS) @@ -701,6 +2132,15 @@ nsInstall::FinalizeInstall(PRInt32* aReturn) //SetProgressDialogThermo(++count); } + if (mLogStream) + { + nsString time; + GetTime(time); + + *mLogStream << nsEndl; + *mLogStream << " Finished Installation " << nsAutoCString(time) << nsEndl << nsEndl; + } + *aReturn = NS_OK; return NS_OK; } @@ -714,6 +2154,66 @@ nsInstall::Gestalt(const nsString& aSelector, PRInt32* aReturn) PRInt32 nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsString** aFolder) +{ + long err; + char* dir; + char* componentCString; + +// FIX: aSubdirectory is not processed at all in this function. + + *aFolder = nsnull; + + nsString *tempString = GetQualifiedPackageName( aComponentName ); + + if (tempString == nsnull) + return NS_OK; + + componentCString = tempString->ToNewCString(); + delete tempString; + + dir = (char*)PR_Malloc(MAXREGPATHLEN); + err = VR_GetDefaultDirectory( componentCString, MAXREGPATHLEN, dir ); + if (err != REGERR_OK) + { + PR_FREEIF(dir); + } + + + if ( dir == NULL ) + { + dir = (char*)PR_Malloc(MAXREGPATHLEN); + err = VR_GetPath( componentCString, MAXREGPATHLEN, dir ); + if (err != REGERR_OK) + { + PR_FREEIF(dir); + } + + if ( dir != nsnull ) + { + int i; + + nsString dirStr(dir); + if ( (i = dirStr.RFind(FILESEP)) > 0 ) + { + PR_FREEIF(dir); + dir = (char*)PR_Malloc(i); + dir = dirStr.ToCString(dir, i); + } + } + } + + if ( dir != NULL ) + { + *aFolder = new nsString(dir); + } + + PR_FREEIF(dir); + delete [] componentCString; + return NS_OK; +} + +PRInt32 +nsInstall::GetComponentFolder(const nsString& aComponentName, nsString** aFolder) { long err; char* dir; @@ -767,7 +2267,6 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS PR_FREEIF(dir); delete [] componentCString; - return NS_OK; } @@ -783,8 +2282,24 @@ nsInstall::GetFolder(const nsString& targetFolder, const nsString& aSubdirectory spec->GetDirectoryPath(dirString); *aFolder = new nsString(dirString); - + return NS_OK; +} +PRInt32 +nsInstall::GetFolder(const nsString& targetFolder, nsString** aFolder) +{ + nsInstallFolder* spec = nsnull; + *aFolder = nsnull; + + // defaulting aSubdirectory to "". + nsString aSubdirectory = ""; + + spec = new nsInstallFolder(targetFolder, aSubdirectory); + + nsString dirString; + spec->GetDirectoryPath(dirString); + + *aFolder = new nsString(dirString); return NS_OK; } @@ -844,7 +2359,91 @@ nsInstall::Patch(const nsString& aRegName, const nsString& aVersion, const nsStr } *aReturn = SaveError(result); + return NS_OK; +} +PRInt32 +nsInstall::Patch(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn) +{ + PRInt32 result = SanityCheck(); + nsString aVersionStr; + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + nsString* qualifiedRegName = GetQualifiedRegName( aRegName ); + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( nsInstall::BAD_PACKAGE_NAME ); + return NS_OK; + } + + nsInstallVersion *newVersion = new nsInstallVersion(); + aVersion->ToString(aVersionStr); + newVersion->Init(aVersionStr); + + nsInstallPatch* ip = new nsInstallPatch( this, + *qualifiedRegName, + newVersion, + aJarSource, + &result); + + + delete newVersion; + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ip ); + } + + *aReturn = SaveError(result); + return NS_OK; +} + +PRInt32 +nsInstall::Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn) +{ + PRInt32 result = SanityCheck(); + + // defaulting aVersion to "null"; + nsString aVersion = "null"; + + if (result != nsInstall::SUCCESS) + { + *aReturn = SaveError( result ); + return NS_OK; + } + + nsString* qualifiedRegName = GetQualifiedRegName( aRegName ); + + if (qualifiedRegName == nsnull) + { + *aReturn = SaveError( nsInstall::BAD_PACKAGE_NAME ); + return NS_OK; + } + + nsInstallVersion *newVersion = new nsInstallVersion(); + newVersion->Init(aVersion); + + nsInstallPatch* ip = new nsInstallPatch( this, + *qualifiedRegName, + newVersion, + aJarSource, + &result); + + + delete newVersion; + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ip ); + } + + *aReturn = SaveError(result); return NS_OK; } @@ -855,15 +2454,9 @@ nsInstall::ResetError() return NS_OK; } - PRInt32 nsInstall::SetPackageFolder(const nsString& aFolder) -{ - if (mPackageFolder != nsnull) - delete mPackageFolder; - - mPackageFolder = new nsString(aFolder); - +{//fix return NS_OK; } @@ -890,20 +2483,22 @@ nsInstall::SetPackageFolder(const nsString& aFolder) PRInt32 nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32 aFlags, PRInt32* aReturn) { +// FIX: aFlags is not processed. *aReturn = nsInstall::SUCCESS; ResetError(); mUserCancelled = PR_FALSE; - mUIName = aUserPackageName; - - if ( aPackageName.Equals("") ) + if ( aPackageName.Equals("") || aPackageName.EqualsIgnoreCase("null")) { *aReturn = nsInstall::INVALID_ARGUMENTS; return NS_OK; } + mUIName = aUserPackageName; + + nsString *tempString = GetQualifiedPackageName( aPackageName ); mRegistryPackageName.SetLength(0); @@ -945,6 +2540,282 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPacka { mRegistryPackageName = ""; // Reset! } + + nsSpecialSystemDirectory logFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); + logFile += "Install.log"; + + mLogStream = new nsOutputFileStream(logFile, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, 0744 ); + // XXX because PR_APPEND is broken + if (mLogStream == nsnull) + return NS_OK; + + mLogStream->seek(logFile.GetFileSize()); + + nsString time; + GetTime(time); + + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << nsAutoCString(mUIName) << nsEndl; + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << nsEndl; + *mLogStream << " Starting Installation at " << nsAutoCString(time) << nsEndl; + *mLogStream << nsEndl; + + return NS_OK; +} + +PRInt32 +nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, nsIDOMInstallVersion* aVersion, PRInt32 aFlags, PRInt32* aReturn) +{ +// FIX: aFlags is not processed. + *aReturn = nsInstall::SUCCESS; + nsString aVersionStr; + + ResetError(); + + mUserCancelled = PR_FALSE; + + if ( aPackageName.Equals("") || aPackageName.EqualsIgnoreCase("null")) + { + *aReturn = nsInstall::INVALID_ARGUMENTS; + return NS_OK; + } + + mUIName = aUserPackageName; + + + nsString *tempString = GetQualifiedPackageName( aPackageName ); + + mRegistryPackageName.SetLength(0); + mRegistryPackageName.Append( *tempString ); + + delete tempString; + + /* Check to see if the PackageName ends in a '/'. If it does nuke it. */ + + if (mRegistryPackageName.Last() == '/') + { + PRInt32 index = mRegistryPackageName.Length(); + mRegistryPackageName.Truncate(--index); + } + + if (mVersionInfo != nsnull) + delete mVersionInfo; + + mVersionInfo = new nsInstallVersion(); + aVersion->ToString(aVersionStr); + mVersionInfo->Init(aVersionStr); + + mInstalledFiles = new nsVector(); + mPatchList = new nsHashtable(); + + /* this function should also check security!!! */ + *aReturn = OpenJARFile(); + + if (*aReturn != nsInstall::SUCCESS) + { + /* if we can not continue with the javascript return a JAR error*/ + return -1; /* FIX: need real error code */ + } + + /* Show our window here */ + + SaveError(*aReturn); + + if (*aReturn != nsInstall::SUCCESS) + { + mRegistryPackageName = ""; // Reset! + } + + nsSpecialSystemDirectory logFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); + logFile += "Install.log"; + + mLogStream = new nsOutputFileStream(logFile, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, 0744 ); + // XXX because PR_APPEND is broken + if (mLogStream == nsnull) + return NS_OK; + + mLogStream->seek(logFile.GetFileSize()); + + nsString time; + GetTime(time); + + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << nsAutoCString(mUIName) << nsEndl; + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << nsEndl; + *mLogStream << " Starting Installation at " << nsAutoCString(time) << nsEndl; + *mLogStream << nsEndl; + + return NS_OK; +} + +PRInt32 +nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn) +{ +// FIX: aFlags is not processed. A default value needs to be used since this function does not accept an aFlags value. + *aReturn = nsInstall::SUCCESS; + + ResetError(); + + mUserCancelled = PR_FALSE; + + if ( aPackageName.Equals("") || aPackageName.EqualsIgnoreCase("null")) + { + *aReturn = nsInstall::INVALID_ARGUMENTS; + return NS_OK; + } + + mUIName = aUserPackageName; + + + nsString *tempString = GetQualifiedPackageName( aPackageName ); + + mRegistryPackageName.SetLength(0); + mRegistryPackageName.Append( *tempString ); + + delete tempString; + + /* Check to see if the PackageName ends in a '/'. If it does nuke it. */ + + if (mRegistryPackageName.Last() == '/') + { + PRInt32 index = mRegistryPackageName.Length(); + mRegistryPackageName.Truncate(--index); + } + + if (mVersionInfo != nsnull) + delete mVersionInfo; + + mVersionInfo = new nsInstallVersion(); + mVersionInfo->Init(aVersion); + + mInstalledFiles = new nsVector(); + mPatchList = new nsHashtable(); + + /* this function should also check security!!! */ + *aReturn = OpenJARFile(); + + if (*aReturn != nsInstall::SUCCESS) + { + /* if we can not continue with the javascript return a JAR error*/ + return -1; /* FIX: need real error code */ + } + + /* Show our window here */ + + SaveError(*aReturn); + + if (*aReturn != nsInstall::SUCCESS) + { + mRegistryPackageName = ""; // Reset! + } + + nsSpecialSystemDirectory logFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); + logFile += "Install.log"; + + mLogStream = new nsOutputFileStream(logFile, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, 0744 ); + // XXX because PR_APPEND is broken + if (mLogStream == nsnull) + return NS_OK; + + mLogStream->seek(logFile.GetFileSize()); + + nsString time; + GetTime(time); + + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << nsAutoCString(mUIName) << nsEndl; + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << nsEndl; + *mLogStream << " Starting Installation at " << nsAutoCString(time) << nsEndl; + *mLogStream << nsEndl; + + return NS_OK; +} + +PRInt32 +nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) +{ +// FIX: aFlags is not processed. A default value needs to be used since this function does not accept an aFlags value. + *aReturn = nsInstall::SUCCESS; + nsString aVersionStr; + + ResetError(); + + mUserCancelled = PR_FALSE; + + if ( aPackageName.Equals("") || aPackageName.EqualsIgnoreCase("null")) + { + *aReturn = nsInstall::INVALID_ARGUMENTS; + return NS_OK; + } + + mUIName = aUserPackageName; + + + nsString *tempString = GetQualifiedPackageName( aPackageName ); + + mRegistryPackageName.SetLength(0); + mRegistryPackageName.Append( *tempString ); + + delete tempString; + + /* Check to see if the PackageName ends in a '/'. If it does nuke it. */ + + if (mRegistryPackageName.Last() == '/') + { + PRInt32 index = mRegistryPackageName.Length(); + mRegistryPackageName.Truncate(--index); + } + + if (mVersionInfo != nsnull) + delete mVersionInfo; + + mVersionInfo = new nsInstallVersion(); + aVersion->ToString(aVersionStr); + mVersionInfo->Init(aVersionStr); + + mInstalledFiles = new nsVector(); + mPatchList = new nsHashtable(); + + /* this function should also check security!!! */ + *aReturn = OpenJARFile(); + + if (*aReturn != nsInstall::SUCCESS) + { + /* if we can not continue with the javascript return a JAR error*/ + return -1; /* FIX: need real error code */ + } + + /* Show our window here */ + + SaveError(*aReturn); + + if (*aReturn != nsInstall::SUCCESS) + { + mRegistryPackageName = ""; // Reset! + } + + nsSpecialSystemDirectory logFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); + logFile += "Install.log"; + + mLogStream = new nsOutputFileStream(logFile, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, 0744 ); + // XXX because PR_APPEND is broken + if (mLogStream == nsnull) + return NS_OK; + + mLogStream->seek(logFile.GetFileSize()); + + nsString time; + GetTime(time); + + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << nsAutoCString(mUIName) << nsEndl; + *mLogStream << "---------------------------------------------------------------------------" << nsEndl; + *mLogStream << nsEndl; + *mLogStream << " Starting Installation at " << nsAutoCString(time) << nsEndl; + *mLogStream << nsEndl; return NS_OK; } @@ -967,15 +2838,22 @@ nsInstall::Uninstall(const nsString& aPackageName, PRInt32* aReturn) *aReturn = SaveError( BAD_PACKAGE_NAME ); return NS_OK; } -// Create UNinstall object here FIX + + nsInstallUninstall *ie = new nsInstallUninstall( this, + *qualifiedPackageName, + &result ); + + if (result == nsInstall::SUCCESS) + { + result = ScheduleForInstall( ie ); + } + else + { + delete ie; + } delete qualifiedPackageName; - if (result == SUCCESS) - { -// result = ScheduleForInstall( ip ); - } - *aReturn = SaveError(result); return NS_OK; @@ -1021,8 +2899,8 @@ nsInstall::ScheduleForInstall(nsInstallObject* ob) // flash current item //SetProgressDialogItem( objString ); - - PR_FREEIF(objString); + + delete [] objString; // do any unpacking or other set-up error = ob->Prepare(); @@ -1047,7 +2925,15 @@ nsInstall::ScheduleForInstall(nsInstallObject* ob) return nsInstall::SUCCESS; } - +void +nsInstall::GetTime(nsString &aString) +{ + PRExplodedTime et; + char line[256]; + PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &et); + PR_FormatTimeUSEnglish(line, sizeof(line), "%m/%d/%Y %H:%M:%S", &et); + aString.SetString(line); +} /** * SanityCheck @@ -1235,7 +3121,6 @@ nsInstall::SaveError(PRInt32 errcode) * CleanUp * call it when done with the install * - * XXX: This is a synchronized method. FIX it. */ void nsInstall::CleanUp(void) @@ -1272,25 +3157,25 @@ nsInstall::CleanUp(void) void nsInstall::GetJarFileLocation(nsString& aFile) { - aFile=mJarFileLocation; + aFile = mJarFileLocation; } void nsInstall::SetJarFileLocation(const nsString& aFile) { - mJarFileLocation=aFile; + mJarFileLocation = aFile; } void nsInstall::GetInstallArguments(nsString& args) { - args=mInstallArguments; + args = mInstallArguments; } void nsInstall::SetInstallArguments(const nsString& args) { - mInstallArguments=args; + mInstallArguments = args; } @@ -1352,10 +3237,10 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa extractHereSpec = new nsFileSpec(*aSuggestedName); } - // FIX: We will overwrite what is in the way. is this something that we want to do? + // We will overwrite what is in the way. is this something that we want to do? extractHereSpec->Delete(PR_FALSE); - result = ZIP_ExtractFile( mJarFileData, nsAutoCString(aJarfile), extractHereSpec->GetCString() ); + result = ZIP_ExtractFile( mJarFileData, nsAutoCString(aJarfile), nsprPath( *extractHereSpec ) ); if (result == 0) { diff --git a/xpinstall/src/nsInstall.h b/xpinstall/src/nsInstall.h index 58f28e7f2143..a0a9664036ce 100644 --- a/xpinstall/src/nsInstall.h +++ b/xpinstall/src/nsInstall.h @@ -32,6 +32,8 @@ #include "jsapi.h" +#include "plevent.h" + #include "nsString.h" #include "nsFileSpec.h" #include "nsVector.h" @@ -61,6 +63,9 @@ class nsInstallInfo PRBool IsMultipleTrigger(); + PLEventQueue* GetUIEventQueue(void) const { return mUIEventQueue; } + void SetUIEventQueue(PLEventQueue* queue) { mUIEventQueue = queue; } + private: void DeleteVector(nsVector* vector); @@ -77,6 +82,8 @@ class nsInstallInfo nsVector *mFromURLs; nsVector *mLocalFiles; + + PLEventQueue *mUIEventQueue; // this should be moved to private and have accessors }; @@ -139,22 +146,40 @@ class nsInstall PRInt32 AbortInstall(); PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn); + PRInt32 AddDirectory(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn); + PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn); + PRInt32 AddDirectory(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn); + PRInt32 AddDirectory(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn); + PRInt32 AddDirectory(const nsString& aJarSource, PRInt32* aReturn); PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn); + PRInt32 AddSubcomponent(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn); + PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); + PRInt32 AddSubcomponent(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); + PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); + PRInt32 AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn); PRInt32 DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn); PRInt32 DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName, PRInt32* aReturn); PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRInt32* aReturn); PRInt32 Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn); + PRInt32 Execute(const nsString& aJarSource, PRInt32* aReturn); PRInt32 FinalizeInstall(PRInt32* aReturn); PRInt32 Gestalt(const nsString& aSelector, PRInt32* aReturn); PRInt32 GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsString** aFolder); + PRInt32 GetComponentFolder(const nsString& aComponentName, nsString** aFolder); PRInt32 GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsString** aFolder); + PRInt32 GetFolder(const nsString& aTargetFolder, nsString** aFolder); PRInt32 GetLastError(PRInt32* aReturn); PRInt32 GetWinProfile(const nsString& aFolder, const nsString& aFile, PRInt32* aReturn); PRInt32 GetWinRegistry(PRInt32* aReturn); PRInt32 Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); + PRInt32 Patch(const nsString& aRegName, nsIDOMInstallVersion* aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); + PRInt32 Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn); PRInt32 ResetError(); PRInt32 SetPackageFolder(const nsString& aFolder); PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32 aFlags, PRInt32* aReturn); + PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, nsIDOMInstallVersion* aVersion, PRInt32 aFlags, PRInt32* aReturn); + PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn); + PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn); @@ -186,18 +211,19 @@ class nsInstall nsString mRegistryPackageName; /* Name of the package we are installing */ nsString mUIName; /* User-readable package name */ - nsInstallVersion* mVersionInfo; /* Component version info */ - - nsString* mPackageFolder; + nsInstallVersion* mVersionInfo; /* Component version info */ nsVector* mInstalledFiles; nsHashtable* mPatchList; - + + nsOutputFileStream *mLogStream; + PRInt32 mLastError; void ParseFlags(int flags); PRInt32 SanityCheck(void); - + void GetTime(nsString &aString); + nsString * GetQualifiedRegName( const nsString& name ); nsString* GetQualifiedPackageName( const nsString& name ); nsString* CurrentUserNode(); @@ -215,4 +241,4 @@ class nsInstall }; -#endif \ No newline at end of file +#endif diff --git a/xpinstall/src/nsInstallDelete.cpp b/xpinstall/src/nsInstallDelete.cpp index 2fb90626575c..0d4afa87d24a 100644 --- a/xpinstall/src/nsInstallDelete.cpp +++ b/xpinstall/src/nsInstallDelete.cpp @@ -31,6 +31,7 @@ #include "VerReg.h" #include "ScheduledTasks.h" #include "nsInstallDelete.h" +#include "nsInstallResources.h" #include "nsInstall.h" #include "nsIDOMInstallVersion.h" @@ -125,7 +126,19 @@ void nsInstallDelete::Abort() char* nsInstallDelete::toString() { - return nsnull; + char* buffer = new char[1024]; + + if (mDeleteStatus == DELETE_COMPONENT) + { + sprintf( buffer, nsInstallResources::GetDeleteComponentString(), nsAutoCString(mRegistryName)); + } + else + { + if (mFinalFile) + sprintf( buffer, nsInstallResources::GetDeleteFileString(), mFinalFile->GetCString()); + } + + return buffer; } @@ -209,14 +222,7 @@ PRInt32 nsInstallDelete::NativeComplete() { if (mFinalFile->IsFile()) { - mFinalFile->Delete(false); - - if (mFinalFile->Exists()) - { - // If file still exists, we need to delete it later! - DeleteFileLater(mFinalFile->GetCString()); - return nsInstall::REBOOT_NEEDED; - } + return DeleteFileLater(*mFinalFile); } else { diff --git a/xpinstall/src/nsInstallExecute.cpp b/xpinstall/src/nsInstallExecute.cpp index 247cc54c6dbe..946838b82ef4 100644 --- a/xpinstall/src/nsInstallExecute.cpp +++ b/xpinstall/src/nsInstallExecute.cpp @@ -31,7 +31,7 @@ #include "VerReg.h" #include "nsInstallExecute.h" - +#include "nsInstallResources.h" #include "ScheduledTasks.h" #include "nsInstall.h" @@ -87,7 +87,7 @@ PRInt32 nsInstallExecute::Complete() PRInt32 result = app.Execute( mArgs ); - DeleteFileLater(app.GetCString()); + DeleteFileLater( app ); return result; } @@ -98,17 +98,17 @@ void nsInstallExecute::Abort() if (mExecutableFile == nsnull) return; - mExecutableFile->Delete(PR_FALSE); - - if ( mExecutableFile->Exists() ) - { - DeleteFileLater(mExecutableFile->GetCString()); - } + DeleteFileLater(*mExecutableFile); } char* nsInstallExecute::toString() { - return nsnull; + char* buffer = new char[1024]; + + sprintf( buffer, nsInstallResources::GetExecuteString(), mExecutableFile->GetCString()); + + return buffer; + } diff --git a/xpinstall/src/nsInstallFile.cpp b/xpinstall/src/nsInstallFile.cpp index 04bc017217ef..1076fd9f66af 100644 --- a/xpinstall/src/nsInstallFile.cpp +++ b/xpinstall/src/nsInstallFile.cpp @@ -29,6 +29,7 @@ #include "ScheduledTasks.h" #include "nsInstall.h" #include "nsInstallVersion.h" +#include "nsInstallResources.h" /* Public Methods */ @@ -62,6 +63,8 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, mFinalFile = new nsFileSpec(folderSpec); *mFinalFile += inPartialPath; + mReplaceFile = mFinalFile->Exists(); + mForceInstall = forceInstall; mVersionRegistryName = new nsString(inComponentName); @@ -162,7 +165,24 @@ void nsInstallFile::Abort() char* nsInstallFile::toString() { - return nsnull; + char* buffer = new char[1024]; + + if (mFinalFile == nsnull) + { + sprintf( buffer, nsInstallResources::GetInstallFileString(), nsnull); + } + else if (mReplaceFile) + { + // we are replacing this file. + + sprintf( buffer, nsInstallResources::GetReplaceFileString(), mFinalFile->GetCString()); + } + else + { + sprintf( buffer, nsInstallResources::GetInstallFileString(), mFinalFile->GetCString()); + } + + return buffer; } @@ -182,41 +202,7 @@ PRInt32 nsInstallFile::CompleteFileMove() } else { - if (mFinalFile->Exists() == PR_FALSE) - { - // We can simple move the extracted file to the mFinalFile's parent - nsFileSpec parentofFinalFile; - - mFinalFile->GetParent(parentofFinalFile); - result = mExtracedFile->Move(parentofFinalFile); - - char* leafName = mFinalFile->GetLeafName(); - mExtracedFile->Rename(leafName); - nsCRT::free(leafName); - - } - else - { - mFinalFile->Delete(PR_FALSE); - - if (! mFinalFile->Exists()) - { - // Now that we have move the existing file, we can move the mExtracedFile into place. - nsFileSpec parentofFinalFile; - - mFinalFile->GetParent(parentofFinalFile); - result = mExtracedFile->Move(parentofFinalFile); - - char* leafName = mFinalFile->GetLeafName(); - mExtracedFile->Rename(leafName); - nsCRT::free(leafName); - } - else - { - ReplaceFileLater(mExtracedFile->GetCString(), mFinalFile->GetCString() ); - result = nsInstall::REBOOT_NEEDED; - } - } + result = ReplaceFileLater(*mExtracedFile, *mFinalFile ); } return result; @@ -225,33 +211,24 @@ PRInt32 nsInstallFile::CompleteFileMove() PRInt32 nsInstallFile::RegisterInVersionRegistry() { - PRInt32 err; int refCount; - int rc; - char* tempCString; - - char *final_file = (char*)mFinalFile->GetCString(); // FIX: mac? What should we be passing to the version registry: native of unix??? - char *vr_name = mVersionRegistryName->ToNewCString(); - nsString regPackageName; mInstall->GetRegPackageName(regPackageName); // Register file and log for Uninstall - // we ignore all registry errors because they're not - // important enough to abort an otherwise OK install. if (!mChildFile) { int found; if (regPackageName != "") { - tempCString = regPackageName.ToNewCString(); - found = VR_UninstallFileExistsInList( tempCString , vr_name ); + found = VR_UninstallFileExistsInList( (char*)(const char*)nsAutoCString(regPackageName) , + (char*)(const char*)nsAutoCString(*mVersionRegistryName)); } else { - found = VR_UninstallFileExistsInList( "", vr_name ); + found = VR_UninstallFileExistsInList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) ); } if (found != REGERR_OK) @@ -259,7 +236,7 @@ nsInstallFile::RegisterInVersionRegistry() else mUpgradeFile = PR_TRUE; } - else if (REGERR_OK == VR_InRegistry(vr_name)) + else if (REGERR_OK == VR_InRegistry( (char*)(const char*)nsAutoCString(*mVersionRegistryName))) { mUpgradeFile = PR_TRUE; } @@ -268,89 +245,52 @@ nsInstallFile::RegisterInVersionRegistry() mUpgradeFile = PR_FALSE; } - err = VR_GetRefCount( vr_name, &refCount ); - if ( err != REGERR_OK ) + if ( REGERR_OK != VR_GetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), &refCount )) { refCount = 0; } + VR_Install( (char*)(const char*)nsAutoCString(*mVersionRegistryName), + (char*)(const char*)nsprPath(*mFinalFile), + (char*)(const char*)nsAutoCString(regPackageName), + PR_FALSE ); + if (!mUpgradeFile) { if (refCount != 0) { - rc = 1 + refCount; - nsString tempString; - mVersionInfo->ToString(tempString); - tempCString = regPackageName.ToNewCString(); - VR_Install( vr_name, final_file, tempCString, PR_FALSE ); - VR_SetRefCount( vr_name, rc ); + VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount + 1 ); } else { if (mFinalFile->Exists()) - { - nsString tempString; - mVersionInfo->ToString(tempString); - tempCString = regPackageName.ToNewCString(); - VR_Install( vr_name, final_file, tempCString, PR_FALSE); - VR_SetRefCount( vr_name, 2 ); - } + VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 2 ); else - { - nsString tempString; - mVersionInfo->ToString(tempString); - tempCString = regPackageName.ToNewCString(); - VR_Install( vr_name, final_file, tempCString, PR_FALSE ); - VR_SetRefCount( vr_name, 1 ); - } + VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 ); } } - else if (mUpgradeFile) + else { if (refCount == 0) - { - nsString tempString; - mVersionInfo->ToString(tempString); - tempCString = regPackageName.ToNewCString(); - VR_Install( vr_name, final_file, tempCString, PR_FALSE ); - VR_SetRefCount( vr_name, 1 ); - } + VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 ); else - { - nsString tempString; - mVersionInfo->ToString(tempString); - tempCString = regPackageName.ToNewCString(); - VR_Install( vr_name, final_file, tempCString, PR_FALSE ); - VR_SetRefCount( vr_name, 0 ); - } + VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 0 ); } if ( !mChildFile && !mUpgradeFile ) { if (regPackageName != "") - { - if (tempCString == nsnull) - tempCString = regPackageName.ToNewCString(); - - VR_UninstallAddFileToList( tempCString, vr_name ); + { + VR_UninstallAddFileToList( (char*)(const char*)nsAutoCString(regPackageName), + (char*)(const char*)nsAutoCString(*mVersionRegistryName)); } else { - VR_UninstallAddFileToList( "", vr_name ); + VR_UninstallAddFileToList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) ); } } - if (vr_name != nsnull) - delete [] vr_name; - - if (tempCString != nsnull) - delete [] tempCString; - - if ( err != 0 ) - return nsInstall::UNEXPECTED_ERROR; - return nsInstall::SUCCESS; - } /* CanUninstall diff --git a/xpinstall/src/nsInstallFile.h b/xpinstall/src/nsInstallFile.h index f31bb8624a64..1b13801e7108 100644 --- a/xpinstall/src/nsInstallFile.h +++ b/xpinstall/src/nsInstallFile.h @@ -81,7 +81,6 @@ class nsInstallFile : public nsInstallObject nsString* mVersionRegistryName; /* full version path */ PRBool mForceInstall; /* whether install is forced */ - PRBool mJavaInstall; /* whether file is installed to a Java directory */ PRBool mReplaceFile; /* whether file exists */ PRBool mChildFile; /* whether file is a child */ PRBool mUpgradeFile; /* whether file is an upgrade */ diff --git a/xpinstall/src/nsInstallFolder.cpp b/xpinstall/src/nsInstallFolder.cpp index 9aee26e59ec0..22d8ef32feca 100644 --- a/xpinstall/src/nsInstallFolder.cpp +++ b/xpinstall/src/nsInstallFolder.cpp @@ -82,42 +82,41 @@ nsInstallFolder::nsInstallFolder(const nsString& aFolderID) nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath) { - mUrlPath = nsnull; - - if ( aFolderID == "null") - { - return; - } - + mFileSpec = nsnull; SetDirectoryPath( aFolderID, aRelativePath); } nsInstallFolder::~nsInstallFolder() { - if (mUrlPath != nsnull) - delete mUrlPath; + if (mFileSpec != nsnull) + delete mFileSpec; } void nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath) { - // We want the a NATIVE path. aDirectoryPath.SetLength(0); - aDirectoryPath.Append(mUrlPath->GetCString()); + + if (mFileSpec != nsnull) + { + // We want the a NATIVE path. + aDirectoryPath.SetString(mFileSpec->GetCString()); + } } - void nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath) { if ( aFolderID.EqualsIgnoreCase("User Pick") ) { PickDefaultDirectory(); + return; } else if ( aFolderID.EqualsIgnoreCase("Installed") ) { - mUrlPath = new nsFileSpec(aRelativePath, PR_TRUE); // creates the directories to the relative path. + mFileSpec = new nsFileSpec(aRelativePath, PR_TRUE); // creates the directories to the relative path. + return; } else { @@ -134,7 +133,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe break; case 102: /////////////////////////////////////////////////////////// Communicator - // FIX + *this = nsSpecialSystemDirectory::OS_CurrentProcessDirectory; // FIX? break; case 103: /////////////////////////////////////////////////////////// User Pick @@ -228,14 +227,27 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe case -1: default: - break; + return; } +#ifndef XP_MAC + if (aRelativePath.Length() > 0) + { + nsString tempPath(aRelativePath); + + if (aRelativePath.Last() != '/' || aRelativePath.Last() != '\\') + tempPath += '/'; + + *mFileSpec += tempPath; + } +#endif + // make sure that the directory is created. + nsFileSpec(mFileSpec->GetCString(), PR_TRUE); } } void nsInstallFolder::PickDefaultDirectory() { - //FIX: Need to put up a dialog here and set mUrlPath + //FIX: Need to put up a dialog here and set mFileSpec return; } @@ -265,5 +277,5 @@ void nsInstallFolder::operator = (enum nsSpecialSystemDirectory::SystemDirectori //---------------------------------------------------------------------------------------- { nsSpecialSystemDirectory temp(aSystemSystemDirectory); - mUrlPath = new nsFileSpec(temp); -} \ No newline at end of file + mFileSpec = new nsFileSpec(temp); +} diff --git a/xpinstall/src/nsInstallFolder.h b/xpinstall/src/nsInstallFolder.h index cca6f4cc2987..0548dc85a507 100644 --- a/xpinstall/src/nsInstallFolder.h +++ b/xpinstall/src/nsInstallFolder.h @@ -46,7 +46,7 @@ class nsInstallFolder private: - nsFileSpec* mUrlPath; + nsFileSpec* mFileSpec; void SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath); void PickDefaultDirectory(); diff --git a/xpinstall/src/nsInstallPatch.cpp b/xpinstall/src/nsInstallPatch.cpp index 5fd421a5aa10..d35c441e501a 100644 --- a/xpinstall/src/nsInstallPatch.cpp +++ b/xpinstall/src/nsInstallPatch.cpp @@ -20,10 +20,44 @@ #include "prmem.h" #include "nsInstall.h" #include "nsInstallPatch.h" +#include "nsInstallResources.h" #include "nsIDOMInstallVersion.h" +#include "zlib.h" + +#include "gdiff.h" #include "VerReg.h" #include "ScheduledTasks.h" +#include "plstr.h" +#include "xp_file.h" /* for XP_PlatformFileToURL */ + + +#ifdef XP_MAC +#include "PatchableAppleSingle.h" +#endif + +#define BUFSIZE 32768 +#define OPSIZE 1 +#define MAXCMDSIZE 12 +#define SRCFILE 0 +#define OUTFILE 1 + +#define getshort(s) (uint16)( ((uchar)*(s) << 8) + ((uchar)*((s)+1)) ) + +#define getlong(s) \ + (uint32)( ((uchar)*(s) << 24) + ((uchar)*((s)+1) << 16 ) + \ + ((uchar)*((s)+2) << 8) + ((uchar)*((s)+3)) ) + + + +static int32 gdiff_parseHeader( pDIFFDATA dd ); +static int32 gdiff_validateFile( pDIFFDATA dd, int file ); +static int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum ); +static int32 gdiff_ApplyPatch( pDIFFDATA dd ); +static int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length ); +static int32 gdiff_add( pDIFFDATA dd, uint32 count ); +static int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count ); +static int32 gdiff_validateFile( pDIFFDATA dd, int file ); nsInstallPatch::nsInstallPatch( nsInstall* inInstall, @@ -34,7 +68,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, : nsInstallObject(inInstall) { - char* tempTargetFile = new char[MAXREGPATHLEN]; + char tempTargetFile[MAXREGPATHLEN]; char* tempVersionString = inVRName.ToNewCString(); PRInt32 err = VR_GetPath(tempVersionString, MAXREGPATHLEN, tempTargetFile ); @@ -43,17 +77,25 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, if (err != REGERR_OK) { - if(tempTargetFile) - delete [] tempTargetFile; - *error = nsInstall::NO_SUCH_COMPONENT; return; } + nsString folderSpec(tempTargetFile); + + mPatchFile = nsnull; + mTargetFile = nsnull; + mPatchedFile = nsnull; + mRegistryName = new nsString(inVRName); + mJarLocation = new nsString(inJarLocation); + + nsString tempString; + inVInfo->ToString(tempString); + mVersionInfo = new nsInstallVersion(); + mVersionInfo->Init(tempString); - - nsInstallPatch( inInstall, inVRName, inVInfo, inJarLocation, nsString(tempTargetFile), "null", error); + + mTargetFile = new nsFileSpec(folderSpec); - delete [] tempTargetFile; } @@ -169,20 +211,12 @@ PRInt32 nsInstallPatch::Prepare() return err; } - if ( mPatchedFile != nsnull ) - { - mInstall->AddPatch(&ikey, mPatchedFile ); - } - else - { - // This is a wierd state. NativePatch should have generated an error here. Is there any - // reason why we return a Invalid_Arg error here? - err = nsInstall::INVALID_ARGUMENTS; - } - + PR_ASSERT(mPatchedFile != nsnull); + mInstall->AddPatch(&ikey, mPatchedFile ); + if ( deleteOldSrc ) { - NativeDeleteFile( fileName ); + DeleteFileLater(*fileName ); } return err; @@ -205,7 +239,7 @@ PRInt32 nsInstallPatch::Complete() if (fileName != nsnull && (*fileName == *mPatchedFile) ) { // the patch has not been superceded--do final replacement - err = NativeReplace( *mTargetFile, *mPatchedFile ); + err = ReplaceFileLater( *mTargetFile, *mPatchedFile); if ( 0 == err || nsInstall::REBOOT_NEEDED == err ) { nsString tempVersionString; @@ -215,7 +249,7 @@ PRInt32 nsInstallPatch::Complete() char* tempVersion = tempVersionString.ToNewCString(); err = VR_Install( tempRegName, - (char*)mTargetFile->GetCString(), + (char*) (const char *) nsprPath(*mTargetFile), tempVersion, PR_FALSE ); @@ -246,14 +280,17 @@ void nsInstallPatch::Abort() if (fileName != nsnull && (*fileName == *mPatchedFile) ) { - NativeDeleteFile( mPatchedFile ); + DeleteFileLater( *mPatchedFile ); } } char* nsInstallPatch::toString() { - //return GetString1(DETAILS_PATCH, targetfile); - return nsnull; + char* buffer = new char[1024]; + + // FIX! sprintf( buffer, nsInstallResources::GetPatchFileString(), mPatchedFile->GetCString()); + + return buffer; } @@ -269,61 +306,248 @@ nsInstallPatch::RegisterPackageNode() return PR_FALSE; } -PRInt32 -nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile) -{ - return -1; -} PRInt32 -nsInstallPatch::NativeDeleteFile(nsFileSpec* doomedFile) +nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchFile, nsFileSpec **newFile) { - if (doomedFile->Exists()) - { - if (doomedFile->IsFile()) - { - doomedFile->Delete(false); - if (doomedFile->Exists()) - { - // If file still exists, we need to delete it later! - DeleteFileLater(doomedFile->GetCString()); - return nsInstall::REBOOT_NEEDED; - } + DIFFDATA *dd; + PRInt32 status = GDIFF_ERR_MEM; + char *tmpurl = NULL; + char *realfile = PL_strdup(nsprPath(sourceFile)); // needs to be sourceFile!!! + nsFileSpec outFileSpec = sourceFile; + + dd = (DIFFDATA *)PR_Calloc( 1, sizeof(DIFFDATA)); + if (dd != NULL) + { + dd->databuf = (uchar*)PR_Malloc(BUFSIZE); + if (dd->databuf == NULL) + { + status = GDIFF_ERR_MEM; + goto cleanup; + } + + + dd->bufsize = BUFSIZE; + + // validate patch header & check for special instructions + dd->fDiff = PR_Open (nsprPath(patchFile), PR_RDONLY, 0666); + + + if (dd->fDiff != NULL) + { + status = gdiff_parseHeader(dd); + } else { + status = GDIFF_ERR_ACCESS; + } + +#ifdef dono +#ifdef WIN32 + + /* unbind Win32 images */ + if ( dd->bWin32BoundImage && status == GDIFF_OK ) { + tmpurl = WH_TempName( xpURL, NULL ); + if ( tmpurl != NULL ) { + if (su_unbind( srcfile, srctype, tmpurl, xpURL )) + { + PL_strfree(realfile); + realfile = tmpurl; + realtype = xpURL; + + } + } + else + status = GDIFF_ERR_MEM; } - else - { - return nsInstall::FILE_IS_DIRECTORY; +#endif +#endif + +#ifdef XP_MAC + + if ( dd->bMacAppleSingle && status == GDIFF_OK ) + { + // create a tmp file, so that we can AppleSingle the src file + nsSpecialSystemDirectory tempMacFile(nsSpecialSystemDirectory::OS_TemporaryDirectory); + nsString srcName = sourceFile.GetLeafName(); + tempMacFile.SetLeafName(srcName); + tempMacFile.MakeUnique(); + + // Encode! + // Encode src file, and put into temp file + FSSpec sourceSpec = sourceFile.GetFSSpec(); + FSSpec tempSpec = tempMacFile.GetFSSpec(); + + status = PAS_EncodeFile(&sourceSpec, &tempSpec); + + if (status == noErr) + { + // set + PL_strfree(realfile); + realfile = PL_strdup(nsprPath(tempMacFile)); + } + } +#endif + + + + if (status != NS_OK) + goto cleanup; + + // make a unique file at the same location of our source file (FILENAME-ptch.EXT) + nsString patchFileName = "-ptch"; + nsString newFileName = sourceFile.GetLeafName(); + + PRInt32 index; + if ((index = newFileName.RFind(".")) > 0) + { + nsString extention; + nsString fileName; + newFileName.Right(extention, (newFileName.Length() - index) ); + newFileName.Left(fileName, (newFileName.Length() - (newFileName.Length() - index))); + newFileName = fileName + patchFileName + extention; + + } else { + newFileName += patchFileName; } - } - - return nsInstall::FILE_DOES_NOT_EXIST; -} - -PRInt32 -nsInstallPatch::NativeReplace(const nsFileSpec& oldfile, nsFileSpec& newFile) -{ - - oldfile.Delete(PR_FALSE); - if (oldfile.Exists()) - { - ReplaceFileLater(newFile.GetCString(), oldfile.GetCString() ); - return nsInstall::REBOOT_NEEDED; - } - else - { - // We can simple move the extracted file to the mFinalFile's parent - nsFileSpec parentofFinalFile; - - oldfile.GetParent(parentofFinalFile); - newFile.Move(parentofFinalFile); - char* leafName = newFile.GetLeafName(); - newFile.Rename(leafName); - nsCRT::free(leafName); + + outFileSpec.SetLeafName(newFileName); //???? + outFileSpec.MakeUnique(); + + char *outFile = PL_strdup(nsprPath(outFileSpec)); + + // apply patch to the source file + dd->fSrc = PR_Open ( realfile, PR_RDONLY, 0666); + dd->fOut = PR_Open ( outFile, PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666); + + if (dd->fSrc != NULL && dd->fOut != NULL) + { + status = gdiff_validateFile (dd, SRCFILE); + + // specify why diff failed + if (status == GDIFF_ERR_CHECKSUM) + status = GDIFF_ERR_CHECKSUM_TARGET; + + if (status == GDIFF_OK) + status = gdiff_ApplyPatch(dd); + + if (status == GDIFF_OK) + status = gdiff_validateFile (dd, OUTFILE); + + if (status == GDIFF_ERR_CHECKSUM) + status = GDIFF_ERR_CHECKSUM_RESULT; + + if (status == GDIFF_OK) + { + *newFile = &outFileSpec; + if ( outFile != nsnull) + PL_strfree( outFile ); + } + + } else { + + status = GDIFF_ERR_ACCESS; + } + } + + + +#ifdef XP_MAC + if ( dd->bMacAppleSingle && status == GDIFF_OK ) + { + // create another file, so that we can decode somewhere + nsFileSpec anotherName = outFileSpec; + anotherName.MakeUnique(); + + // Close the out file so that we can read it + PR_Close( dd->fOut ); + dd->fOut = NULL; + + + FSSpec outSpec = outFileSpec.GetFSSpec(); + FSSpec anotherSpec = anotherName.GetFSSpec(); + + + status = PAS_DecodeFile(&outSpec, &anotherSpec); + if (status != noErr) + { + goto cleanup; + } + + nsFileSpec parent; + + outFileSpec.GetParent(parent); + + outFileSpec.Delete(PR_FALSE); + anotherName.Copy(parent); + + *newFile = &anotherName; + } + +#endif + + +cleanup: + if ( dd != NULL ) + { + if ( dd->fSrc != nsnull ) + PR_Close( dd->fSrc ); + + + if ( dd->fDiff != nsnull ) + PR_Close( dd->fDiff ); + + if ( dd->fOut != nsnull ) + { + PR_Close( dd->fOut ); + } + + if ( status != GDIFF_OK ) + //XP_FileRemove( outfile, outtype ); + newFile = NULL; + + PR_FREEIF( dd->databuf ); + PR_FREEIF( dd->oldChecksum ); + PR_FREEIF( dd->newChecksum ); + PR_DELETE(dd); + } + + if ( tmpurl != NULL ) { + //XP_FileRemove( tmpurl, xpURL ); + tmpurl = NULL; + PR_DELETE( tmpurl ); } - return nsInstall::SUCCESS; + /* lets map any GDIFF error to nice SU errors */ + + switch (status) + { + case GDIFF_OK: + break; + case GDIFF_ERR_HEADER: + case GDIFF_ERR_BADDIFF: + case GDIFF_ERR_OPCODE: + case GDIFF_ERR_CHKSUMTYPE: + status = nsInstall::PATCH_BAD_DIFF; + break; + case GDIFF_ERR_CHECKSUM_TARGET: + status = nsInstall::PATCH_BAD_CHECKSUM_TARGET; + break; + case GDIFF_ERR_CHECKSUM_RESULT: + status = nsInstall::PATCH_BAD_CHECKSUM_RESULT; + break; + case GDIFF_ERR_OLDFILE: + case GDIFF_ERR_ACCESS: + case GDIFF_ERR_MEM: + case GDIFF_ERR_UNKNOWN: + default: + status = nsInstall::UNEXPECTED_ERROR; + break; + } + + return status; + + // return -1; //old return value } @@ -331,20 +555,438 @@ void* nsInstallPatch::HashFilePath(const nsFilePath& aPath) { PRUint32 rv = 0; - const char* cPath = aPath; + + char* cPath = PL_strdup(nsprPath(aPath)); if(cPath != nsnull) { char ch; - char* filePath = nsnull; - strcpy(filePath, cPath); + char* filePath = PL_strdup(cPath); + PRUint32 cnt=0; while ((ch = *filePath++) != 0) { // FYI: rv = rv*37 + ch rv = ((rv << 5) + (rv << 2) + rv) + ch; + cnt++; } - PR_Free(filePath); + + for (PRUint32 i=0; i<=cnt; i++) + *filePath--; + PL_strfree(filePath); } + + PL_strfree(cPath); + return (void*)rv; } + + + + +/*--------------------------------------------------------- + * gdiff_parseHeader() + * + * reads and validates the GDIFF header info + *--------------------------------------------------------- + */ +static +int32 gdiff_parseHeader( pDIFFDATA dd ) +{ + int32 err = GDIFF_OK; + uint8 cslen; + uint8 oldcslen; + uint8 newcslen; + uint32 nRead; + uchar header[GDIFF_HEADERSIZE]; + + /* Read the fixed-size part of the header */ + + nRead = PR_Read (dd->fDiff, header, GDIFF_HEADERSIZE); + if ( nRead != GDIFF_HEADERSIZE || + memcmp( header, GDIFF_MAGIC, GDIFF_MAGIC_LEN ) != 0 || + header[GDIFF_VER_POS] != GDIFF_VER ) + { + err = GDIFF_ERR_HEADER; + } + else + { + /* get the checksum information */ + + dd->checksumType = header[GDIFF_CS_POS]; + cslen = header[GDIFF_CSLEN_POS]; + + if ( cslen > 0 ) + { + oldcslen = cslen / 2; + newcslen = cslen - oldcslen; + PR_ASSERT( newcslen == oldcslen ); + + dd->checksumLength = oldcslen; + dd->oldChecksum = (uchar*)PR_MALLOC(oldcslen); + dd->newChecksum = (uchar*)PR_MALLOC(newcslen); + + if ( dd->oldChecksum != NULL && dd->newChecksum != NULL ) + { + nRead = PR_Read (dd->fDiff, dd->oldChecksum, oldcslen); + if ( nRead == oldcslen ) + { + nRead = PR_Read (dd->fDiff, dd->newChecksum, newcslen); + if ( nRead != newcslen ) { + err = GDIFF_ERR_HEADER; + } + } + else { + err = GDIFF_ERR_HEADER; + } + } + else { + err = GDIFF_ERR_MEM; + } + } + + + /* get application data, if any */ + + if ( err == GDIFF_OK ) + { + uint32 appdataSize; + uchar *buf; + uchar lenbuf[GDIFF_APPDATALEN]; + + nRead = PR_Read(dd->fDiff, lenbuf, GDIFF_APPDATALEN); + if ( nRead == GDIFF_APPDATALEN ) + { + appdataSize = getlong(lenbuf); + + if ( appdataSize > 0 ) + { + buf = (uchar *)PR_MALLOC( appdataSize ); + + if ( buf != NULL ) + { + nRead = PR_Read (dd->fDiff, buf, appdataSize); + if ( nRead == appdataSize ) + { + if ( 0 == memcmp( buf, APPFLAG_W32BOUND, appdataSize ) ) + dd->bWin32BoundImage = TRUE; + + if ( 0 == memcmp( buf, APPFLAG_APPLESINGLE, appdataSize ) ) + dd->bMacAppleSingle = TRUE; + } + else { + err = GDIFF_ERR_HEADER; + } + + PR_DELETE( buf ); + } + else { + err = GDIFF_ERR_MEM; + } + } + } + else { + err = GDIFF_ERR_HEADER; + } + } + } + + return (err); +} + + +/*--------------------------------------------------------- + * gdiff_validateFile() + * + * computes the checksum of the file and compares it to + * the value stored in the GDIFF header + *--------------------------------------------------------- + */ +static +int32 gdiff_validateFile( pDIFFDATA dd, int file ) +{ + int32 result; + PRFileDesc* fh; + uchar* chksum; + + /* which file are we dealing with? */ + if ( file == SRCFILE ) { + fh = dd->fSrc; + chksum = dd->oldChecksum; + } + else { /* OUTFILE */ + fh = dd->fOut; + chksum = dd->newChecksum; + } + + /* make sure file's at beginning */ + PR_Seek( fh, 0, PR_SEEK_SET ); + + /* calculate appropriate checksum */ + switch (dd->checksumType) + { + case GDIFF_CS_NONE: + result = GDIFF_OK; + break; + + + case GDIFF_CS_CRC32: + if ( dd->checksumLength == CRC32_LEN ) + result = gdiff_valCRC32( dd, fh, getlong(chksum) ); + else + result = GDIFF_ERR_HEADER; + break; + + + case GDIFF_CS_MD5: + + + case GDIFF_CS_SHA: + + + default: + /* unsupported checksum type */ + result = GDIFF_ERR_CHKSUMTYPE; + break; + } + + /* reset file position to beginning and return status */ + PR_Seek( fh, 0, PR_SEEK_SET ); + return (result); +} + + +/*--------------------------------------------------------- + * gdiff_valCRC32() + * + * computes the checksum of the file and compares it to + * the passed in checksum. Assumes file is positioned at + * beginning. + *--------------------------------------------------------- + */ +static +int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum ) +{ + uint32 crc; + uint32 nRead; + + crc = crc32(0L, Z_NULL, 0); + + nRead = PR_Read (fh, dd->databuf, dd->bufsize); + while ( nRead > 0 ) + { + crc = crc32( crc, dd->databuf, nRead ); + nRead = PR_Read (fh, dd->databuf, dd->bufsize); + } + + if ( crc == chksum ) + return GDIFF_OK; + else + return GDIFF_ERR_CHECKSUM; +} + + +/*--------------------------------------------------------- + * gdiff_ApplyPatch() + * + * Combines patch data with source file to produce the + * new target file. Assumes all three files have been + * opened, GDIFF header read, and all other setup complete + * + * The GDIFF patch is processed sequentially which random + * access is neccessary for the source file. + *--------------------------------------------------------- + */ +static +int32 gdiff_ApplyPatch( pDIFFDATA dd ) +{ + int32 err; + XP_Bool done; + uint32 position; + uint32 count; + uchar opcode; + uchar cmdbuf[MAXCMDSIZE]; + + done = FALSE; + while ( !done ) { + err = gdiff_getdiff( dd, &opcode, OPSIZE ); + if ( err != GDIFF_OK ) + break; + + switch (opcode) + { + case ENDDIFF: + done = TRUE; + break; + + case ADD16: + err = gdiff_getdiff( dd, cmdbuf, ADD16SIZE ); + if ( err == GDIFF_OK ) { + err = gdiff_add( dd, getshort( cmdbuf ) ); + } + break; + + case ADD32: + err = gdiff_getdiff( dd, cmdbuf, ADD32SIZE ); + if ( err == GDIFF_OK ) { + err = gdiff_add( dd, getlong( cmdbuf ) ); + } + break; + + case COPY16BYTE: + err = gdiff_getdiff( dd, cmdbuf, COPY16BYTESIZE ); + if ( err == GDIFF_OK ) { + position = getshort( cmdbuf ); + count = *(cmdbuf + sizeof(short)); + err = gdiff_copy( dd, position, count ); + } + break; + + case COPY16SHORT: + err = gdiff_getdiff( dd, cmdbuf, COPY16SHORTSIZE ); + if ( err == GDIFF_OK ) { + position = getshort( cmdbuf ); + count = getshort(cmdbuf + sizeof(short)); + err = gdiff_copy( dd, position, count ); + } + break; + + case COPY16LONG: + err = gdiff_getdiff( dd, cmdbuf, COPY16LONGSIZE ); + if ( err == GDIFF_OK ) { + position = getshort( cmdbuf ); + count = getlong(cmdbuf + sizeof(short)); + err = gdiff_copy( dd, position, count ); + } + break; + + case COPY32BYTE: + err = gdiff_getdiff( dd, cmdbuf, COPY32BYTESIZE ); + if ( err == GDIFF_OK ) { + position = getlong( cmdbuf ); + count = *(cmdbuf + sizeof(long)); + err = gdiff_copy( dd, position, count ); + } + break; + + case COPY32SHORT: + err = gdiff_getdiff( dd, cmdbuf, COPY32SHORTSIZE ); + if ( err == GDIFF_OK ) { + position = getlong( cmdbuf ); + count = getshort(cmdbuf + sizeof(long)); + err = gdiff_copy( dd, position, count ); + } + break; + + case COPY32LONG: + err = gdiff_getdiff( dd, cmdbuf, COPY32LONGSIZE ); + if ( err == GDIFF_OK ) { + position = getlong( cmdbuf ); + count = getlong(cmdbuf + sizeof(long)); + err = gdiff_copy( dd, position, count ); + } + break; + + case COPY64: + /* we don't support 64-bit file positioning yet */ + err = GDIFF_ERR_OPCODE; + break; + + default: + err = gdiff_add( dd, opcode ); + break; + } + + if ( err != GDIFF_OK ) + done = TRUE; + } + + /* return status */ + return (err); +} + + +/*--------------------------------------------------------- + * gdiff_getdiff() + * + * reads the next "length" bytes of the diff into "buffer" + * + * XXX: need a diff buffer to optimize reads! + *--------------------------------------------------------- + */ +static +int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length ) +{ + uint32 bytesRead; + + bytesRead = PR_Read (dd->fDiff, buffer, length); + if ( bytesRead != length ) + return GDIFF_ERR_BADDIFF; + + return GDIFF_OK; +} + + +/*--------------------------------------------------------- + * gdiff_add() + * + * append "count" bytes from diff file to new file + *--------------------------------------------------------- + */ +static +int32 gdiff_add( pDIFFDATA dd, uint32 count ) +{ + int32 err = GDIFF_OK; + uint32 nRead; + uint32 chunksize; + + while ( count > 0 ) { + chunksize = ( count > dd->bufsize) ? dd->bufsize : count; + nRead = PR_Read (dd->fDiff, dd->databuf, chunksize); + if ( nRead != chunksize ) { + err = GDIFF_ERR_BADDIFF; + break; + } + + PR_Write (dd->fOut, dd->databuf, chunksize); + + count -= chunksize; + } + + return (err); +} + + + +/*--------------------------------------------------------- + * gdiff_copy() + * + * copy "count" bytes from "position" in source file + *--------------------------------------------------------- + */ +static +int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count ) +{ + int32 err = GDIFF_OK; + uint32 nRead; + uint32 chunksize; + + PR_Seek (dd->fSrc, position, PR_SEEK_SET); + + while ( count > 0 ) { + chunksize = (count > dd->bufsize) ? dd->bufsize : count; + + nRead = PR_Read (dd->fSrc, dd->databuf, chunksize); + if ( nRead != chunksize ) { + err = GDIFF_ERR_OLDFILE; + break; + } + + PR_Write (dd->fOut, dd->databuf, chunksize); + + count -= chunksize; + } + + return (err); +} + diff --git a/xpinstall/src/nsInstallPatch.h b/xpinstall/src/nsInstallPatch.h index d2eade6f1cd8..c422245bce9b 100644 --- a/xpinstall/src/nsInstallPatch.h +++ b/xpinstall/src/nsInstallPatch.h @@ -73,8 +73,6 @@ class nsInstallPatch : public nsInstallObject PRInt32 NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile); - PRInt32 NativeReplace (const nsFileSpec& target, nsFileSpec& tempFile); - PRInt32 NativeDeleteFile(nsFileSpec* doomedFile); void* HashFilePath(const nsFilePath& aPath); }; diff --git a/xpinstall/src/nsInstallTrigger.cpp b/xpinstall/src/nsInstallTrigger.cpp index 101875d12e31..ddc233a0c36e 100644 --- a/xpinstall/src/nsInstallTrigger.cpp +++ b/xpinstall/src/nsInstallTrigger.cpp @@ -123,9 +123,26 @@ nsInstallTrigger::UpdateEnabled(PRBool* aReturn) } +NS_IMETHODIMP +nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn) +{ +// fix: aFlags is not processed! + nsInstallInfo *nextInstall = new nsInstallInfo( aURL, "", ""); + + // start the download (this will clean itself up) + + nsSoftwareUpdateListener *downloader = new nsSoftwareUpdateListener(nextInstall); + + *aReturn = NS_OK; // maybe we should do something more. + return NS_OK; +} + NS_IMETHODIMP nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn) { + PRInt32 aFlags = 0; + +// fix: aFlags is not processed! nsInstallInfo *nextInstall = new nsInstallInfo( aURL, "", ""); // start the download (this will clean itself up) @@ -142,12 +159,54 @@ nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString return NS_OK; } +NS_IMETHODIMP +nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsInstallTrigger::CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) +{ + return NS_OK; +} + NS_IMETHODIMP nsInstallTrigger::CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return NS_OK; } +NS_IMETHODIMP +nsInstallTrigger::CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) +{ + return NS_OK; +} + ///////////////////////////////////////////////////////////////////////// // @@ -249,4 +308,4 @@ nsInstallTriggerFactory::LockFactory(PRBool aLock) PR_AtomicDecrement(&gInstallTriggerLock); return NS_OK; -} \ No newline at end of file +} diff --git a/xpinstall/src/nsInstallTrigger.h b/xpinstall/src/nsInstallTrigger.h index ff76f9d664e9..d2cfbf927ae0 100644 --- a/xpinstall/src/nsInstallTrigger.h +++ b/xpinstall/src/nsInstallTrigger.h @@ -28,9 +28,17 @@ class nsInstallTrigger: public nsIScriptObjectOwner, public nsIDOMInstallTrigger NS_IMETHOD SetScriptObject(void* aScriptObject); NS_IMETHOD UpdateEnabled(PRBool* aReturn); + NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn); NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn); NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); + NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); + NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); + NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); private: @@ -56,4 +64,4 @@ class nsInstallTriggerFactory : public nsIFactory }; -#endif \ No newline at end of file +#endif diff --git a/xpinstall/src/nsInstallVersion.h b/xpinstall/src/nsInstallVersion.h index 5680491b93bf..dc47ba9b4a3d 100644 --- a/xpinstall/src/nsInstallVersion.h +++ b/xpinstall/src/nsInstallVersion.h @@ -42,8 +42,8 @@ class nsInstallVersion: public nsIScriptObjectOwner, public nsIDOMInstallVersion NS_IMETHOD ToString(nsString& aReturn); NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersion, PRInt32* aReturn); - NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn); + NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); static nsresult StringToVersionNumbers(const nsString& version, PRInt32 *aMajor, PRInt32 *aMinor, PRInt32 *aRelease, PRInt32 *aBuild); @@ -73,4 +73,4 @@ class nsInstallVersionFactory : public nsIFactory }; -#endif \ No newline at end of file +#endif diff --git a/xpinstall/src/nsJSInstall.cpp b/xpinstall/src/nsJSInstall.cpp index cf4f8b52c4ab..aee2077b0ce6 100644 --- a/xpinstall/src/nsJSInstall.cpp +++ b/xpinstall/src/nsJSInstall.cpp @@ -24,6 +24,8 @@ #include "nsString.h" #include "nsInstall.h" +#include "nsIDOMInstallVersion.h" + // // Install property ids // @@ -142,6 +144,86 @@ SetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) static void PR_CALLBACK FinalizeInstall(JSContext *cx, JSObject *obj) { + nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); + delete nativeThis; +} + +void nsCvrtJSValToStr(nsString& aString, + JSContext* aContext, + jsval aValue) +{ + JSString *jsstring; + if((jsstring = JS_ValueToString(aContext, aValue)) != nsnull) + { + aString.SetString(JS_GetStringChars(jsstring)); + } + else + { + aString.Truncate(); + } +} + +void nsCvrtStrToJSVal(const nsString& aProp, + JSContext* aContext, + jsval* aReturn) +{ + JSString *jsstring = JS_NewUCStringCopyN(aContext, aProp.GetUnicode(), aProp.Length()); + // set the return value + *aReturn = STRING_TO_JSVAL(jsstring); +} + +PRBool nsCvrtJSValToBool(PRBool* aProp, + JSContext* aContext, + jsval aValue) +{ + JSBool temp; + if(JSVAL_IS_BOOLEAN(aValue) && JS_ValueToBoolean(aContext, aValue, &temp)) + { + *aProp = (PRBool)temp; + } + else + { + JS_ReportError(aContext, "Parameter must be a boolean"); + return JS_FALSE; + } + + return JS_TRUE; +} + +PRBool nsCvrtJSValToObj(nsISupports** aSupports, + REFNSIID aIID, + const nsString& aTypeName, + JSContext* aContext, + jsval aValue) +{ + if (JSVAL_IS_NULL(aValue)) { + *aSupports = nsnull; + } + else if (JSVAL_IS_OBJECT(aValue)) { + JSObject* jsobj = JSVAL_TO_OBJECT(aValue); + JSClass* jsclass = JS_GetClass(aContext, jsobj); + if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) { + nsISupports *supports = (nsISupports *)JS_GetPrivate(aContext, jsobj); + if (NS_OK != supports->QueryInterface(aIID, (void **)aSupports)) { + char buf[128]; + char typeName[128]; + aTypeName.ToCString(typeName, sizeof(typeName)); + sprintf(buf, "Parameter must of type %s", typeName); + JS_ReportError(aContext, buf); + return JS_FALSE; + } + } + else { + JS_ReportError(aContext, "Parameter isn't a object"); + return JS_FALSE; + } + } + else { + JS_ReportError(aContext, "Parameter must be an object"); + return JS_FALSE; + } + + return JS_TRUE; } @@ -161,15 +243,19 @@ InstallAbortInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval return JS_TRUE; } - if (argc >= 0) { + if(argc >= 0) + { + // public int AbortInstall(void); - if (NS_OK != nativeThis->AbortInstall()) { + if(NS_OK != nativeThis->AbortInstall()) + { return JS_FALSE; } *rval = JSVAL_VOID; } - else { + else + { JS_ReportError(cx, "Function AbortInstall requires 0 parameters"); return JS_FALSE; } @@ -201,30 +287,123 @@ InstallAddDirectory(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval return JS_TRUE; } - if (argc >= 6) { + if (argc == 1) + { + // public int AddDirectory (String jarSourcePath) - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); - - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); - - nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]); - - nsJSUtils::nsConvertJSValToString(b3, cx, argv[3]); - - nsJSUtils::nsConvertJSValToString(b4, cx, argv[4]); - - if (!nsJSUtils::nsConvertJSValToBool(&b5, cx, argv[5])) { - return JS_FALSE; - } - - if (NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, b4, b5, &nativeRet)) { + nsCvrtJSValToStr(b0, cx, argv[0]); + + if(NS_OK != nativeThis->AddDirectory(b0, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { - JS_ReportError(cx, "Function AddDirectory requires 6 parameters"); + else if (argc == 4) + { + // public int AddDirectory ( String registryName, + // String jarSourcePath, + // String localDirSpec, + // String relativeLocalPath); + + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); + nsCvrtJSValToStr(b2, cx, argv[2]); + nsCvrtJSValToStr(b3, cx, argv[3]); + + if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, &nativeRet)) + { + return JS_FALSE; + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else if (argc == 5) + { + // public int AddDirectory ( String registryName, + // String version, --OR-- VersionInfo version + // String jarSourcePath, + // Object localDirSpec, + // String relativeLocalPath); + + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b2, cx, argv[2]); + nsCvrtJSValToStr(b3, cx, argv[3]); + nsCvrtJSValToStr(b4, cx, argv[4]); + + if(JSVAL_IS_OBJECT(argv[1])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->AddDirectory(b0, version, b2, b3, b4, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b1, cx, argv[1]); + if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, b4, &nativeRet)) + { + return JS_FALSE; + } + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else if (argc == 6) + { + // public int AddDirectory ( String registryName, + // String version, --OR-- VersionInfo version, + // String jarSourcePath, + // Object localDirSpec, + // String relativeLocalPath, + // Boolean forceUpdate); + + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b2, cx, argv[2]); + nsCvrtJSValToStr(b3, cx, argv[3]); + nsCvrtJSValToStr(b4, cx, argv[4]); + + if(!nsCvrtJSValToBool(&b5, cx, argv[5])) + { + return JS_FALSE; + } + + if(JSVAL_IS_OBJECT(argv[1])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->AddDirectory(b0, version, b2, b3, b4, b5, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b1, cx, argv[1]); + if(NS_OK != nativeThis->AddDirectory(b0, b1, b2, b3, b4, b5, &nativeRet)) + { + return JS_FALSE; + } + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else + { + JS_ReportError(cx, "Install.AddDirectory() parameters error"); return JS_FALSE; } @@ -255,29 +434,122 @@ InstallAddSubcomponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js return JS_TRUE; } - if (argc >= 6) { + if(argc >= 6) + { + // public int AddSubcomponent ( String registryName, + // String version, --OR-- VersionInfo version, + // String jarSourcePath, + // Object localDirSpec, + // String relativeLocalPath, + // Boolean forceUpdate); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b2, cx, argv[2]); + nsCvrtJSValToStr(b3, cx, argv[3]); + nsCvrtJSValToStr(b4, cx, argv[4]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); - - nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]); - - nsJSUtils::nsConvertJSValToString(b3, cx, argv[3]); - - nsJSUtils::nsConvertJSValToString(b4, cx, argv[4]); - - if (!nsJSUtils::nsConvertJSValToBool(&b5, cx, argv[5])) { + if(!nsCvrtJSValToBool(&b5, cx, argv[5])) + { return JS_FALSE; } - if (NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, b4, b5, &nativeRet)) { + if(JSVAL_IS_OBJECT(argv[1])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->AddSubcomponent(b0, version, b2, b3, b4, b5, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b1, cx, argv[1]); + if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, b4, b5, &nativeRet)) + { + return JS_FALSE; + } + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else if(argc >= 5) + { + // public int AddSubcomponent ( String registryName, + // String version, --OR-- VersionInfo version + // String jarSourcePath, + // Object localDirSpec, + // String relativeLocalPath); + + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b2, cx, argv[2]); + nsCvrtJSValToStr(b3, cx, argv[3]); + nsCvrtJSValToStr(b4, cx, argv[4]); + + if(JSVAL_IS_OBJECT(argv[1])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->AddSubcomponent(b0, version, b2, b3, b4, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b1, cx, argv[1]); + if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, b4, &nativeRet)) + { + return JS_FALSE; + } + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else if(argc >= 4) + { + // public int AddSubcomponent ( String registryName, + // String jarSourcePath, + // Object localDirSpec, + // String relativeLocalPath); + + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); + nsCvrtJSValToStr(b2, cx, argv[2]); + nsCvrtJSValToStr(b3, cx, argv[3]); + + if(NS_OK != nativeThis->AddSubcomponent(b0, b1, b2, b3, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else if(argc >= 1) + { + // public int AddSubcomponent ( String jarSourcePath); + + nsCvrtJSValToStr(b0, cx, argv[0]); + + if(NS_OK != nativeThis->AddSubcomponent(b0, &nativeRet)) + { + return JS_FALSE; + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else + { JS_ReportError(cx, "Function AddSubcomponent requires 6 parameters"); return JS_FALSE; } @@ -304,17 +576,21 @@ InstallDeleteComponent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js return JS_TRUE; } - if (argc >= 1) { + if(argc >= 1) + { + // public int DeleteComponent ( String registryName); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); - if (NS_OK != nativeThis->DeleteComponent(b0, &nativeRet)) { + if(NS_OK != nativeThis->DeleteComponent(b0, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function DeleteComponent requires 1 parameters"); return JS_FALSE; } @@ -342,19 +618,23 @@ InstallDeleteFile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval * return JS_TRUE; } - if (argc >= 2) { + if(argc >= 2) + { + // public int DeleteFile ( Object folder, + // String relativeFileName); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); - - if (NS_OK != nativeThis->DeleteFile(b0, b1, &nativeRet)) { + if(NS_OK != nativeThis->DeleteFile(b0, b1, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function DeleteFile requires 2 parameters"); return JS_FALSE; } @@ -381,17 +661,21 @@ InstallDiskSpaceAvailable(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, return JS_TRUE; } - if (argc >= 1) { + if(argc >= 1) + { + // public int DiskSpaceAvailable ( Object localDirSpec); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); - if (NS_OK != nativeThis->DiskSpaceAvailable(b0, &nativeRet)) { + if(NS_OK != nativeThis->DiskSpaceAvailable(b0, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function DiskSpaceAvailable requires 1 parameters"); return JS_FALSE; } @@ -419,19 +703,36 @@ InstallExecute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva return JS_TRUE; } - if (argc >= 2) { + if(argc >= 2) + { + // public int Execute ( String jarSourcePath, + // String args); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); - - if (NS_OK != nativeThis->Execute(b0, b1, &nativeRet)) { + if(NS_OK != nativeThis->Execute(b0, b1, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else if(argc >= 1) + { + // public int Execute ( String jarSourcePath); + + nsCvrtJSValToStr(b0, cx, argv[0]); + + if(NS_OK != nativeThis->Execute(b0, &nativeRet)) + { + return JS_FALSE; + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else + { JS_ReportError(cx, "Function Execute requires 2 parameters"); return JS_FALSE; } @@ -457,15 +758,19 @@ InstallFinalizeInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js return JS_TRUE; } - if (argc >= 0) { + if(argc >= 0) + { + // public int FinalizeInstall (void); - if (NS_OK != nativeThis->FinalizeInstall(&nativeRet)) { + if(NS_OK != nativeThis->FinalizeInstall(&nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function FinalizeInstall requires 0 parameters"); return JS_FALSE; } @@ -492,17 +797,22 @@ InstallGestalt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva return JS_TRUE; } - if (argc >= 1) { + if(argc >= 1) + { + // public int Gestalt ( String selector, + // long *response); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); - if (NS_OK != nativeThis->Gestalt(b0, &nativeRet)) { + if(NS_OK != nativeThis->Gestalt(b0, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function Gestalt requires 1 parameters"); return JS_FALSE; } @@ -530,19 +840,36 @@ InstallGetComponentFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, return JS_TRUE; } - if (argc >= 2) { + if(argc >= 2) + { + // public int GetComponentFolder ( String registryName, + // String subDirectory); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); - - if (NS_OK != nativeThis->GetComponentFolder(b0, b1, &nativeRet)) { + if(NS_OK != nativeThis->GetComponentFolder(b0, b1, &nativeRet)) + { return JS_FALSE; } - nsJSUtils::nsConvertStringToJSVal(*nativeRet, cx, rval); + nsCvrtStrToJSVal(*nativeRet, cx, rval); } - else { + else if(argc >= 1) + { + // public int GetComponentFolder ( String registryName); + + nsCvrtJSValToStr(b0, cx, argv[0]); + + if(NS_OK != nativeThis->GetComponentFolder(b0, &nativeRet)) + { + return JS_FALSE; + } + + nsCvrtStrToJSVal(*nativeRet, cx, rval); + } + else + { JS_ReportError(cx, "Function GetComponentFolder requires 2 parameters"); return JS_FALSE; } @@ -570,19 +897,36 @@ InstallGetFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r return JS_TRUE; } - if (argc >= 2) { + if(argc >= 2) + { + // public int GetFolder ( String folderName, --OR-- Object localDirSpec, + // String subDirectory); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); - - if (NS_OK != nativeThis->GetFolder(b0, b1, &nativeRet)) { + if(NS_OK != nativeThis->GetFolder(b0, b1, &nativeRet)) + { return JS_FALSE; } - nsJSUtils::nsConvertStringToJSVal(*nativeRet, cx, rval); + nsCvrtStrToJSVal(*nativeRet, cx, rval); } - else { + else if(argc >= 1) + { + // public int GetFolder ( String folderName); + + nsCvrtJSValToStr(b0, cx, argv[0]); + + if(NS_OK != nativeThis->GetFolder(b0, &nativeRet)) + { + return JS_FALSE; + } + + nsCvrtStrToJSVal(*nativeRet, cx, rval); + } + else + { JS_ReportError(cx, "Function GetFolder requires 2 parameters"); return JS_FALSE; } @@ -601,6 +945,7 @@ InstallGetLastError(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval JSBool rBool = JS_FALSE; PRInt32 nativeRet; + *rval = JSVAL_NULL; // If there's no private data, this must be the prototype, so ignore @@ -608,15 +953,19 @@ InstallGetLastError(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval return JS_TRUE; } - if (argc >= 0) { + if(argc >= 0) + { + // public int GetLastError (void); - if (NS_OK != nativeThis->GetLastError(&nativeRet)) { + if(NS_OK != nativeThis->GetLastError(&nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function GetLastError requires 0 parameters"); return JS_FALSE; } @@ -644,19 +993,23 @@ InstallGetWinProfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva return JS_TRUE; } - if (argc >= 2) { + if(argc >= 2) + { + // public int GetWinProfile (Object folder, + // String file); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); - - if (NS_OK != nativeThis->GetWinProfile(b0, b1, &nativeRet)) { + if(NS_OK != nativeThis->GetWinProfile(b0, b1, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function GetWinProfile requires 2 parameters"); return JS_FALSE; } @@ -682,15 +1035,19 @@ InstallGetWinRegistry(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv return JS_TRUE; } - if (argc >= 0) { + if(argc >= 0) + { + // public int GetWinRegistry (void); - if (NS_OK != nativeThis->GetWinRegistry(&nativeRet)) { + if(NS_OK != nativeThis->GetWinRegistry(&nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function GetWinRegistry requires 0 parameters"); return JS_FALSE; } @@ -721,25 +1078,65 @@ InstallPatch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) return JS_TRUE; } - if (argc >= 5) { + if(argc >= 5) + { + // public int Patch (String registryName, + // String version, --OR-- VersionInfo version, + // String jarSourcePath, + // Object localDirSpec, + // String relativeLocalPath); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b2, cx, argv[2]); + nsCvrtJSValToStr(b3, cx, argv[3]); + nsCvrtJSValToStr(b4, cx, argv[4]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + if(JSVAL_IS_OBJECT(argv[1])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); - nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]); + if(NS_OK != nativeThis->Patch(b0, version, b2, b3, b4, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b1, cx, argv[1]); + if(NS_OK != nativeThis->Patch(b0, b1, b2, b3, b4, &nativeRet)) + { + return JS_FALSE; + } + } - nsJSUtils::nsConvertJSValToString(b3, cx, argv[3]); + *rval = INT_TO_JSVAL(nativeRet); + } + else if(argc >= 4) + { + // public int Patch (String registryName, + // String jarSourcePath, + // Object localDirSpec, + // String relativeLocalPath); - nsJSUtils::nsConvertJSValToString(b4, cx, argv[4]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); + nsCvrtJSValToStr(b2, cx, argv[2]); + nsCvrtJSValToStr(b3, cx, argv[3]); - if (NS_OK != nativeThis->Patch(b0, b1, b2, b3, b4, &nativeRet)) { + if(NS_OK != nativeThis->Patch(b0, b1, b2, b3, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function Patch requires 5 parameters"); return JS_FALSE; } @@ -764,15 +1161,19 @@ InstallResetError(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval * return JS_TRUE; } - if (argc >= 0) { + if(argc >= 0) + { + // public int ResetError (void); - if (NS_OK != nativeThis->ResetError()) { + if(NS_OK != nativeThis->ResetError()) + { return JS_FALSE; } *rval = JSVAL_VOID; } - else { + else + { JS_ReportError(cx, "Function ResetError requires 0 parameters"); return JS_FALSE; } @@ -798,17 +1199,21 @@ InstallSetPackageFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j return JS_TRUE; } - if (argc >= 1) { + if(argc >= 1) + { + // public int SetPackageFolder (Object folder); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); - if (NS_OK != nativeThis->SetPackageFolder(b0)) { + if(NS_OK != nativeThis->SetPackageFolder(b0)) + { return JS_FALSE; } *rval = JSVAL_VOID; } - else { + else + { JS_ReportError(cx, "Function SetPackageFolder requires 1 parameters"); return JS_FALSE; } @@ -816,7 +1221,6 @@ InstallSetPackageFolder(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j return JS_TRUE; } - // // Native method StartInstall // @@ -838,26 +1242,83 @@ InstallStartInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval return JS_TRUE; } - if (argc >= 4) { + if(argc >= 4) + { + // public int StartInstall (String userPackageName, + // String package, + // String version, --OR-- VersionInfo version, + // int flags); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); - - nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]); - - if (!JS_ValueToInt32(cx, argv[3], (int32 *)&b3)) { + if(!JS_ValueToInt32(cx, argv[3], (int32 *)&b3)) + { JS_ReportError(cx, "Parameter must be a number"); return JS_FALSE; } - if (NS_OK != nativeThis->StartInstall(b0, b1, b2, b3, &nativeRet)) { - return JS_FALSE; + if(JSVAL_IS_OBJECT(argv[1])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[2]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->StartInstall(b0, b1, version, b3, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b1, cx, argv[1]); + if(NS_OK != nativeThis->StartInstall(b0, b1, b2, b3, &nativeRet)) + { + return JS_FALSE; + } } *rval = INT_TO_JSVAL(nativeRet); } - else { + else if(argc >= 3) + { + // public int StartInstall (String userPackageName, + // String package, + // String version); --OR-- VersionInfo version + + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); + + if(JSVAL_IS_OBJECT(argv[1])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[2]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if ((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->StartInstall(b0, b1, version, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b1, cx, argv[1]); + if(NS_OK != nativeThis->StartInstall(b0, b1, b2, &nativeRet)) + { + return JS_FALSE; + } + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else + { JS_ReportError(cx, "Function StartInstall requires 4 parameters"); return JS_FALSE; } @@ -884,17 +1345,21 @@ InstallUninstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r return JS_TRUE; } - if (argc >= 1) { + if(argc >= 1) + { + // public int Uninstall (String packageName); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); - if (NS_OK != nativeThis->Uninstall(b0, &nativeRet)) { + if(NS_OK != nativeThis->Uninstall(b0, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { + else + { JS_ReportError(cx, "Function Uninstall requires 1 parameters"); return JS_FALSE; } diff --git a/xpinstall/src/nsJSInstallTriggerGlobal.cpp b/xpinstall/src/nsJSInstallTriggerGlobal.cpp index d0664c62445d..ef3fa5c912dd 100644 --- a/xpinstall/src/nsJSInstallTriggerGlobal.cpp +++ b/xpinstall/src/nsJSInstallTriggerGlobal.cpp @@ -26,8 +26,26 @@ #include "nsIScriptGlobalObject.h" #include "nsIPtr.h" #include "nsString.h" +#include "nsIDOMInstallVersion.h" #include "nsIDOMInstallTriggerGlobal.h" +extern void nsCvrtJSValToStr(nsString& aString, + JSContext* aContext, + jsval aValue); + +extern void nsCvrtStrToJSVal(const nsString& aProp, + JSContext* aContext, + jsval* aReturn); + +extern PRBool nsCvrtJSValToBool(PRBool* aProp, + JSContext* aContext, + jsval aValue); + +extern PRBool nsCvrtJSValToObj(nsISupports** aSupports, + REFNSIID aIID, + const nsString& aTypeName, + JSContext* aContext, + jsval aValue); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); @@ -123,7 +141,6 @@ ResolveInstallTriggerGlobal(JSContext *cx, JSObject *obj, jsval id) return nsJSUtils::nsGenericResolve(cx, obj, id); } - // // Native method UpdateEnabled // @@ -165,9 +182,10 @@ PR_STATIC_CALLBACK(JSBool) InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; - PRInt32 nativeRet; + JSBool rBool = JS_FALSE; + PRInt32 nativeRet; nsAutoString b0; + PRInt32 b1; *rval = JSVAL_NULL; @@ -176,18 +194,42 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc return JS_TRUE; } - if (argc >= 1) { + if (argc >= 2) + { + // public int StartSoftwareUpdate(String url, + // int flag); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); - if (NS_OK != nativeThis->StartSoftwareUpdate(b0, &nativeRet)) { + if(!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) + { + JS_ReportError(cx, "2nd parameter must be a number"); + return JS_FALSE; + } + + if(NS_OK != nativeThis->StartSoftwareUpdate(b0, b1, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { - JS_ReportError(cx, "Function StartSoftwareUpdate requires 1 parameters"); + else if(argc >= 1) + { + // public int StartSoftwareUpdate(String url); + + nsCvrtJSValToStr(b0, cx, argv[0]); + + if(NS_OK != nativeThis->StartSoftwareUpdate(b0, &nativeRet)) + { + return JS_FALSE; + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else + { + JS_ReportError(cx, "Function StartSoftwareUpdate requires 2 parameters"); return JS_FALSE; } @@ -206,9 +248,11 @@ InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uint PRInt32 nativeRet; nsAutoString b0; nsAutoString b1; - PRInt32 b2; - nsAutoString b3; - PRInt32 b4; + nsAutoString b2str; + PRInt32 b2int; + nsAutoString b3str; + PRInt32 b3int; + PRInt32 b4; *rval = JSVAL_NULL; @@ -217,31 +261,131 @@ InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uint return JS_TRUE; } - if (argc >= 5) { + if(argc >= 5) + { + // public int ConditionalSoftwareUpdate(String url, + // String registryName, + // int diffLevel, + // String version, --OR-- VersionInfo version + // int mode); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); - - if (!JS_ValueToInt32(cx, argv[2], (int32 *)&b2)) { - JS_ReportError(cx, "Parameter must be a number"); + if(!JS_ValueToInt32(cx, argv[2], (int32 *)&b2int)) + { + JS_ReportError(cx, "3rd parameter must be a number"); return JS_FALSE; } - nsJSUtils::nsConvertJSValToString(b3, cx, argv[3]); - - if (!JS_ValueToInt32(cx, argv[4], (int32 *)&b4)) { - JS_ReportError(cx, "Parameter must be a number"); + if(!JS_ValueToInt32(cx, argv[4], (int32 *)&b4)) + { + JS_ReportError(cx, "5th parameter must be a number"); return JS_FALSE; } - if (NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2, b3, b4, &nativeRet)) { - return JS_FALSE; + if(JSVAL_IS_OBJECT(argv[3])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[3]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2int, version, b4, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b3str, cx, argv[3]); + if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2int, b3str, b4, &nativeRet)) + { + return JS_FALSE; + } } *rval = INT_TO_JSVAL(nativeRet); } - else { + else if(argc >= 4) + { + // public int ConditionalSoftwareUpdate(String url, + // String registryName, + // String version, --OR-- VersionInfo version + // int mode); + + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); + + if(!JS_ValueToInt32(cx, argv[3], (int32 *)&b3int)) + { + JS_ReportError(cx, "4th parameter must be a number"); + return JS_FALSE; + } + + if(JSVAL_IS_OBJECT(argv[2])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[2]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, version, b3int, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b2str, cx, argv[2]); + if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2str, b3int, &nativeRet)) + { + return JS_FALSE; + } + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else if(argc >= 3) + { + // public int ConditionalSoftwareUpdate(String url, + // String registryName, + // String version); --OR-- VersionInfo version + + nsCvrtJSValToStr(b0, cx, argv[0]); + nsCvrtJSValToStr(b1, cx, argv[1]); + + if(JSVAL_IS_OBJECT(argv[2])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[2]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, version, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b2str, cx, argv[2]); + if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2str, &nativeRet)) + { + return JS_FALSE; + } + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else + { JS_ReportError(cx, "Function ConditionalSoftwareUpdate requires 5 parameters"); return JS_FALSE; } @@ -260,7 +404,11 @@ InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsv JSBool rBool = JS_FALSE; PRInt32 nativeRet; nsAutoString b0; - nsAutoString b1; + nsAutoString b1str; + PRInt32 b1int; + PRInt32 b2int; + PRInt32 b3int; + PRInt32 b4int; *rval = JSVAL_NULL; @@ -269,20 +417,79 @@ InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsv return JS_TRUE; } - if (argc >= 2) { + if(argc >= 5) + { + // public int CompareVersion(String registryName, + // int major, + // int minor, + // int release, + // int build); - nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsCvrtJSValToStr(b0, cx, argv[0]); - nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + if(!JS_ValueToInt32(cx, argv[1], (int32 *)&b1int)) + { + JS_ReportError(cx, "2th parameter must be a number"); + return JS_FALSE; + } + if(!JS_ValueToInt32(cx, argv[2], (int32 *)&b2int)) + { + JS_ReportError(cx, "3th parameter must be a number"); + return JS_FALSE; + } + if(!JS_ValueToInt32(cx, argv[3], (int32 *)&b3int)) + { + JS_ReportError(cx, "4th parameter must be a number"); + return JS_FALSE; + } + if(!JS_ValueToInt32(cx, argv[4], (int32 *)&b4int)) + { + JS_ReportError(cx, "5th parameter must be a number"); + return JS_FALSE; + } - if (NS_OK != nativeThis->CompareVersion(b0, b1, &nativeRet)) { + if(NS_OK != nativeThis->CompareVersion(b0, b1int, b2int, b3int, b4int, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { - JS_ReportError(cx, "Function CompareVersion requires 2 parameters"); + else if(argc >= 2) + { + // public int CompareVersion(String registryName, + // String version); --OR-- VersionInfo version + + nsCvrtJSValToStr(b0, cx, argv[0]); + + if(JSVAL_IS_OBJECT(argv[1])) + { + JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]); + JSClass* jsclass = JS_GetClass(cx, jsobj); + if((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE)) + { + nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj); + + if(NS_OK != nativeThis->CompareVersion(b0, version, &nativeRet)) + { + return JS_FALSE; + } + } + } + else + { + nsCvrtJSValToStr(b1str, cx, argv[1]); + if(NS_OK != nativeThis->CompareVersion(b0, b1str, &nativeRet)) + { + return JS_FALSE; + } + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else + { + JS_ReportError(cx, "Function CompareVersion requires 5 parameters"); return JS_FALSE; } @@ -323,9 +530,9 @@ static JSPropertySpec InstallTriggerGlobalProperties[] = static JSFunctionSpec InstallTriggerGlobalMethods[] = { {"UpdateEnabled", InstallTriggerGlobalUpdateEnabled, 0}, - {"StartSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 1}, + {"StartSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2}, {"ConditionalSoftwareUpdate", InstallTriggerGlobalConditionalSoftwareUpdate, 5}, - {"CompareVersion", InstallTriggerGlobalCompareVersion, 2}, + {"CompareVersion", InstallTriggerGlobalCompareVersion, 5}, {0} }; diff --git a/xpinstall/src/nsJSInstallVersion.cpp b/xpinstall/src/nsJSInstallVersion.cpp index d755b54147cb..f0c1a3464fa8 100644 --- a/xpinstall/src/nsJSInstallVersion.cpp +++ b/xpinstall/src/nsJSInstallVersion.cpp @@ -31,6 +31,24 @@ #include "nsRepository.h" #include "nsDOMCID.h" +extern void nsCvrtJSValToStr(nsString& aString, + JSContext* aContext, + jsval aValue); + +extern void nsCvrtStrToJSVal(const nsString& aProp, + JSContext* aContext, + jsval* aReturn); + +extern PRBool nsCvrtJSValToBool(PRBool* aProp, + JSContext* aContext, + jsval aValue); + +extern PRBool nsCvrtJSValToObj(nsISupports** aSupports, + REFNSIID aIID, + const nsString& aTypeName, + JSContext* aContext, + jsval aValue); + static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); @@ -319,9 +337,14 @@ PR_STATIC_CALLBACK(JSBool) InstallVersionCompareTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsIDOMInstallVersion *nativeThis = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; - PRInt32 nativeRet; - nsIDOMInstallVersionPtr b0; + JSBool rBool = JS_FALSE; + PRInt32 nativeRet; + nsString b0str; + PRInt32 b0int; + PRInt32 b1int; + PRInt32 b2int; + PRInt32 b3int; + nsIDOMInstallVersionPtr versionObj; *rval = JSVAL_NULL; @@ -330,24 +353,81 @@ InstallVersionCompareTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j return JS_TRUE; } - if (argc >= 1) { + if(argc >= 4) + { + // public int CompareTo(int major, + // int minor, + // int release, + // int build); - if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, - kIInstallVersionIID, - "InstallVersion", - cx, - argv[0])) { - return JS_FALSE; + if(!JSVAL_IS_INT(argv[0])) + { + JS_ReportError(cx, "1st parameter must be a number"); + return JS_FALSE; + } + else if(!JSVAL_IS_INT(argv[1])) + { + JS_ReportError(cx, "2nd parameter must be a number"); + return JS_FALSE; + } + else if(!JSVAL_IS_INT(argv[2])) + { + JS_ReportError(cx, "3rd parameter must be a number"); + return JS_FALSE; + } + else if(!JSVAL_IS_INT(argv[3])) + { + JS_ReportError(cx, "4th parameter must be a number"); + return JS_FALSE; } - if (NS_OK != nativeThis->CompareTo(b0, &nativeRet)) { + b0int = JSVAL_TO_INT(argv[0]); + b1int = JSVAL_TO_INT(argv[1]); + b2int = JSVAL_TO_INT(argv[2]); + b3int = JSVAL_TO_INT(argv[3]); + + if(NS_OK != nativeThis->CompareTo(b0int, b1int, b2int, b3int, &nativeRet)) + { return JS_FALSE; } *rval = INT_TO_JSVAL(nativeRet); } - else { - JS_ReportError(cx, "Function compareTo requires 1 parameters"); + else if(argc >= 1) + { + // public int AddDirectory(String version); --OR-- VersionInfo version + + if(JSVAL_IS_OBJECT(argv[0])) + { + if(JS_FALSE == nsCvrtJSValToObj((nsISupports **)&versionObj, + kIInstallVersionIID, + "InstallVersion", + cx, + argv[0])) + { + return JS_FALSE; + } + + if(NS_OK != nativeThis->CompareTo(versionObj, &nativeRet)) + { + return JS_FALSE; + } + } + else + { + nsCvrtJSValToStr(b0str, cx, argv[0]); + + if(NS_OK != nativeThis->CompareTo(b0str, &nativeRet)) + { + return JS_FALSE; + } + } + + *rval = INT_TO_JSVAL(nativeRet); + } + else + { + JS_ReportError(cx, "Function compareTo requires 4 parameters"); return JS_FALSE; } diff --git a/xpinstall/src/nsSoftwareUpdate.cpp b/xpinstall/src/nsSoftwareUpdate.cpp index 5f2087b8d36d..1c5b04491432 100644 --- a/xpinstall/src/nsSoftwareUpdate.cpp +++ b/xpinstall/src/nsSoftwareUpdate.cpp @@ -21,10 +21,11 @@ #include "nscore.h" #include "nsIFactory.h" #include "nsISupports.h" -#include "nsRepository.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsCOMPtr.h" - -#include "pratom.h" +#include "nspr.h" #include "nsVector.h" #include "VerReg.h" #include "nsSpecialSystemDirectory.h" @@ -32,7 +33,6 @@ #include "nsInstall.h" #include "nsSoftwareUpdateIIDs.h" #include "nsSoftwareUpdate.h" -#include "nsSoftwareUpdateStream.h" #include "nsSoftwareUpdateRun.h" #include "nsInstallTrigger.h" #include "nsInstallVersion.h" @@ -55,6 +55,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); + static NS_DEFINE_IID(kIScriptNameSetRegistryIID, NS_ISCRIPTNAMESETREGISTRY_IID); static NS_DEFINE_IID(kCScriptNameSetRegistryCID, NS_SCRIPT_NAMESET_REGISTRY_CID); static NS_DEFINE_IID(kIScriptExternalNameSetIID, NS_ISCRIPTEXTERNALNAMESET_IID); @@ -124,7 +126,7 @@ nsSoftwareUpdate::Startup() /***************************************/ nsSpecialSystemDirectory appDir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); - VR_SetRegDirectory(appDir.GetCString()); + VR_SetRegDirectory( nsprPath(appDir) ); NR_StartupRegistry(); /* startup the registry; if already started, this will essentially be a noop */ @@ -132,21 +134,28 @@ nsSoftwareUpdate::Startup() /* Stupid Hack to test js env*/ /***************************************/ // FIX: HACK HACK HACK! -#if 1 +#if 0 nsSpecialSystemDirectory jarFile(nsSpecialSystemDirectory::OS_TemporaryDirectory); jarFile += "test.jar"; if (jarFile.Exists()) { - InstallJar(nsString(nsFileURL(jarFile).GetAsString()), "", ""); + InstallJar(nsString(nsFileURL(jarFile)), "", ""); } #endif /***************************************/ - /* Preform Scheduled Tasks */ + /* Perform Scheduled Tasks */ /***************************************/ - DeleteScheduledFiles(); - ReplaceScheduledFiles(); - +#if 1 + PR_CreateThread(PR_USER_THREAD, + PerformScheduledTasks, + nsnull, + PR_PRIORITY_NORMAL, + PR_GLOBAL_THREAD, + PR_UNJOINABLE_THREAD, + 0); +#endif +// PerformScheduledTasks(nsnull); return NS_OK; } @@ -373,33 +382,67 @@ nsSoftwareUpdateNameSet::AddNameSet(nsIScriptContext* aScriptContext) //////////////////////////////////////////////////////////////////////////////// extern "C" NS_EXPORT PRBool -NSCanUnload(nsISupports* serviceMgr) +NSCanUnload(nsISupports* aServMgr) { return PR_FALSE; } extern "C" NS_EXPORT nsresult -NSRegisterSelf(nsISupports* serviceMgr, const char *path) +NSRegisterSelf(nsISupports* aServMgr, const char *path) { - printf("*** XPInstall is being registered\n"); - - nsRepository::RegisterComponent(kSoftwareUpdate_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); - nsRepository::RegisterComponent(kInstallTrigger_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); - nsRepository::RegisterComponent(kInstallVersion_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); + nsresult rv; - return NS_OK; + nsCOMPtr servMgr(do_QueryInterface(aServMgr, &rv)); + if (NS_FAILED(rv)) return rv; + + nsIComponentManager* compMgr; + rv = servMgr->GetService(kComponentManagerCID, + nsIComponentManager::GetIID(), + (nsISupports**)&compMgr); + if (NS_FAILED(rv)) return rv; + +#ifdef NS_DEBUG + printf("*** XPInstall is being registered\n"); +#endif + + rv = compMgr->RegisterComponent(kSoftwareUpdate_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); + if (NS_FAILED(rv)) goto done; + rv = compMgr->RegisterComponent(kInstallTrigger_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); + if (NS_FAILED(rv)) goto done; + rv = compMgr->RegisterComponent(kInstallVersion_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); + done: + (void)servMgr->ReleaseService(kComponentManagerCID, compMgr); + return rv; } + extern "C" NS_EXPORT nsresult -NSUnregisterSelf(nsISupports* serviceMgr, const char *path) +NSUnregisterSelf(nsISupports* aServMgr, const char *path) { +nsresult rv; + + nsCOMPtr servMgr(do_QueryInterface(aServMgr, &rv)); + if (NS_FAILED(rv)) return rv; + + nsIComponentManager* compMgr; + rv = servMgr->GetService(kComponentManagerCID, + nsIComponentManager::GetIID(), + (nsISupports**)&compMgr); + if (NS_FAILED(rv)) return rv; + +#ifdef NS_DEBUG printf("*** XPInstall is being unregistered\n"); +#endif + + rv = compMgr->UnregisterComponent(kSoftwareUpdate_CID, path); + if (NS_FAILED(rv)) goto done; + rv = compMgr->UnregisterComponent(kInstallTrigger_CID, path); + if (NS_FAILED(rv)) goto done; + rv = compMgr->UnregisterComponent(kInstallVersion_CID, path); - nsRepository::UnregisterComponent(kSoftwareUpdate_CID, path); - nsRepository::UnregisterComponent(kInstallTrigger_CID, path); - nsRepository::UnregisterComponent(kInstallVersion_CID, path); - - return NS_OK; + done: + (void)servMgr->ReleaseService(kComponentManagerCID, compMgr); + return rv; } diff --git a/xpinstall/src/nsSoftwareUpdateRun.cpp b/xpinstall/src/nsSoftwareUpdateRun.cpp index 6c107d283425..6c3eb4e3b58f 100644 --- a/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -1,22 +1,66 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + * + * Contributors: + * Daniel Veditz + * Douglas Turner + */ + #include "nsSoftwareUpdate.h" #include "nsSoftwareUpdateRun.h" +#include "nsSoftwareUpdateIIDs.h" #include "nsInstall.h" #include "zipfile.h" #include "nsRepository.h" +#include "nsIServiceManager.h" + #include "nsSpecialSystemDirectory.h" #include "nsFileStream.h" #include "nspr.h" #include "jsapi.h" -#include "nsISoftwareUpdate.h" -#include "nsSoftwareUpdateIIDs.h" +#if 0 +#include "nsIEventQueueService.h" +#include "nsXPComCIID.h" + +#include "nsIURL.h" + +#include "nsAppShellProxy.h" + + +static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); +static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); + +static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID); +static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); +#endif static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID); static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); + + + static JSClass global_class = { "global", JSCLASS_HAS_PRIVATE, @@ -24,6 +68,7 @@ static JSClass global_class = JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub }; + extern PRInt32 InitXPInstallObjects(JSContext *jscontext, JSObject *global, const char* jarfile, const char* args); // Defined in this file: @@ -119,7 +164,7 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 * installJSFileSpec.MakeUnique(); // Extract the install.js file. - rv = ZIP_ExtractFile( hZip, "install.js", installJSFileSpec.GetCString() ); + rv = ZIP_ExtractFile( hZip, "install.js", nsprPath(installJSFileSpec) ); if (rv != ZIP_OK) { ZIP_CloseArchive(&hZip); @@ -146,8 +191,9 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 * { delete [] buffer; } - + ZIP_CloseArchive(&hZip); + fileStream.close(); installJSFileSpec.Delete(PR_FALSE); return rv; @@ -223,6 +269,24 @@ static nsresult SetupInstallContext(const char* jarFile, /////////////////////////////////////////////////////////////////////////////////////////////// PRInt32 RunInstall(nsInstallInfo *installInfo) { +#if 0 + // We are one the UI Thread. Get and save the eventQueue. + // Create the Event Queue for the UI thread... + nsIEventQueueService* eventQService; + nsresult rv = nsServiceManager::GetService(kEventQueueServiceCID, + kIEventQueueServiceIID, + (nsISupports **)&eventQService); + PLEventQueue* thisEventQueue; + if (NS_OK == rv) + { + + rv = eventQService->GetThreadEventQueue(PR_GetCurrentThread(), + &thisEventQueue); + + } + + installInfo->SetUIEventQueue(thisEventQueue); +#endif PR_CreateThread(PR_USER_THREAD, RunInstallOnThread, (void*)installInfo, @@ -245,20 +309,62 @@ PRInt32 RunInstall(nsInstallInfo *installInfo) extern "C" void RunInstallOnThread(void *data) { nsInstallInfo *installInfo = (nsInstallInfo*)data; + nsresult rv; + +#if 0 + /* + * Create the Application Shell instance... + */ + nsIAppShellService* appShell; + rv = nsServiceManager::GetService(kAppShellServiceCID, + kIAppShellServiceIID, + (nsISupports**)&appShell); + if (NS_FAILED(rv)) + { + return; + } + + nsAppShellProxy *appShellProxy = new nsAppShellProxy(installInfo->GetUIEventQueue(), appShell); + + // DO NOT CALL INIT! appShellProxy->Initialize(); + + nsString *aCID = new nsString("00000000-dead-beef-0000-000000000000"); + nsIWebShellWindow* newWindow; + nsIURL* url; + char* urlstr = "resource:/res/samples/xpinstallprogress.xul"; + NS_NewURL(&url, urlstr); + + + appShellProxy->CreateDialogWindow(nsnull, + url, + *aCID, + newWindow, + nsnull, + nsnull, + 250, + 125); + +#endif + RunInstall( (const char*) nsAutoCString( installInfo->GetLocalFile() ), (const char*) nsAutoCString( installInfo->GetFlags() ), (const char*) nsAutoCString( installInfo->GetArguments() ), (const char*) nsAutoCString( installInfo->GetFromURL() )); +#if 0 + appShellProxy->CloseTopLevelWindow(newWindow); + + nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); // After Install, we need to update the queue. +#endif nsISoftwareUpdate *softwareUpdate; - nsresult rv = nsComponentManager::CreateInstance( kSoftwareUpdateCID, - nsnull, - kISoftwareUpdateIID, - (void**) &softwareUpdate); + rv = nsComponentManager::CreateInstance( kSoftwareUpdateCID, + nsnull, + kISoftwareUpdateIID, + (void**) &softwareUpdate); if (NS_FAILED(rv)) { diff --git a/xpinstall/src/nsSoftwareUpdateStream.cpp b/xpinstall/src/nsSoftwareUpdateStream.cpp index bb970805299e..82af5d502dd5 100644 --- a/xpinstall/src/nsSoftwareUpdateStream.cpp +++ b/xpinstall/src/nsSoftwareUpdateStream.cpp @@ -44,7 +44,7 @@ nsSoftwareUpdateListener::nsSoftwareUpdateListener(nsInstallInfo *nextInstall) NS_INIT_REFCNT(); mInstallInfo = nextInstall; - mOutFileDesc = PR_Open(nsAutoCString(nextInstall->GetLocalFile()), PR_CREATE_FILE | PR_RDWR, 0644); + mOutFileDesc = PR_Open(nsAutoCString(nextInstall->GetLocalFile()), PR_CREATE_FILE | PR_RDWR, 0744); if(mOutFileDesc == NULL) {