Skip to content

Commit 2c100d6

Browse files
committed
Installed games will now be restored on adding/removing a root directory or on pressing F5 at the Library
1 parent 7a6d1f9 commit 2c100d6

4 files changed

Lines changed: 27 additions & 10 deletions

File tree

gamevault/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public void SetJumpListGames()
178178
{
179179
try
180180
{
181+
jumpList.JumpItems.RemoveRange(5, jumpList.JumpItems.Count - 5);// Remove all previous games. Now we add the current game list
181182
var lastGames = InstallViewModel.Instance.InstalledGames.Take(5).ToArray();
182183
foreach (var game in lastGames)
183184
{

gamevault/UserControls/InstallUserControl.xaml.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ private async void UserControl_Loaded(object sender, RoutedEventArgs e)
4242
}
4343
public async Task RestoreInstalledGames()
4444
{
45+
if (gamesRestored)
46+
{
47+
InstallViewModel.Instance.InstalledGames.Clear();// Clear here because the double entry code won't allow to refresh
48+
//File watchers are already protected against double entries and dont care, if the same code runs again
49+
}
4550
Dictionary<int, string> foundGames = new Dictionary<int, string>();
4651
Game[]? games = await Task<Game[]>.Run(async () =>
4752
{
48-
49-
//string installationPath = Path.Combine(SettingsViewModel.Instance.RootPath, "GameVault\\Installations");
5053
if (SettingsViewModel.Instance.RootDirectories.Count > 0)
5154
{
5255

@@ -156,6 +159,10 @@ public async Task RestoreInstalledGames()
156159
}
157160
InstallViewModel.Instance.InstalledGames = await SortInstalledGamesByLastPlayed(TempInstalledGames);
158161
InstallViewModel.Instance.InstalledGamesFilter = CollectionViewSource.GetDefaultView(InstallViewModel.Instance.InstalledGames);
162+
if (gamesRestored)
163+
{
164+
SearchFilterInputTimerElapsed(null, null);//Keep the filter
165+
}
159166
}
160167
gamesRestored = true;
161168
App.Instance.SetJumpListGames();
@@ -288,13 +295,13 @@ private void Search_TextChanged(object sender, TextChangedEventArgs e)
288295
inputTimer.Data = ((TextBox)sender).Text;
289296
inputTimer.Start();
290297
}
291-
private void InputTimerElapsed(object sender, EventArgs e)
298+
private void SearchFilterInputTimerElapsed(object sender, EventArgs e)
292299
{
293300
inputTimer.Stop();
294301
if (InstallViewModel.Instance.InstalledGamesFilter == null) return;
295302
InstallViewModel.Instance.InstalledGamesFilter.Filter = item =>
296303
{
297-
return ((KeyValuePair<Game, string>)item).Key.Title.Contains(inputTimer.Data, StringComparison.OrdinalIgnoreCase);
304+
return ((KeyValuePair<Game, string>)item).Key.Title.Contains(inputTimer.Data ?? "", StringComparison.OrdinalIgnoreCase);
298305
};
299306
}
300307

@@ -384,7 +391,7 @@ private void InitTimer()
384391
{
385392
inputTimer = new InputTimer();
386393
inputTimer.Interval = TimeSpan.FromMilliseconds(400);
387-
inputTimer.Tick += InputTimerElapsed;
394+
inputTimer.Tick += SearchFilterInputTimerElapsed;
388395
}
389396

390397
private void InstalledGames_Toggled(object sender, RoutedEventArgs e)

gamevault/UserControls/LibraryUserControl.xaml.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public LibraryUserControl()
3636
{
3737
try
3838
{
39-
uiFilterOrderBy.IsChecked = Preferences.Get(AppConfigKey.LastLibraryOrderBy,LoginManager.Instance.GetUserProfile().UserConfigFile) == "desc" ? true : false;
39+
uiFilterOrderBy.IsChecked = Preferences.Get(AppConfigKey.LastLibraryOrderBy, LoginManager.Instance.GetUserProfile().UserConfigFile) == "desc" ? true : false;
4040

41-
string lastSortBy = Preferences.Get(AppConfigKey.LastLibrarySortBy,LoginManager.Instance.GetUserProfile().UserConfigFile);
41+
string lastSortBy = Preferences.Get(AppConfigKey.LastLibrarySortBy, LoginManager.Instance.GetUserProfile().UserConfigFile);
4242

4343
for (int i = 0; i < ViewModel.GameFilterSortByValues.Count; i++)
4444
{
@@ -146,6 +146,10 @@ private async void ReloadLibrary_Click(object sender, EventArgs e)
146146

147147
uiBtnReloadLibrary.IsEnabled = false;
148148
await Search();
149+
if ((e.GetType() == typeof(KeyEventArgs) && ((KeyEventArgs)e).Key == Key.F5))
150+
{
151+
await MainWindowViewModel.Instance.Library.GetGameInstalls().RestoreInstalledGames();
152+
}
149153
uiBtnReloadLibrary.IsEnabled = true;
150154
}
151155
public InstallUserControl GetGameInstalls()
@@ -276,7 +280,7 @@ private void ScrollToTop_Click(object sender, MouseButtonEventArgs e)
276280

277281
private async void OrderBy_Changed(object sender, RoutedEventArgs e)
278282
{
279-
Preferences.Set(AppConfigKey.LastLibraryOrderBy, (bool)uiFilterOrderBy.IsChecked ? "desc" : "asc",LoginManager.Instance.GetUserProfile().UserConfigFile);
283+
Preferences.Set(AppConfigKey.LastLibraryOrderBy, (bool)uiFilterOrderBy.IsChecked ? "desc" : "asc", LoginManager.Instance.GetUserProfile().UserConfigFile);
280284
await Search();
281285
}
282286
private string ApplyFilter(string filter)
@@ -334,7 +338,7 @@ private async void FilterUpdated(object sender, EventArgs e)
334338
{
335339
if (sender == uiFilterSortBy)
336340
{
337-
Preferences.Set(AppConfigKey.LastLibrarySortBy, ViewModel.SelectedGameFilterSortBy.Value,LoginManager.Instance.GetUserProfile().UserConfigFile);
341+
Preferences.Set(AppConfigKey.LastLibrarySortBy, ViewModel.SelectedGameFilterSortBy.Value, LoginManager.Instance.GetUserProfile().UserConfigFile);
338342
}
339343
OpenFilterIfClosed();
340344
RefreshFilterCounter();

gamevault/UserControls/SettingsUserControl.xaml.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ private async void AddRootDirectory_Click(object sender, RoutedEventArgs e)
636636
ViewModel.RootDirectories.Add(new DirectoryEntry() { Uri = selectedDirectory });
637637
string result = string.Join(";", ViewModel.RootDirectories.Select(entry => entry.Uri));
638638
Preferences.Set(AppConfigKey.RootDirectories, result, LoginManager.Instance.GetUserProfile().UserConfigFile);
639+
await MainWindowViewModel.Instance.Library.GetGameInstalls().RestoreInstalledGames();
639640
}
640641
}
641642
catch (Exception ex)
@@ -644,7 +645,7 @@ private async void AddRootDirectory_Click(object sender, RoutedEventArgs e)
644645
}
645646
((FrameworkElement)sender).IsEnabled = true;
646647
}
647-
private void RemoveRootDirectory_Click(object sender, RoutedEventArgs e)
648+
private async void RemoveRootDirectory_Click(object sender, RoutedEventArgs e)
648649
{
649650
try
650651
{
@@ -654,12 +655,16 @@ private void RemoveRootDirectory_Click(object sender, RoutedEventArgs e)
654655
ViewModel.RootDirectories.RemoveAt(index);
655656
string result = string.Join(";", ViewModel.RootDirectories.Select(entry => entry.Uri));
656657
Preferences.Set(AppConfigKey.RootDirectories, result, LoginManager.Instance.GetUserProfile().UserConfigFile);
658+
659+
((FrameworkElement)sender).IsEnabled = false;//Disable the add button to block async restoring installed games
660+
await MainWindowViewModel.Instance.Library.GetGameInstalls().RestoreInstalledGames();
657661
}
658662
}
659663
catch (Exception ex)
660664
{
661665
MainWindowViewModel.Instance.AppBarText = ex.Message;
662666
}
667+
((FrameworkElement)sender).IsEnabled = true;
663668
}
664669
private void OpenUserCacheFolder_Click(object sender, RoutedEventArgs e)
665670
{

0 commit comments

Comments
 (0)