Skip to content

Commit

Permalink
misc: add warning for windows users
Browse files Browse the repository at this point in the history
- Add a warning for windows users that they need to enable dev mode to
  be allowed to create sym links, along with a link for how to enable
  it. Also, this warning is only shown if we fail the test to create a
  sym link at start up.

- Disable the VFS by default if we cannot create sym links.
  • Loading branch information
revam committed Apr 13, 2024
1 parent 20121a4 commit 6dfefee
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Shokofin/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public class PluginConfiguration : BasePluginConfiguration
{
#region Connection

/// <summary>
/// Helper for the web ui to show the windows only warning, and to disable
/// the VFS by default if we cannot create symbolic links.
/// </summary>
[XmlIgnore, JsonInclude]
public bool CanCreateSymbolicLinks => Plugin.Instance.CanCreateSymbolicLinks;

/// <summary>
/// The URL for where to connect to shoko internally.
/// And externally if no <seealso cref="PublicUrl"/> is set.
Expand Down Expand Up @@ -293,7 +300,7 @@ public PluginConfiguration()
TitleAllowAny = false;
DescriptionSourceList = new[] { TextSourceType.AniDb, TextSourceType.TvDb, TextSourceType.TMDB };
DescriptionSourceOrder = new[] { TextSourceType.AniDb, TextSourceType.TvDb, TextSourceType.TMDB };
VirtualFileSystem = true;
VirtualFileSystem = CanCreateSymbolicLinks;
VirtualFileSystemThreads = 10;
UseGroupsForShows = false;
SeparateMovies = false;
Expand Down
4 changes: 4 additions & 0 deletions Shokofin/Configuration/configController.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,10 @@ export default function (page) {
else {
form.querySelector("#ServerVersion").value = "Version N/A";
}
if (!config.CanCreateSymbolicLinks) {
form.querySelector("#WindowsSymLinkWarning1").removeAttribute("hidden");
form.querySelector("#WindowsSymLinkWarning2").removeAttribute("hidden");
}
if (config.ApiKey) {
form.querySelector("#Url").setAttribute("disabled", "");
form.querySelector("#Username").setAttribute("disabled", "");
Expand Down
2 changes: 2 additions & 0 deletions Shokofin/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ <h3>Media Folder Settings</h3>
</label>
<div class="fieldDescription checkboxFieldDescription">
<div>Enables the use of the Virtual File System&trade; for any new media libraries managed by the plugin.</div>
<div id="WindowsSymLinkWarning1" hidden><strong>Warning</strong>: Windows users are required to <a href="https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging#use-regedit-to-enable-your-device" target="_blank" rel="noopener noreferrer">enable Developer Mode</a> to be able to create symbolic links, a feature <strong>required</strong> to use the VFS.</div>
<details style="margin-top: 0.5em">
<summary style="margin-bottom: 0.25em">What does this mean?</summary>
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.
Expand Down Expand Up @@ -272,6 +273,7 @@ <h3>Media Folder Settings</h3>
</label>
<div class="fieldDescription checkboxFieldDescription">
<div>Enables the use of the Virtual File System&trade; for the library.</div>
<div id="WindowsSymLinkWarning2" hidden><strong>Warning</strong>: Windows users are required to <a href="https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging#use-regedit-to-enable-your-device" target="_blank" rel="noopener noreferrer">enable Developer Mode</a> to be able to create symbolic links, a feature <strong>required</strong> to use the VFS.</div>
<details style="margin-top: 0.5em">
<summary style="margin-bottom: 0.25em">What does this mean?</summary>
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.
Expand Down
26 changes: 25 additions & 1 deletion Shokofin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +20,8 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages

public override Guid Id => Guid.Parse("5216ccbf-d24a-4eb3-8a7e-7da4230b7052");

public readonly bool CanCreateSymbolicLinks;

private readonly ILogger<Plugin> Logger;

/// <summary>
Expand All @@ -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)
Expand Down

0 comments on commit 6dfefee

Please sign in to comment.