@implements IDisposable @using LANCommander.Launcher.Data.Models @using LANCommander.Launcher.Models @using System.Diagnostics @using LANCommander.SDK.Helpers @inject GameService GameService @inject LibraryService LibraryService @inject DownloadService DownloadService @inject ModalService ModalService @inject MessageBusService MessageBusService @inject SDK.Client Client @if (GameActions != null && GameActions.Count() > 0) { @foreach (var action in GameActions.OrderBy(a => a.SortOrder)) { @action.Name } } @if (Game.Installed) { if (Game.Media != null && Game.Media.Any(m => m.Type == SDK.Enums.MediaType.Manual)) { foreach (var manual in Game.Media.Where(m => m.Type == SDK.Enums.MediaType.Manual)) { @(String.IsNullOrWhiteSpace(manual.Name) ? "Manual" : manual.Name) } } Browse Files Uninstall } else { Install } @if (Settings.Debug.EnableScriptDebugging) { Run Install Scripts Run Name Change Scripts Run Key Change Scripts } Report Issue @MenuExtra @code { [Parameter] public LibraryItem Model { get; set; } [Parameter] public RenderFragment MenuExtra { get; set; } Data.Models.Game Game { get; set; } IEnumerable GameActions { get; set; } Settings Settings; protected override async Task OnInitializedAsync() { MessageBusService.OnGameStarted += UpdateState; MessageBusService.OnGameStopped += UpdateState; Settings = SettingService.GetSettings(); } protected override async Task OnParametersSetAsync() { if (Model.DataItem is Game) { Game = Model.DataItem as Game; GameActions = new List(); if (Game.Installed) { var manifest = ManifestHelper.Read(Game.InstallDirectory, Game.Id); if (manifest != null) GameActions = manifest.Actions.Where(a => !a.IsPrimaryAction).ToList(); } } } async Task UpdateState(Game game) { if (Game.Id == game.Id) await InvokeAsync(StateHasChanged); } async Task Run(Game game, SDK.Models.Action action) { LibraryService.Run(Game, action); await InvokeAsync(StateHasChanged); } async Task BrowseFiles() { Process.Start("explorer", Game.InstallDirectory); } async Task Install() { await LibraryService.Install(Model); } async Task Uninstall() { var manifest = ManifestHelper.Read(Game.InstallDirectory, Game.Id); var message = $"Would you like to uninstall {Game.Title}?"; if (manifest.SavePaths != null && manifest.SavePaths.Any()) message += " Your save files have been uploaded to the server."; else message += " Your save files may be unrecoverable if they are contained within the game's install directory."; var confirmed = await ModalService.ConfirmAsync(new ConfirmOptions { OkText = "Uninstall", CancelText = "Cancel", Title = "Uninstall", Content = message, OkType = "danger", Centered = true, Icon = @ }); if (confirmed) await GameService.UninstallAsync(Game); DownloadService.Remove(Game.Id); await LibraryService.LibraryChanged(); } async Task RunInstallScripts() { var manifests = GameService.GetGameManifests(Game); foreach (var manifest in manifests) { await Client.Scripts.RunInstallScriptAsync(Game.InstallDirectory, manifest.Id); } } async Task RunNameChangeScripts() { var manifests = GameService.GetGameManifests(Game); foreach (var manifest in manifests) { await Client.Scripts.RunNameChangeScriptAsync(Game.InstallDirectory, Game.Id, Settings.Profile.Alias); } } async Task RunKeyChangeScripts() { var manifests = GameService.GetGameManifests(Game); foreach (var manifest in manifests) { var key = Client.Games.GetAllocatedKey(manifest.Id); await Client.Scripts.RunKeyChangeScriptAsync(Game.InstallDirectory, Game.Id, key); } } async Task OpenManual(Media media) { var modalOptions = new ModalOptions() { Title = media.Name, Maximizable = true, DefaultMaximized = true, Closable = true, Footer = null, Draggable = true, Resizable = true, WrapClassName = "pdf-reader-dialog", }; var modalRef = await ModalService.CreateModalAsync(modalOptions, media); } async Task ReportIssue() { var modalOptions = new ModalOptions() { Title = "Report Issue", Maximizable = false, DefaultMaximized = false, Closable = true, OkText = "Submit", Draggable = true, Resizable = true }; var modalRef = ModalService.CreateModal(modalOptions, Game); } public void Dispose() { MessageBusService.OnGameStarted -= UpdateState; MessageBusService.OnGameStopped -= UpdateState; } }