@inject SavePathService SavePathService @inject ArchiveService ArchiveService @inject ModalService ModalService @inject IMessageService MessageService @inject ILogger Logger @if (context.Type == SavePathType.Registry) { } else {
@code { [CascadingParameter(Name = "GameId")] public Guid GameId { get; set; } Archive? _archive; ICollection _savePaths = new List(); protected override async Task OnInitializedAsync() { _archive = await ArchiveService.GetLatestArchiveAsync(a => a.GameId == GameId); await LoadPaths(); } async Task LoadPaths() => _savePaths = await SavePathService.GetAsync(p => p.GameId == GameId); void AddPath() { _savePaths.Add(new SavePath { GameId = GameId, WorkingDirectory = "{InstallDir}" }); } async Task RemovePath(SavePath path) { await SavePathService.DeleteAsync(path); await LoadPaths(); } async Task OpenVariablePicker(SavePath savePath, string fieldName) { var currentValue = fieldName switch { nameof(SavePath.Path) => savePath.Path ?? "", nameof(SavePath.WorkingDirectory) => savePath.WorkingDirectory ?? "", _ => "" }; var modalOptions = new ModalOptions { Title = $"Edit {fieldName}", Maximizable = false, Closable = true, OkText = "Apply" }; var pickerOptions = new VariablePickerOptions { Value = currentValue, FieldName = fieldName }; var modalRef = await ModalService.CreateModalAsync(modalOptions, pickerOptions); modalRef.OnOk = (result) => { switch (fieldName) { case nameof(SavePath.Path): savePath.Path = result; break; case nameof(SavePath.WorkingDirectory): savePath.WorkingDirectory = result; break; } StateHasChanged(); return Task.CompletedTask; }; } public async Task Save() { try { foreach (var savePath in _savePaths) { if (savePath.Id == Guid.Empty) await SavePathService.AddAsync(savePath); else await SavePathService.UpdateAsync(savePath); } MessageService.SuccessAsync("Save paths updated!"); } catch (Exception ex) { MessageService.ErrorAsync("Could not update save paths!"); Logger.LogError(ex, "Could not update save paths!"); } await LoadPaths(); } }