From dc132898f87331d35a4084181172ed248ee2e327 Mon Sep 17 00:00:00 2001 From: Francesco Bertolaccini Date: Thu, 28 Jan 2016 08:25:59 +0100 Subject: [PATCH] Added documentation --- SharpPhysFS/Interop.cs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/SharpPhysFS/Interop.cs b/SharpPhysFS/Interop.cs index b3c59bf..840e505 100644 --- a/SharpPhysFS/Interop.cs +++ b/SharpPhysFS/Interop.cs @@ -186,29 +186,38 @@ namespace PhysFS public static void SetUpInterop() { + /* This method is used to dynamically load the physfs + * library. It works by detecting the current platform + * and deciding whether to use LoadLibrary/GetProcAddr + * on Windows or dlopen/dlsym on Linux and OSX. + * The the class is then scanned using reflection + * to populate all the callbacks with the right function + * pointers from the loaded library + */ + Func loadLibrary; Func loadSymbol; + string libraryName; IntPtr library; if (Environment.OSVersion.Platform == PlatformID.Win32NT) { loadLibrary = DynamicLoader.LoadLibrary; - loadSymbol = DynamicLoader.GetProcAddress; - - library = loadLibrary("physfs.dll"); + libraryName = "physfs.dll"; } else { - loadLibrary = n => - { - return DynamicLoader.dlopen(n, 1); - }; - + loadLibrary = n => DynamicLoader.dlopen(n, 1); loadSymbol = DynamicLoader.dlsym; + libraryName = "physfs.so"; + } - library = loadLibrary("physfs.so"); + library = loadLibrary(libraryName); + if (library == IntPtr.Zero) + { + throw new PhysFSLibNotFound(); } var fields = typeof(Interop).GetFields();