1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
---
title: Install Object
slug: Archive/Mozilla/XPInstall/Reference/Install_Object
tags:
- XPInstall_API_reference
translation_of: Archive/Mozilla/XPInstall/Reference/Install_Object
---
<p></p><div class="warning"><p>Parts of this page show the use of the <a href="https://developer.mozilla.org/zh-CN/docs/XPInstall_API_Reference">XPInstall API</a>. The majority of this API is now deprecated and as of Gecko 1.9 no longer available. <a href="https://developer.mozilla.org/zh-CN/docs/Extensions">Extension</a>, <a href="https://developer.mozilla.org/zh-CN/docs/Themes">Theme</a>, and <a href="https://developer.mozilla.org/zh-CN/docs/Plugins">plug-in</a> developers must switch away from <code>install.js</code> based packages to the new <a href="https://developer.mozilla.org/zh-CN/docs/Bundles">packaging scheme</a> with an <code><a href="https://developer.mozilla.org/zh-CN/docs/Install_Manifests">install.rdf</a></code> manifest. In particular plugin developers should see <a class="new" href="https://developer.mozilla.org/zh-CN/docs/Shipping_a_plugin_as_a_Toolkit_bundle" rel="nofollow">how to package a plugin as an extension</a>.</p></div><p></p>
<h2 id="Install_.28Install_.E5.AF.B9.E8.B1.A1.29" name="Install_.28Install_.E5.AF.B9.E8.B1.A1.29">Install (Install 对象)</h2>
<p>Use the <code>Install</code> object to manage the downloading and installation of software with the XPI Installation Manager.<br>
译:使用<code>Install</code>对象协同XPI安装管理器操纵软件的下载和安装.</p>
<h3 id="Overview" name="Overview">Overview</h3>
<p>The Install object is used primarily in installation scripts. In all cases, the <code>Install</code> object is implicit--like the <code>window</code> object in regular web page scripts--and needn't be prefixed to the object methods. The following two lines, for example, are equivalent:<br>
Install对象首先会被安装脚本所使用. Install对象总是隐式的, 如同在规则的web页脚本中的<code>window</code>对象一样, 你并不需要将其作为其方法的调用前缀. 例如, 以下两行代码功能是完全一样的:</p>
<pre>f = getFolder("Program");
f = Install.getFolder("Program");
</pre>
<p>An installation script is composed of calls to the Install object, and generally takes the following form:<br>
一个安装脚本被书写为调用Install对象, 并且通常采取以下形式:</p>
<dl>
<dt>Initialize the installation (初始化安装)</dt>
<dd>Call <a href="cn/XPInstall_API_Reference/Install_Object/Methods/initInstall"> initInstall</a> with the name of the installation and the necessary registry and version information.</dd>
<dd>调用<a href="cn/XPInstall_API_Reference/Install_Object/Methods/initInstall">initInstall(函数)</a>, 和安装的名称, 必须的注册以及版本信息.</dd>
<dt>Add the files to the installation (添加文件到安装)</dt>
<dd>Add files to the installation by calling <a href="cn/XPInstall_API_Reference/Install_Object/Methods/getFolder"> getFolder</a> to get file objects and passing those object refs to <a href="cn/XPInstall_API_Reference/Install_Object/Methods/addFile"> addFile</a> as many times as necessary.</dd>
<dd>添加文件到安装, 通过调用<a href="cn/XPInstall_API_Reference/Install_Object/Methods/getFolder"> getFolder(函数)</a>取得文件对象并传递那些对象引用到<a href="cn/XPInstall_API_Reference/Install_Object/Methods/addFile"> addFile(函数)</a>, 多数时候这样做还是有必要的.</dd>
<dt>Perform installation (执行安装)</dt>
<dd>Check that the files have been added successfully (e.g., by checking the error <a href="cn/XPInstall_API_Reference/Return_Codes"> Return Codes</a> from many of the main installation methods, and go ahead with the install if everything is in order:</dd>
<dd>检查那些文件是否被添加成功(比如通过检查<a href="cn/XPInstall_API_Reference/Return_Codes"> Return Codes</a>从多数主要安装函数所返回的错误代码), 并且如果所有函数的执行都是正确的, 那么就可以进行后继安装步骤:</dd>
</dl>
<pre>performOrCancel();
function performOrCancel()
{
if (0 == getLastError())
performInstall();
else
cancelInstall();
}
</pre>
<p>For complete script examples, see <a href="cn/XPInstall_API_Reference/Examples"> Script Examples</a>.<br>
完事的脚本实例, 参见<a href="cn/XPInstall_API_Reference/Examples"> Script Examples</a>.</p>
|