From 16c6d1c0b52b60121f10d1ff411e5f6b7105086a Mon Sep 17 00:00:00 2001 From: Salvage <29021710+Saalvage@users.noreply.github.com> Date: Fri, 29 Nov 2024 19:55:41 +0100 Subject: [PATCH] Hardcode our chosen binary name format --- AssimpNet/Unmanaged/AssimpLibrary.cs | 29 ++++++---------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/AssimpNet/Unmanaged/AssimpLibrary.cs b/AssimpNet/Unmanaged/AssimpLibrary.cs index 396e84d..51454bb 100755 --- a/AssimpNet/Unmanaged/AssimpLibrary.cs +++ b/AssimpNet/Unmanaged/AssimpLibrary.cs @@ -76,33 +76,16 @@ static AssimpLibrary() Platform.Mac => "macos", } + '-' + RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); - static IntPtr TryLoadLibraryVariations(string dir, string lib) + var binaryFile = GetPlatform() switch { - // This is not strictly equivalent to the built-in order, but it's good enough. - var ext = GetPlatform() switch - { - Platform.Windows => "dll", - Platform.Linux => "so", - Platform.Mac => "dylib", - }; - - foreach (var path in (Span) - [ - $"{dir}{lib}.{ext}", - $"{dir}lib{lib}.{ext}", - $"{dir}{lib}", - $"{dir}lib{lib}", - ]) { - if (NativeLibrary.TryLoad(path, out var handle)) - return handle; - } - - return IntPtr.Zero; - } + Platform.Windows => $"{DefaultLibName}.dll", + Platform.Linux => $"lib{DefaultLibName}.so", + Platform.Mac => $"lib{DefaultLibName}.dylib", + }; NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), (libraryName, _, _) => { if (libraryName == DefaultLibName) - return TryLoadLibraryVariations($"{AppContext.BaseDirectory}runtimes/{rid}/native/", DefaultLibName); + return NativeLibrary.Load($"{AppContext.BaseDirectory}runtimes/{rid}/native/{binaryFile}"); return IntPtr.Zero; });