diff --git a/Deploy/squirrel_installer.ps1 b/Deploy/squirrel_installer.ps1 index 9c1d010d1..160e062ec 100644 --- a/Deploy/squirrel_installer.ps1 +++ b/Deploy/squirrel_installer.ps1 @@ -1,9 +1,12 @@ +# msbuild based installer generation is not working in appveyor, not sure why + $currentPath = Convert-Path . Write-Host "Current path: " + $currentPath $path = $env:APPVEYOR_BUILD_FOLDER + "\Deploy\wox.nuspec" Write-Host "nuspec path: " + $path -& nuget.exe pack $path -Version $env:APPVEYOR_BUILD_VERSION -Properties Configuration=Release +$releasePath = $env:APPVEYOR_BUILD_FOLDER + "\Output\Release" +& nuget.exe pack $path -Version $env:APPVEYOR_BUILD_VERSION -Properties Configuration=Release -BasePath $releasePath $nupkgPath = $env:APPVEYOR_BUILD_FOLDER + "\Wox." + $env:APPVEYOR_BUILD_VERSION + ".nupkg" Write-Host "nupkg path: " + $nupkgPath @@ -12,4 +15,4 @@ Write-Host "nupkg path: " + $nupkgPath $squirrelPath = $env:APPVEYOR_BUILD_FOLDER + "\packages\squirrel*\tools\Squirrel.com" Write-Host "squirrel path: " + $squirrelPath $iconPath = $env:APPVEYOR_BUILD_FOLDER + "\Wox\Resources\app.ico" -& $squirrelPath --releasify $nupkgPath --setupIcon $iconPath --no-msi +& $squirrelPath --releasify $nupkgPath --setupIcon $iconPath --no-msi \ No newline at end of file diff --git a/Deploy/wox.nuspec b/Deploy/wox.nuspec index 448cc8ea3..681099663 100644 --- a/Deploy/wox.nuspec +++ b/Deploy/wox.nuspec @@ -11,6 +11,6 @@ Wox - a launcher for windows - + diff --git a/Plugins/Wox.Plugin.WebSearch/Main.cs b/Plugins/Wox.Plugin.WebSearch/Main.cs index 5d08fa5ac..e99d61529 100644 --- a/Plugins/Wox.Plugin.WebSearch/Main.cs +++ b/Plugins/Wox.Plugin.WebSearch/Main.cs @@ -85,10 +85,10 @@ namespace Wox.Plugin.WebSearch if (_settings.EnableWebSearchSuggestion) { const int waittime = 300; - var task = Task.Run(() => + var task = Task.Run(async () => { - results.AddRange(ResultsFromSuggestions(keyword, subtitle, webSearch)); - + var suggestions = await Suggestions(keyword, subtitle, webSearch); + results.AddRange(suggestions); }, _updateToken); if (!task.Wait(waittime)) @@ -102,12 +102,12 @@ namespace Wox.Plugin.WebSearch } } - private IEnumerable ResultsFromSuggestions(string keyword, string subtitle, WebSearch webSearch) + private async Task> Suggestions(string keyword, string subtitle, WebSearch webSearch) { var source = SuggestionSource.GetSuggestionSource(_settings.WebSearchSuggestionSource, Context); - var suggestions = source?.GetSuggestions(keyword); - if (suggestions != null) + if (source != null) { + var suggestions = await source.GetSuggestions(keyword); var resultsFromSuggestion = suggestions.Select(o => new Result { Title = o, diff --git a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs index c4a472ac9..d05d7287f 100644 --- a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs +++ b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs @@ -2,9 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Wox.Infrastructure.Http; +using Wox.Infrastructure.Logger; namespace Wox.Plugin.WebSearch.SuggestionSources { @@ -14,20 +16,24 @@ namespace Wox.Plugin.WebSearch.SuggestionSources Regex reg = new Regex("window.baidu.sug\\((.*)\\)"); - public override List GetSuggestions(string query) + public override async Task> GetSuggestions(string query) { - var result = HttpRequest.Get("http://suggestion.baidu.com/su?json=1&wd=" + Uri.EscapeUriString(query), Proxy, "GB2312"); + var result = await HttpRequest.Get("http://suggestion.baidu.com/su?json=1&wd=" + Uri.EscapeUriString(query), Proxy, "GB2312"); if (string.IsNullOrEmpty(result)) return new List(); Match match = reg.Match(result); if (match.Success) { - JContainer json = null; + JContainer json; try { json = JsonConvert.DeserializeObject(match.Groups[1].Value) as JContainer; } - catch { } + catch (JsonSerializationException e) + { + Log.Error(e); + return new List(); + } if (json != null) { diff --git a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs index fd732375f..ab569219c 100644 --- a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs +++ b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs @@ -1,34 +1,39 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Wox.Infrastructure.Http; +using Wox.Infrastructure.Logger; namespace Wox.Plugin.WebSearch.SuggestionSources { public class Google : SuggestionSource { public override string Domain { get; set; } = "www.google.com"; - public override List GetSuggestions(string query) + public override async Task> GetSuggestions(string query) { - var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query), Proxy); + var result = await HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query), Proxy); if (string.IsNullOrEmpty(result)) return new List(); - + JContainer json; try { - JContainer json = JsonConvert.DeserializeObject(result) as JContainer; - if (json != null) + json = JsonConvert.DeserializeObject(result) as JContainer; + } + catch (JsonSerializationException e) + { + Log.Error(e); + return new List(); + } + if (json != null) + { + var results = json[1] as JContainer; + if (results != null) { - var results = json[1] as JContainer; - if (results != null) - { - return results.OfType().Select(o => o.Value).OfType().ToList(); - } + return results.OfType().Select(o => o.Value).OfType().ToList(); } } - catch { } - return new List(); } diff --git a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/ISuggestionSource.cs b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/ISuggestionSource.cs index 75556602e..8c654ecd4 100644 --- a/Plugins/Wox.Plugin.WebSearch/SuggestionSources/ISuggestionSource.cs +++ b/Plugins/Wox.Plugin.WebSearch/SuggestionSources/ISuggestionSource.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; namespace Wox.Plugin.WebSearch.SuggestionSources { @@ -12,7 +13,7 @@ namespace Wox.Plugin.WebSearch.SuggestionSources Proxy = httpProxy; } - public abstract List GetSuggestions(string query); + public abstract Task> GetSuggestions(string query); public static SuggestionSource GetSuggestionSource(string name, PluginInitContext context) { diff --git a/SolutionAssemblyInfo.cs b/SolutionAssemblyInfo.cs index 980e82176..0c060df81 100644 --- a/SolutionAssemblyInfo.cs +++ b/SolutionAssemblyInfo.cs @@ -15,6 +15,6 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] -[assembly: AssemblyVersion("1.2.0")] -[assembly: AssemblyFileVersion("1.2.0")] -[assembly: AssemblyInformationalVersion("1.2.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.0.*")] +[assembly: AssemblyFileVersion("1.2.0.*")] +[assembly: AssemblyInformationalVersion("1.2.0.*")] \ No newline at end of file diff --git a/Wox.Core/APIServer.cs b/Wox.Core/APIServer.cs deleted file mode 100644 index 7830d091a..000000000 --- a/Wox.Core/APIServer.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Wox.Core -{ - public static class APIServer - { - private static string BaseAPIURL = "http://api.getwox.com"; - public static string ErrorReportURL = BaseAPIURL + "/error/"; - public static string LastestReleaseURL = BaseAPIURL + "/release/latest/"; - } -} diff --git a/Wox.Core/Updater/Release.cs b/Wox.Core/Updater/Release.cs deleted file mode 100644 index 4808ffefb..000000000 --- a/Wox.Core/Updater/Release.cs +++ /dev/null @@ -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; - } - } -} \ No newline at end of file diff --git a/Wox.Core/Updater/SemanticVersion.cs b/Wox.Core/Updater/SemanticVersion.cs deleted file mode 100644 index 01012183d..000000000 --- a/Wox.Core/Updater/SemanticVersion.cs +++ /dev/null @@ -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; - } - } -} diff --git a/Wox.Core/Updater/UpdaterManager.cs b/Wox.Core/Updater/UpdaterManager.cs deleted file mode 100644 index 62ea31291..000000000 --- a/Wox.Core/Updater/UpdaterManager.cs +++ /dev/null @@ -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 GetAvailableUpdateFiles() - { - List files = new List(); - 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(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); - } - } -} diff --git a/Wox.Core/Updater/WoxUpdateSource.cs b/Wox.Core/Updater/WoxUpdateSource.cs deleted file mode 100644 index a9f86807d..000000000 --- a/Wox.Core/Updater/WoxUpdateSource.cs +++ /dev/null @@ -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 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); - } - } -} diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 78e8244d2..92b58b27c 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -64,12 +64,8 @@ Properties\SolutionAssemblyInfo.cs - - - - @@ -90,7 +86,6 @@ - diff --git a/Wox.CrashReporter/ReportWindow.xaml.cs b/Wox.CrashReporter/ReportWindow.xaml.cs index 584e73f3a..e16fc09bc 100644 --- a/Wox.CrashReporter/ReportWindow.xaml.cs +++ b/Wox.CrashReporter/ReportWindow.xaml.cs @@ -5,7 +5,7 @@ using System.Windows; using System.Windows.Documents; using Exceptionless; using Wox.Core.Resource; -using Wox.Core.Updater; +using Wox.Infrastructure; namespace Wox.CrashReporter { @@ -23,7 +23,7 @@ namespace Wox.CrashReporter private void SetException(Exception exception) { tbSummary.AppendText(exception.Message); - tbVersion.Text = UpdaterManager.Instance.CurrentVersion.ToString(); + tbVersion.Text = Infrastructure.Wox.Version; tbDatetime.Text = DateTime.Now.ToString(); tbStackTrace.AppendText(exception.StackTrace); tbSource.Text = exception.Source; diff --git a/Wox.CrashReporter/Wox.CrashReporter.csproj b/Wox.CrashReporter/Wox.CrashReporter.csproj index 6a9d6ae48..dd4269796 100644 --- a/Wox.CrashReporter/Wox.CrashReporter.csproj +++ b/Wox.CrashReporter/Wox.CrashReporter.csproj @@ -78,6 +78,10 @@ {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} Wox.Core + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + diff --git a/Wox.Infrastructure/Exception/ExceptionFormatter.cs b/Wox.Infrastructure/Exception/ExceptionFormatter.cs index ce232d07d..5c472b5fc 100644 --- a/Wox.Infrastructure/Exception/ExceptionFormatter.cs +++ b/Wox.Infrastructure/Exception/ExceptionFormatter.cs @@ -14,6 +14,7 @@ namespace Wox.Infrastructure.Exception return CreateExceptionReport(exception); } + //todo log /display line by line private static string CreateExceptionReport(System.Exception ex) { var sb = new StringBuilder(); @@ -84,7 +85,21 @@ namespace Wox.Infrastructure.Exception sb.Append("* "); sb.Append(ass.FullName); sb.Append(" ("); - sb.Append(string.IsNullOrEmpty(ass.Location) ? "not supported" : ass.Location); + + if (ass.IsDynamic) + { + sb.Append("dynamic assembly doesn't has location"); + } + else if (string.IsNullOrEmpty(ass.Location)) + { + sb.Append("location is null or empty"); + + } + else + { + sb.Append(ass.Location); + + } sb.AppendLine(")"); } diff --git a/Wox.Infrastructure/Http/HttpRequest.cs b/Wox.Infrastructure/Http/HttpRequest.cs index 1142f217f..6dd7030af 100644 --- a/Wox.Infrastructure/Http/HttpRequest.cs +++ b/Wox.Infrastructure/Http/HttpRequest.cs @@ -1,120 +1,79 @@ -using System.IO; +using System; +using System.IO; using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; using System.Text; +using System.Threading.Tasks; +using JetBrains.Annotations; using Wox.Infrastructure.Logger; using Wox.Plugin; namespace Wox.Infrastructure.Http { - public class HttpRequest + public static class HttpRequest { - public static string Get(string url, IHttpProxy proxy, string encoding = "UTF-8") - { - return Get(url, encoding, proxy); - } - - public static WebProxy GetWebProxy(IHttpProxy proxy) + private static WebProxy GetWebProxy(IHttpProxy proxy) { if (proxy != null && proxy.Enabled && !string.IsNullOrEmpty(proxy.Server)) { if (string.IsNullOrEmpty(proxy.UserName) || string.IsNullOrEmpty(proxy.Password)) { - return new WebProxy(proxy.Server, proxy.Port); - } - - return new WebProxy(proxy.Server, proxy.Port) - { - Credentials = new NetworkCredential(proxy.UserName, proxy.Password) - }; - } - - return null; - } - - private static string Get(string url, string encoding, IHttpProxy proxy) - { - if (string.IsNullOrEmpty(url)) return string.Empty; - - HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; - request.Method = "GET"; - request.Timeout = 10 * 1000; - request.Proxy = GetWebProxy(proxy); - - try - { - HttpWebResponse response = request.GetResponse() as HttpWebResponse; - if (response != null) - { - Stream stream = response.GetResponseStream(); - if (stream != null) - { - using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(encoding))) - { - return reader.ReadToEnd(); - } - } - } - } - catch (System.Exception e) - { - Log.Error(e); - return string.Empty; - } - - return string.Empty; - } - - public static string Post(string url, string jsonData, IHttpProxy proxy) - { - if (string.IsNullOrEmpty(url)) return string.Empty; - - HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; - request.Method = "POST"; - request.ContentType = "text/json"; - request.Timeout = 10 * 1000; - if (proxy != null && proxy.Enabled && !string.IsNullOrEmpty(proxy.Server)) - { - if (string.IsNullOrEmpty(proxy.UserName) || string.IsNullOrEmpty(proxy.Password)) - { - request.Proxy = new WebProxy(proxy.Server, proxy.Port); + var webProxy = new WebProxy(proxy.Server, proxy.Port); + return webProxy; } else { - request.Proxy = new WebProxy(proxy.Server, proxy.Port) + var webProxy = new WebProxy(proxy.Server, proxy.Port) { Credentials = new NetworkCredential(proxy.UserName, proxy.Password) }; + return webProxy; } } - using (var streamWriter = new StreamWriter(request.GetRequestStream())) + else { - streamWriter.Write(jsonData); - streamWriter.Flush(); - streamWriter.Close(); + return null; } + } + public static async Task Get([NotNull] string url, IHttpProxy proxy, string encoding = "UTF-8") + { + + HttpWebRequest request = WebRequest.CreateHttp(url); + request.Method = "GET"; + request.Timeout = 10 * 1000; + request.Proxy = GetWebProxy(proxy); + request.UserAgent = @"Mozilla/5.0 (Trident/7.0; rv:11.0) like Gecko"; + HttpWebResponse response; try { - HttpWebResponse response = request.GetResponse() as HttpWebResponse; - if (response != null) - { - Stream stream = response.GetResponseStream(); - if (stream != null) - { - using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8"))) - { - return reader.ReadToEnd(); - } - } - } + response = await request.GetResponseAsync() as HttpWebResponse; } - catch (System.Exception e) + catch (WebException e) { Log.Error(e); return string.Empty; } - - return string.Empty; + if (response != null) + { + var stream = response.GetResponseStream(); + if (stream != null) + { + using (var reader = new StreamReader(stream, Encoding.GetEncoding(encoding))) + { + return await reader.ReadToEndAsync(); + } + } + else + { + return string.Empty; + } + } + else + { + return string.Empty; + } } } } \ No newline at end of file diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index dcdb0e2be..77653ce8a 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -57,6 +57,7 @@ + diff --git a/Wox.Infrastructure/Wox.cs b/Wox.Infrastructure/Wox.cs index 3e04189da..c6353acfb 100644 --- a/Wox.Infrastructure/Wox.cs +++ b/Wox.Infrastructure/Wox.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Reflection; @@ -10,11 +11,13 @@ namespace Wox.Infrastructure public const string Plugins = "Plugins"; public const string Settings = "Settings"; - public static readonly string ProgramPath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString(); + private static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); + public static readonly string ProgramPath = Directory.GetParent(Assembly.Location).ToString(); public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Name); public static readonly string UserDirectory = Path.Combine(DataPath, Plugins); public static readonly string PreinstalledDirectory = Path.Combine(ProgramPath, Plugins); public static readonly string SettingsPath = Path.Combine(DataPath, Settings); public const string Github = "https://github.com/Wox-launcher/Wox"; + public static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion; } } diff --git a/Wox.Test/SemanticVersionTest.cs b/Wox.Test/SemanticVersionTest.cs deleted file mode 100644 index 5b7097b69..000000000 --- a/Wox.Test/SemanticVersionTest.cs +++ /dev/null @@ -1,23 +0,0 @@ -using NUnit.Framework; -using Wox.Core.Updater; - -namespace Wox.Test -{ - [TestFixture] - public class SemanticVersionTest - { - [Test] - public void CompareTest() - { - SemanticVersion v1 = new SemanticVersion(1, 1, 0); - SemanticVersion v2 = new SemanticVersion(1, 2, 0); - SemanticVersion v3 = new SemanticVersion(1, 1, 0); - SemanticVersion v4 = new SemanticVersion("1.1.0"); - Assert.IsTrue(v1 < v2); - Assert.IsTrue(v2 > v1); - Assert.IsTrue(v1 == v3); - Assert.IsTrue(v1.Equals(v3)); - Assert.IsTrue(v1 == v4); - } - } -} diff --git a/Wox.Test/Wox.Test.csproj b/Wox.Test/Wox.Test.csproj index e1b65e45b..0827bde5a 100644 --- a/Wox.Test/Wox.Test.csproj +++ b/Wox.Test/Wox.Test.csproj @@ -52,7 +52,6 @@ - diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 842bd91a4..2412eb3d9 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Net; using System.Windows; using Squirrel; using Wox.Core.Plugin; @@ -57,14 +58,26 @@ namespace Wox { try { - using (Updater = await UpdateManager.GitHubUpdateManager(Infrastructure.Wox.Github, prerelease: true)) + using (Updater = await UpdateManager.GitHubUpdateManager(Infrastructure.Wox.Github)) { await Updater.UpdateApp(); } } + catch (WebException ex) + { + Log.Error(ex); + } catch (Exception exception) { - Log.Error(exception); + const string info = "Update.exe not found, not a Squirrel-installed app?"; + if (exception.Message == info) + { + Log.Warn(info); + } + else + { + throw; + } } } diff --git a/Wox/CommandArgs/CommandArgsFactory.cs b/Wox/CommandArgs/CommandArgsFactory.cs deleted file mode 100644 index 2b7a7b8b5..000000000 --- a/Wox/CommandArgs/CommandArgsFactory.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Wox.Helper; - -namespace Wox.CommandArgs -{ - internal static class CommandArgsFactory - { - private static List commandArgs; - - static CommandArgsFactory() - { - var type = typeof(ICommandArg); - commandArgs = Assembly.GetExecutingAssembly() - .GetTypes() - .Where(p => type.IsAssignableFrom(p) && !p.IsInterface) - .Select(t => Activator.CreateInstance(t) as ICommandArg).ToList(); - } - - public static void Execute(IList args) - { - // todo restart command line args? - //if (args.Count > 0 && args[0] != SingleInstance.Restart) - if (args.Count > 0) - { - string command = args[0]; - ICommandArg cmd = commandArgs.FirstOrDefault(o => o.Command.ToLower() == command); - if (cmd != null) - { - args.RemoveAt(0); //remove command itself - cmd.Execute(args); - } - } - else - { - App.API.ShowApp(); - } - } - } -} diff --git a/Wox/CommandArgs/HideStartCommandArg.cs b/Wox/CommandArgs/HideStartCommandArg.cs deleted file mode 100644 index 1918858b1..000000000 --- a/Wox/CommandArgs/HideStartCommandArg.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections.Generic; - -namespace Wox.CommandArgs -{ - public class HideStartCommandArg : ICommandArg - { - public string Command - { - get { return "hidestart"; } - } - - public void Execute(IList args) - { - //App.Window.ShowApp(); - //App.Window.HideApp(); - } - } -} diff --git a/Wox/CommandArgs/ICommandArg.cs b/Wox/CommandArgs/ICommandArg.cs deleted file mode 100644 index 11db54557..000000000 --- a/Wox/CommandArgs/ICommandArg.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; - -namespace Wox.CommandArgs -{ - interface ICommandArg - { - string Command { get; } - void Execute(IList args); - } -} diff --git a/Wox/CommandArgs/InstallPluginCommandArg.cs b/Wox/CommandArgs/InstallPluginCommandArg.cs deleted file mode 100644 index 524115b4d..000000000 --- a/Wox/CommandArgs/InstallPluginCommandArg.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Windows; -using Wox.Core.Plugin; - -namespace Wox.CommandArgs -{ - public class InstallPluginCommandArg : ICommandArg - { - public string Command - { - get { return "installplugin"; } - } - - public void Execute(IList args) - { - if (args.Count > 0) - { - var path = args[0]; - if (!File.Exists(path)) - { - MessageBox.Show("Plugin " + path + " didn't exist"); - return; - } - PluginManager.InstallPlugin(path); - } - } - } -} \ No newline at end of file diff --git a/Wox/CommandArgs/QueryCommandArg.cs b/Wox/CommandArgs/QueryCommandArg.cs deleted file mode 100644 index d1df8e0a5..000000000 --- a/Wox/CommandArgs/QueryCommandArg.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Wox.CommandArgs -{ - public class QueryCommandArg : ICommandArg - { - public string Command - { - get { return "query"; } - } - - public void Execute(IList args) - { - Console.WriteLine("test"); - if (args.Count > 0) - { - string query = args[0]; - App.API.ChangeQuery(query); - } - App.API.ShowApp(); - } - } -} diff --git a/Wox/CommandArgs/ToggleCommandArg.cs b/Wox/CommandArgs/ToggleCommandArg.cs deleted file mode 100644 index e50931629..000000000 --- a/Wox/CommandArgs/ToggleCommandArg.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; - -namespace Wox.CommandArgs -{ - public class ToggleCommandArg:ICommandArg - { - public string Command - { - get { return "toggle"; } - } - - public void Execute(IList args) - { - if (App.Window.IsVisible) - { - App.API.HideApp(); - } - else - { - App.API.ShowApp(); - } - } - } -} diff --git a/Wox/Languages/en.xaml b/Wox/Languages/en.xaml index 71065ba6b..35d0a80db 100644 --- a/Wox/Languages/en.xaml +++ b/Wox/Languages/en.xaml @@ -78,6 +78,9 @@ About Website Version + Check Updates + New Version {0} avaiable, please restart + Release Notes: You have activated Wox {0} times diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index cf9e20e62..4d94ef8d9 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -7,7 +7,6 @@ using System.Windows.Media.Animation; using System.Windows.Controls; using Wox.Core.Plugin; using Wox.Core.Resource; -using Wox.Core.Updater; using Wox.Core.UserSettings; using Wox.Helper; using Wox.Infrastructure.Hotkey; @@ -47,8 +46,6 @@ namespace Wox private void OnLoaded(object sender, RoutedEventArgs _) { - CheckUpdate(); - InitProgressbarAnimation(); WindowIntelopHelper.DisableControlBox(this); @@ -110,27 +107,6 @@ namespace Wox return top; } - private void CheckUpdate() - { - UpdaterManager.Instance.PrepareUpdateReady += OnPrepareUpdateReady; - UpdaterManager.Instance.UpdateError += OnUpdateError; - UpdaterManager.Instance.CheckUpdate(); - } - - void OnUpdateError(object sender, EventArgs e) - { - string updateError = InternationalizationManager.Instance.GetTranslation("update_wox_update_error"); - MessageBox.Show(updateError); - } - - private void OnPrepareUpdateReady(object sender, EventArgs e) - { - Dispatcher.Invoke(() => - { - new WoxUpdate().ShowDialog(); - }); - } - private void InitProgressbarAnimation() { var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index 500df1217..c4626cba8 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -68,6 +68,11 @@ namespace Wox public void RestarApp() { + HideWox(); + // we must force dispose application + // UpdateManager.RestartApp() will call Environment.Exit(0) + // which will cause ungraceful exit + ((IDisposable) Application.Current).Dispose(); UpdateManager.RestartApp(); } diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 9fd385ecf..45bd9442f 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -340,27 +340,42 @@ - - + + + + - - - - - - - - - + + + + + https://github.com/Wox-launcher/Wox + + + + + + + + + + + https://github.com/Wox-launcher/Wox/releases/latest + + + +