2016-05-10 03:40:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
2016-05-11 02:24:15 +08:00
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Net.Sockets;
|
2016-05-10 03:40:59 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2017-03-06 09:30:47 +08:00
|
|
|
|
using System.Windows;
|
2016-05-10 03:40:59 +08:00
|
|
|
|
using Squirrel;
|
2017-03-06 09:30:47 +08:00
|
|
|
|
using Wox.Core.Resource;
|
|
|
|
|
using Wox.Infrastructure;
|
2016-05-10 03:40:59 +08:00
|
|
|
|
using Wox.Infrastructure.Http;
|
|
|
|
|
using Wox.Infrastructure.Logger;
|
|
|
|
|
|
|
|
|
|
namespace Wox.Core
|
|
|
|
|
{
|
|
|
|
|
public static class Updater
|
|
|
|
|
{
|
2017-03-06 07:59:10 +08:00
|
|
|
|
public static async Task UpdateApp()
|
2016-05-10 03:40:59 +08:00
|
|
|
|
{
|
2016-05-10 06:51:10 +08:00
|
|
|
|
|
2017-03-06 08:05:03 +08:00
|
|
|
|
var c = new WebClient { Proxy = Http.WebProxy() };
|
|
|
|
|
var d = new FileDownloader(c);
|
2016-05-10 06:51:10 +08:00
|
|
|
|
|
2016-05-10 03:40:59 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-03-06 09:30:47 +08:00
|
|
|
|
const string url = Constant.Github;
|
2017-03-06 08:05:03 +08:00
|
|
|
|
using (var m = await UpdateManager.GitHubUpdateManager(url, urlDownloader: d))
|
2016-05-10 03:40:59 +08:00
|
|
|
|
{
|
2017-03-08 02:33:18 +08:00
|
|
|
|
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
|
2017-03-06 09:30:47 +08:00
|
|
|
|
var e = await m.CheckForUpdate().NonNull();
|
|
|
|
|
var fe = e.FutureReleaseEntry;
|
|
|
|
|
var ce = e.CurrentlyInstalledVersion;
|
|
|
|
|
if (fe.Version > ce.Version)
|
|
|
|
|
{
|
|
|
|
|
var t = NewVersinoTips(fe.Version.ToString());
|
|
|
|
|
MessageBox.Show(t);
|
|
|
|
|
|
|
|
|
|
await m.DownloadReleases(e.ReleasesToApply);
|
|
|
|
|
await m.ApplyReleases(e);
|
|
|
|
|
await m.CreateUninstallerRegistryEntry();
|
|
|
|
|
|
|
|
|
|
Log.Info($"|Updater.UpdateApp|Future Release <{fe.Formatted()}>");
|
|
|
|
|
}
|
2016-05-10 03:40:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-06 08:05:03 +08:00
|
|
|
|
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
|
2016-05-10 03:40:59 +08:00
|
|
|
|
{
|
2017-03-06 08:05:03 +08:00
|
|
|
|
Log.Exception("|Updater.UpdateApp|Network error", e);
|
|
|
|
|
|
2016-05-10 03:40:59 +08:00
|
|
|
|
}
|
2017-03-06 08:05:03 +08:00
|
|
|
|
catch (Exception e)
|
2016-05-10 03:40:59 +08:00
|
|
|
|
{
|
|
|
|
|
const string info = "Update.exe not found, not a Squirrel-installed app?";
|
2017-03-06 08:05:03 +08:00
|
|
|
|
if (e.Message == info)
|
2016-05-10 03:40:59 +08:00
|
|
|
|
{
|
2017-03-06 08:05:03 +08:00
|
|
|
|
Log.Error($"|Updater.UpdateApp|{info}");
|
2016-05-10 03:40:59 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 09:54:06 +08:00
|
|
|
|
private static string NewVersinoTips(string version)
|
2017-03-06 09:30:47 +08:00
|
|
|
|
{
|
|
|
|
|
var translater = InternationalizationManager.Instance;
|
|
|
|
|
var tips = string.Format(translater.GetTranslation("newVersionTips"), version);
|
|
|
|
|
return tips;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-10 03:40:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|