-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathSettingsUserControl.xaml.cs
More file actions
700 lines (670 loc) · 33.2 KB
/
Copy pathSettingsUserControl.xaml.cs
File metadata and controls
700 lines (670 loc) · 33.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
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
using gamevault.Models;
using gamevault.ViewModels;
using System.IO;
using System.Windows.Controls;
using System.Windows;
using System;
using gamevault.Helper;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Diagnostics;
using MahApps.Metro.Controls.Dialogs;
using MahApps.Metro.Controls;
using System.Text.Json;
using System.Collections.ObjectModel;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Markup;
using gamevault.Helper.Integrations;
using gamevault.Windows;
using gamevault.UserControls.SettingsComponents;
namespace gamevault.UserControls
{
/// <summary>
/// Interaction logic for SettingsUserControl.xaml
/// </summary>
public partial class SettingsUserControl : UserControl
{
private SettingsViewModel ViewModel { get; set; }
private bool loaded = false;
public SettingsUserControl()
{
InitializeComponent();
ViewModel = SettingsViewModel.Instance;
this.DataContext = ViewModel;
}
public void SetTabIndex(int index)
{
uiTabControl.SelectedIndex = index;
}
private void ClearImageCache_Clicked(object sender, RoutedEventArgs e)
{
try
{
Directory.Delete(LoginManager.Instance.GetUserProfile().ImageCacheDir, true);
Directory.CreateDirectory(LoginManager.Instance.GetUserProfile().ImageCacheDir);
ViewModel.ImageCacheSize = 0;
MainWindowViewModel.Instance.AppBarText = "Image cache cleared";
}
catch
{
MainWindowViewModel.Instance.AppBarText = "Something went wrong while the image cache was cleared";
}
}
private async void ClearOfflineCache_Clicked(object sender, RoutedEventArgs e)
{
MessageDialogResult result = await ((MetroWindow)App.Current.MainWindow).ShowMessageAsync($"Are you sure you want delete the offline cache? \nThis can lead to games not being displayed correctly when you are offline.", "", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", AnimateHide = false });
if (result == MessageDialogResult.Affirmative)
{
try
{
if (File.Exists(LoginManager.Instance.GetUserProfile().IgnoreList))
{
File.Delete(LoginManager.Instance.GetUserProfile().IgnoreList);
}
if (File.Exists(LoginManager.Instance.GetUserProfile().OfflineCache))
{
File.Delete(LoginManager.Instance.GetUserProfile().OfflineCache);
}
ViewModel.OfflineCacheSize = 0;
MainWindowViewModel.Instance.AppBarText = "Offline cache cleared";
}
catch
{
MainWindowViewModel.Instance.AppBarText = "Something went wrong while the offline cache was cleared";
}
}
}
private async void UserControl_Loaded(object sender, RoutedEventArgs e)
{
if (loaded)
return;
loaded = true;
if (App.IsWindowsPackage)
{
uiAutostartToggle.IsOn = await AutostartHelper.IsWindowsPackageAutostartEnabled();
}
else
{
uiAutostartToggle.IsOn = AutostartHelper.RegistryAutoStartKeyExists();
}
uiAutostartToggle.Toggled += AppAutostart_Toggled;
LoadThemes();
uiPwExtraction.Password = Preferences.Get(AppConfigKey.ExtractionPassword, LoginManager.Instance.GetUserProfile().UserConfigFile, true);
}
private async void AppAutostart_Toggled(object sender, RoutedEventArgs e)
{
if (App.IsWindowsPackage)
{
await AutostartHelper.HandleWindowsPackageAutostart();
}
else
{
if (AutostartHelper.RegistryAutoStartKeyExists())
{
AutostartHelper.RegistryDeleteAutostartKey();
}
else
{
AutostartHelper.RegistryCreateAutostartKey();
}
}
}
private async void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (((TabControl)sender).SelectedIndex == 3)
{
ViewModel.ImageCacheSize = await CalculateDirectorySize(new DirectoryInfo(LoginManager.Instance.GetUserProfile().ImageCacheDir));
ViewModel.OfflineCacheSize = (File.Exists(LoginManager.Instance.GetUserProfile().OfflineCache) ? new FileInfo(LoginManager.Instance.GetUserProfile().OfflineCache).Length : 0);
}
}
private async Task<long> CalculateDirectorySize(DirectoryInfo d)
{
return await Task<long>.Run(async () =>
{
long size = 0;
try
{
FileInfo[] fis = d.GetFiles();
foreach (FileInfo fi in fis)
{
size += fi.Length;
}
DirectoryInfo[] dis = d.GetDirectories();
foreach (DirectoryInfo di in dis)
{
size += await CalculateDirectorySize(di);
}
}
catch { }
return size;
});
}
private void ChangeUserProfile_Click(object sender, RoutedEventArgs e)
{
((FrameworkElement)sender).IsEnabled = false;
Preferences.DeleteKey(AppConfigKey.LastUserProfile, ProfileManager.ProfileConfigFile);
((MainWindow)App.Current.MainWindow).Dispose();
App.Current.MainWindow = new LoginWindow(true);
App.Current.MainWindow.Show();
((FrameworkElement)sender).IsEnabled = true;
}
private async void Logout_Click(object sender, RoutedEventArgs e)
{
((FrameworkElement)sender).IsEnabled = false;
MessageDialogResult result = await ((MetroWindow)App.Current.MainWindow).ShowMessageAsync($"Are you sure you want to log out?", "", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", AnimateHide = false });
if (result == MessageDialogResult.Affirmative)
{
try
{
bool isLoggedInWithSSO = Preferences.Get(AppConfigKey.IsLoggedInWithSSO, LoginManager.Instance.GetUserProfile().UserConfigFile) == "1";
Preferences.DeleteKey(AppConfigKey.SessionToken, LoginManager.Instance.GetUserProfile().UserConfigFile);
await WebHelper.PostAsync($"{SettingsViewModel.Instance.ServerUrl}/api/auth/revoke", "{" + $"\"refresh_token\": \"{WebHelper.GetRefreshToken()}\"" + "}");
if (!isLoggedInWithSSO)
{
Preferences.DeleteKey(AppConfigKey.Password, LoginManager.Instance.GetUserProfile().UserConfigFile);
}
Preferences.DeleteKey(AppConfigKey.LastUserProfile, ProfileManager.ProfileConfigFile);
((MainWindow)App.Current.MainWindow).Dispose();
App.Current.MainWindow = new LoginWindow(true);
App.Current.MainWindow.Show();
}
catch (Exception ex)
{
MainWindowViewModel.Instance.AppBarText = ex.Message;
}
}
((FrameworkElement)sender).IsEnabled = true;
}
private async void LogoutFromAllDevices_Click(object sender, RoutedEventArgs e)
{
((FrameworkElement)sender).IsEnabled = false;
MessageDialogResult result = await ((MetroWindow)App.Current.MainWindow).ShowMessageAsync($"Are you sure you want to log out from all devices?", "", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", AnimateHide = false });
if (result == MessageDialogResult.Affirmative)
{
try
{
bool isLoggedInWithSSO = Preferences.Get(AppConfigKey.IsLoggedInWithSSO, LoginManager.Instance.GetUserProfile().UserConfigFile) == "1";
Preferences.DeleteKey(AppConfigKey.SessionToken, LoginManager.Instance.GetUserProfile().UserConfigFile);
await WebHelper.PostAsync($"{SettingsViewModel.Instance.ServerUrl}/api/auth/revoke/all", "");
if (!isLoggedInWithSSO)
{
Preferences.DeleteKey(AppConfigKey.Password, LoginManager.Instance.GetUserProfile().UserConfigFile);
}
Preferences.DeleteKey(AppConfigKey.LastUserProfile, ProfileManager.ProfileConfigFile);
((MainWindow)App.Current.MainWindow).Dispose();
App.Current.MainWindow = new LoginWindow(true);
App.Current.MainWindow.Show();
}
catch (Exception ex)
{
MainWindowViewModel.Instance.AppBarText = ex.Message;
}
}
((FrameworkElement)sender).IsEnabled = true;
}
private void DownloadLimit_InputValidation(object sender, EventArgs e)
{
if (e.GetType() == typeof(TextCompositionEventArgs))
{
((TextCompositionEventArgs)e).Handled = new Regex("[^0-9]+").IsMatch(((TextCompositionEventArgs)e).Text);
}
else if (e.GetType() == typeof(TextChangedEventArgs))
{
if (string.IsNullOrEmpty(((TextBox)sender).Text))
{
((TextBox)sender).Text = "0";
}
else if (!long.TryParse(((TextBox)sender).Text, out long result))
{
((TextBox)sender).Text = "0";
}
}
}
private void DownloadLimit_Save(object sender, RoutedEventArgs e)
{
if (e.GetType() == typeof(KeyEventArgs))
{
if (((KeyEventArgs)e).Key != Key.Enter)
{
return;
}
}
ViewModel.DownloadLimit = ViewModel.DownloadLimitUIValue;
Preferences.Set(AppConfigKey.DownloadLimit, ViewModel.DownloadLimit, LoginManager.Instance.GetUserProfile().UserConfigFile);
MainWindowViewModel.Instance.AppBarText = "Successfully saved download limit";
}
private void EditUser_Click(object sender, RoutedEventArgs e)
{
if (LoginManager.Instance.IsLoggedIn())
{
MainWindowViewModel.Instance.OpenPopup(new UserSettingsUserControl(LoginManager.Instance.GetCurrentUser()) { Width = 1200, Height = 800, Margin = new Thickness(50) });
}
else { MainWindowViewModel.Instance.AppBarText = "You are not logged in or offline"; }
}
private async void PhalcodeLoginLogout_Click(object sender, RoutedEventArgs e)
{
((FrameworkElement)sender).IsEnabled = false;
if (string.IsNullOrEmpty(SettingsViewModel.Instance.License.UserName))
{
string phalcodeLoginMessage = await LoginManager.Instance.PhalcodeLogin();
if (phalcodeLoginMessage != string.Empty)
MainWindowViewModel.Instance.AppBarText = phalcodeLoginMessage;
}
else
{
MessageDialogResult result = await ((MetroWindow)App.Current.MainWindow).ShowMessageAsync($"Are you sure you want to log out of your Phalcode account? GameVault Plus features will no longer be usable.", "", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", AnimateHide = false });
if (result == MessageDialogResult.Affirmative)
{
LoginManager.Instance.PhalcodeLogout();
}
}
((FrameworkElement)sender).IsEnabled = true;
}
private async void RefreshLicense_Click(object sender, MouseButtonEventArgs e)
{
((FrameworkElement)sender).IsEnabled = false;
await LoginManager.Instance.PhalcodeLogin(true);
((FrameworkElement)sender).IsEnabled = true;
}
private void ManageBilling_Click(object sender, RoutedEventArgs e)
{
string url = "https://phalco.de/account";
if (SettingsViewModel.Instance.DevTargetPhalcodeTestBackend)
{
url = "https://test.phalco.de/account";
}
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
private void ManagePhalcodeUser_Click(object sender, RoutedEventArgs e)
{
ManageBilling_Click(null, null);//Will maybe change in the Future
}
private void SubscribeGVPlus_Click(object sender, RoutedEventArgs e)
{
string url = "https://phalco.de/products/gamevault-plus/checkout";
if (SettingsViewModel.Instance.DevTargetPhalcodeTestBackend)
{
url = "https://test.phalco.de/products/gamevault-plus/checkout";
}
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
#region THEMES
private void Themes_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ThemeItem selectedTheme = (ThemeItem)((ComboBox)sender).SelectedValue;
if (((ComboBox)sender).SelectionBoxItem == string.Empty)
return;
if (selectedTheme == null)
return;
if (((ThemeItem)((ComboBox)sender).SelectionBoxItem).Path == selectedTheme.Path)
return;
ViewModel.IsCommunityThemeSelected = File.Exists(selectedTheme?.Path);
if (selectedTheme.IsPlus == true && ViewModel.License.IsActive() == false)
{
((ComboBox)sender).SelectedItem = (ThemeItem)((ComboBox)sender).SelectionBoxItem;
try
{
MainWindowViewModel.Instance.SetActiveControl(MainControl.Settings);
MainWindowViewModel.Instance.Settings.SetTabIndex(4);
MainWindowViewModel.Instance.AppBarText = "Oops! You just reached a premium feature of GameVault - Upgrade now and support the devs!";
}
catch { }
return;
}
try
{
App.Instance.SetTheme(selectedTheme.Path);
Preferences.Set(AppConfigKey.Theme, JsonSerializer.Serialize(selectedTheme), LoginManager.Instance.GetUserProfile().UserConfigFile, true);
}
catch (Exception ex) { MainWindowViewModel.Instance.AppBarText = ex.Message; }
}
private void LoadThemes()
{
try
{
if (ViewModel.Themes == null)
{
ViewModel.Themes = new ObservableCollection<ThemeItem>();
}
else
{
ViewModel.Themes.Clear();
}
//Load embedded Themes
ResourceDictionary res = new ResourceDictionary();
res.Source = new Uri("pack://application:,,,/gamevault;component/Resources/Assets/Themes/ThemeDefaultDark.xaml");
ViewModel.Themes.Add(new ThemeItem() { DisplayName = (string)res["Theme.DisplayName"], Description = (string)res["Theme.Description"], Author = (string)res["Theme.Author"], IsPlus = false, Path = res.Source.OriginalString });
res.Source = new Uri("pack://application:,,,/gamevault;component/Resources/Assets/Themes/ThemeDefaultLight.xaml");
ViewModel.Themes.Add(new ThemeItem() { DisplayName = (string)res["Theme.DisplayName"], Description = (string)res["Theme.Description"], Author = (string)res["Theme.Author"], IsPlus = false, Path = res.Source.OriginalString });
res.Source = new Uri("pack://application:,,,/gamevault;component/Resources/Assets/Themes/ThemeClassicDark.xaml");
ViewModel.Themes.Add(new ThemeItem() { DisplayName = (string)res["Theme.DisplayName"], Description = (string)res["Theme.Description"], Author = (string)res["Theme.Author"], IsPlus = false, Path = res.Source.OriginalString });
res.Source = new Uri("pack://application:,,,/gamevault;component/Resources/Assets/Themes/ThemePhalcodeDark.xaml");
ViewModel.Themes.Add(new ThemeItem() { DisplayName = (string)res["Theme.DisplayName"], Description = (string)res["Theme.Description"], Author = (string)res["Theme.Author"], IsPlus = true, Path = res.Source.OriginalString });
res.Source = new Uri("pack://application:,,,/gamevault;component/Resources/Assets/Themes/ThemePhalcodeLight.xaml");
ViewModel.Themes.Add(new ThemeItem() { DisplayName = (string)res["Theme.DisplayName"], Description = (string)res["Theme.Description"], Author = (string)res["Theme.Author"], IsPlus = true, Path = res.Source.OriginalString });
res.Source = new Uri("pack://application:,,,/gamevault;component/Resources/Assets/Themes/ThemeHalloweenDark.xaml");
ViewModel.Themes.Add(new ThemeItem() { DisplayName = (string)res["Theme.DisplayName"], Description = (string)res["Theme.Description"], Author = (string)res["Theme.Author"], IsPlus = true, Path = res.Source.OriginalString });
res.Source = new Uri("pack://application:,,,/gamevault;component/Resources/Assets/Themes/ThemeChristmasDark.xaml");
ViewModel.Themes.Add(new ThemeItem() { DisplayName = (string)res["Theme.DisplayName"], Description = (string)res["Theme.Description"], Author = (string)res["Theme.Author"], IsPlus = true, Path = res.Source.OriginalString });
if (Directory.Exists(LoginManager.Instance.GetUserProfile().ThemesLoadDir))
{
foreach (var file in Directory.GetFiles(LoginManager.Instance.GetUserProfile().ThemesLoadDir, "*.xaml", SearchOption.AllDirectories))
{
try
{
res.Source = new Uri(file);
ViewModel.Themes.Add(new ThemeItem() { DisplayName = (string)res["Theme.DisplayName"], Description = (string)res["Theme.Description"], Author = (string)res["Theme.Author"], IsPlus = true, Path = res.Source.OriginalString });
}
catch { }
}
}
string currentThemeString = Preferences.Get(AppConfigKey.Theme, LoginManager.Instance.GetUserProfile().UserConfigFile, true);
ThemeItem currentTheme = JsonSerializer.Deserialize<ThemeItem>(currentThemeString);
int themeIndex = ViewModel.Themes.ToList().FindIndex(i => i.Path == currentTheme.Path);
if (themeIndex != -1 && (ViewModel.Themes[themeIndex].IsPlus == true ? ViewModel.License.IsActive() : true))
{
uiCbTheme.SelectedIndex = themeIndex;
}
else
{
uiCbTheme.SelectedIndex = 0;
}
ViewModel.IsCommunityThemeSelected = File.Exists(((ThemeItem)uiCbTheme.SelectedItem)?.Path);
}
catch { uiCbTheme.SelectedIndex = 0; }
}
private void OpenThemeFolder_Click(object sender, RoutedEventArgs e)
{
try
{
if (Directory.Exists(LoginManager.Instance.GetUserProfile().ThemesLoadDir))
{
Directory.CreateDirectory(LoginManager.Instance.GetUserProfile().ThemesLoadDir);
}
Process.Start(new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = $"\"{LoginManager.Instance.GetUserProfile().ThemesLoadDir}\"",
UseShellExecute = true
});
}
catch { }
}
private void OpenCommunityThemeRepository_Click(object sender, RoutedEventArgs e)
{
try
{
Process.Start(new ProcessStartInfo("https://github.com/Phalcode/gamevault-community-themes") { UseShellExecute = true });
}
catch { }
}
private async void ReloadThemeList_Click(object sender, RoutedEventArgs e)
{
((FrameworkElement)sender).IsEnabled = false;
LoadThemes();
await Task.Delay(500);
((FrameworkElement)sender).IsEnabled = true;
}
private async Task<List<JsonElement>> LoadCommunityThemesHeader()
{
string jsonResponse = await WebHelper.BaseGetAsync("https://api.github.com/repos/phalcode/gamevault-community-themes/contents/v1");
return JsonSerializer.Deserialize<List<JsonElement>>(jsonResponse, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
}
private async Task<ThemeItem> LoadThemeItemFromUrl(string url)
{
try
{
string result = await WebHelper.BaseGetAsync(url);
ResourceDictionary res = (ResourceDictionary)XamlReader.Parse(result);
return new ThemeItem() { DisplayName = (string)res["Theme.DisplayName"], Description = (string)res["Theme.Description"], Author = (string)res["Theme.Author"], Path = url };
}
catch { return null; }
}
private async Task LoadCommunityThemes()
{
try
{
List<JsonElement> fetchedList = await LoadCommunityThemesHeader();
foreach (var entry in fetchedList)
{
if (entry.TryGetProperty("name", out JsonElement nameElement) && nameElement.GetString()?.First() != '_' && entry.TryGetProperty("download_url", out JsonElement downloadUrlElement))
{
ThemeItem theme = await LoadThemeItemFromUrl(downloadUrlElement.GetString()!);
if (theme != null)
{
ViewModel.CommunityThemes.Add(theme);
}
}
}
}
catch { }
}
private async void CommunityThemes_DropDownOpened(object sender, EventArgs e)
{
if (ViewModel.CommunityThemes == null)
{
ViewModel.CommunityThemes = new ObservableCollection<ThemeItem>();
await LoadCommunityThemes();
}
}
private async void ReloadCommunityThemeList_Click(object sender, RoutedEventArgs e)
{
if (ViewModel.CommunityThemes == null)
{
ViewModel.CommunityThemes = new ObservableCollection<ThemeItem>();
}
else
{
ViewModel.CommunityThemes.Clear();
}
((FrameworkElement)sender).IsEnabled = false;
await LoadCommunityThemes();
((FrameworkElement)sender).IsEnabled = true;
}
private async void InstallCommunityTheme_Click(object sender, RoutedEventArgs e)
{
if (uiCBCommunityThemes.SelectedItem == null)
{
MainWindowViewModel.Instance.AppBarText = "No Theme selected";
return;
}
((FrameworkElement)sender).IsEnabled = false;
try
{
ThemeItem theme = (ThemeItem)uiCBCommunityThemes.SelectedItem;
string installationPath = Path.Combine(LoginManager.Instance.GetUserProfile().ThemesLoadDir, theme.DisplayName + ".xaml");
string result = await WebHelper.BaseGetAsync(theme.Path);
File.WriteAllText(installationPath, result);
LoadThemes();
try
{
int installedThemeIndex = ViewModel.Themes.IndexOf(ViewModel.Themes.First(t => t.DisplayName == theme.DisplayName));
uiCbTheme.SelectedIndex = installedThemeIndex;
}
catch { }
MainWindowViewModel.Instance.AppBarText = $"Successfully installed {theme.DisplayName}";
}
catch (Exception ex)
{
MainWindowViewModel.Instance.AppBarText = ex.Message;
((FrameworkElement)sender).IsEnabled = true;
}
((FrameworkElement)sender).IsEnabled = true;
}
private void UninstallTheme_Click(object sender, RoutedEventArgs e)
{
try
{
if (File.Exists(((ThemeItem)uiCbTheme.SelectedItem)?.Path))
{
File.Delete(((ThemeItem)uiCbTheme.SelectedItem).Path);
uiCbTheme.SelectedIndex = 0;
LoadThemes();
}
}
catch { }
}
#endregion
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
{
try
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true });
}
catch { }
}
private void Awesome_Click(object sender, MouseButtonEventArgs e)
{
((FrameworkElement)sender).IsEnabled = false;
imgAwesome.Data = "https://phalco.de/images/gamevault/eastereggs/awesome.gif";
AnalyticsHelper.Instance.SendCustomEvent(CustomAnalyticsEventKeys.EASTER_EGG, new { name = "awesome" });
}
private void ExtractionPasswordSave_Click(object sender, RoutedEventArgs e)
{
Preferences.Set(AppConfigKey.ExtractionPassword, uiPwExtraction.Password, LoginManager.Instance.GetUserProfile().UserConfigFile, true);
MainWindowViewModel.Instance.AppBarText = "Successfully saved extraction password";
}
private async void IgnoredExecutablesReset_Click(object sender, RoutedEventArgs e)
{
try
{
if (File.Exists(LoginManager.Instance.GetUserProfile().IgnoreList))
File.Delete(LoginManager.Instance.GetUserProfile().IgnoreList);
await SettingsViewModel.Instance.InitIgnoreList();
}
catch { }
}
private void IgnoredExecutablesSave_Click(object sender, RoutedEventArgs e)
{
try
{
Preferences.Set("IL", SettingsViewModel.Instance.IgnoreList, LoginManager.Instance.GetUserProfile().IgnoreList);
}
catch { }
}
private async void SyncSteamShortcuts_Toggled(object sender, RoutedEventArgs e)
{
if (!this.loaded)//Make sure the toggle came from the ui
return;
if (((ToggleSwitch)sender).IsOn)
{
await SteamHelper.SyncGamesWithSteamShortcuts(InstallViewModel.Instance.InstalledGames.ToDictionary(pair => pair.Key, pair => pair.Value));
}
else
{
SteamHelper.RemoveGameVaultGamesFromSteamShortcuts();
}
}
private async void RestoreSteamShortcutBackup_Click(object sender, RoutedEventArgs e)
{
MessageDialogResult result = await ((MetroWindow)App.Current.MainWindow).ShowMessageAsync($"Are you sure you want to restore the backup? Your current shortcuts will be reset to the state when the backup was created. This can lead to some shortcuts being lost.", "", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", AnimateHide = false });
if (result == MessageDialogResult.Affirmative)
{
SteamHelper.RestoreBackup();
}
}
private int devModeCount = 0;
private void DevMode_Click(object sender, MouseButtonEventArgs e)
{
devModeCount++;
if (devModeCount == 5)
{
ViewModel.DevModeEnabled = true;
}
}
private void RemoveCustomCloudSaveManifest_Click(object sender, RoutedEventArgs e)
{
int index = ViewModel.CustomCloudSaveManifests.IndexOf(((DirectoryEntry)((FrameworkElement)sender).DataContext));
if (index >= 0)
{
ViewModel.CustomCloudSaveManifests.RemoveAt(index);
}
}
private void AddCustomCloudSaveManifest_Click(object sender, RoutedEventArgs e)
{
ViewModel.CustomCloudSaveManifests.Add(new DirectoryEntry());
}
private void SaveCustomCloudSaveManifests_Click(object sender, RoutedEventArgs e)
{
try
{
string result = string.Join(";", ViewModel.CustomCloudSaveManifests.Where(entry => !string.IsNullOrWhiteSpace(entry.Uri)).Select(entry => entry.Uri));
Preferences.Set(AppConfigKey.CustomCloudSaveManifests, result, LoginManager.Instance.GetUserProfile().UserConfigFile);
}
catch { }
MainWindowViewModel.Instance.AppBarText = "Successfully saved custom Ludusavi Manifests";
}
private async void AddRootDirectory_Click(object sender, RoutedEventArgs e)
{
((FrameworkElement)sender).IsEnabled = false;
try
{
string selectedDirectory = await SettingsViewModel.Instance.SelectDownloadPath();
if (Directory.Exists(selectedDirectory))
{
ViewModel.RootDirectories.Add(new DirectoryEntry() { Uri = selectedDirectory });
string result = string.Join(";", ViewModel.RootDirectories.Select(entry => entry.Uri));
Preferences.Set(AppConfigKey.RootDirectories, result, LoginManager.Instance.GetUserProfile().UserConfigFile);
await MainWindowViewModel.Instance.Library.GetGameInstalls().RestoreInstalledGames();
await MainWindowViewModel.Instance.Downloads.RestoreDownloadedGames();
if (InstallViewModel.Instance.InstalledGamesDuplicates.Any())
{
await ShowInstalledGameDuplicates();
}
}
}
catch (Exception ex)
{
MainWindowViewModel.Instance.AppBarText = ex.Message;
}
((FrameworkElement)sender).IsEnabled = true;
}
private async Task ShowInstalledGameDuplicates()
{
string duplicateMessage = "";
foreach (var duplicate in InstallViewModel.Instance.InstalledGamesDuplicates)
{
var matchingGame = InstallViewModel.Instance.InstalledGames?.FirstOrDefault(game => game.Key.ID == duplicate.Key);
if (string.IsNullOrEmpty(matchingGame?.Key?.Title))
continue;
duplicateMessage += $"\n\n'{matchingGame?.Key?.Title}' is already installed at:\n{duplicate.Value}";
}
await ((MetroWindow)App.Current.MainWindow).ShowMessageAsync("Duplicate game installation detected", duplicateMessage, MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "Ok", DialogTitleFontSize = 20, AnimateHide = false });
}
private async void RemoveRootDirectory_Click(object sender, RoutedEventArgs e)
{
try
{
int index = ViewModel.RootDirectories.IndexOf(((DirectoryEntry)((FrameworkElement)sender).DataContext));
if (index >= 0)
{
ViewModel.RootDirectories.RemoveAt(index);
string result = string.Join(";", ViewModel.RootDirectories.Select(entry => entry.Uri));
Preferences.Set(AppConfigKey.RootDirectories, result, LoginManager.Instance.GetUserProfile().UserConfigFile);
((FrameworkElement)sender).IsEnabled = false;//Disable the add button to block async restoring installed games
await MainWindowViewModel.Instance.Library.GetGameInstalls().RestoreInstalledGames();
await MainWindowViewModel.Instance.Downloads.RestoreDownloadedGames();
}
}
catch (Exception ex)
{
MainWindowViewModel.Instance.AppBarText = ex.Message;
}
((FrameworkElement)sender).IsEnabled = true;
}
private void OpenUserCacheFolder_Click(object sender, RoutedEventArgs e)
{
if (Directory.Exists(LoginManager.Instance.GetUserProfile().RootDir))
{
Process.Start(new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = $"\"{LoginManager.Instance.GetUserProfile().RootDir}\"",
UseShellExecute = true
});
}
}
}
}