mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-16 10:58:31 -05:00
Move update message logic to common and remove restarting on update (installer will do that)
This commit is contained in:
@@ -1,18 +1,15 @@
|
|||||||
using System;
|
using Common.Debug;
|
||||||
|
using Common.Helpers;
|
||||||
|
using Common.IO;
|
||||||
|
using Common.Settings;
|
||||||
|
using Common.Wpf.Extensions;
|
||||||
|
using FeedCenter.Properties;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
|
||||||
using Microsoft.Win32;
|
|
||||||
|
|
||||||
using Common.Debug;
|
|
||||||
using Common.Helpers;
|
|
||||||
using Common.IO;
|
|
||||||
using Common.Wpf.Extensions;
|
|
||||||
using Common.Settings;
|
|
||||||
|
|
||||||
using FeedCenter.Properties;
|
|
||||||
|
|
||||||
namespace FeedCenter
|
namespace FeedCenter
|
||||||
{
|
{
|
||||||
@@ -20,13 +17,7 @@ namespace FeedCenter
|
|||||||
{
|
{
|
||||||
#region Debug properties
|
#region Debug properties
|
||||||
|
|
||||||
public static bool UseDebugPath;
|
private static bool _useDebugPath;
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Properties
|
|
||||||
|
|
||||||
public bool Restart;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -35,12 +26,14 @@ namespace FeedCenter
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
|
_useDebugPath = Environment.CommandLine.IndexOf("/debugPath", StringComparison.InvariantCultureIgnoreCase) != -1;
|
||||||
|
|
||||||
// Create and initialize the app object
|
// Create and initialize the app object
|
||||||
App app = new App();
|
var app = new App();
|
||||||
app.InitializeComponent();
|
app.InitializeComponent();
|
||||||
|
|
||||||
// Create an isolation handle to see if we are already running
|
// Create an isolation handle to see if we are already running
|
||||||
IDisposable isolationHandle = ApplicationIsolation.GetIsolationHandle(FeedCenter.Properties.Resources.ApplicationName);
|
var isolationHandle = ApplicationIsolation.GetIsolationHandle(FeedCenter.Properties.Resources.ApplicationName);
|
||||||
|
|
||||||
// If there is another copy then pass it the command line and exit
|
// If there is another copy then pass it the command line and exit
|
||||||
if (isolationHandle == null)
|
if (isolationHandle == null)
|
||||||
@@ -54,7 +47,7 @@ namespace FeedCenter
|
|||||||
{
|
{
|
||||||
// Set the data directory based on debug or not
|
// Set the data directory based on debug or not
|
||||||
AppDomain.CurrentDomain.SetData("DataDirectory",
|
AppDomain.CurrentDomain.SetData("DataDirectory",
|
||||||
UseDebugPath
|
_useDebugPath
|
||||||
? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
|
? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
|
||||||
: UserSettingsPath);
|
: UserSettingsPath);
|
||||||
|
|
||||||
@@ -87,15 +80,12 @@ namespace FeedCenter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the main window before the splash otherwise WPF gets messed up
|
// Create the main window before the splash otherwise WPF gets messed up
|
||||||
MainWindow mainWindow = new MainWindow();
|
var mainWindow = new MainWindow();
|
||||||
|
|
||||||
// Show the splash window
|
// Show the splash window
|
||||||
SplashWindow splashWindow = new SplashWindow();
|
var splashWindow = new SplashWindow();
|
||||||
splashWindow.ShowDialog();
|
splashWindow.ShowDialog();
|
||||||
|
|
||||||
// If we don't need to restart then fire up the main window
|
|
||||||
if (!app.Restart)
|
|
||||||
{
|
|
||||||
// Update the registry settings
|
// Update the registry settings
|
||||||
SetStartWithWindows(Settings.Default.StartWithWindows);
|
SetStartWithWindows(Settings.Default.StartWithWindows);
|
||||||
SetDefaultFeedReader(Settings.Default.RegisterAsDefaultFeedReader);
|
SetDefaultFeedReader(Settings.Default.RegisterAsDefaultFeedReader);
|
||||||
@@ -105,17 +95,6 @@ namespace FeedCenter
|
|||||||
|
|
||||||
// Run the app
|
// Run the app
|
||||||
app.Run(mainWindow);
|
app.Run(mainWindow);
|
||||||
}
|
|
||||||
|
|
||||||
// If we need to restart
|
|
||||||
if (app.Restart)
|
|
||||||
{
|
|
||||||
// Wait a bit to make sure any previous upgrade has settled
|
|
||||||
Thread.Sleep(2000);
|
|
||||||
|
|
||||||
// Restart the application
|
|
||||||
Current.Restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Terminate the tracer
|
// Terminate the tracer
|
||||||
Tracer.Dispose();
|
Tracer.Dispose();
|
||||||
@@ -143,11 +122,11 @@ namespace FeedCenter
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
// If we're running in debug mode then use a local path for the database and logs
|
// If we're running in debug mode then use a local path for the database and logs
|
||||||
if (UseDebugPath)
|
if (_useDebugPath)
|
||||||
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||||
|
|
||||||
// Get the path to the local application data directory
|
// Get the path to the local application data directory
|
||||||
string path = Path.Combine(
|
var path = Path.Combine(
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||||
FeedCenter.Properties.Resources.ApplicationName);
|
FeedCenter.Properties.Resources.ApplicationName);
|
||||||
|
|
||||||
@@ -162,13 +141,13 @@ namespace FeedCenter
|
|||||||
public static void SetStartWithWindows(bool value)
|
public static void SetStartWithWindows(bool value)
|
||||||
{
|
{
|
||||||
// Get the application name
|
// Get the application name
|
||||||
string applicationName = FeedCenter.Properties.Resources.ApplicationDisplayName;
|
var applicationName = FeedCenter.Properties.Resources.ApplicationDisplayName;
|
||||||
|
|
||||||
// Get application details
|
// Get application details
|
||||||
string publisherName = applicationName;
|
var publisherName = applicationName;
|
||||||
string productName = applicationName;
|
var productName = applicationName;
|
||||||
string allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
|
var allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
|
||||||
string shortcutPath = Path.Combine(allProgramsPath, publisherName);
|
var shortcutPath = Path.Combine(allProgramsPath, publisherName);
|
||||||
|
|
||||||
// Build the auto start path
|
// Build the auto start path
|
||||||
shortcutPath = "\"" + Path.Combine(shortcutPath, productName) + ".appref-ms\"";
|
shortcutPath = "\"" + Path.Combine(shortcutPath, productName) + ".appref-ms\"";
|
||||||
@@ -180,10 +159,10 @@ namespace FeedCenter
|
|||||||
public static void SetDefaultFeedReader(bool value)
|
public static void SetDefaultFeedReader(bool value)
|
||||||
{
|
{
|
||||||
// Get the location of the assembly
|
// Get the location of the assembly
|
||||||
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
|
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
|
||||||
|
|
||||||
// Open the registry key (creating if needed)
|
// Open the registry key (creating if needed)
|
||||||
using (RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("Software\\Classes\\feed", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
using (var registryKey = Registry.CurrentUser.CreateSubKey("Software\\Classes\\feed", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||||
{
|
{
|
||||||
if (registryKey == null)
|
if (registryKey == null)
|
||||||
return;
|
return;
|
||||||
@@ -193,7 +172,7 @@ namespace FeedCenter
|
|||||||
registryKey.SetValue("URL Protocol", string.Empty);
|
registryKey.SetValue("URL Protocol", string.Empty);
|
||||||
|
|
||||||
// Open the icon subkey (creating if needed)
|
// Open the icon subkey (creating if needed)
|
||||||
using (RegistryKey subKey = registryKey.CreateSubKey("DefaultIcon", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
using (var subKey = registryKey.CreateSubKey("DefaultIcon", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||||
{
|
{
|
||||||
if (subKey != null)
|
if (subKey != null)
|
||||||
{
|
{
|
||||||
@@ -206,7 +185,7 @@ namespace FeedCenter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open the subkey for the command (creating if needed)
|
// Open the subkey for the command (creating if needed)
|
||||||
using (RegistryKey subKey = registryKey.CreateSubKey("shell\\open\\command", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
using (var subKey = registryKey.CreateSubKey("shell\\open\\command", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||||
{
|
{
|
||||||
if (subKey != null)
|
if (subKey != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,6 +66,14 @@ namespace FeedCenter
|
|||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
|
// Setup the update message properties and callbacks
|
||||||
|
UpdateCheck.ApplicationName = Properties.Resources.ApplicationDisplayName;
|
||||||
|
UpdateCheck.UpdateServer = Settings.Default.VersionLocation;
|
||||||
|
UpdateCheck.UpdateFile = Settings.Default.VersionFile;
|
||||||
|
UpdateCheck.ApplicationShutdown = ApplicationShutdown;
|
||||||
|
UpdateCheck.ApplicationCurrentMessage = ApplicationCurrentMessage;
|
||||||
|
UpdateCheck.ApplicationUpdateMessage = ApplicationUpdateMessage;
|
||||||
|
|
||||||
// Show the notification icon
|
// Show the notification icon
|
||||||
NotificationIcon.Initialize(this);
|
NotificationIcon.Initialize(this);
|
||||||
|
|
||||||
@@ -105,6 +113,21 @@ namespace FeedCenter
|
|||||||
Tracer.WriteLine("MainForm creation finished");
|
Tracer.WriteLine("MainForm creation finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool ApplicationUpdateMessage(string title, string message)
|
||||||
|
{
|
||||||
|
return MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ApplicationCurrentMessage(string title, string message)
|
||||||
|
{
|
||||||
|
MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Information);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ApplicationShutdown()
|
||||||
|
{
|
||||||
|
Application.Current.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Window overrides
|
#region Window overrides
|
||||||
@@ -385,7 +408,7 @@ namespace FeedCenter
|
|||||||
// Increment the index and adjust if we've gone around the end
|
// Increment the index and adjust if we've gone around the end
|
||||||
_feedIndex = (_feedIndex + 1) % feedCount;
|
_feedIndex = (_feedIndex + 1) % feedCount;
|
||||||
}
|
}
|
||||||
while (startIndex != _feedIndex);
|
while (_feedIndex != startIndex);
|
||||||
|
|
||||||
// If nothing was found then clear the current feed
|
// If nothing was found then clear the current feed
|
||||||
if (!found)
|
if (!found)
|
||||||
@@ -456,7 +479,7 @@ namespace FeedCenter
|
|||||||
if (_feedIndex < 0)
|
if (_feedIndex < 0)
|
||||||
_feedIndex = feedCount - 1;
|
_feedIndex = feedCount - 1;
|
||||||
}
|
}
|
||||||
while (startIndex != _feedIndex);
|
while (_feedIndex != startIndex);
|
||||||
|
|
||||||
// If nothing was found then clear the current feed
|
// If nothing was found then clear the current feed
|
||||||
if (!found)
|
if (!found)
|
||||||
@@ -690,7 +713,7 @@ namespace FeedCenter
|
|||||||
if (DateTime.Now - Settings.Default.LastVersionCheck >= Settings.Default.VersionCheckInterval)
|
if (DateTime.Now - Settings.Default.LastVersionCheck >= Settings.Default.VersionCheckInterval)
|
||||||
{
|
{
|
||||||
// Get the update information
|
// Get the update information
|
||||||
UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile);
|
UpdateCheck.CheckForUpdate();
|
||||||
|
|
||||||
// Update the last check time
|
// Update the last check time
|
||||||
Settings.Default.LastVersionCheck = DateTime.Now;
|
Settings.Default.LastVersionCheck = DateTime.Now;
|
||||||
@@ -1192,7 +1215,7 @@ namespace FeedCenter
|
|||||||
|
|
||||||
private void HandleOpenAllToolbarButtonClick(object sender, RoutedEventArgs e)
|
private void HandleOpenAllToolbarButtonClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var multipleOpenAction = (MultipleOpenAction) _currentFeed.MultipleOpenAction;
|
var multipleOpenAction = _currentFeed.MultipleOpenAction;
|
||||||
|
|
||||||
switch (multipleOpenAction)
|
switch (multipleOpenAction)
|
||||||
{
|
{
|
||||||
@@ -1321,7 +1344,7 @@ namespace FeedCenter
|
|||||||
private void HandleNewVersionLinkClick(object sender, RoutedEventArgs e)
|
private void HandleNewVersionLinkClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// Display update information
|
// Display update information
|
||||||
VersionCheck.DisplayUpdateInformation(true);
|
UpdateCheck.DisplayUpdateInformation(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace FeedCenter.Options
|
|||||||
|
|
||||||
applicationNameLabel.Text = Properties.Resources.ApplicationDisplayName;
|
applicationNameLabel.Text = Properties.Resources.ApplicationDisplayName;
|
||||||
|
|
||||||
string version = UpdateCheck.CurrentVersion.ToString();
|
string version = UpdateCheck.LocalVersion.ToString();
|
||||||
versionLabel.Text = string.Format(Properties.Resources.Version, version);
|
versionLabel.Text = string.Format(Properties.Resources.Version, version);
|
||||||
|
|
||||||
companyLabel.Text = ((AssemblyCompanyAttribute) Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false)[0]).Company;
|
companyLabel.Text = ((AssemblyCompanyAttribute) Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false)[0]).Company;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace FeedCenter.Options
|
using Common.Update;
|
||||||
|
|
||||||
|
namespace FeedCenter.Options
|
||||||
{
|
{
|
||||||
public partial class UpdateOptionsPanel
|
public partial class UpdateOptionsPanel
|
||||||
{
|
{
|
||||||
@@ -32,7 +34,7 @@
|
|||||||
|
|
||||||
private void HandleCheckVersionNowButtonClick(object sender, System.Windows.RoutedEventArgs e)
|
private void HandleCheckVersionNowButtonClick(object sender, System.Windows.RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
VersionCheck.DisplayUpdateInformation(true);
|
UpdateCheck.DisplayUpdateInformation(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
Application/Properties/Resources.Designer.cs
generated
42
Application/Properties/Resources.Designer.cs
generated
@@ -1,7 +1,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.34209
|
// Runtime Version:4.0.30319.34014
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
@@ -1360,46 +1360,6 @@ namespace FeedCenter.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to An update to version {0} is now available..
|
|
||||||
/// </summary>
|
|
||||||
public static string UpdateAvailable {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("UpdateAvailable", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to You are already running the most recent version.
|
|
||||||
///
|
|
||||||
///No updates are available at this time..
|
|
||||||
/// </summary>
|
|
||||||
public static string UpdateCheckCurrent {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("UpdateCheckCurrent", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Version {1} of {0} is now available.
|
|
||||||
///
|
|
||||||
///Would you like to download and install it now?.
|
|
||||||
/// </summary>
|
|
||||||
public static string UpdateCheckNewVersion {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("UpdateCheckNewVersion", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to {0} Update.
|
|
||||||
/// </summary>
|
|
||||||
public static string UpdateCheckTitle {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("UpdateCheckTitle", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Version: {0}.
|
/// Looks up a localized string similar to Version: {0}.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -184,22 +184,6 @@
|
|||||||
<data name="ApplicationName" xml:space="preserve">
|
<data name="ApplicationName" xml:space="preserve">
|
||||||
<value>FeedCenter</value>
|
<value>FeedCenter</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UpdateCheckNewVersion" xml:space="preserve">
|
|
||||||
<value>Version {1} of {0} is now available.
|
|
||||||
|
|
||||||
Would you like to download and install it now?</value>
|
|
||||||
</data>
|
|
||||||
<data name="UpdateCheckCurrent" xml:space="preserve">
|
|
||||||
<value>You are already running the most recent version.
|
|
||||||
|
|
||||||
No updates are available at this time.</value>
|
|
||||||
</data>
|
|
||||||
<data name="UpdateCheckTitle" xml:space="preserve">
|
|
||||||
<value>{0} Update</value>
|
|
||||||
</data>
|
|
||||||
<data name="UpdateAvailable" xml:space="preserve">
|
|
||||||
<value>An update to version {0} is now available.</value>
|
|
||||||
</data>
|
|
||||||
<data name="FeedAddedNotification" xml:space="preserve">
|
<data name="FeedAddedNotification" xml:space="preserve">
|
||||||
<value>"{0}" has been successfully added to your feed list.</value>
|
<value>"{0}" has been successfully added to your feed list.</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace FeedCenter
|
|||||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||||
|
|
||||||
// Get the version to display
|
// Get the version to display
|
||||||
string version = UpdateCheck.CurrentVersion.ToString();
|
string version = UpdateCheck.LocalVersion.ToString();
|
||||||
|
|
||||||
// Show the version
|
// Show the version
|
||||||
lblVersion.Content = string.Format(Properties.Resources.Version, version);
|
lblVersion.Content = string.Format(Properties.Resources.Version, version);
|
||||||
@@ -198,7 +198,7 @@ namespace FeedCenter
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Return if the check worked and an update is available
|
// Return if the check worked and an update is available
|
||||||
return UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile) && UpdateCheck.UpdateAvailable;
|
return UpdateCheck.CheckForUpdate() && UpdateCheck.UpdateAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CheckDatabase()
|
private static bool CheckDatabase()
|
||||||
|
|||||||
@@ -1,111 +1,10 @@
|
|||||||
using Common.Debug;
|
using Common.Update;
|
||||||
using Common.Update;
|
|
||||||
using FeedCenter.Properties;
|
using FeedCenter.Properties;
|
||||||
using System;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Application = System.Windows.Forms.Application;
|
|
||||||
|
|
||||||
namespace FeedCenter
|
namespace FeedCenter
|
||||||
{
|
{
|
||||||
internal static class VersionCheck
|
internal static class VersionCheck
|
||||||
{
|
{
|
||||||
public static async void DisplayUpdateInformation(bool showIfCurrent)
|
|
||||||
{
|
|
||||||
UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile);
|
|
||||||
|
|
||||||
// Check for an update
|
|
||||||
if (UpdateCheck.UpdateAvailable)
|
|
||||||
{
|
|
||||||
// Load the version string from the server
|
|
||||||
Version serverVersion = UpdateCheck.VersionInfo.Version;
|
|
||||||
|
|
||||||
// Format the check title
|
|
||||||
string updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationDisplayName);
|
|
||||||
|
|
||||||
// Format the message
|
|
||||||
string updateCheckMessage = string.Format(Resources.UpdateCheckNewVersion, Resources.ApplicationDisplayName, serverVersion);
|
|
||||||
|
|
||||||
// Ask the user to update
|
|
||||||
if (MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Get the update
|
|
||||||
await UpdateCheck.DownloadUpdate();
|
|
||||||
|
|
||||||
// Install the update
|
|
||||||
UpdateCheck.InstallUpdate();
|
|
||||||
|
|
||||||
// Set to restart
|
|
||||||
((App) System.Windows.Application.Current).Restart = true;
|
|
||||||
|
|
||||||
// Restart the application
|
|
||||||
System.Windows.Application.Current.Shutdown();
|
|
||||||
}
|
|
||||||
else if (showIfCurrent)
|
|
||||||
{
|
|
||||||
// Format the check title
|
|
||||||
string updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationDisplayName);
|
|
||||||
|
|
||||||
// Format the message
|
|
||||||
string updateCheckMessage = string.Format(Resources.UpdateCheckCurrent, Resources.ApplicationDisplayName);
|
|
||||||
|
|
||||||
MessageBox.Show(updateCheckMessage, updateCheckTitle, MessageBoxButton.OK, MessageBoxImage.Information);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Background checking
|
|
||||||
|
|
||||||
private static BackgroundWorker _backgroundWorker;
|
|
||||||
|
|
||||||
public static void DisplayUpdateInformationAsync()
|
|
||||||
{
|
|
||||||
// Do nothing if we already have a worker
|
|
||||||
if (_backgroundWorker != null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Create a new worker
|
|
||||||
_backgroundWorker = new BackgroundWorker();
|
|
||||||
|
|
||||||
// Setup worker events
|
|
||||||
_backgroundWorker.DoWork += HandleBackgroundWorkerDoWork;
|
|
||||||
_backgroundWorker.RunWorkerCompleted += HandleBackgroundWorkerCompleted;
|
|
||||||
|
|
||||||
// Run the worker
|
|
||||||
_backgroundWorker.RunWorkerAsync();
|
|
||||||
|
|
||||||
// Wait for the worker
|
|
||||||
while (_backgroundWorker.IsBusy)
|
|
||||||
Application.DoEvents();
|
|
||||||
|
|
||||||
// Clear out the worker
|
|
||||||
_backgroundWorker.Dispose();
|
|
||||||
_backgroundWorker = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void HandleBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
|
|
||||||
{
|
|
||||||
e.Result = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile);
|
|
||||||
|
|
||||||
// Get the update information and set it into the result
|
|
||||||
e.Result = UpdateCheck.UpdateAvailable;
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
Tracer.WriteException(exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void HandleBackgroundWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
|
||||||
{
|
|
||||||
// Display any update info
|
|
||||||
DisplayUpdateInformation(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user