-
Notifications
You must be signed in to change notification settings - Fork 11
/
App.xaml.cs
56 lines (50 loc) · 1.48 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
namespace GTAVModdingLauncher
{
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs a)
{
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
}
private Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
string assemblyName = args.Name.Split(',')[0] + ".dll";
try
{
Stream stream = GetResourceStream(new Uri("/GTAVModdingLauncher;component/libs/" + assemblyName, UriKind.Relative)).Stream;
if(stream != null)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
return Assembly.Load(bytes);
}
else throw new IOException();
}
catch(IOException)
{
MessageBox.Show("Unable to load " + assemblyName, "Fatal error", MessageBoxButton.OK, MessageBoxImage.Error);
Process.GetCurrentProcess().Kill();
return null;
}
}
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
if(Launcher.Instance != null && Launcher.Instance.Window != null)
{
Launcher.Instance.Window.Dispatcher.Invoke(delegate
{
Launcher.Instance.Window.Visibility = Visibility.Hidden;
new CrashReporter(e, true).ShowDialog();
});
}
else new CrashReporter(e, false);
}
}
}