2016-03-08 177 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

我以爲你說它是無意義的,這就是爲什麼我刪除它 –