diff --git a/mozilla/xpinstall/src/Makefile.in b/mozilla/xpinstall/src/Makefile.in index 3d29f9405b3..be49de14eb1 100644 --- a/mozilla/xpinstall/src/Makefile.in +++ b/mozilla/xpinstall/src/Makefile.in @@ -35,25 +35,28 @@ IS_COMPONENT = 1 REQUIRES = dom js netlib raptor xpcom CPPSRCS = \ - nsSoftwareUpdate.cpp \ nsInstall.cpp \ - nsInstallDelete.cpp \ - nsInstallExecute.cpp \ - nsInstallFile.cpp \ - nsInstallFolder.cpp \ - nsInstallPatch.cpp \ - nsInstallUninstall.cpp \ nsInstallTrigger.cpp \ - nsInstallResources.cpp \ + nsInstallVersion.cpp \ + nsInstallFolder.cpp \ nsJSInstall.cpp \ nsJSInstallTriggerGlobal.cpp\ + nsJSInstallVersion.cpp \ + nsSoftwareUpdate.cpp \ nsSoftwareUpdateRun.cpp \ + nsInstallFile.cpp \ + nsInstallDelete.cpp \ + nsInstallExecute.cpp \ + nsInstallPatch.cpp \ + nsInstallUninstall.cpp \ + nsInstallResources.cpp \ nsTopProgressNotifier.cpp \ nsLoggingProgressNotifier.cpp \ ScheduledTasks.cpp \ - nsInstallFileOpItem.cpp \ + nsInstallProgressDialog.cpp \ nsXPITriggerInfo.cpp \ nsXPInstallManager.cpp \ + nsInstallFileOpItem.cpp \ $(NULL) INCLUDES += -I$(srcdir)/../public diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index 93b46b283ae..b4967442214 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -43,7 +43,7 @@ #include "prmem.h" #include "VerReg.h" -#include "zipfile.h" +//#include "zipfile.h" // replaced by nsIJAR.h #include "nsInstall.h" #include "nsInstallFolder.h" @@ -108,12 +108,13 @@ nsInstallInfo::GetLocalFile(char **aPath) static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID); static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); +static NS_DEFINE_IID(kIJARIID, NS_IJAR_IID); +static NS_DEFINE_IID(kJARCID, NS_JAR_CID); nsInstall::nsInstall() { mScriptObject = nsnull; // this is the jsobject for our context - mVersionInfo = nsnull; // this is the version information passed to us in StartInstall() - mJarFileData = nsnull; // this is an opaque handle to the jarfile. + mVersionInfo = nsnull; // this is the version information passed to us in StartInstall() mRegistryPackageName = ""; // this is the name that we will add into the registry for the component we are installing mUIName = ""; // this is the name that will be displayed in UI. @@ -123,8 +124,12 @@ nsInstall::nsInstall() mJarFileLocation = ""; mInstallArguments = ""; + // mJarFileData is an opaque handle to the jarfile. + nsresult rv = nsComponentManager::CreateInstance(kJARCID, nsnull, kIJARIID, + (void**) &mJarFileData); + nsISoftwareUpdate *su; - nsresult rv = nsServiceManager::GetService(kSoftwareUpdateCID, + rv = nsServiceManager::GetService(kSoftwareUpdateCID, kISoftwareUpdateIID, (nsISupports**) &su); @@ -687,6 +692,8 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS char dir[MAXREGPATHLEN]; nsFileSpec nsfsDir; +// FIX: aSubdirectory is not processed at all in this function. + *aFolder = nsnull; nsString tempString; @@ -1676,17 +1683,19 @@ nsInstall::SetInstallArguments(const nsString& args) PRInt32 nsInstall::OpenJARFile(void) { - - PRInt32 result = ZIP_OpenArchive(nsAutoCString(mJarFileLocation), &mJarFileData); - + PRInt32 result; + + nsresult rv = mJarFileData->Open( nsAutoCString(mJarFileLocation), &result ); + if (NS_FAILED(rv)) + return UNEXPECTED_ERROR; + return result; } void nsInstall::CloseJARFile(void) { - ZIP_CloseArchive(&mJarFileData); - mJarFileData = nsnull; + NS_IF_RELEASE(mJarFileData); } @@ -1708,7 +1717,7 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa // Get the extention of the file in the jar. - PRInt32 result = aJarfile.RFind("."); + result = aJarfile.RFind("."); if (result != -1) { // We found an extention. Add it to the tempfileName string @@ -1733,7 +1742,13 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa // 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), nsNSPRPath( *extractHereSpec ) ); + nsresult rv = mJarFileData->Extract( nsAutoCString(aJarfile), nsNSPRPath( *extractHereSpec ), &result ); + if (NS_FAILED(rv)) + { + if (extractHereSpec != nsnull) + delete extractHereSpec; + return EXTRACTION_FAILED; + } if (result == 0) { @@ -1751,38 +1766,59 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa PRInt32 nsInstall::ExtractDirEntries(const nsString& directory, nsVector *paths) { - PRInt32 err; - char buf[512]; // XXX: need an XP "max path" + char *buf; + nsISimpleEnumerator *jarEnum = nsnull; + nsIJARItem *currJARItem = nsnull; if ( paths ) { nsString pattern(directory); pattern += "/?*"; + PRInt32 prefix_length = directory.Length(); - void* find = ZIP_FindInit( mJarFileData, nsAutoCString(pattern) ); + nsresult rv = mJarFileData->Find( nsAutoCString(pattern), &jarEnum ); + if (NS_FAILED(rv) || !jarEnum) + goto handle_err; - if ( find ) + PRBool bMore; + rv = jarEnum->HasMoreElements(&bMore); + if (NS_FAILED(rv)) + goto handle_err; + + while (bMore) { - PRInt32 prefix_length = directory.Length(); - if ( prefix_length >= sizeof(buf)-1 ) - return UNEXPECTED_ERROR; - - err = ZIP_FindNext( find, buf, sizeof(buf) ); - while ( err == ZIP_OK ) + rv = jarEnum->GetNext( (nsISupports**) &currJARItem ); + if (currJARItem) { - paths->Add(new nsString(buf+prefix_length)); - err = ZIP_FindNext( find, buf, sizeof(buf) ); + // expensive 'buf' callee malloc per iteration! + rv = currJARItem->GetName(&buf); + if (NS_FAILED(rv)) + goto handle_err; + if (buf) + { + if ( prefix_length >= sizeof(buf)-1 ) + { + PR_FREEIF( buf ); + goto handle_err; + } + paths->Add( new nsString(buf+prefix_length) ); // XXX manipulation should be in caller + PR_FREEIF( buf ); + } + NS_IF_RELEASE(currJARItem); } - ZIP_FindFree( find ); + rv = jarEnum->HasMoreElements(&bMore); + if (NS_FAILED(rv)) + goto handle_err; } - else - err = ZIP_ERR_GENERAL; - - if ( err == ZIP_ERR_FNF ) - return SUCCESS; // found them all } - return UNEXPECTED_ERROR; + NS_IF_RELEASE(jarEnum); + return SUCCESS; + +handle_err: + NS_IF_RELEASE(jarEnum); + NS_IF_RELEASE(currJARItem); + return EXTRACTION_FAILED; } void diff --git a/mozilla/xpinstall/src/nsInstall.h b/mozilla/xpinstall/src/nsInstall.h index 33f3ba29b31..be2792a02d2 100644 --- a/mozilla/xpinstall/src/nsInstall.h +++ b/mozilla/xpinstall/src/nsInstall.h @@ -54,6 +54,8 @@ #include "nsIServiceManager.h" #include "nsIComponentManager.h" #include "nsIProperties.h" +#include "nsIEnumerator.h" +#include "nsIJAR.h" class nsInstallInfo { @@ -115,6 +117,7 @@ class nsInstall PATCH_BAD_CHECKSUM_RESULT = -222, UNINSTALL_FAILED = -223, PACKAGE_FOLDER_NOT_SET = -224, + EXTRACTION_FAILED = -225, GESTALT_UNKNOWN_ERR = -5550, GESTALT_INVALID_ARGUMENT = -5551, @@ -221,7 +224,7 @@ class nsInstall JSObject* mWinProfileObject; nsString mJarFileLocation; - void* mJarFileData; + nsIJAR* mJarFileData; nsString mInstallArguments; nsString mPackageFolder; diff --git a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp index d4c4ef3b497..b275f1304cc 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -28,7 +28,7 @@ #include "nsSoftwareUpdateIIDs.h" #include "nsInstall.h" -#include "zipfile.h" +//#include "zipfile.h" // replaced by nsIJAR.h #include "nsRepository.h" #include "nsIServiceManager.h" @@ -40,7 +40,8 @@ #include "jsapi.h" #include "nsIEventQueueService.h" - +#include "nsIEnumerator.h" +#include "nsIJAR.h" static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID); static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); @@ -126,16 +127,29 @@ XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report static nsresult GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *scriptLength) { - // Open the jarfile. - void* hZip; + nsIJAR* hZip = nsnull; + PRInt32 result; *scriptBuffer = nsnull; *scriptLength = 0; - nsresult rv = ZIP_OpenArchive(jarFile , &hZip); - - if (rv != ZIP_OK) + static NS_DEFINE_IID(kIJARIID, NS_IJAR_IID); + static NS_DEFINE_IID(kJARCID, NS_JAR_CID); + nsresult rv = nsComponentManager::CreateInstance(kJARCID, nsnull, kIJARIID, + (void**) &hZip); + // Open the jarfile + if (hZip) + rv = hZip->Open( jarFile, &result ); + if (NS_FAILED(rv)) + { + NS_IF_RELEASE(hZip); return rv; + } + if (result != 0) + { + NS_IF_RELEASE(hZip); + return NS_ERROR_FAILURE; + } // Read manifest file for Install Script filename. @@ -147,13 +161,18 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 * installJSFileSpec.MakeUnique(); // Extract the install.js file. - rv = ZIP_ExtractFile( hZip, "install.js", nsNSPRPath(installJSFileSpec) ); - if (rv != ZIP_OK) + rv = hZip->Extract( "install.js", nsNSPRPath(installJSFileSpec), &result ); + if (NS_FAILED(rv)) { - ZIP_CloseArchive(&hZip); + NS_IF_RELEASE( hZip ); return rv; } - + if (result != 0) + { + NS_IF_RELEASE(hZip); + return NS_ERROR_FAILURE; + } + // Read it into a buffer char* buffer; PRUint32 bufferLength; @@ -175,7 +194,7 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 * delete [] buffer; } - ZIP_CloseArchive(&hZip); + NS_IF_RELEASE( hZip ); fileStream.close(); installJSFileSpec.Delete(PR_FALSE);