diff --git a/Doc/app.psd b/Doc/app.psd index 1694f8d5d..833fd6529 100644 Binary files a/Doc/app.psd and b/Doc/app.psd differ diff --git a/Doc/app_error.png b/Doc/app_error.png new file mode 100644 index 000000000..5106d6e8a Binary files /dev/null and b/Doc/app_error.png differ diff --git a/Doc/app_error.psd b/Doc/app_error.psd new file mode 100644 index 000000000..174e9cb62 Binary files /dev/null and b/Doc/app_error.psd differ diff --git a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj index c061fcc43..f4128edd7 100644 --- a/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj +++ b/Plugins/Wox.Plugin.WebSearch/Wox.Plugin.WebSearch.csproj @@ -1,144 +1,144 @@ - - - - - Debug - AnyCPU - {403B57F2-1856-4FC7-8A24-36AB346B763E} - Library - Properties - Wox.Plugin.WebSearch - Wox.Plugin.WebSearch - v3.5 - 512 - ..\..\ - true - - - true - full - false - ..\..\Output\Debug\Plugins\Wox.Plugin.WebSearch\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - ..\..\Output\Release\Plugins\Wox.Plugin.WebSearch\ - TRACE - prompt - 4 - - - - ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll - - - False - ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - WebSearchesSetting.xaml - - - - WebSearchSetting.xaml - - - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - PreserveNewest - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - - - - - - {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} - Wox.Core - - - {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} - Wox.Infrastructure - - - {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} - Wox.Plugin - - - - - - PreserveNewest - - - - - PreserveNewest - - - - - PreserveNewest - - - - - PreserveNewest - - - - - - - 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 - - - - + + + + + Debug + AnyCPU + {403B57F2-1856-4FC7-8A24-36AB346B763E} + Library + Properties + Wox.Plugin.WebSearch + Wox.Plugin.WebSearch + v3.5 + 512 + ..\..\ + true + + + true + full + false + ..\..\Output\Debug\Plugins\Wox.Plugin.WebSearch\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\Output\Release\Plugins\Wox.Plugin.WebSearch\ + TRACE + prompt + 4 + + + + ..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll + + + False + ..\..\packages\Newtonsoft.Json.6.0.7\lib\net35\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + WebSearchesSetting.xaml + + + + WebSearchSetting.xaml + + + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + PreserveNewest + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + + + + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} + Wox.Core + + + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} + Wox.Infrastructure + + + {8451ecdd-2ea4-4966-bb0a-7bbc40138e80} + Wox.Plugin + + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + \ No newline at end of file diff --git a/Wox.Core/APIServer.cs b/Wox.Core/APIServer.cs new file mode 100644 index 000000000..8aec75068 --- /dev/null +++ b/Wox.Core/APIServer.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +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/Version/SemanticVersion.cs b/Wox.Core/Version/SemanticVersion.cs new file mode 100644 index 000000000..9ba46238c --- /dev/null +++ b/Wox.Core/Version/SemanticVersion.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Wox.Core.Exception; + +namespace Wox.Core.Version +{ + public class SemanticVersion : IComparable + { + public int MAJOR { get; set; } + public int MINOR { get; set; } + public int PATCH { get; set; } + + public SemanticVersion(System.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/Version/VersionManager.cs b/Wox.Core/Version/VersionManager.cs new file mode 100644 index 000000000..994e46e16 --- /dev/null +++ b/Wox.Core/Version/VersionManager.cs @@ -0,0 +1,36 @@ +using System.Reflection; + +namespace Wox.Core.Version +{ + public class VersionManager + { + private static VersionManager versionManager; + private static SemanticVersion currentVersion; + + public static VersionManager Instance + { + get + { + if (versionManager == null) + { + versionManager = new VersionManager(); + } + return versionManager; + } + } + + private VersionManager() { } + + public SemanticVersion CurrentVersion + { + get + { + if (currentVersion == null) + { + currentVersion = new SemanticVersion(Assembly.GetExecutingAssembly().GetName().Version); + } + return currentVersion; + } + } + } +} diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 21cad4e12..d58b7a7a9 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -53,6 +53,7 @@ + @@ -89,6 +90,8 @@ + + diff --git a/Wox.CrashReporter/CrashReporter.cs b/Wox.CrashReporter/CrashReporter.cs new file mode 100644 index 000000000..3ca1e9b54 --- /dev/null +++ b/Wox.CrashReporter/CrashReporter.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.CrashReporter +{ + public class CrashReporter + { + private Exception exception; + + public CrashReporter(Exception e) + { + exception = e; + } + + public void Show() + { + if (exception == null) return; + + ReportWindow reportWindow = new ReportWindow(exception); + reportWindow.Show(); + } + } +} diff --git a/Wox.CrashReporter/Images/app_error.png b/Wox.CrashReporter/Images/app_error.png new file mode 100644 index 000000000..5106d6e8a Binary files /dev/null and b/Wox.CrashReporter/Images/app_error.png differ diff --git a/Wox.CrashReporter/Images/crash_go.png b/Wox.CrashReporter/Images/crash_go.png new file mode 100644 index 000000000..f71e37a32 Binary files /dev/null and b/Wox.CrashReporter/Images/crash_go.png differ diff --git a/Wox.CrashReporter/Images/crash_stop.png b/Wox.CrashReporter/Images/crash_stop.png new file mode 100644 index 000000000..807117fc6 Binary files /dev/null and b/Wox.CrashReporter/Images/crash_stop.png differ diff --git a/Wox.CrashReporter/Images/crash_warning.png b/Wox.CrashReporter/Images/crash_warning.png new file mode 100644 index 000000000..b1b5f0acd Binary files /dev/null and b/Wox.CrashReporter/Images/crash_warning.png differ diff --git a/Wox.CrashReporter/Properties/AssemblyInfo.cs b/Wox.CrashReporter/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..688a8e327 --- /dev/null +++ b/Wox.CrashReporter/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Wox.CrashReporter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Wox.CrashReporter")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("0ea3743c-2c0d-4b13-b9ce-e5e1f85aea23")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Wox.CrashReporter/ReportWindow.xaml b/Wox.CrashReporter/ReportWindow.xaml new file mode 100644 index 000000000..ae0e2fe0e --- /dev/null +++ b/Wox.CrashReporter/ReportWindow.xaml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wox.CrashReporter/ReportWindow.xaml.cs b/Wox.CrashReporter/ReportWindow.xaml.cs new file mode 100644 index 000000000..63a65bfc7 --- /dev/null +++ b/Wox.CrashReporter/ReportWindow.xaml.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Wox.Core; +using Wox.Core.Exception; +using Wox.Core.UI; +using Wox.Core.UserSettings; +using Wox.Core.Version; +using Wox.Infrastructure.Http; + +namespace Wox.CrashReporter +{ + internal partial class ReportWindow : IUIResource + { + private Exception exception; + + public ReportWindow(Exception exception) + { + this.exception = exception; + InitializeComponent(); + SetException(exception); + } + + private void SetException(Exception exception) + { + tbSummary.AppendText(exception.Message); + tbVersion.Text = VersionManager.Instance.CurrentVersion.ToString(); + tbDatetime.Text = DateTime.Now.ToString(); + tbStackTrace.AppendText(exception.StackTrace); + tbSource.Text = exception.Source; + tbType.Text = exception.GetType().ToString(); + } + + public ResourceDictionary GetResourceDictionary() + { + return null; + } + + private void btnSend_Click(object sender, RoutedEventArgs e) + { + tbSendReport.Content = "Sending"; + btnSend.IsEnabled = false; + string error = string.Format("{{\"data\":{0}}}", ExceptionFormatter.FormatExcpetion(exception)); + string response = HttpRequest.Post(APIServer.ErrorReportURL, error, HttpProxy.Instance); + } + + private void btnCancel_Click(object sender, RoutedEventArgs e) + { + Close(); + } + } +} diff --git a/Wox.CrashReporter/Wox.CrashReporter.csproj b/Wox.CrashReporter/Wox.CrashReporter.csproj new file mode 100644 index 000000000..708c75f91 --- /dev/null +++ b/Wox.CrashReporter/Wox.CrashReporter.csproj @@ -0,0 +1,112 @@ + + + + + Debug + AnyCPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC} + Library + Properties + Wox.CrashReporter + Wox.CrashReporter + v3.5 + 512 + ..\ + true + + + true + full + false + ..\Output\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\Output\Release\ + TRACE + prompt + 4 + + + + False + ..\packages\log4net.2.0.3\lib\net35-full\log4net.dll + + + + + + + + + + + + + + + + ReportWindow.xaml + + + + + Designer + MSBuild:Compile + + + + + {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} + Wox.Core + + + {4FD29318-A8AB-4D8F-AA47-60BC241B8DA3} + Wox.Infrastructure + + + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80} + Wox.Plugin + + + + + PreserveNewest + + + PreserveNewest + + + + + PreserveNewest + + + + + PreserveNewest + + + + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + \ No newline at end of file diff --git a/Wox.CrashReporter/packages.config b/Wox.CrashReporter/packages.config new file mode 100644 index 000000000..7eb67aa24 --- /dev/null +++ b/Wox.CrashReporter/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Wox.Infrastructure/Http/HttpRequest.cs b/Wox.Infrastructure/Http/HttpRequest.cs index eaec09f0f..5c08377d6 100644 --- a/Wox.Infrastructure/Http/HttpRequest.cs +++ b/Wox.Infrastructure/Http/HttpRequest.cs @@ -53,6 +53,60 @@ private static string Get(string url, string encoding, IHttpProxy proxy) } catch (Exception e) { + Logger.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); + } + else + { + request.Proxy = new WebProxy(proxy.Server, proxy.Port) + { + Credentials = new NetworkCredential(proxy.UserName, proxy.Password) + }; + } + } + using (var streamWriter = new StreamWriter(request.GetRequestStream())) + { + streamWriter.Write(jsonData); + streamWriter.Flush(); + streamWriter.Close(); + } + + 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(); + } + } + } + } + catch (Exception e) + { + Logger.Log.Error(e); return string.Empty; } diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index 1144ac5b9..52fd73176 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -13,6 +13,11 @@ public static void Error(string msg) fileLogger.Error(msg); } + public static void Error(Exception e) + { + fileLogger.Error(e.Message + "\r\n" + e.StackTrace); + } + public static void Debug(string msg) { fileLogger.Debug(msg); diff --git a/Wox.Test/SemanticVersionTest.cs b/Wox.Test/SemanticVersionTest.cs new file mode 100644 index 000000000..c4abdcbbd --- /dev/null +++ b/Wox.Test/SemanticVersionTest.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using Wox.Core.Version; + +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 e6f189a01..b2b4ef604 100644 --- a/Wox.Test/Wox.Test.csproj +++ b/Wox.Test/Wox.Test.csproj @@ -50,6 +50,7 @@ + diff --git a/Wox.sln b/Wox.sln index cbbf9ec2d..089fe39c8 100644 --- a/Wox.sln +++ b/Wox.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 +VisualStudioVersion = 12.0.30723.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Test", "Wox.Test\Wox.Test.csproj", "{FF742965-9A80-41A5-B042-D6C7D3A21708}" EndProject @@ -37,6 +37,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Url", "Plugins\W EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Color", "Plugins\Wox.Plugin.Color\Wox.Plugin.Color.csproj", "{F35190AA-4758-4D9E-A193-E3BDF6AD3567}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.CrashReporter", "Wox.CrashReporter\Wox.CrashReporter.csproj", "{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -107,6 +109,10 @@ Global {F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Debug|Any CPU.Build.0 = Debug|Any CPU {F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Release|Any CPU.ActiveCfg = Release|Any CPU {F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Release|Any CPU.Build.0 = Release|Any CPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Wox/App.config b/Wox/App.config index 83d95cfff..2725471d1 100644 --- a/Wox/App.config +++ b/Wox/App.config @@ -3,9 +3,6 @@
- - - @@ -36,4 +33,4 @@ - + \ No newline at end of file diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 8b4f9af49..602fd1971 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -5,7 +5,6 @@ using System.Threading; using Wox.CommandArgs; using Wox.Helper; -using Wox.Helper.ErrorReporting; using Application = System.Windows.Application; using MessageBox = System.Windows.MessageBox; using StartupEventArgs = System.Windows.StartupEventArgs; diff --git a/Wox/Helper/ErrorReporting.cs b/Wox/Helper/ErrorReporting.cs new file mode 100644 index 000000000..af7b47b9a --- /dev/null +++ b/Wox/Helper/ErrorReporting.cs @@ -0,0 +1,35 @@ +using System; +using System.Diagnostics; +using System.Windows; +using System.Windows.Forms; +using System.Windows.Threading; +using Wox.Core.Exception; +using Wox.Infrastructure.Logger; + +namespace Wox.Helper +{ + public static class ErrorReporting + { + private static void Report(Exception e) + { + //if (Debugger.IsAttached) return; + Log.Error(ExceptionFormatter.FormatExcpetion(e)); + new CrashReporter.CrashReporter(e).Show(); + } + + public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e) + { + Report((Exception)e.ExceptionObject); + } + + public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + Report(e.Exception); + } + + public static void ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) + { + Report(e.Exception); + } + } +} diff --git a/Wox/Helper/ErrorReporting/ErrorReporting.cs b/Wox/Helper/ErrorReporting/ErrorReporting.cs deleted file mode 100644 index a373edb4d..000000000 --- a/Wox/Helper/ErrorReporting/ErrorReporting.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Forms; -using System.Windows.Threading; -using System.Xml; -using Microsoft.Win32; -using Wox.Core.Exception; -using Wox.Infrastructure.Logger; - -namespace Wox.Helper.ErrorReporting -{ - public static class ErrorReporting - { - public static void UnhandledExceptionHandle(object sender, System.UnhandledExceptionEventArgs e) - { - if (Debugger.IsAttached) return; - - string error = ExceptionFormatter.FormatExcpetion(e.ExceptionObject); - //e.IsTerminating is always true in most times, so try to avoid use this property - //http://stackoverflow.com/questions/10982443/what-causes-the-unhandledexceptioneventargs-isterminating-flag-to-be-true-or-fal - Log.Error(error); - TryShowErrorMessageBox(error, e.ExceptionObject); - } - - public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) - { - if (Debugger.IsAttached) return; - - e.Handled = true; - string error = ExceptionFormatter.FormatExcpetion(e.Exception); - - Log.Error(error); - TryShowErrorMessageBox(error, e.Exception); - } - - public static void ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) - { - if (Debugger.IsAttached) return; - - string error = ExceptionFormatter.FormatExcpetion(e.Exception); - - Log.Fatal(error); - TryShowErrorMessageBox(error, e.Exception); - } - - public static bool TryShowErrorMessageBox(string error, object exceptionObject) - { - var title = "Wox - Unhandled Exception"; - - try - { - ShowWPFDialog(error, title, exceptionObject); - return true; - } - catch { } - - error = "Wox has occured an error that can't be handled. " + Environment.NewLine + Environment.NewLine + error; - - try - { - ShowWPFMessageBox(error, title); - return true; - } - catch { } - - try - { - ShowWindowsFormsMessageBox(error, title); - return true; - } - catch { } - - return true; - } - - private static void ShowWPFDialog(string error, string title, object exceptionObject) - { - var dialog = new WPFErrorReportingDialog(error, title, exceptionObject); - dialog.ShowDialog(); - } - - private static void ShowWPFMessageBox(string error, string title) - { - System.Windows.MessageBox.Show(error, title, MessageBoxButton.OK, MessageBoxImage.Error, - MessageBoxResult.OK, System.Windows.MessageBoxOptions.None); - } - - private static void ShowWindowsFormsMessageBox(string error, string title) - { - System.Windows.Forms.MessageBox.Show(error, title, MessageBoxButtons.OK, - MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); - } - } -} diff --git a/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml b/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml deleted file mode 100644 index 54d0f04bd..000000000 --- a/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml.cs b/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml.cs deleted file mode 100644 index f16669bd3..000000000 --- a/Wox/Helper/ErrorReporting/WPFErrorReportingDialog.xaml.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace Wox.Helper.ErrorReporting -{ - /// - /// Interaction logic for WPFErrorReportingDialog.xaml - /// - public partial class WPFErrorReportingDialog : Window - { - private object exceptionObject; - - public WPFErrorReportingDialog(string error, string title, object exceptionObject) - { - InitializeComponent(); - - this.tbErrorReport.Text = error; - this.Title = title; - this.exceptionObject = exceptionObject; - } - } -} diff --git a/Wox/Helper/WoxLog4netPathConverter.cs b/Wox/Helper/WoxLog4netPathConverter.cs new file mode 100644 index 000000000..98cd17620 --- /dev/null +++ b/Wox/Helper/WoxLog4netPathConverter.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace Wox.Helper +{ + public class WoxLog4netPathConverter : log4net.Util.PatternConverter + { + protected override void Convert(TextWriter writer, object state) + { + string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); + writer.Write(Path.Combine(userProfilePath, ".Wox")); + } + } +} diff --git a/Wox/Update/NewVersionWindow.xaml.cs b/Wox/Update/NewVersionWindow.xaml.cs index 66fbaf88e..8ef044782 100644 --- a/Wox/Update/NewVersionWindow.xaml.cs +++ b/Wox/Update/NewVersionWindow.xaml.cs @@ -12,19 +12,17 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using Wox.Core.Version; namespace Wox.Update { - /// - /// NewVersionWindow.xaml 的交互逻辑 - /// public partial class NewVersionWindow : Window { public NewVersionWindow() { InitializeComponent(); - tbCurrentVersion.Text = ConfigurationManager.AppSettings["version"]; + tbCurrentVersion.Text = VersionManager.Instance.CurrentVersion.ToString(); Release newRelease = new UpdateChecker().CheckUpgrade(); if (newRelease == null) { diff --git a/Wox/Update/UpdateChecker.cs b/Wox/Update/UpdateChecker.cs index 8c6e151a8..65fb0c4d3 100644 --- a/Wox/Update/UpdateChecker.cs +++ b/Wox/Update/UpdateChecker.cs @@ -6,7 +6,9 @@ using System.Net; using System.Text; using Newtonsoft.Json; +using Wox.Core; using Wox.Core.UserSettings; +using Wox.Core.Version; using Wox.Helper; using Wox.Infrastructure; using Wox.Infrastructure.Http; @@ -15,7 +17,6 @@ namespace Wox.Update { public class UpdateChecker { - private const string updateURL = "https://api.getwox.com/release/latest/"; private static Release newRelease; private static bool checkedUpdate = false; @@ -27,7 +28,7 @@ public class UpdateChecker public Release CheckUpgrade(bool forceCheck = false) { if (checkedUpdate && !forceCheck) return newRelease; - string json = HttpRequest.Get(updateURL,HttpProxy.Instance); + string json = HttpRequest.Get(APIServer.LastestReleaseURL,HttpProxy.Instance); if (string.IsNullOrEmpty(json)) return null; try @@ -48,46 +49,7 @@ private bool IsNewerThanCurrent(Release release) { if (release == null) return false; - string currentVersion = ConfigurationManager.AppSettings["version"]; - return CompareVersion(release.version, currentVersion) > 0; - } - - /// - /// if version1 > version2 return 1 - /// else -1 - /// - /// - /// - /// - private int CompareVersion(string version1, string version2) - { - if (version1 == version2) return 0; - if (string.IsNullOrEmpty(version1) || string.IsNullOrEmpty(version2)) return 0; - - //semantic version, e.g. 1.1.0 - List version1List = version1.Split('.').Select(int.Parse).ToList(); - List version2List = version2.Split('.').Select(int.Parse).ToList(); - - if (version1List[0] > version2List[0]) - { - return 1; - } - else if (version1List[0] == version2List[0]) - { - if (version1List[1] > version2List[1]) - { - return 1; - } - else if (version1List[1] == version2List[1]) - { - if (version1List[2] > version2List[2]) - { - return 1; - } - } - } - - return -1; + return new SemanticVersion(release.version) > VersionManager.Instance.CurrentVersion; } } } diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 63952eb25..9f585e94f 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -132,10 +132,7 @@ - - - WPFErrorReportingDialog.xaml - + @@ -164,10 +161,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - Designer MSBuild:Compile @@ -278,6 +271,10 @@ {B749F0DB-8E75-47DB-9E5E-265D16D0C0D2} Wox.Core + + {2FEB2298-7653-4009-B1EA-FFFB1A768BCC} + Wox.CrashReporter + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} Wox.Infrastructure