public static void PreLoadLibrary(string baseName) { lock (NativeLibraryManager.q) { if (!NativeLibraryManager.R.ContainsKey(baseName)) { NativeLibraryManager.R.Add(baseName, 0); if (PlatformInfo.Platform == PlatformInfo.PlanformType.Windows) { baseName += ".dll"; } else if (PlatformInfo.Platform == PlatformInfo.PlanformType.MacOSX) { string path = Path.Combine(NativeLibraryManager.GetNativeLibrariesDirectory(), baseName + ".bundle"); if (Directory.Exists(path)) { baseName += ".bundle"; } else { baseName += ".dylib"; } } else if (PlatformInfo.Platform == PlatformInfo.PlanformType.Android) { string str = "lib"; if (baseName.Length > 3 && baseName.Substring(0, 3) == "lib") { str = ""; } baseName = str + baseName + ".so"; } else { Log.Fatal("NativeLibraryManager: PreLoadLibrary: no code."); } string currentDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(NativeLibraryManager.GetNativeLibrariesDirectory()); if (PlatformInfo.Platform == PlatformInfo.PlanformType.Windows) { try { NativeLibraryManager.SetDllDirectory(NativeLibraryManager.GetNativeLibrariesDirectory()); } catch { } } string text = Path.Combine(NativeLibraryManager.GetNativeLibrariesDirectory(), baseName); if (PlatformNative.Get().LoadLibrary(text) == IntPtr.Zero) { Log.Fatal("Loading native library failed ({0}).", text); return; } Directory.SetCurrentDirectory(currentDirectory); } } }
/// <summary> /// 初始化 /// </summary> /// <param name="logFileName">日志文件</param> /// <param name="correctCurrentDirectory">!</param> /// <param name="specialExecutableDirectoryPath">程序目录</param> /// <param name="specialResourceDirectoryPath">资源目录</param> /// <param name="specialUserDirectoryPath">用户目录</param> /// <param name="specialNativeLibrariesDirectoryPath">DLL目录</param> /// <returns></returns> public static bool Init(string logFileName, bool correctCurrentDirectory, string specialExecutableDirectoryPath, string specialResourceDirectoryPath, string specialUserDirectoryPath, string specialNativeLibrariesDirectoryPath) { logFileName = NormalizePath(logFileName); specialExecutableDirectoryPath = NormalizePath(specialExecutableDirectoryPath); specialResourceDirectoryPath = NormalizePath(specialResourceDirectoryPath); specialUserDirectoryPath = NormalizePath(specialUserDirectoryPath); specialNativeLibrariesDirectoryPath = NormalizePath(specialNativeLibrariesDirectoryPath); NativeLibraryManager.specialNativeLibrariesDirectoryPath = specialNativeLibrariesDirectoryPath; if (Initialized) { Log.Fatal("VirtualFileSystem: Init: File system already initialized."); return(false); } if (!string.IsNullOrEmpty(specialExecutableDirectoryPath) && !Path.IsPathRooted(specialExecutableDirectoryPath)) { Log.Fatal("VirtualFileSystem: Init: Special executable directory path must be rooted."); return(false); } Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); executableDirectoryPath = specialExecutableDirectoryPath; if (string.IsNullOrEmpty(executableDirectoryPath)) { executableDirectoryPath = PlatformNative.Get().GetExecutableDirectoryPath(); } resourceDirectoryPath = specialResourceDirectoryPath; if (string.IsNullOrEmpty(resourceDirectoryPath)) { resourceDirectoryPath = Path.Combine(executableDirectoryPath, "Data"); } if (!string.IsNullOrEmpty(specialUserDirectoryPath)) { userDirectoryPath = specialUserDirectoryPath; } bool flag = Type.GetType("Mono.Runtime", false) != null; if (flag) { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ResolveAssembly); } if (PlatformInfo.Platform == PlatformInfo.PlanformType.MacOSX) { NativeLibraryManager.PreLoadLibrary("MacAppNativeWrapper"); } if (correctCurrentDirectory) { _CorrectCurrentDirectory(); } ComponentManager.Init(); if (!ArchiveManager.A()) { Shutdown(); return(false); } Initialized = true; InitDeployment(); string dumpRealFileName = null; if (!string.IsNullOrEmpty(logFileName)) { dumpRealFileName = GetRealPathByVirtual(logFileName); } Log._Init(Thread.CurrentThread, dumpRealFileName); InitCachingExtensions(); return(true); }