gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:19:15 27 4
gpt4 key购买 nike

我有两个共享通用代码的设置脚本。有可能重构它们吗?
这样做的一种方法是为每个脚本引用的公共(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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com