Skip to content
This repository was archived by the owner on Dec 13, 2020. It is now read-only.

Commit a091dbd

Browse files
author
Firestack
committed
add error stuff
1 parent 81953c3 commit a091dbd

File tree

7 files changed

+183
-13
lines changed

7 files changed

+183
-13
lines changed

UnityMultiLauncher/App.xaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Windows;
2+
using System;
23
using MahApps.Metro;
34

45
namespace UnityMultiLauncher
@@ -16,8 +17,27 @@ protected override void OnStartup(StartupEventArgs e)
1617
// now set the Green accent and dark theme
1718
ThemeManager.ChangeAppStyle(Application.Current, ProgramConfig.conf.appStyle.Item2, ProgramConfig.conf.appStyle.Item1);
1819

20+
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
1921

2022
base.OnStartup(e);
2123
}
24+
25+
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
26+
{
27+
System.TimeSpan timeDifference = DateTime.UtcNow -
28+
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
29+
long unixEpochTime = System.Convert.ToInt64(timeDifference.TotalSeconds);
30+
31+
var filePath = @"Crashes/log." + unixEpochTime.ToString() + ".txt";
32+
System.IO.FileInfo file = new System.IO.FileInfo(filePath);
33+
file.Directory.Create();
34+
System.IO.File.WriteAllText(file.FullName, e.Exception.ToString());
35+
36+
var Win = new Views.ErrorWindow();
37+
Win.EVMP.Exception = e.Exception;
38+
39+
Win.metroWindow.ShowDialog();
40+
41+
}
2242
}
2343
}

