mirror of
https://github.com/tgeorgiadis/quiver-launcher.git
synced 2026-11-22 21:50:52 -05:00
Rename GithubLauncher to Quiver, vendor Quiver.Core into the main repository, add community catalog support, tests, and updated branding assets for the 2.0 release. Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
using System.Collections.ObjectModel;
|
|
using Quiver.Models;
|
|
using Quiver.Services;
|
|
|
|
namespace Quiver.ViewModels;
|
|
|
|
public class GameGridViewModel
|
|
{
|
|
public IReadOnlyList<GameInfo> SortGames(IEnumerable<GameInfo> games, string sortMode, string gamesFolder)
|
|
{
|
|
var list = games.Where(g => g != null).Cast<GameInfo>().ToList();
|
|
|
|
return sortMode switch
|
|
{
|
|
"NameDesc" => list.OrderByDescending(g => g.Name ?? string.Empty).ToList(),
|
|
"Installed" => list
|
|
.OrderByDescending(g => g.IsInstalled)
|
|
.ThenBy(g => g.Name ?? string.Empty)
|
|
.ToList(),
|
|
"NotInstalled" => list
|
|
.OrderBy(g => g.IsInstalled)
|
|
.ThenBy(g => g.Name ?? string.Empty)
|
|
.ToList(),
|
|
"LastPlayed" => list
|
|
.OrderByDescending(g => GetLastPlayedTime(g, gamesFolder))
|
|
.ThenBy(g => g.Name ?? string.Empty)
|
|
.ToList(),
|
|
_ => list.OrderBy(g => g.Name ?? string.Empty).ToList(),
|
|
};
|
|
}
|
|
|
|
public void ApplySort(ObservableCollection<GameInfo> games, string sortMode, string gamesFolder)
|
|
{
|
|
if (games.Count == 0)
|
|
return;
|
|
|
|
var sorted = SortGames(games, sortMode, gamesFolder);
|
|
games.Clear();
|
|
foreach (var game in sorted)
|
|
games.Add(game);
|
|
}
|
|
|
|
public static DateTime GetLastPlayedTime(GameInfo game, string gamesFolder)
|
|
{
|
|
if (string.IsNullOrEmpty(game.FolderName))
|
|
return DateTime.MinValue;
|
|
|
|
try
|
|
{
|
|
var gamePath = game.GetInstallPath(gamesFolder);
|
|
var lastPlayedPath = Path.Combine(gamePath, "LastPlayed.txt");
|
|
|
|
if (File.Exists(lastPlayedPath))
|
|
{
|
|
var content = File.ReadAllText(lastPlayedPath).Trim();
|
|
if (DateTime.TryParseExact(content, "yyyy-MM-dd HH:mm:ss", null,
|
|
System.Globalization.DateTimeStyles.None, out var lastPlayed))
|
|
return lastPlayed;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"Failed to read LastPlayed for {game.Name}: {ex.Message}");
|
|
}
|
|
|
|
return DateTime.MinValue;
|
|
}
|
|
}
|