static IntPtr dlopen(string filename, int flags)
 {
     if (Platform.RunningOS == OS.Linux)
     {
         return(LinuxInterop.dlopen(filename, flags));
     }
     else
     {
         return(MacInterop.dlopen(filename, flags));
     }
 }
Esempio n. 2
0
        public static IntPtr LoadLibrary(string libName, string libraryPath)
        {
            var libHandler     = IntPtr.Zero;
            var libNameWithExt = string.Empty;

            if (string.IsNullOrEmpty(libName) || string.IsNullOrEmpty(libraryPath))
            {
                return(libHandler);
            }

            SetLibraryDirectory(libraryPath);

            var libraryFiles = Directory.GetFiles(libraryPath);

            foreach (var libraryFile in libraryFiles)
            {
                if (libraryFile.EndsWith(".meta"))
                {
                    continue;
                }

                var fileName = Path.GetFileName(libraryFile);

                if (fileName.StartsWith(libName + ".") && (string.IsNullOrEmpty(libNameWithExt) || fileName.Any(char.IsDigit)))
                {
                    libNameWithExt = fileName;
                }
            }

            switch (UMPSettings.RuntimePlatform)
            {
            case UMPSettings.Platforms.Win:
                libHandler = WindowsInterop.LoadLibrary(Path.Combine(libraryPath, libNameWithExt));
                break;

            case UMPSettings.Platforms.Mac:
                libHandler = MacInterop.dlopen(Path.Combine(libraryPath, libNameWithExt), LIN_RTLD_NOW);
                break;

            case UMPSettings.Platforms.Linux:
                libHandler = LinuxInterop.dlopen(Path.Combine(libraryPath, libNameWithExt), LIN_RTLD_NOW);
                break;
            }

            if (libHandler == IntPtr.Zero)
            {
                throw new Exception(string.Format("[LoadLibrary] Can't load '{0}' library", libName));
            }

            return(libHandler);
        }