forked from cdwcgt/GTA5onlineTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
114 lines (100 loc) · 4.56 KB
/
App.xaml.cs
File metadata and controls
114 lines (100 loc) · 4.56 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using Prism.Ioc;
using Prism.DryIoc;
using GTA5OnlineTools.Views;
using GTA5OnlineTools.Common.Utils;
using GTA5OnlineTools.Modules.Windows.ExternalMenu;
namespace GTA5OnlineTools
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : PrismApplication
{
public static Mutex AppMainMutex;
protected override void OnStartup(StartupEventArgs e)
{
AppMainMutex = new Mutex(true, ResourceAssembly.GetName().Name, out var createdNew);
if (createdNew)
{
RegisterEvents();
base.OnStartup(e);
}
else
{
MessageBox.Show("请不要重复打开,程序已经运行\n如果一直提示,请到\"任务管理器-详细信息(win7为进程)\"里结束本程序",
"警告", MessageBoxButton.OK, MessageBoxImage.Warning);
Current.Shutdown();
}
}
protected override Window CreateShell()
{
return Container.Resolve<MainView>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<UC0IndexView>();
containerRegistry.RegisterForNavigation<UC1HacksView>();
containerRegistry.RegisterForNavigation<UC2ModulesView>();
containerRegistry.RegisterForNavigation<UC3ToolsView>();
containerRegistry.RegisterForNavigation<UC4UpdateView>();
containerRegistry.RegisterForNavigation<UC5AboutView>();
containerRegistry.RegisterForNavigation<EM00ReadMeView>();
containerRegistry.RegisterForNavigation<EM01PlayerStateView>();
containerRegistry.RegisterForNavigation<EM02WorldFunctionView>();
containerRegistry.RegisterForNavigation<EM03OnlineOptionView>();
containerRegistry.RegisterForNavigation<EM04PlayerListView>();
containerRegistry.RegisterForNavigation<EM05SpawnVehicleView>();
containerRegistry.RegisterForNavigation<EM06SpawnWeaponView>();
containerRegistry.RegisterForNavigation<EM07CustomTPView>();
containerRegistry.RegisterForNavigation<EM08ExternalOverlayView>();
containerRegistry.RegisterForNavigation<EM09SessionChatView>();
containerRegistry.RegisterForNavigation<EM10JobHelperView>();
}
private void RegisterEvents()
{
// UI线程未捕获异常处理事件(UI主线程)
DispatcherUnhandledException += App_DispatcherUnhandledException;
// 非UI线程未捕获异常处理事件(例如自己创建的一个子线程)
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
// Task线程内未捕获异常处理事件
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
}
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
string str = GetExceptionMsg(e.Exception, e.ToString());
FileUtil.SaveErrorLog(str);
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());
FileUtil.SaveErrorLog(str);
}
private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
string str = GetExceptionMsg(e.Exception, e.ToString());
FileUtil.SaveErrorLog(str);
}
/// <summary>
/// 生成自定义异常消息
/// </summary>
/// <param name="ex">异常对象</param>
/// <param name="backStr">备用异常消息:当ex为null时有效</param>
/// <returns>异常字符串文本</returns>
private static string GetExceptionMsg(Exception ex, string backStr)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("【出现时间】:" + DateTime.Now.ToString());
if (ex != null)
{
sb.AppendLine("【异常类型】:" + ex.GetType().Name);
sb.AppendLine("【异常信息】:" + ex.Message);
sb.AppendLine("【堆栈调用】:" + ex.StackTrace);
}
else
{
sb.AppendLine("【未处理异常】:" + backStr);
}
return sb.ToString();
}
}
}