using System.Diagnostics; using System.IO; using System.Windows.Media.Imaging; using Caliburn.Micro; using WixSharp; using WixSharp.UI.Forms; using WixSharp.UI.WPF; using IO = System.IO; namespace Sai.RvKits_Setup { /// /// The standard ExitDialog. /// Follows the design of the canonical Caliburn.Micro View (MVVM). /// See https://caliburnmicro.com/documentation/cheat-sheet /// /// /// /// public partial class ExitDialog : WpfDialog, IWpfDialog { /// /// Initializes a new instance of the class. /// public ExitDialog() { InitializeComponent(); } /// /// This method is invoked by WixSHarp runtime when the custom dialog content is internally fully initialized. /// This is a convenient place to do further initialization activities (e.g. localization). /// public void Init() { UpdateTitles(ManagedFormHost.Runtime.Session); ViewModelBinder.Bind(new ExitDialogModel { Host = ManagedFormHost }, this, null); } /// /// Updates the titles of the dialog depending on the success of the installation action. /// /// The session. 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(); } } /// /// ViewModel for standard ExitDialog. /// Follows the design of the canonical Caliburn.Micro ViewModel (MVVM). /// See https://caliburnmicro.com/documentation/cheat-sheet /// /// internal class ExitDialogModel : Caliburn.Micro.Screen { public ManagedForm Host { get; set; } ISession session => Host?.Runtime.Session; IManagedUIShell shell => Host?.Shell; public BitmapImage Banner => session?.GetResourceBitmap("WixSharpUI_Bmp_Dialog").ToImageSource(); public void GoExit() => shell?.Exit(); public void Cancel() => shell?.Exit(); public void ViewLog() { if (shell != null) try { string logFile = session.LogFile; if (logFile.IsEmpty()) { string wixSharpDir = Path.GetTempPath().PathCombine("WixSharp"); if (!Directory.Exists(wixSharpDir)) Directory.CreateDirectory(wixSharpDir); logFile = wixSharpDir.PathCombine(Host.Runtime.ProductName + ".log"); IO.File.WriteAllText(logFile, shell.Log); } Process.Start("notepad.exe", logFile); } catch { // Catch all, we don't want the installer to crash in an // attempt to view the log. } } } }