From c39ebc5bca048c29bf720e52be13d2a20cba2512 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 21 Dec 2020 01:37:00 +0000 Subject: [PATCH] Update winfsp-netcore to .NET 5. --- RomRepoMgr.Core/Filesystem/Fuse.cs | 3 +++ RomRepoMgr.Core/Filesystem/Vfs.cs | 27 ++++++++++++++++--------- RomRepoMgr.Core/Filesystem/Winfsp.cs | 2 ++ RomRepoMgr.Settings/Interop/DetectOS.cs | 2 +- RomRepoMgr.Settings/Settings.cs | 20 +++++++++--------- winfsp-netcore/winfsp-netcore.csproj | 2 +- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/RomRepoMgr.Core/Filesystem/Fuse.cs b/RomRepoMgr.Core/Filesystem/Fuse.cs index 45c910e..d20243d 100644 --- a/RomRepoMgr.Core/Filesystem/Fuse.cs +++ b/RomRepoMgr.Core/Filesystem/Fuse.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Text; using Mono.Fuse.NETStandard; using Mono.Unix.Native; @@ -12,6 +13,8 @@ using RomRepoMgr.Database.Models; namespace RomRepoMgr.Core.Filesystem { // TODO: Last handle goes negative + [SupportedOSPlatform("Linux")] + [SupportedOSPlatform("macOS")] public sealed class Fuse : FileSystem { readonly ConcurrentDictionary> _directoryCache; diff --git a/RomRepoMgr.Core/Filesystem/Vfs.cs b/RomRepoMgr.Core/Filesystem/Vfs.cs index 26ccf42..db04249 100644 --- a/RomRepoMgr.Core/Filesystem/Vfs.cs +++ b/RomRepoMgr.Core/Filesystem/Vfs.cs @@ -41,7 +41,9 @@ namespace RomRepoMgr.Core.Filesystem _lastHandle = 0; } - public static bool IsAvailable => Winfsp.IsAvailable || Fuse.IsAvailable; + public static bool IsAvailable => OperatingSystem.IsMacOS() || + OperatingSystem.IsLinux() ? Fuse.IsAvailable + : OperatingSystem.IsWindows() && Winfsp.IsAvailable; public void Dispose() => Umount(); @@ -49,7 +51,7 @@ namespace RomRepoMgr.Core.Filesystem public void MountTo(string mountPoint) { - if(Fuse.IsAvailable) + if((OperatingSystem.IsMacOS() || OperatingSystem.IsLinux()) && Fuse.IsAvailable) { _fuse = new Fuse(this) { @@ -63,7 +65,7 @@ namespace RomRepoMgr.Core.Filesystem CleanUp(); }); } - else if(Winfsp.IsAvailable) + else if(OperatingSystem.IsWindows() && Winfsp.IsAvailable) { _winfsp = new Winfsp(this); bool ret = _winfsp.Mount(mountPoint); @@ -80,10 +82,17 @@ namespace RomRepoMgr.Core.Filesystem public void Umount() { - _fuse?.Umount(); - _fuse = null; - _winfsp?.Umount(); - _winfsp = null; + if(OperatingSystem.IsMacOS() || OperatingSystem.IsLinux()) + { + _fuse?.Umount(); + _fuse = null; + } + + if(OperatingSystem.IsWindows()) + { + _winfsp?.Umount(); + _winfsp = null; + } CleanUp(); } @@ -112,7 +121,7 @@ namespace RomRepoMgr.Core.Filesystem } internal string[] SplitPath(string path) => - path.Split(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "\\" : "/", + path.Split(OperatingSystem.IsWindows() ? "\\" : "/", StringSplitOptions.RemoveEmptyEntries); void FillRootDirectoryCache() @@ -125,7 +134,7 @@ namespace RomRepoMgr.Core.Filesystem { string name; - if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if(OperatingSystem.IsWindows()) { name = set.Name.Replace('/', '∕').Replace('<', '\uFF1C').Replace('>', '\uFF1E'). Replace(':', '\uFF1A').Replace('"', '\u2033').Replace('\\', '\').Replace('|', '|'). diff --git a/RomRepoMgr.Core/Filesystem/Winfsp.cs b/RomRepoMgr.Core/Filesystem/Winfsp.cs index 69e38bf..b91b29f 100644 --- a/RomRepoMgr.Core/Filesystem/Winfsp.cs +++ b/RomRepoMgr.Core/Filesystem/Winfsp.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Security.AccessControl; using Fsp; using Fsp.Interop; @@ -12,6 +13,7 @@ using FileInfo = Fsp.Interop.FileInfo; namespace RomRepoMgr.Core.Filesystem { + [SupportedOSPlatform("windows")] public class Winfsp : FileSystemBase { readonly Vfs _vfs; diff --git a/RomRepoMgr.Settings/Interop/DetectOS.cs b/RomRepoMgr.Settings/Interop/DetectOS.cs index 8ac71bb..95180dd 100644 --- a/RomRepoMgr.Settings/Interop/DetectOS.cs +++ b/RomRepoMgr.Settings/Interop/DetectOS.cs @@ -73,7 +73,7 @@ namespace Aaru.CommonTypes.Interop { get { - if(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if(!OperatingSystem.IsWindows()) return Environment.UserName == "root"; bool isAdmin; diff --git a/RomRepoMgr.Settings/Settings.cs b/RomRepoMgr.Settings/Settings.cs index 93b6373..17e72cf 100644 --- a/RomRepoMgr.Settings/Settings.cs +++ b/RomRepoMgr.Settings/Settings.cs @@ -116,11 +116,11 @@ namespace RomRepoMgr.Settings #if !NETSTANDARD2_0 // In case of Windows settings will be saved in the registry: HKLM/SOFTWARE/Claunia.com/RomRepoMgr - case PlatformID.Win32NT when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): - case PlatformID.Win32S when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): - case PlatformID.Win32Windows when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): - case PlatformID.WinCE when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): - case PlatformID.WindowsPhone when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): + case PlatformID.Win32NT when OperatingSystem.IsWindows(): + case PlatformID.Win32S when OperatingSystem.IsWindows(): + case PlatformID.Win32Windows when OperatingSystem.IsWindows(): + case PlatformID.WinCE when OperatingSystem.IsWindows(): + case PlatformID.WindowsPhone when OperatingSystem.IsWindows(): { RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE")?.OpenSubKey("Claunia.com"); @@ -235,11 +235,11 @@ namespace RomRepoMgr.Settings #if !NETSTANDARD2_0 // In case of Windows settings will be saved in the registry: HKLM/SOFTWARE/Claunia.com/RomRepoMgr - case PlatformID.Win32NT when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): - case PlatformID.Win32S when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): - case PlatformID.Win32Windows when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): - case PlatformID.WinCE when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): - case PlatformID.WindowsPhone when RuntimeInformation.IsOSPlatform(OSPlatform.Windows): + case PlatformID.Win32NT when OperatingSystem.IsWindows(): + case PlatformID.Win32S when OperatingSystem.IsWindows(): + case PlatformID.Win32Windows when OperatingSystem.IsWindows(): + case PlatformID.WinCE when OperatingSystem.IsWindows(): + case PlatformID.WindowsPhone when OperatingSystem.IsWindows(): { RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true)?. CreateSubKey("Claunia.com"); diff --git a/winfsp-netcore/winfsp-netcore.csproj b/winfsp-netcore/winfsp-netcore.csproj index fe74805..f2e7e4c 100644 --- a/winfsp-netcore/winfsp-netcore.csproj +++ b/winfsp-netcore/winfsp-netcore.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 winfsp_netcore