Winify

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 83  →  ?path2? @ 84
/trunk/Winify/MainForm.cs
@@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
@@ -55,7 +56,7 @@
 
private readonly LogMemorySink _memorySink;
 
private readonly Toasts.ToastDisplay _toastDisplay;
private readonly ToastDisplay _toastDisplay;
 
#endregion
 
@@ -72,7 +73,7 @@
 
ChangedConfigurationContinuation = new ScheduledContinuation();
 
_toastDisplay = new Toasts.ToastDisplay(_cancellationToken);
_toastDisplay = new ToastDisplay(_cancellationToken);
}
 
public MainForm(Mutex mutex) : this()
@@ -141,6 +142,10 @@
 
private async void MainForm_Load(object sender, EventArgs e)
{
#pragma warning disable CS4014
PerformUpgrade();
#pragma warning restore CS4014
 
Configuration = await LoadConfiguration();
 
var servers = await LoadServers();
@@ -324,19 +329,7 @@
 
private async void UpdateToolStripMenuItem_Click(object sender, EventArgs e)
{
// Manually check for updates, this will not show a ui
var result = await _sparkle.CheckForUpdatesQuietly();
var updates = result.Updates;
if (result.Status == UpdateStatus.UpdateAvailable)
{
// if update(s) are found, then we have to trigger the UI to show it gracefully
_sparkle.ShowUpdateNeededUI();
return;
}
 
MessageBox.Show("No updates available at this time.", "Winify", MessageBoxButtons.OK,
MessageBoxIcon.Asterisk,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false);
await PerformUpgrade();
}
 
#endregion
@@ -386,6 +379,73 @@
 
#region Private Methods
 
private async Task PerformUpgrade()
{
// Manually check for updates, this will not show a ui
var updateCheck = await _sparkle.CheckForUpdatesQuietly();
switch (updateCheck.Status)
{
case UpdateStatus.UserSkipped:
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
updateCheck.Updates.Sort(UpdateComparer);
var latestVersion = updateCheck.Updates.FirstOrDefault();
if (latestVersion != null)
{
var availableVersion = new Version(latestVersion.Version);
 
if (availableVersion <= assemblyVersion)
{
return;
}
}
 
var decision = MessageBox.Show(
"Update available but it has been previously skipped. Should the update proceed anyway?",
Assembly.GetExecutingAssembly().GetName().Name, MessageBoxButtons.YesNo,
MessageBoxIcon.Asterisk,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false);
 
if (decision.HasFlag(DialogResult.No))
{
return;
}
 
goto default;
case UpdateStatus.UpdateNotAvailable:
MessageBox.Show("No updates available at this time.",
Assembly.GetExecutingAssembly().GetName().Name, MessageBoxButtons.OK,
MessageBoxIcon.Asterisk,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false);
break;
case UpdateStatus.CouldNotDetermine:
Log.Error("Could not determine the update availability status.");
break;
default:
_sparkle.ShowUpdateNeededUI();
break;
}
}
 
private static int UpdateComparer(AppCastItem x, AppCastItem y)
{
if (x == null)
{
return 1;
}
 
if (y == null)
{
return -1;
}
 
if (x == y)
{
return 0;
}
 
return new Version(y.Version).CompareTo(new Version(x.Version));
}
 
private static async Task SaveAnnouncements(Announcements.Announcements announcements)
{
switch (await Serialization.Serialize(announcements, Constants.AnnouncementsFile, "Announcements",