完成某个页面后,有没有办法在 Inno Setup 中提取 .zip 文件?

3 inno-setup

所以我的目录中基本上有一个 .zip 文件{tmp},并且想要提取它的内容,{tmp}但只有当我的第三种形式完成它的工作时,而不是更早。原因是:因为在第三种形式中,我从互联网上下载了这个 .zip 并将其保存到 .zip 文件中{tmp}。现在,在此之后,我想将这些文件提取到{tmp}其中,以便从提取的文件夹中获取文件,例如发行说明、许可协议文件,以便在安装程序的其余表单中使用。意思是,已经在第三个之后的形式中,我正在使用提取的文件。

在某种形式之后,我无法在任何地方找到如何执行此操作。我只在运行部分找到了如何完成提取。

And*_*eev 7

编辑:我描述的旧方法被证明在某些 Windows 版本上不能很好地工作。它可能会弹出一个对话窗口而不是静默覆盖文件。这很容易谷歌:CopyHere 忽略 options

新方式:

新方式使用7zip 独立控制台版本。它是一个单一的7za.exe,您不需要 DLL。

#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;
Run Code Online (Sandbox Code Playgroud)

如果您想在安装开始前下载、解压和使用文件(例如,作为许可协议),我只能给出一般指导:

  1. [Setup]: 中启用欢迎页面DisableWelcomePage=no
  2. 使用idpDownloadAfter(wpWelcome);. 现在它会在“欢迎”页面之后立即下载。
  3. 您需要一个空的许可证文件[Setup]:LicenseFile=license.txt才能显示许可证页面。或者可能不是空的,而是带有“正在加载许可协议...”文本。
  4. 你实现procedure CurPageChanged():如果当前页面是wpLicense那么你调用Exec()函数来启动 7zip 并等待它终止。[Run]现在部分没有 7zip 。然后您可能使用LoadStringFromFile()函数从提取的文件中获取许可协议。然后把它放到UI中。可能WizardForm.LicenseMemo.RTFText = ...应该工作。无论如何,UI 是可访问的,如果您在设置文本时遇到问题,请就此单独提出问题。

老车方式

等效,更清洁的方式不unzipper.dll这里描述。一种或另一种方式,它使用有缺陷的CopyHere Windows 功能。

#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;
Run Code Online (Sandbox Code Playgroud)

您可能可以尝试其他方法而不是wpReadyssPostInstall。对于我的小拉链,这很管用。