UnityMultiLauncher/UnityMultiLauncher.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<Compile Include="Models\ProgramConfig.cs" />
111111
<Compile Include="Models\Utility.cs" />
112112
<Compile Include="Util\ExtentionMethods.cs" />
113+
<Compile Include="ViewModels\ErrorViewModel.cs" />
113114
<Compile Include="ViewModels\StyleViewModel.cs" />
114115
<Compile Include="ViewModels\UnityViewModel.cs" />
115116
<Compile Include="ViewModels\Utils\ViewCommand.cs" />
@@ -122,6 +123,10 @@
122123
<SubType>Designer</SubType>
123124
<Generator>MSBuild:Compile</Generator>
124125
</Page>
126+
<Page Include="Views\ErrorWindow.xaml">
127+
<SubType>Designer</SubType>
128+
<Generator>MSBuild:Compile</Generator>
129+
</Page>
125130
<Page Include="Views\MainWindow.xaml">
126131
<Generator>MSBuild:Compile</Generator>
127132
<SubType>Designer</SubType>
@@ -134,6 +139,9 @@
134139
<Compile Include="Controls\BaseFilesystemControl.xaml.cs">
135140
<DependentUpon>BaseFilesystemControl.xaml</DependentUpon>
136141
</Compile>
142+
<Compile Include="Views\ErrorWindow.xaml.cs">
143+
<DependentUpon>ErrorWindow.xaml</DependentUpon>
144+
</Compile>
137145
<Compile Include="Views\MainWindow.xaml.cs">
138146
<DependentUpon>MainWindow.xaml</DependentUpon>
139147
<SubType>Code</SubType>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace UnityMultiLauncher.ViewModels
8+
{
9+
using Utils;
10+
public class ErrorViewModel : ViewModel
11+
{
12+
public System.Exception Exception
13+
{
14+
get
15+
{
16+
return GetProperty() as Exception;
17+
}
18+
set
19+
{
20+
SetProperty(value);
21+
UpdateProperty(nameof(ExceptionString));
22+
}
23+
}
24+
25+
public string ExceptionString
26+
{
27+
get
28+
{
29+
return Exception.ToString();
30+
}
31+
}
32+
33+
public System.IO.FileInfo FileLocation
34+
{
35+
get
36+
{
37+
return GetProperty() as System.IO.FileInfo;
38+
}
39+
set
40+
{
41+
SetProperty(value);
42+
}
43+
}
44+
45+
public void OpenGithubFunc(object obj)
46+
{
47+
48+
49+
var url = "https://github.com/firestack/UnityMultiLauncher/issues/new?"+
50+
"title=Automatic Error Report" +
51+
"&body=<Insert Info Here>\n```"+ExceptionString+"```";
52+
var uri = new Uri(url, UriKind.Absolute);
53+
System.Diagnostics.Process.Start(uri.AbsoluteUri);
54+
}
55+
56+
public ViewCommand OpenGithub
57+
{
58+
get
59+
{
60+
return GetProperty() as ViewCommand ?? SetProperty(new ViewCommand(OpenGithubFunc));
61+
}
62+
}
63+
64+
65+
}
66+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Controls:MetroWindow
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
5+
xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
6+
xmlns:UMControls="clr-namespace:UnityMultiLauncher.Controls"
7+
xmlns:VM="clr-namespace:UnityMultiLauncher.ViewModels"
8+
xmlns:Converter="clr-namespace:UnityMultiLauncher.Controls.Converters"
9+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
10+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
11+
xmlns:System="clr-namespace:System;assembly=mscorlib"
12+
mc:Ignorable="d"
13+
x:Name="metroWindow"
14+
x:Class="UnityMultiLauncher.Views.ErrorWindow"
15+
Title="Unity Multi Launcher: Error"
16+
WindowButtonCommandsOverlayBehavior="Never"
17+
RightWindowCommandsOverlayBehavior="Never" >
18+
<Controls:MetroWindow.Resources>
19+
<VM:ErrorViewModel x:Key="EVM"/>
20+
</Controls:MetroWindow.Resources>
21+
<Controls:MetroWindow.RightWindowCommands>
22+
<Controls:WindowCommands>
23+
<Button Content="Open Github" Command="{Binding OpenGithub, Mode=OneWay, Source={StaticResource EVM}}" />
24+
25+
</Controls:WindowCommands>
26+
</Controls:MetroWindow.RightWindowCommands>
27+
<Grid>
28+
<Grid.RowDefinitions>
29+
<RowDefinition Height="40*"/>
30+
<RowDefinition Height="427*"/>
31+
<RowDefinition Height="37*"/>
32+
</Grid.RowDefinitions>
33+
<Label Content="Oops, an Exception occurred and forced UML to quit" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" FontFamily="Hack" FontSize="20"/>
34+
<Label Content="{Binding FileLocation.FullName, Mode=OneWay, Source={StaticResource EVM}}" ></Label>
35+
<TextBlock Grid.Row="1" Text="{Binding ExceptionString, Mode=OneWay, Source={StaticResource EVM}}" TextWrapping="Wrap" />
36+
37+
</Grid>
38+
</Controls:MetroWindow>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Shapes;
14+
using MahApps.Metro.Controls;
15+
16+
17+
namespace UnityMultiLauncher.Views
18+
{
19+
/// <summary>
20+
/// Interaction logic for ErrorWindow.xaml
21+
/// </summary>
22+
public partial class ErrorWindow : MetroWindow
23+
{
24+
public ViewModels.ErrorViewModel EVMP;
25+
26+
public ErrorWindow()
27+
{
28+
InitializeComponent();
29+
EVMP = FindResource("EVM") as ViewModels.ErrorViewModel;
30+
31+
}
32+
}
33+
}

UnityMultiLauncher/Views/MainWindow.xaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<Controls:MetroWindow
2-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
5-
xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
6-
xmlns:UMControls="clr-namespace:UnityMultiLauncher.Controls"
7-
xmlns:VM="clr-namespace:UnityMultiLauncher.ViewModels"
8-
xmlns:Converter="clr-namespace:UnityMultiLauncher.Controls.Converters"
9-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:System="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" x:Name="metroWindow" x:Class="UnityMultiLauncher.MainWindow"
10-
Title="Unity Multi Launcher"
11-
Height="600"
12-
Width="800" WindowButtonCommandsOverlayBehavior="Never" RightWindowCommandsOverlayBehavior="Never" >
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
5+
xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
6+
xmlns:UMControls="clr-namespace:UnityMultiLauncher.Controls"
7+
xmlns:VM="clr-namespace:UnityMultiLauncher.ViewModels"
8+
xmlns:Converter="clr-namespace:UnityMultiLauncher.Controls.Converters"
9+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
10+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
11+
xmlns:System="clr-namespace:System;assembly=mscorlib"
12+
mc:Ignorable="d"
13+
x:Name="metroWindow"
14+
x:Class="UnityMultiLauncher.MainWindow"
15+
Title="Unity Multi Launcher"
16+
Height="600"
17+
Width="800" WindowButtonCommandsOverlayBehavior="Never" RightWindowCommandsOverlayBehavior="Never" >
1318

1419
<Controls:MetroWindow.Resources>
1520

UnityMultiLauncher/Views/MainWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public MainWindow()
1414
{
1515
cwin = this;
1616
InitializeComponent();
17-
18-
var a = Environment.SpecialFolder.MyComputer.GetLocation();
17+
18+
//var a = Environment.SpecialFolder.MyComputer.GetLocation();
1919
}
2020
}
2121
}

0 commit comments

Comments
 (0)