Browse Source

Did something with the send crash report thing

CPKreuz 3 years ago
parent
commit
959de66098

+ 19 - 0
PixiEditor/Helpers/ProcessHelpers.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Diagnostics;
+
+namespace PixiEditor.Helpers
+{
+    public static class ProcessHelpers
+    {
+        public static void ShellExecute(string url)
+        {
+            Process.Start(new ProcessStartInfo
+            {
+                FileName = url,
+                UseShellExecute = true
+            });
+        }
+
+        public static void ShellExecuteEV(string path) => ShellExecute(Environment.ExpandEnvironmentVariables(path));
+    }
+}

+ 4 - 0
PixiEditor/ViewModels/CrashReportViewModel.cs

@@ -1,5 +1,6 @@
 using GalaSoft.MvvmLight.CommandWpf;
 using PixiEditor.Models.DataHolders;
+using PixiEditor.Views.Dialogs;
 using System.Diagnostics;
 using System.Windows;
 
@@ -13,6 +14,8 @@ namespace PixiEditor.ViewModels
 
         public int DocumentCount { get; }
 
+        public RelayCommand OpenSendCrashReportCommand { get; }
+
         public RelayCommand RecoverDocumentsCommand { get; }
 
         public RelayCommand AttachDebuggerCommand { get; }
@@ -26,6 +29,7 @@ namespace PixiEditor.ViewModels
             CrashReport = report;
             ReportText = report.ReportText;
             DocumentCount = report.GetDocumentCount();
+            OpenSendCrashReportCommand = new(() => new SendCrashReportWindow(CrashReport).Show());
             RecoverDocumentsCommand = new(RecoverDocuments);
             AttachDebuggerCommand = new(AttachDebugger);
         }

+ 2 - 12
PixiEditor/ViewModels/SubViewModels/Main/DebugViewModel.cs

@@ -1,6 +1,5 @@
 using PixiEditor.Helpers;
 using System;
-using System.Diagnostics;
 using System.IO;
 using System.Reflection;
 
@@ -24,21 +23,12 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public static void OpenFolder(object parameter)
         {
-            OpenShellExecute((string)parameter);
+            ProcessHelpers.ShellExecuteEV(parameter as string);
         }
 
         public static void OpenInstallLocation(object parameter)
         {
-            OpenShellExecute(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
-        }
-
-        private static void OpenShellExecute(string path)
-        {
-            ProcessStartInfo startInfo = new (Environment.ExpandEnvironmentVariables(path));
-
-            startInfo.UseShellExecute = true;
-
-            Process.Start(startInfo);
+            ProcessHelpers.ShellExecuteEV(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
         }
     }
 }

+ 2 - 8
PixiEditor/ViewModels/SubViewModels/Main/MiscViewModel.cs

@@ -40,18 +40,12 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         private void OpenHyperlink(object parameter)
         {
-            if (parameter == null)
+            if (parameter is not string s)
             {
                 return;
             }
 
-            var url = (string)parameter;
-            var processInfo = new ProcessStartInfo()
-            {
-                FileName = url,
-                UseShellExecute = true
-            };
-            Process.Start(processInfo);
+            ProcessHelpers.ShellExecute(s);
         }
 
         private void OpenShortcutWindow(object parameter)

+ 17 - 36
PixiEditor/Views/Dialogs/CrashReportDialog.xaml

@@ -4,21 +4,14 @@
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:vm="clr-namespace:PixiEditor.ViewModels"
-        xmlns:local="clr-namespace:PixiEditor.Views.Dialogs"
+        xmlns:dial="clr-namespace:PixiEditor.Views.Dialogs"
         d:DataContext="{d:DesignInstance vm:CrashReportViewModel}"
-        mc:Ignorable="d" Background="{StaticResource AccentColor}"
+        mc:Ignorable="d"
+        Background="{StaticResource AccentColor}" Foreground="White"
         Title="Oh no!" WindowStyle="None"
-        MinWidth="400" MinHeight="250"
-        Width="500" Height="300">
-
-    <Window.Resources>
-        <Style TargetType="TextBlock">
-            <Setter Property="Foreground" Value="White"/>
-            <Setter Property="FontSize" Value="16"/>
-        </Style>
-
-    </Window.Resources>
-
+        MinWidth="450" MinHeight="195"
+        Width="450" Height="195">
+    
     <WindowChrome.WindowChrome>
         <WindowChrome CaptionHeight="35"  GlassFrameThickness="0.1"
                       ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}"/>
@@ -29,37 +22,25 @@
                         Executed="CommandBinding_Executed_Close" />
     </Window.CommandBindings>
 
-    <Grid>
-        <Grid.RowDefinitions>
-            <RowDefinition Height="35"/>
-            <RowDefinition/>
-        </Grid.RowDefinitions>
-        <DockPanel Grid.Row="0" Background="{StaticResource MainColor}">
-            <Button DockPanel.Dock="Right" HorizontalAlignment="Right" Style="{StaticResource CloseButtonStyle}"
-                    WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close"
-                    Command="{x:Static SystemCommands.CloseWindowCommand}" />
-        </DockPanel>
-        <StackPanel Grid.Row="1" Margin="5">
-
+    <StackPanel>
+        <dial:DialogTitleBar TitleText="Oh no!" CloseCommand="{x:Static SystemCommands.CloseWindowCommand}" />
+        <StackPanel Grid.Row="1" Margin="5" VerticalAlignment="Center">
             <TextBlock>PixiEditor has crashed!</TextBlock>
             <TextBlock Text="{Binding DocumentCount, StringFormat={}{0} file(s) can be recovered}"
