0

I'm trying to extract a file using 7zip in the [Codes] section as I want to extract before any files get copied by the [Files] section.

With the code below I am not getting it, I tried and changed it, but it appears that The system cannot find the specified file

Am I doing something wrong?

[Files]

// Copy 7za.exe to {tmp} folder
Source: "tools\7zip\7za.exe"; DestDir: "{tmp}\7zip"; Flags: deleteafterinstall;

Source: "{tmp}\launchers\Launcher1"; DestDir: "{app}"; Flags: onlyifdoesntexist external; BeforeInstall: ExtractLauncher
Source: "{tmp}\launchers\Launcher2"; DestDir: "{app}"; Flags: onlyifdoesntexist external; BeforeInstall: ExtractLauncher

// --------------------------- Extract Launcher --------------------------- \\

[Code]
var
 ResultCode: integer;

procedure ExtractLauncher();
begin                                                                               
  Exec(ExpandConstant('{tmp}\7zip\7za.exe'), 'x "{tmp}\launchers\launcher.zip" -o"{tmp}\launchers" * -r -aoa', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) 
  MsgBox(SysErrorMessage(ResultCode), mbError, MB_OK);
end;

The launcher.zip file is downloaded during installation to the {tmp}\launchers folder

I kept looking at the {tmp} folder, and the launcher.zip file and 7za.exe are created before running my [Codes], I did this to make sure they were there when run the code. And yes, they were there before running the code.

1 Answers1

0

Thanks to Martin's Prikryl comment, I just added ExpandConstant to the rest of the command line and the code worked!

It was like this:

[Files]

// Copy 7za.exe to {tmp} folder
Source: "tools\7zip\7za.exe"; DestDir: "{tmp}\7zip"; Flags: deleteafterinstall;

Source: "{tmp}\launchers\Launcher1"; DestDir: "{app}"; Flags: onlyifdoesntexist external; BeforeInstall: ExtractLauncher
Source: "{tmp}\launchers\Launcher2"; DestDir: "{app}"; Flags: onlyifdoesntexist external; BeforeInstall: ExtractLauncher

// --------------------------- Extract Launcher ---------------------------

[Code]
var
 ResultCode: integer;

procedure ExtractLauncher();
begin                                                                               
  Exec(ExpandConstant('{tmp}\7zip\7za.exe'), ' x ' + ExpandConstant('{tmp}\launchers\launcher.zip') + ' -o' + ExpandConstant('{tmp}\launchers') + ' * -r -aoa', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) 
  MsgBox(SysErrorMessage(ResultCode), mbError, MB_OK);
end;
  • 1
    Glad it helped. Though next time you get solution, allow the one who suggested it, to post his/hers answer, instead of re-posting it yourself. – Martin Prikryl Feb 09 '22 at 21:15
  • 1
    I'm sorry, I'll remove it for you to post it! :) – faelBrunnoS Feb 10 '22 at 12:50
  • 1
    @MartinPrikryl in fairness to the OP, you did have the opportunity to post an answer instead of just leaving a comment. (Not that your point is invalid in general, and its a a good thing to mention to a newer user.) – StayOnTarget Feb 10 '22 at 16:15