Install Object

This is an archived page. It's not actively maintained.

Parts of this page show the use of the XPInstall API. The majority of this API is now deprecated and as of Gecko 1.9 no longer available. Extension, Theme, and plug-in developers must switch away from install.js based packages to the new packaging scheme with an install.rdf manifest. In particular plugin developers should see how to package a plugin as an extension.

Install (Install 对象)

Use the Install object to manage the downloading and installation of software with the XPI Installation Manager.


The Install object is used primarily in installation scripts. In all cases, the Install object is implicit--like the window object in regular web page scripts--and needn't be prefixed to the object methods. The following two lines, for example, are equivalent:
Install对象首先会被安装脚本所使用. Install对象总是隐式的, 如同在规则的web页脚本中的window对象一样, 你并不需要将其作为其方法的调用前缀. 例如, 以下两行代码功能是完全一样的:

f = getFolder("Program");
f = Install.getFolder("Program");

An installation script is composed of calls to the Install object, and generally takes the following form:
一个安装脚本被书写为调用Install对象, 并且通常采取以下形式:

Initialize the installation (初始化安装)
Call initInstall with the name of the installation and the necessary registry and version information.
调用initInstall(函数), 和安装的名称, 必须的注册以及版本信息.
Add the files to the installation (添加文件到安装)
Add files to the installation by calling getFolder to get file objects and passing those object refs to addFile as many times as necessary.
添加文件到安装, 通过调用 getFolder(函数)取得文件对象并传递那些对象引用到 addFile(函数), 多数时候这样做还是有必要的.
Perform installation (执行安装)
Check that the files have been added successfully (e.g., by checking the error Return Codes from many of the main installation methods, and go ahead with the install if everything is in order:
检查那些文件是否被添加成功(比如通过检查 Return Codes从多数主要安装函数所返回的错误代码), 并且如果所有函数的执行都是正确的, 那么就可以进行后继安装步骤:
function performOrCancel()
  if (0 == getLastError())

For complete script examples, see Script Examples.
完事的脚本实例, 参见 Script Examples.