[wpkg-users] wpkg-0.9.2-test1 released

Dr. F. Lee rl201 at cam.ac.uk
Tue Dec 6 19:28:32 CET 2005


Hi All,

> WPKG 0.9.2-test1 has been released.
> * some check types were removed because they introduced many bugs and weren't 
> tested very well:
> o registry: missing, equalsnocase, equals, lessthan, greaterthan
> o file: missing, sizeequals, sizelessthan, sizegreaterthan
> Depending on the user input, these features may be reintroduced again some 
> day in the future (did anyone use it?) - please comment on that.

I don't use filesize comparisons (although I might do one day - I suspect 
that if I need to strongly enough I'll write a patch and send it in) or 
registry comparisons other than 'exists'.

What I do use a lot of, though, is file version comparisons and I include 
a patch at the end of this mail to add this functionality: please consider 
whether this could be included into the main wpkg distribution.

(Some aimless web surfing a few minutes ago lead me to believe that 
getting the version of a file in JScript natively was possible and so I've 
scrapped my horrible technique of launching perl to do the job for me.)

I use this for installing hotfixes sensitively: no need to run the 
installer if the file is already the right version.

Yours,

Frank

Some notes on the patch below:

This patch adds five new 'conditions' to the 'file' test:

versionsmallerthan (true if the file version is smaller *)
versionlessorequal (true if the file version equals or is smaller *)
versionequalto (true if the file versions are the same)
versiongreaterorequal (true if the file version is larger or equal *)
versiongreaterthan (true if the file version is larger *)

* - ... than the version given in the 'value' argument.

All tests return 'false' if the file does not exist or the version could 
not be found.

--- wpkg-0.9.2test1.js  2005-12-06 17:29:43.000000000 +0000
+++ wpkg-new.js 2005-12-06 18:19:34.000000000 +0000
@@ -925,8 +925,7 @@
  /**
   * Checks for the success of a check condition for a package.
   */
-function checkCondition(checkType, checkCond, checkPath) {
-
+function checkCondition(checkType, checkCond, checkPath, checkValue) {
      if (checkType == "registry") {
          if (checkCond == "exists") {
              var WshShell = new ActiveXObject("WScript.Shell");
@@ -945,16 +944,57 @@
                  "for type registry.");
          }
      } else if (checkType == "file") {
+        var shell = new ActiveXObject("WScript.Shell");
+       checkPath=shell.ExpandEnvironmentStrings(checkPath);
+
          if (checkCond == "exists") {
              var fso = new ActiveXObject("Scripting.FileSystemObject");
              if (fso.FileExists(checkPath)) {
                  return true;
              }
-        } else {
+        } else if (checkCond.substring(0,7) == "version") {
+           CheckValFromFileSystem = GetFileVersion(checkPath);
+           CheckValFromWpkg       = checkValue;
+           if (CheckValFromFileSystem != "UNKNOWN") {
+               var versionresult = VersionCompare(CheckValFromFileSystem,
+                                                  CheckValFromWpkg);
+               if (debug) {
+                   info ("Checking file version " + 
CheckValFromFileSystem +
+                         " is " + checkType + " (than) " + 
CheckValFromWpkg);
+               }
+                switch (checkCond) {
+                   case "versionsmallerthan":
+                       return (versionresult == -1);
+                       break;
+                   case "versionlessorequal":
+                       return (   (versionresult == -1)
+                               || (versionresult == 0) );
+                       break;
+                   case "versionequalto":
+                       return (versionresult == 0);
+                       break;
+                   case "versiongreaterorequal":
+                       return (   (versionresult == 1)
+                               || (versionresult == 0) );
+                       break;
+                   case "versiongreaterthan":
+                       return (versionresult == 1);
+                       break;
+                   default:
+                       throw new Error("Unknown operation on file " +
+                                        "versions : " + checkType);
+                       break;
+               }
+           } else {
+               if (debug) {
+                   info("Unable to find the file version for " + 
checkPath);
+               }
+               return (false);
+            }
+       } else {
              throw new Error("Check condition " + checkCond + " unknown 
for " +
                  "type file.");
          }
-
      } else if (checkType == "uninstall") {
          if (checkCond == "exists") {
              if (scanUninstallKeys(checkPath)) {
@@ -973,6 +1013,50 @@
  }

  /**
+ *   VersionCompare - compare two executable versions
+ */
+function VersionCompare(a,b) {
+    // Return 0 if equal
+    // Return -1 if a < b
+    // Return +1 if a > b
+    var as = a.split(".");
+    var bs = b.split(".");
+    var length=as.length;
+    var ret=0;
+    for (var i = 0; i < length; i++) {
+        if (as[i]<bs[i]) {
+            ret=-1;
+            i=length; // Hack to exit loop
+        } else if (as[i]<bs[i]) {
+            ret=1;
+            i=length;
+        }
+    }
+    return ret;
+}
+
+
+/**
+ *  Gets the version of a file
+ */
+function GetFileVersion (file) {
+    var version="UNKNOWN";
+    try {
+        if (debug) { info ("Finding version of "+file+"\n");}
+        var FSO = new ActiveXObject("Scripting.FileSystemObject");
+        version = FSO.GetFileVersion(file);
+        if (debug) { info ("Obtained version \""+version+"\".");}
+    } catch (e) {
+        version="UNKNOWN";
+        if (debug) { info ("Unable to find file version for "+file+" : "+
+                          e.description);}
+    }
+    if (debug) { info ("Leaving GetFileVersion with version "+version); }
+    return version;
+}
+
+
+/**
   *  Check if package is installed.
   */
  function checkInstalled(packageNode) {
@@ -999,13 +1083,14 @@
          var checkType = checkNode.getAttribute("type");
          var checkCond = checkNode.getAttribute("condition");
          var checkPath = checkNode.getAttribute("path");
+       var checkValue = checkNode.getAttribute("value");

          if (checkType == null ||
              checkCond == null ||
              checkPath == null) {
              throw new Error("Invalid check condition on package " +
                  packageName + ", aborting.");
-        } else if (! checkCondition(checkType, checkCond, checkPath)) {
+        } else if (! checkCondition(checkType, checkCond, checkPath, 
checkValue)) {
              info("Checking presence of " + packageName +
                  "; " + checkType + " check condition failed !");






More information about the wpkg-users mailing list