【问题标题】:Conditional file copy in Inno SetupInno Setup 中的条件文件复制
【发布时间】:2017-01-15 10:11:31
【问题描述】:

我想进行有条件的文件复制/安装,具体取决于{app} 位置的给定 .cfg(文本)文件中的内容。该文件中包含一个 URL,该 URL 如下所示:“update.website.eu”,或者这个“update.website.com”,或者“update.worldoftanks.kr”,但也可以是“update.worldoftanks.kr/ "等等,有几种可能。所以我需要一种机制来检测 url 并让我为每个检测到的 url 安装不同的文件。

目前我有这样的例子,但我不是高级程序员(我只是或多或少知道一些基础知识),我需要一个很好的例子。

if (CurPageID = wpPreparing) then
begin
  client_ver :=
    LoadValueFromXML(ExpandConstant('{app}\file.cfg'),
    '//info/patch_info_urls/item');
  if client_ver = 'http://update.website.eu/' then
    if MsgBox('Are you sure?', mbConfirmation, MB_OKCANCEL) = IDCANCEL then
      Result:=False;
end;

file.cfg 的示例:

<?xml version="1.0" encoding="UTF-8"?>
<info version="3.1">
    <!-- ... -->
    <patch_info_urls>
        <item>http://update.website.eu/</item>
    </patch_info_urls>
</info>

无论如何我想在[Files] 部分使用它,是否可以从那里触发它,调用[Files] 中的过程或其他东西?

我尝试了几次,但在编译过程中总是给我一些不匹配的错误。

ps。忽略MsgBox,这只是示例,我不会显示类似的内容。我只需要复制文件。

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:

    使用Check parameter

    [Files]
    Source: "file_for_url1"; DestDir: "{app}"; Check: IsURl1
    Source: "file_for_url2"; DestDir: "{app}"; Check: IsURl2
    
    [Code]
    
    var
      ClientVer: string;
    
    procedure CurStepChanged(CurStep: TSetupStep);
    begin
      if CurStep = ssInstall then
      begin
        ClientVer :=
          LoadValueFromXML(ExpandConstant('{app}\file.cfg'), 
          '//info/patch_info_urls/item');
        Log(Format('Client version is %s', [ClientVer]));
      end;
    end;
    
    function IsUrl1: Boolean;
    begin
      Result := (ClientVer = 'http://update.website.eu/');
    end;
    
    function IsUrl2: Boolean;
    begin
      Result := (ClientVer = 'http://update.website.com/');
    end;
    

    【讨论】:

    • 认为这个问题已经解决了。我已经优化了我的代码,现在可以编译了。
    猜你喜欢
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2019-09-19
    • 2014-12-19
    • 1970-01-01
    • 2012-09-19
    相关资源
    最近更新 更多