-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
107 lines (94 loc) · 2.68 KB
/
App.xaml.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
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Media;
using ControlLauncher.RMDP;
namespace ControlLauncher;
public partial class App
{
public FontFamily? AkzidenzGrotesk { get; private set; }
private static readonly string[] AKZIDENZ_GROTESK_PATHS =
{
"data/uiresources/p7/fonts/AkzidGrtskProBol.otf",
"data/uiresources/p7/fonts/AkzidGrtskProReg.otf",
};
private static bool CheckFontExistence(string path)
{
foreach (var fontPath in AKZIDENZ_GROTESK_PATHS)
{
var localFontPath = Path.Combine(path, Path.GetFileName(fontPath));
if (!File.Exists(localFontPath))
return false;
}
return true;
}
private void LoadFonts()
{
var exePath = AppContext.BaseDirectory;
if (!CheckFontExistence(exePath))
{
Debug.WriteLine("fonts are missing, will extract them");
try
{
if (!RMDPExtractor.ExtractGameFiles(exePath, "ep100-000-generic", AKZIDENZ_GROTESK_PATHS))
return;
Debug.WriteLine("font files extracted");
}
catch (Exception exception)
{
Debug.WriteLine(exception); // do nothing, FontFamily will be set to Inter in the XAML
}
}
// recheck font existence and load them
if (CheckFontExistence(exePath))
{
Debug.WriteLine("font files found");
var fontFamilyPath = Path.Combine(exePath, "#Akzidenz-Grotesk Pro");
this.AkzidenzGrotesk = new FontFamily(fontFamilyPath);
}
}
private void App_OnStartup(object sender, StartupEventArgs e)
{
if (!Helpers.IsLauncherInGameDir())
MessageBox.Show("Please put this launcher into Control's game directory.", "Installation failed", MessageBoxButton.OK, MessageBoxImage.Warning);
else
{
var args = Helpers.GetCommandLineArgs();
if (args.Contains("-dx11", StringComparer.OrdinalIgnoreCase))
{
Debug.WriteLine("Launching DX11 because -dx11");
Launcher.LaunchDX11(args);
this.Shutdown();
return;
}
if (args.Contains("-dx12", StringComparer.OrdinalIgnoreCase))
{
Debug.WriteLine("Launching DX12 because -dx12");
Launcher.LaunchDX12(args);
this.Shutdown();
return;
}
if (!Helpers.InstallRedistributableIfNeeded())
{
MessageBox.Show("Microsoft Visual C++ Redistributable installation failed.", "Installation failed", MessageBoxButton.OK, MessageBoxImage.Error);
this.Shutdown(1);
}
else if (Helpers.IsWin7OrWin8())
{
Debug.WriteLine("Launching DX11 because Win 7/8 detected");
Launcher.LaunchDX11(args);
this.Shutdown();
}
else if (!Helpers.CheckForRaytracing())
{
Debug.WriteLine("Launching DX11 because no RT");
Launcher.LaunchDX11(args);
this.Shutdown();
}
}
this.LoadFonts();
}
}