This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
109 lines (96 loc) · 3.79 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
using BmLauncherWForm.infrastructure;
using BmLauncherWForm.ui;
using NLog;
using NLog.Config;
using NLog.Targets;
using System;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace BmLauncherWForm
{
/// <summary>
/// Replacement Application for the original Batman: Arkham Asylum 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 frofoo (https://steamcommunity.com/id/frofoo)
/// </summary>
internal static class Program
{
// logger for easy debugging
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public static Factory MyFactory;
public static BmLauncherForm Client;
public static NvidiaWorker NvWorker;
private static readonly string CurrentTime = DateTime.Now.ToString("dd-MM-yy__hh-mm-ss");
// Mutex with this applications GUID as name
private static readonly Mutex Mutex = new Mutex(true, "{cbb275f6-724f-4e82-a403-e333dcf6c0bf}");
[STAThread]
private static void Main()
{
if (Mutex.WaitOne(TimeSpan.Zero, true))
{
SetupLogger();
logger.Info("Main - Starting logs at {0}, on {1}.",
DateTime.Now.ToString("HH:mm:ss"), DateTime.Now.ToString("D", new CultureInfo("en-GB")));
RunWindow();
Mutex.ReleaseMutex();
}
else
{
NativeMethods.PostMessage((IntPtr)NativeMethods.HwndBroadcast, NativeMethods.WmShowme, IntPtr.Zero,
IntPtr.Zero);
}
}
private static void SetupLogger()
{
LoggingConfiguration config = new LoggingConfiguration();
ConsoleTarget logconsole = new ConsoleTarget("logconsole");
if (!Directory.Exists("logs"))
{
Directory.CreateDirectory("logs");
}
FileTarget logfile = new FileTarget("logfile")
{
FileName = Directory.GetCurrentDirectory() + "\\logs\\bmlauncher_report__" + CurrentTime + ".log"
};
DirectoryInfo logDirectory = new DirectoryInfo(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;
}
private static void DetectTexmod()
{
DirectoryInfo d = new DirectoryInfo(Directory.GetCurrentDirectory());
FileInfo[] Files = d.GetFiles("*.exe");
foreach (FileInfo f in Files)
{
if (f.Name == "texmod_autoload.exe")
{
Factory.TexmodDetected = true;
}
}
}
public static void RunWindow()
{
new SysResolutions().getResolutions();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Client = new BmLauncherForm();
DetectTexmod();
MyFactory = new Factory(Client);
MyFactory.readFiles();
Application.Run(Client);
}
}
}