3

So I basically have a .zip file in my {tmp} directory, and want to extract it's contents in {tmp} but only when my third form is done with it's work, not earlier. The reason is: Because in the third form I download this .zip from the internet and it is saved into {tmp}. Now after this I want to extract these files into {tmp} from which I am to get the files from the extracted folders, like the release notes, license agreement files to use in the rest of the forms in the installer. Meaning, already in the form after the third one, I am using the files extracted.

I can't find anywhere how to do this after a certain form. I only found in the run section how extracting is done.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Please, show what you have. Edit your post and add the relevant part of your Inno Setup script, and let us know what plugins you use. – Andrey Moiseev Nov 20 '16 at 13:28
  • I will have to do that on monday, because i do not have that PC with me before that. I don't have any plugins for extracting, just downloading over the internet. –  Nov 20 '16 at 13:35

1 Answers1

8

EDIT: The old way I described proved not to work well on some Windows versions. It may pop up a dialog window instead of overwriting files silently. This is easy to google: CopyHere ignores options.

The new way:

The new way uses 7zip standalone console version. It is a single 7za.exe, you don't need the DLLs.

#include <idp.iss>

; Languages section
; Includes for Mitrich plugin's additional languages
; #include <idplang\Russian.iss>

[Files]
Source: "7za.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall;

[Run]
Filename: {tmp}\7za.exe; Parameters: "x ""{tmp}\example.zip"" -o""{app}\"" * -r -aoa"; Flags: runhidden runascurrentuser;

[Code]
procedure InitializeWizard;
begin
  idpAddFile('https://example.comt/example.zip', ExpandConstant('{tmp}\example.zip'));
  { Download after "Ready" wizard page }
  idpDownloadAfter(wpReady);
end;

If you want to download, unzip and use files (for example, as license agreement) before the installation starts, I can only give the general guideline:

  1. Enable welcome page in [Setup]: DisableWelcomePage=no.
  2. Use idpDownloadAfter(wpWelcome);. Now it downloads right after "Welcome" page.
  3. You need an empty license file in [Setup]: LicenseFile=license.txt for license page to show up. Or probably not empty, but with "Loading license agreement..." text.
  4. You implement procedure CurPageChanged(): if current page is wpLicense then you call Exec() function to launch 7zip and wait for it to terminate. No 7zip in [Run] section now. Then you probably use LoadStringFromFile() function to get license agreement from extracted file. Then put it into UI. Probably WizardForm.LicenseMemo.RTFText = ... should work. Anyway, UI is accessible, if you have trouble setting the text, ask a separate question on this.

The old buggy way:

An equivalent, cleaner way without unzipper.dll is described here. One way or another, it uses buggy CopyHere Windows feature.

#include <idp.iss>

; Languages section
; Includes for Mitrich plugin's additional languages
; #include <idplang\Russian.iss>

[Files]
Source: "unzipper.dll"; Flags: dontcopy

[Code]
procedure InitializeWizard;
begin
  idpAddFile('https://example.comt/example.zip', ExpandConstant('{tmp}\example.zip'));
  { Download after "Ready" wizard page }
  idpDownloadAfter(wpReady);
end;

procedure unzip(src, target: AnsiString);
external 'unzip@files:unzipper.dll stdcall delayload';

procedure ExtractMe(src, target : AnsiString);
begin
  unzip(ExpandConstant(src), ExpandConstant(target));
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then 
  begin
    { Extract when "Finishing installation" setup step is being performed. }
    { Extraction crashes if the output dir does not exist. }
    { If so, create it first: }
    { CreateDir(ExpandConstant(...)); }
    ExtractMe('{tmp}\example.zip', '{app}\');
  end;
end;

You can probably try other things instead of wpReady and ssPostInstall. For my small zip this works well.

Community
  • 1
  • 1
Andrey Moiseev
  • 3,914
  • 7
  • 48
  • 64
  • 1
    Note that using the `unzipper.dll` is an overkill. You can implement the same using a native Pascal Script code. See [How to get Inno Setup to unzip a file it installed (all as part of the one installation process)](http://stackoverflow.com/a/40706549/850848). – Martin Prikryl Nov 20 '16 at 16:39
  • @MartinPrikryl That's good, thank you. I'll check it out and edit my answer if it works well. – Andrey Moiseev Nov 20 '16 at 17:23
  • 1
    @MartinPrikryl I found out `CopyHere` may ignore the options on some Windows versions. I updated my answer, now I simply use 7zip. – Andrey Moiseev Nov 20 '16 at 20:27
  • The flags work on Windows Vista and newer. I've added this to my answer. – Martin Prikryl Nov 21 '16 at 09:09
  • In this new way, how do you know that it is unzipped after it is downloaded? –  Nov 21 '16 at 11:01
  • @HeraldJones The download is performed immediately after the `wpReady` page. Unzipping is in the `[Run]` section, which is executed as a part of installation, I believe, it's `wpInstalling` page. Anyway, I've tested it and it works as is. – Andrey Moiseev Nov 21 '16 at 11:41
  • I need the unzipping to take place before the installing, before the license agreement. This is because i get the license agreement from the extracted zip... How do I do this? –  Nov 21 '16 at 11:56
  • @HeraldJones I've updated the answer, right below the new solution. I do not have exact code for your tricky scenario, but I have some general steps. – Andrey Moiseev Nov 21 '16 at 13:21
  • 1
    Make sure you add double quotes around the `{tmp}` and `{app}` in `7za.exe` parameters. – Martin Prikryl Nov 24 '16 at 14:26