-
Notifications
You must be signed in to change notification settings - Fork 11
/
App.xaml.cs
107 lines (80 loc) · 3.51 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
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
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using Handheld_Control_Panel.Classes;
using Handheld_Control_Panel.Classes.Fan_Management;
using Handheld_Control_Panel.Classes.Global_Variables;
using Handheld_Control_Panel.Classes.TaskSchedulerWin32;
using Handheld_Control_Panel.Classes.Update_Software;
namespace Handheld_Control_Panel
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
string message = "An unhandled exception just occurred: " + e.Exception.Message + ". Stack Trace: " + e.Exception.StackTrace + ". Source: " + e.Exception.Source + ". Inner Exception: " + e.Exception.InnerException;
MessageBox.Show(message, "Exception Sample", MessageBoxButton.OK, MessageBoxImage.Error);
Log_Writer.writeLog(message);
Environment.Exit(0);
}
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
bool quietStart = false;
//if start is from system32 (task scheduled start) then set quietStart to true, means auto start
if (String.Equals("C:\\Windows\\System32", Directory.GetCurrentDirectory(), StringComparison.OrdinalIgnoreCase))
{
quietStart = true;
}
var splashScreen = new SplashScreenStartUp();
if (!Handheld_Control_Panel.Properties.Settings.Default.hideSplashScreen && !quietStart)
{
//if not quiet start then show splashscreen
this.MainWindow = splashScreen;
splashScreen.Show();
}
//you can do additional work here, call start routine
//do the update settings check first
Update_Software.checkUpdateSettings();
await Task.Run(() => Start_Up.Start_Routine());
this.MainWindow = new MainWindow();
if (quietStart)
{
MainWindow.Visibility = Visibility.Hidden;
}
else
{
if (!Handheld_Control_Panel.Properties.Settings.Default.hideSplashScreen)
{
splashScreen.Close();
}
MainWindow.Show();
}
}
private void Application_Exit(object sender, ExitEventArgs e)
{
//close task scheduler
// Dispose of thread to allow program to close properly
Handheld_Control_Panel.Classes.Task_Scheduler.Task_Scheduler.closeScheduler();
//mouse keyboard input hook
MouseKeyHook.Unsubscribe();
//kill controller thread
Global_Variables.killControllerThread = true;
//restore original power plan applied before launching the app
Powercfg.closingAppPowerPlanRestore();
//set auto tdp to false to make sure the autoTDP thread closes properly
Global_Variables.autoTDP = false;
if (Global_Variables.Device.FanCapable)
{
Global_Variables.softwareAutoFanControlEnabled = false;
Global_Variables.fanControlEnabled = false;
Fan_Management.setFanControlHardware();
WinRingEC_Management.OlsFree();
}
}
}
}