@page "/FirstTimeSetup/Paths" @layout FirstTimeSetupLayout @using Microsoft.EntityFrameworkCore @inject DatabaseServiceFactory DatabaseServiceFactory @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 StorageLocation(); StorageLocation SavesStorageLocation = new StorageLocation(); bool Loading = false; string RootPath = Path.GetPathRoot(Directory.GetCurrentDirectory()); protected override async Task OnInitializedAsync() { await Layout.ChangeCurrentStep(FirstTimeSetupStep.Paths); using (var storageLocationService = DatabaseServiceFactory.Create()) { try { ArchiveStorageLocations = await storageLocationService.GetAsync(l => l.Type == SDK.Enums.StorageLocationType.Archive); } catch (Exception ex) { Logger?.LogError(ex, "Couldn't retrieve existing archive storage locations"); } finally { if (!ArchiveStorageLocations.Any()) ArchiveStorageLocations.Add(new StorageLocation { Path = "Uploads", Type = SDK.Enums.StorageLocationType.Archive, Default = true, }); } try { SavesStorageLocation = await storageLocationService.FirstAsync(l => l.Type == SDK.Enums.StorageLocationType.Save && l.Default); } catch (Exception ex) { Logger?.LogError(ex, "Couldn't retrieve existing store locations"); SavesStorageLocation = new StorageLocation { Path = "Saves", Type = SDK.Enums.StorageLocationType.Save }; } try { MediaStorageLocation = await storageLocationService.FirstAsync(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 = "Media", Type = SDK.Enums.StorageLocationType.Media }; } } } void ValidatePaths() { var valid = false; try { foreach (var storageLocation in ArchiveStorageLocations) { if (!Directory.Exists(storageLocation.Path)) Directory.CreateDirectory(storageLocation.Path); } if (!Directory.Exists(SavesStorageLocation.Path)) Directory.CreateDirectory(SavesStorageLocation.Path); if (!Directory.Exists(MediaStorageLocation.Path)) Directory.CreateDirectory(MediaStorageLocation.Path); valid = true; } catch (Exception ex) { Logger?.LogError(ex, $"Error validating path"); MessageService.Error($"Error validating path: {ex.Message}", 10); } if (valid) NavigationManager.NavigateTo("/FirstTimeSetup/Metadata"); } void SetDefault(StorageLocation storageLocation) { foreach (var archiveStorageLocation in ArchiveStorageLocations) { archiveStorageLocation.Default = archiveStorageLocation.Id == storageLocation.Id; } } void OnPathSelected(StorageLocation storageLocation, string path) { var appPath = Directory.GetCurrentDirectory(); if (path != null && path.StartsWith(appPath)) path = path.Substring(appPath.Length).TrimStart(Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar); storageLocation.Path = path; } void AddArchiveStorageLocation() { ArchiveStorageLocations.Add(new StorageLocation()); StateHasChanged(); } void RemoveArchiveStorageLocation(StorageLocation storageLocation) { ArchiveStorageLocations.Remove(storageLocation); } }