[xiph-commits] r3101 - liboggplay/trunk/Installer

tahn at svn.annodex.net tahn at svn.annodex.net
Wed Jun 27 18:42:37 PDT 2007


Author: tahn
Date: 2007-06-27 18:42:37 -0700 (Wed, 27 Jun 2007)
New Revision: 3101

Modified:
   liboggplay/trunk/Installer/install.js
Log:
Added Mac installation, tidied up.


Modified: liboggplay/trunk/Installer/install.js
===================================================================
--- liboggplay/trunk/Installer/install.js	2007-06-28 01:24:33 UTC (rev 3100)
+++ liboggplay/trunk/Installer/install.js	2007-06-28 01:42:37 UTC (rev 3101)
@@ -23,6 +23,7 @@
  *   Andre Pang <andre.pang at csiro.au>
  *   Chris Ford <christophertford at gmail.com> 
  *   Marcin Lubonski <marcin.lubonski at csiro.au>
+ *   Michael Martin
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -38,144 +39,129 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
-// Define some constants 
-const PLID                  = "CSIRO.au/Oggplay,version=1.0";
-const VERSION               = "1.0.0.0";
-const PLUGIN_NAME           = "Oggplay media player";
-const PLUGIN_FILE_STEM      = "npliboggplugin";
-// This plugin consists of an XPT file because it is scriptable
-//   http://mozilla.org/projects/plugins/scripting-plugins.html
-const COMPONENT_FILE          = "npliboggplugin.xpt";
-const COMPONENT_FILE_SIZE     = 10; // (.XPT file size after unpacking)
-
-// Win32 specific
-const WIN32_PLUGIN_FILE_SIZE      = 2600; // (.DLL file size after unpacking)
+const PLID        = "CSIRO.au/Oggplay,version=1.0";
+const VERSION     = "1.0.0.0";
+const PLUGIN_NAME = "Oggplay media player";
 
-// Unix/Linux specific
-const LUNIX_PLUGIN_FILE_SIZE      = 2000; // (.DLL file size after unpacking)
+// Size values are for unpacked files, in kb
+var pluginName;
+var pluginSize;
+var useAddDir;
+var installDir;
 
-// Mac specific
+var xptName = "nsILibOggPlugin.xpt";
+var xptSize = 10;
 
-// !!! Win32 specific
-const WIN32_LIB_FILE_SUFFIX   = ".dll";
-const LUNIX_LIB_FILE_SUFFIX   = ".so";
+// wrap everything in a function so it's easier to exit on error
+doInstall();
 
