home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2006 March / maximum-cd-2006-03.iso / Software / Apps / firefox_setup_1.5.exe / xpcom.xpi / install.js
Encoding:
JavaScript  |  2005-11-11  |  5.4 KB  |  199 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 if (!platformStr.search(/^OS\/2/))
  75.       platformNode = 'win';
  76.     else
  77.       platformNode = 'unix';
  78.   }
  79.   else
  80.   {
  81.     var fOSMac  = getFolder("Mac System");
  82.     var fOSWin  = getFolder("Win System");
  83.  
  84.     logComment("fOSMac: "  + fOSMac);
  85.     logComment("fOSWin: "  + fOSWin);
  86.  
  87.     if(fOSMac != null)
  88.       platformNode = 'mac';
  89.     else if(fOSWin != null)
  90.       platformNode = 'win';
  91.     else
  92.       platformNode = 'unix';
  93.   }
  94.  
  95.   return platformNode;
  96. }
  97.  
  98. // main
  99. var srDest;
  100. var err;
  101. var szUninstall;
  102. var fProgram;
  103. var fWindowsSystem;
  104. var fileComponentReg;
  105. var fileComponentRegStr;
  106. var fileMsvcrt;
  107. var fileMsvcirt;
  108.  
  109. srDest = 163;
  110. err    = initInstall("Mozilla XPCOM", "XPCOM", "1.5"); 
  111. logComment("initInstall: " + err);
  112.  
  113. fProgram  = getFolder("Program");
  114. fWindowsSystem = getFolder("Win System");
  115. logComment("fProgram: " + fProgram);
  116.  
  117. // build the uninstall folder path
  118. szUninstall = fProgram + "Uninstall";
  119.  
  120. // Log component.reg file so it can be deleted by the uninstaller.
  121. // These two files are created after installation is done, thus
  122. // are normally not logged for uninstall.
  123. logComment("Installing: " + fProgram + "component.reg");
  124.  
  125. if(verifyDiskSpace(fProgram, srDest))
  126. {
  127.   setPackageFolder(fProgram);
  128.  
  129.   err = addDirectory("",
  130.                      "1.5",
  131.                      "bin",              // dir name in jar to extract 
  132.                      fProgram,           // Where to put this file (Returned from GetFolder) 
  133.                      "",                 // subdir name to create relative to fProgram
  134.                      true);              // Force Flag 
  135.   logComment("addDirectory() of Program returned: " + err);
  136.  
  137.   if( err == SUCCESS )
  138.   {
  139.     // install msvcrt.dll *only* if it does not exist
  140.     // we don't care if addFile() fails (if the file does not exist in the archive)
  141.     // bacause it will still install
  142.     fileMsvcrt = getFolder(fWindowsSystem, "msvcrt.dll");
  143.     rv         = File.exists(fileMsvcrt);
  144.     logComment("fileExists() returned: " + rv);
  145.     if(rv == false)
  146.     {
  147.       logComment("File not found: " + fileMsvcrt);
  148.       addFile("/Microsoft/Shared/msvcrt.dll",
  149.               "1.5",
  150.               "msvcrt.dll",         // dir name in jar to extract 
  151.               fWindowsSystem,       // Where to put this file (Returned from getFolder) 
  152.               "",                   // subdir name to create relative to fProgram
  153.               WIN_SHARED_FILE);
  154.       logComment("addFile() of msvcrt.dll returned: " + err);
  155.     }
  156.     else
  157.     {
  158.       logComment("File found: " + fileMsvcrt);
  159.     }
  160.  
  161.     // install msvcirt.dll *only* if it does not exist
  162.     // we don't care if addFile() fails (if the file does not exist in the archive)
  163.     // bacause it will still install
  164.     fileMsvcirt = getFolder(fWindowsSystem, "msvcirt.dll");
  165.     rv          = File.exists(fileMsvcirt);
  166.     logComment("fileExists() returned: " + rv);
  167.     if(rv == false)
  168.     {
  169.       logComment("File not found: " + fileMsvcirt);
  170.       addFile("/Microsoft/Shared/msvcirt.dll",
  171.               "1.5",
  172.               "msvcirt.dll",        // dir name in jar to extract 
  173.               fWindowsSystem,       // Where to put this file (Returned from getFolder) 
  174.               "",                   // subdir name to create relative to fProgram
  175.               WIN_SHARED_FILE);
  176.       logComment("addFile() of msvcirt.dll returned: " + err);
  177.     }
  178.     else
  179.     {
  180.       logComment("File found: " + fileMsvcirt);
  181.     }
  182.   }
  183.  
  184.   // check return value
  185.   if( err == SUCCESS )
  186.   {
  187.     err = performInstall(); 
  188.     logComment("performInstall() returned: " + err);
  189.   }
  190.   else
  191.     cancelInstall(err);
  192. }
  193. else
  194.   cancelInstall(INSUFFICIENT_DISK_SPACE);
  195.  
  196.  
  197. // end main
  198.  
  199.