-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMainWindow.xaml.cs
961 lines (950 loc) · 36.5 KB
/
MainWindow.xaml.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
using GameLauncher.Models;
using GameLauncher.Properties;
using GameLauncher.ViewModels;
using GameLauncher.Views;
using MaterialDesignThemes.Wpf;
using Microsoft.Win32;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Media;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Text.RegularExpressions;
using System.Device.Location;
using Innovative.SolarCalculator;
namespace GameLauncher
{
public partial class MainWindow : Window
{
public bool isDownloadOpen = false;
public bool isExeSearchOpen = false;
public static AddGames DialogAddGames = new AddGames();
public static EditGames DialogEditGames = new EditGames();
public static ExeSelection DialogExeSelection = new ExeSelection();
public static ObservableCollection<GameList> GameListMW
{
get; set;
}
public static ObservableCollection<GenreList> GenreListMW
{
get; set;
}
public LoadAllGames lag = new LoadAllGames();
private BannerViewModel bannerViewModel = new BannerViewModel();
private ListViewModel listViewModel = new ListViewModel();
private PosterViewModel posterViewModel = new PosterViewModel();
private SettingsViewModel settingsViewModel = new SettingsViewModel();
private ExesViewModel exesViewModel = new ExesViewModel();
private Loading loadingdialog = new Loading();
public Loading loadingprogressdialog = new Loading();
public PosterView pv = new PosterView();
public BannerView bv = new BannerView();
public Views.ListView lv = new Views.ListView();
public CollectionViewSource cvs;
public bool isDialogOpen;
public bool isLoading;
public string dialogOpen;
public string DLGameTitle;
public string DLImgType;
public string view;
public string newText;
public BackgroundWorker lagbw;
public bool LauncherSteam;
public bool LauncherEpic;
public bool LauncherUplay;
public bool LauncherOrigin;
public bool LauncherBattleNet;
public string SteamExePath;
public string EpicExePath;
public string UplayExePath;
public string OriginExePath;
public string BattleNetExePath;
public DateTime sunriseTime;
public DateTime sunsetTime;
public MainWindow()
{
MakeDirectories();
MakeDefaultGenres();
lagbw = new BackgroundWorker
{
WorkerReportsProgress = true
};
lagbw.ProgressChanged += LagBWProgressChanged;
lagbw.DoWork += LagBWDoWork;
lagbw.RunWorkerCompleted += LagBWRunWorkerCompleted;
Trace.Listeners.Clear();
CheckLaunchersExist();
FixFilePaths();
InitTraceListen();
this.Height = (SystemParameters.PrimaryScreenHeight * 0.75);
this.Width = (SystemParameters.PrimaryScreenWidth * 0.75);
LoadAllGames lag = new LoadAllGames();
LoadSearch ls = new LoadSearch();
lag.LoadGenres();
InitializeComponent();
ManageLauncherIconVisibility();
LoadAllViews();
DataContext = null;
isDownloadOpen = false;
LoadSettings();
Trace.WriteLine(DateTime.Now + ": New Session started");
}
public void CheckLaunchersExist()
{
//Steam checker
try
{
string steam32 = "SOFTWARE\\VALVE";
string steam64 = "SOFTWARE\\Wow6432Node\\Valve";
string steam32path;
string steam64path;
RegistryKey key32 = Registry.LocalMachine.OpenSubKey(steam32);
RegistryKey key64 = Registry.LocalMachine.OpenSubKey(steam64);
if (key64.ToString() != null || key64.ToString() != "")
{
//Steam is installed - 64 bit
foreach (string k64subKey in key64.GetSubKeyNames())
{
using (RegistryKey subKey = key64.OpenSubKey(k64subKey))
{
steam64path = subKey.GetValue("InstallPath").ToString();
SteamExePath = steam64path + "\\Steam.exe";
LauncherSteam = true;
}
}
}
if (key32.ToString() != null || key32.ToString() != "")
{
//Steam is installed - 32 bit
foreach (string k32subKey in key32.GetSubKeyNames())
{
using (RegistryKey subKey = key32.OpenSubKey(k32subKey))
{
steam32path = subKey.GetValue("InstallPath").ToString();
SteamExePath = steam32path + "\\Steam.exe";
LauncherSteam = true;
}
}
}
}
catch (Exception e) { Trace.WriteLine("Steam Check Failed: " + e); }
//Epic Games Checker
try
{
string epicRegistry = "SOFTWARE\\WOW6432Node\\EpicGames\\Unreal Engine";
string epicGamesDir;
RegistryKey epickey = Registry.LocalMachine.OpenSubKey(epicRegistry);
foreach (string ksubkey in epickey.GetSubKeyNames())
{
using (RegistryKey subkey = epickey.OpenSubKey(ksubkey))
{
epicGamesDir = subkey.GetValue("InstalledDirectory").ToString();
epicGamesDir = epicGamesDir.Substring(0, epicGamesDir.Length - 4);
EpicExePath = epicGamesDir + "Launcher\\Portal\\Binaries\\Win32\\EpicGamesLauncher.exe";
LauncherEpic = true;
}
}
}
catch (Exception e) { Trace.WriteLine("Epic Check Failed: " + e); }
//Origin Checker
try
{
string regkey = "SOFTWARE\\WOW6432Node\\Origin";
RegistryKey originkey = Registry.LocalMachine.OpenSubKey(regkey);
using (RegistryKey subkey = originkey.OpenSubKey(regkey))
{
OriginExePath = originkey.GetValue("ClientPath").ToString();
LauncherOrigin = true;
}
}
catch (Exception e) { Trace.WriteLine("Origin Check Failed: " + e); }
//BattleNet Checker
try
{
string regkey = "SOFTWARE\\WOW6432Node\\Blizzard Entertainment\\Battle.net\\Capabilities";
RegistryKey battlenetKey = Registry.LocalMachine.OpenSubKey(regkey);
using (RegistryKey subkey = battlenetKey.OpenSubKey(regkey))
{
string battlenetExe = battlenetKey.GetValue("ApplicationIcon").ToString();
battlenetExe = battlenetExe.Replace("\"", "");
BattleNetExePath = battlenetExe.Replace(",0", "");
LauncherBattleNet = true;
}
}
catch (Exception e) { Trace.WriteLine("BattleNet Check Failed: " + e); }
//Uplay Checker
try
{
string regkey = "SOFTWARE\\WOW6432Node\\Ubisoft\\Launcher";
RegistryKey uplay = Registry.LocalMachine.OpenSubKey(regkey);
using (RegistryKey subkey = uplay.OpenSubKey(regkey))
{
UplayExePath = uplay.GetValue("InstallDir").ToString();
UplayExePath = UplayExePath + "Uplay.exe";
LauncherUplay = true;
}
}
catch (Exception e) { Trace.WriteLine("Uplay Check Failed: " + e); }
}
public void ManageLauncherIconVisibility()
{
if (LauncherSteam == false)
{
SteamLaunchBtn.Visibility = Visibility.Collapsed;
}
if (LauncherEpic == false)
{
EpicLaunchBtn.Visibility = Visibility.Collapsed;
}
if (LauncherOrigin == false)
{
OriginLaunchBtn.Visibility = Visibility.Collapsed;
}
if (LauncherBattleNet == false)
{
BattleNetLaunchBtn.Visibility = Visibility.Collapsed;
}
if (LauncherUplay == false)
{
UplayLaunchBtn.Visibility = Visibility.Collapsed;
}
}
public void OpenLauncher(object sender, RoutedEventArgs e)
{
string tag = ((Button)sender).Tag.ToString();
if (tag == "Steam")
{
try
{
Process.Start(SteamExePath);
}
catch (Exception exc) { Trace.WriteLine("Failed to start Steam: " + exc); }
}
if (tag == "Origin")
{
try
{
Process.Start(OriginExePath);
}
catch (Exception exc) { Trace.WriteLine("Failed to start Origin: " + exc); }
}
if (tag == "Uplay")
{
try
{
Process.Start(UplayExePath);
}
catch (Exception exc) { Trace.WriteLine("Failed to start Uplay: " + exc); }
}
if (tag == "Epic")
{
try
{
Process.Start(EpicExePath);
}
catch (Exception exc) { Trace.WriteLine("Failed to start Epic Games: " + exc); }
}
if (tag == "Battle")
{
try
{
Process.Start(BattleNetExePath);
}
catch (Exception exc) { Trace.WriteLine("Failed to start Battle.Net: " + exc); }
}
}
public void LagBWDoWork(object sender, DoWorkEventArgs e)
{
lag.LoadGenres();
lag.LoadGames();
}
public void LagBWProgressChanged(object sender, ProgressChangedEventArgs e)
{
Console.WriteLine(e);
}
public void LagBWRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
GameListMW = lag.Games;
GenreListMW = lag.Genres;
posterViewModel.LoadGames();
listViewModel.LoadGames();
bannerViewModel.LoadGames();
if (Settings.Default.viewtype.ToString() == "Poster")
{
PosterViewActive();
}
if (Settings.Default.viewtype.ToString() == "Banner")
{
BannerViewActive();
}
if (Settings.Default.viewtype.ToString() == "List")
{
ListViewActive();
}
DialogFrame.Visibility = Visibility.Hidden;
}
public void MakeDirectories()
{
if (!Directory.Exists("./Resources/"))
{
Directory.CreateDirectory("./Resources/");
}
if (!Directory.Exists("./Resources/img/"))
{
Directory.CreateDirectory("./Resources/img/");
}
if (!Directory.Exists("./Resources/shortcuts/"))
{
Directory.CreateDirectory("./Resources/shortcuts/");
}
}
public void LoadAllViews()
{
DialogFrame.Visibility = Visibility.Visible;
DialogFrame.Content = loadingdialog;
try
{
try
{
GenreListMW.Clear();
}
catch { }
try
{
GameListMW.Clear();
}
catch { }
lagbw.RunWorkerAsync();
}
catch { }
}
public void OpenLoadingProgressDialog()
{
DialogFrame.Visibility = Visibility.Visible;
DialogFrame.Content = loadingprogressdialog;
}
public void CloseLoadingProgressDialog()
{
DialogFrame.Visibility = Visibility.Hidden;
DialogFrame.Content = null;
}
public void RefreshDataContext()
{
if (view == "poster")
{
DataContext = posterViewModel;
}
else if (view == "list")
{
DataContext = listViewModel;
}
else if (view == "banner")
{
DataContext = bannerViewModel;
}
if (view == "settings")
{
DataContext = settingsViewModel;
}
}
public void MakeDefaultGenres()
{
if (!File.Exists("./Resources/GenreList.txt"))
{
TextWriter tsw = new StreamWriter(@"./Resources/GenreList.txt", true);
Guid gameGuid = Guid.NewGuid();
tsw.WriteLine("Action|" + Guid.NewGuid());
tsw.WriteLine("Adventure|" + Guid.NewGuid());
tsw.WriteLine("Casual|" + Guid.NewGuid());
tsw.WriteLine("Emulator|" + Guid.NewGuid());
tsw.WriteLine("Horror|" + Guid.NewGuid());
tsw.WriteLine("Indie|" + Guid.NewGuid());
tsw.WriteLine("MMO|" + Guid.NewGuid());
tsw.WriteLine("Open World|" + Guid.NewGuid());
tsw.WriteLine("Platform|" + Guid.NewGuid());
tsw.WriteLine("Racing|" + Guid.NewGuid());
tsw.WriteLine("Retro|" + Guid.NewGuid());
tsw.WriteLine("RPG|" + Guid.NewGuid());
tsw.WriteLine("Simulation|" + Guid.NewGuid());
tsw.WriteLine("Sport|" + Guid.NewGuid());
tsw.WriteLine("Strategy|" + Guid.NewGuid());
tsw.WriteLine("VR|" + Guid.NewGuid());
tsw.Close();
}
}
public void InitTraceListen()
{
string appdir = AppDomain.CurrentDomain.BaseDirectory;
string logfile = appdir + "\\log\\logfile.log";
if (!Directory.Exists(appdir + "\\log"))
{
Directory.CreateDirectory(appdir + "\\log");
}
if (File.Exists(logfile))
{
Directory.Delete(appdir + "\\log", true);
Directory.CreateDirectory(appdir + "\\log");
var log = File.Create(logfile);
log.Close();
}
else
{
var log = File.Create(logfile);
}
TextWriterTraceListener twtl = new TextWriterTraceListener(logfile)
{
TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime
};
ConsoleTraceListener ctl = new ConsoleTraceListener(false)
{
TraceOutputOptions = TraceOptions.DateTime
};
Trace.Listeners.Add(twtl);
Trace.Listeners.Add(ctl);
Trace.AutoFlush = true;
}
public void OpenAddGameWindow_OnClick(object sender, RoutedEventArgs e)
{
OpenAddGameDialog();
}
public void OpenAddGameDialog()
{
DialogFrame.Visibility = Visibility.Visible;
DialogFrame.Content = DialogAddGames;
dialogOpen = "add";
isDialogOpen = true;
DialogAddGames.AddGameDialog.IsOpen = true;
}
public void UpdateObsCol(string title, string exe)
{
exesViewModel.UpdateObsCol(title, exe);
}
public bool CheckBinding(string title)
{
bool result = exesViewModel.CheckBinding(title);
if (result == true)
{
return true;
}
else
{
return false;
}
}
public void OpenExeSearchDialog()
{
DataContext = exesViewModel;
exesViewModel.SearchExe();
DialogFrame.Visibility = Visibility.Visible;
DialogFrame.Content = DialogExeSelection;
isDialogOpen = true;
dialogOpen = "exeSelection";
DialogExeSelection.ExeSelectionDialog.IsOpen = true;
isExeSearchOpen = true;
}
public void CloseExeSearchDialog()
{
DataContext = settingsViewModel;
DialogFrame.Visibility = Visibility.Hidden;
isDialogOpen = false;
DialogExeSelection.ExeSelectionDialog.IsOpen = false;
isExeSearchOpen = false;
}
public void OpenEditGameDialog(string guid)
{
DialogFrame.Visibility = Visibility.Visible;
DialogFrame.Content = DialogEditGames;
dialogOpen = "edit";
isDialogOpen = true;
DialogEditGames.currentGuid(guid);
DialogEditGames.EditGameDialog.IsOpen = true;
}
public void OpenImageDL(string gametitle, string searchstring, string imagetype)
{
ImageDownload DialogImageDL = new ImageDownload(gametitle, searchstring, imagetype);
DLGameTitle = gametitle;
DLImgType = imagetype;
if (DialogFrame.Content.ToString() == "GameLauncher.EditGames" || DialogFrame.Content.ToString() == "GameLauncher.AddGames")
{
DialogFrame.Visibility = Visibility.Visible;
DialogFrame.Content = DialogImageDL;
DialogAddGames.AddGameDialog.IsOpen = false;
DialogEditGames.EditGameDialog.IsOpen = false;
DialogImageDL.DownloadDialog.IsOpen = true;
isDownloadOpen = true;
}
else if (DialogFrame.Content.ToString() == "GameLauncher.Views.ImageDownload")
{
if (dialogOpen == "edit")
{
DialogFrame.Content = DialogEditGames;
DialogEditGames.EditGameDialog.IsOpen = true;
DialogImageDL.DownloadDialog.IsOpen = false;
isDownloadOpen = false;
GC.Collect();
}
else if (dialogOpen == "add")
{
DialogFrame.Content = DialogAddGames;
DialogAddGames.AddGameDialog.IsOpen = true;
DialogImageDL.DownloadDialog.IsOpen = false;
isDownloadOpen = false;
GC.Collect();
}
else
{
Trace.WriteLine(DateTime.Now + ": -System unsure which dialog currently open");
}
}
}
public void GenresLoaded(object sender, RoutedEventArgs e)
{
var converter = new BrushConverter();
Brush colour = (Brush)converter.ConvertFromString(Settings.Default.genrecolour);
UpdateGenreColours(colour);
}
public void UpdateGenreColours(Brush colour)
{
if (GenreSidebar.Items.Count != 0)
{
for (int i = 0; i < GenreSidebar.Items.Count; i++)
{
ContentPresenter c = (ContentPresenter)GenreSidebar.ItemContainerGenerator.ContainerFromItem(GenreSidebar.Items[i]);
try
{
Button tb = c.ContentTemplate.FindName("GenreButton", c) as Button;
tb.Foreground = colour;
AllGenreBtn.Foreground = colour;
}
catch (Exception br) { Trace.WriteLine("Break: " + br); }
}
}
}
public void UpdateLauncherButtons()
{
var converter = new BrushConverter();
SteamLaunchBtn.Foreground = (Brush)converter.ConvertFromString(Settings.Default.launchercolour);
OriginLaunchBtn.Foreground = (Brush)converter.ConvertFromString(Settings.Default.launchercolour);
UplayLaunchBtn.Foreground = (Brush)converter.ConvertFromString(Settings.Default.launchercolour);
EpicLaunchBtn.Foreground = (Brush)converter.ConvertFromString(Settings.Default.launchercolour);
BattleNetLaunchBtn.Foreground = (Brush)converter.ConvertFromString(Settings.Default.launchercolour);
}
public void DownloadImage(string url)
{
if (!File.Exists(@"Resources/img/" + DLGameTitle + "-" + DLImgType + ".png"))
{
using (WebClient client = new WebClient())
{
try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.UseDefaultCredentials = true;
client.Proxy.Credentials = CredentialCache.DefaultCredentials;
client.DownloadFile(new Uri(url), @"Resources\img\" + DLGameTitle + "-" + DLImgType + ".png");
SetPath(DLGameTitle, DLImgType, dialogOpen);
}
catch (Exception e) { Trace.WriteLine(DateTime.Now + ": DownloadImage:" + e); MessageBox.Show("Sorry! That's failed, Try again or try another image"); }
}
}
else if (File.Exists(@"Resources/img/" + DLGameTitle + "-" + DLImgType + ".png"))
{
File.Delete(@"Resources/img/" + DLGameTitle + "-" + DLImgType + ".png");
using (WebClient client = new WebClient())
{
try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.UseDefaultCredentials = true;
client.Proxy.Credentials = CredentialCache.DefaultCredentials;
client.DownloadFile(new Uri(url), @"Resources\img\" + DLGameTitle + "-" + DLImgType + ".png");
SetPath(DLGameTitle, DLImgType, dialogOpen);
}
catch (Exception e) { Trace.WriteLine(DateTime.Now + ": DownloadImage2: " + e); }
}
}
}
public void SetPath(string title, string imagetype, string dialogType)
{
string imgpath = AppDomain.CurrentDomain.BaseDirectory + "Resources\\img\\" + DLGameTitle + "-" + DLImgType + ".png";
if (imagetype == "icon")
{
if (dialogType == "edit")
{
DialogEditGames.EditIcon.Text = title + "-" + DLImgType + ".png";
OpenImageDL("", "", "");
}
else if (dialogType == "add")
{
DialogAddGames.NewGameIcon.Text = title + "-" + DLImgType + ".png";
OpenImageDL("", "", "");
}
}
else if (imagetype == "poster")
{
if (dialogType == "edit")
{
DialogEditGames.EditPoster.Text = title + "-" + DLImgType + ".png";
OpenImageDL("", "", "");
}
else if (dialogType == "add")
{
DialogAddGames.NewGamePoster.Text = title + "-" + DLImgType + ".png";
OpenImageDL("", "", "");
}
}
else if (imagetype == "banner")
{
if (dialogType == "edit")
{
DialogEditGames.EditBanner.Text = title + "-" + DLImgType + ".png";
OpenImageDL("", "", "");
}
else if (dialogType == "add")
{
DialogAddGames.NewGameBanner.Text = title + "-" + DLImgType + ".png";
OpenImageDL("", "", "");
}
}
}
public void ApplyGenreFilter_OnClick(object sender, RoutedEventArgs e)
{
string genreToFilter = ((Button)sender).Tag.ToString();
if (DataContext == settingsViewModel)
{
if (Settings.Default.viewtype == "Poster")
{
DataContext = posterViewModel;
}
if (Settings.Default.viewtype == "Banner")
{
DataContext = bannerViewModel;
}
if (Settings.Default.viewtype == "List")
{
DataContext = listViewModel;
}
}
pv.GenreToFilter(genreToFilter);
pv.RefreshList2(cvs);
bv.GenreToFilter(genreToFilter);
bv.RefreshList2(cvs);
lv.GenreToFilter(genreToFilter);
lv.RefreshList2(cvs);
MenuToggleButton.IsChecked = false;
}
public void PosterViewActive()
{
view = "poster";
DataContext = posterViewModel;
Settings.Default.viewtype = "Poster";
Settings.Default.Save();
}
public void BannerViewActive()
{
view = "banner";
DataContext = bannerViewModel;
Settings.Default.viewtype = "Banner";
Settings.Default.Save();
}
public void ListViewActive()
{
view = "list";
DataContext = listViewModel;
Settings.Default.viewtype = "List";
Settings.Default.Save();
}
public void SettingsViewActive()
{
view = "settings";
settingsViewModel = new SettingsViewModel();
settingsViewModel.LoadGenres();
DataContext = settingsViewModel;
}
public void IncreaseExeSearch()
{
DialogExeSelection.IncreaseImages();
}
public void FixFilePaths()
{
if (File.Exists("./Resources/GamesList.txt"))
{
string file = "./Resources/GamesList.txt";
string fileout = "./Resources/GamesList2.txt";
var contents = File.ReadAllLines(file);
Array.Sort(contents);
File.WriteAllLines(fileout, contents);
File.Delete("./Resources/GamesList.txt");
File.Move("./Resources/GamesList2.txt", "./Resources/GamesList.txt");
bool textModified = false;
string installPath = AppDomain.CurrentDomain.BaseDirectory;
if (File.Exists("./Resources/GamesList.txt"))
{
string text = File.ReadAllText("./Resources/GamesList.txt");
if (text.Contains(installPath + "Resources/img/"))
{
newText = text.Replace(installPath + "Resources/img/", "");
textModified = true;
}
if (text.Contains(installPath + "Resources\\img\\"))
{
if (textModified)
{
newText = newText.Replace(installPath + "Resources\\img\\", "");
}
else
{
newText = text.Replace(installPath + "Resources\\img\\", "");
textModified = true;
}
}
if (text.Contains(installPath + "Resources/shortcuts/"))
{
if (textModified)
{
newText = newText.Replace(installPath + "Resources/shortcuts/", "");
}
else
{
newText = text.Replace(installPath + "Resources/shortcuts/", "");
textModified = true;
}
}
else if (text.Contains(installPath + "Resources\\shortcuts\\"))
{
if (textModified)
{
newText = newText.Replace(installPath + "Resources\\shortcuts\\", "");
}
else
{
newText = text.Replace(installPath + "Resources\\shortcuts\\", "");
}
}
if (newText != null)
{
File.WriteAllText("./Resources/GamesList2.txt", newText);
File.Delete("./Resources/GamesList.txt");
File.Move("./Resources/GamesList2.txt", "./Resources/GamesList.txt");
}
}
}
}
public void RefreshGames()
{
DialogFrame.Visibility = Visibility.Visible;
DialogFrame.Content = loadingdialog;
try
{
try
{
GenreListMW.Clear();
}
catch { }
try
{
GameListMW.Clear();
}
catch { }
lagbw.RunWorkerAsync();
}
catch { }
if (view == "list")
{
ListViewActive();
}
else if (view == "poster")
{
PosterViewActive();
}
else if (view == "banner")
{
BannerViewActive();
}
else if (view == "settings")
{
SettingsViewActive();
}
}
private void PosterButton_OnClick(object sender, RoutedEventArgs e)
{
Trace.WriteLine(DateTime.Now + ": Poster View Active");
PosterViewActive();
}
private void BannerButton_OnClick(object sender, RoutedEventArgs e)
{
Trace.WriteLine(DateTime.Now + ": Banner View Active");
BannerViewActive();
}
private void ListButton_OnClick(object sender, RoutedEventArgs e)
{
Trace.WriteLine(DateTime.Now + ": List View Active");
ListViewActive();
}
private void SettingsButton_OnClick(object sender, RoutedEventArgs e)
{
Trace.WriteLine(DateTime.Now + ": Settings View Active");
SettingsViewActive();
}
private void RefreshGames_OnClick(object sender, RoutedEventArgs e)
{
RefreshGames();
}
private void MWSizeChanged(object sender, SizeChangedEventArgs e)
{
Resized();
}
public void Resized()
{
if (isDownloadOpen == true)
{
ImageDownload.ChangeWindowSize(this.ActualWidth * 0.8, this.ActualHeight * 0.8);
}
if (isExeSearchOpen == true)
{
ExeSelection.ChangeWindowSize(this.ActualWidth * 0.9, this.ActualHeight * 0.9);
}
}
public void StoreSize()
{
Top = Settings.Default.Top;
Left = Settings.Default.Left;
Height = Settings.Default.Height;
Width = Settings.Default.Width;
if (Settings.Default.Maximized)
{
WindowState = WindowState.Maximized;
}
}
public void Window_Closed(object sender, CancelEventArgs e)
{
if (WindowState == WindowState.Maximized)
{
Settings.Default.Top = RestoreBounds.Top;
Settings.Default.Left = RestoreBounds.Left;
Settings.Default.Height = RestoreBounds.Height;
Settings.Default.Location = RestoreBounds.Location.ToString();
Settings.Default.Maximized = true;
}
else
{
Settings.Default.Top = Top;
Settings.Default.Left = Left;
Settings.Default.Height = Height;
Settings.Default.Width = Width;
Settings.Default.Location = RestoreBounds.Location.ToString();
Settings.Default.Maximized = false;
}
Settings.Default.Save();
}
public void LoadSettings()
{
Regex regexColourCode8 = new Regex("^#[a-fA-F0-9]{8}$");
Regex regexColourCode6 = new Regex("^#[a-fA-F0-9]{6}$");
string launcher = Settings.Default.launchercolour;
string genre = Settings.Default.genrecolour;
string titles = Settings.Default.gametitles;
string banner = Settings.Default.bannertitles;
string list = Settings.Default.listtitles;
try
{
if (regexColourCode6.IsMatch(launcher) || regexColourCode8.IsMatch(launcher))
{
}
else
{
Settings.Default.launchercolour = "#3369e8";
}
}
catch (Exception e) { Trace.WriteLine("Error: " + e); }
try
{
if (regexColourCode6.IsMatch(genre) || regexColourCode8.IsMatch(genre))
{
var converter = new BrushConverter();
AllGenreBtn.Foreground = (Brush)converter.ConvertFromString(genre);
}
else
{
Settings.Default.genrecolour = "#3369e8";
genre = "#3369e8";
var converter = new BrushConverter();
AllGenreBtn.Foreground = (Brush)converter.ConvertFromString(genre);
}
}
catch (Exception e) { Trace.WriteLine("Error: " + e); }
try
{
if (regexColourCode6.IsMatch(titles) || regexColourCode8.IsMatch(titles))
{
}
else
{
Settings.Default.gametitles = "#3369e8";
}
}
catch (Exception e) { Trace.WriteLine("Error: " + e); }
try
{
if (regexColourCode6.IsMatch(banner) || regexColourCode8.IsMatch(banner))
{
}
else
{
Settings.Default.bannertitles = "#3369e8";
}
}
catch (Exception e) { Trace.WriteLine("Error: " + e); }
try
{
if (regexColourCode6.IsMatch(list) || regexColourCode8.IsMatch(list))
{
}
else
{
Settings.Default.listtitles = "#3369e8";
}
}
catch (Exception e) { Trace.WriteLine("Error: " + e); }
Top = Settings.Default.Top;
Left = Settings.Default.Left;
Height = Settings.Default.Height;
Width = Settings.Default.Width;
if (Settings.Default.Maximized)
{
WindowState = WindowState.Maximized;
}
if (Settings.Default.theme.ToString() == "Dark")
{
ThemeAssist.SetTheme(Application.Current.MainWindow, BaseTheme.Dark);
}
else if (Settings.Default.theme.ToString() == "Light")
{
ThemeAssist.SetTheme(Application.Current.MainWindow, BaseTheme.Light);
}
if (Settings.Default.primary.ToString() != "")
{
new PaletteHelper().ReplacePrimaryColor(Settings.Default.primary.ToString());
}
if (Settings.Default.accent.ToString() != "")
{
new PaletteHelper().ReplaceAccentColor(Settings.Default.accent.ToString());
}
if (Settings.Default.fabcolour == "primary")
{
AddGameButton.Style = Application.Current.Resources["MaterialDesignFloatingActionButton"] as Style;
}
if (Settings.Default.fabcolour == "accent")
{
AddGameButton.Style = Application.Current.Resources["MaterialDesignFloatingActionAccentButton"] as Style;
}
UpdateLauncherButtons();
}
}
}