mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Allow to umount VFS.
This commit is contained in:
@@ -27,6 +27,7 @@ namespace RomRepoMgr.Core.Filesystem
|
|||||||
readonly ConcurrentDictionary<long, Stream> _streamsCache;
|
readonly ConcurrentDictionary<long, Stream> _streamsCache;
|
||||||
long _lastHandle;
|
long _lastHandle;
|
||||||
ConcurrentDictionary<string, long> _rootDirectoryCache;
|
ConcurrentDictionary<string, long> _rootDirectoryCache;
|
||||||
|
string _umountToken;
|
||||||
|
|
||||||
public Fuse()
|
public Fuse()
|
||||||
{
|
{
|
||||||
@@ -107,7 +108,27 @@ namespace RomRepoMgr.Core.Filesystem
|
|||||||
FillRootDirectoryCache();
|
FillRootDirectoryCache();
|
||||||
|
|
||||||
if(!_rootDirectoryCache.TryGetValue(pieces[0], out long romSetId))
|
if(!_rootDirectoryCache.TryGetValue(pieces[0], out long romSetId))
|
||||||
|
{
|
||||||
|
if(pieces[0] == ".fuse_umount" &&
|
||||||
|
_umountToken != null)
|
||||||
|
{
|
||||||
|
stat = new Stat
|
||||||
|
{
|
||||||
|
st_mode = FilePermissions.S_IFREG | NativeConvert.FromOctalPermissionString("0444"),
|
||||||
|
st_nlink = 1,
|
||||||
|
st_ctime = NativeConvert.ToTimeT(DateTime.UtcNow),
|
||||||
|
st_mtime = NativeConvert.ToTimeT(DateTime.UtcNow),
|
||||||
|
st_blksize = 0,
|
||||||
|
st_blocks = 0,
|
||||||
|
st_ino = 0,
|
||||||
|
st_size = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return Errno.ENOENT;
|
return Errno.ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
if(!_romSetsCache.TryGetValue(romSetId, out RomSet romSet))
|
if(!_romSetsCache.TryGetValue(romSetId, out RomSet romSet))
|
||||||
{
|
{
|
||||||
@@ -472,8 +493,25 @@ namespace RomRepoMgr.Core.Filesystem
|
|||||||
protected override Errno OnSynchronizeHandle(string file, OpenedPathInfo info, bool onlyUserData) =>
|
protected override Errno OnSynchronizeHandle(string file, OpenedPathInfo info, bool onlyUserData) =>
|
||||||
Errno.EOPNOTSUPP;
|
Errno.EOPNOTSUPP;
|
||||||
|
|
||||||
protected override Errno OnSetPathExtendedAttribute(string path, string name, byte[] value, XattrFlags flags) =>
|
protected override Errno OnSetPathExtendedAttribute(string path, string name, byte[] value, XattrFlags flags)
|
||||||
Errno.EROFS;
|
{
|
||||||
|
if(_umountToken == null)
|
||||||
|
return Errno.EROFS;
|
||||||
|
|
||||||
|
if(path != "/.fuse_umount")
|
||||||
|
return Errno.EROFS;
|
||||||
|
|
||||||
|
if(name != _umountToken)
|
||||||
|
return Errno.EROFS;
|
||||||
|
|
||||||
|
if(value?.Length != 0)
|
||||||
|
return Errno.EROFS;
|
||||||
|
|
||||||
|
_umountToken = null;
|
||||||
|
Stop();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
protected override Errno OnGetPathExtendedAttribute(string path, string name, byte[] value,
|
protected override Errno OnGetPathExtendedAttribute(string path, string name, byte[] value,
|
||||||
out int bytesWritten)
|
out int bytesWritten)
|
||||||
@@ -1155,6 +1193,18 @@ namespace RomRepoMgr.Core.Filesystem
|
|||||||
return Errno.EOPNOTSUPP;
|
return Errno.EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("libc", SetLastError = true)]
|
||||||
|
static extern int setxattr(string path, string name, IntPtr value, long size, int flags);
|
||||||
|
|
||||||
|
public void Umount()
|
||||||
|
{
|
||||||
|
var rnd = new Random();
|
||||||
|
byte[] token = new byte[64];
|
||||||
|
rnd.NextBytes(token);
|
||||||
|
_umountToken = Base32.ToBase32String(token);
|
||||||
|
setxattr(Path.Combine(MountPoint, ".fuse_umount"), _umountToken, IntPtr.Zero, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
sealed class CachedMachine
|
sealed class CachedMachine
|
||||||
{
|
{
|
||||||
public ulong Id { get; set; }
|
public ulong Id { get; set; }
|
||||||
|
|||||||
@@ -1,7 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace RomRepoMgr.Core.Filesystem
|
namespace RomRepoMgr.Core.Filesystem
|
||||||
{
|
{
|
||||||
public class Vfs
|
public class Vfs : IDisposable
|
||||||
{
|
{
|
||||||
|
Fuse _fuse;
|
||||||
|
|
||||||
public static bool IsAvailable => Winfsp.IsAvailable || Fuse.IsAvailable;
|
public static bool IsAvailable => Winfsp.IsAvailable || Fuse.IsAvailable;
|
||||||
|
|
||||||
|
public void Dispose() => _fuse?.Dispose();
|
||||||
|
|
||||||
|
public event EventHandler<System.EventArgs> Umounted;
|
||||||
|
|
||||||
|
public void MountTo(string result)
|
||||||
|
{
|
||||||
|
if(Fuse.IsAvailable)
|
||||||
|
{
|
||||||
|
_fuse = new Fuse
|
||||||
|
{
|
||||||
|
MountPoint = result
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
_fuse.Start();
|
||||||
|
|
||||||
|
Umounted?.Invoke(this, System.EventArgs.Empty);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Umount()
|
||||||
|
{
|
||||||
|
_fuse?.Umount();
|
||||||
|
_fuse = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Aaru/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Aaru/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=datfiles/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=datfiles/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=dlclose/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=libdl/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=lsar/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=lsar/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=romrepo/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=romrepo/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=romrepombgrfs/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=romrepombgrfs/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=setxattr/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Umounted/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=unar/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=unar/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Winfsp/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Winfsp/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=xattr/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=xattr/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
|||||||
1519
RomRepoMgr/Resources/Localization.Designer.cs
generated
1519
RomRepoMgr/Resources/Localization.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@@ -340,4 +340,7 @@
|
|||||||
<data name="UnArPathLabel" xml:space="preserve">
|
<data name="UnArPathLabel" xml:space="preserve">
|
||||||
<value>Ruta a UnAr</value>
|
<value>Ruta a UnAr</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="FilesystemMenuUmountText" xml:space="preserve">
|
||||||
|
<value>_Desmontar</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -346,4 +346,7 @@ Do you want to delete the file?</value>
|
|||||||
<data name="ExitButtonText" xml:space="preserve">
|
<data name="ExitButtonText" xml:space="preserve">
|
||||||
<value>Exit</value>
|
<value>Exit</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="FilesystemMenuUmountText" xml:space="preserve">
|
||||||
|
<value>_Umount</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -23,8 +23,10 @@
|
|||||||
// Copyright © 2020 Natalia Portillo
|
// Copyright © 2020 Natalia Portillo
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
@@ -45,8 +47,8 @@ namespace RomRepoMgr.ViewModels
|
|||||||
public class MainWindowViewModel : ViewModelBase
|
public class MainWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
readonly MainWindow _view;
|
readonly MainWindow _view;
|
||||||
|
RomSetModel _selectedRomSet;
|
||||||
RomSetModel _selectedRomSet;
|
Vfs _vfs;
|
||||||
|
|
||||||
public MainWindowViewModel(MainWindow view, List<RomSetModel> romSets)
|
public MainWindowViewModel(MainWindow view, List<RomSetModel> romSets)
|
||||||
{
|
{
|
||||||
@@ -62,6 +64,7 @@ namespace RomRepoMgr.ViewModels
|
|||||||
ExportDatCommand = ReactiveCommand.Create(ExecuteExportDatCommand);
|
ExportDatCommand = ReactiveCommand.Create(ExecuteExportDatCommand);
|
||||||
ExportRomsCommand = ReactiveCommand.Create(ExecuteExportRomsCommand);
|
ExportRomsCommand = ReactiveCommand.Create(ExecuteExportRomsCommand);
|
||||||
MountCommand = ReactiveCommand.Create(ExecuteMountCommand);
|
MountCommand = ReactiveCommand.Create(ExecuteMountCommand);
|
||||||
|
UmountCommand = ReactiveCommand.Create(ExecuteUmountCommand);
|
||||||
RomSets = new ObservableCollection<RomSetModel>(romSets);
|
RomSets = new ObservableCollection<RomSetModel>(romSets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +99,7 @@ namespace RomRepoMgr.ViewModels
|
|||||||
public string RomSetsMenuDeleteText => Localization.RomSetsMenuDeleteText;
|
public string RomSetsMenuDeleteText => Localization.RomSetsMenuDeleteText;
|
||||||
public string HelpMenuText => Localization.HelpMenuText;
|
public string HelpMenuText => Localization.HelpMenuText;
|
||||||
public string HelpMenuAboutText => Localization.HelpMenuAboutText;
|
public string HelpMenuAboutText => Localization.HelpMenuAboutText;
|
||||||
|
public string FilesystemMenuUmountText => Localization.FilesystemMenuUmountText;
|
||||||
|
|
||||||
public bool NativeMenuSupported =>
|
public bool NativeMenuSupported =>
|
||||||
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
|
NativeMenu.GetIsNativeMenuExported((Application.Current.ApplicationLifetime as
|
||||||
@@ -112,6 +116,13 @@ namespace RomRepoMgr.ViewModels
|
|||||||
public ReactiveCommand<Unit, Unit> ExportDatCommand { get; }
|
public ReactiveCommand<Unit, Unit> ExportDatCommand { get; }
|
||||||
public ReactiveCommand<Unit, Unit> ExportRomsCommand { get; }
|
public ReactiveCommand<Unit, Unit> ExportRomsCommand { get; }
|
||||||
public ReactiveCommand<Unit, Unit> MountCommand { get; }
|
public ReactiveCommand<Unit, Unit> MountCommand { get; }
|
||||||
|
public ReactiveCommand<Unit, Unit> UmountCommand { get; }
|
||||||
|
|
||||||
|
public Vfs Vfs
|
||||||
|
{
|
||||||
|
get => _vfs;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _vfs, value);
|
||||||
|
}
|
||||||
|
|
||||||
public RomSetModel SelectedRomSet
|
public RomSetModel SelectedRomSet
|
||||||
{
|
{
|
||||||
@@ -304,6 +315,9 @@ namespace RomRepoMgr.ViewModels
|
|||||||
|
|
||||||
async void ExecuteMountCommand()
|
async void ExecuteMountCommand()
|
||||||
{
|
{
|
||||||
|
if(Vfs != null)
|
||||||
|
return;
|
||||||
|
|
||||||
var dlgOpen = new OpenFolderDialog
|
var dlgOpen = new OpenFolderDialog
|
||||||
{
|
{
|
||||||
Title = Localization.SelectMountPointDialogTitle
|
Title = Localization.SelectMountPointDialogTitle
|
||||||
@@ -314,12 +328,23 @@ namespace RomRepoMgr.ViewModels
|
|||||||
if(result == null)
|
if(result == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var fs = new Fuse
|
try
|
||||||
{
|
{
|
||||||
MountPoint = result
|
Vfs = new Vfs();
|
||||||
};
|
Vfs.Umounted += VfsOnUmounted;
|
||||||
|
Vfs.MountTo(result);
|
||||||
|
}
|
||||||
|
catch(Exception)
|
||||||
|
{
|
||||||
|
if(Debugger.IsAttached)
|
||||||
|
throw;
|
||||||
|
|
||||||
fs.Start();
|
Vfs = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VfsOnUmounted(object sender, EventArgs e) => Vfs = null;
|
||||||
|
|
||||||
|
void ExecuteUmountCommand() => Vfs?.Umount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,12 @@
|
|||||||
Command="{Binding ExitCommand}" />
|
Command="{Binding ExitCommand}" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="{Binding FilesystemMenuText}" IsEnabled="{Binding IsVfsAvailable}">
|
<MenuItem Header="{Binding FilesystemMenuText}" IsEnabled="{Binding IsVfsAvailable}">
|
||||||
<MenuItem Header="{Binding FilesystemMenuMountText}" Command="{Binding MountCommand}" /> <Separator />
|
<MenuItem Header="{Binding FilesystemMenuMountText}" Command="{Binding MountCommand}"
|
||||||
|
IsEnabled="{Binding Vfs, Converter={x:Static ObjectConverters.IsNull}}" />
|
||||||
|
<Separator />
|
||||||
|
<MenuItem Header="{Binding FilesystemMenuUmountText}" Command="{Binding UmountCommand}"
|
||||||
|
IsEnabled="{Binding Vfs, Converter={x:Static ObjectConverters.IsNotNull}}" />
|
||||||
|
<Separator />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="{Binding RomsMenuText}">
|
<MenuItem Header="{Binding RomsMenuText}">
|
||||||
<MenuItem Header="{Binding RomsMenuImportText}" Command="{Binding ImportRomFolderCommand}" />
|
<MenuItem Header="{Binding RomsMenuImportText}" Command="{Binding ImportRomFolderCommand}" />
|
||||||
|
|||||||
Reference in New Issue
Block a user