mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-17 22:43:07 +03:00
safer shortcut migration
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using MediaBrowser.Common.Constants;
|
||||
using MediaBrowser.Common.Implementations.Logging;
|
||||
using MediaBrowser.Common.Implementations.Updates;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Server.Implementations;
|
||||
using MediaBrowser.ServerApplication.Native;
|
||||
@@ -187,6 +188,8 @@ namespace MediaBrowser.ServerApplication
|
||||
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
|
||||
SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
|
||||
|
||||
MigrateShortcuts(appPaths.RootFolderPath);
|
||||
|
||||
_appHost = new ApplicationHost(appPaths, logManager);
|
||||
|
||||
_app = new App(_appHost, _appHost.LogManager.GetLogger("App"), runService);
|
||||
@@ -523,5 +526,34 @@ namespace MediaBrowser.ServerApplication
|
||||
/// </summary>
|
||||
SEM_NOOPENFILEERRORBOX = 0x8000
|
||||
}
|
||||
|
||||
private static void MigrateShortcuts(string directory)
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
foreach (var file in Directory.EnumerateFiles(directory, "*.lnk", SearchOption.AllDirectories).ToList())
|
||||
{
|
||||
MigrateShortcut(file);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MigrateShortcut(string file)
|
||||
{
|
||||
var newFile = Path.ChangeExtension(file, ".mblink");
|
||||
|
||||
try
|
||||
{
|
||||
var resolvedPath = FileSystem.ResolveShortcut(file);
|
||||
|
||||
if (!string.IsNullOrEmpty(resolvedPath))
|
||||
{
|
||||
FileSystem.CreateShortcut(newFile, resolvedPath);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user