2016-12-02 127 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的操作系统上。 –