Enables the use of the Virtual File System™ for any new media libraries managed by the plugin.
+
Warning: Windows users are required to
enable Developer Mode to be able to create symbolic links, a feature
required to use the VFS.
What does this mean?
Enabling this setting should in theory make it so you won't have to think about file structure incompatibilities, since it will override your existing file structure and replace it with a layer of symbolic links managed by the plugin instead of your actual file structure.
@@ -272,6 +273,7 @@ Media Folder Settings
Enables the use of the Virtual File System™ for the library.
+
Warning: Windows users are required to
enable Developer Mode to be able to create symbolic links, a feature
required to use the VFS.
What does this mean?
Enabling this setting should in theory make it so you won't have to think about file structure incompatibilities, since it will override your existing file structure and replace it with a layer of symbolic links managed by the plugin instead of your actual file structure.
diff --git a/Shokofin/Plugin.cs b/Shokofin/Plugin.cs
index 4f9cfe1f..472b0cf1 100644
--- a/Shokofin/Plugin.cs
+++ b/Shokofin/Plugin.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Runtime.InteropServices;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
@@ -19,6 +20,8 @@ public class Plugin : BasePlugin, IHasWebPages
public override Guid Id => Guid.Parse("5216ccbf-d24a-4eb3-8a7e-7da4230b7052");
+ public readonly bool CanCreateSymbolicLinks;
+
private readonly ILogger Logger;
///
@@ -33,7 +36,28 @@ public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer,
IgnoredFolders = Configuration.IgnoredFolders.ToHashSet();
VirtualRoot = Path.Combine(applicationPaths.ProgramDataPath, "Shokofin", "VFS");
Logger = logger;
- Logger.LogInformation("Virtual File System Location; {Path}", VirtualRoot);
+ CanCreateSymbolicLinks = true;
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
+ var target = Path.Combine(Path.GetDirectoryName(VirtualRoot)!, "TestTarget.txt");
+ var link = Path.Combine(Path.GetDirectoryName(VirtualRoot)!, "TestLink.txt");
+ try {
+ if (!Directory.Exists(Path.GetDirectoryName(VirtualRoot)!))
+ Directory.CreateDirectory(Path.GetDirectoryName(VirtualRoot)!);
+ File.Create(target);
+ File.CreateSymbolicLink(link, target);
+ }
+ catch {
+ CanCreateSymbolicLinks = false;
+ }
+ finally {
+ if (File.Exists(link))
+ File.Delete(link);
+ if (File.Exists(target))
+ File.Delete(target);
+ }
+ }
+ Logger.LogDebug("Virtual File System Location; {Path}", VirtualRoot);
+ Logger.LogDebug("Can create symbolic links; {Value}", CanCreateSymbolicLinks);
}
public void OnConfigChanged(object? sender, BasePluginConfiguration e)