refactoring - 如何将 Inno Setup 脚本分成多个文件?

标签 refactoring inno-setup

我有两个共享通用代码的设置脚本。有可能重构它们吗?
这样做的一种方法是为每个脚本引用的公共(public)代码文件。
这可能吗?

最佳答案

根据您使用的 InnoSetup 版本,您可以使用包含文件。下面的示例使用三个文件(main.iss、code.iss、commonfiles.iss):

主文件:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "My Program"
#define MyAppVerName "My Program 1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "MyProg.exe"

[Setup]
AppName={#MyAppName}
AppVerName={#MyAppVerName}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\util\innosetup\Examples\MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion

#include "CommonFiles.iss"

; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppName}}"; Flags: nowait postinstall skipifsilent

#include "code.iss"

CommonFiles.iss:
Source: "Common.DLL"; DestDir: "{app}"; Flags: ignoreversion

代码.iss:
[code]
function IsDotNET11Detected(): boolean;
// Indicates whether .NET Framework 1.1 is installed.
var
    success: boolean;
    install: cardinal;
begin
    success := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322', 'Install', install);
    Result := success and (install = 1);
end;

function InitializeSetup(): Boolean;
begin
    if not IsDotNET11Detected then begin
        MsgBox('This software requires the Microsoft .NET Framework 1.1.'#13#13
            'Please use Windows Update to install this version,'#13
            'and then re-run the setup program.', mbInformation, MB_OK);
        Result := false;
    end else
        begin
        MsgBox('Framework installed',mbInformation, MB_OK);
        Result := true;
        end
end;

关于refactoring - 如何将 Inno Setup 脚本分成多个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3968461/

相关文章:

android - 将开源的JniLibs整合到自己的android项目中

python - 更好的方法来测试功能

java - 比较哪里

inno-setup - 在 Inno Setup 脚本中使用 Inno Setup 编译器命令行上指定的路径/值

inno-setup - 在 Inno Setup 中禁用静默和非常静默卸载

inno-setup - 创建服务之前运行安装后文件替换

python - 在 Python 中重构长语句

javascript - 我该如何重构这段 JavaScript 代码?

desktop-application - 如何在innosetup脚本中查询用户的语言选择?

loops - Inno Setup 在 Pascal 代码中迭代 [Files] 部分