2016-12-02 100 views
1

我想在卸載過程中顯示一個對話框或消息框(帶有是或否按鈕)。
我需要從我的對話框(是(true)或否(false))中設置用戶選擇的屬性。
此屬性非常重要,因爲如果用戶的回答爲「是」,所有文件都將被刪除。
我試圖顯示卸載時的自定義對話框,並沒有奏效。自定義對話框沒有給我一個錯誤。它甚至不出現在詳細日誌中。如何在WiX卸載時顯示對話框或消息框?

這裏是自定義對話框:

<Dialog Id="ClearAllDataDlg" Width="260" Height="85" Title="[Setup] - [ProductName]" NoMinimize="yes"> 
    <Control Id="No" Type="PushButton" X="132" Y="57" Width="56" Height="17" Default="yes" Cancel="yes" Text="[ButtonText_No]"> 
     <Publish Property="CLEARALLDATA" Value="0" /> 
     <Publish Event="EndDialog" Value="Return">1</Publish> 
    </Control> 
    <Control Id="Yes" Type="PushButton" X="72" Y="57" Width="56" Height="17" Text="[ButtonText_Yes]"> 
     <Publish Property="CLEARALLDATA" Value="1" /> 
     <Publish Event="EndDialog" Value="Exit">1</Publish> 
    </Control> 
    <Control Id="Text" Type="Text" X="48" Y="15" Width="194" Height="30"> 
     <Text>Do yo want to clear all data including your settings?</Text> 
    </Control> 
    <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Information icon" FixedSize="yes" IconSize="32" Text="[InfoIcon]" /> 
    </Dialog> 

和InstallUISequence:

<Show Dialog="ClearAllDataDlg" Before="CostFinalize">REMOVE ~= "ALL"</Show> 

我試過後的序列= 「MigrateFeatureStates」,但也不能工作。
在另一個問題有人問Stopping display of custom dialog boxes in WiX uninstall這很有趣,因爲所有其他問題都試圖做到相反。
我不想在自定義操作中執行此操作,因爲我想阻止卸載進度並等待用戶的答案。
有什麼辦法可以做到這一點?
任何幫助,將不勝感激。謝謝!

回答

2

我正是在我們生產的SDK安裝中做到這一點。這個想法是,如果用戶在SDK安裝位置內進行了任何實際的開發,所有的東西都會被刪除,我們希望確保它們保存了他們真正需要的東西。

我沒有爲這個警告框創建一個新的對話框,因爲消息框在所有的Windows產品中都是一個非常明確定義和使用的概念。

在產品中,我在之前添加了一項自定義操作,計劃爲任何實際發生的事情。

<CustomAction Id='CA_UninstallWarning' BinaryKey='SDKCustomActionsDLL' DllEntry='UninstallWarning' Execute='immediate' Return='check' /> 

<InstallExecuteSequence> 
    <Custom Action='CA_UninstallWarning' Before='FindRelatedProducts'>NOT UPGRADINGPRODUCTCODE AND REMOVE~="ALL"</Custom> 
    ... 
</InstallExecuteSequence> 

而在我的自定義操作我有

[CustomAction] 
public static ActionResult UninstallWarning(Session session) 
{ 
    session.Log("Begin UninstallWarning."); 

    Record record = new Record(); 
    record.FormatString = session["WarningText"]; 

    MessageResult msgRes = session.Message(InstallMessage.Warning | (InstallMessage)System.Windows.Forms.MessageBoxButtons.OKCancel, record); 

    session.Log("End UninstallWarning."); 

    if (msgRes == MessageResult.OK) 
    { 
     return ActionResult.Success; 
    } 

    return ActionResult.Failure; 
} 

在你的情況,你可以在你的自定義操作使用messageboxbuttons.YesNo的艾伯塔省代替

隨着return="check",安裝將停止,如果你從自定義操作返回ActionResult.Failure。

我確實從wix bootstrapper啓動了這個卸載,但行爲應該是相同的。

+2

謝謝你的回答。我試過你的方式,它的工作。我使用MessageBoxButtons.YesNo並根據用戶的選擇設置屬性。它可以阻止卸載進程,並等待答案,這是驚人的。 **注意:**如果您使用C#自定義操作項目,請不要忘記將.CA.dll文件引用到Product.wxs中的二進制表。 **另一個注意事項:**如果您使用System.Windows.Forms,那麼您必須使用.NET Framework(最低支持版本爲1.0),所以請記住,這將**不運行在沒有.NET Framework的操作系統上。 –