LANCommander/LANCommander.Launcher/UI/Components/RemoveFromLibraryDialog.razor
Pat Hartl 6dfc0906ac Refactor launcher library importing, manifests
Switched the library importing in the launcher to work based on a queue. As a new game is added to the queue, it should find any related data and also add it to the queue. This should result in an easier to maintain importer while reducing the load on the launcher's DAL. This may result in more RAM usage while importing. Local manifests have also been refactored to match manifests in import/export LCX files, removing the old manifest format. This is a large breaking change that will probably break existing game installations. A migration will probably have to be created.
2025-11-29 18:24:27 -06:00

84 lines
No EOL
2.8 KiB
Text

@using LANCommander.Launcher.Data.Models
@using LANCommander.Launcher.Models
@using LANCommander.SDK.Enums
@using LANCommander.SDK.Extensions
@inherits FeedbackComponent<Models.ListItem, string>
@inject LibraryService LibraryService
@inject IMessageService MessageService
@inject ILogger<RemoveFromLibraryDialog> Logger
@inject LocalizationService LocalizationService
<div class="remove-from-library-dialog" style="padding: 16px;">
<div class="game-item">
<div class="icon">
<MediaImage Id="@Options.IconId" />
</div>
<span class="title-pre">@LocalizationService.GetString("BaseGame")</span>
<span class="title">@Options.Name</span>
</div>
@if (DependentGames.Any())
{
<Divider Text="@LocalizationService.GetString("AddonsToRemove")" Orientation="DividerOrientation.Left" Plain />
<CheckboxButtonGroup @bind-Selected="SelectedDependentGames" DataSource="DependentGames"
KeySelector="a => a.Id"
LabelSelector="a => a.Title"
Direction="SpaceDirection.Vertical"
IconSelected="@IconType.Outline.Close"
IconUnselected="@IconType.Fill.Pushpin"
ButtonPropsSelected="@(new[] { ("Danger", (object)true) })"
DisableSelector="g => g.Type == GameType.Mod || g.Type == GameType.Expansion"
/>
}
</div>
<Flex Gap="FlexGap.Middle" Style="padding: 16px; padding-top: 0px" Justify="FlexJustify.FlexEnd">
<Button Type="ButtonType.Primary" OnClick="RemoveFromLibrary">@LocalizationService.GetString("Remove")</Button>
<Button OnClick="() => Close()">@LocalizationService.GetString("Close")</Button>
</Flex>
@code {
Data.Models.Game? Game;
List<Data.Models.Game> DependentGames = new();
IEnumerable<Data.Models.Game> SelectedDependentGames = [];
protected override void OnInitialized()
{
base.OnInitialized();
Game = (Game)Options.DataItem;
DependentGames = Game?.DependentGames.OrderBy(g => g.SortTitle ?? g.Title).ToList() ?? [];
SelectedDependentGames = DependentGames?.Where(g => g.Type == GameType.Expansion || g.Type == GameType.Mod) ?? [];
}
async Task Close()
{
await CloseFeedbackAsync();
}
async Task RemoveFromLibrary()
{
if (Options.DataItem is Game game)
{
try
{
var addonIds = SelectedDependentGames?.Select(a => a.Id).ToArray() ?? [];
await LibraryService.RemoveFromLibraryAsync(game!.Id, addonIds);
await LibraryService.RefreshItemsAsync(true);
}
catch (Exception ex)
{
MessageService.Error(LocalizationService.GetString("CouldNotRemoveGame"));
Logger?.LogError(ex, "Could not remove game {GameTitle}", game.Title);
}
}
await CloseFeedbackAsync();
}
}