LANCommander/LANCommander.Launcher.Models/ListItem.cs

97 lines
2.6 KiB
C#
Raw Permalink Normal View History

using LANCommander.Launcher.Data.Models;
using LANCommander.SDK.Helpers;
2024-05-23 23:41:38 -05:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
2024-05-23 23:41:38 -05:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LANCommander.Launcher.Models
2024-05-23 23:41:38 -05:00
{
2024-11-09 17:15:04 -06:00
public enum ListItemState
{
NotInstalled,
Installed,
Queued,
Installing,
2025-01-27 00:04:42 -06:00
UpdateAvailable,
Uninstalling,
}
2024-11-09 17:15:04 -06:00
public enum ListItemType
2024-05-23 23:41:38 -05:00
{
Game,
Redistributable
}
2024-11-09 17:15:04 -06:00
public class ListItem
2024-05-23 23:41:38 -05:00
{
public Guid Key { get; set; }
2024-06-05 19:03:04 -05:00
public Guid IconId { get; set; }
2024-11-09 17:15:04 -06:00
public ListItemType Type { get; set; }
public ListItemState State { get; set; }
2024-05-23 23:41:38 -05:00
public string Name { get; set; }
public string SortName { get; set; }
public string[] Groups { get; set; }
2024-05-23 23:41:38 -05:00
public object DataItem { get; set; }
2024-11-09 17:15:04 -06:00
public ListItem(Collection collection)
2024-05-23 23:41:38 -05:00
{
Key = collection.Id;
2024-11-09 17:15:04 -06:00
Type = ListItemType.Game;
2024-05-23 23:41:38 -05:00
Name = collection.Name;
DataItem = collection;
}
2024-11-09 17:15:04 -06:00
public ListItem(Game game)
2024-05-23 23:41:38 -05:00
{
Key = game.Id;
2024-11-09 17:15:04 -06:00
Type = ListItemType.Game;
2024-05-23 23:41:38 -05:00
Name = game.Title;
SortName = game.SortTitle;
DataItem = game;
var manifestPath = ManifestHelper.GetPath(game.InstallDirectory, game.Id);
if (game.Installed && !String.IsNullOrWhiteSpace(game.LatestVersion) && game.InstalledVersion != game.LatestVersion)
2024-11-09 17:15:04 -06:00
State = ListItemState.UpdateAvailable;
else if (game.Installed && File.Exists(manifestPath))
2024-11-09 17:15:04 -06:00
State = ListItemState.Installed;
else
2024-11-09 17:15:04 -06:00
State = ListItemState.NotInstalled;
2024-06-05 19:03:04 -05:00
2024-06-19 19:36:04 -05:00
var icon = game.Media.FirstOrDefault(m => m.Type == SDK.Enums.MediaType.Icon);
2024-06-05 19:03:04 -05:00
if (icon != null)
IconId = icon.Id;
2024-05-23 23:41:38 -05:00
}
2024-11-09 17:15:04 -06:00
public ListItem(Redistributable redistributable)
2024-05-23 23:41:38 -05:00
{
Key = redistributable.Id;
2024-11-09 17:15:04 -06:00
Type = ListItemType.Redistributable;
2024-05-23 23:41:38 -05:00
Name = redistributable.Name;
DataItem = redistributable;
}
2024-11-09 17:15:04 -06:00
public ListItem(SDK.Models.Game game)
{
Key = game.Id;
Type = ListItemType.Game;
Name = game.Title;
SortName = game.SortTitle;
DataItem = game;
}
2024-11-12 02:35:28 -06:00
public ListItem(SDK.Models.DepotGame game)
{
Key = game.Id;
Type = ListItemType.Game;
Name = game.Title;
SortName = game.SortTitle;
DataItem = game;
}
2024-05-23 23:41:38 -05:00
}
}