-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathSideloader.cs
More file actions
371 lines (323 loc) · 16.2 KB
/
Sideloader.cs
File metadata and controls
371 lines (323 loc) · 16.2 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
using JR.Utils.GUI.Forms;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace AndroidSideloader
{
internal class Sideloader
{
public static string TempFolder = Path.Combine(Environment.CurrentDirectory, "temp");
public static string CrashLogPath = "crashlog.txt";
//push user.json to device (required for some devices like oculus quest)
public static void PushUserJsons()
{
foreach (string userJson in UsernameForm.userJsons)
{
UsernameForm.createUserJsonByName(Utilities.GeneralUtilities.randomString(16), userJson);
_ = ADB.RunAdbCommandToString("push \"" + Environment.CurrentDirectory + $"\\{userJson}\" " + " /sdcard/");
File.Delete(userJson);
}
}
//List of all installed package names from connected device
//public static List<string> InstalledPackageNames = new List<string>(); //Remove folder from device
public static ProcessOutput RemoveFolder(string path)
{
if (path == "/sdcard/Android/obb/" || path == "sdcard/Android/data/")
{
return null;
}
return ADB.RunAdbCommandToString($"shell rm -r {path}");
}
public static ProcessOutput RemoveFile(string path)
{
return ADB.RunAdbCommandToString($"shell rm -f {path}");
}
//For games that require manual install, like having another folder that isnt an obb
public static ProcessOutput RunADBCommandsFromFile(string path)
{
ProcessOutput output = new ProcessOutput();
string[] commands = File.ReadAllLines(path);
string currfolder = Path.GetDirectoryName(path);
string[] zipz = Directory.GetFiles(currfolder, "*.7z", SearchOption.AllDirectories);
foreach (string zip in zipz)
{
Utilities.Zip.ExtractFile($"{zip}", currfolder);
}
foreach (string cmd in commands)
{
if (cmd.StartsWith("adb"))
{
string replacement = "";
string pattern = "adb";
replacement = ADB.DeviceID.Length > 1
? $"{Properties.Settings.Default.ADBPath} -s {ADB.DeviceID}"
: $"{Properties.Settings.Default.ADBPath}";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(cmd, replacement);
Program.form.changeTitle($"Running {result}");
_ = Logger.Log($"Logging command: {result} from file: {path}");
output += ADB.RunAdbCommandToStringWOADB(result, path);
if (output.Error.Contains("mkdir"))
{
output.Error = "";
}
if (output.Output.Contains("reserved"))
{
output.Output = "";
}
}
}
output.Output += "Custom install successful!";
return output;
}
//Recursive sideload any apk fileD
public static ProcessOutput RecursiveOutput = new ProcessOutput();
public static void RecursiveSideload(string FolderPath)
{
try
{
foreach (string f in Directory.GetFiles(FolderPath))
{
if (Path.GetExtension(f) == ".apk")
{
RecursiveOutput += ADB.Sideload(f);
}
}
foreach (string d in Directory.GetDirectories(FolderPath))
{
RecursiveSideload(d);
}
}
catch (Exception ex) { _ = Logger.Log(ex.Message, LogLevel.ERROR); }
}
//Recursive copy any obb folder
public static void RecursiveCopyOBB(string FolderPath)
{
try
{
foreach (string f in Directory.GetFiles(FolderPath))
{
RecursiveOutput += ADB.CopyOBB(f);
}
foreach (string d in Directory.GetDirectories(FolderPath))
{
RecursiveCopyOBB(d);
}
}
catch (Exception ex) { _ = Logger.Log(ex.Message, LogLevel.ERROR); }
}
// Removes the game package and its OBB + Data Folders.
public static ProcessOutput UninstallGame(string packagename)
{
ProcessOutput output = ADB.UninstallPackage(packagename);
Program.form.changeTitle("");
_ = Sideloader.RemoveFolder("/sdcard/Android/obb/" + packagename);
_ = Sideloader.RemoveFolder("/sdcard/Android/data/" + packagename);
return output;
}
public static void BackupGame(string packagename)
{
if (!Properties.Settings.Default.customBackupDir)
{
MainForm.backupFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), $"Rookie Backups");
}
else
{
MainForm.backupFolder = Path.Combine((Properties.Settings.Default.backupDir), $"Rookie Backups");
}
if (!Directory.Exists(MainForm.backupFolder))
{
_ = Directory.CreateDirectory(MainForm.backupFolder);
}
Program.form.changeTitle($"Attempting to backup any savedata to {MainForm.backupFolder}\\Rookie Backups...");
_ = new ProcessOutput("", "");
string date_str = DateTime.Today.ToString("yyyy.MM.dd");
string CurrBackups = Path.Combine(MainForm.backupFolder, date_str);
if (!Directory.Exists(CurrBackups))
{
_ = Directory.CreateDirectory(CurrBackups);
}
_ = ADB.RunAdbCommandToString($"pull \"/sdcard/Android/data/{packagename}\" \"{CurrBackups}\"");
}
public static ProcessOutput DeleteFile(string GameName)
{
ProcessOutput output = new ProcessOutput("", "");
string packageName = Sideloader.gameNameToPackageName(GameName);
DialogResult dialogResult = FlexibleMessageBox.Show(Program.form, $"Are you sure you want to uninstall custom QU settings for {packageName}? this CANNOT be undone!", "WARNING!", MessageBoxButtons.YesNo);
if (dialogResult != DialogResult.Yes)
{
return output;
}
output = Sideloader.RemoveFile($"/sdcard/Android/data/{packageName}/private/Config.Json");
return output;
}
//Extracts apk from device, saves it by package name to sideloader folder
public static ProcessOutput getApk(string GameName)
{
_ = new ProcessOutput("", "");
string packageName = Sideloader.gameNameToPackageName(GameName);
ProcessOutput output = ADB.RunAdbCommandToString("shell pm path " + packageName);
string apkPath = output.Output; //Get apk
apkPath = apkPath.Remove(apkPath.Length - 1);
apkPath = apkPath.Remove(0, 8); //remove package:
apkPath = apkPath.Remove(apkPath.Length - 1);
if (File.Exists($"{Properties.Settings.Default.ADBFolder}\\base.apk"))
{
File.Delete($"{Properties.Settings.Default.ADBFolder}\\base.apk");
}
if (File.Exists($"{Properties.Settings.Default.MainDir}\\{packageName}\\{packageName}.apk"))
{
File.Delete($"{Properties.Settings.Default.MainDir}\\{packageName}\\{packageName}.apk");
}
output += ADB.RunAdbCommandToString("pull " + apkPath); //pull apk
if (Directory.Exists($"{Properties.Settings.Default.MainDir}\\{packageName}"))
{
Directory.Delete($"{Properties.Settings.Default.MainDir}\\{packageName}", true);
}
_ = Directory.CreateDirectory($"{Properties.Settings.Default.MainDir}\\{packageName}");
File.Move($"{Properties.Settings.Default.ADBFolder}\\base.apk", $"{Properties.Settings.Default.MainDir}\\{packageName}\\{packageName}.apk");
return output;
}
public static string gameNameToPackageName(string gameName)
{
foreach (string[] game in SideloaderRCLONE.games)
{
if (gameName.Equals(game[SideloaderRCLONE.GameNameIndex]) || gameName.Equals(game[SideloaderRCLONE.ReleaseNameIndex]))
return game[SideloaderRCLONE.PackageNameIndex];
}
return gameName;
}
public static string PackageNametoGameName(string packageName)
{
foreach (string[] game in SideloaderRCLONE.games)
{
if (packageName.Equals(game[SideloaderRCLONE.PackageNameIndex]))
return game[SideloaderRCLONE.ReleaseNameIndex];
}
return packageName;
}
public static string gameNameToSimpleName(string gameName)
{
foreach (string[] game in SideloaderRCLONE.games)
{
if (gameName.Equals(game[SideloaderRCLONE.GameNameIndex]) || gameName.Equals(game[SideloaderRCLONE.ReleaseNameIndex]))
return game[SideloaderRCLONE.GameNameIndex];
}
return gameName;
}
public static string PackageNameToSimpleName(string packageName)
{
foreach (string[] game in SideloaderRCLONE.games)
{
if (packageName.Contains(game[SideloaderRCLONE.PackageNameIndex]))
return game[SideloaderRCLONE.GameNameIndex];
}
return packageName;
}
// Download required dependencies.
public static void downloadFiles()
{
WebClient client = new WebClient();
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var currentAccessedWebsite = "";
try
{
if (!File.Exists("Sideloader Launcher.exe"))
{
currentAccessedWebsite = "github";
client.DownloadFile("https://github.com/VRPirates/rookie/raw/master/Sideloader%20Launcher.exe", "Sideloader Launcher.exe");
}
if (!File.Exists("Rookie Offline.cmd"))
{
currentAccessedWebsite = "github";
client.DownloadFile("https://github.com/VRPirates/rookie/raw/master/Rookie%20Offline.cmd", "Rookie Offline.cmd");
}
if (!File.Exists($"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\platform-tools\\aug2021.txt") || !File.Exists($"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\platform-tools\\adb.exe")) //if adb is not updated, download and auto extract
{
if (Directory.Exists($"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\2.8.2"))
{
Directory.Delete($"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\2.8.2", true);
}
if (Directory.Exists($"{Properties.Settings.Default.MainDir}\\adb"))
{
Directory.Delete($"{Properties.Settings.Default.MainDir}\\adb", true);
}
if (!Directory.Exists($"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\platform-tools"))
{
_ = Directory.CreateDirectory($"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\platform-tools");
}
currentAccessedWebsite = "github";
client.DownloadFile("https://github.com/VRPirates/rookie/raw/master/adb2.zip", "Ad.7z");
Utilities.Zip.ExtractFile(Environment.CurrentDirectory + "\\Ad.7z", $"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\platform-tools");
File.Delete("Ad.7z");
}
if (!Directory.Exists(Environment.CurrentDirectory + "\\rclone"))
{
currentAccessedWebsite = "rclone";
string url = Environment.Is64BitOperatingSystem
? "https://downloads.rclone.org/v1.62.2/rclone-v1.62.2-windows-amd64.zip"
: "https://downloads.rclone.org/v1.62.2/rclone-v1.62.2-windows-386.zip";
//Since sideloader is build for x86, it should work on both x86 and x64 so we download the according rclone version
client.DownloadFile(url, "rclone.zip");
Utilities.Zip.ExtractFile(Environment.CurrentDirectory + "\\rclone.zip", Environment.CurrentDirectory);
File.Delete("rclone.zip");
string[] folders = Directory.GetDirectories(Environment.CurrentDirectory);
foreach (string folder in folders)
{
if (folder.Contains("rclone"))
{
Directory.Move(folder, "rclone");
break; //only 1 rclone folder
}
}
}
else
{
string pathToRclone = Path.Combine(Environment.CurrentDirectory, "rclone", "rclone.exe");
if (File.Exists(pathToRclone))
{
var versionInfo = FileVersionInfo.GetVersionInfo(pathToRclone);
string version = versionInfo.ProductVersion;
Logger.Log($"Current RCLONE Version {version}");
if (!MainForm.noRcloneUpdating)
{
if (version != "1.62.2")
{
Logger.Log("RCLONE Version not matching! Downloading required version.", LogLevel.WARNING);
File.Delete(pathToRclone);
currentAccessedWebsite = "rclone";
string architecture = Environment.Is64BitOperatingSystem ? "amd64" : "386";
string url = $"https://downloads.rclone.org/v1.62.2/rclone-v1.62.2-windows-{architecture}.zip";
client.DownloadFile(url, "rclone.zip");
Utilities.Zip.ExtractFile(Path.Combine(Environment.CurrentDirectory, "rclone.zip"), Environment.CurrentDirectory);
File.Delete("rclone.zip");
string rcloneDirectory = Path.Combine(Environment.CurrentDirectory, $"rclone-v1.62.2-windows-{architecture}");
File.Move(Path.Combine(rcloneDirectory, "rclone.exe"), pathToRclone);
Directory.Delete(rcloneDirectory, true);
}
}
}
}
}
catch (Exception ex)
{
if (currentAccessedWebsite == "github")
{
_ = FlexibleMessageBox.Show($"You are unable to access the raw.githubusercontent.com page with the Exception: {ex.Message}\nSome files may be missing (ADB, Offline Script, Launcher)");
_ = FlexibleMessageBox.Show("These required files were unable to be downloaded\nRookie will now close, please use Offline Mode for manual sideloading if needed");
Application.Exit();
}
if (currentAccessedWebsite == "rclone")
{
_ = FlexibleMessageBox.Show($"You are unable to access the rclone page with the Exception: {ex.Message}\nSome files may be missing (RCLONE)");
_ = FlexibleMessageBox.Show("Rclone was unable to be downloaded\nRookie will now close, please use Offline Mode for manual sideloading if needed");
Application.Exit();
}
}
}
}
}