-var error; // stores errors for the installation to the browser 'plugins' directory
-var pluginFileName;
-var pluginFileSize; // (.DLL/.so file size after unpacking)
-var componentFileSize; // (.xpt file size after unpacking)
+function doInstall() {
 
-// Initialise the installer
-var error = initInstall(
-    PLUGIN_NAME, 
-    PLID, 
-    VERSION);
+  // Initialise the installer
+  var error = initInstall(PLUGIN_NAME, PLID, VERSION);
+  if (error != SUCCESS) {
+    logComment("initInstall() failed: " + error);
+    return;
+  }
 
-if (error != 0)
-{
-	// call initInstall again in case illegal characters in PLID	
-	error = initInstall(SOFTWARE_NAME, SOFTWARE_NAME, VERSION);	
-	
-	if (error != 0)
-	cancelInstall(error);
-}
+  // Set up platform-specific details
+  switch (getPlatform()) {
+    case "unix":
+      pluginName = "npliboggplugin.so";
+      pluginSize = 2000;
+      installDir = getFolder("Plugins");
+      useAddDir  = false;
+      break;
 
-if (getPlatform() == "unix") {
-    pluginFileName = PLUGIN_FILE_STEM + LUNIX_LIB_FILE_SUFFIX;
-    pluginFileSize = LUNIX_PLUGIN_FILE_SIZE;
-    componentFileSize = COMPONENT_FILE_SIZE
-} else if (getPlatform() == "windows") {
-    pluginFileName = PLUGIN_FILE_STEM + WIN32_LIB_FILE_SUFFIX;
-    pluginFileSize = WIN32_PLUGIN_FILE_SIZE;
-    componentFileSize = COMPONENT_FILE_SIZE;
-} else if (getPlatform() == "mac") {
-    /** add here what necessary for Mac */
-} else {
-    alert(  "You are attempting to install the Oggplay plugin on "
-        + "an unsupported platform.  Please email "
-	    + "annodex-dev at lists.annodex.net for assistance.");
-}
+    case "windows":
+      pluginName = "npliboggplugin.dll";
+      pluginSize = 2600;
+      installDir = getFolder("Plugins");
+      useAddDir  = false;
+      break;
 
-var pluginsFolder = getFolder("Plugins");
+    case "mac":
+      pluginName = "liboggplay.plugin";
+      pluginSize = 2000;
+      installDir = getFolder("MacOSX User Internet PlugIn");
+      useAddDir  = true;
+      break;
 
-// check if there is enough disk space to install the plugin
-if (verifyDiskSpace(pluginsFolder, pluginFileSize + componentFileSize)) {
+    default:
+      alert("You are attempting to install the Oggplay plug-in on " +
+            "an unsupported platform.\n" +
+            "Please email annodex-dev at lists.annodex.net for assistance.");
+  }
 
-    resetError();
-    
-    error = addFile(PLID, VERSION, pluginFileName, pluginsFolder, null);
-
-	//alert("Installation of NPLIBOGGPLAY plug-in failed. Error code "+ error);
-    if (error != 0)
-    {
-	    logComment("Could NOT add " + pluginFileName + " to " + pluginsFolder + ":" + error);
-	    //cancelInstall(error);
-    } 
-
-    error = addFile(PLID, VERSION, COMPONENT_FILE, pluginsFolder, null);
-    if (error != 0)
-    {
-	    //alert("Installation of NPLIBOGGPLAY component failed. Error code "+ error);
-	    logComment("Could NOT add " + COMPONENT_FILE + " to " + pluginsFolder + ":" + error);
-        //cancelInstall(error);
-    }
+  // Check if there is enough disk space to install the plugin
+  if (!verifyDiskSpace(installDir, pluginSize + xptSize)) {
+    alert("There is not enough disk space to install the Oggplay plug-in.");
+    cancelInstall(INSUFFICIENT_DISK_SPACE);
+    return;
+  }
 
-} else {
-    logComment("Cancelling current browser install due to lack of space...");
-	cancellInstall();
-}
+  // Copy the plugin files to the installation directory
+  if (useAddDir) {
+    error = addDirectory(PLID, VERSION, pluginName, installDir, pluginName);
+  } else {
+    error = addFile(PLID, VERSION, pluginName, installDir, null);
+  }
+  if (error != SUCCESS) {
+    alert("Oggplay plug-in installation failed; could not copy plug-in files to "
+          + installDir);
+    logComment("Could not add " + pluginName + " to " + installDir + ":" + error);
+    cancelInstall(error);
+    return;
+  }
 
-if (error == SUCCESS) {
-    // Perform the install
-    var performInstallResult = performInstall();
-  
-    if (performInstallResult != SUCCESS) {
-        logComment("performInstall() returned: " + performInstallResult);
-    } else {
-        refreshPlugins();
-    }
-} else {
-    // try installing into a specified directory / different from default Plugin location
-    
-    resetError();
-    
+  error = addFile(PLID, VERSION, xptName, installDir, null);
+  if (error != SUCCESS) {
+    alert("Oggplay plug-in installation failed; could not copy plug-in files to "
+          + installDir);
+    logComment("Could not add " + xptName + " to " + installDir + ":" + error);
+    cancelInstall(error);
+    return;
+  }
+
+  // Perform the install
+  error = performInstall();
+  if (error != SUCCESS) {
+    logComment("performInstall() failed: " + error);
+  } else {
+    refreshPlugins();
+    alert("Completed installation of Oggplay plug-in");
+  }
 }
 
 
-/**
- * Installation environment specific functions 
- */
-function verifyDiskSpace(dirPath, spaceRequired)
-{
-  var spaceAvailable;
-
-  // Get the available disk space on the given path
-  spaceAvailable = fileGetDiskSpaceAvailable(dirPath);
-
-  // Convert the available disk space into kilobytes
-  spaceAvailable = parseInt(spaceAvailable / 1024);
-
-  // do the verification
-  if(spaceAvailable < spaceRequired)
-  {
-    logComment("Insufficient disk space to install NPLIBOGGPLAY plug-in : " + dirPath);
-    logComment("  required : " + spaceRequired + " K");
-    logComment("  available: " + spaceAvailable + " K");
-    return(false);
-  }
-
-  return(true);
-}
-
-// What platform are we on?
-function getPlatform ()
-{
+// -- Utility functions --
+function verifyDiskSpace(dirPath, spaceRequired) {
+  var spaceAvailable;
+
+  // Get the available disk space on the given path
+  spaceAvailable = fileGetDiskSpaceAvailable(dirPath);
+
+  // Convert the available disk space into kilobytes
+  spaceAvailable = parseInt(spaceAvailable / 1024);
+
+  // Do the verification
+  if (spaceAvailable < spaceRequired) {
+    logComment("Insufficient disk space to install Oggplay plug-in:");
+    logComment("  destination path: " + dirPath);
+    logComment("  required : " + spaceRequired + " kb");
+    logComment("  available: " + spaceAvailable + " kb");
+    return false;
+  }
+  return true;
+}
+
+function getPlatform() {
   var platformString = new String(Install.platform);
 
   if (!platformString.search(/^Macintosh/))
-    return "macosx";
+    return "mac";
   else if (!platformString.search(/^Win/))
     return "windows";
   else
     return "unix";
-}
\ No newline at end of file
+}



More information about the commits mailing list