Inno Setup根据所选组件更改AppName [英] Inno Setup Change AppName based on component(s) selected

查看:101
本文介绍了Inno Setup根据所选组件更改AppName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要安装程序根据(未选择)组件显示不同的AppName.我试过了:

I need the installer to show different AppName based on (un)selected components. I tried this:

[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;

但是,您可能会猜到,这是行不通的.这个脚本是不完整的还是应该以完全不同的方式完成?

But, as you can guess, this doesn't work. Is this script incomplete or should it be done in a different way altogether?

推荐答案

指令值在

The AppName directive value is resolved (= your GetAppName is called) immediately after the InitializeSetup (if any) finishes. That is a long before the user is able to change the components.

因此您不能使AppName依赖于所选组件.

So you cannot make AppName depend on the selected components.

虽然AppName的某些用法可以用自定义值覆盖,但不是全部. 请参见下文.

Some uses of the AppName could be overridden with a custom value though, but not all. See below.

但是,据我所知,您的问题实际上是关于设置类型的,您可以执行以下操作:

Though, as I know that your question is actually about a setup type, you can do this:

  • 创建自定义类型"页面(如菜单)作为第一个页面.
  • 用户选择类型"后,请使用自定义开关(例如/APPTYPE=slasher)重新启动安装程序并退出.
  • 一旦安装程序与/APPTYPE(重新)运行,您便会从一开始就知道要安装的组件/类型,因此可以正常设置AppName.
  • 当然,您会跳过自定义的类型"页面.
  • Create custom "type" page (like a menu) as the very first one.
  • Once the user selects the "type", restart the installer with a custom switch (e.g. /APPTYPE=slasher) and exit.
  • Once the installer is (re-)run with the /APPTYPE, you know from the beginning, what component/type you are installing and hence you can set the AppName normally.
  • Of course, you skip the custom "type" page.

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

This is actually a way simpler to implement. The only drawback is that the setup window is "recreated" after the user selects the "type".

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

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

First, your implementation of the GetAppName is wrong. You are using an uninitialized variable CurPageID. And anyway, as mentioned already, the GetAppName is called even before the wizard window is created, so "current page" is irrelevant here.

正确的实现方式是:

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指令中工作.稍后我们将在其他情况下使用它.

But this still won't make it working in the AppName directive. We will use it in other contexts though later.

还请注意,对于您的特定安装程序,您最好使用

Also note that for your specific installer, you should better use the WizardSetupType(false) function instead of the IsComponentSelected.

完成标签

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

Just override the Inno Setup default text in CurPageChanged(wpFinished):

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;


添加/删除程序

那很容易.为此,有一个 UninstallDisplayName指令,只有在实际情况下才能解决该问题.安装时,我们已经知道所选的组件.因此,我们可以在此处使用您的(固定)GetAppName:

That's easy. There's the UninstallDisplayName directive for this, which is resolved only during the actual installation, when we already know the selected components. So we can use your (fixed) GetAppName here:

[Setup]
UninstallDisplayName={code:GetAppName}


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


Are you sure you want to completely remove AppName and all of its components?

您无法更改.您最好在AppName中使用一些通用名称,以便此消息适用于任何组件.

You cannot change that. You better use some generic name in the AppName so that this message works for any component.

或者让该消息根本不提及应用程序名称:

Or make the message not mention the application name at all:

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

或者完全删除该消息:
在Inno Setup中替换或自定义模式卸载窗口

Alternatively remove the message completely:
Replace or customize modal uninstallation windows in Inno Setup

请等待从计算机中删除AppName

Please wait while AppName is removed from your computer

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

The same solution as for the WizardForm.FinishedLabel. Just use the UninstallProgressForm.PageDescriptionLabel from the InitializeUninstallProgressForm.

AppName已成功从计算机中删除

AppName was successfully removed from your computer

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

Similar as with the "Are you sure you want to completely remove AppName and all of its components?"

要么使AppName通用.或以静音"模式禁用该消息,并在 CurUninstallStepChanged(usPostUninstall) . 再次,请参见在Inno Setup中替换或自定义模式卸载窗口.

Either make the AppName generic. Or disable the message with "silent" mode and implement your own message in the CurUninstallStepChanged(usPostUninstall). Again, see Replace or customize modal uninstallation windows in Inno Setup.

有关类似的讨论,另请参见根据Inno Setup中的语言更改AppName和AppDir.

For a similar discussion, see also Changing AppName and AppDir depending on language in Inno Setup.

这篇关于Inno Setup根据所选组件更改AppName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