diff --git a/gamevault/UserControls/GameSettingsUserControl.xaml b/gamevault/UserControls/GameSettingsUserControl.xaml index b06ffd6..bc4a6d8 100644 --- a/gamevault/UserControls/GameSettingsUserControl.xaml +++ b/gamevault/UserControls/GameSettingsUserControl.xaml @@ -163,7 +163,7 @@ - + diff --git a/gamevault/UserControls/GameViewUserControl.xaml.cs b/gamevault/UserControls/GameViewUserControl.xaml.cs index e142575..4242c76 100644 --- a/gamevault/UserControls/GameViewUserControl.xaml.cs +++ b/gamevault/UserControls/GameViewUserControl.xaml.cs @@ -139,7 +139,8 @@ private void GamePlay_Click(object sender, MouseButtonEventArgs e) MainWindowViewModel.Instance.AppBarText = $"Can not execute '{savedExecutable}'"; } } - Preferences.Set(AppConfigKey.LastPlayed, DateTime.Now.ToString(), $"{path}\\gamevault-exec"); + MainWindowViewModel.Instance.Library.GetGameInstalls().SetLastPlayedGame(result.Key.ID); + //Preferences.Set(AppConfigKey.LastPlayed, DateTime.Now.ToString(), $"{path}\\gamevault-exec"); } else { diff --git a/gamevault/UserControls/InstallUserControl.xaml.cs b/gamevault/UserControls/InstallUserControl.xaml.cs index 63eb9f2..6241756 100644 --- a/gamevault/UserControls/InstallUserControl.xaml.cs +++ b/gamevault/UserControls/InstallUserControl.xaml.cs @@ -152,27 +152,33 @@ private async Task>> SortInstall { try { - Dictionary lastPlayedDates = new Dictionary(); - foreach (var val in collection) - { - if (File.Exists(val.Value + @"\gamevault-exec")) - { - string lastTimePlayed = Preferences.Get(AppConfigKey.LastPlayed, val.Value + @"\gamevault-exec"); - lastPlayedDates.Add(val.Key.ID, lastTimePlayed); - } - } - lastPlayedDates = lastPlayedDates.OrderByDescending(kv => string.IsNullOrEmpty(kv.Value) ? DateTime.MinValue : DateTime.Parse(kv.Value)).ToDictionary(kv => kv.Key, kv => kv.Value); + string lastTimePlayed = Preferences.Get(AppConfigKey.LastPlayed, AppFilePath.UserFile); + List lastPlayedDates = lastTimePlayed.Split(';').ToList(); collection = new System.Collections.ObjectModel.ObservableCollection>(collection.OrderByDescending(item => { int key = item.Key.ID; - return lastPlayedDates.ContainsKey(key) ? lastPlayedDates[key] : string.Empty; - })); + return lastPlayedDates.Contains(key.ToString()) ? lastPlayedDates.IndexOf(key.ToString()) : int.MaxValue; + }).Reverse()); } catch { } return collection; }); } + public void SetLastPlayedGame(int gameID) + { + try + { + string lastTimePlayed = Preferences.Get(AppConfigKey.LastPlayed, AppFilePath.UserFile); + if (lastTimePlayed.Contains($"{gameID}")) + { + lastTimePlayed = lastTimePlayed.Replace($"{gameID};", ""); + } + lastTimePlayed = lastTimePlayed.Insert(0, $"{gameID};"); + Preferences.Set(AppConfigKey.LastPlayed, lastTimePlayed, AppFilePath.UserFile); + } + catch { } + } public void AddSystemFileWatcher(string path) { @@ -324,7 +330,8 @@ private void Play_Click(object sender, MouseButtonEventArgs e) MainWindowViewModel.Instance.AppBarText = $"Can not execute '{savedExecutable}'"; } } - Preferences.Set(AppConfigKey.LastPlayed, DateTime.Now.ToString(), $"{((KeyValuePair)((FrameworkElement)sender).DataContext).Value}\\gamevault-exec"); + SetLastPlayedGame(((KeyValuePair)((FrameworkElement)sender).DataContext).Key.ID); + //Preferences.Set(AppConfigKey.LastPlayed, DateTime.Now.ToString(), $"{((KeyValuePair)((FrameworkElement)sender).DataContext).Value}\\gamevault-exec"); } else { @@ -348,7 +355,7 @@ private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e { if (((ScrollViewer)sender).ComputedHorizontalScrollBarVisibility == Visibility.Visible) { - e.Handled = true; + e.Handled = true; if (e.Delta > 0) ((ScrollViewer)sender).LineLeft(); else