Tải bản đầy đủ (.pdf) (15 trang)

Tài liệu Creating Applications with Mozilla-Chapter 6. Packaging and Installing Applications-P3 pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (63.96 KB, 15 trang )

Chapter 6. Packaging and Installing Applications-P3
When you have very simple installations -- such as when you want to install
a new skin -- you may not need to use the services from the Install
object. Besides providing the services necessary for "triggering" the
downloading of a package from a web site, the InstallTrigger object
offers some simple methods for installing when you do not need to rearrange
of the disk, register complications, or do other install-type preparation (see
Table 6-2
).
Table 6-2. InstallTrigger interface showing the role of the InstallTrigger
object in the overall installation process
Method Description
compareVersion
Compares the version of a file or
package with the version of an
existing file or package.
Enabled
Indicates whether the Software
Installation is enabled for this client
machine.
getVersionInfo
Returns an InstallVersion
object representing the version
number from the Client Version
Registry for the specified software or
component.
Method Description
Install
Installs one or more XPI files on the
local machine.
installChrome


Installs new skin or locale packages
in Netscape 6 and Mozilla.
startSoftwareUpdate
Initiates the download and
installation of specified software.
Note: deprecated in favor of install.
This web page installation script defines its own install method in which
a callback parameter on the InstallTrigger's own install( )
method checks the success of the installation and displays a relevant alert for
the user (as shown in Example 6-17
).
Example 6-17. Install script callback
function doneFn (name, result)
{
if (result != 0 && result != 999)
alert("The install didn't seem to work, you
could maybe try " +
"a manual install instead.\nFailure code
was " + result + ".");
else
alert("Installation complete, please restart
your browser.");
}
function install(packageName, fileName)
{
var xpi = new Object( );
xpi[packageName] = fileName;
InstallTrigger.install(xpi, doneFn);
}
<a

href="javascript:install('xFly','xfly.xpi');">insta
ll</a>
6.3.3.3. Installing non-Mozilla software
The XPInstall technology downloads and installs any software on any
machine using Mozilla or Netscape 6/7. The same Install object methods
that download, register, and install new Mozilla packages (e.g., new themes
or new Mozilla applications like xFly) can be used to download other
executables and software into any location on the local machine.
As with Mozilla application installs, you use an installation script within a
XPI to initialize the installation, add the files you want to the installation,
and then perform the install and put the software in the designated locations.
Note that non-Mozilla software installations do not include a registration
step, since the chrome registry does not track non-Mozilla software or any
more general additions to the operating system. Example 6-18 shows a
simple and typical non-Mozilla installation.
Example 6-18. Non-Mozilla software installation script
var xpiSrc = "file.txt";
initInstall(
"Adding A File",
"testFile",
"1.0.1.7",
1);
f = getFolder("Program"); // keyword for the main
program
// directory on the
target platform
// (e.g., the "Program
Files" dir on win32)
setPackageFolder(f);
addFile(xpiSrc);

if (0 == getLastError( ))
performInstall( );
else
cancelInstall( );
Refer to the "XPInstall API Reference" on for
more detailed information about the XPInstall API and how it can be used in
more complex installations.
6.3.4. Uninstalling Applications
You may have noticed an uninstall( ) method on the Install object
in the XPInstall API. This method does some of the work you need to do to
uninstall packages from Mozilla, but it's a buggy process and doesn't finish
the job.[1]
Beyond the physical removal of the package resources during the
uninstall, several RDF files in the chrome registry need to be updated, and
the XPInstall uninstall( ) does not get to some of these files.
Fortunately, the JSLib JavaScript developer's library has a well-implemented
uninstall function, which you can use by importing the uninstall.js
file and calling uninstall on the package you want uninstalled.
uninstall.js is one of the JS file collections that comprise the JSLib.
Once you install JSLib, using the uninstall method is simple:
include("chrome://jslib/install/uninstall.js");
var p = new Uninstall('myPackageName');
p.removePkg( );
You might want to put this uninstall routine in a function so you can reuse it.
function unInstall(pkg) {
var p = new Uninstall(pkg);
p.removePkg( );
}
This method removes the resources themselves and deletes all references to
the package in the chrome registry. The pkg parameter is the name of the

package as defined in the manifest for that package. The xFly package
manifest, for example, defines "xfly" as the name of the package, as shown
in Example 6-19
.
Example 6-19. Package metadata in the xFly manifest
<!-- xFly package information -->
<RDF:Description about="urn:mozilla:package:xfly"
chrome:displayName="xFly"
chrome:author="frillies"
chrome:name="xfly">
</RDF:Description>
Example 6-9
comes from the content package manifest for xFly, which is
similar to the full content manifest for the XMLTerm application you saw in
Example 6-4
.
To uninstall the xFly package, then -- as you should do to the working
version you have as you develop before installing the final version -- hook
up a menuitem to call the uninstall routine:
<menuitem id="uninstall-item" label="Uninstall
xFly" oncommand="unInstall("xfly")" />
This menuitem should have access to a JavaScript file and contains the
following code:
include("chrome://jslib/install/uninstall.js");
function unInstall(pkg) {

×