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

laser13 at svn.annodex.net laser13 at svn.annodex.net
Tue Jun 26 03:24:38 PDT 2007


Author: laser13
Date: 2007-06-26 03:24:38 -0700 (Tue, 26 Jun 2007)
New Revision: 3063

Modified:
   liboggplay/trunk/Installer/install.js
Log:
Rewritten trigger script for XPI installer (so far supports Win32 and Linux).

Modified: liboggplay/trunk/Installer/install.js
===================================================================
--- liboggplay/trunk/Installer/install.js	2007-06-26 10:23:39 UTC (rev 3062)
+++ liboggplay/trunk/Installer/install.js	2007-06-26 10:24:38 UTC (rev 3063)
@@ -21,7 +21,8 @@
  *
  * Contributor(s):
  *   Andre Pang <andre.pang at csiro.au>
- *   Chris Ford <christophertford at gmail.com> (converted for Oggplay)
+ *   Chris Ford <christophertford at gmail.com> 
+ *   Marcin Lubonski <marcin.lubonski at csiro.au>
  *
  * 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
@@ -37,117 +38,144 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
-const REGISTERED_PACKAGE_NAME  = "Oggplay";
-const PACKAGE_VERSION         = "0.1.0";
+// 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)
 
-// Initialise the installer
-var initError = initInstall
-(
-  "Oggplay media player",
-  REGISTERED_PACKAGE_NAME,
-  PACKAGE_VERSION
-);
+// Unix/Linux specific
+const LUNIX_PLUGIN_FILE_SIZE      = 2000; // (.DLL file size after unpacking)
 
-// What platform are we on?
-function getPlatform ()
-{
-  var platformString = new String(Install.platform);
+// Mac specific
 
-  if (!platformString.search(/^Macintosh/))
-    return "macosx";
-  else if (!platformString.search(/^Win/))
-    return "windows";
-  else
-    return "unix";
-}
+// !!! Win32 specific
+const WIN32_LIB_FILE_SUFFIX   = ".dll";
+const LUNIX_LIB_FILE_SUFFIX   = ".so";
 
-// Where are we installing to?  This depends on what platform we're running on.
-var PluginsDirectory;
-var OggplayTempDirectory;  // For UNIX systems only: see comment below
+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)
 
-if (getPlatform() == "unix")
-{
-  // On UNIX systems, we install the plugins to a directory named "OggplayTemp"
-  // in the user's profile directory: this is because I can't find out a way to
-  // install things to the $HOME/.mozilla/plugins/ directory, which is where
-  // plugins should go.  We rely on a shell script that gets invoked later in
-  // the installation to move the installed plugin from the OggplayTemp 
-  // directory to the ~/.mozilla/plugins/ directory.
+// Initialise the installer
+var error = initInstall(
+    PLUGIN_NAME, 
+    PLID, 
+    VERSION);
 
-  PluginsDirectory = getFolder("Profile", "OggplayTemp");
-  OggplayTempDirectory = PluginsDirectory;
+if (error != 0)
+{
+	// call initInstall again in case illegal characters in PLID	
+	error = initInstall(SOFTWARE_NAME, SOFTWARE_NAME, VERSION);	
+	
+	if (error != 0)
+	cancelInstall(error);
+}
 
-  currentUserDirectory = getFolder("Current User");
-  logComment("currentUserDirectory is " + currentUserDirectory);
-}
-else if (getPlatform() == "windows")
-{
-  // Note: this will fail if the user does not have write access to the
-  // Mozilla system plugins directory!  (Typically
-  // "C:\Program Files\mozilla.org\Mozilla\Plugins")
-  PluginsDirectory = getFolder("Plugins");
-}
-else if (getPlatform() == "macosx")
-{
-  PluginsDirectory = getFolder("Profile", "../../../../Internet Plug-Ins");
-}
-else
-{
-  // In the rather unlikely event we're not being installed on a Mac,
-  // Windows, or UNIX system ...
-  alert(  "You are attempting to install the Oggplay plugin on "
+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.");
+	    + "annodex-dev at lists.annodex.net for assistance.");
 }
 
-logComment("Destination Plugins directory: " + PluginsDirectory);
+var pluginsFolder = getFolder("Plugins");
 
-if (getPlatform() == "unix")
-{
+// check if there is enough disk space to install the plugin
+if (verifyDiskSpace(pluginsFolder, pluginFileSize + componentFileSize)) {
 
-  // We need to put double quotes around the name of the directory for
-  // the XPInstall API's execute() command to work properly (see the XPInstall
-  // API documentation for more details about this)
-  var OggplayTempDirectoryAsQuotedString ='"' + new String(OggplayTempDirectory)
-  				       + '"';
-  // Move the plugin from the $profile/OggplayTemp/ directory to 
-  // ~/.mozilla/plugins
-  var executeResult = execute("MovePluginsFromOggplayTempToMozillaPlugins.sh",
-	  		      OggplayTempDirectoryAsQuotedString,
-	   		      true);
+    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);
+    }
 
-  if (executeResult != SUCCESS)
-  {
-    logComment("MovePluginsFromOggplayTempToMozillaPlugins.sh returned error: "
-               + executeResult);
-  }
+} else {
+    logComment("Cancelling current browser install due to lack of space...");
+	cancellInstall();
 }
 
-// TODO: Check disk space
+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();
+    
+}
 
-// Set up the target directory
-var addDirectoryResult = addDirectory
-(
-  REGISTERED_PACKAGE_NAME,
-  PACKAGE_VERSION,
-  "bin/plugins",  		// jar source folder
-  PluginsDirectory,		// target folder
-  "",             		// target subdirectory
-  true            		// overwrite files
-);
 
-// Perform the install
-if (addDirectoryResult == SUCCESS)
+/**
+ * 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 ()
 {
-  var performInstallResult = performInstall();
-  
-  if (performInstallResult != SUCCESS)
-    logComment("performInstall() returned: " + performInstallResult);
+  var platformString = new String(Install.platform);
 
-  refreshPlugins();
-}
-else
-{
-  cancelInstall(addDirectoryError);
-  logComment("addDirectory() failed: " + addDirectoryError);
-}
+  if (!platformString.search(/^Macintosh/))
+    return "macosx";
+  else if (!platformString.search(/^Win/))
+    return "windows";
+  else
+    return "unix";
+}
\ No newline at end of file



More information about the commits mailing list