Inno Setup:如何在 InitializeWizard 中使用 {app}?

Inno Setup: how to use {app} in InitializeWizard?

我知道 this question was asked before 的标题几乎相同。但是答案没有为我提供足够的信息来解决问题。我的问题也有点不同。

我正在使用Inno Download Plugin

我的来源看起来像

[Components]
Name: "dl";           Description: "{cm:DLMessage}";  Types: full fullService
Name: "dl\aaa";       Description: "aaa111";          Types: full fullService;
Name: "dl\bbb";       Description: "bbb222";          Types: full fullService;
Name: "dl\ccc";       Description: "ccc333";          Types: full fullService;

[Code]
procedure InitializeWizard();
begin
    idpAddFileComp('ftp://user:pass@server.xy/folder/myFile1.exe', ExpandConstant('{app}\subfolder\Download\myFile1.exe'), 'dl\aaa');
    idpAddFileComp('ftp://user:pass@server.xy/folder/myFile2.exe', ExpandConstant('{app}\subfolder\Download\myFile2.exe'), 'dl\bbb');
    idpAddFileComp('ftp://user:pass@server.xy/folder/myFile3.exe', ExpandConstant('{app}\subfolder\Download\myFile3.exe'), 'dl\ccc');
    idpDownloadAfter(wpReady);
end;

我想要实现的是根据对组件所做的选择下载一些文件。

由于我对 inno 比较陌生...答案

Prototype:

function WizardDirValue: String;

对我说同样的话,就像你试着告诉牙医如何修理汽车:)

我想在 InitializeWizard 中使用 {app},但我不知道如何使用,即使给定 "hint"。任何人都可以向我解释这个吗? (Google 并没有真正帮助我)

InitializeWizard 事件方法在创建向导表单后立即触发,因此将 {app} 目录传递给插件还为时过早(WizardDirValue 函数会做一样),因为用户还没有通过目录输入页面。您需要将代码移动到用户选择目录后触发的事件中。

试试这样的方法:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
procedure InitializeWizard;
begin
  // only tell the plugin when we want to start downloading
  idpDownloadAfter(wpReady);
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  // if the user just reached the ready page, then...
  if CurPageID = wpReady then
  begin
    // because the user can move back and forth in the wizard, this code branch can
    // be executed multiple times, so we need to clear the file list first
    idpClearFiles;
    // and add the files to the list; at this time, the {app} directory is known
    idpAddFileComp('ftp://user:pass@server.xy/folder/myFile1.exe', ExpandConstant('{app}\subfolder\Download\myFile1.exe'), 'dl\aaa');
    idpAddFileComp('ftp://user:pass@server.xy/folder/myFile2.exe', ExpandConstant('{app}\subfolder\Download\myFile2.exe'), 'dl\bbb');
    idpAddFileComp('ftp://user:pass@server.xy/folder/myFile3.exe', ExpandConstant('{app}\subfolder\Download\myFile3.exe'), 'dl\ccc');
  end;
end;