forked from neatodev/CityLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
112 lines (98 loc) · 4.02 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
using NLog;
using NLog.Config;
using NLog.Targets;
using System.Diagnostics;
using System.Globalization;
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://steamcommunity.com/id/frofoo)
/// </summary>
[STAThread]
static void Main()
{
bool IsNewWindow = true;
using (Mutex mtx = new(true, "{BD4C408D-EF15-4C98-B792-C30D089E19D1}", out IsNewWindow))
{
if (IsNewWindow)
{
SetupCulture();
SetupLogger();
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")));
ApplicationConfiguration.Initialize();
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();
}
private static void SetupLogger()
{
LoggingConfiguration config = new();
ConsoleTarget logconsole = new("logconsole");
if (!Directory.Exists("logs"))
{
Directory.CreateDirectory("logs");
}
FileTarget logfile = new("logfile")
{
FileName = Directory.GetCurrentDirectory() + "\\logs\\citylauncher_report__" + CurrentTime + ".log"
};
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.Warn, logconsole);
config.AddRule(LogLevel.Debug, LogLevel.Warn, logfile);
LogManager.Configuration = config;
}
}
}