From fba778679b81017770050378d842c83e94635f80 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Sat, 22 Nov 2014 07:30:22 -0500 Subject: [PATCH] Move update check to common --- Application/FeedCenter.csproj | 2 - Application/MainWindow.xaml.cs | 4 +- Application/Options/AboutOptionsPanel.xaml.cs | 2 +- Application/SplashWindow.xaml.cs | 6 +- Application/Update/UpdateCheck.cs | 64 ------------------- Application/Update/VersionFile.cs | 49 -------------- Application/VersionCheck.cs | 8 +-- 7 files changed, 10 insertions(+), 125 deletions(-) delete mode 100644 Application/Update/UpdateCheck.cs delete mode 100644 Application/Update/VersionFile.cs diff --git a/Application/FeedCenter.csproj b/Application/FeedCenter.csproj index 23c9c28..45eec01 100644 --- a/Application/FeedCenter.csproj +++ b/Application/FeedCenter.csproj @@ -261,8 +261,6 @@ SplashWindow.xaml - - Designer diff --git a/Application/MainWindow.xaml.cs b/Application/MainWindow.xaml.cs index 02b02ba..245a858 100644 --- a/Application/MainWindow.xaml.cs +++ b/Application/MainWindow.xaml.cs @@ -1,6 +1,7 @@ using Common.Debug; using Common.Helpers; using Common.IO; +using Common.Update; using Common.Wpf.Extensions; using FeedCenter.Options; using FeedCenter.Properties; @@ -16,7 +17,6 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; -using FeedCenter.Update; namespace FeedCenter { @@ -690,7 +690,7 @@ namespace FeedCenter if (DateTime.Now - Settings.Default.LastVersionCheck >= Settings.Default.VersionCheckInterval) { // Get the update information - UpdateCheck.CheckForUpdate(); + UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile); // Update the last check time Settings.Default.LastVersionCheck = DateTime.Now; diff --git a/Application/Options/AboutOptionsPanel.xaml.cs b/Application/Options/AboutOptionsPanel.xaml.cs index d862dab..0338f24 100644 --- a/Application/Options/AboutOptionsPanel.xaml.cs +++ b/Application/Options/AboutOptionsPanel.xaml.cs @@ -1,4 +1,4 @@ -using FeedCenter.Update; +using Common.Update; using System.Reflection; namespace FeedCenter.Options diff --git a/Application/SplashWindow.xaml.cs b/Application/SplashWindow.xaml.cs index 0025073..609aafb 100644 --- a/Application/SplashWindow.xaml.cs +++ b/Application/SplashWindow.xaml.cs @@ -1,6 +1,6 @@ -using FeedCenter.Data; +using Common.Update; +using FeedCenter.Data; using FeedCenter.Properties; -using FeedCenter.Update; using System; using System.Collections.Generic; using System.ComponentModel; @@ -198,7 +198,7 @@ namespace FeedCenter return false; // Return if the check worked and an update is available - return UpdateCheck.CheckForUpdate() && UpdateCheck.UpdateAvailable; + return UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile) && UpdateCheck.UpdateAvailable; } private static bool CheckDatabase() diff --git a/Application/Update/UpdateCheck.cs b/Application/Update/UpdateCheck.cs deleted file mode 100644 index a0d6a38..0000000 --- a/Application/Update/UpdateCheck.cs +++ /dev/null @@ -1,64 +0,0 @@ -using FeedCenter.Properties; -using System; -using System.Diagnostics; -using System.IO; -using System.Net; -using System.Reflection; -using System.Threading.Tasks; - -namespace FeedCenter.Update -{ - public static class UpdateCheck - { - public static VersionFile VersionFile { get; private set; } - public static string LocalInstallFile { get; private set; } - - public static bool UpdateAvailable { get; private set; } - - public static Version CurrentVersion - { - get { return Assembly.GetExecutingAssembly().GetName().Version; } - } - - public static bool CheckForUpdate() - { - VersionFile = VersionFile.Load(); - - if (VersionFile == null) - return false; - - var serverVersion = VersionFile.Version; - var localVersion = CurrentVersion; - - UpdateAvailable = serverVersion > localVersion; - - return true; - } - - internal static async Task DownloadUpdate() - { - if (VersionFile == null) - return false; - - var remoteFile = Settings.Default.VersionLocation + VersionFile.InstallFile; - - LocalInstallFile = Path.Combine(Path.GetTempPath(), VersionFile.InstallFile); - - var webClient = new WebClient(); - - await webClient.DownloadFileTaskAsync(new Uri(remoteFile), LocalInstallFile); - - return true; - } - - internal static bool InstallUpdate() - { - if (VersionFile == null) - return false; - - Process.Start(LocalInstallFile, "/passive"); - - return true; - } - } -} diff --git a/Application/Update/VersionFile.cs b/Application/Update/VersionFile.cs deleted file mode 100644 index cb9b833..0000000 --- a/Application/Update/VersionFile.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Common.Debug; -using FeedCenter.Properties; -using System; -using System.Xml.Linq; - -namespace FeedCenter.Update -{ - public class VersionFile - { - public Version Version { get; set; } - public string InstallFile { get; set; } - public DateTime InstallCreated { get; set; } - - public static VersionFile Load() - { - try - { - var document = XDocument.Load(Settings.Default.VersionLocation + Settings.Default.VersionFile); - - var versionInformationElement = document.Element("versionInformation"); - - if (versionInformationElement == null) - return null; - - var versionElement = versionInformationElement.Element("version"); - var installFileElement = versionInformationElement.Element("installFile"); - var installCreatedElement = versionInformationElement.Element("installCreated"); - - if (versionElement == null || installFileElement == null || installCreatedElement == null) - return null; - - var versionFile = new VersionFile - { - Version = Version.Parse(versionElement.Value), - InstallFile = installFileElement.Value, - InstallCreated = DateTime.Parse(installCreatedElement.Value) - }; - - return versionFile; - } - catch (Exception exception) - { - Tracer.WriteException(exception); - - return null; - } - } - } -} diff --git a/Application/VersionCheck.cs b/Application/VersionCheck.cs index ade8d99..1598e74 100644 --- a/Application/VersionCheck.cs +++ b/Application/VersionCheck.cs @@ -1,9 +1,9 @@ using Common.Debug; +using Common.Update; using FeedCenter.Properties; using System; using System.ComponentModel; using System.Windows; -using FeedCenter.Update; using Application = System.Windows.Forms.Application; namespace FeedCenter @@ -12,13 +12,13 @@ namespace FeedCenter { public static async void DisplayUpdateInformation(bool showIfCurrent) { - UpdateCheck.CheckForUpdate(); + 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.VersionFile.Version; + Version serverVersion = UpdateCheck.VersionInfo.Version; // Format the check title string updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationDisplayName); @@ -89,7 +89,7 @@ namespace FeedCenter try { - UpdateCheck.CheckForUpdate(); + UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile); // Get the update information and set it into the result e.Result = UpdateCheck.UpdateAvailable;