Fixes the action, custom field, multiplayer mode, and save path editors from clearing out taxonomies when saving. Also passes the Game/Server/Redistributable ID as a cascading parameter.
96 lines
3.3 KiB
Text
96 lines
3.3 KiB
Text
@inject SavePathService SavePathService
|
|
@inject ArchiveService ArchiveService
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<SavePathEditor> Logger
|
|
|
|
<Flex Direction="FlexDirection.Vertical" Gap="FlexGap.Large">
|
|
<Table TItem="SavePath" DataSource="@_savePaths" HidePagination="true" Responsive>
|
|
<PropertyColumn Property="p => p.Type">
|
|
<Select @bind-Value="context.Type" TItem="SavePathType" TItemValue="SavePathType" DataSource="Enum.GetValues<SavePathType>()">
|
|
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
|
|
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
|
|
</Select>
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="p => p.Path">
|
|
@if (context.Type == SavePathType.Registry)
|
|
{
|
|
<InputRegistry @bind-Value="context.Path" />
|
|
}
|
|
else
|
|
{
|
|
<FilePicker @bind-Value="context.Path" ArchiveId="@_archive.Id" AllowDirectories="true" />
|
|
}
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="p => p.WorkingDirectory" Title="Working Directory">
|
|
<FilePicker @bind-Value="context.WorkingDirectory" Disabled="@(context.Type == SavePathType.Registry)" ArchiveId="@_archive.Id" AllowDirectories Title="Select Working Directory" />
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="p => p.IsRegex" Title="Regex">
|
|
<Checkbox @bind-Checked="context.IsRegex" Disabled="@(context.Type == SavePathType.Registry)" />
|
|
</PropertyColumn>
|
|
<ActionColumn>
|
|
<Flex Gap="FlexGap.Small" Justify="FlexJustify.End">
|
|
<Button OnClick="() => RemovePath(context)" Type="@ButtonType.Text" Danger Icon="@IconType.Outline.Close" />
|
|
</Flex>
|
|
</ActionColumn>
|
|
</Table>
|
|
|
|
<Flex Justify="FlexJustify.End">
|
|
<Button OnClick="AddPath" Type="@ButtonType.Primary">Add Path</Button>
|
|
</Flex>
|
|
</Flex>
|
|
|
|
@code {
|
|
[CascadingParameter(Name = "GameId")] public Guid GameId { get; set; }
|
|
|
|
Archive _archive;
|
|
ICollection<SavePath> _savePaths = new List<SavePath>();
|
|
|
|
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();
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|