2020-09-01 11:54:16 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2020-08-30 14:22:41 +01:00
|
|
|
namespace RomRepoMgr.Core.Filesystem
|
|
|
|
|
{
|
2020-09-01 11:54:16 +01:00
|
|
|
public class Vfs : IDisposable
|
2020-08-30 14:22:41 +01:00
|
|
|
{
|
2020-09-02 16:53:21 +01:00
|
|
|
Fuse _fuse;
|
|
|
|
|
Winfsp _winfsp;
|
2020-09-01 11:54:16 +01:00
|
|
|
|
2020-08-30 14:22:41 +01:00
|
|
|
public static bool IsAvailable => Winfsp.IsAvailable || Fuse.IsAvailable;
|
2020-09-01 11:54:16 +01:00
|
|
|
|
|
|
|
|
public void Dispose() => _fuse?.Dispose();
|
|
|
|
|
|
|
|
|
|
public event EventHandler<System.EventArgs> Umounted;
|
|
|
|
|
|
2020-09-02 16:53:21 +01:00
|
|
|
public void MountTo(string mountPoint)
|
2020-09-01 11:54:16 +01:00
|
|
|
{
|
|
|
|
|
if(Fuse.IsAvailable)
|
|
|
|
|
{
|
|
|
|
|
_fuse = new Fuse
|
|
|
|
|
{
|
2020-09-02 16:53:21 +01:00
|
|
|
MountPoint = mountPoint
|
2020-09-01 11:54:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
_fuse.Start();
|
|
|
|
|
|
|
|
|
|
Umounted?.Invoke(this, System.EventArgs.Empty);
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-09-02 16:53:21 +01:00
|
|
|
else if(Winfsp.IsAvailable)
|
|
|
|
|
{
|
|
|
|
|
_winfsp = new Winfsp();
|
|
|
|
|
bool ret = _winfsp.Mount(mountPoint);
|
|
|
|
|
|
|
|
|
|
if(ret)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_winfsp = null;
|
|
|
|
|
Umounted?.Invoke(this, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Umounted?.Invoke(this, System.EventArgs.Empty);
|
2020-09-01 11:54:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Umount()
|
|
|
|
|
{
|
|
|
|
|
_fuse?.Umount();
|
|
|
|
|
_fuse = null;
|
2020-09-02 16:53:21 +01:00
|
|
|
_winfsp?.Umount();
|
|
|
|
|
_winfsp = null;
|
|
|
|
|
|
|
|
|
|
Umounted?.Invoke(this, System.EventArgs.Empty);
|
2020-09-01 11:54:16 +01:00
|
|
|
}
|
2020-08-30 14:22:41 +01:00
|
|
|
}
|
|
|
|
|
}
|