Skip to content

Commit

Permalink
Process optimized. It is now faster and less complicated, with fewer …
Browse files Browse the repository at this point in the history
…file accesses required
  • Loading branch information
Yelo420 committed Jan 13, 2024
1 parent 119e0e0 commit a454564
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gamevault/UserControls/GameSettingsUserControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
</StackPanel>
<TextBlock Text="Disk Usage" FontSize="15" FontWeight="Bold" TextDecorations="Underline" Margin="0,20,0,0"/>
<lvc:PieChart x:Name="uiDiscUsagePieChart" Width="600" Height="400" InitialRotation="-90" IsClockwise="True" HorizontalAlignment="Left" Margin="0,10,0,0" LegendPosition="Right"/>
<StackPanel Margin="150,0,0,0" HorizontalAlignment="Left">
<StackPanel Margin="133,-70,0,0" HorizontalAlignment="Left">
<TextBlock Text="Total Disk Size" FontSize="15" FontWeight="Bold" />
<TextBlock x:Name="uiTxtAllInstalledGamesSize" FontSize="15" FontWeight="Bold" HorizontalAlignment="Center"/>
</StackPanel>
Expand Down
3 changes: 2 additions & 1 deletion gamevault/UserControls/GameViewUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
35 changes: 21 additions & 14 deletions gamevault/UserControls/InstallUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,33 @@ private async Task<ObservableCollection<KeyValuePair<Game, string>>> SortInstall
{
try
{
Dictionary<int, string> lastPlayedDates = new Dictionary<int, string>();
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<string> lastPlayedDates = lastTimePlayed.Split(';').ToList();
collection = new System.Collections.ObjectModel.ObservableCollection<KeyValuePair<Game, string>>(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)
{
Expand Down Expand Up @@ -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<Game, string>)((FrameworkElement)sender).DataContext).Value}\\gamevault-exec");
SetLastPlayedGame(((KeyValuePair<Game, string>)((FrameworkElement)sender).DataContext).Key.ID);
//Preferences.Set(AppConfigKey.LastPlayed, DateTime.Now.ToString(), $"{((KeyValuePair<Game, string>)((FrameworkElement)sender).DataContext).Value}\\gamevault-exec");
}
else
{
Expand All @@ -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
Expand Down

0 comments on commit a454564

Please sign in to comment.