@page "/Settings/UserSaves" @using LANCommander.SDK.Enums @inject StorageLocationService StorageLocationService @inject IMessageService MessageService @inject ILogger Logger @attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
@code { Settings Settings = SettingService.GetSettings(); string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory()); StorageLocation SaveStorageLocation = new(); protected override async Task OnInitializedAsync() { SaveStorageLocation = await StorageLocationService.FirstOrDefaultAsync(l => l.Default && l.Type == StorageLocationType.Save); } async Task Save() { try { SettingService.SaveSettings(Settings); await StorageLocationService.UpdateAsync(SaveStorageLocation); 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); SaveStorageLocation.Path = path; } }