代码之家  ›  专栏  ›  技术社区  ›  Jader Dias

如何将一个Inno安装脚本分成多个文件?

  •  4
  • Jader Dias  · 技术社区  · 14 年前

    我有两个共享公共代码的安装脚本。可以重构它们吗? 一种方法是为每个脚本引用的公共代码创建一个文件。 这有可能吗?

    1 回复  |  直到 14 年前
        1
  •  9
  •   mirtheil    14 年前

    根据您使用的InnoSetup的版本,您可以使用include文件。下面的示例使用三个文件(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"
    

    通用文件.iss:

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

    Code.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;
    
    推荐文章