2016-03-08 185 views
1

我需要安装程序根据(未)选定的组件显示不同的AppName。我试过这个:Inno Setup根据所选组件更改AppName

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

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

+0

窗口标题 - 不要紧, FinishedLabel - 最好, 整个卸载过程 - 应该改变, 添加/删除程序 - 应改为 –

回答

2

The AppName directivethe 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 InitializeUninstallProgressFormUninstallProgressForm.PageDescriptionLabel


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

类似与“你确定要完全删除AppName和它的所有组件?”

要么使AppName通用。或者用“无声”模式禁用消息并在the CurUninstallStepChanged(usPostUninstall)中实现您自己的消息。


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

+0

现在我会尝试这一权利。至于卸载过程,我需要“你确定要彻底删除.....“消息”,请等待从应用程序中删除“AppName”(PageDescriptionLabel),“卸载AppName ...”(StatusLabel),“AppName已成功从您的计算机中删除”,如果可能,卸载窗口标题 –

+0

也要感谢WizardSetupType上的提示,正如我之前所说的,我通常不使用类型,所以我甚至不知道这个, –

+0

我以为你说它是无意义的,这就是为什么我删除它 –