forked from ReClassNET/ReClass.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
107 lines (85 loc) · 2.47 KB
/
Copy pathProgram.cs
File metadata and controls
107 lines (85 loc) · 2.47 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
using System;
using System.Globalization;
using System.Security.Principal;
using System.Windows.Forms;
using Microsoft.SqlServer.MessageBox;
using ReClassNET.Forms;
using ReClassNET.Logger;
using ReClassNET.Memory;
using ReClassNET.UI;
using ReClassNET.Util;
namespace ReClassNET
{
static class Program
{
private static Settings settings;
private static ILogger logger;
private static Random random = new Random();
private static MainForm mainForm;
private static bool designMode = true;
public static Settings Settings => settings;
public static ILogger Logger => logger;
public static Random GlobalRandom => random;
public static MainForm MainForm => mainForm;
public static bool DesignMode => designMode;
[STAThread]
static void Main()
{
designMode = false; // The designer doesn't call Main()
DpiUtil.ConfigureProcess();
EnableDebugPrivileges();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
settings = Settings.Load(Constants.SettingsFile);
logger = new GuiLogger();
#if RELEASE
try
{
using (var nativeHelper = new NativeHelper())
{
mainForm = new MainForm(nativeHelper);
Application.Run(mainForm);
}
}
catch (Exception ex)
{
ShowException(ex);
}
#else
using (var nativeHelper = new NativeHelper())
{
mainForm = new MainForm(nativeHelper);
Application.Run(mainForm);
}
#endif
Settings.Save(settings, Constants.SettingsFile);
}
private static bool EnableDebugPrivileges()
{
var result = false;
IntPtr token;
if (NativeMethods.OpenProcessToken(System.Diagnostics.Process.GetCurrentProcess().Handle, TokenAccessLevels.AllAccess, out token))
{
var privileges = new NativeMethods.TOKEN_PRIVILEGES();
privileges.PrivilegeCount = 1;
privileges.Luid.LowPart = 0x14;
privileges.Luid.HighPart = 0;
privileges.Attributes = 2;
result = NativeMethods.AdjustTokenPrivileges(token, false, ref privileges, 0, IntPtr.Zero, IntPtr.Zero);
NativeMethods.CloseHandle(token);
}
return result;
}
/// <summary>Shows the exception in a special form.</summary>
/// <param name="ex">The exception.</param>
public static void ShowException(Exception ex)
{
ex.HelpLink = Constants.HelpUrl;
var msg = new ExceptionMessageBox(ex);
msg.ShowToolBar = true;
msg.Symbol = ExceptionMessageBoxSymbol.Error;
msg.Show(null);
}
}
}