-
Notifications
You must be signed in to change notification settings - Fork 51
/
MainForm.cs
4276 lines (3794 loc) · 187 KB
/
MainForm.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
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using AndroidSideloader.Models;
using AndroidSideloader.Utilities;
using JR.Utils.GUI.Forms;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;
using Newtonsoft.Json;
using SergeUtils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AndroidSideloader
{
public partial class MainForm : Form
{
private readonly ListViewColumnSorter lvwColumnSorter;
#if DEBUG
public static bool debugMode = true;
public bool DeviceConnected;
public bool keyheld;
public bool keyheld2;
public static string CurrAPK;
public static string CurrPCKG;
List<UploadGame> gamesToUpload = new List<UploadGame>();
public static string currremotesimple = String.Empty;
#else
public bool keyheld;
public static string CurrAPK;
public static string CurrPCKG;
private readonly List<UploadGame> gamesToUpload = new List<UploadGame>();
public static bool debugMode = false;
public bool DeviceConnected = false;
public static string currremotesimple = "";
#endif
private bool isLoading = true;
public static bool isOffline = false;
public static bool noRcloneUpdating;
public static bool hasPublicConfig = false;
public static bool enviromentCreated = false;
public static PublicConfig PublicConfigFile;
public static string PublicMirrorExtraArgs = " --tpslimit 1.0 --tpslimit-burst 3";
private bool manualIP;
private System.Windows.Forms.Timer _debounceTimer;
private CancellationTokenSource _cts;
private List<ListViewItem> _allItems;
public MainForm()
{
// Check for Offline Mode or No RCLONE Updating
string[] args = Environment.GetCommandLineArgs();
foreach (string arg in args)
{
if (arg == "--offline")
{
isOffline = true;
}
if (arg == "--no-rclone-update")
{
noRcloneUpdating = true;
}
}
if (isOffline)
{
_ = FlexibleMessageBox.Show(Program.form, "Offline mode activated. You can't download games in this mode, only do local stuff.");
}
InitializeComponent();
_debounceTimer = new System.Windows.Forms.Timer
{
Interval = 1000, // 1 second delay
Enabled = false
};
_debounceTimer.Tick += async (sender, e) => await RunSearch();
gamesQueListBox.DataSource = gamesQueueList;
//Time between asking for new apps if user clicks No. 96,0,0 DEFAULT
TimeSpan newDayReference = new TimeSpan(96, 0, 0);
//Time between asking for updates after uploading. 72,0,0 DEFAULT
TimeSpan newDayReference2 = new TimeSpan(72, 0, 0);
TimeSpan comparison;
TimeSpan comparison2;
//These two variables set to show difference.
DateTime A = Properties.Settings.Default.LastLaunch;
DateTime B = DateTime.Now;
DateTime C = Properties.Settings.Default.LastLaunch2;
comparison = B - A;
comparison2 = B - C;
// If enough time has passed reset property containing packagenames
if (comparison > newDayReference)
{
Properties.Settings.Default.ListUpped = false;
Properties.Settings.Default.NonAppPackages = String.Empty;
Properties.Settings.Default.AppPackages = String.Empty;
Properties.Settings.Default.LastLaunch = DateTime.Now;
Properties.Settings.Default.Save();
}
if (comparison2 > newDayReference2)
{
Properties.Settings.Default.LastLaunch2 = DateTime.Now;
Properties.Settings.Default.SubmittedUpdates = String.Empty;
Properties.Settings.Default.Save();
}
// Launch time used within debuglog.
string launchtime = DateTime.Now.ToString("hh:mmtt(UTC)");
_ = Logger.Log($"\n------\n------\nProgram Launched at: {launchtime}\n------\n------");
if (string.IsNullOrEmpty(Properties.Settings.Default.CurrentLogPath))
{
Properties.Settings.Default.CurrentLogPath = $"{Environment.CurrentDirectory}\\debuglog.txt";
}
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer
{
Interval = 840000 // 14 mins between wakeup commands
};
t.Tick += new EventHandler(timer_Tick);
t.Start();
System.Windows.Forms.Timer t2 = new System.Windows.Forms.Timer
{
Interval = 300 // 30ms
};
t2.Tick += new EventHandler(timer_Tick2);
t2.Start();
lvwColumnSorter = new ListViewColumnSorter();
gamesListView.ListViewItemSorter = lvwColumnSorter;
if (searchTextBox.Visible)
{
_ = searchTextBox.Focus();
}
}
public static string donorApps = String.Empty;
private string oldTitle = String.Empty;
public static bool updatesNotified = false;
public static string backupFolder;
private async void Form1_Load(object sender, EventArgs e)
{
Splash splash = new Splash();
splash.Show();
if (!isOffline)
{
if (File.Exists($"{Environment.CurrentDirectory}\\vrp-public.json"))
{
Thread worker = new Thread(() =>
{
SideloaderRCLONE.updatePublicConfig();
});
worker.Start();
while (worker.IsAlive)
{
Thread.Sleep(10);
}
try
{
string configFileData =
File.ReadAllText($"{Environment.CurrentDirectory}\\vrp-public.json");
PublicConfig config = JsonConvert.DeserializeObject<PublicConfig>(configFileData);
if (config != null
&& !string.IsNullOrWhiteSpace(config.BaseUri)
&& !string.IsNullOrWhiteSpace(config.Password))
{
PublicConfigFile = config;
hasPublicConfig = true;
}
}
catch
{
hasPublicConfig = false;
}
if (!hasPublicConfig)
{
_ = FlexibleMessageBox.Show(Program.form, "Failed to fetch public mirror config, and the current one is unreadable.\r\nPlease ensure you can access https://wiki.vrpirates.club/ in your browser.", "Config Update Failed", MessageBoxButtons.OK);
}
if (Directory.Exists($@"{Path.GetPathRoot(Environment.SystemDirectory)}\RSL\EBWebView"))
{
Directory.Delete($@"{Path.GetPathRoot(Environment.SystemDirectory)}\RSL\EBWebView", true);
}
}
}
if (File.Exists($"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\platform-tools\\adb.exe"))
{
_ = ADB.RunAdbCommandToString("kill-server");
_ = ADB.RunAdbCommandToString("start-server");
}
Properties.Settings.Default.MainDir = Environment.CurrentDirectory;
Properties.Settings.Default.Save();
Sideloader.downloadFiles();
await Task.Delay(100);
if (Directory.Exists(Sideloader.TempFolder))
{
Directory.Delete(Sideloader.TempFolder, true);
_ = Directory.CreateDirectory(Sideloader.TempFolder);
}
// Delete the Debug file if it is more than 5MB
string logFilePath = Properties.Settings.Default.CurrentLogPath;
if (File.Exists(logFilePath))
{
FileInfo fileInfo = new FileInfo(logFilePath);
long fileSizeInBytes = fileInfo.Length;
long maxSizeInBytes = 5 * 1024 * 1024; // 5MB in bytes
if (fileSizeInBytes > maxSizeInBytes)
{
File.Delete(logFilePath);
}
}
if (!isOffline)
{
RCLONE.Init();
}
if (Properties.Settings.Default.CallUpgrade)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.CallUpgrade = false;
Properties.Settings.Default.Save();
}
CenterToScreen();
gamesListView.View = View.Details;
gamesListView.FullRowSelect = true;
gamesListView.GridLines = false;
etaLabel.Text = String.Empty;
speedLabel.Text = String.Empty;
diskLabel.Text = String.Empty;
verLabel.Text = Updater.LocalVersion;
if (File.Exists("crashlog.txt"))
{
if (File.Exists(Properties.Settings.Default.CurrentCrashPath))
{
File.Delete(Properties.Settings.Default.CurrentCrashPath);
}
DialogResult dialogResult = FlexibleMessageBox.Show(Program.form, $"Sideloader crashed during your last use.\nPress OK if you'd like to send us your crash log.\n\n NOTE: THIS CAN TAKE UP TO 30 SECONDS.", "Crash Detected", MessageBoxButtons.OKCancel);
if (dialogResult == DialogResult.OK)
{
if (File.Exists($"{Environment.CurrentDirectory}\\crashlog.txt"))
{
string UUID = SideloaderUtilities.UUID();
System.IO.File.Move("crashlog.txt", $"{Environment.CurrentDirectory}\\{UUID}.log");
Properties.Settings.Default.CurrentCrashPath = $"{Environment.CurrentDirectory}\\{UUID}.log";
Properties.Settings.Default.CurrentCrashName = UUID;
Properties.Settings.Default.Save();
Clipboard.SetText(UUID);
_ = RCLONE.runRcloneCommand_UploadConfig($"copy \"{Properties.Settings.Default.CurrentCrashPath}\" RSL-gameuploads:CrashLogs");
_ = FlexibleMessageBox.Show(Program.form, $"Your CrashLog has been copied to the server.\nPlease mention your CrashLogID ({Properties.Settings.Default.CurrentCrashName}) to the Mods.\nIt has been automatically copied to your clipboard.");
Clipboard.SetText(Properties.Settings.Default.CurrentCrashName);
}
}
else
{
File.Delete($"{Environment.CurrentDirectory}\\crashlog.txt");
}
}
if (hasPublicConfig)
{
lblMirror.Text = " Public Mirror";
remotesList.Size = Size.Empty;
}
if (isOffline)
{
lblMirror.Text = " Offline Mode";
remotesList.Size = Size.Empty;
}
splash.Close();
}
private async void Form1_Shown(object sender, EventArgs e)
{
EnterInstallBox.Checked = Properties.Settings.Default.EnterKeyInstall;
new Thread(() =>
{
Thread.Sleep(10000);
freeDisclaimer.Invoke(() => {
freeDisclaimer.Dispose();
});
freeDisclaimer.Invoke(() => {
freeDisclaimer.Enabled = false;
});
}).Start();
progressBar.Style = ProgressBarStyle.Marquee;
Thread t1 = new Thread(() =>
{
if (!debugMode && Properties.Settings.Default.checkForUpdates)
{
Updater.AppName = "AndroidSideloader";
Updater.Repository = "VRPirates/rookie";
Updater.Update();
}
progressBar.Invoke(() => { progressBar.Style = ProgressBarStyle.Marquee; });
progressBar.Style = ProgressBarStyle.Marquee;
if (!isOffline)
{
changeTitle("Initializing Servers...");
initMirrors(true);
if (Properties.Settings.Default.autoUpdateConfig)
{
changeTitle("Checking for a new Configuration File...");
SideloaderRCLONE.updateDownloadConfig();
}
SideloaderRCLONE.updateUploadConfig();
if (!hasPublicConfig)
{
changeTitle("Grabbing the Games List...");
SideloaderRCLONE.initGames(currentRemote);
}
}
else
{
changeTitle("Offline mode enabled, no Rclone");
}
});
t1.SetApartmentState(ApartmentState.STA);
t1.IsBackground = true;
if (!isOffline)
{
t1.Start();
}
while (t1.IsAlive)
{
await Task.Delay(100);
}
Thread t5 = new Thread(() =>
{
if (!string.IsNullOrEmpty(Properties.Settings.Default.IPAddress))
{
string path = $"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\platform-tools\\adb.exe";
ProcessOutput wakeywakey = ADB.RunCommandToString($"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\platform-tools\\adb.exe shell input keyevent KEYCODE_WAKEUP", path);
if (wakeywakey.Output.Contains("more than one"))
{
Properties.Settings.Default.Wired = true;
Properties.Settings.Default.Save();
}
else if (wakeywakey.Output.Contains("found"))
{
Properties.Settings.Default.Wired = false;
Properties.Settings.Default.Save();
}
}
if (File.Exists($@"{Path.GetPathRoot(Environment.SystemDirectory)}\RSL\platform-tools\StoredIP.txt") && !Properties.Settings.Default.Wired)
{
string IPcmndfromtxt = File.ReadAllText($@"{Path.GetPathRoot(Environment.SystemDirectory)}\RSL\platform-tools\StoredIP.txt");
Properties.Settings.Default.IPAddress = IPcmndfromtxt;
Properties.Settings.Default.Save();
ProcessOutput IPoutput = ADB.RunAdbCommandToString(IPcmndfromtxt);
if (IPoutput.Output.Contains("attempt failed") || IPoutput.Output.Contains("refused"))
{
_ = FlexibleMessageBox.Show(Program.form, "Attempt to connect to saved IP has failed. This is usually due to rebooting the device or not having a STATIC IP set in your router.\nYou must enable Wireless ADB again!");
Properties.Settings.Default.IPAddress = "";
Properties.Settings.Default.Save();
File.Delete($"{Path.GetPathRoot(Environment.SystemDirectory)}RSL\\platform-tools\\StoredIP.txt");
}
else
{
_ = ADB.RunAdbCommandToString("shell settings put global wifi_wakeup_available 1");
_ = ADB.RunAdbCommandToString("shell settings put global wifi_wakeup_enabled 1");
}
}
else if (!File.Exists($@"{Path.GetPathRoot(Environment.SystemDirectory)}\RSL\platform-tools\StoredIP.txt"))
{
Properties.Settings.Default.IPAddress = "";
Properties.Settings.Default.Save();
}
})
{
IsBackground = true
};
t5.Start();
while (t5.IsAlive)
{
await Task.Delay(100);
}
if (hasPublicConfig)
{
Thread t2 = new Thread(() =>
{
changeTitle("Updating Metadata...");
SideloaderRCLONE.UpdateMetadataFromPublic();
changeTitle("Processing Metadata...");
SideloaderRCLONE.ProcessMetadataFromPublic();
})
{
IsBackground = true
};
if (!isOffline)
{
t2.Start();
}
while (t2.IsAlive)
{
await Task.Delay(50);
}
}
else
{
Thread t2 = new Thread(() =>
{
changeTitle("Updating Game Notes...");
SideloaderRCLONE.UpdateGameNotes(currentRemote);
});
Thread t3 = new Thread(() =>
{
changeTitle("Updating Game Thumbnails (This may take a minute or two)...");
SideloaderRCLONE.UpdateGamePhotos(currentRemote);
});
Thread t4 = new Thread(() =>
{
SideloaderRCLONE.UpdateNouns(currentRemote);
if (!Directory.Exists(SideloaderRCLONE.ThumbnailsFolder) ||
!Directory.Exists(SideloaderRCLONE.NotesFolder))
{
_ = FlexibleMessageBox.Show(Program.form,
"It seems you are missing the thumbnails and/or notes database, the first start of the sideloader takes a bit more time, so dont worry if it looks stuck!");
}
});
t2.IsBackground = true;
t3.IsBackground = true;
t4.IsBackground = true;
if (!isOffline)
{
t2.Start();
}
while (t2.IsAlive)
{
await Task.Delay(50);
}
if (!isOffline)
{
t3.Start();
}
while (t3.IsAlive)
{
await Task.Delay(50);
}
if (!isOffline)
{
t4.Start();
}
while (t4.IsAlive)
{
await Task.Delay(50);
}
}
progressBar.Style = ProgressBarStyle.Marquee;
changeTitle("Populating Game Update List, Almost There!");
_ = await CheckForDevice();
if (ADB.DeviceID.Length < 5)
{
nodeviceonstart = true;
}
listAppsBtn();
showAvailableSpace();
downloadInstallGameButton.Enabled = true;
isLoading = false;
initListView();
string[] files = Directory.GetFiles(Environment.CurrentDirectory);
foreach (string file in files)
{
string fileName = file;
while (fileName.Contains("\\"))
{
fileName = fileName.Substring(fileName.IndexOf("\\") + 1);
}
if (!fileName.Contains(Properties.Settings.Default.CurrentLogName) && !fileName.Contains(Properties.Settings.Default.CurrentCrashName))
{
if (!fileName.Contains("debuglog") && fileName.EndsWith(".txt"))
{
System.IO.File.Delete(fileName);
}
}
}
}
private void timer_Tick(object sender, EventArgs e)
{
_ = ADB.RunAdbCommandToString("shell input keyevent KEYCODE_WAKEUP");
}
private void timer_Tick2(object sender, EventArgs e)
{
keyheld = false;
}
public async void changeTitle(string txt, bool reset = true)
{
try
{
if (ProgressText.IsDisposed)
{
return;
}
this.Invoke(() => { oldTitle = txt; Text = "Rookie Sideloader v" + Updater.LocalVersion + " | " + txt; });
ProgressText.Invoke(() =>
{
if (!ProgressText.IsDisposed)
{
var states = new[] { "Sideloading", "Installing", "Copying", "Comparing", "Deleting" };
if (ProgressText.ForeColor == Color.LimeGreen)
{
ProgressText.ForeColor = Color.White;
}
if (states.Any(txt.Contains))
{
ProgressText.ForeColor = Color.LimeGreen;
}
ProgressText.Text = txt;
}
});
if (!reset)
{
return;
}
await Task.Delay(TimeSpan.FromSeconds(5));
this.Invoke(() => { Text = "Rookie Sideloader v" + Updater.LocalVersion + " | " + oldTitle; });
ProgressText.Invoke(() =>
{
if (!ProgressText.IsDisposed)
{
ProgressText.Text = oldTitle;
}
});
}
catch
{
}
}
private void ShowSubMenu(Panel subMenu)
{
subMenu.Visible = subMenu.Visible == false;
}
private async void startsideloadbutton_Click(object sender, EventArgs e)
{
ProcessOutput output = new ProcessOutput("", "");
string path = string.Empty;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Android apps (*.apk)|*.apk";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
path = openFileDialog.FileName;
}
else
{
return;
}
}
ADB.DeviceID = GetDeviceID();
Thread t1 = new Thread(() =>
{
output += ADB.Sideload(path);
})
{
IsBackground = true
};
t1.Start();
while (t1.IsAlive)
{
await Task.Delay(100);
}
showAvailableSpace();
ShowPrcOutput(output);
}
public void ShowPrcOutput(ProcessOutput prcout)
{
string message = $"Output: {prcout.Output}";
if (prcout.Error.Length != 0)
{
message += $"\nError: {prcout.Error}";
}
_ = FlexibleMessageBox.Show(Program.form, message);
}
public List<string> Devices = new List<string>();
public async Task<int> CheckForDevice()
{
Devices.Clear();
string output = string.Empty;
string error = string.Empty;
string battery = string.Empty;
ADB.DeviceID = GetDeviceID();
Thread t1 = new Thread(() =>
{
output = ADB.RunAdbCommandToString("devices").Output;
});
t1.Start();
while (t1.IsAlive)
{
await Task.Delay(100);
}
string[] line = output.Split('\n');
int i = 0;
devicesComboBox.Items.Clear();
_ = Logger.Log("Devices:");
foreach (string currLine in line)
{
if (i > 0 && currLine.Length > 0)
{
Devices.Add(currLine.Split(' ')[0]);
_ = devicesComboBox.Items.Add(currLine.Split(' ')[0]);
_ = Logger.Log(currLine.Split(' ')[0] + "\n", LogLevel.INFO, false);
}
Debug.WriteLine(currLine);
i++;
}
if (devicesComboBox.Items.Count > 0)
{
devicesComboBox.SelectedIndex = 0;
}
battery = ADB.RunAdbCommandToString("shell dumpsys battery").Output;
battery = Utilities.StringUtilities.RemoveEverythingBeforeFirst(battery, "level:");
battery = Utilities.StringUtilities.RemoveEverythingAfterFirst(battery, "\n");
battery = Utilities.StringUtilities.KeepOnlyNumbers(battery);
BatteryLbl.Text = battery + "%";
return devicesComboBox.SelectedIndex;
}
public async void devicesbutton_Click(object sender, EventArgs e)
{
_ = await CheckForDevice();
changeTitlebarToDevice();
showAvailableSpace();
}
public static void notify(string message)
{
if (Properties.Settings.Default.enableMessageBoxes == true)
{
_ = FlexibleMessageBox.Show(new Form
{
TopMost = true,
StartPosition = FormStartPosition.CenterScreen
}, message);
}
}
private async void obbcopybutton_Click(object sender, EventArgs e)
{
ProcessOutput output = new ProcessOutput(String.Empty, String.Empty);
FolderSelectDialog dialog = new FolderSelectDialog
{
Title = "Select OBB folder (must be direct OBB folder, E.G: com.Company.AppName)"
};
if (dialog.Show(Handle))
{
progressBar.Style = ProgressBarStyle.Marquee;
string path = dialog.FileName;
changeTitle($"Copying {path} obb to device...");
Thread t1 = new Thread(() =>
{
output += output += ADB.CopyOBB(path);
})
{
IsBackground = true
};
t1.Start();
while (t1.IsAlive)
{
await Task.Delay(100);
}
Program.form.changeTitle("Done.");
showAvailableSpace();
ShowPrcOutput(output);
Program.form.changeTitle(String.Empty);
}
}
public void changeTitlebarToDevice()
{
if (Devices == null || Devices.Count == 0)
{
this.Invoke(() =>
{
DeviceConnected = false;
Text = "No Device Connected";
if (!Properties.Settings.Default.nodevicemode)
{
DialogResult dialogResult = FlexibleMessageBox.Show(Program.form, "No device found. Please ensure the following: \n\n -Developer mode is enabled. \n -ADB drivers are installed. \n -ADB connection is enabled on your device (this can reset). \n -Your device is plugged in.\n\nThen press \"Retry\"", "No device found.", MessageBoxButtons.RetryCancel);
if (dialogResult == DialogResult.Retry)
{
devicesbutton.PerformClick();
}
}
});
return;
}
if (Devices[0].Contains("unauthorized"))
{
DeviceConnected = false;
this.Invoke(() =>
{
Text = "Device Not Authorized";
DialogResult dialogResult = FlexibleMessageBox.Show(Program.form, "Device not authorized, be sure to authorize computer on device.", "Not Authorized", MessageBoxButtons.RetryCancel);
if (dialogResult == DialogResult.Retry)
{
devicesbutton.PerformClick();
}
});
}
else
{
this.Invoke(() => { Text = "Device Connected with ID | " + Devices[0].Replace("device", String.Empty); });
DeviceConnected = true;
}
}
public async void showAvailableSpace()
{
string AvailableSpace = string.Empty;
if (!Properties.Settings.Default.nodevicemode || DeviceConnected)
{
try
{
ADB.DeviceID = GetDeviceID();
Thread t1 = new Thread(() =>
{
AvailableSpace = ADB.GetAvailableSpace();
});
t1.Start();
while (t1.IsAlive)
{
await Task.Delay(100);
}
diskLabel.Invoke(() => { diskLabel.Text = AvailableSpace; });
}
catch (Exception ex)
{
_ = Logger.Log($"Unable to get available space with the exception: {ex}", LogLevel.ERROR);
}
}
}
public string GetDeviceID()
{
string deviceId = string.Empty;
int index = -1;
devicesComboBox.Invoke(() => { index = devicesComboBox.SelectedIndex; });
if (index != -1)
{
devicesComboBox.Invoke(() => { deviceId = devicesComboBox.SelectedItem.ToString(); });
}
return deviceId;
}
public static string taa = String.Empty;
private async void backupbutton_Click(object sender, EventArgs e)
{
if (!Properties.Settings.Default.customBackupDir)
{
backupFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), $"Rookie Backups");
}
else
{
backupFolder = Path.Combine((Properties.Settings.Default.backupDir), $"Rookie Backups");
}
if (!Directory.Exists(backupFolder))
{
_ = Directory.CreateDirectory(backupFolder);
}
ProcessOutput output = new ProcessOutput(String.Empty, String.Empty);
Thread t1 = new Thread(() =>
{
string date_str = DateTime.Today.ToString("yyyy.MM.dd");
string CurrBackups = Path.Combine(backupFolder, date_str);
_ = FlexibleMessageBox.Show(Program.form, $"This may take up to a minute. Backing up gamesaves to {backupFolder}\\{date_str} (year.month.date)");
_ = Directory.CreateDirectory(CurrBackups);
output = ADB.RunAdbCommandToString($"pull \"/sdcard/Android/data\" \"{CurrBackups}\"");
changeTitle("Backing up gamedatas...");
try
{
Directory.Move(ADB.adbFolderPath + "\\data", CurrBackups + "\\data");
}
catch (Exception ex)
{
_ = Logger.Log($"Exception on backup: {ex}", LogLevel.ERROR);
}
})
{
IsBackground = true
};
t1.Start();
while (t1.IsAlive)
{
await Task.Delay(100);
}
ShowPrcOutput(output);
changeTitle(" \n\n");
}
private async void restorebutton_Click(object sender, EventArgs e)
{
ProcessOutput output = new ProcessOutput("", "");
FolderSelectDialog dialog = new FolderSelectDialog
{
Title = "Select full backup or packagename backup folder"
};
if (dialog.Show(Handle))
{
string path = dialog.FileName;
Thread t1 = new Thread(() =>
{
if (path.Contains("data"))
{
output += ADB.RunAdbCommandToString($"push \"{path}\" /sdcard/Android/");
}
else
{
output += ADB.RunAdbCommandToString($"push \"{path}\" /sdcard/Android/data/");
}
})
{
IsBackground = true
};
t1.Start();
while (t1.IsAlive)
{
await Task.Delay(100);
}
}
else
{
return;
}
ShowPrcOutput(output);
}
private string listApps()
{
ADB.DeviceID = GetDeviceID();
return ADB.RunAdbCommandToString("shell pm list packages -3").Output;
}
public void listAppsBtn()
{
m_combo.Invoke(() => { m_combo.Items.Clear(); });
string[] line = listApps().Split('\n');
string forsettings = string.Join(String.Empty, line);
Properties.Settings.Default.InstalledApps = forsettings;
Properties.Settings.Default.Save();
for (int i = 0; i < line.Length; i++)
{
if (line[i].Length > 9)
{
line[i] = line[i].Remove(0, 8);
line[i] = line[i].Remove(line[i].Length - 1);
foreach (string[] game in SideloaderRCLONE.games)
{
if (line[i].Length > 0 && game[2].Contains(line[i]))
{
line[i] = game[0];
}
}
}
}
Array.Sort(line);
foreach (string game in line)
{
if (game.Length > 0)
{
m_combo.Invoke(() => { _ = m_combo.Items.Add(game); });
}
}
m_combo.Invoke(() => { m_combo.MatchingMethod = StringMatchingMethod.NoWildcards; });
}
public static bool isuploading = false;
public static bool isworking = false;
private async void getApkButton_Click(object sender, EventArgs e)
{
if (isOffline)
{
notify("You are not connected to the Internet!");
return;
}
if (m_combo.SelectedIndex == -1)
{
notify("Please select an app first");
return;
}
DialogResult dialogResult1 = FlexibleMessageBox.Show(Program.form, $"Do you want to upload {m_combo.SelectedItem} now?", "Upload app?", MessageBoxButtons.YesNo);
if (dialogResult1 == DialogResult.No)
{
return;
}
if (!isworking)
{
isworking = true;
progressBar.Style = ProgressBarStyle.Marquee;
string HWID = SideloaderUtilities.UUID();
string GameName = m_combo.SelectedItem.ToString();
string packageName = Sideloader.gameNameToPackageName(GameName);
string InstalledVersionCode = ADB.RunAdbCommandToString($"shell \"dumpsys package {packageName} | grep versionCode -F\"").Output;
InstalledVersionCode = Utilities.StringUtilities.RemoveEverythingBeforeFirst(InstalledVersionCode, "versionCode=");
InstalledVersionCode = Utilities.StringUtilities.RemoveEverythingAfterFirst(InstalledVersionCode, " ");
ulong VersionInt = ulong.Parse(Utilities.StringUtilities.KeepOnlyNumbers(InstalledVersionCode));
string gameName = $"{GameName} v{VersionInt} {packageName} {HWID.Substring(0, 1)}";