-
Notifications
You must be signed in to change notification settings - Fork 9
/
Form_yuzuEarlyAccessLauncher.cs
1457 lines (1328 loc) · 61.4 KB
/
Form_yuzuEarlyAccessLauncher.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 IWshRuntimeLibrary;
using SharpCompress.Archives;
using SharpCompress.Common;
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Management;
using System.Net;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Collections.Generic;
using static System.Net.WebRequestMethods;
using System.Data.SqlTypes;
using System.Xml;
using System.Drawing.Drawing2D;
namespace yuzu_Early_Access_Launcher
{
public partial class Form_yuzuEarlyAccessLauncher : Form
{
static readonly String path = Path.GetDirectoryName(Application.ExecutablePath), UserProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
String version = "", VersionName = "", branch = "", theme= "", file = "", firfile = "", launcherlatest = "", lurl = "", lsize = "", latest = "", url = "", ysize = "", kurl = "", lfirm = "", furl = "", fsize = "", installed = "", firm = "", reg = "", xsdir = "";
bool Internet, Downloading = false, DeleteyuzuArchive = false, DeleteFirmwareArchive = false, ExitLauncher = true;
long xdsize = 0;
Color Back, Fore;
StreamWriter log;
Ini ini = new Ini("launcher.ini");
public Form_yuzuEarlyAccessLauncher(String ver, String Theme, Color BackColor, Color ForeColor, Color ConBack, Color ConBackBox)
{
InitializeComponent();
version = ver;
try
{
branch = version.Split('-')[1];
}
catch (Exception)
{
branch = "main";
}
if (branch != "Preview")
{
if (Application.ExecutablePath != UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe")
{
if (path == UserProfile + "\\AppData\\Local\\Temp" || path.Split('\\').Last() == "Release" || !System.IO.File.Exists(UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe"))
{
if (!Directory.Exists(UserProfile + "\\AppData\\Local\\yuzu"))
{
Directory.CreateDirectory(UserProfile + "\\AppData\\Local\\yuzu");
}
if (System.IO.File.Exists(UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe"))
{
System.IO.File.Delete(UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe");
}
System.IO.File.Copy(Path.GetFullPath(Application.ExecutablePath), UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe");
Process.Start(UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe");
Environment.Exit(0);
}
else if (path.Split('\\').Last() != "Debug")
{
Process.Start(UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe");
Environment.Exit(0);
}
}
if (!System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\yuzu Early Access Launcher.lnk")) {
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\yuzu Early Access Launcher.lnk");
shortcut.Description = "Launch yuzu Early Access";
shortcut.TargetPath = UserProfile + "\\AppData\\Local\\yuzu\\yuzu Early Access Launcher.exe";
shortcut.Save();
}
if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs"))
{
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs");
}
if (!System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs\\yuzu Early Access Launcher.lnk"))
{
System.IO.File.Copy(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\yuzu Early Access Launcher.lnk", Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs\\yuzu Early Access Launcher.lnk");
}
}
Back = BackColor;
Fore = ForeColor;
theme = Theme;
groupBox_Progress.ForeColor = Fore;
groupBox_Firmware.ForeColor = Fore;
groupBox_SystemInfo.ForeColor = Fore;
groupBox_Settings.ForeColor = Fore;
groupBox_HelpandSupport.ForeColor = Fore;
comboBox_Theme.ForeColor = Fore;
button_Launch.BackColor = ConBack;
button_Download.BackColor = ConBack;
button_Cancel.BackColor = ConBack;
button_Firmware.BackColor = ConBack;
button_Video.BackColor = ConBack;
button_Support.BackColor = ConBack;
button_Report.BackColor = ConBack;
button_Compatibility.BackColor = ConBack;
button_FAQ.BackColor = ConBack;
button_About.BackColor = ConBack;
comboBox_Theme.BackColor = ConBackBox;
toolTip_1.SetToolTip(button_Video, "https://www.youtube.com/watch?v=nxNkwPrHAlo");
toolTip_1.SetToolTip(pictureBox_Refresh, "Refresh");
toolTip_1.SetToolTip(pictureBox_Settings, "Settings");
toolTip_1.SetToolTip(button_Report, "Report an Issue with this Launcher.");
toolTip_1.SetToolTip(button_Compatibility, "Check the Compatibiliy of different Games in yuzu as reported by Players using different hardwares from all over the World.");
toolTip_1.SetToolTip(button_FAQ, "Visit yuzu FAQ page to find the Solutions to Common Problems in yuzu.");
toolTip_1.SetToolTip(button_About, "More Information about yuzu and this Launcher.");
if (ini.Read("DeleteyuzuArchive", "settings") == "true" || ini.Read("DeleteyuzuArchive", "settings") == "True")
{
DeleteyuzuArchive = true;
}
else
{
ini.Write("DeleteyuzuArchive", DeleteyuzuArchive.ToString(), "settings");
}
if (ini.Read("DeleteFirmwareArchive", "settings") == "true" || ini.Read("DeleteFirmwareArchive", "settings") == "True")
{
DeleteFirmwareArchive = true;
}
else
{
ini.Write("DeleteFirmwareArchive", DeleteFirmwareArchive.ToString(), "settings");
}
if (ini.Read("ExitLauncher", "settings") == "false" || ini.Read("ExitLauncher", "settings") == "False")
{
ExitLauncher = false;
}
else
{
ini.Write("ExitLauncher", ExitLauncher.ToString(), "settings");
}
String themeini = ini.Read("theme", "settings");
if (themeini != "Light" && themeini != "Dark" && themeini != "Midnight Blue")
{
themeini = "Same as yuzu";
}
comboBox_Theme.Text = themeini;
label_ThemeInfo.Visible = false;
checkBox_Delyuzu.Checked = DeleteyuzuArchive;
checkBox_DelFirm.Checked = DeleteFirmwareArchive;
checkBox_Exit.Checked = ExitLauncher;
log = System.IO.File.CreateText("Launcher.log");
if (System.IO.File.Exists(UserProfile + "\\AppData\\Roaming\\yuzu\\config\\qt-config.ini"))
{
Ini yini = new Ini(UserProfile + "\\AppData\\Roaming\\yuzu\\config\\qt-config.ini");
reg = Path.Combine(yini.Read("nand_directory", "Data%20Storage"), "system\\Contents\\registered");
}
if (reg == "")
{
reg = UserProfile + "\\AppData\\Roaming\\yuzu\\nand\\system\\Contents\\registered";
}
backgroundWorker_SystemInfo.RunWorkerAsync();
backgroundWorker_Check.RunWorkerAsync();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == NativeMethods.WM_SHOWME)
{
ShowMe();
}
base.WndProc(ref m);
}
private void ShowMe()
{
if (WindowState == FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;
}
bool top = TopMost;
TopMost = true;
TopMost = top;
}
private void Button_Launch_Click(object sender, EventArgs e)
{
Process.Start("yuzu-windows-msvc-early-access\\yuzu.exe");
if (ExitLauncher)
{
Environment.Exit(0);
}
}
private void Button_Download_Click(object sender, EventArgs e)
{
backgroundWorker_Download.RunWorkerAsync(2);
}
private void Button_Firmware_Click(object sender, EventArgs e)
{
backgroundWorker_Download.RunWorkerAsync(3);
}
private void Button_Cancel_Click(object sender, EventArgs e)
{
Application.Restart();
Environment.Exit(0);
}
private void checkBox_Exit_CheckedChanged(object sender, EventArgs e)
{
ExitLauncher = checkBox_Exit.Checked;
ini.Write("ExitLauncher", ExitLauncher.ToString(), "settings");
}
private void checkBox_DelFirm_CheckedChanged(object sender, EventArgs e)
{
DeleteFirmwareArchive = checkBox_DelFirm.Checked;
ini.Write("DeleteFirmwareArchive", DeleteFirmwareArchive.ToString(), "settings");
}
private void checkBox_Delyuzu_CheckedChanged(object sender, EventArgs e)
{
DeleteyuzuArchive = checkBox_Delyuzu.Checked;
ini.Write("DeleteyuzuArchive", DeleteyuzuArchive.ToString(), "settings");
}
private void pictureBox_Refresh_Click(object sender, EventArgs e)
{
log.WriteLine("\nRefreshing");
progressBar1.Value = 0;
label_Progress.Text = progressBar1.Value.ToString() + "%";
button_Launch.Visible = false;
button_Download.Visible = false;
button_Firmware.Visible = true;
button_Cancel.Visible = true;
button_Launch.Font = new Font(button_Launch.Font.Name, button_Launch.Font.Size, FontStyle.Regular);
button_Download.Font = new Font(button_Download.Font.Name, button_Download.Font.Size, FontStyle.Regular);
button_Firmware.Font = new Font(button_Firmware.Font.Name, button_Firmware.Font.Size, FontStyle.Regular);
button_Launch.Size = new Size(350, 60);
button_Download.Size = new Size(350, 60);
button_Download.Location = new Point(368, 225);
groupBox_Progress.Visible = false;
groupBox_Firmware.Visible = false;
label_Info.Text = "";
label_Speed.Visible = true;
label_Info.Visible = false;
label_Info.ForeColor = Fore;
label_Info.Font = new Font(label_Info.Font.Name, label_Info.Font.Size, FontStyle.Regular);
label_Firmware.Font = new Font(label_Firmware.Font.Name, label_Firmware.Font.Size, FontStyle.Regular);
pictureBox_Refresh.Visible = false;
backgroundWorker_Check.RunWorkerAsync();
}
private void pictureBox_Settings_Click(object sender, EventArgs e)
{
groupBox_SystemInfo.Visible = groupBox_Settings.Visible;
groupBox_Settings.Visible = !groupBox_Settings.Visible;
}
private void comboBox_Theme_SelectedIndexChanged(object sender, EventArgs e)
{
String newtheme = comboBox_Theme.Text;
if (newtheme == "Same as yuzu")
{
if (System.IO.File.Exists(UserProfile + "\\AppData\\Roaming\\yuzu\\config\\qt-config.ini"))
{
Ini yini = new Ini(UserProfile + "\\AppData\\Roaming\\yuzu\\config\\qt-config.ini");
newtheme = yini.Read("theme", "UI");
}
else
{
newtheme = "Light";
}
}
if (newtheme == "qdarkstyle" || newtheme == "colorful_dark")
{
newtheme = "Dark";
}
if (newtheme == "qdarkstyle_midnight_blue" || newtheme == "colorful_midnight_blue")
{
newtheme = "Midnight Blue";
}
if (theme != newtheme)
{
label_ThemeInfo.Visible = true;
}
else
{
label_ThemeInfo.Visible = false;
}
ini.Write("theme", comboBox_Theme.Text, "settings");
}
private void comboBox_Theme_DropDownClosed(object sender, EventArgs e)
{
pictureBox_Settings.Focus();
}
private void Button_Video_Click(object sender, EventArgs e)
{
Process.Start("https://www.youtube.com/watch?v=nxNkwPrHAlo");
}
private void Button_Support_Click(object sender, EventArgs e)
{
Process.Start("https://www.youtube.com/channel/UCy3fBVKd0RMY05CgiiuGqSA?sub_confirmation=1");
}
private void Button_Report_Click(object sender, EventArgs e)
{
Process.Start("https://github.com/HimDek/yuzu-Early-Access-Launcher/issues/new");
}
private void Button_Compatibility_Click(object sender, EventArgs e)
{
Process.Start("https://yuzu-emu.org/game/");
}
private void Button_FAQ_Click(object sender, EventArgs e)
{
Process.Start("https://yuzu-emu.org/wiki/faq/");
}
private void Button_About_Click(object sender, EventArgs e)
{
var AboutBox = new Form_AboutBox(version)
{
BackColor = Back,
ForeColor = Fore,
Owner = this,
Text = "About yuzu Early Access and yuzu Early Access Launcher Version " + version.Replace('-', ' ')
};
AboutBox.ShowDialog();
}
private void Timer_Refresh_Tick(object sender, EventArgs e)
{
timer_Refresh.Enabled = false;
pictureBox_Refresh_Click(sender, e);
}
private void BackgroundWorker_SystemInfo_DoWork(object sender, DoWorkEventArgs e)
{
double GHz = 0, RAM = 0;
String CPU = "";
ManagementClass mc = new ManagementClass("win32_processor");
foreach (ManagementObject mo in mc.GetInstances())
{
CPU = (string)mo["Name"];
CPU = CPU.Replace("(TM)", "™").Replace("(tm)", "™").Replace("(R)", "®").Replace("(r)", "®").Replace("(C)", "©").Replace("(c)", "©").Replace(" ", " ").Replace(" ", " ");
GHz = 0.001 * (UInt32)mo.Properties["CurrentClockSpeed"].Value;
}
ManagementScope oMs = new ManagementScope();
ObjectQuery oQuery = new ObjectQuery("SELECT Capacity FROM Win32_PhysicalMemory");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
ManagementObjectCollection oCollection = oSearcher.Get();
foreach (ManagementObject obj in oCollection)
{
long mCap = Convert.ToInt64(obj["Capacity"]);
RAM += mCap;
}
e.Result = new Tuple<String, double, double>(CPU, GHz, RAM / 1024 / 1024);
}
private void BackgroundWorker_SystemInfo_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Tuple<String, double, double> Result = e.Result as Tuple<String, double, double>;
String CPU = Result.Item1;
double GHz = Result.Item2, RAM = Result.Item3;
label_CPUName.Text = "CPU: " + CPU.Split('@')[0] + "@ " + GHz.ToString("0.0") + " GHz";
label_RAMCapacity.Text = "RAM: " + (RAM / 1024).ToString("0.0") + " GB";
int NumberOfLogicalProcessors = Environment.ProcessorCount;
double MaxClockSpeed = GHz * 1000;
if (NumberOfLogicalProcessors < 2)
{
label_CPUInfo.Font = new Font(label_CPUInfo.Font.Name, label_CPUInfo.Font.Size, FontStyle.Bold);
label_CPUInfo.ForeColor = Color.Red;
label_CPUInfo.Text = "This CPU is not powerful enough to handle yuzu.";
}
if (NumberOfLogicalProcessors < 4)
{
if (MaxClockSpeed < 2000)
{
label_CPUInfo.Font = new Font(label_CPUInfo.Font.Name, label_CPUInfo.Font.Size, FontStyle.Bold);
label_CPUInfo.ForeColor = Color.Red;
label_CPUInfo.Text = "This CPU is not powerful enough to handle yuzu.";
}
else
{
label_CPUInfo.Font = new Font(label_CPUInfo.Font.Name, label_CPUInfo.Font.Size, FontStyle.Bold);
label_CPUInfo.Text = "This CPU might handle Single Core Emulation in yuzu.";
if (MaxClockSpeed > 2700)
{
label_CPUInfo.Font = new Font(label_CPUInfo.Font.Name, label_CPUInfo.Font.Size, FontStyle.Regular);
label_CPUInfo.Text = "This CPU should handle Single Core Emulation in yuzu.";
if (MaxClockSpeed > 3400)
{
label_CPUInfo.Text = "This CPU will handle Single Core Emulation in yuzu.";
}
}
}
}
else
{
if (MaxClockSpeed < 2000)
{
label_CPUInfo.Text = "This CPU might handle Multi Core Emulation in yuzu.";
if (MaxClockSpeed < 1500)
{
label_CPUInfo.Font = new Font(label_CPUInfo.Font.Name, label_CPUInfo.Font.Size, FontStyle.Bold);
label_CPUInfo.ForeColor = Color.Red;
label_CPUInfo.Text = "This CPU is not powerful enough to handle yuzu.";
}
}
else
{
label_CPUInfo.Text = "This CPU might be powerful enough to handle yuzu.";
if (MaxClockSpeed > 2700)
{
label_CPUInfo.Text = "This CPU should be powerful enough to handle yuzu.";
if (MaxClockSpeed > 3400)
{
label_CPUInfo.Text = "This CPU is powerful enough to handle yuzu.";
}
}
}
}
if (RAM < 8000)
{
label_RAMInfo.Font = new Font(label_RAMInfo.Font.Name, label_RAMInfo.Font.Size, FontStyle.Bold);
label_RAMInfo.Text = "This amount of RAM is not enough for yuzu to load heavy games.";
if (RAM < 6000)
{
label_RAMInfo.Font = new Font(label_RAMInfo.Font.Name, label_RAMInfo.Font.Size, FontStyle.Regular);
label_RAMInfo.Text = "This amount of RAM is not enough for yuzu to load large games.";
if (RAM < 4000)
{
label_RAMInfo.Font = new Font(label_RAMInfo.Font.Name, label_RAMInfo.Font.Size, FontStyle.Bold);
label_RAMInfo.ForeColor = Color.Red;
label_RAMInfo.Text = "This amount of RAM is enough for yuzu to load only light or small games.";
if (RAM < 2000)
{
label_RAMInfo.Text = "This amount of RAM is not enough for yuzu to load any game.";
}
}
}
}
else
{
label_RAMInfo.Text = "This amount of RAM is enough for yuzu to load most games.";
if (RAM > 12000)
{
label_RAMInfo.Text = "This amount of RAM is enough for yuzu to load even the heaviest game.";
if (RAM > 16000)
{
label_RAMInfo.Text = "This amount of RAM is more than enough for yuzu.";
}
}
}
}
private void BackgroundWorker_Check_DoWork(object sender, DoWorkEventArgs e)
{
log.AutoFlush = true;
if (System.IO.File.Exists(UserProfile + "\\AppData\\Local\\Temp\\yuzu Early Access Launcher.exe"))
{
System.IO.File.Delete(UserProfile + "\\AppData\\Local\\Temp\\yuzu Early Access Launcher.exe");
}
backgroundWorker_Check.ReportProgress(1);
String yuzulauncher = "", yuzu = "", /*firminf = "",*/ firmdata = "", keysdata = "", lfirmfile = "";
try
{
WebClient wc = new WebClient();
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
try
{
wc.Headers.Add("user-agent", "request");
yuzulauncher = wc.DownloadString(new System.Uri("https://api.github.com/repos/HimDek/yuzu-Early-Access-Launcher/releases/latest"));
backgroundWorker_Check.ReportProgress(2);
}
catch
{
wc.Headers.Add("user-agent", "request");
yuzulauncher = wc.DownloadString(new System.Uri("https://api.github.com/repos/HiDe-Techno-Tips/yuzu-Early-Access-Launcher/releases/latest"));
backgroundWorker_Check.ReportProgress(2);
}
wc.Headers.Add("user-agent", "request");
yuzu = wc.DownloadString(new System.Uri("https://api.github.com/repos/pineappleEA/pineapple-src/releases"));
wc.Headers.Add("user-agent", "request");
firmdata = wc.DownloadString(new System.Uri("https://archive.org/download/nintendo-switch-global-firmwares/nintendo-switch-global-firmwares_files.xml"));
wc.Headers.Add("user-agent", "request");
keysdata = wc.DownloadString(new System.Uri("https://archive.org/download/prod.keys/prod.keys_files.xml"));
Internet = true;
log.WriteLine(" Internet Connection is available");
}
catch (Exception)
{
Internet = false;
log.WriteLine(" Internet Connection is not available");
}
if (Internet)
{
launcherlatest = JsonDocument.Parse("[ " + yuzulauncher + " ]").RootElement[0].GetProperty("tag_name").ToString().Split('v')[1];
if (branch == "Preview")
{
launcherlatest = version;
}
VersionName = "Version " + version;
for (int i = 0; true; i++)
{
latest = JsonDocument.Parse(yuzu).RootElement[0].GetProperty("tag_name").ToString().Split('-').Last();
if (JsonDocument.Parse(JsonDocument.Parse(yuzu).RootElement[0].GetProperty("assets").ToString()).RootElement[i].GetProperty("name").ToString().Split('-').First() == "Windows")
{
url = JsonDocument.Parse(JsonDocument.Parse(yuzu).RootElement[0].GetProperty("assets").ToString()).RootElement[i].GetProperty("browser_download_url").ToString();
ysize = JsonDocument.Parse(JsonDocument.Parse(yuzu).RootElement[0].GetProperty("assets").ToString()).RootElement[i].GetProperty("size").ToString();
break;
}
}
lurl = JsonDocument.Parse(JsonDocument.Parse("[ " + yuzulauncher + " ]").RootElement[0].GetProperty("assets").ToString()).RootElement[0].GetProperty("browser_download_url").ToString();
lsize = JsonDocument.Parse(JsonDocument.Parse("[ " + yuzulauncher + " ]").RootElement[0].GetProperty("assets").ToString()).RootElement[0].GetProperty("size").ToString();
string[] firmparts = GetLatestFirmwareFileName(firmdata).Split(',');
fsize = firmparts[0];
lfirmfile = firmparts[1];
lfirm = lfirmfile.Replace(".zip", "").Replace("Firmware ", "");
furl = "https://archive.org/download/nintendo-switch-global-firmwares/Firmware%20" + lfirm + ".zip";
kurl = "https://archive.org/download/prod.keys/" + GetLatestKeysVersion(keysdata) + ".x.x/prod.keys";
log.WriteLine(" Latest Keys: " + kurl);
log.WriteLine(" Latest yuzu Early Access Launcher:");
log.WriteLine(" Version: " + launcherlatest);
log.WriteLine(" Size: " + lsize);
log.WriteLine(" URL: " + lurl);
log.WriteLine(" Latest yuzu Early Access:");
log.WriteLine(" Version: " + latest);
log.WriteLine(" Size: " + ysize);
log.WriteLine(" URL: " + url);
if (System.IO.File.Exists("prod.keys") || System.IO.File.Exists(UserProfile + "\\AppData\\Roaming\\yuzu\\keys\\prod.keys"))
{
backgroundWorker_Check.ReportProgress(3);
}
else
{
backgroundWorker_Check.ReportProgress(4);
}
try
{
WebClient wc = new WebClient();
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
wc.Headers.Add("user-agent", "request");
wc.DownloadFile(new System.Uri(kurl), UserProfile + "\\AppData\\Local\\Temp\\prod.keys");
log.WriteLine(" Done");
}
catch (Exception)
{
backgroundWorker_Check.ReportProgress(5);
}
if (System.IO.File.Exists(UserProfile + "\\AppData\\Local\\Temp\\prod.keys"))
{
if (System.IO.File.Exists("prod.keys"))
{
System.IO.File.Delete("prod.keys");
}
log.WriteLine("\nMoving \"" + UserProfile + "\\AppData\\Local\\Temp\\prod.keys\" to \"" + path + "\\prod.keys\"");
System.IO.File.Move(UserProfile + "\\AppData\\Local\\Temp\\prod.keys", "prod.keys");
log.WriteLine(" Done");
}
}
backgroundWorker_Check.ReportProgress(6);
if (System.IO.File.Exists("prod.keys"))
{
if (!Directory.Exists(UserProfile + "\\AppData\\Roaming\\yuzu\\keys"))
{
Directory.CreateDirectory(UserProfile + "\\AppData\\Roaming\\yuzu\\keys");
}
if (System.IO.File.Exists(UserProfile + "\\AppData\\Roaming\\yuzu\\keys\\prod.keys"))
{
System.IO.File.Delete(UserProfile + "\\AppData\\Roaming\\yuzu\\keys\\prod.keys");
}
log.WriteLine("\nCopying \"" + path + "\\prod.keys\" to \"" + UserProfile + "\\AppData\\Roaming\\yuzu\\keys\\prod.keys\"");
System.IO.File.Copy("prod.keys", UserProfile + "\\AppData\\Roaming\\yuzu\\keys\\prod.keys");
log.WriteLine(" Done");
}
if (System.IO.File.Exists("launcher.ini"))
{
log.WriteLine("\nReading \"" + path + "\\launcher.ini\"");
installed = ini.Read("version", "installed");
firm = ini.Read("firm", "installed");
if (installed != "")
{
log.WriteLine(" Detected yuzu Early Access " + installed + " from \"" + path + "\\launcher.ini\"");
}
else
{
log.WriteLine(" Not detected yuzu Early Access from \"" + path + "\\launcher.ini\"");
}
if (firm != "")
{
log.WriteLine(" Detected Switch Firmware " + firm + " from \"" + path + "\\launcher.ini\"");
}
else
{
log.WriteLine(" Not detected Switch Firmware from \"" + path + "\\launcher.ini\"");
}
try
{
if (Directory.GetFiles(reg, "*").Last().Split('.').Last() != "nca")
{
log.WriteLine(" But Switch Firmware is not installed in \"" + reg + "\"");
firm = "";
}
}
catch (Exception)
{
log.WriteLine(" But Switch Firmware is not installed in \"" + reg + "\"");
firm = "";
}
}
if (installed == "")
{
log.WriteLine("\nChecking for \"" + path + "\\yuzu-windows-msvc-early-access\\yuzu.exe\"");
if (System.IO.File.Exists("yuzu-windows-msvc-early-access\\yuzu.exe"))
{
log.WriteLine(" Preinstalled yuzu Early Access found in \"" + path + "\\yuzu-windows-msvc-early-access\"");
installed = "pre";
}
else
{
log.WriteLine(" Not found");
}
}
else
{
if (!System.IO.File.Exists("yuzu-windows-msvc-early-access\\yuzu.exe"))
{
log.WriteLine(" But yuzu Early Access is not installed in \"" + path + "\\yuzu-windows-msvc-early-access\"");
installed = "";
}
else
{
log.WriteLine(" yuzu Early Access is installed in \"" + path + "\\yuzu-windows-msvc-early-access\"");
}
}
if (installed == "")
{
installed = "0";
}
if (installed == "pre")
{
installed = "1";
}
if (firm == "")
{
firm = "0.0.0";
}
if (latest == "")
{
latest = "0";
}
if (lfirm == "")
{
lfirm = "0.0.0";
}
String latestfileVer = installed;
String latestfirfileVer = firm;
log.WriteLine("\nChecking Files");
for (int i = 0; i < 2; i++)
{
foreach (string f in Directory.EnumerateFiles(path, "Windows-Yuzu-EA-*.zip"))
{
int fVer = int.Parse(f.Split('\\').Last().Split('-', '.')[3]);
if (fVer < int.Parse(latestfileVer))
{
System.IO.File.Delete(f);
}
else
{
latestfileVer = fVer.ToString();
}
if (int.Parse(latestfileVer) > int.Parse(latest) || int.Parse(latestfileVer) > int.Parse(installed) || !Internet)
{
latest = latestfileVer;
}
if (Internet)
{
if (DeleteyuzuArchive)
{
if ((fVer < int.Parse(latestfileVer) && fVer < int.Parse(latest)) || int.Parse(latestfileVer) == int.Parse(installed))
{
System.IO.File.Delete(f);
}
}
}
}
}
for (int i = 0; i < 2; i++)
{
foreach (string f in Directory.EnumerateFiles(path, "Switch-Firmware-*.zip"))
{
Version fVer = Version.Parse(f.Split('\\').Last().Split('-', '.')[2] + "." + f.Split('\\').Last().Split('-', '.')[3] + "." + f.Split('\\').Last().Split('-', '.')[4]);
if (fVer < Version.Parse(latestfirfileVer))
{
System.IO.File.Delete(f);
}
else
{
latestfirfileVer = fVer.ToString();
}
if (Version.Parse(latestfirfileVer) > Version.Parse(lfirm) || Version.Parse(latestfirfileVer) > Version.Parse(firm) || !Internet)
{
lfirm = latestfirfileVer;
}
if (Internet)
{
if (DeleteFirmwareArchive)
{
if ((fVer < Version.Parse(latestfirfileVer) && fVer < Version.Parse(lfirm)) || Version.Parse(latestfirfileVer) == Version.Parse(firm))
{
System.IO.File.Delete(f);
}
}
}
}
}
if (installed == "0")
{
installed = "";
}
if (installed == "1")
{
installed = "pre";
}
if (firm == "0.0.0")
{
firm = "";
}
if (latest == "0")
{
latest = "";
}
if (lfirm == "0.0.0")
{
lfirm = "";
}
file = "Windows-Yuzu-EA-" + latest + ".zip";
firfile = "Switch-Firmware-" + lfirm + ".zip";
if (System.IO.File.Exists(file))
{
log.WriteLine(" Latest found yuzu Early Access file: \"" + path + "\\Windows-Yuzu-EA-" + latest + ".zip\"");
}
else
{
log.WriteLine(" Not found file \"" + path + "\\Windows-Yuzu-EA-" + latest + ".zip\"");
}
if (System.IO.File.Exists(firfile))
{
log.WriteLine(" Latest found Switch Firmware file: \"" + path + "\\Switch-Firmware-" + lfirm + ".zip\"");
}
else
{
log.WriteLine(" Not found file \"" + path + "\\Switch-Firmware-" + lfirm + ".zip\"");
}
if (Internet && version != launcherlatest)
{
Downloading = true;
backgroundWorker_Check.ReportProgress(7);
while (Downloading)
{
System.Threading.Thread.Sleep(1000);
}
}
}
private void BackgroundWorker_Check_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
label_Message.Size = new Size(728, 194);
if (e.ProgressPercentage == 1)
{
log.WriteLine("\nChecking Internet Connection");
label_Message.Text = "Checking Internet Connection!";
label_Message.Visible = true;
}
else if (e.ProgressPercentage == 2)
{
log.WriteLine("\nChecking for Updates");
label_Message.Text = "Checking for Updates!";
label_Message.Visible = true;
}
else if (e.ProgressPercentage == 3)
{
log.WriteLine("\nRetrieving latest \"prod.keys\" from \"" + kurl + "\" to \"" + UserProfile + "\\AppData\\Local\\Temp\\prod.keys\"");
label_Message.Text = "Downloading prod.keys!";
label_Message.Visible = true;
}
else if (e.ProgressPercentage == 4)
{
log.WriteLine("\nDownloading \"" + UserProfile + "\\AppData\\Local\\Temp\\prod.keys\" from \"" + kurl + "\"");
label_Message.Text = "Retrieving Latest prod.keys!";
label_Message.Visible = true;
}
else if (e.ProgressPercentage == 5)
{
log.WriteLine(" Failed Downloading \"" + path + "\\prod.keys\" from \"" + kurl + "\"");
label_Info.Text = "Could not download latest prod.keys!";
}
else if (e.ProgressPercentage == 6)
{
label_Message.Text = "\nReading Metadata!";
label_Message.Visible = true;
}
else if (e.ProgressPercentage == 7)
{
backgroundWorker_Download.RunWorkerAsync(1);
}
}
private void BackgroundWorker_Check_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
log.WriteLine("\nUpdating UI");
label_Message.Visible = false;
if (installed != "")
{
button_Launch.Font = new Font(button_Launch.Font.Name, button_Launch.Font.Size, FontStyle.Bold);
button_Launch.Text = "Launch yuzu Early Access " + installed;
toolTip_1.SetToolTip(button_Launch, path + "\\yuzu-windows-msvc-early-access\\yuzu.exe");
if (installed == "pre")
{
button_Launch.Text = "Launch yuzu Early Access";
}
}
if (Internet)
{
if (installed == "")
{
if (System.IO.File.Exists(file))
{
button_Download.Text = "Install yuzu Early Access " + latest;
toolTip_1.SetToolTip(button_Download, path + "\\" + file);
}
else
{
button_Download.Text = "Download yuzu Early Access " + latest;
toolTip_1.SetToolTip(button_Download, url);
}
button_Launch.Font = new Font(button_Launch.Font.Name, button_Launch.Font.Size, FontStyle.Regular);
button_Download.Font = new Font(button_Download.Font.Name, button_Download.Font.Size, FontStyle.Bold);
button_Download.Size = new Size(706, 60);
button_Download.Location = button_Launch.Location;
}
else
{
if (installed == latest)
{
if (System.IO.File.Exists(file))
{
button_Download.Text = "Reinstall yuzu Early Access " + latest;
toolTip_1.SetToolTip(button_Download, path + "\\" + file);
}
else
{
button_Download.Text = "Redownload yuzu Early Access " + latest;
toolTip_1.SetToolTip(button_Download, url);
}
}
else
{
if (System.IO.File.Exists(file))
{
button_Download.Text = "Update to yuzu Early Access " + latest;
toolTip_1.SetToolTip(button_Download, path + "\\" + file);
}
else
{
button_Download.Text = "Download yuzu Early Access " + latest;
toolTip_1.SetToolTip(button_Download, url);
}
button_Download.Font = new Font(button_Download.Font.Name, button_Download.Font.Size, FontStyle.Bold);
button_Launch.Font = new Font(button_Launch.Font.Name, button_Launch.Font.Size, FontStyle.Regular);
}
button_Launch.Visible = true;
}
button_Download.Visible = true;
if (firm == "")
{
if (System.IO.File.Exists(firfile))
{
button_Firmware.Text = "Install Firmware " + lfirm;
toolTip_1.SetToolTip(button_Firmware, path + "\\" + firfile);
}
else
{
button_Firmware.Text = "Download Firmware " + lfirm;
toolTip_1.SetToolTip(button_Firmware, furl);
}
button_Firmware.Font = new Font(button_Firmware.Font.Name, button_Firmware.Font.Size, FontStyle.Bold);
}
else
{
if (lfirm == firm)
{
if (System.IO.File.Exists(firfile))
{
button_Firmware.Text = "Reinstall Firmware " + lfirm;
toolTip_1.SetToolTip(button_Firmware, path + "\\" + firfile);
}
else
{
button_Firmware.Text = "Redownload Firmware " + lfirm;
toolTip_1.SetToolTip(button_Firmware, furl);
}
}
else
{
button_Firmware.Font = new Font(button_Firmware.Font.Name, button_Firmware.Font.Size, FontStyle.Bold);
if (System.IO.File.Exists(firfile))
{
button_Firmware.Text = "Update Firmware to " + lfirm;
toolTip_1.SetToolTip(button_Firmware, path + "\\" + firfile);
}
else
{
button_Firmware.Text = "Download Firmware " + lfirm;
toolTip_1.SetToolTip(button_Firmware, furl);
}
}
}
}
groupBox_Firmware.Visible = true;
if (!Internet)
{
toolTip_1.SetToolTip(button_Download, path + "\\" + file);
if (installed == "")
{
if (System.IO.File.Exists(file))
{
button_Download.Font = new Font(button_Download.Font.Name, button_Download.Font.Size, FontStyle.Bold);
button_Download.Text = "Install yuzu Early Access " + latest;