forked from wokhan/WFN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
62 lines (51 loc) · 2.25 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
using System;
using System.Windows;
using Wokhan.WindowsFirewallNotifier.Common.Config;
using Wokhan.WindowsFirewallNotifier.Common.Helpers;
using Wokhan.WindowsFirewallNotifier.Common.Logging;
using Wokhan.WindowsFirewallNotifier.Common.Processes;
namespace Wokhan.WindowsFirewallNotifier.Console
{
public partial class App : Application
{
public App() : base()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
this.DispatcherUnhandledException += Current_DispatcherUnhandledException;
LogHelper.Debug("Starting Console: " + Environment.CommandLine);
if (Settings.Default.AlwaysRunAs && !UAC.CheckProcessElevated())
{
RestartAsAdmin();
}
}
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message, Common.Properties.Resources.MSG_DLG_ERR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show(((Exception)e.ExceptionObject).Message, Common.Properties.Resources.MSG_DLG_ERR_TITLE, MessageBoxButton.OK, MessageBoxImage.Error);
}
public bool IsElevated { get; } = UAC.CheckProcessElevated();
private void Application_Startup(object sender, StartupEventArgs e)
{
if (Settings.Default.AccentColor != null)
{
Resources["AccentColorBrush"] = Settings.Default.AccentColor;
}
if (Settings.Default.ConsoleSizeWidth > 900)
{
Resources["ConsoleSizeWidth"] = Convert.ToDouble(Settings.Default.ConsoleSizeWidth);
}
if (Settings.Default.ConsoleSizeHeight > 600)
{
Resources["ConsoleSizeHeight"] = Convert.ToDouble(Settings.Default.ConsoleSizeHeight);
}
}
internal void RestartAsAdmin()
{
ProcessHelper.ElevateCurrentProcess();
Environment.Exit(0);
}
}
}