59 lines
1.9 KiB
Text
59 lines
1.9 KiB
Text
@page "/Settings/Servers"
|
|
@using LANCommander.Server.Settings
|
|
@using LANCommander.Server.UI.Pages.Settings.Components
|
|
@using Microsoft.Extensions.Options
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Servers> Logger
|
|
@inject IOptions<Settings> Settings
|
|
@inject SettingsProvider<Settings> SettingsProvider
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
<PageHeader Title="Servers">
|
|
<PageHeaderExtra>
|
|
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<PageContent>
|
|
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
|
|
<FormItem Label="Storage Path">
|
|
<FilePicker Root="@RootPath" EntrySelectable="x => x is FileManagerDirectory" @bind-Value="@context.Server.GameServers.StoragePath" OkText="Select Path" Title="Choose Path" OnSelected="OnPathSelected" />
|
|
</FormItem>
|
|
</Form>
|
|
|
|
<Divider Text="Server Engines" />
|
|
|
|
<ServerEngineEditor @bind-Values="Settings.Value.Server.GameServers.ServerEngines" />
|
|
</PageContent>
|
|
|
|
@code {
|
|
string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory());
|
|
|
|
void Save()
|
|
{
|
|
try
|
|
{
|
|
SettingsProvider.Update(s =>
|
|
{
|
|
s.Server.GameServers = Settings.Value.Server.GameServers;
|
|
});
|
|
|
|
MessageService.Success("Settings saved!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("An unknown error occurred.");
|
|
Logger.LogError(ex, "An unknown error occurred.");
|
|
}
|
|
}
|
|
|
|
void OnPathSelected(string path)
|
|
{
|
|
var appPath = Directory.GetCurrentDirectory();
|
|
|
|
if (path != null && path.StartsWith(appPath))
|
|
path = path.Substring(appPath.Length).TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
|
|
|
|
Settings.Value.Server.GameServers.StoragePath = path;
|
|
}
|
|
}
|