Remove unused updater and command line arguments

This commit is contained in:
bao-qian
2016-05-08 22:13:23 +01:00
parent d06fb83fee
commit e88e912c3c
20 changed files with 10 additions and 642 deletions

View File

@@ -1,16 +0,0 @@
namespace Wox.Core.Updater
{
public class Release
{
public string version { get; set; }
public string download_link { get; set; }
public string download_link1 { get; set; }
public string download_link2 { get; set; }
public string description { get; set; }
public override string ToString()
{
return version;
}
}
}

View File

@@ -1,95 +0,0 @@
using System;
using Wox.Infrastructure.Exception;
namespace Wox.Core.Updater
{
public class SemanticVersion : IComparable
{
public int MAJOR { get; set; }
public int MINOR { get; set; }
public int PATCH { get; set; }
public SemanticVersion(Version version)
{
MAJOR = version.Major;
MINOR = version.Minor;
PATCH = version.Build;
}
public SemanticVersion(int major, int minor, int patch)
{
MAJOR = major;
MINOR = minor;
PATCH = patch;
}
public SemanticVersion(string version)
{
var strings = version.Split('.');
if (strings.Length != 3)
{
throw new WoxException("Invalid semantic version");
}
MAJOR = int.Parse(strings[0]);
MINOR = int.Parse(strings[1]);
PATCH = int.Parse(strings[2]);
}
public static bool operator >(SemanticVersion v1, SemanticVersion v2)
{
return v1.CompareTo(v2) > 0;
}
public static bool operator <(SemanticVersion v1, SemanticVersion v2)
{
return v1.CompareTo(v2) < 0;
}
public static bool operator ==(SemanticVersion v1, SemanticVersion v2)
{
if (ReferenceEquals(v1, null))
{
return ReferenceEquals(v2, null);
}
if (ReferenceEquals(v2, null))
{
return false;
}
return v1.Equals(v2);
}
public static bool operator !=(SemanticVersion v1, SemanticVersion v2)
{
return !(v1 == v2);
}
public override string ToString()
{
return string.Format("{0}.{1}.{2}", MAJOR, MINOR, PATCH);
}
public override bool Equals(object version)
{
var v2 = (SemanticVersion)version;
return MAJOR == v2.MAJOR && MINOR == v2.MINOR && PATCH == v2.PATCH;
}
public int CompareTo(object version)
{
var v2 = (SemanticVersion)version;
if (MAJOR == v2.MAJOR)
{
if (MINOR == v2.MINOR)
{
if (PATCH == v2.PATCH)
{
return 0;
}
return PATCH - v2.PATCH;
}
return MINOR - v2.MINOR;
}
return MAJOR - v2.MAJOR;
}
}
}

View File

@@ -1,182 +0,0 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAppUpdate.Framework;
using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Sources;
using NAppUpdate.Framework.Tasks;
using Newtonsoft.Json;
using Wox.Core.Resource;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Http;
using Wox.Infrastructure.Logger;
namespace Wox.Core.Updater
{
public class UpdaterManager
{
private static UpdaterManager instance;
private const string VersionCheckURL = "http://api.getwox.com/release/latest/";
private const string UpdateFeedURL = "http://upgrade.getwox.com/update.xml";
//private const string UpdateFeedURL = "http://127.0.0.1:8888/update.xml";
private static SemanticVersion currentVersion;
public UserSettings.Settings Settings { get; set; }
public event EventHandler PrepareUpdateReady;
public event EventHandler UpdateError;
public Release NewRelease { get; set; }
public static UpdaterManager Instance
{
get
{
if (instance == null)
{
instance = new UpdaterManager();
}
return instance;
}
}
private UpdaterManager()
{
UpdateManager.Instance.UpdateSource = GetUpdateSource();
}
public SemanticVersion CurrentVersion
{
get
{
if (currentVersion == null)
{
currentVersion = new SemanticVersion(Assembly.GetExecutingAssembly().GetName().Version);
}
return currentVersion;
}
}
private bool IsNewerThanCurrent(Release release)
{
if (release == null) return false;
return new SemanticVersion(release.version) > CurrentVersion;
}
public List<string> GetAvailableUpdateFiles()
{
List<string> files = new List<string>();
foreach (var task in UpdateManager.Instance.Tasks)
{
if (task is FileUpdateTask)
{
files.Add(((FileUpdateTask)task).LocalPath);
}
}
return files;
}
public void CheckUpdate()
{
Task.Run(() =>
{
string json = HttpRequest.Get(VersionCheckURL, HttpProxy.Instance);
if (!string.IsNullOrEmpty(json))
{
try
{
NewRelease = JsonConvert.DeserializeObject<Release>(json);
if (IsNewerThanCurrent(NewRelease) && !Settings.DontPromptUpdateMsg)
{
StartUpdate();
}
}
catch (Exception e)
{
Log.Error(e);
}
}
});
}
private void StartUpdate()
{
UpdateManager updManager = UpdateManager.Instance;
updManager.BeginCheckForUpdates(asyncResult =>
{
if (asyncResult.IsCompleted)
{
// still need to check for caught exceptions if any and rethrow
try
{
((UpdateProcessAsyncResult)asyncResult).EndInvoke();
}
catch (Exception e)
{
updManager.CleanUp();
Log.Error(e);
return;
}
// No updates were found, or an error has occured. We might want to check that...
if (updManager.UpdatesAvailable == 0)
{
return;
}
}
updManager.BeginPrepareUpdates(result =>
{
((UpdateProcessAsyncResult)result).EndInvoke();
OnPrepareUpdateReady();
}, null);
}, null);
}
public void CleanUp()
{
UpdateManager.Instance.CleanUp();
}
public void ApplyUpdates()
{
// ApplyUpdates is a synchronous method by design. Make sure to save all user work before calling
// it as it might restart your application
// get out of the way so the console window isn't obstructed
try
{
UpdateManager.Instance.ApplyUpdates(true, Settings.EnableUpdateLog, false);
}
catch (Exception e)
{
string updateError = InternationalizationManager.Instance.GetTranslation("update_wox_update_error");
Log.Error(e);
MessageBox.Show(updateError);
OnUpdateError();
}
UpdateManager.Instance.CleanUp();
}
private IUpdateSource GetUpdateSource()
{
var source = new WoxUpdateSource(UpdateFeedURL, HttpRequest.GetWebProxy(HttpProxy.Instance));
return source;
}
protected virtual void OnPrepareUpdateReady()
{
var handler = PrepareUpdateReady;
if (handler != null) handler(this, EventArgs.Empty);
}
protected virtual void OnUpdateError()
{
var handler = UpdateError;
if (handler != null) handler(this, EventArgs.Empty);
}
}
}

