-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bootstrap.cs
151 lines (132 loc) · 5.04 KB
/
Bootstrap.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
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace BedrockLauncher.Bootstrap
{
public static class Bootstrap
{
public static Main BootstrapWindow;
public static void CheckForNETRuntime()
{
Thread.Sleep(500);
bool result = false;
string minimumVersionS = "6.0";
try
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\WOW6432Node\\dotnet\\Setup\\InstalledVersions\\x64\\sharedfx\\Microsoft.WindowsDesktop.App"))
{
Version currentVersion;
Version minimumVersion = new Version(minimumVersionS);
if (key != null)
{
foreach (var item in key.GetValueNames())
{
if (Version.TryParse(item, out currentVersion))
{
if (currentVersion.CompareTo(minimumVersion) >= 0)
{
result = true;
break;
}
}
}
}
}
}
catch (Exception) { }
if (!result)
{
ShowMessageBox("You need .NET Desktop Runtime " + minimumVersionS + " or higher to run this application! Please download it!");
Application.Exit();
}
}
public static void CheckForVCRuntime()
{
Thread.Sleep(500);
bool result = false;
string minimumVersionS = "14.14.26405.0";
try
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64"))
{
if (key != null)
{
Object o = key.GetValue("Version");
if (o != null)
{
Version currentVersion = new Version((o as String).Replace("v", ""));
Version minimumVersion = new Version(minimumVersionS);
if (currentVersion.CompareTo(minimumVersion) >= 0) result = true;
}
}
}
}
catch (Exception) { }
if (!result)
{
ShowMessageBox("You need VC++ Runtime " + minimumVersionS + " or higher to run this application! Please download it!");
Application.Exit();
}
}
public static void CheckForWindowsVersion()
{
Thread.Sleep(500);
bool result = false;
string minimumVersionS = "10.0.19041.0";
try
{
Version currentVersion = Environment.OSVersion.Version;
Version minimumVersion = new Version(minimumVersionS);
if (currentVersion.CompareTo(minimumVersion) >= 0) result = true;
}
catch (Exception) { }
if (!result)
{
ShowMessageBox("This application only works on Windows version " + minimumVersionS + " or above!");
Application.Exit();
}
}
public static void StartLauncher()
{
Thread.Sleep(500);
string currentDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string launcherExePath1 = Path.Combine(currentDir, "app", "BedrockLauncher.exe");
string launcherExePath2 = Path.Combine(currentDir, "app", "launcher.exe");
if (File.Exists(launcherExePath1)) StartProcess(launcherExePath1);
else if (File.Exists(launcherExePath2)) StartProcess(launcherExePath2);
else
{
ShowMessageBox("Launcher files missing!");
Application.Exit();
}
void StartProcess(string path)
{
var startInfo = new ProcessStartInfo(path);
startInfo.Arguments = string.Join(" ", Environment.GetCommandLineArgs());
startInfo.UseShellExecute = true;
Process.Start(startInfo);
Application.Exit();
}
}
private static void ShowMessageBox(string message)
{
BootstrapWindow.Invoke((MethodInvoker)delegate
{
BootstrapWindow.TopMost = false;
});
MessageBox.Show(message);
BootstrapWindow.Invoke((MethodInvoker)delegate
{
BootstrapWindow.TopMost = true;
});
}
}
}