in Clients/Xamarin.Interactive.Client.Windows/Views/UpdaterWindow.xaml.cs [90:186]
void Hyperlink_Click (object sender, RoutedEventArgs e)
=> Commands.Commands.ShowOptions.Execute (OptionsWindow.Tab.Updater);
sealed class WpfUpdaterViewModel : UpdaterViewModel
{
const string TAG = nameof (WpfUpdaterViewModel);
readonly Window ownerWindow;
public WpfUpdaterViewModel (Window ownerWindow, UpdateItem updateItem)
: base (ClientInfo.FullProductName, updateItem)
{
if (ownerWindow == null)
throw new ArgumentNullException (nameof (ownerWindow));
this.ownerWindow = ownerWindow;
}
MetroDialogWindow CreateDialog (string title, string message)
=> new MetroDialogWindow {
Owner = ownerWindow,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Width = ownerWindow.Width,
Title = title,
Message = message
};
void DeleteUpdate ()
{
try {
File.Delete (DownloadItem.TargetFile);
} catch (Exception ex) {
Log.Error (TAG, $"unable to delete file {DownloadItem.TargetFile}", ex);
}
}
protected override Task InstallUpdateAsync ()
{
MainThread.Ensure ();
var window = CreateDialog (
Catalog.Format (Catalog.GetString (
"{0} must be closed before continuing.",
comment: "{0} is the application name"),
AppName),
Catalog.Format (Catalog.GetString (
"The update was downloaded successfully and is ready " +
"to be installed, but {0} must be closed first.",
comment: "{0} is the application name"),
AppName));
window.ButtonStyle = MessageDialogStyle.AffirmativeAndNegative;
window.AffirmativeButtonText = Catalog.GetString ("Quit & Install Update");
window.NegativeButtonText = Catalog.GetString ("Cancel Update");
window.ShowDialog ();
if (window.Result != MessageDialogResult.Affirmative) {
DeleteUpdate ();
ownerWindow.Close ();
return Task.CompletedTask;
}
Process.Start (DownloadItem.TargetFile).WaitForInputIdle (2000);
App.Current.Shutdown ();
return Task.CompletedTask;
}
protected override void RunErrorDialog (bool isDownloadError, string message)
{
MainThread.Ensure ();
MetroDialogWindow dialog;
if (isDownloadError) {
dialog = CreateDialog (Catalog.GetString ("Download Failed"), message);
dialog.ButtonStyle = MessageDialogStyle.AffirmativeAndNegative;
dialog.AffirmativeButtonText = Catalog.GetString ("Download & Install Manually");
dialog.NegativeButtonText = Catalog.GetString ("Cancel");
} else {
dialog = CreateDialog (Catalog.GetString ("Installation Failed"), message);
dialog.ButtonStyle = MessageDialogStyle.Affirmative;
dialog.AffirmativeButtonText = Catalog.GetString ("Close");
}
dialog.ShowDialog ();
if (dialog.Result == MessageDialogResult.Affirmative && isDownloadError) {
try {
Process.Start (UpdateItem.DownloadUrl.ToString ());
} catch (Exception e) {
Log.Error (TAG, $"unable to Process.Start({UpdateItem.DownloadUrl})", e);
}
}
}
}