PowerToys/Wox/ReportWindow.xaml.cs

71 lines
2.7 KiB
C#
Raw Normal View History

2015-01-11 21:52:30 +08:00
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
2015-01-11 21:52:30 +08:00
using System.Windows;
using System.Windows.Documents;
using Wox.Infrastructure;
using Wox.Infrastructure.Logger;
2015-01-11 21:52:30 +08:00
namespace Wox
2015-01-11 21:52:30 +08:00
{
2015-01-12 22:46:36 +08:00
internal partial class ReportWindow
2015-01-11 21:52:30 +08:00
{
public ReportWindow(Exception exception)
{
InitializeComponent();
ErrorTextbox.Document.Blocks.FirstBlock.Margin = new Thickness(0);
2015-01-11 21:52:30 +08:00
SetException(exception);
}
private void SetException(Exception exception)
{
string path = Path.Combine(Constant.DataDirectory, Log.DirectoryName, Constant.Version);
var directory = new DirectoryInfo(path);
var log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
2015-01-11 21:52:30 +08:00
var paragraph = Hyperlink("Please open new issue in: " , Constant.Issue);
paragraph.Inlines.Add($"1. upload log file: {log.FullName}\n");
paragraph.Inlines.Add($"2. copy below exception message");
ErrorTextbox.Document.Blocks.Add(paragraph);
2015-01-16 23:42:12 +08:00
StringBuilder content = new StringBuilder();
content.AppendLine($"Wox version: {Constant.Version}");
content.AppendLine($"OS Version: {Environment.OSVersion.VersionString}");
2016-07-20 09:01:47 +08:00
content.AppendLine($"IntPtr Length: {IntPtr.Size}");
content.AppendLine($"x64: {Environment.Is64BitOperatingSystem}");
content.AppendLine($"Python Path: {Constant.PythonPath}");
content.AppendLine($"Everything SDK Path: {Constant.EverythingSDKPath}");
content.AppendLine($"Date: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}");
content.AppendLine("Exception:");
content.AppendLine(exception.Source);
content.AppendLine(exception.GetType().ToString());
content.AppendLine(exception.Message);
content.AppendLine(exception.StackTrace);
paragraph = new Paragraph();
paragraph.Inlines.Add(content.ToString());
ErrorTextbox.Document.Blocks.Add(paragraph);
2015-01-11 21:52:30 +08:00
}
private Paragraph Hyperlink(string textBeforeUrl, string url)
2015-01-11 21:52:30 +08:00
{
var paragraph = new Paragraph();
paragraph.Margin = new Thickness(0);
var link = new Hyperlink {IsEnabled = true};
link.Inlines.Add(url);
link.NavigateUri = new Uri(url);
link.RequestNavigate += (s, e) => Process.Start(e.Uri.ToString());
link.Click += (s, e) => Process.Start(url);
paragraph.Inlines.Add(textBeforeUrl);
paragraph.Inlines.Add(link);
paragraph.Inlines.Add("\n");
return paragraph;
2015-01-11 21:52:30 +08:00
}
}
}