Files
romrepomgr/RomRepoMgr.Core/Filesystem/Vfs.cs

58 lines
1.4 KiB
C#
Raw Normal View History

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
{
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;
public void MountTo(string mountPoint)
2020-09-01 11:54:16 +01:00
{
if(Fuse.IsAvailable)
{
_fuse = new Fuse
{
MountPoint = mountPoint
2020-09-01 11:54:16 +01:00
};
Task.Run(() =>
{
_fuse.Start();
Umounted?.Invoke(this, System.EventArgs.Empty);
});
}
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;
_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
}
}