Detect if FUSE is available before allowing to use it for VFS.

This commit is contained in:
2020-08-29 18:23:53 +01:00
parent ddc974a610
commit 8e3b5fee6a
3 changed files with 44 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Mono.Fuse.NETStandard;
using Mono.Unix.Native;
using RomRepoMgr.Database;
@@ -40,6 +41,46 @@ namespace RomRepoMgr.Core.Filesystem
Name = "romrepombgrfs";
}
public static bool IsAvailable
{
get
{
try
{
IntPtr fuse = dlopen("libfuse.so.2", 2);
if(fuse == IntPtr.Zero)
return false;
dlclose(fuse);
IntPtr helper = dlopen("libMonoFuseHelper.so", 2);
if(helper == IntPtr.Zero)
{
helper = dlopen("./libMonoFuseHelper.so", 2);
if(helper == IntPtr.Zero)
return false;
}
dlclose(helper);
return true;
}
catch(Exception e)
{
return false;
}
}
}
[DllImport("libdl")]
static extern IntPtr dlopen(string filename, int flags);
[DllImport("libdl")]
static extern int dlclose(IntPtr handle);
protected override void Dispose(bool disposing)
{
if(!disposing)

View File

@@ -101,6 +101,8 @@ namespace RomRepoMgr.ViewModels
set => this.RaiseAndSetIfChanged(ref _selectedRomSet, value);
}
public bool IsVfsAvailable => Fuse.IsAvailable;
internal async void ExecuteSettingsCommand()
{
var dialog = new SettingsDialog();
@@ -288,9 +290,6 @@ namespace RomRepoMgr.ViewModels
async void ExecuteMountCommand()
{
// TODO: Detect if Windows or *NIX
// TODO: Detect if libraries are available
var dlgOpen = new OpenFolderDialog
{
Title = "Select mount point..."

View File

@@ -16,7 +16,7 @@
<Separator />
<MenuItem Header="E_xit" IsVisible="{Binding !NativeMenuSupported}" Command="{Binding ExitCommand}" />
</MenuItem>
<MenuItem Header="File_system">
<MenuItem Header="File_system" IsEnabled="{Binding IsVfsAvailable}">
<MenuItem Header="_Mount" Command="{Binding MountCommand}" /> <Separator />
</MenuItem>
<MenuItem Header="_ROMs">