mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-16 10:58:31 -05:00
More installer migration
This commit is contained in:
64
Application/Update/UpdateCheck.cs
Normal file
64
Application/Update/UpdateCheck.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
49
Application/Update/VersionFile.cs
Normal file
49
Application/Update/VersionFile.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user