mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-16 10:58:31 -05:00
Move update check to common
This commit is contained in:
@@ -261,8 +261,6 @@
|
|||||||
<Compile Include="SplashWindow.xaml.cs">
|
<Compile Include="SplashWindow.xaml.cs">
|
||||||
<DependentUpon>SplashWindow.xaml</DependentUpon>
|
<DependentUpon>SplashWindow.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Update\UpdateCheck.cs" />
|
|
||||||
<Compile Include="Update\VersionFile.cs" />
|
|
||||||
<Compile Include="VersionCheck.cs" />
|
<Compile Include="VersionCheck.cs" />
|
||||||
<Page Include="FeedErrorWindow.xaml">
|
<Page Include="FeedErrorWindow.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Common.Debug;
|
using Common.Debug;
|
||||||
using Common.Helpers;
|
using Common.Helpers;
|
||||||
using Common.IO;
|
using Common.IO;
|
||||||
|
using Common.Update;
|
||||||
using Common.Wpf.Extensions;
|
using Common.Wpf.Extensions;
|
||||||
using FeedCenter.Options;
|
using FeedCenter.Options;
|
||||||
using FeedCenter.Properties;
|
using FeedCenter.Properties;
|
||||||
@@ -16,7 +17,6 @@ using System.Windows.Controls;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using FeedCenter.Update;
|
|
||||||
|
|
||||||
namespace FeedCenter
|
namespace FeedCenter
|
||||||
{
|
{
|
||||||
@@ -690,7 +690,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();
|
UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile);
|
||||||
|
|
||||||
// Update the last check time
|
// Update the last check time
|
||||||
Settings.Default.LastVersionCheck = DateTime.Now;
|
Settings.Default.LastVersionCheck = DateTime.Now;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using FeedCenter.Update;
|
using Common.Update;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace FeedCenter.Options
|
namespace FeedCenter.Options
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using FeedCenter.Data;
|
using Common.Update;
|
||||||
|
using FeedCenter.Data;
|
||||||
using FeedCenter.Properties;
|
using FeedCenter.Properties;
|
||||||
using FeedCenter.Update;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
@@ -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() && UpdateCheck.UpdateAvailable;
|
return UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile) && UpdateCheck.UpdateAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CheckDatabase()
|
private static bool CheckDatabase()
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using Common.Debug;
|
using Common.Debug;
|
||||||
|
using Common.Update;
|
||||||
using FeedCenter.Properties;
|
using FeedCenter.Properties;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using FeedCenter.Update;
|
|
||||||
using Application = System.Windows.Forms.Application;
|
using Application = System.Windows.Forms.Application;
|
||||||
|
|
||||||
namespace FeedCenter
|
namespace FeedCenter
|
||||||
@@ -12,13 +12,13 @@ namespace FeedCenter
|
|||||||
{
|
{
|
||||||
public static async void DisplayUpdateInformation(bool showIfCurrent)
|
public static async void DisplayUpdateInformation(bool showIfCurrent)
|
||||||
{
|
{
|
||||||
UpdateCheck.CheckForUpdate();
|
UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile);
|
||||||
|
|
||||||
// Check for an update
|
// Check for an update
|
||||||
if (UpdateCheck.UpdateAvailable)
|
if (UpdateCheck.UpdateAvailable)
|
||||||
{
|
{
|
||||||
// Load the version string from the server
|
// Load the version string from the server
|
||||||
Version serverVersion = UpdateCheck.VersionFile.Version;
|
Version serverVersion = UpdateCheck.VersionInfo.Version;
|
||||||
|
|
||||||
// Format the check title
|
// Format the check title
|
||||||
string updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationDisplayName);
|
string updateCheckTitle = string.Format(Resources.UpdateCheckTitle, Resources.ApplicationDisplayName);
|
||||||
@@ -89,7 +89,7 @@ namespace FeedCenter
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
UpdateCheck.CheckForUpdate();
|
UpdateCheck.CheckForUpdate(Settings.Default.VersionLocation, Settings.Default.VersionFile);
|
||||||
|
|
||||||
// Get the update information and set it into the result
|
// Get the update information and set it into the result
|
||||||
e.Result = UpdateCheck.UpdateAvailable;
|
e.Result = UpdateCheck.UpdateAvailable;
|
||||||
|
|||||||
Reference in New Issue
Block a user