Skip to content

Commit

Permalink
- Fixed multiple samples
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-shilo committed Feb 25, 2022
1 parent e046cc1 commit ec5e6b9
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

<Image x:Name="Banner" Grid.RowSpan="2" />
<TextBlock
x:Name="DialogTitleLabel"
Grid.RowSpan="1"
Grid.Column="1"
Margin="10,25,10,10"
Expand Down Expand Up @@ -101,8 +102,8 @@
<Button
x:Name="GoPrev"
Height="23"
IsEnabled="False"
MinWidth="73">
MinWidth="73"
IsEnabled="False">
[WixUIBack]
</Button>
<Separator Width="10" Opacity="0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,30 @@ public ExitDialog()

public void Init()
{
UpdateTitles(ManagedFormHost.Runtime.Session);
ViewModelBinder.Bind(new ExitDialogModel { Host = ManagedFormHost }, this, null);
}

/// <summary>
/// Updates the titles of the dialog depending on the success of the installation action.
/// </summary>
/// <param name="session">The session.</param>
public void UpdateTitles(ISession session)
{
if (Shell.UserInterrupted || Shell.Log.Contains("User canceled installation."))
{
DialogTitleLabel.Text = "[UserExitTitle]";
DialogDescription.Text = "[UserExitDescription1]";
}
else if (Shell.ErrorDetected)
{
DialogTitleLabel.Text = "[FatalErrorTitle]";
DialogDescription.Text = Shell.CustomErrorDescription ?? "[FatalErrorDescription1]";
}

// `Localize` resolves [...] titles and descriptions into the localized strings stored in MSI resources tables
this.Localize();
}
}

public class ExitDialogModel : Caliburn.Micro.Screen
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Windows.Media.Imaging;
using Caliburn.Micro;
using WixSharp;
using WixSharp.UI.Forms;

using IO = System.IO;

namespace WixSharp.UI.WPF.Sequence
{
public partial class MaintenanceTypeDialog : WpfDialog, IWpfDialog
{
public MaintenanceTypeDialog()
{
InitializeComponent();
}

public void Init()
{
ViewModelBinder.Bind(new MaintenanceTypeDialogModel { Host = ManagedFormHost, }, this, null);
}
}

public class MaintenanceTypeDialogModel : Caliburn.Micro.Screen
{
public ManagedForm Host;

ISession session => Host?.Runtime.Session;
IManagedUIShell shell => Host?.Shell;

public BitmapImage Banner => session?.GetResourceBitmap("WixUI_Bmp_Banner").ToImageSource();

void JumpToProgressDialog()
{
int index = shell.Dialogs.IndexOfDialogImplementing<IProgressDialog>();
if (index != -1)
shell.GoTo(index);
else
shell.GoNext(); // if user did not supply progress dialog then simply go next
}

public void Change()
{
if (session != null)
{
session["MODIFY_ACTION"] = "Change";
shell.GoNext();
}
}

public void Repair()
{
if (session != null)
{
session["MODIFY_ACTION"] = "Repair";
JumpToProgressDialog();
}
}

public void Remove()
{
if (session != null)
{
session["REMOVE"] = "ALL";
session["MODIFY_ACTION"] = "Remove";

JumpToProgressDialog();
}
}

public void GoPrev()
=> shell?.GoPrev();

public void Cancel()
=> Host?.Shell.Cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@
<TextBlock x:Name="CurrentAction" TextWrapping="WrapWithOverflow" />
</StackPanel>
<ProgressBar
x:Name="Progress"
x:Name="ProgressValue"
Height="10"
Margin="10"
VerticalContentAlignment="Center" />
VerticalContentAlignment="Center"
Maximum="100"
Value="{Binding ProgressValue}" />
<Grid
x:Name="UacPromptIsVisible"
Width="328"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public override MessageResult ProcessMessage(InstallMessage messageType, Record

public override void OnExecuteComplete()
=> model?.OnExecuteComplete();

public override void OnProgress(int progressPercentage)
{
if (model != null)
model.ProgressValue = progressPercentage;
}
}

public class ProgressDialogModel : Caliburn.Micro.Screen
Expand All @@ -64,10 +70,13 @@ public class ProgressDialogModel : Caliburn.Micro.Screen

public BitmapImage Banner => session?.GetResourceBitmap("WixUI_Bmp_Banner").ToImageSource();

public int ProgressValue { get => progressValue; set { progressValue = value; base.NotifyOfPropertyChange(() => ProgressValue); } }

public bool UacPromptIsVisible => (!WindowsIdentity.GetCurrent().IsAdmin() && Uac.IsEnabled() && !uacPromptActioned);

public string CurrentAction { get => currentAction; set { currentAction = value; base.NotifyOfPropertyChange(() => CurrentAction); } }

int progressValue;
bool uacPromptActioned = false;
private string currentAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ static public void Main()
static private void BuildMsi()
{
var project = new ManagedProject("MyProduct",
new Dir(@"C:\My Company\My Product",
new File("readme.txt")));
new Dir(@"C:\My Company\My Product",
new File("readme.txt")));
project.ManagedUI = new ManagedUI();

project.ManagedUI.InstallDialogs.Add(Dialogs.InstallScope)
Expand All @@ -42,7 +42,7 @@ static private void BuildMsiRemember()
new File("readme.txt")),
new RegValue(RegistryHive.LocalMachine, @"SOFTWARE\My Company\My Product", "InstallDir", "[INSTALLDIR]") { Condition = new Condition("ALLUSERS=\"1\"") },
new RegValue(RegistryHive.CurrentUser, @"SOFTWARE\My Company\My Product", "InstallPerUser", "yes") { Condition = new Condition("MSIINSTALLPERUSER=\"1\"") }
);
);
project.ManagedUI = new ManagedUI();

project.ManagedUI.InstallDialogs.Add(Dialogs.InstallScope)
Expand All @@ -56,7 +56,7 @@ static private void BuildMsiRemember()

project.UIInitialized += (SetupEventArgs e) =>
{
if (e.IsInstalling && !e.IsUpgrading)
if (e.IsInstalling && !e.IsUpgradingInstalledVersion)
{
e.Session["ALLUSERS"] = "2";

Expand Down
4 changes: 2 additions & 2 deletions Source/src/WixSharp.UI.WPF/Dialogs/ProgressDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class ProgressDialogModel : Caliburn.Micro.Screen
public int ProgressValue { get => progressValue; set { progressValue = value; base.NotifyOfPropertyChange(() => ProgressValue); } }

bool uacPromptActioned = false;
private string currentAction;
private int progressValue;
string currentAction;
int progressValue;

public string UacPrompt
{
Expand Down

0 comments on commit ec5e6b9

Please sign in to comment.