-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
148 lines (134 loc) · 6.25 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
using Helper;
using PatchLauncher.Properties;
using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
namespace PatchLauncher
{
internal class Program
{
static readonly Mutex _mutex = new(true, ConstStrings.C_MUTEX_NAME);
static readonly string RegistryDetectedGameLocale = RegistryService.ReadRegKeyBFME1("locale");
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
string configPath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
if (!File.Exists(configPath))
{
Settings.Default.Upgrade();
Settings.Default.Reload();
Settings.Default.Save();
}
if (args.Length < 1)
{
return;
}
else if (args[0] == "--showLauncherUpdateLog")
{
LogHelper.LoggerBFME1GUI.Information(string.Format("Launched after LauncherUpdate now with version: > {0} <", AssemblyNameHelper.BFMELauncherGameVerion));
Settings.Default.OpenLauncherChangelogPageAfterUpdate = true;
Settings.Default.Save();
}
else if (args[0] != "--official")
{
LogHelper.LoggerBFME1GUI.Warning(string.Format("Parameter > {0} < not the expected one at void Main() args in {1}", args[0], AssemblyNameHelper.BFMELauncherGameName));
return;
}
}
catch (Exception ex)
{
LogHelper.LoggerBFME1GUI.Error(ex, "");
return;
}
ApplicationConfiguration.Initialize();
try
{
Thread.CurrentThread.CurrentUICulture = Settings.Default.LauncherLanguage switch
{
"de" => new System.Globalization.CultureInfo("de"),
_ => new System.Globalization.CultureInfo("en"),
};
if (!Settings.Default.IsGameInstalled)
{
switch (Settings.Default.InstalledLanguageISOCode)
{
case "de":
if (RegistryDetectedGameLocale == ConstStrings.C_REGISTRY_SERVICE_NOT_FOUND)
{
Settings.Default.InstalledLanguageISOCode = "de";
Settings.Default.Save();
}
else
{
Settings.Default.InstalledLanguageISOCode = RegistryDetectedGameLocale;
Settings.Default.Save();
}
break;
default:
if (RegistryDetectedGameLocale == ConstStrings.C_REGISTRY_SERVICE_NOT_FOUND)
{
Settings.Default.InstalledLanguageISOCode = "en_uk";
Settings.Default.Save();
}
else
{
Settings.Default.InstalledLanguageISOCode = RegistryDetectedGameLocale;
Settings.Default.Save();
}
break;
}
}
}
catch (Exception ex)
{
LogHelper.LoggerBFME1GUI.Error(ex, "");
}
if (_mutex.WaitOne(TimeSpan.Zero, true))
{
try
{
GameFileTools _gameFileTools = new();
//string json = File.ReadAllText(Path.Combine(Application.StartupPath, ConstStrings.C_JSON_GAMEDICTIONARY_MAIN_FILE));
GameFileDictionary gameFileDictionary = GameFileTools.LoadGameFileDictionary().Result; //JsonConvert.DeserializeObject<GameFileDictionary>(json)!; //GameFileTools.LoadGameFileDictionary().Result;
JSONDataListHelper._DictionarylanguageSettings = gameFileDictionary.LanguagePacks[AssemblyNameHelper.BFMELauncherGameName].ToDictionary(x => x.RegistrySelectedLocale, x => x);
JSONDataListHelper._MainPackSettings = gameFileDictionary.MainPacks[AssemblyNameHelper.BFMELauncherGameName];
JSONDataListHelper._DictionaryPatchPacksSettings = gameFileDictionary.PatchPacks[AssemblyNameHelper.BFMELauncherGameName].ToDictionary(x => x.Index, x => x);
PatchPacks _latestPatchPack = JSONDataListHelper._DictionaryPatchPacksSettings[JSONDataListHelper._DictionaryPatchPacksSettings.Keys.Max()];
PatchPacksBeta _betaPatchFiles = JSONDataListHelper._PatchBetaSettings = gameFileDictionary.PatchPacksBeta[AssemblyNameHelper.BFMELauncherGameName];
Settings.Default.LatestPatchVersion = _latestPatchPack.MinorVersion * 10 + _latestPatchPack.Revision;
Settings.Default.Save();
}
catch (Exception ex)
{
LogHelper.LoggerBFME1GUI.Error(ex, "JSON File Error!");
Application.Exit();
}
try
{
GameFileTools.EnsureBFMEAppDataFolderExists(AssemblyNameHelper.BFMELauncherGameName);
GameFileTools.EnsureBFMEOptionsIniFileExists(AssemblyNameHelper.BFMELauncherGameName);
Application.Run(new WinFormsMainGUI());
_mutex.ReleaseMutex();
_mutex.Dispose();
}
catch (Exception ex)
{
LogHelper.LoggerBFME1GUI.Error(ex, "Window Related Error!");
}
}
else
{
MessageBox.Show(Strings.Warning_AlreadyRunning, Strings.Warning_AlreadyRunningTitle);
Application.Exit();
}
}
}
}