mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-21 06:45:32 -06:00
53 lines
No EOL
1.5 KiB
C#
53 lines
No EOL
1.5 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using NetNativeLibLoader.PathResolver;
|
|
|
|
namespace Qml.Net.Internal
|
|
{
|
|
public class LinuxDllImportLibraryPathResolver : IPathResolver
|
|
{
|
|
IPathResolver _original;
|
|
|
|
public LinuxDllImportLibraryPathResolver(IPathResolver original)
|
|
{
|
|
_original = original;
|
|
}
|
|
|
|
public ResolvePathResult Resolve(string library)
|
|
{
|
|
var result = _original.Resolve(library);
|
|
|
|
if(!result.IsSuccess && library == "QmlNet")
|
|
{
|
|
// Try to let .NET load the library.
|
|
try
|
|
{
|
|
qml_net_getVersion();
|
|
|
|
using (var currentProcess = Process.GetCurrentProcess())
|
|
{
|
|
foreach (ProcessModule module in currentProcess.Modules)
|
|
{
|
|
if (Path.GetFileNameWithoutExtension(module.FileName) == "libQmlNet")
|
|
{
|
|
return ResolvePathResult.FromSuccess(module.FileName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// ReSharper disable EmptyGeneralCatchClause
|
|
catch (Exception)
|
|
// ReSharper restore EmptyGeneralCatchClause
|
|
{
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
[DllImport("libQmlNet.so")]
|
|
static extern long qml_net_getVersion();
|
|
}
|
|
} |