@using LANCommander.Launcher.Data.Models @using LANCommander.Launcher.Models @using LANCommander.SDK.Extensions @inherits FeedbackComponent @inject InstallService InstallService @inject SDK.Client Client
@if (Addons.Any()) { } @if (Settings.Games.InstallDirectories.Length > 1) { @foreach (var directory in Settings.Games.InstallDirectories) { @directory } }
@if (GetOperation() != InstallOperation.None) { } @code { Settings Settings = SettingService.GetSettings(); string SelectedDirectory = ""; List Addons = new(); SDK.Models.Game RemoteGame; Data.Models.Game Game; IEnumerable SelectedAddons = new List(); enum InstallOperation { None, Install, Move, Modify, } protected override async Task OnInitializedAsync() { Game = Options.DataItem as Game; if (Game.Installed) SelectedDirectory = Settings.Games.InstallDirectories.FirstOrDefault(d => Game.InstallDirectory.StartsWith(d)); if (String.IsNullOrWhiteSpace(SelectedDirectory)) SelectedDirectory = Settings.Games.InstallDirectories.First(); RemoteGame = await Client.Games.GetAsync(Options.Key); Addons = (await Client.Games.GetAddonsAsync(Options.Key)).OrderByTitle(g => g.SortTitle ?? g.Title).ToList(); } async Task Close() { await CloseFeedbackAsync(); } async Task Install() { var game = Options.DataItem as Game; InstallService.Add(game, SelectedDirectory, SelectedAddons.Select(a => a.Id).ToArray()); await CloseFeedbackAsync(); } InstallOperation GetOperation() { if (!Game.Installed) return InstallOperation.Install; if (Game.DependentGames.Any(g => !g.Installed && SelectedAddons.Any(a => a.Id == g.Id))) return InstallOperation.Modify; if (!Game.InstallDirectory.StartsWith(SelectedDirectory)) return InstallOperation.Move; return InstallOperation.None; } long GetDownloadSize() { long size = 0; if (RemoteGame != null && RemoteGame.Archives.Any()) { size += RemoteGame.Archives.OrderByDescending(a => a.CreatedOn).First().CompressedSize; size += SelectedAddons.Sum(a => a.Archives.OrderByDescending(arc => arc.CreatedOn).First().CompressedSize); } return size; } long GetSpaceRequired() { long size = 0; if (RemoteGame != null && RemoteGame.Archives.Any()) { size += RemoteGame.Archives.OrderByDescending(a => a.CreatedOn).First().UncompressedSize; size += SelectedAddons.Sum(a => a.Archives.OrderByDescending(arc => arc.CreatedOn).First().UncompressedSize); } return size; } long GetFreeSpace(string path) { var root = Path.GetPathRoot(path); var drive = new DriveInfo(path); return drive.AvailableFreeSpace; } }