diff --git a/Shokofin/Configuration/MediaFolderConfigurationService.cs b/Shokofin/Configuration/MediaFolderConfigurationService.cs index 3e3ed887..2718b6d4 100644 --- a/Shokofin/Configuration/MediaFolderConfigurationService.cs +++ b/Shokofin/Configuration/MediaFolderConfigurationService.cs @@ -337,14 +337,9 @@ private async Task GenerateAllConfigurations(List allVirtualF edits.add.Add(vfsPath); } - var virtualRoots = new string[] { - Plugin.Instance.VirtualRoot_Default, - Plugin.Instance.VirtualRoot_Cache, - Plugin.Instance.VirtualRoot_Custom ?? string.Empty, - }.Where(s => !string.IsNullOrEmpty(s)).ToArray(); var toRemove = virtualFolder.Locations .Except(shouldAttach ? [vfsPath] : []) - .Where(location => virtualRoots.Any(virtualRoot => location.StartsWith(virtualRoot, Path.DirectorySeparatorChar is '\\' ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))) + .Where(location => Plugin.Instance.AllVirtualRoots.Any(virtualRoot => location.StartsWith(virtualRoot, Path.DirectorySeparatorChar is '\\' ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))) .ToList(); if (toRemove.Count > 0) { if (!LibraryEdits.TryGetValue(libraryId, out var edits)) diff --git a/Shokofin/Plugin.cs b/Shokofin/Plugin.cs index fde8d593..ff0dbd95 100644 --- a/Shokofin/Plugin.cs +++ b/Shokofin/Plugin.cs @@ -144,11 +144,25 @@ public string VirtualRoot } } - public string VirtualRoot_Default => Path.Join(ApplicationPaths.ProgramDataPath, Name); - - public string VirtualRoot_Cache => Path.Join(ApplicationPaths.CachePath, Name); + private string[]? _allVirtualRoots; - public string? VirtualRoot_Custom => string.IsNullOrWhiteSpace(Configuration.VFS_CustomLocation) ? null : Path.Combine(ApplicationPaths.ProgramDataPath, Configuration.VFS_CustomLocation); + /// + /// All "Virtual" File System Root Directories. + /// + public string[] AllVirtualRoots => _allVirtualRoots ??= (new string[] { + VirtualRoot_Default, + VirtualRoot_Cache, + VirtualRoot_Custom ?? string.Empty + }) + .Except([string.Empty]) + .Distinct() + .ToArray(); + + private string VirtualRoot_Default => Path.Join(ApplicationPaths.ProgramDataPath, Name); + + private string VirtualRoot_Cache => Path.Join(ApplicationPaths.CachePath, Name); + + private string? VirtualRoot_Custom => string.IsNullOrWhiteSpace(Configuration.VFS_CustomLocation) ? null : Path.Combine(ApplicationPaths.ProgramDataPath, Configuration.VFS_CustomLocation); /// /// Gets or sets the event handler that is triggered when this configuration changes. @@ -218,6 +232,7 @@ public void OnConfigChanged(object? sender, BasePluginConfiguration e) // Reset the cached VFS root directory in case it has changed. _virtualRoot = null; + _allVirtualRoots = null; ConfigurationChanged?.Invoke(sender, config); } diff --git a/Shokofin/Tasks/CleanupVirtualRootTask.cs b/Shokofin/Tasks/CleanupVirtualRootTask.cs index b73e6900..43f61538 100644 --- a/Shokofin/Tasks/CleanupVirtualRootTask.cs +++ b/Shokofin/Tasks/CleanupVirtualRootTask.cs @@ -56,12 +56,7 @@ public Task ExecuteAsync(IProgress progress, CancellationToken cancellat return Task.CompletedTask; var start = DateTime.Now; - var virtualRoots = new string[] { - Plugin.Instance.VirtualRoot_Default, - Plugin.Instance.VirtualRoot_Cache, - Plugin.Instance.VirtualRoot_Custom ?? string.Empty, - } - .Except([Plugin.Instance.VirtualRoot, string.Empty]) + var virtualRoots = Plugin.Instance.AllVirtualRoots .Where(Directory.Exists) .ToList(); Logger.LogDebug("Found {RemoveCount} VFS roots to remove.", virtualRoots.Count);