user253008
user253008

Reputation: 143

How to install only file based on condition (external configuration file) in Inno Setup

I have an XML file with some tags like names of DLL files.

I want a Inno Setup script code to install only files stated in the XML file (I can read from XML file).

My question is: How can I embed all DLL files and according to the XML file, I only install only the required files.

The idea I just need one XML for each release, and I never change the DLL files.

Upvotes: 2

Views: 821

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202292

Use the Check parameter to programmatically decide if a certain file should be installed:

[Files]
Source: "Dll1.dll"; DestDir: "{app}"; Check: ShouldInstallDll1
Source: "Dll2.dll"; DestDir: "{app}"; Check: ShouldInstallDll2
[Code]

function ShouldInstallDll1: Boolean;
begin
  Result := ???;
end;

function ShouldInstallDll2: Boolean;
begin
  Result := ???;
end;

If it better suits your logic, you can also use a single "check" function and use the CurrentFileName magic variable, to test, if the file being installed, is the one you want to really install:

[Files]
Source: "Dll1.dll"; DestDir: "{app}"; Check: ShouldInstallDll
Source: "Dll2.dll"; DestDir: "{app}"; Check: ShouldInstallDll
[Code]

var
  FileToInstall: string;

function InitializeSetup(): Boolean;
begin
  FileToInstall := ??? // 'Dll1.dll' or 'Dll2.dll' based on the XML file
  Result := True;
end;

function ShouldInstallDll: Boolean;
var
  FileName: string;
begin
  FileName := ExtractFileName(CurrentFileName);
  Result := (CompareText(FileName, FileToInstall) = 0);
end;

The latter approach can be used, even if you pack files using a wildcard:

[Files]
Source: "*.dll"; DestDir: "{app}"; Check: ShouldInstallDll

Upvotes: 2

Related Questions