home *** CD-ROM | disk | FTP | other *** search
/ Flash MX Savvy / FlashMX Savvy.iso / pc / MAC / Amapi3D / Amapi3DTrial_Edition / 3SPACE / 3SpaceInstallation.js next >
Encoding:
JavaScript  |  2001-02-20  |  5.2 KB  |  230 lines  |  [AMAS/AMAP]

  1. /**
  2.  * 3SpaceInstaller.js
  3.  *
  4.  *
  5.  * Created: Mon Oct 16 19:50:45 2000
  6.  *
  7.  * @author Mickael Gasrel
  8.  * @version 1.0
  9.  */
  10.  
  11. /*
  12. * Global variables
  13. */
  14. var winNetPluginVersion = "3.1.0.4" ;
  15. var winExpPluginVersion = 0000 ;
  16. var macNetPluginVersion = 0000 ;
  17.  
  18. var jarDirWin = "http://lion.g5g.fr/mickael/3SpaceWin.jar" ;
  19. //var jarDirWin = "http://3SpaceWin.jar" ;
  20. var jarDirMac = "../3SpaceMac.jar" ;
  21. var cabDirWin ="" ;
  22.  
  23. /* 
  24. * You must call the function findBrowser () to initialize this four variables.
  25. */
  26. var platformName ;
  27. var browserName ;
  28. var numberVersion ;
  29. var pluginVersion = -1 ;
  30.  
  31. /*
  32. * Used to find informations on the browser. The informations are :
  33. *        - name of the platform,
  34. *       - name of the browser,
  35. *       - number of the version of the navogator.
  36. * The function return Unknown if the plugin can't be supported.
  37. */
  38. function  findBrowser () {
  39.   platformName = findPlatformName () ;
  40.   browserName = findBrowserName () ;
  41.   numberVersion = findNumberVersionBrowser () ;
  42.   var browser = "Unknown" ;
  43.   
  44.   if (platformName == "Unknown" || browserName == "Unknown" || numberVersion == "NaN") {
  45.     return browser ;
  46.   }
  47.   
  48.   if (browserName == "Netscape") {
  49.     if (platformName == "Windows") {
  50.       if (numberVersion >= 4) {
  51.     browser = "Net.Win.4" ;
  52.     pluginVersion =  winNetPluginVersion ;
  53.       }
  54.     }
  55.     else {
  56.       if (platformName == "Macintosh") {
  57.     if (numberVerion >= 4) {
  58.       browser = "Net.Mac.4" ;
  59.       pluginVersion = macNetPluginVersion ;
  60.     }
  61.       }
  62.     }
  63.   }
  64.   
  65.   else {
  66.     if (browserName == "Explorer") {
  67.       if (platformName == "Windows") {
  68.     if (numberVersion >= 4) {
  69.       browser = "Exp.Win.4" ;
  70.       pluginVersion = winExpPluginVersion ;
  71.     }
  72.       }
  73.     }
  74.   }
  75.   
  76.   return browser ;
  77. }
  78.  
  79. /*
  80. * Used to know if a user has a plugin or the last version of this plugin.
  81. * The function return false if there is nothing to do and true if
  82. * the plugin must be replaced.
  83. * The function findBrowser () must be call before this function.
  84. */
  85. function installNewPlugin (mimeType, pluginName) {
  86.   if (pluginVersion == -1) {
  87.     return false ;
  88.   }
  89.     
  90.   if (findPlugin (mimeType, pluginName) == false) {
  91.     return true ;
  92.   }
  93.          
  94.   var pluginDescription = navigator.plugins [pluginName].description ;
  95.   var indexVersion = pluginDescription.indexOf ("version") ;
  96.          
  97.   if (indexVersion == -1 || indexVersion == "") {
  98.     return false ;
  99.   }
  100.          
  101.   //var userVersion = parseFloat (pluginDescription.substring (indexVersion + 8, indexVersion + 14)) ;
  102.   var userVersion = pluginDescription.substring (indexVersion + 8, indexVersion + 16) ;
  103.  
  104.   if (userVersion < pluginVersion) {
  105.     return true ;
  106.   }
  107.   else {
  108.     return false ;
  109.   }
  110. }
  111.  
  112. /* 
  113. * Used to update or installe the plugin.
  114. */
  115. function updatePlugin () {
  116.   var browser = findBrowser () ;
  117.   var install = installNewPlugin ("application/x-z3d","3Space Plugin") ; 
  118.  
  119.   if (install == true) {
  120.     if (browser == "Net.Win.4") {
  121.       netscape.softupdate.Trigger.StartSoftwareUpdate (jarDirWin, netscape.softupdate.Trigger.DEFAULT_MODE) ;
  122.     }
  123.     else if (browser == "Net.Mac.4") {
  124.       netscape.softupdate.Trigger.StartSoftwareUpdate (jarDirMac, netscape.softupdate.Trigger.DEFAULT_MODE) ;
  125.     } 
  126.   }
  127. }
  128.  
  129. /*
  130. * Used to find the name of the platform.
  131. * The function can return :
  132. *       - Windows,
  133. *       - Macintosh,
  134. *      - Unknown.
  135. * Example for the field navigator.userAgent :
  136. *           Mozilla/2.0 (Win16; I). 
  137. */
  138. function findPlatformName () {
  139.   var platform = navigator.userAgent ;
  140.   var indexWin = (platform.toLowerCase ()).indexOf ("win") ;
  141.   var indexMac = (platform.toLowerCase ()).indexOf ("mac") ;
  142.          
  143.   if (indexWin != -1 && indexWin != "") {
  144.     platformName = "Windows" ;
  145.   }
  146.   else {
  147.     if (indexMac != -1 && indexMac != "") {
  148.       platformName = "Macintosh" ;
  149.     } 
  150.     else {
  151.       platformName = "Unknown" ;
  152.     }
  153.   }
  154.          
  155.   return platformName ;    
  156. }
  157.  
  158. /*
  159. * Used to find the name of the browser.
  160. * The function can return :
  161. *       - Netscape,
  162. *      - Explorer,
  163. *      - Unknown.
  164. * Example for the field navigator.appName :
  165. *           Netscape 
  166. */
  167. function  findBrowserName () {
  168.   var browser = navigator.appName.toLowerCase () ;
  169.             
  170.   if (browser == "netscape") {
  171.     browserName = "Netscape" ;            
  172.   }
  173.   else {
  174.     if (browser == "microsoft internet explorer") {
  175.       browserName = "Explorer" ;
  176.     }
  177.     else {
  178.       browserName = "Unknown" ;
  179.     }
  180.   }     
  181.  
  182.   return browserName ;
  183. }     
  184.  
  185. /*
  186. * Used to find the number of the version of the navigator.
  187. * if there is a problem the function return NaN (Not a Number).
  188. * Example for the field navigator.appVersion :
  189. *           3.0 (WinNT, I)
  190. */
  191. function findNumberVersionBrowser () {
  192.   var version = navigator.appVersion ;
  193.   numberVersion = parseFloat (version.substring (0, version.indexOf (" "))) ;
  194.   return numberVersion ;    
  195. }
  196.  
  197. /*
  198. * Used to know if the plugin is installed.
  199. * Example for the parameters :
  200. *           - mimeType: application/x-zap
  201. *          - pluginName: TGS Europe NPZap
  202. */
  203. function findPlugin (mimeType, pluginName) {
  204.   var sizePlugin = navigator.plugins.length ;
  205.          
  206.   for (var i = 0 ; i < sizePlugin ; i++) {
  207.     var aPlugin = navigator.plugins[i] ;
  208.     if (aPlugin.name == pluginName) {
  209.       var sizeMime = aPlugin.length ;
  210.       for (var j = 0 ; j < sizeMime ; j++) {
  211.     var aMime = aPlugin [j] ;
  212.     if (aMime.type == mimeType) {
  213.       return true ;
  214.     }
  215.       }
  216.     }
  217.   }     
  218.   return false ;
  219. }
  220.     
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.