File:  [mozdev] / calculator / src / install.js
Revision 1.9: download - view: text, annotated - select for diffs - revision graph
Fri Dec 29 15:26:08 2006 UTC (12 years, 2 months ago) by imarc
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

    1: // This code is heavily inspired by Chris Pederick (useragentswitcher) install.js
    2: var contentFlag         = CONTENT | PROFILE_CHROME;
    3: var localeFlag          = LOCALE | PROFILE_CHROME;
    4: var skinFlag            = SKIN | PROFILE_CHROME;
    5: 
    6: var displayName         = "Mozilla Calculator"; // The name displayed to the user (don't include the version)
    7: var version             = "1.1.5";
    8: 
    9: var name                = "calculator"; // The leafname of the JAR file (without the .jar part)
   10: var jarName             = name + ".jar";
   11: var jarFolder           = "content/" // + name + "/"
   12: 
   13: var error               = null;
   14: 
   15: var folder              = getFolder("Profile", "chrome");
   16: var prefFolder          = getFolder(getFolder("Program", "defaults"), "pref");
   17: 
   18: var existsInApplication = File.exists(getFolder(getFolder("chrome"), jarName));
   19: var existsInProfile     = File.exists(getFolder(folder, jarName));
   20: 
   21: var locales             = new Array( "en-US", "it-IT", "fr-FR", "es-ES", "de-DE", "ja-JP", "pl-PL", "nl-NL", "tr-TR", "ru-RU", "sl-SI", "sk-SK", "cs-CZ", "pt-BR", "zh-CN", "az-AZ" );
   22: var skins               = new Array( "classic" );
   23: var prefs               = new Array( "prefs.js" );
   24: var components          = new Array(  );
   25: 
   26: // Mozilla Suite/Seamonkey stores all pref files in a single directory
   27: // under the application directory.  If the name of the preference file(s)
   28: // is/are not unique enough, you may override other extension preferences.
   29: // set this to true if you need to prevent this.
   30: var disambiguatePrefs   = true;
   31: 
   32: // If the extension exists in the application folder or it doesn't exist
   33: // in the profile folder and the user doesn't want it installed to the
   34: // profile folder
   35: if(existsInApplication ||
   36:     (!existsInProfile &&
   37:       !confirm( "Do you want to install the " + displayName +
   38:                 " extension into your profile folder?\n" +
   39:                 "(Cancel will install into the application folder)")))
   40: {
   41:     contentFlag = CONTENT | DELAYED_CHROME;
   42:     folder      = getFolder("chrome");
   43:     localeFlag  = LOCALE | DELAYED_CHROME;
   44:     skinFlag    = SKIN | DELAYED_CHROME;
   45: }
   46: 
   47: initInstall(displayName, name, version);
   48: setPackageFolder(folder);
   49: error = addFile(name, version, "chrome/" + jarName, folder, null);
   50: 
   51: // If adding the JAR file succeeded
   52: if(error == SUCCESS)
   53: {
   54:     folder = getFolder(folder, jarName);
   55: 
   56:     registerChrome(contentFlag, folder, jarFolder);
   57:     for (var i = 0; i < locales.length; i++) {
   58:         registerChrome(localeFlag, folder, "locale/" + locales[i] + "/");
   59:     }
   60: 
   61:     for (var i = 0; i < skins.length; i++) {
   62:         registerChrome(skinFlag, folder, "skin/" + skins[i] + "/");
   63:     }
   64: 
   65:     for (var i = 0; i < prefs.length; i++) {
   66:         if (!disambiguatePrefs) {
   67:             addFile(name + " Defaults", version, "defaults/preferences/" + prefs[i],
   68:                 prefFolder, prefs[i], true);
   69:         } else {
   70:             addFile(name + " Defaults", version, "defaults/preferences/" + prefs[i],
   71:                 prefFolder, name + "-" + prefs[i], true);
   72:         }
   73:     }
   74: 
   75:     error = performInstall();
   76: 
   77:     // If the install failed
   78:     if(error != SUCCESS && error != REBOOT_NEEDED)
   79:     {
   80:         displayError(error);
   81:     	cancelInstall(error);
   82:     }
   83:     else
   84:     {
   85:         alert("The installation of the " + displayName + " extension succeeded.");
   86:     }
   87: }
   88: else
   89: {
   90:     displayError(error);
   91: 	cancelInstall(error);
   92: }
   93: 
   94: // Displays the error message to the user
   95: function displayError(error)
   96: {
   97:     // If the error code was -215
   98:     if(error == READ_ONLY)
   99:     {
  100:         alert("The installation of " + displayName +
  101:             " failed.\nOne of the files being overwritten is read-only.");
  102:     }
  103:     // If the error code was -235
  104:     else if(error == INSUFFICIENT_DISK_SPACE)
  105:     {
  106:         alert("The installation of " + displayName +
  107:             " failed.\nThere is insufficient disk space.");
  108:     }
  109:     // If the error code was -239
  110:     else if(error == CHROME_REGISTRY_ERROR)
  111:     {
  112:         alert("The installation of " + displayName +
  113:             " failed.\nChrome registration failed.");
  114:     }
  115:     else
  116:     {
  117:         alert("The installation of " + displayName +
  118:             " failed.\nThe error code is: " + error);
  119:     }
  120: }

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