home *** CD-ROM | disk | FTP | other *** search
/ Enter 2003: The Beautiful Scenery / enter-parhaat-2003.iso / files / Netscape / xpcom.xpi / install.js next >
Encoding:
JavaScript  |  2002-08-23  |  8.9 KB  |  308 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 registerMainKeys(winreg)
  97. {
  98.   var subkey;  //the name of the subkey you are poking around in
  99.   var valname; //the name of the value you want to look at
  100.   var value;   //the data in the value you want to look at.
  101.   var err;
  102.  
  103.   subkey  = "SOFTWARE\\Netscape";
  104.   winreg.createKey(subkey,"");
  105.  
  106.   subkey  = "SOFTWARE\\Netscape\\Netscape";
  107.   winreg.createKey(subkey,"");
  108.  
  109.   valname = "CurrentVersion";
  110.   value   = "7.0 (en)";
  111.   err     = winreg.setValueString(subkey, valname, value);
  112.  
  113.   subkey  = "SOFTWARE\\Netscape\\Netscape\\7.0 (en)";
  114.   winreg.createKey(subkey,"");
  115.  
  116.   subkey  = "SOFTWARE\\Netscape\\Netscape\\7.0 (en)\\Main";
  117.   winreg.createKey(subkey,"");
  118.  
  119.   valname = "Install Directory";
  120.   value   = fCommunicator;
  121.   err     = winreg.setValueString(subkey, valname, value);
  122.  
  123.   subkey  = "SOFTWARE\\Netscape\\Netscape\\7.0 (en)\\Uninstall";
  124.   winreg.createKey(subkey,"");
  125.  
  126.   valname = "Uninstall Log Folder";
  127.   value   = szUninstall;
  128.   err     = winreg.setValueString(subkey, valname, value);
  129.  
  130.   valname = "Description";
  131.   value   = "Netscape (7.0)";
  132.   err     = winreg.setValueString(subkey, valname, value);
  133. }
  134.  
  135. function updateWinReg()
  136. {
  137.   //Notes:
  138.   // can't use a double backslash before subkey - Windows already puts it in.
  139.   // subkeys have to exist before values can be put in.
  140.   var winreg = getWinRegistry();
  141.   var subkey;  //the name of the subkey you are poking around in
  142.   var valname; //the name of the value you want to look at
  143.   var value;   //the data in the value you want to look at.
  144.   var restrictedAccess;
  145.   var ikwDefined;
  146.  
  147.   if(winreg != null) 
  148.   {
  149.     /* This will check to see if the user has restricted access or not.
  150.      * It checks to see if HKEY_LOCALMACHINE\SOFTWARE is writable.  If
  151.      * it is, then access is not restricted.  This is only used to
  152.      * determine which Desktop, Programs, and Start Menu folders
  153.      * are to used: common or per user
  154.      */
  155.     restrictedAccess = false;
  156.     ikwDefined = typeof(winreg.isKeyWritable);
  157.     logComment("winreg.isKeyWritable(): " + ikwDefined);
  158.     if(ikwDefined == "function")
  159.     {
  160.       winreg.setRootKey(winreg.HKEY_LOCAL_MACHINE);
  161.       if(!winreg.isKeyWritable("SOFTWARE"))
  162.         restrictedAccess = true;
  163.     }
  164.  
  165.     logComment("restrictedAccess value: " + restrictedAccess);
  166.     if(!restrictedAccess)
  167.     {
  168.       winreg.setRootKey(winreg.HKEY_LOCAL_MACHINE);
  169.       registerMainKeys(winreg);
  170.     }
  171.  
  172.     winreg.setRootKey(winreg.HKEY_CURRENT_USER);
  173.     registerMainKeys(winreg);
  174.   }
  175. }
  176.  
  177. function upgradeCleanup()
  178. {
  179.   deleteThisFile("Program",    "component.reg");
  180.   deleteThisFile("Program",    "ren8dot3.exe");
  181.   deleteThisFile("Components", "xpti.dat");
  182.   deleteThisFile("Components", "xptitemp.dat");
  183. }
  184.  
  185. // main
  186. var srDest;
  187. var err;
  188. var szUninstall;
  189. var fCommunicator;
  190. var fWindowsSystem;
  191. var fileTemp;
  192. var fileComponentReg;
  193. var fileComponentRegStr;
  194. var fileMsvcrt;
  195. var fileMsvcirt;
  196. var fileMsvcp60;
  197.  
  198. srDest = 1537;
  199. err    = initInstall("Netscape XPCOM", "XPCOM", "7.0.0.2002082310"); 
  200. logComment("initInstall: " + err);
  201.  
  202. fCommunicator  = getFolder("Program");
  203. fWindowsSystem = getFolder("Win System");
  204. logComment("fCommunicator: " + fCommunicator);
  205.  
  206. // build the uninstall folder path
  207. szUninstall = fCommunicator + "Uninstall";
  208.  
  209. // Log component.reg and xpcom.log files so it can be deleted by
  210. // the uninstaller.
  211. // These two files are created after installation is done, thus
  212. // are normally not logged for uninstall.
  213. logComment("Installing: " + fCommunicator + "component.reg");
  214.  
  215. if(verifyDiskSpace(fCommunicator, srDest))
  216. {
  217.   setPackageFolder(fCommunicator);
  218.  
  219.   upgradeCleanup();
  220.   err = addDirectory("",
  221.                      "7.0.0.2002082310",
  222.                      "bin",              // dir name in jar to extract 
  223.                      fCommunicator,      // Where to put this file (Returned from getFolder) 
  224.                      "",                 // subdir name to create relative to fCommunicator
  225.                      true);              // Force Flag 
  226.   logComment("addDirectory() of Program returned: " + err);
  227.  
  228.   if(err == SUCCESS)
  229.   {
  230.     fileTemp   = fWindowsSystem + "msvcrt.dll";
  231.     fileMsvcrt = getFolder("file:///", fileTemp);
  232.     rv         = File.exists(fileMsvcrt);
  233.     logComment("fileExists() returned: " + rv);
  234.     if(rv == false)
  235.     {
  236.       logComment("File not found: " + fileMsvcrt);
  237.       err = addFile("/Microsoft/Shared",
  238.                     "7.0.0.2002082310",
  239.                     "msvcrt.dll",         // dir name in jar to extract 
  240.                     fWindowsSystem,       // Where to put this file (Returned from getFolder) 
  241.                     "",                   // subdir name to create relative to fCommunicator
  242.                     WIN_SHARED_FILE);
  243.       logComment("addFile() of msvcrt.dll returned: " + err);
  244.     }
  245.     else
  246.     {
  247.       logComment("File found: " + fileMsvcrt);
  248.     }
  249.  
  250.     fileTemp    = fWindowsSystem + "msvcirt.dll";
  251.     fileMsvcirt = getFolder("file:///", fileTemp);
  252.     rv          = File.exists(fileMsvcirt);
  253.     logComment("fileExists() returned: " + rv);
  254.     if(rv == false)
  255.     {
  256.       logComment("File not found: " + fileMsvcirt);
  257.       err = addFile("/Microsoft/Shared",
  258.                     "7.0.0.2002082310",
  259.                     "msvcirt.dll",        // dir name in jar to extract 
  260.                     fWindowsSystem,       // Where to put this file (Returned from getFolder) 
  261.                     "",                   // subdir name to create relative to fCommunicator
  262.                     WIN_SHARED_FILE);
  263.       logComment("addFile() of msvcirt.dll returned: " + err);
  264.     }
  265.     else
  266.     {
  267.       logComment("File found: " + fileMsvcirt);
  268.     }
  269.  
  270.     fileTemp    = fWindowsSystem + "msvcp60.dll";
  271.     fileMsvcp60 = getFolder("file:///", fileTemp);
  272.     rv          = File.exists(fileMsvcp60);
  273.     logComment("fileExists() returned: " + rv);
  274.     if(rv == false)
  275.     {
  276.       logComment("File not found: " + fileMsvcp60);
  277.       err = addFile("/Microsoft/Shared",
  278.                     "7.0.0.2002082310",
  279.                     "msvcp60.dll",        // dir name in jar to extract 
  280.                     fWindowsSystem,       // Where to put this file (Returned from getFolder) 
  281.                     "",                   // subdir name to create relative to fCommunicator
  282.                     WIN_SHARED_FILE);
  283.       logComment("addFile() of msvcp60.dll returned: " + err);
  284.     }
  285.     else
  286.     {
  287.       logComment("File found: " + fileMsvcp60);
  288.     }
  289.  
  290.     if(!err)
  291.     {
  292.       updateWinReg();
  293.  
  294.       err = performInstall(); 
  295.       logComment("performInstall() returned: " + err);
  296.     }
  297.     else
  298.       cancelInstall(err);
  299.   }
  300.   else
  301.     cancelInstall(err);
  302. }
  303. else
  304.   cancelInstall(INSUFFICIENT_DISK_SPACE);
  305.  
  306. // end main
  307.  
  308.