File:  [mozdev] / annozilla / www / installer.js
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Fri Jan 31 15:35:55 2003 UTC (16 years, 1 month ago) by rainking
Branches: MAIN
CVS tags: HEAD, ANNOZILLA-ES-CHANGES, ANNOZILLA-ES, ANNOZILLA-CGH-CHANGES, ANNOZILLA-0-7-0, ANNOZILLA-0-6-7-BRANCH, ANNOZILLA-0-6-7
- initial checkin

// Installer script
// (adapted from Ben Bucksch's install.js)

var gXpiList;  // Associative list of packages to be installed {name:URL, ...}
var gXpiCount;   // Count of URLs to be installed
var gStatusList; // Associative list of status coded {URL:code, ...}
var gStatusCount;

var gErrCodes = {'0':'SUCCESS',
'999':'REBOOT_NEEDED',
'-200':'BAD_PACKAGE_NAME',
'-201':'UNEXPECTED_ERROR',
'-202':'ACCESS_DENIED',
'-203':'TOO_MANY_CERTIFICATES',
'-204':'NO_INSTALL_SCRIPT',
'-205':'NO_CERTIFICATE',
'-206':'NO_MATCHING_CERTIFICATE',
'-207':'CANT_READ_ARCHIVE',
'-208':'INVALID_ARGUMENTS',
'-209':'ILLEGAL_RELATIVE_PATH',
'-210':'USER_CANCELLED',
'-211':'INSTALL_NOT_STARTED',
'-212':'SILENT_MODE_DENIED',
'-213':'NO_SUCH_COMPONENT',
'-214':'DOES_NOT_EXIST',
'-215':'READ_ONLY',
'-216':'IS_DIRECTORY',
'-217':'NETWORK_FILE_IS_IN_USE',
'-218':'APPLE_SINGLE_ERR',
'-219':'INVALID_PATH_ERR',
'-220':'PATCH_BAD_DIFF',
'-221':'PATCH_BAD_CHECKSUM_TARGET',
'-222':'PATCH_BAD_CHECKSUM_RESULT',
'-223':'UNINSTALL_FAILED',
'-224':'PACKAGE_FOLDER_NOT_SET',
'-225':'EXTRACTION_FAILED',
'-226':'FILENAME_ALREADY_USED',
'-227':'INSTALL_CANCELLED',
'-228':'DOWNLOAD_ERROR',
'-229':'SCRIPT_ERROR',
'-230':'ALREADY_EXISTS',
'-231':'IS_FILE',
'-232':'SOURCE_DOES_NOT_EXIST',
'-233':'SOURCE_IS_DIRECTORY',
'-234':'SOURCE_IS_FILE',
'-235':'INSUFFICIENT_DISK_SPACE',
'-236':'FILENAME_TOO_LONG',
'-237':'UNABLE_TO_LOCATE_LIB_FUNCTION',
'-238':'UNABLE_TO_LOAD_LIBRARY',
'-239':'CHROME_REGISTRY_ERROR',
'-240':'MALFORMED_INSTALL',
'-299':'OUT_OF_MEMORY',
'-5550':'GESTALT_UNKNOWN_ERROR',
'-5551':'GESTALT_INVALID_ARGUMENT'};

// xpiList = Associative array of the form {name:URL, ...}
function installPackages(xpiList) {
  gXpiList = xpiList;
  gStatusList = new Object();

  gStatusCount = 0;

  gXpiCount = 0;
  for (var k in xpiList) {
    gStatusList[k] = null;
    gXpiCount++;
  }

  if (!InstallTrigger.updateEnabled()) {
     alert( "Please enable the software installation preference!" );
     return;
  }

  InstallTrigger.install(xpiList, statusCallback);
}

function statusCallback(url, status) {
    var k;

    dump("statusCallback: "+url+", "+status+"\n");

    for (k in gXpiList) {
        if ( url.indexOf(gXpiList[k]) != -1 ) {
            gStatusList[k] = status;
            gStatusCount++;
            break;
        }
    }

    if (gStatusCount == gXpiCount) {
        // All packages installed
        var failed = false;
        var restart = false;
        var results = "Installation report\n";

        for (k in gXpiList) {
            var j = gStatusList[k];

            results += k + ": ";
            switch (j) {
              case 999:
                 restart = true;     // fall-through

              case 0:
                 results += "Successful";
                 break;

              case -210:
                 results += "Cancelled";
                 failed = true;
                 break;

              default:
                 results += "Error encountered ("+j+")";
                 if (gErrCodes[""+j])
                   results += " "+gErrCodes[""+j];

                 failed = true;
                 break;
            }

            results += "\n";
        }

        results += "\nPlease restart Mozilla/Netscape.";

        if (restart) {
            if (isWindows())
              results += "\nIf you are using Win9x (incl. Windows ME), restart your computer.";
        }

        alert(results);
    }
}

function getMozVersion() {
  var matches = navigator.userAgent.match(/;\s*rv:([\d.]+)/);

  if (matches && matches.length == 2) {
    return matches[1];
  } else {
    return "";
  }
}

function getNSVersion() {
  var matches = navigator.userAgent.match(/\sNetscape\d\/([\d.]+)/);

  if (matches && matches.length == 2) {
    return matches[1];
  } else {
    return "";
  }
}

// Returns +1 if a > b,
//          0 if a==b, and
//         -1 if a < b
function compareVersions(a, b) {
   var asplit = a.split(".");
   var bsplit = b.split(".");

   var depth = Math.max(asplit.length, bsplit.length);

   for (var j=0; j<depth; j++) {
      var asub = 0;
      var bsub = 0;

      if (j < asplit.length)
         asub = asplit[j];

      if (j < bsplit.length)
         bsub = bsplit[j];

      if (asub > bsub)
         return 1;

      if (asub < bsub)
         return -1;
   }

   return 0;
}

function isWindows() {
  return (navigator.platform.search(/Win/i) == 0);
}

function isLinux() {
  return (navigator.platform.search(/Linux/i) == 0);
}

function isMac() {
  return (navigator.platform.search(/Mac/i) != -1);
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>