Added documentation

pull/2/head
Francesco Bertolaccini 2016-01-28 08:25:59 +01:00
parent 5f1ee154a5
commit dc132898f8
1 changed files with 18 additions and 9 deletions

View File

@ -186,29 +186,38 @@ namespace PhysFS
public static void SetUpInterop() 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<string, IntPtr> loadLibrary; Func<string, IntPtr> loadLibrary;
Func<IntPtr, string, IntPtr> loadSymbol; Func<IntPtr, string, IntPtr> loadSymbol;
string libraryName;
IntPtr library; IntPtr library;
if (Environment.OSVersion.Platform == PlatformID.Win32NT) if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{ {
loadLibrary = DynamicLoader.LoadLibrary; loadLibrary = DynamicLoader.LoadLibrary;
loadSymbol = DynamicLoader.GetProcAddress; loadSymbol = DynamicLoader.GetProcAddress;
libraryName = "physfs.dll";
library = loadLibrary("physfs.dll");
} }
else else
{ {
loadLibrary = n => loadLibrary = n => DynamicLoader.dlopen(n, 1);
{
return DynamicLoader.dlopen(n, 1);
};
loadSymbol = DynamicLoader.dlsym; 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(); var fields = typeof(Interop).GetFields();