mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Add Wox.CrashReporter
This commit is contained in:
@@ -3,9 +3,6 @@
|
||||
<configSections>
|
||||
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
|
||||
</configSections>
|
||||
<appSettings>
|
||||
<add key="version" value="1.1.1"/>
|
||||
</appSettings>
|
||||
<log4net>
|
||||
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
|
||||
<file type="log4net.Util.PatternString">
|
||||
@@ -36,4 +33,4 @@
|
||||
<!--http://stackoverflow.com/questions/186854/how-to-prevent-an-exception-in-a-background-thread-from-terminating-an-applicati-->
|
||||
<legacyUnhandledExceptionPolicy enabled="1" />
|
||||
</runtime>
|
||||
</configuration>
|
||||
</configuration>
|
||||
@@ -5,7 +5,6 @@ using System.Linq;
|
||||
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;
|
||||
|
||||
35
Wox/Helper/ErrorReporting.cs
Normal file
35
Wox/Helper/ErrorReporting.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<Window x:Class="Wox.Helper.ErrorReporting.WPFErrorReportingDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="ErrorReportingDialog" WindowStartupLocation="CenterScreen">
|
||||
<DockPanel>
|
||||
<TextBlock Margin="10" TextWrapping="Wrap" DockPanel.Dock="Top" Text="Wox has occured an error that can't be handled. "/>
|
||||
<TextBox x:Name="tbErrorReport" IsReadOnly="True" IsUndoEnabled="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" />
|
||||
</DockPanel>
|
||||
</Window>
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for WPFErrorReportingDialog.xaml
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Wox/Helper/WoxLog4netPathConverter.cs
Normal file
17
Wox/Helper/WoxLog4netPathConverter.cs
Normal file
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,19 +12,17 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using Wox.Core.Version;
|
||||
|
||||
namespace Wox.Update
|
||||
{
|
||||
/// <summary>
|
||||
/// NewVersionWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,9 @@ using System.Linq;
|
||||
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 @@ namespace Wox.Update
|
||||
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 @@ namespace Wox.Update
|
||||
{
|
||||
if (release == null) return false;
|
||||
|
||||
string currentVersion = ConfigurationManager.AppSettings["version"];
|
||||
return CompareVersion(release.version, currentVersion) > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// if version1 > version2 return 1
|
||||
/// else -1
|
||||
/// </summary>
|
||||
/// <param name="version1"></param>
|
||||
/// <param name="version2"></param>
|
||||
/// <returns></returns>
|
||||
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<int> version1List = version1.Split('.').Select(int.Parse).ToList();
|
||||
List<int> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,10 +132,7 @@
|
||||
<Compile Include="CommandArgs\QueryCommandArg.cs" />
|
||||
<Compile Include="CommandArgs\ReloadPluginCommandArg.cs" />
|
||||
<Compile Include="Helper\DataWebRequestFactory.cs" />
|
||||
<Compile Include="Helper\ErrorReporting\ErrorReporting.cs" />
|
||||
<Compile Include="Helper\ErrorReporting\WPFErrorReportingDialog.xaml.cs">
|
||||
<DependentUpon>WPFErrorReportingDialog.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Helper\ErrorReporting.cs" />
|
||||
<Compile Include="ImageLoader\ImageLoader.cs" />
|
||||
<Compile Include="Helper\SingleInstance.cs" />
|
||||
<Compile Include="Helper\SyntaxSugars.cs" />
|
||||
@@ -164,10 +161,6 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Helper\ErrorReporting\WPFErrorReportingDialog.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="CustomQueryHotkeySetting.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
@@ -278,6 +271,10 @@
|
||||
<Project>{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}</Project>
|
||||
<Name>Wox.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Wox.CrashReporter\Wox.CrashReporter.csproj">
|
||||
<Project>{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}</Project>
|
||||
<Name>Wox.CrashReporter</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Wox.Infrastructure\Wox.Infrastructure.csproj">
|
||||
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
|
||||
<Name>Wox.Infrastructure</Name>
|
||||
|
||||
Reference in New Issue
Block a user