Operations
操作
The operations are prepared by component and controller scripts or component.xml and performed by the installer.
这些操作由组件和控制器脚本或component.xml准备,并由安装程序执行。
Note: Operations are performed threaded.
注意:操作是线程化的。
Internally, each operation has a DO step that contains instructions for the installer and an UNDO step that contains instructions for the uninstaller.
在内部,每个操作都有一个DO步骤和一个UNDO步骤,DO步骤包含安装程序的说明,UNDO步骤包含卸载程序的说明。
Some operations especially in Windows might need native separators. Use installer.toNativeSeparators()
to convert separators to ones that are appropriate for the underlying operating system.
某些操作(尤其是在Windows中)可能需要本机分隔符。使用installer.toNativeSeparators()将分隔符转换为适合底层操作系统的分隔符。
Summary of Operations
操作概况
The following table summarizes the available operations and their syntax in component and controller scripts. Syntax for operations in component.xml is:
下表总结了组件和控制器脚本中的可用操作及其语法。component.xml中操作的语法为:
<Operations>
<Operation name="operation">
<Argument>argument1</Argument>
<Argument>argument2</Argument>
</Operation>
</Operations>
Note: The argument order in component.xml is the same as in scripting, except for
Extract
operation where the argumentarchive
is optional, and must be defined as the last argument.注意:component.xml中的参数顺序与脚本中的相同,除了Extract操作,其中参数
archive
是可选的,并且必须定义为最后一个参数。
Operation | Syntax | Use |
---|---|---|
Copy | "Copy" source target | Copies a file from 将文件从源复制到目标。
|
Move | "Move" source target | Moves a file from 将文件从源移动到目标。
|
SimpleMoveFile | "SimpleMoveFile" source target | Moves a file from 将文件从源移动到目标。
|
Delete | "Delete" filename | Deletes the file specified by 删除由filename指定的文件。
|
Mkdir | "Mkdir" path | Creates the directory path 创建目录路径。
|
Rmdir | "Rmdir" path | Removes the directory path 删除目录路径。
|
CopyDirectory | "CopyDirectory" sourcePath targetPath | Copies a directory from 将目录从sourcePath复制到targetPath。
|
AppendFile | "AppendFile" filename text | Appends 将
|
PrependFile | "PrependFile" filename text | Prepends 将
|
Replace | "Replace" file search replace mode | Opens 打开 Note that testing the operation using 请注意,使用devtool测试操作不支持 |
LineReplace | "LineReplace" file search replace | Opens 打开 |
Execute | "Execute" [{exitcodes }] command [parameter1 [parameter... [parameter10 ]]] | Executes the command specified by 执行命令指定的命令。最多可以传递10个参数。如果这还不够,可以使用JavaScript字符串数组。 Optionally, you can pass a comma-separated list of exit codes within curly brackets ({}) as the first argument to specify the exit codes for successful execution. This defaults to "{0}". Other optional named arguments are: "workingdirectory=<your_working_dir>"; "errormessage=<your_custom_errormessage>" 可以选择在花括号({})内传递一个逗号分隔的退出代码列表作为第一个参数,以指定成功执行的退出代码。默认为“{0}”。 In addition, a special argument, UNDOEXECUTE, separates the DO step of the operation from the UNDO step. 此外,一个特殊的参数UNDOEXECUTE将操作的DO步骤与UNDO步骤分开。 Example:
|
CreateShortcut | "CreateShortcut" filename linkname [arguments ] | Creates a shortcut from the file specified by 从文件名指定的文件到链接名创建快捷方式。在Windows上,这会创建一个可以有参数的.lnk文件。 Furthermore, 此外,
|
CreateDesktopEntry | "CreateDesktopEntry" filename "key=value[ key2=value2[ key3=value3]]]" | Creates a .desktop initialization file, as specified by freedesktop.org. This operation is useful only on X11 or Wayland based Linux distributions. 按照freedesktop.org的指定创建.desktop初始化文件。此操作仅在基于X11或Wayland的Linux发行版上有用。 If 如果filename是绝对的,则桌面条目存储在那里。否则,它将存储在$XDG_DATA_HOME/applications中指定的位置,包括freedesktop.org定义的默认路径。对于系统范围的安装,它存储在/usr/local/share/applications中。 The key-value pairs are written to the file. 键值对被写入文件。 The file is set to use UTF-8 encoding. 设置编码 |
InstallIcons | "InstallIcons" directory [Vendorprefix] | Installs the contents of 将 |
Extract | "Extract" archive targetdirectory | Extracts 将 |
GlobalConfig | "GlobalConfig" company application key value or "GlobalConfig" or "GlobalConfig" | Stores 将
|
EnvironmentVariable | "EnvironmentVariable" key value [persistent [system ]] | Sets the environment variable 将环境变量 |
RegisterFileType | "RegisterFileType" extension command [description [contentType [icon ]]]. | Registers the file type with 注册要通过
|
ConsumeOutput | "ConsumeOutput" installerKeyName executablePath processArguments | Saves the output from running the executable located at 将运行位于可执行文件路径的 |
CreateLink | "CreateLink" linkPath targetPath | Creates a link in the location specified by 在linkPath指定的位置创建指向targetPath指定位置的链接。 |
CreateLocalRepository | "CreateLocalRepository" binaryPath repoPath | Creates a local repository in the directory specified by 在repoPath指定的目录中创建本地存储库。对于脱机安装程序,将二进制数据存储在binaryPath指定的目录中。
|
FakeStopProcessForUpdate | "FakeStopProcessForUpdate" processlist | Matches running processes against the comma-separated entries in 在卸载过程中,将正在运行的进程与 |
License | "License" licenses | Copies the license files specified by 将 |
MinimumProgress | "MinimumProgress" | Increases the progress value by one. 将进度值增加1。 |
SelfRestart | "SelfRestart" core | Restarts the updater or package manager specified by 重新启动 |
Settings | "Settings" path method key value | Sets or removes the
|
The Extract, License, and MinimumProgress operations are automatically added for matching components that do not overwrite the component::createOperations() method. See also component::autoCreateOperations.
对于不覆盖 component::createOperations()方法的匹配组件,会自动添加Extract、License和MinimumProgress操作。另请参见component::autoCreateOperations。
If errors occur, you can test operations manually using the devtool
. However, variables are not resolved, so you need to use absolute values.
如果发生错误,可以使用devtool手动测试操作。但是,变量不会被解析,因此需要使用绝对值。
For example, to test copying a file:
例如,要测试复制文件:
devtool operation <binary> DO,Copy,<source>,<target>
Execution Groups
执行组
The operations owned by a component belong to either of two groups: Unpack or Install. The Extract
operations are performed as part of the Unpack group before all other operations and executed concurrently between all components that are going to be installed. The rest of the operations are performed in the Install group and executed sequentially for each component at a time.
组件所拥有的操作属于以下两组之一:Unpack 或Install。Extract
操作在所有其他操作之前作为Unpack 组的一部分执行,并在将要安装的所有组件之间同时执行。其余操作在Install组中执行,并一次对每个组件按顺序执行。
Custom operations can define their execution group by calling the setGroup()
method in their constructor. For more information about custom operations, see Registering Custom Operations.
自定义操作可以通过在构造函数中调用setGroup()方法来定义其执行组。有关自定义操作的更多信息,请参阅注册自定义操作。
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. The Qt Company, Qt and their respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.