Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
277 lines (249 loc) · 11.4 KB
/
Copy pathProgram.cs
File metadata and controls
277 lines (249 loc) · 11.4 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
* 6/17/22 11:33 PM
* PlexoDev/PlexoLauncherMain/Program.cs
* Main launcher for first time installations of Plexo
* pos0 2022
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Win32;
namespace PlexoLauncherMain
{
class Program
{
private static string currentVersion = ""; // we get this later on
private static string tempPath = Path.GetTempPath();
private static string plexoInstallPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
private static RegistryKey softwareClasses = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Classes", true);
private static bool uninstalling = false;
private static bool useProgramFiles = false;
private static string getStringFromUrl(string url)
{
using(WebClient wc = new WebClient())
{
return wc.DownloadString(url);
}
}
private static string generateRandString(int length = 8)
{
const string chars = "ABCDEF0123456789";
Random random = new Random();
string randomString = new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
return randomString;
}
private static async Task downloadFile(string url, string location)
{
using(WebClient wc = new WebClient())
{
try
{
await wc.DownloadFileTaskAsync(url, location);
} catch (WebException e)
{
MessageBox.Show("Plexo was not downloaded. Error: " + e.Message + " Ask for help in the Plexo discord, if needed.", "Error");
}
}
}
private static string generateBaseUrl(int type)
{
switch(type)
{
case 0: // plexxo.xyz
return "http://plexxo.xyz";
case 1: // setup.plexxo.xyz
return "http://setup.plexxo.xyz";
case 2: // api.plexxo.xyz
return "http://api.plexxo.xyz";
default: // plexxo.xyz
return "http://plexxo.xyz";
}
}
// https://stackoverflow.com/a/194223/
private static string getProgramFilesDir()
{
if (8 == IntPtr.Size || (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
{
return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
}
return Environment.GetEnvironmentVariable("ProgramFiles");
}
private static void registerInRegistry()
{
// Prelauncher
RegistryKey key = softwareClasses.CreateSubKey("plexo-prelaunch14l", true);
key.SetValue("", "URL: PlexoPreLaunch14L Protocol");
key.SetValue("URL Protocol", "");
RegistryKey key1 = key.CreateSubKey("DefaultIcon", true);
key1.SetValue("", plexoInstallPath + "\\Ple14L\\Versions\\" + currentVersion + "\\PlexoParseLauncherUri.exe");
RegistryKey key2 = key.CreateSubKey("shell", true);
RegistryKey key3 = key2.CreateSubKey("open", true);
RegistryKey key4 = key3.CreateSubKey("command", true);
key4.SetValue("", "\"" + plexoInstallPath + "\\Ple14L\\Versions\\" + currentVersion + "\\PlexoParseLauncherUri.exe" + "\" %1");
Console.WriteLine("Created all keys for Prelauncher.");
// Actual launcher
RegistryKey key5 = softwareClasses.CreateSubKey("ple14l-player", true);
key5.SetValue("", "URL: Ple14L Protocol");
key5.SetValue("URL Protocol", "");
RegistryKey key6 = key5.CreateSubKey("DefaultIcon", true);
key6.SetValue("", plexoInstallPath + "\\Ple14L\\Versions\\" + currentVersion + "\\RobloxPlayerLauncher.exe");
RegistryKey key7 = key5.CreateSubKey("shell", true);
RegistryKey key8 = key7.CreateSubKey("open", true);
RegistryKey key9 = key8.CreateSubKey("command", true);
key9.SetValue("", "\"" + plexoInstallPath + "\\Ple14L\\Versions\\" + currentVersion + "\\RobloxPlayerLauncher.exe" + "\" %1");
// Let's close everything now
key.Close();
key1.Close();
key2.Close();
key3.Close();
key4.Close();
key5.Close();
key6.Close();
key7.Close();
key8.Close();
key9.Close();
Console.WriteLine("Created all keys for actual launcher.");
Console.WriteLine("Created all keys successfully!");
}
private static bool regKeyExists(RegistryKey baseKey, string subKeyName)
{
RegistryKey ret = baseKey.OpenSubKey(subKeyName);
return ret != null;
}
private static void process_Exited(object sender, EventArgs args)
{
// we need to make sure that all of these actually exist before we create keys in the registry
if(useProgramFiles)
{
plexoInstallPath = getProgramFilesDir();
}
if (File.Exists(plexoInstallPath + "\\Ple14L\\Versions\\" + currentVersion + "\\RobloxPlayerLauncher.exe")
&& File.Exists(plexoInstallPath + "\\Ple14L\\Versions\\" + currentVersion + "\\PlexoParseLauncherUri.exe"))
{
Console.WriteLine("Plexo installation part one was a success, let's try to register our keys in the registry.");
try
{
registerInRegistry();
MessageBox.Show("Plexo Install was successful.", "Success", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
catch (Exception e)
{
MessageBox.Show("Plexo Install failed whilst writing registry keys. Error: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
else
{
Console.WriteLine("Cannot continue, as Plexo installation part one failed.");
MessageBox.Show("Plexo was not completely downloaded. Try installing again. If the issue persists, ask for help in the Discord.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(0);
}
}
private static bool isAdministrator()
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
private static void checkIfInstalled()
{
if (regKeyExists(softwareClasses, "plexo-prelaunch14l") || regKeyExists(softwareClasses, "ple14l-player"))
{
Console.WriteLine("Plexo is already installed!");
MessageBox.Show("Plexo is already installed!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(0);
}
}
static async Task Main(string[] args)
{
foreach(string arg in args)
{
switch(arg.ToLower())
{
case "-uninstall":
Console.WriteLine("Uninstalling argument found");
uninstalling = true;
break;
default:
break;
}
}
if(!uninstalling)
{
checkIfInstalled();
string bootstrapperExePath = tempPath + "\\PlexoPlayerLauncher-" + generateRandString() + ".exe";
currentVersion = getStringFromUrl(generateBaseUrl(1) + "/version");
Console.WriteLine("Downloading Bootstrapper...");
await downloadFile(generateBaseUrl(1) + "/Roblox.exe", bootstrapperExePath);
if (File.Exists(bootstrapperExePath))
{
Console.WriteLine("Bootstrapper found!");
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = bootstrapperExePath;
Process process = new Process();
process.EnableRaisingEvents = true;
process.Exited += new EventHandler(process_Exited);
process.StartInfo = info;
process.Start();
Console.WriteLine("Started Bootstrapper");
process.WaitForExit();
if(!Directory.Exists(plexoInstallPath + "\\Ple14L") && Directory.Exists(getProgramFilesDir() + "\\Ple14L"))
{
useProgramFiles = true;
}
}
else
{
Console.WriteLine("Cannot continue with installation, as the Bootstrapper was not found.");
MessageBox.Show("Plexo Install was unsuccessful. Bootstrapper was not found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
} else
{
Console.WriteLine("Uninstalling...");
if (!Directory.Exists(plexoInstallPath + "\\Ple14L") && Directory.Exists(getProgramFilesDir() + "\\Ple14L"))
{
Console.WriteLine("Using Program Files (x86) folder");
useProgramFiles = true;
}
if(useProgramFiles)
{
if (Directory.Exists(getProgramFilesDir() + "\\Ple14L"))
{
if(isAdministrator())
{
Console.WriteLine("Deleting folder " + getProgramFilesDir() + "\\Ple14L");
Directory.Delete(getProgramFilesDir() + "\\Ple14L", true);
} else
{
MessageBox.Show("You must run as administrator to uninstall Plexo.", "Error whilst uninstalling", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
}
} else
{
if (Directory.Exists(plexoInstallPath + "\\Ple14L"))
{
Console.WriteLine("Deleting folder " + plexoInstallPath + "\\Ple14L");
Directory.Delete(plexoInstallPath + "\\Ple14L", true);
}
}
if(regKeyExists(softwareClasses, "plexo-prelaunch14l") && regKeyExists(softwareClasses, "ple14l-player"))
{
Console.WriteLine("Deleting registry key plexo-prelaunch14l");
softwareClasses.DeleteSubKeyTree("plexo-prelaunch14l");
Console.WriteLine("Deleting registry key ple14l-player");
softwareClasses.DeleteSubKeyTree("ple14l-player");
}
Console.WriteLine("Successfully uninstalled Plexo!");
MessageBox.Show("Plexo Uninstall was successful!", "Uninstalled", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
Console.ReadKey();
//Environment.Exit(0);
}
}
}