home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / linux / mozilla-installer_linux / xpi / browser.xpi / install.js
Text File  |  2001-11-20  |  7KB  |  191 lines

  1. // this function verifies disk space in kilobytes
  2. function verifyDiskSpace(dirPath, spaceRequired)
  3. {
  4.   var spaceAvailable;
  5.  
  6.   // Get the available disk space on the given path
  7.   spaceAvailable = fileGetDiskSpaceAvailable(dirPath);
  8.  
  9.   // Convert the available disk space into kilobytes
  10.   spaceAvailable = parseInt(spaceAvailable / 1024);
  11.  
  12.   // do the verification
  13.   if(spaceAvailable < spaceRequired)
  14.   {
  15.     logComment("Insufficient disk space: " + dirPath);
  16.     logComment("  required : " + spaceRequired + " K");
  17.     logComment("  available: " + spaceAvailable + " K");
  18.     return(false);
  19.   }
  20.  
  21.   return(true);
  22. }
  23.  
  24. // this function deletes a file if it exists
  25. function deleteThisFile(dirKey, file)
  26. {
  27.   var fFileToDelete;
  28.  
  29.   fFileToDelete = getFolder(dirKey, file);
  30.   logComment("File to delete: " + fFileToDelete);
  31.   if(File.isFile(fFileToDelete))
  32.   {
  33.     File.remove(fFileToDelete);
  34.     return(true);
  35.   }
  36.   else
  37.     return(false);
  38. }
  39.  
  40. // this function deletes a folder if it exists
  41. function deleteThisFolder(dirKey, folder, recursiveDelete)
  42. {
  43.   var fToDelete;
  44.  
  45.   if(typeof recursiveDelete == "undefined")
  46.     recursiveDelete = true;
  47.  
  48.   fToDelete = getFolder(dirKey, folder);
  49.   logComment("folder to delete: " + fToDelete);
  50.   if(File.isDirectory(fToDelete))
  51.   {
  52.     File.dirRemove(fToDelete, recursiveDelete);
  53.     return(true);
  54.   }
  55.   else
  56.     return(false);
  57. }
  58.  
  59. // OS type detection
  60. // which platform?
  61. function getPlatform()
  62. {
  63.   var platformStr;
  64.   var platformNode;
  65.  
  66.   if('platform' in Install)
  67.   {
  68.     platformStr = new String(Install.platform);
  69.  
  70.     if (!platformStr.search(/^Macintosh/))
  71.       platformNode = 'mac';
  72.     else if (!platformStr.search(/^Win/))
  73.       platformNode = 'win';
  74.     else
  75.       platformNode = 'unix';
  76.   }
  77.   else
  78.   {
  79.     var fOSMac  = getFolder("Mac System");
  80.     var fOSWin  = getFolder("Win System");
  81.  
  82.     logComment("fOSMac: "  + fOSMac);
  83.     logComment("fOSWin: "  + fOSWin);
  84.  
  85.     if(fOSMac != null)
  86.       platformNode = 'mac';
  87.     else if(fOSWin != null)
  88.       platformNode = 'win';
  89.     else
  90.       platformNode = 'unix';
  91.   }
  92.  
  93.   return platformNode;
  94. }
  95.  
  96. function upgradeCleanup()
  97. {
  98.   // Obsolete files from Netscape 6.0 and Netscape 6.01 that
  99.   // need to be cleaned up.
  100.   deleteThisFile("Components", "libmozucth.so");
  101.   deleteThisFile("Components", "libpsmglue.so");
  102.   deleteThisFile("Components", "libsample.so");
  103.   deleteThisFile("Components", "nsSample.js");
  104.   deleteThisFile("Program",    "defaults/wallet/URLFieldSchema.tbl");
  105.   deleteThisFile("Program",    "libcmt.so");
  106.   deleteThisFile("Program",    "libjpeg.so");
  107.   deleteThisFile("Program",    "libprotocol.so");
  108. }
  109.  
  110. var srDest = 21634;
  111.  
  112. var err = initInstall("Mozilla Seamonkey", "Seamonkey", "0.9.5.2001112012"); 
  113. logComment("initInstall: " + err);
  114.  
  115. var communicatorFolder = getFolder("Program");
  116. logComment("communicatorFolder: " + communicatorFolder);
  117.  
  118. if (verifyDiskSpace(communicatorFolder, srDest))
  119. {
  120.     // Call upgradeCleanup() before addDirectory() in case we accidentaly
  121.     // delete files that we happen to be also installing.  This way, if we do,
  122.     // it will just get reinstalled.  This is for safety measure.
  123.     upgradeCleanup();
  124.     err = addDirectory("Program",
  125.                        "0.9.5.2001112012",
  126.                        "bin",              // jar source folder
  127.                        communicatorFolder, // target folder
  128.                        "",                 // target subdir 
  129.                        true );             // force flag 
  130.  
  131.     logComment("addDirectory() returned: " + err);
  132.  
  133.     // create the plugins folder next to mozilla 
  134.     var pluginsFolder = getFolder("Plugins");
  135.     var ignoreErr = dirCreate(pluginsFolder);
  136.     logComment("dirCreate() returned: " + ignoreErr);
  137.  
  138.     var cf = getFolder("Chrome");
  139.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"toolkit.jar"),"content/global-platform/");
  140.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/communicator-platform/");
  141.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/navigator-platform/");
  142.  
  143.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"toolkit.jar"),"content/global-region/");
  144.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/communicator-region/");
  145.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/editor-region/");
  146.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/navigator-region/");
  147.  
  148.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"toolkit.jar"),"content/global/");
  149.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/cookie/");
  150.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/wallet/");
  151.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"content-packs.jar"),"content/content-packs/");
  152.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/communicator/");
  153.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/editor/");
  154.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/navigator/");
  155.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/necko/");
  156.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"comm.jar"),"content/mozldap/");
  157.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"classic.jar"),"skin/classic/communicator/");
  158.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"classic.jar"),"skin/classic/editor/");
  159.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"classic.jar"),"skin/classic/global/");
  160.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"classic.jar"),"skin/classic/messenger/");
  161.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"classic.jar"),"skin/classic/navigator/");
  162.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"modern.jar"),"skin/modern/communicator/");
  163.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"modern.jar"),"skin/modern/editor/");
  164.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"modern.jar"),"skin/modern/global/");
  165.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"modern.jar"),"skin/modern/messenger/");
  166.     registerChrome(SKIN | DELAYED_CHROME, getFolder(cf,"modern.jar"),"skin/modern/navigator/");
  167.     registerChrome(CONTENT | DELAYED_CHROME, getFolder(cf,"help.jar"),"content/help/");
  168.  
  169.     if (err==SUCCESS)
  170.     {
  171.         err = performInstall(); 
  172.         logComment("performInstall() returned: " + err);
  173.         if (! ('buildID' in Install))
  174.         {
  175.           logComment("Running Pre-Mozilla 0.9.1");
  176.           initInstall("Post-install Cleanup Utility", "xpicleanup", "0.9.5.2001112012");
  177.           cleanupUtility = getFolder(communicatorFolder, "xpicleanup");
  178.           err = File.execute(cleanupUtility);
  179.           logComment("execute() returned: " + err);
  180.           err = performInstall();
  181.         }
  182.     }
  183.     else
  184.     {
  185.         cancelInstall(err);
  186.         logComment("cancelInstall() due to error: " + err);
  187.     }
  188. }
  189. else
  190.     cancelInstall(INSUFFICIENT_DISK_SPACE);
  191.