Skip to content

Instantly share code, notes, and snippets.

@haydenjameslee
Created June 17, 2015 19:57
Show Gist options
  • Save haydenjameslee/63732a2d50d95bdadd3b to your computer and use it in GitHub Desktop.
Save haydenjameslee/63732a2d50d95bdadd3b to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using wyDay.Controls;
namespace convrge
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class UpdateWindow : Window
{
AutomaticUpdaterBackend updater;
public UpdateWindow()
{
System.Threading.Thread.Sleep(3000);
InitializeComponent();
updater = new AutomaticUpdaterBackend()
{
GUID = "APP_GUID",
UpdateType = UpdateType.CheckAndDownload,
};
updater.CheckingFailed += OnCheckingFailed;
updater.UpdateAvailable += OnUpdateAvailable;
updater.DownloadingFailed += OnDownloadingFailed;
updater.ExtractingFailed += OnExtractingFailed;
updater.ReadyToBeInstalled += OnReadyToBeInstalled;
updater.UpdateSuccessful += OnUpdateSuccessful;
updater.UpdateFailed += OnFailed;
updater.UpToDate += OnUpToDate;
updater.Initialize();
updater.AppLoaded();
updater.ForceCheckForUpdate();
// Console.WriteLine("lez go");
}
void OnCheckingFailed(object sender, FailArgs e)
{
Console.WriteLine("fail");
UpdateErrorBox();
}
void OnUpdateAvailable(object sender, EventArgs e)
{
Console.WriteLine("up avail");
}
void OnDownloadingFailed(object sender, FailArgs e)
{
Console.WriteLine("dl fail");
UpdateErrorBox();
}
void OnExtractingFailed(object sender, FailArgs e)
{
Console.WriteLine("ex fail");
UpdateErrorBox();
}
void OnReadyToBeInstalled(object sender, EventArgs e)
{
Console.WriteLine("ready to install");
updater.InstallNow();
}
void OnUpToDate(object sender, EventArgs e)
{
Console.WriteLine("up to date");
LoadMainWindow();
}
void OnUpdateSuccessful(object sender, SuccessArgs e)
{
Console.WriteLine("success");
}
void OnFailed(object sender, FailArgs e)
{
Console.WriteLine("fail");
UpdateErrorBox();
}
void UpdateErrorBox()
{
MessageBoxResult result = MessageBox.Show("ERROR: Update failed. Please try again or reach out to _______.");
Application.Current.Shutdown();
}
void LoadMainWindow()
{
Application.Current.Dispatcher.Invoke((Action)delegate
{
MainWindow main = new MainWindow();
App.Current.MainWindow = main;
main.Show();
this.Close();
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment