PowerToys/src/modules/launcher/PowerLauncher/ReportWindow.xaml.cs
Niels Laute dad8cbecc1
[Launcher] ReportWindow redesign and theming support (#5790)
* Updated adaptive trigger behavior

* Fixed wrapping for KBM subtitle textblock

* Fix

* Theme support for ReportWindow

* Fix

* Fix

* Spacing issue fix

* Revert "Fix"

This reverts commit 8b2812e2de.

* Revert "Fixed wrapping for KBM subtitle textblock"

This reverts commit aa9ec54121.

* Revert "Updated adaptive trigger behavior"

This reverts commit e6f4ed27a1.

* Update ReportWindow.xaml.cs

* Update ReportWindow.xaml.cs

* Update ReportWindow.xaml.cs

* Removed redundant code, fixed trailing issue

Co-authored-by: Niels Laute <niels9001@hotmail.com>
2020-08-17 13:48:54 -07:00

89 lines
2.8 KiB
C#

// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using PowerLauncher.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
namespace PowerLauncher
{
internal partial class ReportWindow
{
public ReportWindow(Exception exception)
{
InitializeComponent();
BitmapImage image = GetImageFromPath(ImageLoader.ErrorIconPath);
if (image != null)
{
Icon = image;
}
ErrorTextbox.Document.Blocks.FirstBlock.Margin = new Thickness(0);
SetException(exception);
}
private void SetException(Exception exception)
{
string path = Log.CurrentLogDirectory;
var directory = new DirectoryInfo(path);
var log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
LogFilePathBox.Text = log.FullName;
StringBuilder content = new StringBuilder();
content.AppendLine(ErrorReporting.RuntimeInfo());
content.AppendLine($"Date: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}");
content.AppendLine("Exception:");
content.AppendLine(exception.ToString());
var paragraph = new Paragraph();
paragraph.Inlines.Add(content.ToString());
ErrorTextbox.Document.Blocks.Add(paragraph);
}
// Function to get the Bitmap Image from the path
private static BitmapImage GetImageFromPath(string path)
{
if (File.Exists(path))
{
MemoryStream memoryStream = new MemoryStream();
byte[] fileBytes = File.ReadAllBytes(path);
memoryStream.Write(fileBytes, 0, fileBytes.Length);
memoryStream.Position = 0;
var image = new BitmapImage();
image.BeginInit();
image.StreamSource = memoryStream;
image.EndInit();
return image;
}
else
{
return null;
}
}
private void RepositoryHyperlink_Click(object sender, RoutedEventArgs e)
{
var ps = new ProcessStartInfo((sender as Hyperlink).NavigateUri.ToString())
{
UseShellExecute = true,
Verb = "open",
};
Process.Start(ps);
}
}
}