diff --git a/mozilla/xpinstall/Makefile.in b/mozilla/xpinstall/Makefile.in new file mode 100644 index 00000000000..16b83d80736 --- /dev/null +++ b/mozilla/xpinstall/Makefile.in @@ -0,0 +1,31 @@ +# +# 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. +# + +DEPTH = .. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = public src + +include $(topsrcdir)/config/config.mk + +include $(topsrcdir)/config/rules.mk + + diff --git a/mozilla/xpinstall/makefile.win b/mozilla/xpinstall/makefile.win index 1166b03f914..6b60af16bc7 100644 --- a/mozilla/xpinstall/makefile.win +++ b/mozilla/xpinstall/makefile.win @@ -17,6 +17,6 @@ DEPTH=.. -DIRS= public src +DIRS= public src include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/xpinstall/public/Makefile.in b/mozilla/xpinstall/public/Makefile.in new file mode 100644 index 00000000000..46dfe7ef8b8 --- /dev/null +++ b/mozilla/xpinstall/public/Makefile.in @@ -0,0 +1,36 @@ +#!gmake +# +# 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. + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = xpinstall + +EXPORTS = \ + nsSoftwareUpdateIIDs.h \ + nsISoftwareUpdate.h \ + $(NULL) + +EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) + +include $(topsrcdir)/config/config.mk + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpinstall/public/idl/Install.idl b/mozilla/xpinstall/public/idl/Install.idl index 31f6b25cbc9..6651bc174a8 100644 --- a/mozilla/xpinstall/public/idl/Install.idl +++ b/mozilla/xpinstall/public/idl/Install.idl @@ -3,48 +3,48 @@ interface Install /* IID: { 0x18c2f988, 0xb09f, 0x11d2, \ {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */ - const int SUERR_BAD_PACKAGE_NAME = -200; - const int SUERR_UNEXPECTED_ERROR = -201; - const int SUERR_ACCESS_DENIED = -202; - const int SUERR_TOO_MANY_CERTIFICATES = -203; /* Installer file must have 1 certificate */ - const int SUERR_NO_INSTALLER_CERTIFICATE = -204; /* Installer file must have a certificate */ - const int SUERR_NO_CERTIFICATE = -205; /* Extracted file is not signed */ - const int SUERR_NO_MATCHING_CERTIFICATE = -206; /* Extracted file does not match installer certificate */ - const int SUERR_UNKNOWN_JAR_FILE = -207; /* JAR file has not been opened */ - const int SUERR_INVALID_ARGUMENTS = -208; /* Bad arguments to a function */ - const int SUERR_ILLEGAL_RELATIVE_PATH = -209; /* Illegal relative path */ - const int SUERR_USER_CANCELLED = -210; /* User cancelled */ - const int SUERR_INSTALL_NOT_STARTED = -211; - const int SUERR_SILENT_MODE_DENIED = -212; - const int SUERR_NO_SUCH_COMPONENT = -213; /* no such component in the registry. */ - const int SUERR_FILE_DOES_NOT_EXIST = -214; /* File cannot be deleted as it does not exist */ - const int SUERR_FILE_READ_ONLY = -215; /* File cannot be deleted as it is read only. */ - const int SUERR_FILE_IS_DIRECTORY = -216; /* File cannot be deleted as it is a directory */ - const int SUERR_NETWORK_FILE_IS_IN_USE = -217; /* File on the network is in-use */ - const int SUERR_APPLE_SINGLE_ERR = -218; /* error in AppleSingle unpacking */ - const int SUERR_INVALID_PATH_ERR = -219; /* GetFolder() did not like the folderID */ - const int SUERR_PATCH_BAD_DIFF = -220; /* error in GDIFF patch */ - const int SUERR_PATCH_BAD_CHECKSUM_TARGET = -221; /* source file doesn't checksum */ - const int SUERR_PATCH_BAD_CHECKSUM_RESULT = -222; /* final patched file fails checksum */ - const int SUERR_UNINSTALL_FAILED = -223; /* error while uninstalling a package */ - const int SUERR_GESTALT_UNKNOWN_ERR = -5550; - const int SUERR_GESTALT_INVALID_ARGUMENT = -5551; + const int BAD_PACKAGE_NAME = -200; + const int UNEXPECTED_ERROR = -201; + const int ACCESS_DENIED = -202; + const int TOO_MANY_CERTIFICATES = -203; /* Installer file must have 1 certificate */ + const int NO_INSTALLER_CERTIFICATE = -204; /* Installer file must have a certificate */ + const int NO_CERTIFICATE = -205; /* Extracted file is not signed */ + const int NO_MATCHING_CERTIFICATE = -206; /* Extracted file does not match installer certificate */ + const int UNKNOWN_JAR_FILE = -207; /* JAR file has not been opened */ + const int INVALID_ARGUMENTS = -208; /* Bad arguments to a function */ + const int ILLEGAL_RELATIVE_PATH = -209; /* Illegal relative path */ + const int USER_CANCELLED = -210; /* User cancelled */ + const int INSTALL_NOT_STARTED = -211; + const int SILENT_MODE_DENIED = -212; + const int NO_SUCH_COMPONENT = -213; /* no such component in the registry. */ + const int FILE_DOES_NOT_EXIST = -214; /* File cannot be deleted as it does not exist */ + const int FILE_READ_ONLY = -215; /* File cannot be deleted as it is read only. */ + const int FILE_IS_DIRECTORY = -216; /* File cannot be deleted as it is a directory */ + const int NETWORK_FILE_IS_IN_USE = -217; /* File on the network is in-use */ + const int APPLE_SINGLE_ERR = -218; /* error in AppleSingle unpacking */ + const int INVALID_PATH_ERR = -219; /* GetFolder() did not like the folderID */ + const int PATCH_BAD_DIFF = -220; /* error in GDIFF patch */ + const int PATCH_BAD_CHECKSUM_TARGET = -221; /* source file doesn't checksum */ + const int PATCH_BAD_CHECKSUM_RESULT = -222; /* final patched file fails checksum */ + const int UNINSTALL_FAILED = -223; /* error while uninstalling a package */ + const int GESTALT_UNKNOWN_ERR = -5550; + const int GESTALT_INVALID_ARGUMENT = -5551; - const int SU_SUCCESS = 0; - const int SU_REBOOT_NEEDED = 999; + const int SUCCESS = 0; + const int REBOOT_NEEDED = 999; /* install types */ - const int SU_LIMITED_INSTALL = 0; - const int SU_FULL_INSTALL = 1; - const int SU_NO_STATUS_DLG = 2; - const int SU_NO_FINALIZE_DLG = 4; + const int LIMITED_INSTALL = 0; + const int FULL_INSTALL = 1; + const int NO_STATUS_DLG = 2; + const int NO_FINALIZE_DLG = 4; - + // these should not be public... /* message IDs*/ const int SU_INSTALL_FILE_UNEXPECTED_MSG_ID = 0; const int SU_DETAILS_REPLACE_FILE_MSG_ID = 1; const int SU_DETAILS_INSTALL_FILE_MSG_ID = 2; - + ////////////////////////// readonly attribute wstring UserPackageName; readonly attribute wstring RegPackageName; diff --git a/mozilla/xpinstall/public/idl/InstallVersion.idl b/mozilla/xpinstall/public/idl/InstallVersion.idl index cef90000952..531a35b0685 100644 --- a/mozilla/xpinstall/public/idl/InstallVersion.idl +++ b/mozilla/xpinstall/public/idl/InstallVersion.idl @@ -3,15 +3,15 @@ interface InstallVersion /* IID: { 0x18c2f986, 0xb09f, 0x11d2, \ {0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */ - const int SU_EQUAL = 0; - const int SU_BLD_DIFF = 1; - const int SU_BLD_DIFF_MINUS = -1; - const int SU_REL_DIFF = 2; - const int SU_REL_DIFF_MINUS = -2; - const int SU_MINOR_DIFF = 3; - const int SU_MINOR_DIFF_MINUS = -3; - const int SU_MAJOR_DIFF = 4; - const int SU_MAJOR_DIFF_MINUS = -4; + const int EQUAL = 0; + const int BLD_DIFF = 1; + const int BLD_DIFF_MINUS = -1; + const int REL_DIFF = 2; + const int REL_DIFF_MINUS = -2; + const int MINOR_DIFF = 3; + const int MINOR_DIFF_MINUS = -3; + const int MAJOR_DIFF = 4; + const int MAJOR_DIFF_MINUS = -4; attribute int major; attribute int minor; diff --git a/mozilla/xpinstall/public/nsIDOMInstallVersion.h b/mozilla/xpinstall/public/nsIDOMInstallVersion.h index 056803b2603..813cb19320c 100644 --- a/mozilla/xpinstall/public/nsIDOMInstallVersion.h +++ b/mozilla/xpinstall/public/nsIDOMInstallVersion.h @@ -34,15 +34,15 @@ class nsIDOMInstallVersion : public nsISupports { public: static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLVERSION_IID; return iid; } enum { - SU_EQUAL = 0, - SU_BLD_DIFF = 1, - SU_BLD_DIFF_MINUS = -1, - SU_REL_DIFF = 2, - SU_REL_DIFF_MINUS = -2, - SU_MINOR_DIFF = 3, - SU_MINOR_DIFF_MINUS = -3, - SU_MAJOR_DIFF = 4, - SU_MAJOR_DIFF_MINUS = -4 + EQUAL = 0, + BLD_DIFF = 1, + BLD_DIFF_MINUS = -1, + REL_DIFF = 2, + REL_DIFF_MINUS = -2, + MINOR_DIFF = 3, + MINOR_DIFF_MINUS = -3, + MAJOR_DIFF = 4, + MAJOR_DIFF_MINUS = -4 }; NS_IMETHOD GetMajor(PRInt32* aMajor)=0; diff --git a/mozilla/xpinstall/public/nsISoftwareUpdate.h b/mozilla/xpinstall/public/nsISoftwareUpdate.h index 4a7c944741d..2fce36fa3d4 100644 --- a/mozilla/xpinstall/public/nsISoftwareUpdate.h +++ b/mozilla/xpinstall/public/nsISoftwareUpdate.h @@ -21,6 +21,9 @@ #include "nsISupports.h" #include "nsIFactory.h" +#include "nsString.h" + + //FIX NEED REAL IID #define NS_ISOFTWAREUPDATE_IID \ @@ -34,6 +37,8 @@ class nsISoftwareUpdate : public nsISupports NS_IMETHOD Startup() = 0; NS_IMETHOD Shutdown()= 0; + NS_IMETHOD InstallJar(const nsString& jarFile, const nsString& args) = 0; + }; diff --git a/mozilla/xpinstall/src/Makefile.in b/mozilla/xpinstall/src/Makefile.in new file mode 100644 index 00000000000..dbe5df58484 --- /dev/null +++ b/mozilla/xpinstall/src/Makefile.in @@ -0,0 +1,23 @@ +# +# 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. +# + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +VPATH = @srcdir@ +srcdir = @srcdir@ + +include $(topsrcdir)/config/rules.mk \ No newline at end of file diff --git a/mozilla/xpinstall/src/makefile.win b/mozilla/xpinstall/src/makefile.win index d5246667926..d862f1c9cf2 100644 --- a/mozilla/xpinstall/src/makefile.win +++ b/mozilla/xpinstall/src/makefile.win @@ -35,6 +35,7 @@ LINCS= \ -I..\base \ -I$(XPDIST)\public\xpinstall \ -I$(XPDIST)\public\js \ + -I$(XPDIST)\public\jar \ -I$(XPDIST)\public\netlib \ -I$(XPDIST)\public\network \ -I$(XPDIST)\public\dom \ @@ -47,6 +48,7 @@ LINCS= \ $(NULL) LLIBS = \ + $(DIST)\lib\jar50.lib \ $(DIST)\lib\libreg32.lib \ $(DIST)\lib\netlib.lib \ $(DIST)\lib\xpcom32.lib \ diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index 2c20d1eee1e..d9c39cfcd4d 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -24,12 +24,14 @@ #include "nsVector.h" #include "nsHashtable.h" +#include "nsFileSpec.h" #include "prmem.h" #include "pratom.h" #include "prefapi.h" #include "VerReg.h" +#include "zipfile.h" #include "nsInstall.h" @@ -58,6 +60,8 @@ nsInstall::nsInstall() mScriptObject = nsnull; mVersionInfo = nsnull; + mJarFileData = nsnull; + mPackageName = ""; mUserPackageName= ""; @@ -734,8 +738,7 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPacka *aReturn = nsInstall::SUCCESS; ResetError(); - ParseFlags(aFlags); - + mUserCancelled = PR_FALSE; mUserPackageName = aUserPackageName; @@ -779,36 +782,8 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aPacka return -1; /* FIX: need real error code */ } - if (mShowProgress) - { - /* Show our window here */ - } - -#if 0 - // set up default package folder, if any - int err; - char* path = (char*) PR_Malloc(MAXREGPATHLEN); - char* packageNameCString = mPackageName.ToNewCString(); - - err = VR_GetDefaultDirectory( packageNameCString , MAXREGPATHLEN, path ); + /* Show our window here */ - delete [] packageNameCString; - - if (err != REGERR_OK) - { - PR_FREEIF(path); - path = NULL; - } - - if ( path != NULL ) - { - mPackageFolder = new nsInstallFolder(); - mPackageFolder->Init("Installed", nsString(path), mPackageName); - - PR_FREEIF(path); - } -#endif - SaveError(*aReturn); if (*aReturn != nsInstall::SUCCESS) @@ -853,20 +828,6 @@ nsInstall::Uninstall(const nsString& aPackageName, PRInt32* aReturn) //////////////////////////////////////// -/* - - aJarFile - location inside a jar file - - -*/ - -PRInt32 -nsInstall::ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFile, nsString& aTempFile, PRInt32* error) -{ - *error = SUCCESS; - return NS_OK; -} - void nsInstall::AddPatch(nsHashKey *aKey, nsString* fileName) @@ -932,21 +893,7 @@ nsInstall::ScheduleForInstall(nsInstallObject* ob) } - -void -nsInstall::ParseFlags(int flags) -{ - mShowProgress = mShowFinalize = PR_TRUE; - if ((flags & NO_STATUS_DLG) == NO_STATUS_DLG) - { - mShowProgress = PR_FALSE; - } - if ((flags & NO_FINALIZE_DLG) == NO_FINALIZE_DLG) - { - mShowFinalize = PR_FALSE; - } -} - + /** * SanityCheck * @@ -1166,17 +1113,88 @@ nsInstall::CleanUp(void) //CloseProgressDialog(); } + +void +nsInstall::GetJarFileLocation(char** aFile) +{ + *aFile = mJarFileLocation; +} + +void +nsInstall::SetJarFileLocation(char* aFile) +{ + mJarFileLocation = aFile; +} + +void +nsInstall::GetInstallArguments(char** args) +{ + *args = mInstallArguments; +} + +void +nsInstall::SetInstallArguments(char* args) +{ + mInstallArguments = args; +} + + + PRInt32 nsInstall::OpenJARFile(void) -{ - return nsInstall::SUCCESS; +{ + + PRInt32 result = ZIPR_OpenArchive(mJarFileLocation, &mJarFileData); + + return result; } void nsInstall::CloseJARFile(void) { + ZIPR_CloseArchive(&mJarFileData); + mJarFileData = nsnull; } + +// aJarFile - This is the filepath within the jar file. +// aSuggestedName - This is the name that we should try to extract to. If we can, we will create a new temporary file. +// aRealName - This is the name that we did extract to. This will be allocated by use and should be disposed by the caller. + +PRInt32 +nsInstall::ExtractFileFromJar(const nsString& aJarfile, const nsString& aSuggestedName, nsString** aRealName) +{ + PRInt32 result; + char* extractFileHere; + + + nsFileSpec finalFile(aSuggestedName); + + if (aSuggestedName == "" || finalFile.Exists() ) + { + // Create a temporary file to extract to. + + extractFileHere = "c:\\temp\\tempFile.tmp"; + } + else + { + // extract to the final destination. + extractFileHere = aSuggestedName.ToNewCString(); + } + + *aRealName = new nsString(extractFileHere); + + char* fileInJar = aJarfile.ToNewCString(); + + result = ZIPR_ExtractFile( mJarFileData, fileInJar, extractFileHere ); + + delete [] fileInJar; + //delete [] extractFileHere; + + return result; +} + + PRInt32 nsInstall::ExtractDirEntries(const nsString& directory, nsVector *paths) { diff --git a/mozilla/xpinstall/src/nsInstall.h b/mozilla/xpinstall/src/nsInstall.h index b994546399f..f30990f4c7c 100644 --- a/mozilla/xpinstall/src/nsInstall.h +++ b/mozilla/xpinstall/src/nsInstall.h @@ -2,21 +2,21 @@ #define __NS_INSTALL_H__ #include "nscore.h" -#include "nsString.h" #include "nsISupports.h" + #include "jsapi.h" +#include "nsString.h" #include "nsFileSpec.h" #include "nsVector.h" #include "nsHashtable.h" #include "nsSoftwareUpdate.h" +#include "nsInstallObject.h" #include "nsInstallFolder.h" #include "nsInstallVersion.h" -#include "nsInstallObject.h" - class nsInstall { public: @@ -94,16 +94,28 @@ class nsInstall - PRInt32 ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFile, nsString& aTempFile, PRInt32* aError); + PRInt32 ExtractFileFromJar(const nsString& aJarfile, const nsString& aFinalFile, nsString** aTempFile); void AddPatch(nsHashKey *aKey, nsString* fileName); void GetPatch(nsHashKey *aKey, nsString* fileName); + + void GetJarFileLocation(char** aFile); + void SetJarFileLocation(char* aFile); + + void GetInstallArguments(char** args); + void SetInstallArguments(char* args); + private: JSObject* mScriptObject; + + char* mJarFileLocation; + void* mJarFileData; + + char* mInstallArguments; + PRBool mUserCancelled; - PRBool mShowProgress; - PRBool mShowFinalize; + PRBool mUninstallPackage; PRBool mRegisterPackage; diff --git a/mozilla/xpinstall/src/nsInstallExecute.cpp b/mozilla/xpinstall/src/nsInstallExecute.cpp index 9a3189dec03..28455be2d65 100644 --- a/mozilla/xpinstall/src/nsInstallExecute.cpp +++ b/mozilla/xpinstall/src/nsInstallExecute.cpp @@ -44,31 +44,34 @@ nsInstallExecute:: nsInstallExecute( nsInstall* inInstall, return; } - mJarLocation = inJarLocation; - mArgs = inArgs; + mJarLocation = inJarLocation; + mArgs = inArgs; + mExecutableFile = nsnull; } nsInstallExecute::~nsInstallExecute() { + delete mExecutableFile; } + PRInt32 nsInstallExecute::Prepare() { - if (mInstall == NULL || mExecutableFile == "null" || mJarLocation == "null") + if (mInstall == NULL || mJarLocation == "null") return nsInstall::INVALID_ARGUMENTS; - PRInt32 err; - mInstall->ExtractFileFromJar(mJarLocation, "", mExecutableFile, &err); - - return err; + return mInstall->ExtractFileFromJar(mJarLocation, "", &mExecutableFile); } PRInt32 nsInstallExecute::Complete() { - char* tempCString = mExecutableFile.ToNewCString(); + if (mExecutableFile == nsnull) + return nsInstall::INVALID_ARGUMENTS; + + char* tempCString = mExecutableFile->ToNewCString(); nsFileSpec appPath(tempCString , false); @@ -94,23 +97,23 @@ void nsInstallExecute::Abort() int result; /* Get the names */ - if (mExecutableFile == "") + if (mExecutableFile == nsnull) return; - currentName = mExecutableFile.ToNewCString(); + + currentName = mExecutableFile->ToNewCString(); result = PR_Delete(currentName); - PR_ASSERT(result == 0); /* XXX: need to fe_deletefilelater() or something */ + PR_ASSERT(result == 0); /* FIX: need to fe_deletefilelater() or something */ + delete currentName; } char* nsInstallExecute::toString() { - nsString fullPathString; + nsString fullPathString(mJarLocation); + fullPathString.Append(*mExecutableFile); - fullPathString = mJarLocation; - fullPathString += mExecutableFile; - - if (mExecutableFile == "null") + if (mExecutableFile == nsnull) { // FIX! // return nsInstallErrorMessages::GetString(nsInstall::DETAILS_EXECUTE_PROGRESS, fullPathString); diff --git a/mozilla/xpinstall/src/nsInstallExecute.h b/mozilla/xpinstall/src/nsInstallExecute.h index 07f74f2b04d..df5a620fd9a 100644 --- a/mozilla/xpinstall/src/nsInstallExecute.h +++ b/mozilla/xpinstall/src/nsInstallExecute.h @@ -53,9 +53,11 @@ class nsInstallExecute : public nsInstallObject private: nsString mJarLocation; // Location in the JAR - nsString mExecutableFile; // temporary file location nsString mArgs; // command line arguments - + + nsString *mExecutableFile; // temporary file location + + PRInt32 NativeComplete(void); void NativeAbort(void); diff --git a/mozilla/xpinstall/src/nsInstallFile.cpp b/mozilla/xpinstall/src/nsInstallFile.cpp index e14a5fc28ac..da02363f6f6 100644 --- a/mozilla/xpinstall/src/nsInstallFile.cpp +++ b/mozilla/xpinstall/src/nsInstallFile.cpp @@ -31,8 +31,9 @@ #include "nsInstallFile.h" #include "nsInstall.h" +#include "nsInstallVersion.h" #include "nsIDOMInstallFolder.h" -#include "nsIDOMInstallVersion.h" + #include "nsInstallErrorMessages.h" @@ -80,16 +81,25 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, return; } - mVersionRegistryName = new nsString(inVRName); - mJarLocation = new nsString(inJarLocation); - mVersionInfo = inVInfo; /* XXX: Who owns and who free's this object. Is it nsSoftwareUpdate?? */ + + mReplaceFile = DoesFileExist(); mForceInstall = forceInstall; - folderSpec->IsJavaCapable(&mJavaInstall); + mVersionRegistryName = new nsString(inVRName); + mJarLocation = new nsString(inJarLocation); + mVersionInfo = new nsInstallVersion(); + + + //FIX need to delete char* created by .ToNewCString(). + + nsString tempString; + inVInfo->ToString(tempString); + mVersionInfo->Init(tempString.ToNewCString()); + mFinalFile = new nsString(); folderSpec->MakeFullPath(inPartialPath, *mFinalFile); - mReplaceFile = DoesFileExist(); + nsString regPackageName; @@ -122,12 +132,20 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, nsInstallFile::~nsInstallFile() { - delete mVersionRegistryName; - delete mJarLocation; - if (mTempFile) - delete mTempFile; - if (mFinalFile) - delete mFinalFile; + if (mVersionRegistryName) + delete mVersionRegistryName; + + if (mJarLocation) + delete mJarLocation; + + if (mTempFile) + delete mTempFile; + + if (mFinalFile) + delete mFinalFile; + + if (mVersionInfo) + delete mVersionInfo; } /* Prepare @@ -138,10 +156,7 @@ PRInt32 nsInstallFile::Prepare() if (mInstall == NULL || mFinalFile == NULL || mJarLocation == NULL) return nsInstall::INVALID_ARGUMENTS; - PRInt32 err; - mInstall->ExtractFileFromJar(*mJarLocation, *mFinalFile, *mTempFile, &err); - - return err; + return mInstall->ExtractFileFromJar(*mJarLocation, *mFinalFile, &mTempFile); } /* Complete @@ -165,22 +180,9 @@ PRInt32 nsInstallFile::Complete() err = NativeComplete(); - char *vr_name = mVersionRegistryName->ToNewCString(); char *final_file = mFinalFile->ToNewCString(); - - // Add java archives to the classpath. Don't add if we're - // replacing an existing file -- it'll already be there. - - if ( mJavaInstall && !mReplaceFile ) - { - PRBool found_zip = endsWith(mFinalFile, ".zip"); - PRBool found_jar = endsWith(mFinalFile, ".jar");; - if (found_zip || found_jar) - { - AddToClasspath( mFinalFile ); - } - } - + char *vr_name = mVersionRegistryName->ToNewCString(); + nsString regPackageName; mInstall->GetRegPackageName(regPackageName); @@ -421,17 +423,6 @@ end: } - -void nsInstallFile::AddToClasspath(nsString* file) -{ - if ( file != NULL ) { - char *final_file = file->ToNewCString(); -// FIX JVM_AddToClassPath(final_file); - delete final_file; - } -} - - /* Finds out if the file exists */ PRBool nsInstallFile::DoesFileExist() diff --git a/mozilla/xpinstall/src/nsInstallFile.h b/mozilla/xpinstall/src/nsInstallFile.h index 7cf07245a9f..30eec6d51a0 100644 --- a/mozilla/xpinstall/src/nsInstallFile.h +++ b/mozilla/xpinstall/src/nsInstallFile.h @@ -25,8 +25,9 @@ #include "nsInstallObject.h" #include "nsInstall.h" +#include "nsInstallVersion.h" #include "nsIDOMInstallFolder.h" -#include "nsIDOMInstallVersion.h" + class nsInstallFile : public nsInstallObject @@ -66,7 +67,7 @@ class nsInstallFile : public nsInstallObject private: /* Private Fields */ - nsIDOMInstallVersion* mVersionInfo; /* Version info for this file*/ + nsInstallVersion* mVersionInfo; /* Version info for this file*/ nsString* mJarLocation; /* Location in the JAR */ nsString* mTempFile; /* temporary file location */ @@ -81,7 +82,6 @@ class nsInstallFile : public nsInstallObject int NativeComplete(); PRBool DoesFileExist(); - void AddToClasspath(nsString* file); }; #endif /* nsInstallFile_h__ */ diff --git a/mozilla/xpinstall/src/nsInstallPatch.cpp b/mozilla/xpinstall/src/nsInstallPatch.cpp index 24a6042806a..792f0d72fb4 100644 --- a/mozilla/xpinstall/src/nsInstallPatch.cpp +++ b/mozilla/xpinstall/src/nsInstallPatch.cpp @@ -51,7 +51,8 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mJarLocation = inJarLocation; - mPatchFile = ""; + mPatchFile = nsnull; + mTargetFile = ""; mPatchedFile = ""; @@ -97,7 +98,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mVersionInfo = inVInfo; /* Who owns this object? May be we should make a copy of it */ mJarLocation = inJarLocation; - mPatchFile = ""; + mPatchFile = nsnull; mPatchedFile = ""; folderSpec->MakeFullPath(inPartialPath, mTargetFile); @@ -105,6 +106,8 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, nsInstallPatch::~nsInstallPatch() { + if (mPatchFile != nsnull) + delete mPatchFile; } @@ -138,7 +141,7 @@ PRInt32 nsInstallPatch::Prepare() return err; } - mInstall->ExtractFileFromJar(mJarLocation, mTargetFile, mPatchFile, &err); + err = mInstall->ExtractFileFromJar(mJarLocation, mTargetFile, &mPatchFile); nsString *fileName = nsnull; @@ -156,7 +159,7 @@ PRInt32 nsInstallPatch::Prepare() deleteOldSrc = PR_FALSE; } - err = NativePatch( *fileName, mPatchFile, mPatchedFile); + err = NativePatch( *fileName, *mPatchFile, mPatchedFile); if (err != nsInstall::SUCCESS) { diff --git a/mozilla/xpinstall/src/nsInstallPatch.h b/mozilla/xpinstall/src/nsInstallPatch.h index 95bc1104bd2..09b3922d830 100644 --- a/mozilla/xpinstall/src/nsInstallPatch.h +++ b/mozilla/xpinstall/src/nsInstallPatch.h @@ -64,7 +64,9 @@ class nsInstallPatch : public nsInstallObject nsIDOMInstallVersion* mVersionInfo; nsString mJarLocation; - nsString mPatchFile; + + nsString *mPatchFile; + nsString mTargetFile; nsString mPatchedFile; diff --git a/mozilla/xpinstall/src/nsJSInstall.cpp b/mozilla/xpinstall/src/nsJSInstall.cpp index d62d20d4727..72a0f8b588e 100644 --- a/mozilla/xpinstall/src/nsJSInstall.cpp +++ b/mozilla/xpinstall/src/nsJSInstall.cpp @@ -85,6 +85,22 @@ GetInstallProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case INSTALL_JARFILE: + { + char* prop; + a->GetJarFileLocation(&prop); + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + break; + } + + case INSTALL_ARGUMENTS: + { + char* prop; + a->GetInstallArguments(&prop); + nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); + break; + } + default: return JS_TRUE; } @@ -1065,7 +1081,7 @@ Install(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) // Install class initialization // -PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, nsFileSpec* jarfile, PRInt32 flags, char* argc, PRInt32 argv) +PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, char* jarfile, char* args) { JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); JSObject *global = JS_GetGlobalObject(jscontext); @@ -1094,6 +1110,8 @@ PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, nsFileSpec* jarfile, PR nativeInstallObject = new nsInstall(); + nativeInstallObject->SetJarFileLocation(jarfile); + nativeInstallObject->SetInstallArguments(args); JS_SetPrivate(jscontext, installObject, nativeInstallObject); nativeInstallObject->SetScriptObject(installObject); diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp index d8601903df4..948e1593cee 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp @@ -28,6 +28,7 @@ #include "VerReg.h" + #include "nsIScriptObjectOwner.h" #include "nsIScriptGlobalObject.h" @@ -164,7 +165,7 @@ nsSoftwareUpdate::Startup() /* Stupid Hack to test js env*/ /***************************************/ - RunInstallJS("c:\\temp\\test.js"); + InstallJar(nsString("c:\\temp\\test.jar"), ""); DeleteScheduledNodes(); @@ -179,6 +180,23 @@ nsSoftwareUpdate::Shutdown() return NS_OK; } +// We will need to have a overloaded function for multiple jarfile triggers. + +NS_IMETHODIMP +nsSoftwareUpdate::InstallJar(const nsString& jarFile, const nsString& args) +{ + // FIX: Display some UI indicating that we are going to start an install. + + + char* tempJarFileName = jarFile.ToNewCString(); + + PRInt32 result = Install(tempJarFileName, nsnull); + + delete [] tempJarFileName; + + return result; +} + nsresult nsSoftwareUpdate::DeleteScheduledNodes() @@ -334,13 +352,6 @@ nsSoftwareUpdateNameSet::AddNameSet(nsIScriptContext* aScriptContext) result = aScriptContext->GetNameSpaceManager(&manager); if (NS_OK == result) { -/* - result = manager->RegisterGlobalName("Install", - kInstall_CID, - PR_TRUE); - - if (result != NS_OK) return result; -*/ result = manager->RegisterGlobalName("InstallVersion", kInstallVersion_CID, PR_TRUE); @@ -374,24 +385,28 @@ nsSoftwareUpdateNameSet::AddNameSet(nsIScriptContext* aScriptContext) //////////////////////////////////////////////////////////////////////////////// extern "C" NS_EXPORT PRBool -NSCanUnload(void) +NSCanUnload(nsISupports* serviceMgr) { return PRBool (gInstanceCnt == 0 && gLockCnt == 0); } extern "C" NS_EXPORT nsresult -NSRegisterSelf(const char *path) +NSRegisterSelf(nsISupports* serviceMgr, const char *path) { - nsRepository::RegisterFactory(kSoftwareUpdate_CID, path, PR_TRUE, PR_TRUE); - nsRepository::RegisterFactory(kInstallTrigger_CID, path, PR_TRUE, PR_TRUE); - nsRepository::RegisterFactory(kInstallVersion_CID, path, PR_TRUE, PR_TRUE); - nsRepository::RegisterFactory(kInstallFolder_CID, path, PR_TRUE, PR_TRUE); + 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); + nsRepository::RegisterComponent(kInstallFolder_CID, NULL, NULL, path, PR_TRUE, PR_TRUE); + return NS_OK; } extern "C" NS_EXPORT nsresult -NSUnregisterSelf(const char *path) +NSUnregisterSelf(nsISupports* serviceMgr, const char *path) { + printf("*** XPInstall is being unregistered\n"); + nsRepository::UnregisterFactory(kSoftwareUpdate_CID, path); nsRepository::UnregisterFactory(kInstallTrigger_CID, path); nsRepository::UnregisterFactory(kInstallVersion_CID, path); @@ -403,7 +418,11 @@ NSUnregisterSelf(const char *path) extern "C" NS_EXPORT nsresult -NSGetFactory(const nsCID &aClass, nsISupports* serviceMgr, nsIFactory **aFactory) +NSGetFactory(nsISupports* serviceMgr, + const nsCID &aClass, + const char *aClassName, + const char *aProgID, + nsIFactory **aFactory) { if (aFactory == NULL) diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.h b/mozilla/xpinstall/src/nsSoftwareUpdate.h index ebfed7bbb8a..7f40afe8158 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.h +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.h @@ -8,6 +8,7 @@ #include "nscore.h" #include "nsIFactory.h" #include "nsISupports.h" +#include "nsString.h" #include "nsIScriptExternalNameSet.h" @@ -23,6 +24,7 @@ class nsSoftwareUpdate: public nsISoftwareUpdate NS_IMETHOD Startup(); NS_IMETHOD Shutdown(); + NS_IMETHOD InstallJar(const nsString& jarFile, const nsString& args); private: nsresult DeleteScheduledNodes(); @@ -40,7 +42,6 @@ class nsSoftwareUpdateNameSet : public nsIScriptExternalNameSet NS_IMETHOD AddNameSet(nsIScriptContext* aScriptContext); }; - #define AUTOUPDATE_ENABLE_PREF "autoupdate.enabled" #define AUTOUPDATE_CONFIRM_PREF "autoupdate.confirm_install" #define CHARSET_HEADER "Charset" @@ -50,12 +51,5 @@ class nsSoftwareUpdateNameSet : public nsIScriptExternalNameSet #define REG_SOFTUPDT_DIR "Netscape/Communicator/SoftwareUpdate/" #define LAST_REGPACK_TIME "LastRegPackTime" -/* error codes */ -#define ErrInvalidArgs -1 -#define ErrUnknownInstaller -2 -#define ErrInternalError -3 -#define ErrBadScript -4 -#define JarError -5 -#define DiskSpaceError -6 #endif \ No newline at end of file diff --git a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp index 6c0f4f5a90e..67d5fc1a69b 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -12,8 +12,10 @@ #include "nsIScriptContextOwner.h" #include "nsInstall.h" +#include "zipfile.h" -extern PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, nsFileSpec* jarfile, PRInt32 flags, char* argc, PRInt32 argv); + +extern PRInt32 InitXPInstallObjects(nsIScriptContext *aContext, char* jarfile, char* args); static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID); @@ -35,7 +37,7 @@ static short ReadFileIntoBuffer(char * fileName, char** buffer, unsigned long *b if ( stat( fileName, &st) != 0 ) { - result = ErrInternalError; + result = -1; goto fail; } @@ -53,13 +55,13 @@ static short ReadFileIntoBuffer(char * fileName, char** buffer, unsigned long *b if ( file == NULL) { - result = ErrInternalError; + result = -1; goto fail; } if ( PR_Read(file, *buffer, *bufferSize ) != st.st_size ) { - result = ErrInternalError; + result = -1; PR_Close( file ); goto fail; } @@ -77,12 +79,40 @@ fail: } - -int RunInstallJS(char* installJSFile) +extern "C" NS_EXPORT PRInt32 Install(char* jarFile, char* args) { + // Open the jarfile. + void* hZip; + + PRInt32 result = ZIPR_OpenArchive(jarFile , &hZip); + + if (result != ZIP_OK) + { + return result; + } + + + // Read manifest file for Install Script filename. + //FIX: need to do. + + char* installJSFile = "c:\\temp\\install.js"; + + + remove(installJSFile); + + // Extract the install.js file. + result = ZIPR_ExtractFile( hZip, "install.js", installJSFile ); + if (result != ZIP_OK) + { + return result; + } + + nsIBrowserWindow *aWindow; nsIWebShell *aWebShell; + // Create a new window so that we can both run a script in it and display UI. + nsresult rv = nsRepository::CreateInstance( kBrowserWindowCID, nsnull, kIBrowserWindowIID, @@ -90,6 +120,12 @@ int RunInstallJS(char* installJSFile) if (rv == NS_OK) { nsRect rect(0, 0, 275, 300); + + nsAutoString retval; + PRBool isUndefined; + + nsIScriptContextOwner* scriptContextOwner; + nsIScriptContext* scriptContext; rv = aWindow->Init(nsnull, nsnull, rect, PRUint32(0), PR_FALSE); @@ -97,47 +133,27 @@ int RunInstallJS(char* installJSFile) { rv = aWindow->GetWebShell(aWebShell); - /* FIX: Display a window here...(ie.OpenURL) - - What about silent/forced installs? - */ + /* + * FIX: Display a window here...(ie.OpenURL) + */ - - nsAutoString retval; - PRBool isUndefined; - nsIScriptContextOwner* scriptContextOwner; - - if (NS_OK == aWebShell->QueryInterface( kIScriptContextOwnerIID, - (void**)&scriptContextOwner)) + if (NS_OK == aWebShell->QueryInterface( kIScriptContextOwnerIID, (void**)&scriptContextOwner)) { - const char* url = ""; - nsIScriptContext* scriptContext; rv = scriptContextOwner->GetScriptContext(&scriptContext); if (NS_OK == rv) { - - /////////////////////////////////////////////////////////////////////// - // Init Install Object - /////////////////////////////////////////////////////////////////////// - nsFileSpec jarfile("c:\\temp\\jarfile.jar"); - PRInt32 flags = 0; - char* argc = nsnull; - PRInt32 argv = 0; - - InitXPInstallObjects(scriptContext, &jarfile, flags, argc, argv ); - - /////////////////////////////////////////////////////////////////////// - - - + + InitXPInstallObjects(scriptContext, jarFile, args ); char* buffer; unsigned long bufferLength; + ReadFileIntoBuffer(installJSFile, &buffer, &bufferLength); - + + // We expected this to block. scriptContext->EvaluateString(nsString(buffer), nsnull, 0, retval, &isUndefined); - + PR_FREEIF(buffer); NS_RELEASE(scriptContext); } @@ -145,9 +161,16 @@ int RunInstallJS(char* installJSFile) NS_RELEASE(scriptContextOwner); } } + aWindow->Close(); NS_RELEASE(aWindow); } + else + { + return -1; + } + + ZIPR_CloseArchive(&hZip); + return 0; } - diff --git a/mozilla/xpinstall/src/nsSoftwareUpdateRun.h b/mozilla/xpinstall/src/nsSoftwareUpdateRun.h index 4cec01a4b61..b4590cee701 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdateRun.h +++ b/mozilla/xpinstall/src/nsSoftwareUpdateRun.h @@ -1,6 +1,6 @@ #ifndef __NS_SoftwareUpdateRun_H__ #define __NS_SoftwareUpdateRun_H__ -int RunInstallJS(char* filename); +extern "C" NS_EXPORT PRInt32 Install(char* jarFile, char* args); #endif \ No newline at end of file