views:

23

answers:

1

I have two setup scripts that share common code. It is possible to refactor them? One way of doing that is having a file for common code which will be referenced by each script. Is this possible?

+3  A: 

Depending on the version of InnoSetup you are using, you can use an include file. The example below uses three files (main.iss, code.iss, commonfiles.iss):

Main File:

; 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

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;
mirtheil
I think your solution depends on the [Inno Setup Preprocessor](http://ispp.sourceforge.net/) which is included on the [Inno Setup QuickStart Pack](http://www.jrsoftware.org/isdl.php#qsp)
Jader Dias