仅当用户选择使用Inno Setup下载文件时 [英] Downloading file with Inno Setup only when user chooses to
问题描述
问题:我想知道如何编写脚本来下载第二个文件,即zip,但最初是在两个zip文件之间进行选择;下载,解压缩并删除该zip.每个zip文件都具有不同的名称,但是内容与zips具有不同的名称(每个名称都相同);无需重命名.这个问题有点类似于在inno-setup中应用下载文件条件
Question: I’d like to know how to script to download a second file which is a zip but initially give a choice between two zip files; download, unzip and delete the zip. The zip files each have different names but the contents have a different name to the zips (each the same name); no renaming required. This question is a little similar to Apply Download file condition in inno-setup
有问题的文件是通过SourceForge网站下载的.这些文件专用的程序(克隆)未在SF上列出或用途已更改.
The files in question are downloaded via the SourceForge website. The programs (clones) these files are intended for are either not listed on SF or have changed purpose.
修复了PChar
错误之后: InnoTools Downloader无法使用Inno 5.5 现在,我可以重用2011年以来的这个Inno Setup脚本,但希望对其进行一些扩展,但仍需努力.
After fixing the PChar
bug: InnoTools Downloader not working with Inno 5.5 I'm now able to re-use this Inno Setup script from 2011 but want to expand it slightly but struggling to.
#include ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','ScriptPath','');
[Code]
procedure InitializeWizard();
begin
itd_init;
{ Set download source.. }
itd_addfile('http://www.example.com/Textfile.txt', ExpandConstant('{tmp}\Textfile.txt'));
itd_setoption('UI_AllowContinue','1');
itd_setoption('UI_DetailedMode','1');
{ Start the download after the "Ready to install" screen is shown }
itd_downloadafter(wpReady);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then { Lets install the downloaded files }
begin
FileCopy(ExpandConstant('{tmp}\Textfile.txt'), ExpandConstant('{userappdata}\program_name\Textfile.txt'), false);
end;
end;
基于答案的工作代码:
Working code based on the answer:
#pragma include __INCLUDE__ + ";" + "c:\lib\InnoDownloadPlugin"
[Setup]
...
CreateUninstallRegKey=no
#include <idp.iss>
...
[Types]
Name: full; Description: "Full installation"
Name: compact; Description: "Compact installation"
Name: custom; Description: "Custom installation"; Flags: iscustom
[Components]
Name: abc; Description: "C File"; Types: full compact custom; Flags: fixed
Name: hlnj; Description: "HL (Recommended)"; Types: custom; Flags: exclusive
Name: hnj; Description: "HF"; Types: custom; Flags: exclusive
[Files]
Source: "{tmp}\text.net"; DestDir: "{userappdata}\ccc"; Flags: external; Components: abc
Source: "{tmp}\HLNJ.zip"; DestDir: "{userappdata}\ccc"; Flags: external; Components: hlnj
Source: "{tmp}\HNJ.zip"; DestDir: "{userappdata}\ccc"; Flags: external; Components: hnj
[Code]
procedure InitializeWizard;
begin
idpAddFileComp('http://www.example.com/text.net', ExpandConstant('{tmp}\text.net'), 'abc');
idpAddFileComp('http://www.example.com/SecurityUpdates/HLNJ.zip', ExpandConstant('{tmp}\HLNJ.zip'), 'hlnj');
idpAddFileComp('http://www.example.com/SecurityUpdates/HNJ.zip', ExpandConstant('{tmp}\HNJ.zip'), 'hnj');
idpDownloadAfter(wpReady);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
FileCopy(ExpandConstant('{tmp}\text.net'), ExpandConstant('{userappdata}\ccc\text.net'), false);
FileCopy(ExpandConstant('{tmp}\HLNJ.zip'), ExpandConstant('{userappdata}\ccc\HLNJ.txt'), false);
FileCopy(ExpandConstant('{tmp}\HNJ.zip'), ExpandConstant('{userappdata}\ccc\HNJ.txt'), false);
end;
end;
推荐答案
仅在发布答案后,我注意到尽管您标记了问题 InnoTools下载器已死且无法维护.
Only after posting my answer, I've noticed that despite you tagging the question inno-download-plugin, you are actually using InnoTools Downloader. Do not – InnoTools Downloader is dead and unmaintained.
还请注意,即将发布的Inno Setup 6.1将具有对下载的内置支持.使用该API,该解决方案将更容易,但与IDP如下所示的解决方案有所不同.
在Inno Download Plugin安装的examples
文件夹中,有components1.iss
和components2.iss
示例.
In the examples
folder of Inno Download Plugin installation, there are components1.iss
and components2.iss
examples.
第一个示例显示了选择组件时如何使用idpAddFileComp
有条件地下载文件.
The first shows how to use idpAddFileComp
to conditionally download a file, when a component is selected.
我要重新发布一个完整的示例:
I'm re-posting a full example:
; Uncomment one of following lines, if you haven't checked "Add IDP include path to ISPPBuiltins.iss" option during IDP installation:
;#pragma include __INCLUDE__ + ";" + ReadReg(HKLM, "Software\Mitrich Software\Inno Download Plugin", "InstallDir")
;#pragma include __INCLUDE__ + ";" + "c:\lib\InnoDownloadPlugin"
[Setup]
AppName = My Program
AppVersion = 1.0
DefaultDirName = {pf}\My Program
DefaultGroupName = My Program
OutputDir = userdocs:Inno Setup Examples Output
#include <idp.iss>
[Types]
Name: full; Description: "Full installation"
Name: compact; Description: "Compact installation"
Name: custom; Description: "Custom installation"; Flags: iscustom
[Components]
Name: app; Description: "My Program"; Types: full compact custom; Flags: fixed
Name: help; Description: "Help files"; Types: full
Name: src; Description: "Source code"; Types: full
[Files]
Source: "{tmp}\app.exe"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576; Components: app
Source: "{tmp}\help.chm"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576; Components: help
Source: "{tmp}\src.zip"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576; Components: src
[Icons]
Name: "{group}\My Program"; Filename: "app.exe"; Components: app
Name: "{group}\Help file"; Filename: "help.chm"; Components: help
Name: "{group}\{cm:UninstallProgram,My Program}"; Filename: "{uninstallexe}"
[Code]
procedure InitializeWizard;
begin
idpAddFileComp('http://127.0.0.1/app.exe', ExpandConstant('{tmp}\app.exe'), 'app');
idpAddFileComp('http://127.0.0.1/help.chm', ExpandConstant('{tmp}\help.chm'), 'help');
idpAddFileComp('http://127.0.0.1/src.zip', ExpandConstant('{tmp}\src.zip'), 'src');
idpDownloadAfter(wpReady);
end;
注意事项:传递给idpAddFileComp
的组件名称必须小写(实际的组件名称可以大写).
Caveat: The component name passed to idpAddFileComp
must be in lowercase (the actual component name can use uppercase).
这篇关于仅当用户选择使用Inno Setup下载文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!