Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional file copy in Inno Setup

I would like to make a conditional file copy/installation, depending what is inside given .cfg (text) file at {app} location. That file contains an URL inside, that URL looks like this: "update.website.eu", or this "update.website.com", or "update.worldoftanks.kr" but can be also "update.worldoftanks.kr/" and so on, there is a few possibilities. So I need a mechanism that will detect the url and let me install different files for each detected url.

Currently I have something like this as example, but I since I'm not advanced programmer (I know some basics only more or less), I need to have a good example.

if (CurPageID = wpPreparing) then
begin
  client_ver :=
    LoadValueFromXML(ExpandConstant('{app}\file.cfg'),
    '//info/patch_info_urls/item');
  if client_ver = 'http://update.website.eu/' then
    if MsgBox('Are you sure?', mbConfirmation, MB_OKCANCEL) = IDCANCEL then
      Result:=False;
end;

Example of file.cfg:

<?xml version="1.0" encoding="UTF-8"?>
<info version="3.1">
    <!-- ... -->
    <patch_info_urls>
        <item>http://update.website.eu/</item>
    </patch_info_urls>
</info>

Anyway I would like to use it in [Files] section, is that possible to trigger it from there, to call a procedure or something in [Files]?

I've made few tries but it always gives me some mismatch error during compilation.

ps. ignore that MsgBox, it's just example, I will not display anything like that. I need to copy files only.

like image 607
Jerry Zoden Avatar asked Feb 06 '23 08:02

Jerry Zoden


1 Answers

Use the Check parameter:

[Files]
Source: "file_for_url1"; DestDir: "{app}"; Check: IsURl1
Source: "file_for_url2"; DestDir: "{app}"; Check: IsURl2
[Code]

var
  ClientVer: string;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    ClientVer :=
      LoadValueFromXML(ExpandConstant('{app}\file.cfg'), 
      '//info/patch_info_urls/item');
    Log(Format('Client version is %s', [ClientVer]));
  end;
end;

function IsUrl1: Boolean;
begin
  Result := (ClientVer = 'http://update.website.eu/');
end;

function IsUrl2: Boolean;
begin
  Result := (ClientVer = 'http://update.website.com/');
end;
like image 126
Martin Prikryl Avatar answered May 09 '23 06:05

Martin Prikryl