Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we specify the path in ExtractTemporaryFiles function in Inno Setup?

I've been reading through Inno Setup documentation and got confused about why do we specify the path in ExtractTemporaryFiles function if according to the documentation it extracts the files matching the wildcard specified by Pattern from the [Files] section to a temporary directory.? If we have this Source: "Readme.txt"; Flags: dontcopy in the [Files] section why do we type ExtractTemporaryFiles('{tmp}\Readme.txt') in the [Code] section? Is that a mistake or I just don't understand how this function works? The same applies to the ExtractTemporaryFile procedure.

Here's the code from ExtractTemporyFile page:

[Files]
Source: "Readme.txt"; Flags: dontcopy noencryption

[Code]
function InitializeSetup: Boolean;
var
  S: AnsiString;
begin
  // Show the contents of Readme.txt (non Unicode) in a message box
  ExtractTemporaryFile('Readme.txt');
  if LoadStringFromFile(ExpandConstant('{tmp}\Readme.txt'), S) then
  begin
    MsgBox(S, mbInformation, MB_OK);
  end;

  Result := True;
end;

And here's the code from ExtractTemporaryFiles page:

[Files]
Source: "Readme.txt"; Flags: dontcopy
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"

[Code]
function InitializeSetup: Boolean;
var
  S: AnsiString;
  ResultCode: Integer;
begin
  // Show the contents of Readme.txt (non Unicode) in a message box
  ExtractTemporaryFiles('{tmp}\Readme.txt');
  if LoadStringFromFile(ExpandConstant('{tmp}\Readme.txt'), S) then
  begin
    MsgBox(S, mbInformation, MB_OK);
  end;

  // Extract all MyProg files and launch it. Note how {app} is left unexpanded.
  ExtractTemporaryFiles('{app}\MyProg.*');
  ExecAsOriginalUser(ExpandConstant('{tmp}\')+'{app}\MyProg.exe', '', '',
    SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);

  Result := True;
end;

In the first case we have:

[Files]
Source: "Readme.txt"; Flags: dontcopy noencryption
[Code]
ExtractTemporaryFile('Readme.txt');

And in the second one we have:

[Files]
Source: "Readme.txt"; Flags: dontcopy
[Code]
ExtractTemporaryFiles('{tmp}\Readme.txt');

What's the difference between those two? (noencryption flag does not count) Why do we need to specify the {tmp} constant in the second case if we already extracting from there? In order to be able to use those methods correctly I need to have a clear understanding of the syntax.

like image 801
JConstantine Avatar asked Sep 14 '25 03:09

JConstantine


1 Answers

With ExtractTemporaryFiles (contrary to ExtractTemporaryFile), you need to use the full value of the DestDir parameter (in addition to the filename) to select the correct copy of the file, in case there are multiple files with the same name in the installer. On the contrary, ExtractTemporaryFile will always extract the first file with the given name.

So having this:

[Files]
Source: "one\readme.txt"; DestDir: "{app}\one"
Source: "two\readme.txt"; DestDir: "{app}\two"
Source: "three\readme.txt"; Flags: dontcopy
  • To extract the one\readme.txt, use: ExtractTemporaryFiles('{app}\one\readme.txt')
  • To extract the two\readme.txt, use: ExtractTemporaryFiles('{app}\two\readme.txt')
  • To extract the three\readme.txt, use: ExtractTemporaryFiles('{tmp}\readme.txt')
    (Flags: dontcopy implies DestDir: {tmp} for some reason)
like image 159
Martin Prikryl Avatar answered Sep 16 '25 22:09

Martin Prikryl