127 lines
4.4 KiB
Text
127 lines
4.4 KiB
Text
@page "/Settings"
|
|
@using LANCommander.Launcher.Models
|
|
@inject NavigationManager NavigationManager
|
|
@inject UpdateService UpdateService
|
|
@inject SDK.Client Client
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Index> Logger
|
|
|
|
<div style="flex-grow: 1">
|
|
<PageHeader Title="Settings" OnBack="@(() => { NavigationManager.NavigateTo("/"); })" Style="padding-top: 48px">
|
|
<PageHeaderExtra>
|
|
<Flex Gap="FlexGap.Small" Justify="FlexJustify.End">
|
|
<Button OnClick="CheckForUpdates">Check for Updates</Button>
|
|
<Button OnClick="Save" Type="ButtonType.Primary">Save</Button>
|
|
</Flex>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<Form Model="Settings" Layout="@FormLayout.Vertical" Style="padding: 0 24px">
|
|
<Divider Orientation="DividerOrientation.Left" Plain>Games</Divider>
|
|
<FormItem Label="Storage Paths">
|
|
<Flex Direction="FlexDirection.Vertical" Gap="FlexGap.Middle">
|
|
@foreach (var installDirectory in InstallDirectories)
|
|
{
|
|
<Flex Gap="FlexGap.Small">
|
|
<Input @bind-Value="installDirectory.Path"/>
|
|
<Button OnClick="() => RemoveInstallDirectory(installDirectory)" Type="@ButtonType.Text" Danger Icon="@IconType.Outline.Close" Disabled="InstallDirectories.Count == 1"/>
|
|
</Flex>
|
|
}
|
|
<Flex Justify="FlexJustify.End">
|
|
<Button OnClick="AddInstallDirectory" Type="ButtonType.Primary">Add Path</Button>
|
|
</Flex>
|
|
</Flex>
|
|
</FormItem>
|
|
|
|
<Divider Orientation="DividerOrientation.Left" Plain>Media</Divider>
|
|
<FormItem Label="Storage Path">
|
|
<Input @bind-Value="@context.Media.StoragePath" />
|
|
</FormItem>
|
|
|
|
<Divider Orientation="DividerOrientation.Left" Plain>Debug</Divider>
|
|
<FormItem Label="Enable Script Debugging">
|
|
<Switch @bind-Checked="@context.Debug.EnableScriptDebugging" />
|
|
</FormItem>
|
|
<FormItem Label="Logging Path">
|
|
<Input @bind-Value="@context.Debug.LoggingPath" />
|
|
</FormItem>
|
|
<FormItem Label="Logging Level">
|
|
<Select @bind-Value="@context.Debug.LoggingLevel" TItem="LogLevel" TItemValue="LogLevel" DataSource="Enum.GetValues<LogLevel>()">
|
|
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
|
|
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
|
|
</Select>
|
|
</FormItem>
|
|
</Form>
|
|
</div>
|
|
|
|
<Flex Justify="FlexJustify.Center" Style="padding: 12px;">
|
|
LANCommander Launcher v@(UpdateService.GetCurrentVersion().ToString())
|
|
</Flex>
|
|
|
|
@code {
|
|
Settings Settings;
|
|
|
|
List<InstallDirectory> InstallDirectories = new List<InstallDirectory>();
|
|
|
|
internal class InstallDirectory
|
|
{
|
|
internal Guid Id { get; set; }
|
|
internal string Path { get; set; }
|
|
|
|
public InstallDirectory(string path)
|
|
{
|
|
Id = Guid.NewGuid();
|
|
Path = path;
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Settings = SettingService.GetSettings();
|
|
|
|
foreach (var installDirectory in Settings.Games.InstallDirectories)
|
|
{
|
|
InstallDirectories.Add(new InstallDirectory(installDirectory));
|
|
}
|
|
}
|
|
|
|
void Save()
|
|
{
|
|
try
|
|
{
|
|
Settings.Games.InstallDirectories = InstallDirectories.Where(d => !String.IsNullOrWhiteSpace(d.Path)).Select(d => d.Path).ToArray();
|
|
|
|
SettingService.SaveSettings(Settings);
|
|
|
|
Client.DefaultInstallDirectory = Settings.Games.InstallDirectories.First();
|
|
Client.Scripts.Debug = Settings.Debug.EnableScriptDebugging;
|
|
|
|
MessageService.Success("Settings saved!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("An unknown error occurred.");
|
|
Logger.LogError(ex, "An unknown error occurred.");
|
|
}
|
|
}
|
|
|
|
async Task CheckForUpdates()
|
|
{
|
|
var updateVersion = await UpdateService.CheckForUpdateAsync();
|
|
|
|
if (updateVersion == null)
|
|
MessageService.Success("You are on the latest version!");
|
|
}
|
|
|
|
async Task AddInstallDirectory()
|
|
{
|
|
InstallDirectories.Add(new InstallDirectory(""));
|
|
|
|
StateHasChanged();
|
|
}
|
|
|
|
async Task RemoveInstallDirectory(InstallDirectory installDirectory)
|
|
{
|
|
InstallDirectories.Remove(installDirectory);
|
|
}
|
|
}
|