From 4477f5a169a84cc36ab2331e810a5d1ccaa048d4 Mon Sep 17 00:00:00 2001 From: "ssu%netscape.com" Date: Mon, 8 Oct 2001 21:24:19 +0000 Subject: [PATCH] fixing bug 103228 - Fix xpinstall engine so InstallTrigger.compareVersion() works. r=syd, sr=dveditz. --- xpinstall/packager/common/share.t | 19 +++++---- xpinstall/src/makefile.win | 1 + xpinstall/src/nsInstall.cpp | 68 +++++++++++++++++++++++++++++- xpinstall/src/nsInstallTrigger.cpp | 3 +- xpinstall/src/nsJSFile.cpp | 1 + 5 files changed, 82 insertions(+), 10 deletions(-) diff --git a/xpinstall/packager/common/share.t b/xpinstall/packager/common/share.t index 53c34cc4879..17c687a13b2 100644 --- a/xpinstall/packager/common/share.t +++ b/xpinstall/packager/common/share.t @@ -27,26 +27,29 @@ function deleteThisFile(dirKey, file) var fFileToDelete; fFileToDelete = getFolder(dirKey, file); - logComment(file + " file: " + fFileToDelete); - if(File.exists(fFileToDelete)) + logComment("File to delete: " + fFileToDelete); + if(File.isFile(fFileToDelete)) { - fileDelete(fFileToDelete); + File.remove(fFileToDelete); return(true); } else return(false); } -// this function deletes a folder (recursively) if it exists -function deleteThisFolder(dirKey, folder) +// this function deletes a folder if it exists +function deleteThisFolder(dirKey, folder, recursiveDelete) { var fToDelete; + if(typeof recursiveDelete == "undefined") + recursiveDelete = true; + fToDelete = getFolder(dirKey, folder); - logComment(folder + " folder: " + fToDelete); - if(File.exists(fToDelete)) + logComment("folder to delete: " + fToDelete); + if(File.isDirectory(fToDelete)) { - File.dirRemove(fToDelete, true); + File.dirRemove(fToDelete, recursiveDelete); return(true); } else diff --git a/xpinstall/src/makefile.win b/xpinstall/src/makefile.win index 9267e94e941..b9644581bd9 100644 --- a/xpinstall/src/makefile.win +++ b/xpinstall/src/makefile.win @@ -118,6 +118,7 @@ OBJS = \ WIN_LIBS= \ ole32.lib \ + version.lib \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index 7ed80969483..8bbed3ad90f 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -22,6 +22,7 @@ * Daniel Veditz * Douglas Turner * Pierre Phaneuf + * Sean Su */ @@ -1813,10 +1814,75 @@ nsInstall::FileOpFileExists(nsInstallFolder& aTarget, PRBool* aReturn) return NS_OK; } +#ifdef XP_WIN +#include +#endif + PRInt32 nsInstall::FileOpFileGetNativeVersion(nsInstallFolder& aTarget, nsString* aReturn) { - return NS_OK; + PRInt32 rv = NS_OK; + +#ifdef XP_WIN + PRBool flagExists; + nsCOMPtr localTarget(aTarget.GetFileSpec()); + UINT uLen; + UINT dwLen; + DWORD dwHandle; + LPVOID lpData; + LPVOID lpBuffer; + VS_FIXEDFILEINFO *lpBuffer2; + DWORD dwMajor = 0; + DWORD dwMinor = 0; + DWORD dwRelease = 0; + DWORD dwBuild = 0; + nsXPIDLCString nativeTargetPath; + char *nativeVersionString = nsnull; + + if(localTarget == nsnull) + return(rv); + + flagExists = PR_FALSE; + localTarget->Exists(&flagExists); + if(flagExists) + { + localTarget->GetPath(getter_Copies(nativeTargetPath)); + uLen = 0; + /* GetFileVersionInfoSize() requires a char *, but the api doesn't + * indicate that it will modify it */ + dwLen = GetFileVersionInfoSize((char *)nativeTargetPath.get(), &dwHandle); + lpData = (LPVOID)PR_Malloc(sizeof(long)*dwLen); + if(!lpData) + return(nsInstall::OUT_OF_MEMORY); + + /* GetFileVersionInfo() requires a char *, but the api doesn't + * indicate that it will modify it */ + if(GetFileVersionInfo((char *)nativeTargetPath.get(), dwHandle, dwLen, lpData) != 0) + { + if(VerQueryValue(lpData, "\\", &lpBuffer, &uLen) != 0) + { + lpBuffer2 = (VS_FIXEDFILEINFO *)lpBuffer; + dwMajor = HIWORD(lpBuffer2->dwFileVersionMS); + dwMinor = LOWORD(lpBuffer2->dwFileVersionMS); + dwRelease = HIWORD(lpBuffer2->dwFileVersionLS); + dwBuild = LOWORD(lpBuffer2->dwFileVersionLS); + } + } + + nativeVersionString = PR_smprintf("%d.%d.%d.%d", dwMajor, dwMinor, dwRelease, dwBuild); + if(!nativeVersionString) + rv = nsInstall::OUT_OF_MEMORY; + else + { + aReturn->Assign(NS_ConvertASCIItoUCS2(nativeVersionString)); + PR_smprintf_free(nativeVersionString); + } + + PR_FREEIF(lpData); + } +#endif + + return(rv); } PRInt32 diff --git a/xpinstall/src/nsInstallTrigger.cpp b/xpinstall/src/nsInstallTrigger.cpp index 7cbc681a9b0..5e7855e7553 100644 --- a/xpinstall/src/nsInstallTrigger.cpp +++ b/xpinstall/src/nsInstallTrigger.cpp @@ -189,7 +189,8 @@ nsInstallTrigger::UpdateEnabled(PRBool* aReturn) } else { - *aReturn = PR_FALSE; /* no prefs manager. set to false */ + // no prefs manager: we're in the install wizard and always work + *aReturn = PR_TRUE; } return NS_OK; diff --git a/xpinstall/src/nsJSFile.cpp b/xpinstall/src/nsJSFile.cpp index 3c73f7090ef..68bbb71c107 100644 --- a/xpinstall/src/nsJSFile.cpp +++ b/xpinstall/src/nsJSFile.cpp @@ -1483,6 +1483,7 @@ static JSFunctionSpec FileOpMethods[] = {"exists", InstallFileOpFileExists, 1}, {"execute", InstallFileOpFileExecute, 2}, {"nativeVersion", InstallFileOpFileGetNativeVersion, 1}, + {"windowsVersion", InstallFileOpFileGetNativeVersion, 1}, {"diskSpaceAvailable", InstallFileOpFileGetDiskSpaceAvailable,1}, {"modDate", InstallFileOpFileGetModDate, 1}, {"size", InstallFileOpFileGetSize, 1},