-
Notifications
You must be signed in to change notification settings - Fork 111
/
Program.cs
74 lines (59 loc) · 2.24 KB
/
Program.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
using System;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using DevExpress.LookAndFeel;
using DevExpress.XtraSplashScreen;
namespace SQLIndexManager {
static class Program {
[STAThread]
static void Main(string[] args) {
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
if (args != null && args.Length > 0) {
Settings.IgnoreFileSetting = true;
Output.Current.Add($"Command line: {string.Join(" ", args)}");
try {
AttachConsole();
var provider = new CmdWorker(CmdParser.Parse(args));
Environment.Exit(provider.FixIndexes());
}
catch (Exception ex) {
Output.Current.Add(ex.Message);
}
}
else {
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
UserLookAndFeel.Default.SetSkinStyle("Office 2016 Dark");
SplashScreenManager.ShowForm(typeof(SplashScreenBox));
var mainBox = new MainBox();
SplashScreenManager.CloseForm();
Application.Run(mainBox);
}
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) {
Utils.ShowErrorFrom(e.Exception);
}
private static void AttachConsole() {
const uint attachParentProcess = 0xffffffff;
const uint errorSuccess = 0;
const uint errorAccessDenied = 5;
bool consoleAttached = NativeMethods.AttachConsole(attachParentProcess);
if (consoleAttached) return;
var error = NativeMethods.GetLastError();
if (error == errorSuccess || error == errorAccessDenied)
consoleAttached = true;
if (!consoleAttached && !NativeMethods.AllocConsole())
Environment.Exit(1);
else
Console.OutputEncoding = (Encoding)Console.OutputEncoding.Clone();
}
}
}