Mear1628
Mear1628

Reputation: 15

Inno Setup ExtractTemporaryFiles to specific directory

I'm new to Inno Setup, but I want to write some files to the temp directory temporarily, but in a directory structure:

tmp\App.exe
tmp\lic\readme.txt
tmp\cfg\configfile.txt

Code below is only for the tmp\lic\readme.txt file:

[Files]
Source: "\\Mac\Home\Desktop\License\Readme.txt"; Flags: dontcopy
[Code]
function InitializeSetup: Boolean;

begin
  if not DirExists(ExpandConstant('{tmp}\lic')) then
    CreateDir(ExpandConstant('{tmp}\lic'));

  ExtractTemporaryFiles('{tmp}\lic\Readme.txt');
end;

The directory lic is created but I get an error message when extracting the readme.txt file:

Exception: Internal error: ExtractTemporaryFiles: No files matching "{tmp}\lic\Readme.txt" found.

If I do not use the directory lic I do not get this error message.
Is it not possible to temporarily extract a file to a directory in the tmp folder?

Upvotes: 1

Views: 437

Answers (2)

StayOnTarget
StayOnTarget

Reputation: 12998

I think this would work... my installer does something similar. An alternative to using ExtractTemporaryFiles is to have the [Files] entries deploy to tmp yourself. Example:

[Files]
Source: "sourcefolder\*"; DestDir: "{app}"; Excludes: "sourcefolder\sometempfile"
Source: "sourcefolder\sometempfile"; DestDir: "{tmp}\somefolder"

Be mindful of the Excludes section of the second line.

Then you can refer to those temp files elsewhere in the installer, for instance:

[Run]
Filename: "{tmp}\somefolder\sometempfile"; Flags: ...

This approach may avoid scripting code entirely.

Files placed in {tmp} get cleaned up automatically:

{tmp}

Temporary directory used by Setup or Uninstall. This is not the value of the user's TEMP environment variable. It is a subdirectory of the user's temporary directory which is created by Setup or Uninstall at startup (with a name like "C:\WINDOWS\TEMP\IS-xxxxx.tmp"). All files and subdirectories in this directory are deleted when Setup or Uninstall exits. During Setup, this is primarily useful for extracting files that are to be executed in the [Run] section but aren't needed after the installation.

https://jrsoftware.org/ishelp/index.php?topic=consts

(Note that in real code I would #define folders, the the temp filename, etc. as constants and use that everywhere.)

Upvotes: 0

Martin Prikryl
Martin Prikryl

Reputation: 202098

The argument of ExtractTemporaryFiles specifies the file to extract, not the destination path. You cannot choose the destination path. The file is always extracted directly to {tmp}.

See also Extracting files with same name from installer during Inno Setup InitializeSetup


Two approaches you can try:

  • Move the file using RenameFile, after you extract it; or

  • Extract the file using [Files] section, instead of using the code.

    [Files]
    Source: "\\...\Readme.txt"; Dest: {tmp}\lic\readme.txt 
    

Upvotes: 1

Related Questions