inno-setuppascalscript

How to set my own variable in [Setup] and read it from [Code]


I'm trying to create a script in Inno Setup to pull files from a GitHub repository, extract it, and write it to a directory defined in the [Setup] section.

[Setup]
MyVariable={userappdata}\MetaQuotes\Terminal\{#MyAppName}
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
  // Copy the selected files to the selected directory
  if not FileCopy(Output + '\file1.txt', MyVariable + '\file1.txt', False) then
  begin
    MsgBox('Failed to copy file1.txt to the selected directory.', mbError, MB_OK);
    Abort();
  end;
  if not FileCopy(Output + '\file2.txt', MyVariable + '\file2.txt', False) then
  begin
    MsgBox('Failed to copy file2.txt to the selected directory.', mbError, MB_OK);
    Abort();
  end;
end;

Obviously, this won't compile because MyVariable hasn't been defined in the Pascal script. Only, I'm not sure how to reference the value in [Setup]. Or am I going about this in the wrong way?


Solution

  • Well, you can read the [Setup] section directives with SetupSetting preprocessor function:
    How to read a [Setup] parameter in the Pascal code?

    But you cannot invent your own new directives.


    But you can either: