home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 114 / CDRom114.iso / internet / extens / nlinky / Linky.xpi / install.js next >
Encoding:
Text File  |  2004-11-19  |  12.7 KB  |  331 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10.  * for the specific language governing rights and limitations under the
  11.  * License.
  12.  *
  13.  * The Initial Developer of the Original Code is
  14.  * Henrik Gemal http://gemal.dk
  15.  *
  16.  * Portions created by the Initial Developer are Copyright (C) 2001-2004
  17.  * the Initial Developer. All Rights Reserved.
  18.  *
  19.  * Alternatively, the contents of this file may be used under the terms of
  20.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  21.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  22.  * in which case the provisions of the GPL or the LGPL are applicable instead
  23.  * of those above. If you wish to allow use of your version of this file only
  24.  * under the terms of either the GPL or the LGPL, and not to allow others to
  25.  * use your version of this file under the terms of the MPL, indicate your
  26.  * decision by deleting the provisions above and replace them with the notice
  27.  * and other provisions required by the GPL or the LGPL. If you do not delete
  28.  * the provisions above, a recipient may use your version of this file under
  29.  * the terms of any one of the MPL, the GPL or the LGPL.
  30.  *
  31.  * ***** END LICENSE BLOCK ***** */
  32.  
  33. // product related settings
  34. // you can change these
  35. const myProductName = "Linky";
  36. const myProductRegKey = "linky";
  37. const myProductRegVersion = "2.2.0";
  38. const myJarFileName = "linky.jar";
  39. const myJarFileSize = 23; // the filesize in KB of myJarFileName
  40. const myJSFileName = ""; // the default prefs file. set it to "" if not used
  41. const myJSFileSize = 0; // the filesize in KB of myJSFileName
  42. const myExtraFileName = "";
  43. const myExtraFileSize = 0; // the filesize in KB of myExtraFileName
  44. const myLocales = new Array("en-US"); // the locales available
  45. const mySkin = ""; // the skins available
  46. const myJarCheckDupe = 1; // check if myJarFileName exist both in personal chrome folder and global chrome folder set it to "" if not used
  47. const myJarCheckReq = ""; // are there any requirements for this extension? set it to "" if not used
  48. const myJarCheckReqOS = ""; // are there any OS requirements for this extension? Supported OS is win, mac and unix. set it to "" if not used
  49.  
  50. // global settings
  51. // dont change these
  52. const sysChromeGlobal = getFolder("Chrome");
  53. const sysChromeGlobalJar = getFolder("Chrome", myJarFileName);
  54. const sysChromeUser = getFolder("Current User", "chrome");
  55. const sysChromeUserJar = getFolder("Current User", "chrome/" + myJarFileName);
  56. const errPage = "http://devedge.netscape.com/library/manuals/2001/xpinstall/1.0/err.html";
  57.  
  58. // OS detection
  59. function getPlatform() {
  60.     var platformStr;
  61.     var platformNode;
  62.     if ("platform" in Install) {
  63.         platformStr = new String(Install.platform);
  64.         if (!platformStr.search(/^Macintosh/))
  65.             platformNode = "mac";
  66.         else if (!platformStr.search(/^Win/))
  67.             platformNode = "win";
  68.         else if (!platformStr.search(/^OS\/2/))
  69.             platformNode = "win";
  70.         else
  71.             platformNode = "unix";
  72.     } else {
  73.         var fOSMac    = getFolder("Mac System");
  74.         var fOSWin    = getFolder("Win System");
  75.         if (fOSMac != null)
  76.             platformNode = "mac";
  77.         else if(fOSWin != null)
  78.             platformNode = "win";
  79.         else
  80.             platformNode = "unix";
  81.     }
  82.     return platformNode;
  83. }
  84.  
  85. // verify disk space in kilobytes
  86. function verifyDiskSpace(dirPath, spaceRequired) {
  87.     var spaceAvailable = fileGetDiskSpaceAvailable(dirPath);
  88.     if (parseInt(spaceAvailable/1024) < spaceRequired) {
  89.         logComment("Insufficient disk space: " + dirPath + "\n\trequired : " + spaceRequired + " K\n\tavailable: " + spaceAvailable + " K");
  90.         return false;
  91.     } else {
  92.         return true;
  93.     }
  94. }
  95.  
  96. var oci = false; // one-click-install
  97. var inst; // inst is the installation method:
  98. //        0 means that the installation was cancelled.
  99. //        1 is in the global chrome folder. This *has* to be the default!
  100. //        2 in in the personal profile folder. This is only supported for newer builds.
  101.  
  102. if (myJarCheckDupe && File.exists(sysChromeGlobalJar) && File.exists(sysChromeUserJar)) {
  103.     alert(myProductName + " is installed in BOTH the personal chrome folder:\n" + sysChromeUserJar + "\nand the global chrome folder:\n" + sysChromeGlobalJar + "\n\nThis will cause weird behaviour. Please delete one of the instances!");
  104.     inst = 0;
  105. } else {
  106.     if (myJarCheckReq) {
  107.         for (var i = 0; i < myJarCheckReq.length; i++) {
  108.             if (!File.isDirectory(getFolder("Chrome", myJarCheckReq[i])) && !File.isDirectory(getFolder("Current User", "chrome/" + myJarCheckReq[i])) && !File.exists(getFolder("Chrome", myJarCheckReq[i] + ".jar")) && !File.exists(getFolder("Current User", "chrome/" + myJarCheckReq[i] + ".jar"))) {
  109.                 alert(myProductName + " cant be installed since " + myJarCheckReq[i] + " needs to be installed before installing " + myProductName + "\nPlease visit mozdev.org and install the " + myJarCheckReq[i] + " module first");
  110.                 inst = 0;
  111.             }
  112.         }
  113.     }
  114.     if (myJarCheckReqOS) {
  115.         var os = getPlatform();
  116.         if (os && os != myJarCheckReqOS) {
  117.             alert(myProductName + " cant be installed since your operating system (" + os + ") needs to be " + myJarCheckReqOS);
  118.             inst = 0;
  119.         }
  120.     }
  121.  
  122.     if (typeof(inst) != "number") {
  123.         var ans;
  124.         ans = confirm(myProductName + " version " + myProductRegVersion + " installation.\nClick OK to use one-click-install or click Cancel to choose yourself where to install.");
  125.         if (ans)
  126.             oci = true;
  127.  
  128.         // Can we install in the personal profile folder? Assumes that builds without a buildID are used by people who knows what they are doing.
  129.         if (!buildID || (buildID && buildID >= 2003030700)) {
  130.             if (!oci)
  131.                 alert("You can install " + myProductName + " " + myProductRegVersion + " in two ways:\n\n1) in the global chrome folder. This will make " + myProductName + " available in all profiles.\n\n2) in the personal profile folder. This will make " + myProductName + " available only in the current profile.\n\nYou will now be prompted to select a way...");
  132.  
  133.             // Check if extension already is installed
  134.             if (File.exists(sysChromeGlobalJar)) {
  135.                 if (!oci)
  136.                     ans = confirm("A version of " + myProductName + " is already installed in the global chrome folder:\n" + sysChromeGlobal + "\nIt's recommended that you install " + myProductName + " into this folder.\nClick OK to install into this folder.");
  137.                 inst = 1;
  138.             } else if (File.exists(sysChromeUserJar)) {
  139.                 if (!oci)
  140.                     ans = confirm("A version of " + myProductName + " is already installed in the personal chrome folder:\n" + sysChromeUser + "\nIt's recommended that you install " + myProductName + " into this folder.\nClick OK to install into this folder.");
  141.                 inst = 2;
  142.             } else {
  143.                 inst = 2;
  144.             }
  145.  
  146.             if (!ans && !oci) {
  147.                 if (inst != 1)
  148.                     ans = confirm("Click OK to install in the global chrome folder:\n" + sysChromeGlobal + "\nThis is the recommended install option!");
  149.                 if (!ans) {
  150.                     if (inst != 2)
  151.                         ans = confirm("Click OK to install in your personal profile folder:\n" + sysChromeUser);
  152.                     if (!ans) {
  153.                         alert("You didn't choose any of the supported installation options!\nPlease restart the installation!");
  154.                         inst = 0;
  155.                     } else {
  156.                         inst = 2;
  157.                     }
  158.                 } else {
  159.                     inst = 1;
  160.                 }
  161.             }
  162.         } else {
  163.             if (!oci) {
  164.                 ans = confirm("Click OK to install " + myProductName + " " + myProductRegVersion + " in the global chrome folder:\n" + sysChromeGlobal);
  165.                 if (!ans) {
  166.                     alert("You didn't choose any of the supported installation options!\nPlease restart the installation!");
  167.                     inst = 0;
  168.                 } else {
  169.                     inst = 1;
  170.                 }
  171.             } else {
  172.                 inst = 1;
  173.             }
  174.         }
  175.     }
  176. }
  177.  
  178. // did the user cancel?
  179. if (inst) {
  180.     var err;
  181.     var err_tmp;
  182.  
  183.     // init the installation
  184.     err_tmp = initInstall(myProductName, myProductRegKey, myProductRegVersion);
  185.     if (err_tmp) {
  186.         err = err_tmp;
  187.     }
  188.  
  189.     // what folder to install into
  190.     var folder = (inst == 1 ? sysChromeGlobal : sysChromeUser);
  191.  
  192.     if (buildID)
  193.         logComment(myProductName + " version <" + myProductRegVersion + "> being installed on build <" + buildID + ">");
  194.     else
  195.         logComment(myProductName + " version <" + myProductRegVersion + "> being installed on a build without buildID");
  196.     logComment("Installation method is " + inst);
  197.  
  198.     // check if there"s disk space for myJSFileSize
  199.     if (!err && myJSFileName && !verifyDiskSpace(sysChromeGlobal, myJSFileSize)) {
  200.         err = INSUFFICIENT_DISK_SPACE;
  201.     }
  202.  
  203.     // check if there"s disk space for myJarFileSize
  204.     if (!err && myJarFileName && !verifyDiskSpace(folder, myJarFileSize)) {
  205.         err = INSUFFICIENT_DISK_SPACE;
  206.     }
  207.  
  208.     // check if there"s disk space for myJarFileSize
  209.     if (!err && myJarFileName && !verifyDiskSpace(folder, myExtraFileSize)) {
  210.         err = INSUFFICIENT_DISK_SPACE;
  211.     }
  212.  
  213.     // add the jar file
  214.     if (!err) {
  215.         err_tmp = addFile(myProductName, myProductRegVersion, myJarFileName, folder, null);
  216.         if (err_tmp) {
  217.             logComment("Problem adding jar file <" + myJarFileName + "> to <" + folder + ">. Error code: " + err_tmp);
  218.             err = err_tmp;
  219.         } else {
  220.             logComment("ok adding jar file <" + myJarFileName + "> to <" + folder + ">.");
  221.         }
  222.     }
  223.  
  224.     // add the default prefs, but only if we have to install into global chrome
  225.     if (!err && inst == 1 && myJSFileName) {
  226.         err_tmp = addFile(myProductName, myJSFileName, getFolder("Program","defaults/pref"), "");
  227.         if (err_tmp) {
  228.             logComment("Problem adding default prefs <" + myJSFileName + "> to <" + getFolder("Program", "defaults/pref") + ">. Error code: " + err_tmp);
  229.             err = err_tmp;
  230.         } else {
  231.             logComment("ok adding default prefs <" + myJSFileName + "> to <" + getFolder("Program","defaults/pref") + ">.");
  232.         }
  233.     }
  234.  
  235.     // add the extra file
  236.     if (!err && myExtraFileName) {
  237.         err_tmp = addFile(myProductName, myExtraFileName, folder, "");
  238.         if (err_tmp) {
  239.             logComment("Problem adding extra file <" + myExtraFileName + "> to <" + folder + ">. Error code: " + err_tmp);
  240.             err = err_tmp;
  241.         } else {
  242.             logComment("ok adding extra file <" + myExtraFileName + "> to <" + folder + ">.");
  243.         }
  244.     }
  245.  
  246.     // register the content
  247.     if (!err) {
  248.         folder = getFolder(folder, myJarFileName);
  249.         if (inst == 2) {
  250.             err_tmp = registerChrome(CONTENT | PROFILE_CHROME, folder, "content/");
  251.         } else {
  252.             err_tmp = registerChrome(CONTENT | DELAYED_CHROME, folder, "content/");
  253.         }
  254.         if (err_tmp) {
  255.             logComment("Problem registering the content chrome. Error code: " + err_tmp);
  256.             err = err_tmp;
  257.         } else {
  258.             logComment("ok registering the content chrome.");
  259.         }
  260.     }
  261.  
  262.     // register the locale
  263.     if (!err) {
  264.         if (inst == 2) {
  265.             for (var i = 0; i < myLocales.length; i++) {
  266.                 err_tmp = registerChrome(LOCALE | PROFILE_CHROME, folder, "locale/" + myLocales[i] + "/");
  267.                 if (err_tmp)
  268.                     break;
  269.             }
  270.         } else {
  271.             for (var i = 0; i < myLocales.length; i++) {
  272.                 err_tmp = registerChrome(LOCALE | DELAYED_CHROME, folder, "locale/" + myLocales[i] + "/");
  273.                 if (err_tmp) {
  274.                     break;
  275.                 }
  276.             }
  277.         }
  278.         if (err_tmp) {
  279.             logComment("Problem registering the locale. Error code: " + err_tmp);
  280.             err = err_tmp;
  281.         } else {
  282.             logComment("ok registering the locale.");
  283.         }
  284.     }
  285.  
  286.     // register the skin
  287.     if (!err) {
  288.         if (inst == 2) {
  289.             for (var i = 0; i < mySkin.length; i++) {
  290.                 err_tmp = registerChrome(SKIN | PROFILE_CHROME, folder, "skin/" + mySkin[i] + "/");
  291.                 if (err_tmp)
  292.                     break;
  293.             }
  294.         } else {
  295.             for (var i = 0; i < mySkin.length; i++) {
  296.                 err_tmp = registerChrome(SKIN | DELAYED_CHROME, folder, "skin/" + mySkin[i] + "/");
  297.                 if (err_tmp) {
  298.                     break;
  299.                 }
  300.             }
  301.         }
  302.         if (err_tmp) {
  303.             logComment("Problem registering the skin. Error code: " + err_tmp);
  304.             err = err_tmp;
  305.         } else {
  306.             logComment("ok registering the skin.");
  307.         }
  308.     }
  309.  
  310.     // do the install
  311.     if (!err) {
  312.         err_tmp = performInstall();
  313.         if (err_tmp < 0) {
  314.             logComment("Problem performing install. Error code: " + err_tmp);
  315.             err = err_tmp;
  316.         } else {
  317.             if (!oci)
  318.                 alert(myProductName + " version " + myProductRegVersion + " has been successfully installed!\nWhen you right-click on a webpage your will now have a new context menuitem called " + myProductName + "!\n\nYou must restart your browser to complete installation!");
  319.         }
  320.     }
  321.  
  322.     // did it work?
  323.     if (err) {
  324.         logComment("Problem installing. Error code: " + err + ". Error codes can been seen at: " + errPage);
  325.         alert(myProductName + " version " + myProductRegVersion + " was not installed!\nError code: " + err + "\n\nError codes can been seen at:\n" + errPage)
  326.         cancelInstall(err);
  327.     }
  328. } else {
  329.     cancelInstall();
  330. }
  331.