-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
195 lines (177 loc) · 7.93 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using NLog;
using NLog.Config;
using NLog.Targets;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing.Text;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
namespace CityLauncher
{
internal static class Program
{
private static readonly Logger Nlog = LogManager.GetCurrentClassLogger();
public static readonly string CurrentTime = DateTime.Now.ToString("dd-MM-yy__hh-mm-ss");
public static CityLauncher MainWindow;
public static IniHandler IniHandler;
public static FileHandler FileHandler;
public static InputHandler InputHandler;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
/// <summary>
/// Replacement Application for the original Batman: Arkham City BmLauncher
/// Offers more configuration options, enables compatibility with High-Res Texture Packs
/// and automatically takes care of the ReadOnly properties of each file, removing
/// any requirement to manually edit .ini files. Guarantees a much more comfortable user experience.
/// @author Neato (https://www.nexusmods.com/users/81089053)
/// </summary>
[STAThread]
static void Main(string[] args)
{
bool logs = true;
bool IsNewWindow = true;
using (Mutex mtx = new(true, "{BD4C408D-EF15-4C98-B792-C30D089E19D1}", out IsNewWindow))
{
if (args.Contains("-nologs"))
{
logs = false;
}
if (args.Contains("-nolauncher"))
{
SetupCulture();
SetupLogger(logs);
LauncherBypass();
}
else if (IsNewWindow)
{
SetupCulture();
SetupLogger(logs);
InitializeProgram();
Application.Run(MainWindow);
}
else
{
Process Current = Process.GetCurrentProcess();
foreach (Process P in Process.GetProcessesByName(Current.ProcessName))
{
if (P.Id != Current.Id)
{
SetForegroundWindow(P.MainWindowHandle);
break;
}
}
}
}
}
private static void SetupCulture()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
}
private static void InitializeProgram()
{
Nlog.Info("InitializeProgram - Starting logs at {0} on {1}.", DateTime.Now.ToString("HH:mm:ss"), DateTime.Now.ToString("D", new CultureInfo("en-GB")));
Nlog.Info("InitializeProgram - Current application version: {0}", Assembly.GetExecutingAssembly().GetName().Version.ToString());
ApplicationConfiguration.Initialize();
InitFonts();
MainWindow = new CityLauncher();
FileHandler = new FileHandler();
IniHandler = new IniHandler();
InputHandler = new InputHandler();
var SystemHandler = new SystemHandler();
MainWindow.GPULabel.Text = SystemHandler.GPUData;
MainWindow.CPULabel.Text = SystemHandler.CPUData;
new IniReader().InitDisplay();
new InputReader().InitControls();
new InputWriter().WriteBmInput();
}
private static void SetupLogger(bool logs)
{
LoggingConfiguration config = new();
ConsoleTarget logconsole = new("logconsole");
if (!Directory.Exists("logs"))
{
Directory.CreateDirectory("logs");
}
if (logs)
{
FileTarget logfile = new("logfile")
{
FileName = Directory.GetCurrentDirectory() + "\\logs\\citylauncher_report__" + CurrentTime + ".log"
};
config.AddRule(LogLevel.Debug, LogLevel.Error, logfile);
}
DirectoryInfo LogDirectory = new(Directory.GetCurrentDirectory() + "\\logs");
DateTime OldestAllowedArchive = DateTime.Now - new TimeSpan(3, 0, 0, 0);
foreach (FileInfo file in LogDirectory.GetFiles())
{
if (file.CreationTime < OldestAllowedArchive)
{
file.Delete();
}
}
config.AddRule(LogLevel.Debug, LogLevel.Error, logconsole);
LogManager.Configuration = config;
}
private static void InitFonts()
{
bool calibri = IsFontInstalled("calibri");
bool impact = IsFontInstalled("impact");
if (!impact && !calibri)
{
Nlog.Warn("InitFonts - Impact and Calibri are not installed. May cause display issues.");
MessageBox.Show("The fonts \"Calibri\" and \"Impact\" are missing on your system. This may lead to display and scaling issues inside of the application.", "Missing fonts!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else if (!impact)
{
Nlog.Warn("InitFonts - Impact is not installed. May cause display issues.");
MessageBox.Show("The font \"Impact\" is missing on your system. This may lead to display and scaling issues inside of the application.", "Missing font!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else if (!calibri)
{
Nlog.Warn("InitFonts - Calibri is not installed. May cause display issues.");
MessageBox.Show("The font \"Calibri\" is missing on your system. This may lead to display and scaling issues inside of the application.", "Missing font!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Nlog.Info("InitFonts - Necessary fonts installed.");
}
private static bool IsFontInstalled(string FontFamily)
{
using (Font f = new Font(FontFamily, 10f, FontStyle.Regular))
{
StringComparison comparison = StringComparison.InvariantCultureIgnoreCase;
return (string.Compare(FontFamily, f.Name, comparison) == 0);
}
}
private static void LauncherBypass()
{
Nlog.Info("LauncherBypass - Starting logs at {0} on {1}.", DateTime.Now.ToString("HH:mm:ss"), DateTime.Now.ToString("D", new CultureInfo("en-GB")));
using (Process LaunchGame = new())
{
try
{
if (FileHandler.DetectGameExe())
{
LaunchGame.StartInfo.FileName = "BatmanAC.exe";
LaunchGame.StartInfo.CreateNoWindow = true;
LaunchGame.Start();
Nlog.Info("LauncherBypass - Launching the game. Concluding logs at {0} on {1}.", DateTime.Now.ToString("HH:mm:ss"), DateTime.Now.ToString("D", new CultureInfo("en-GB")));
Application.Exit();
}
else
{
MessageBox.Show("Could not find 'BatmanAC.exe'.\nIs the Launcher in the correct folder?", "Error!", MessageBoxButtons.OK);
}
}
catch (Win32Exception e)
{
Nlog.Error("LauncherBypass - \"BatmanAC.exe\" does not appear to be a Windows executable file: {0}", e);
MessageBox.Show("'BatmanAC.exe' does not appear to be a Windows executable file!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}