-                   d:Text="2 file(s) can be recovered"/>
+                       d:Text="2 file(s) can be recovered"/>
             <TextBlock TextWrapping="Wrap">You can help the developers fixing this bug by sending a crash report that was generated</TextBlock>
 
-            <Grid Margin="0,20,0,5">
-                <Grid.ColumnDefinitions>
-                    <ColumnDefinition/>
-                    <ColumnDefinition/>
-                </Grid.ColumnDefinitions>
-                <Button Margin="0,0,5,0"
+            <StackPanel Margin="0,20,0,5" Orientation="Horizontal" HorizontalAlignment="Center">
+                <Button Margin="0,0,5,0" Command="{Binding OpenSendCrashReportCommand}"
+                        Width="120"
                         Style="{StaticResource DarkRoundButton}">Send report</Button>
-                <Button Grid.Column="1" Margin="5,0,0,0"
+                <Button Grid.Column="1" Margin="5,0,0,0" Width="120"
                         Command="{Binding RecoverDocumentsCommand}"
                         Style="{StaticResource DarkRoundButton}">Recover files</Button>
-            </Grid>
+            </StackPanel>
             <Button Visibility="{Binding IsDebugBuild, Converter={BoolToVisibilityConverter}}"
-                    Style="{StaticResource DarkRoundButton}"
+                    Style="{StaticResource DarkRoundButton}" Width="250"
                     Command="{Binding AttachDebuggerCommand}">(Re)Attach debugger</Button>
         </StackPanel>
-    </Grid>
+    </StackPanel>
 </Window>

+ 24 - 16
PixiEditor/Views/Dialogs/SendCrashReportWindow.xaml

@@ -3,33 +3,41 @@
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-        xmlns:uc="clr-namespace:PixiEditor.Views.UserControls"
-        xmlns:local="clr-namespace:PixiEditor.Views.Dialogs"
+        xmlns:dial="clr-namespace:PixiEditor.Views.Dialogs"
         mc:Ignorable="d"
         Background="{StaticResource AccentColor}" Foreground="White"
-        Title="SendCrashReportWindow" Height="180" Width="340">
+        Title="Send crash report"
+        WindowStyle="None"
+        Height="150" Width="340">
     <Window.Resources>
         <Style TargetType="TextBlock">
             <Setter Property="HorizontalAlignment" Value="Center"/>
         </Style>
         <Style TargetType="Button" BasedOn="{StaticResource DarkRoundButton}">
-            <Setter Property="FontSize" Value="14"/>
             <Setter Property="Margin" Value="5"/>
-            <Setter Property="Height" Value="25"/>
             <Setter Property="Width" Value="100"/>
         </Style>
     </Window.Resources>
-    <StackPanel Margin="5" VerticalAlignment="Center">
-        <TextBlock>You can find the report here:</TextBlock>
-        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
-            <Button Width="130">Copy to clipboard</Button>
-            <Button Width="130">Open in Explorer</Button>
-        </StackPanel>
-        <TextBlock TextAlignment="Center">You can report your crash report here:</TextBlock>
-        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
-            <Button>GitHub</Button>
-            <Button>Discord</Button>
-            <Button>E-Mail</Button>
+
+    <WindowChrome.WindowChrome>
+        <WindowChrome CaptionHeight="35"  GlassFrameThickness="0.1"
+                      ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}"/>
+    </WindowChrome.WindowChrome>
+
+    <StackPanel>
+        <dial:DialogTitleBar TitleText="Send crash report" CloseCommand="{x:Static SystemCommands.CloseWindowCommand}" />
+        <StackPanel Margin="5">
+            <TextBlock>You can find the report here:</TextBlock>
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
+                <Button Width="140" Click="CopyToClipboard">Copy to clipboard</Button>
+                <Button Width="140" Click="OpenInExplorer">Open in Explorer</Button>
+            </StackPanel>
+            <TextBlock TextAlignment="Center">You can report your crash report here:</TextBlock>
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
+                <Button Click="OpenHyperlink" Tag="">GitHub</Button>
+                <Button Click="OpenHyperlink" Tag="">Discord</Button>
+                <Button Click="OpenHyperlink" Tag="">E-Mail</Button>
+            </StackPanel>
         </StackPanel>
     </StackPanel>
 </Window>

+ 24 - 2
PixiEditor/Views/Dialogs/SendCrashReportWindow.xaml.cs

@@ -1,4 +1,6 @@
-using System;
+using PixiEditor.Helpers;
+using PixiEditor.Models.DataHolders;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -19,9 +21,29 @@ namespace PixiEditor.Views.Dialogs
     /// </summary>
     public partial class SendCrashReportWindow : Window
     {
-        public SendCrashReportWindow()
+        private readonly CrashReport report;
+
+        public SendCrashReportWindow(CrashReport report)
         {
+            this.report = report;
             InitializeComponent();
         }
+
+        private void CopyToClipboard(object sender, RoutedEventArgs e)
+        {
+            Clipboard.SetFileDropList(new() { report.FilePath });
+        }
+
+        private void OpenInExplorer(object sender, RoutedEventArgs e)
+        {
+            ProcessHelpers.ShellExecute(report.FilePath);
+        }
+
+        private void OpenHyperlink(object sender, RoutedEventArgs e)
+        {
+            var button = sender as Button;
+
+            ProcessHelpers.ShellExecute(button.Tag as string);
+        }
     }
 }