Some1Else
Some1Else

Reputation: 795

Read destination directory from ini file during install time in Inno Setup

I need to read a directory path from an ini file at install time.

Under the [Code] section I have defined a function like

function GetDirectoryFromIni: String;
begin
  Result := 
    GetIniString('Directories' , 'Name' ,
      ExpandConstant('{app}')+'\Default_Path\' , 
      ExpandConstant('{app}')+'my_ini_file.ini');
end;

How can I use this function/path/string in the [Files] section?

Something like:

[Files]
Source: "C:\Source_Directory\*.*"; DestDir: "GetDirectoryFromIni"; \
    Flags: ignoreversion

The basic logic is if the user has changed the "Default_Path" from a previous installation I want to adjust to use it, otherwise it uses the default path when the program is first installed.

I cannot seem to define or set a string variable to use the GetDirectoryFromIni result. Can anyone help?

Upvotes: 2

Views: 498

Answers (2)

Martin Prikryl
Martin Prikryl

Reputation: 202088

You can do this even without any Pascal Script code. There's {ini} "constant":

[Files]
Source: "C:\Source_Directory\*.*"; \
  DestDir: "{ini:{app}\my_ini_file.ini,Directories,Name|{app}\Default_Path\}"; \
  Flags: ignoreversion

For an answer for your expected solution, see:
Using global string script variable in Run or other section in Inno Setup

Upvotes: 1

Some1Else
Some1Else

Reputation: 795

You need to refer to the function in the [Files] section like

[Files]
Source: "C:\Source_Directory\*.*"; DestDir: "{code:GetDirectoryFromIni}"; Flags: ignoreversion

Then it works.

Upvotes: 0

Related Questions