forked from wokhan/WFN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
59 lines (51 loc) · 2.08 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
using System;
using System.Windows;
using Wokhan.WindowsFirewallNotifier.Common;
using Wokhan.WindowsFirewallNotifier.Common.Helpers;
using Wokhan.WindowsFirewallNotifier.Common.Properties;
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);
CommonHelper.OverrideSettingsFile("WFN.config");
if (Settings.Default.AlwaysRunAs && !UacHelper.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);
}
private bool? _isElevated = null;
public bool IsElevated
{
get
{
if (_isElevated == null) { _isElevated = UacHelper.CheckProcessElevated(); }
return _isElevated.Value;
}
}
private void Application_Startup(object sender, StartupEventArgs e)
{
if (Settings.Default.AccentColor != null)
{
Resources["AccentColorBrush"] = Settings.Default.AccentColor;
}
}
internal void RestartAsAdmin()
{
ProcessHelper.ElevateCurrentProcess();
Environment.Exit(0);
}
}
}