View File

@@ -1,65 +0,0 @@
using System;
using System.IO;
using System.Net;
using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Sources;
using NAppUpdate.Framework.Utils;
namespace Wox.Core.Updater
{
internal class WoxUpdateSource : IUpdateSource
{
public IWebProxy Proxy { get; set; }
public string FeedUrl { get; set; }
public WoxUpdateSource(string feedUrl,IWebProxy proxy)
{
FeedUrl = feedUrl;
Proxy = proxy;
}
private void TryResolvingHost()
{
Uri uri = new Uri(FeedUrl);
try
{
Dns.GetHostEntry(uri.Host);
}
catch (Exception ex)
{
throw new WebException(string.Format("Failed to resolve {0}. Check your connectivity.", uri.Host), WebExceptionStatus.ConnectFailure);
}
}
public string GetUpdatesFeed()
{
TryResolvingHost();
string str = string.Empty;
WebRequest webRequest = WebRequest.Create(FeedUrl);
webRequest.Method = "GET";
webRequest.Proxy = Proxy;
using (WebResponse response = webRequest.GetResponse())
{
Stream responseStream = response.GetResponseStream();
if (responseStream != null)
{
using (StreamReader streamReader = new StreamReader(responseStream, true))
str = streamReader.ReadToEnd();
}
}
return str;
}
public bool GetData(string url, string baseUrl, Action<UpdateProgressInfo> onProgress, ref string tempLocation)
{
if (!string.IsNullOrEmpty(baseUrl) && !baseUrl.EndsWith("/"))
baseUrl += "/";
FileDownloader fileDownloader = !Uri.IsWellFormedUriString(url, UriKind.Absolute) ? (!Uri.IsWellFormedUriString(baseUrl, UriKind.Absolute) ? (string.IsNullOrEmpty(baseUrl) ? new FileDownloader(url) : new FileDownloader(new Uri(new Uri(baseUrl), url))) : new FileDownloader(new Uri(new Uri(baseUrl, UriKind.Absolute), url))) : new FileDownloader(url);
fileDownloader.Proxy = Proxy;
if (string.IsNullOrEmpty(tempLocation) || !Directory.Exists(Path.GetDirectoryName(tempLocation)))
tempLocation = Path.GetTempFileName();
return fileDownloader.DownloadToFile(tempLocation, onProgress);
}
}
}

View File

@@ -67,9 +67,6 @@
<Compile Include="APIServer.cs" />
<Compile Include="Plugin\ExecutablePlugin.cs" />
<Compile Include="Plugin\PluginsLoader.cs" />
<Compile Include="Updater\Release.cs" />
<Compile Include="Updater\UpdaterManager.cs" />
<Compile Include="Updater\WoxUpdateSource.cs" />
<Compile Include="UserSettings\HttpProxy.cs" />
<Compile Include="Resource\AvailableLanguages.cs" />
<Compile Include="Resource\Internationalization.cs" />
@@ -90,7 +87,6 @@
<Compile Include="UserSettings\PluginSettings.cs" />
<Compile Include="UserSettings\PluginHotkey.cs" />
<Compile Include="UserSettings\Settings.cs" />
<Compile Include="Updater\SemanticVersion.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />