@page "/FirstTimeSetup/Paths" @using LANCommander.SDK @using LANCommander.SDK.Enums @using LANCommander.Server.Settings @using Microsoft.Extensions.Options @layout FirstTimeSetupLayout @inject SetupService SetupService @inject StorageLocationService StorageLocationService @inject SettingsProvider SettingsProvider @inject IOptions Settings @inject NavigationManager NavigationManager @inject IMessageService MessageService @inject ILogger Logger Configure Paths - First Time Setup
Configure where archives, saves, and media get stored.
@if (SavesStorageLocation != null) { } @if (MediaStorageLocation != null) { } @code { [CascadingParameter] FirstTimeSetupLayout Layout { get; set; } ICollection ArchiveStorageLocations = new List(); StorageLocation MediaStorageLocation = new() { Path = AppPaths.GetConfigPath("Media"), Type = StorageLocationType.Media, Default = true, }; StorageLocation SavesStorageLocation = new() { Path = AppPaths.GetConfigPath("Saves"), Type = StorageLocationType.Save, Default = true, }; bool Loading = false; string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory()); protected override async Task OnInitializedAsync() { await Layout.ChangeCurrentStep(FirstTimeSetupStep.Paths); var isSetupInitialized = await SetupService.IsSetupInitialized(); if (isSetupInitialized) { NavigationManager.NavigateTo("/"); return; } try { ArchiveStorageLocations = await StorageLocationService .AsNoTracking() .GetAsync(l => l.Type == StorageLocationType.Archive); } catch (Exception ex) { Logger?.LogError(ex, "Couldn't retrieve existing archive storage locations"); } finally { if (!ArchiveStorageLocations.Any()) ArchiveStorageLocations.Add(new StorageLocation { Path = Path.Join(AppPaths.GetConfigDirectory(), "Uploads"), Type = StorageLocationType.Archive, Default = true, }); } try { SavesStorageLocation = await StorageLocationService .AsNoTracking() .FirstOrDefaultAsync(l => l.Type == StorageLocationType.Save && l.Default); } catch (Exception ex) { Logger?.LogError(ex, "Couldn't retrieve existing store locations"); SavesStorageLocation = new StorageLocation { Path = Path.Join(AppPaths.GetConfigDirectory(), "Saves"), Type = StorageLocationType.Save, Default = true, }; } try { MediaStorageLocation = await StorageLocationService .AsNoTracking() .FirstOrDefaultAsync(l => l.Type == SDK.Enums.StorageLocationType.Media && l.Default); } catch (Exception ex) { Logger?.LogError(ex, "Couldn't retrieve existing store locations"); MediaStorageLocation = new StorageLocation { Path = Path.Join(AppPaths.GetConfigDirectory(), "Media"), Type = StorageLocationType.Media, Default = true, }; } } async Task ValidatePaths() { try { var locations = new List(ArchiveStorageLocations); locations.Add(SavesStorageLocation); locations.Add(MediaStorageLocation); await SetupService.UpdatePaths(locations); NavigationManager.NavigateTo("/FirstTimeSetup/Metadata"); } catch (Exception ex) { Logger?.LogError(ex, $"Error validating path"); MessageService.Error($"Error validating path: {ex.Message}", 10); } } void SetDefault(StorageLocation storageLocation) { foreach (var archiveStorageLocation in ArchiveStorageLocations) { archiveStorageLocation.Default = archiveStorageLocation.Id == storageLocation.Id; } } string OnPathSelected(string path) { var appPath = Directory.GetCurrentDirectory(); if (path != null && path.StartsWith(appPath)) path = path.Substring(appPath.Length).TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar); return path; } void OnPathSelected(StorageLocation storageLocation, string path) { storageLocation.Path = OnPathSelected(path); } void AddArchiveStorageLocation() { ArchiveStorageLocations.Add(new StorageLocation()); StateHasChanged(); } void RemoveArchiveStorageLocation(StorageLocation storageLocation) { ArchiveStorageLocations.Remove(storageLocation); } }