Move update check to common

This commit is contained in:
2014-11-22 07:30:22 -05:00
parent 2eec143074
commit fba778679b
7 changed files with 10 additions and 125 deletions

View File

@@ -261,8 +261,6 @@
<Compile Include="SplashWindow.xaml.cs">
<DependentUpon>SplashWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Update\UpdateCheck.cs" />
<Compile Include="Update\VersionFile.cs" />
<Compile Include="VersionCheck.cs" />
<Page Include="FeedErrorWindow.xaml">
<SubType>Designer</SubType>

View File

@@ -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;

View File

@@ -1,4 +1,4 @@
using FeedCenter.Update;
using Common.Update;
using System.Reflection;
namespace FeedCenter.Options

View File

@@ -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()

View File

@@ -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<bool> 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;
}
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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;