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.
68 lines
1.8 KiB
Text
68 lines
1.8 KiB
Text
@implements IDisposable
|
|
@using LANCommander.Launcher.Data.Models
|
|
@inject SDK.Client Client
|
|
@inject MediaService MediaService
|
|
@inject ImportService ImportService
|
|
@inject MessageBusService MessageBusService
|
|
@inject ILogger<MediaImage> Logger
|
|
|
|
<img @ref="Ref" @key="@(String.IsNullOrWhiteSpace(Key) ? Id.ToString() : Key)" src="@MediaUrl" class="@Class @HiddenClass" @onerror="Hide" />
|
|
|
|
@code {
|
|
[Parameter] public Guid Id { get; set; }
|
|
[Parameter] public string Class { get; set; }
|
|
[Parameter] public string Key { get; set; }
|
|
[CascadingParameter] public bool Connected { get; set; }
|
|
[CascadingParameter] public bool OfflineMode { get; set; }
|
|
|
|
string MediaUrl { get; set; }
|
|
string HiddenClass { get; set; }
|
|
|
|
ElementReference Ref;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
MessageBusService.OnMediaChanged += OnMediaChanged;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
try {
|
|
var media = await MediaService.GetAsync(Id);
|
|
|
|
//if (media == null && (Connected || OfflineMode))
|
|
// media = await ImportService.ImportMediaAsync(Id);
|
|
|
|
UpdateMediaUrl(media);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger?.LogError(ex, "Could not load media with ID {MediaId}", Id);
|
|
}
|
|
}
|
|
|
|
async Task OnMediaChanged(Media media)
|
|
{
|
|
if (media.Id == Id)
|
|
{
|
|
UpdateMediaUrl(media);
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
async Task Hide()
|
|
{
|
|
HiddenClass = "hidden";
|
|
}
|
|
|
|
void UpdateMediaUrl(Media media)
|
|
{
|
|
MediaUrl = $"media://image?id={media?.Id}&fileId={media?.FileId}&crc32={media?.Crc32}&mime={media?.MimeType}";
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
MessageBusService.OnMediaChanged -= OnMediaChanged;
|
|
}
|
|
}
|