Inno Setup根据所选组件更改AppName

时间:2016-03-08 07:14:40

标签: inno-setup pascalscript

我需要安装程序根据(未)选定的组件显示不同的[Setup] AppName={code:GetAppName} AppVersion=1.0 AppVerName=Dagon Video Tools AppId=Dagon Video Tools DefaultDirName={sd}\Games\Dagon Video Tools [Code] function GetAppName(Value: string): string; var CurPageID: Integer; Begin Result := 'Dagon Video Tools' if (CurPageID=wpSelectComponents) and IsComponentSelected('Slasher') and not IsComponentSelected('Frankenstein') then begin Result := 'Dagon Slasher'; end; if (CurPageID=wpSelectComponents) and IsComponentSelected('Frankenstein') and not IsComponentSelected('Slasher') then begin Result := 'Dagon Frankenstein'; end; if (CurPageID=wpSelectComponents) and IsComponentSelected('Slasher') and IsComponentSelected('Frankenstein') then begin Result := 'Dagon Video Tools'; end; End; 。我试过这个:

pyinstaller --onefile --windowed gui_app.py

但是,正如你猜测的那样,这不起作用。这个脚本是不完整的还是应该以完全不同的方式完成?

1 个答案:

答案 0 :(得分:2)

The AppName directive(如果有)完成后立即解析

the InitializeSetup值(= GetAppName被调用)。在用户能够更改组件之前很久。

因此,您无法使AppName依赖于所选组件。

AppName的某些用法可以用自定义值覆盖,但不是全部。 见下文。

虽然我知道您的问题实际上是关于设置类型的,但您可以这样做:

  • 创建自定义"输入"页面(如菜单)作为第一个。
  • 用户选择"键入"后,使用自定义切换(例如/APPTYPE=slasher)重新启动安装程序并退出。
  • 使用/APPTYPE(重新)运行安装程序后,您从一开始就知道要安装的组件/类型,因此您可以正常设置AppName
  • 当然,您跳过自定义"类型"页。

这实际上是一种更简单的实现方式。唯一的缺点是设置窗口被重新创建"在用户选择"类型"。

之后

如果您不想使用上述解决方案,这是原始回复。

首先,您对GetAppName的实施是错误的。您正在使用未初始化的变量CurPageID。无论如何,如前所述,甚至在创建向导窗口之前就会调用GetAppName,因此"当前页面"这里无关紧要。

正确的实施方式如下:

function GetAppName(Value: string): string;
begin
  if IsComponentSelected('Slasher') and not IsComponentSelected('Frankenstein') then
  begin
    Result := 'Dagon Slasher';
  end
    else
  if IsComponentSelected('Frankenstein') and not IsComponentSelected('Slasher') then
  begin
    Result := 'Dagon Frankenstein';
  end
    else
  begin
    Result := 'Dagon Video Tools';
  end;
end;

但是这仍然不能使它在AppName指令中运行。我们稍后会在其他情况下使用它。

另请注意,对于your specific installer,您最好使用the WizardSetupType(false) function代替IsComponentSelected

<强> FinishedLabel

只需覆盖CurPageChanged(wpFinished)中的Inno Setup默认文字:

procedure CurPageChanged(CurPageID: Integer);
var
  S: string;
begin
  if CurPageID = wpFinished then
  begin
    S := SetupMessage(msgFinishedHeadingLabel);
    StringChange(S, '[name]', GetAppName(''));
    WizardForm.FinishedHeadingLabel.Caption := S;
    WizardForm.AdjustLabelHeight(WizardForm.FinishedHeadingLabel);
    { Ideally we should shift the FinishedLabel up or down here, }
    { if the height of the header changed. }

    { Note that other messages (msgFinishedLabelNoIcons or msgFinishedRestartLabel) }
    { are used in special situations, so this is not a complete solution. }
    S := SetupMessage(msgFinishedLabel);
    StringChange(S, '[name]', GetAppName(''));
    WizardForm.FinishedLabel.Caption := S;
    WizardForm.AdjustLabelHeight(WizardForm.FinishedLabel);
  end;
end;

添加/删除程序

这很容易。对此有the UninstallDisplayName directive,只有在我们已经知道所选组件的实际安装过程中才会解决这个问题。所以我们可以在这里使用您的(固定)GetAppName

[Setup]
UninstallDisplayName={code:GetAppName}

您确定要完全删除AppName及其所有组件吗?

你不能改变它。您最好在AppName中使用一些通用名称,以便此消息适用于任何组件。

或者根本不提及应用程序名称:

[Messages]
ConfirmUninstall=Are you sure you want to completely remove this game?

或者完全删除该消息:
Can I disable uninstall confirmation message?
并可选择将其替换为您在the InitializeUninstall event function中实现的消息。

请等待从计算机中删除AppName

WizardForm.FinishedLabel相同的解决方案。只需使用the InitializeUninstallProgressForm中的UninstallProgressForm.PageDescriptionLabel

AppName已成功从您的计算机中删除

&#34类似;您确定要完全删除AppName及其所有组件吗?&#34;

使AppName通用。或者使用&#34; silent&#34;禁用该消息。模式并在the CurUninstallStepChanged(usPostUninstall)中实现您自己的消息。

有关类似的讨论,另请参阅Changing AppName and AppDir depending on language in Inno Setup

相关问题