public void GetDllInfo() { object[] args = new object[1]; this.m_tDllReg.InvokeMember("DLL_GetInfo", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, args); this.info = (DLLInfo)args[0]; }
public VersionedAssemblyLoader(ModContentPack content) : base(content) { List <string> dllFileNames = new List <string>(); //List<FileInfo> infos = new List<FileInfo>(); Hashtable dllFiles = new Hashtable(); // build list of all dll files in VersionedAssemblies in all mods foreach (ModContentPack Pack in LoadedModManager.RunningModsListForReading) { // mostly copied from Verse.ModAssemblyHandler.ReloadAll() string path = Path.Combine(Pack.RootDir, "VersionedAssemblies"); string path2 = Path.Combine(GenFilePaths.CoreModsFolderPath, path); DirectoryInfo directoryInfo = new DirectoryInfo(path2); if (!directoryInfo.Exists) { continue; } FileInfo[] files = directoryInfo.GetFiles("*.*", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { FileInfo fileInfo = files[i]; if (!(fileInfo.Extension.ToLower() != ".dll")) { string name = fileInfo.Name; if (name == "UnityEngine.dll") { // Ignore unity. It shouldn't be there, but if it's there anyway, do not try to load it continue; } if (dllFiles.ContainsKey(name)) { ((DLLInfo)dllFiles[name]).update(fileInfo); } else { dllFiles[name] = new DLLInfo(fileInfo); dllFileNames.Add(name); } } } } // load DLL files alphabetically dllFileNames.Sort(); foreach (string dll in dllFileNames) { DLLInfo info = dllFiles[dll] as DLLInfo; byte[] rawAssembly = File.ReadAllBytes(info.path); Assembly assembly = AppDomain.CurrentDomain.Load(rawAssembly); var asm = assembly.CreateInstance(dll + ".VersionedAssemblyInit"); // DLL loaded, now try to call the init method AssemblyTitleAttribute[] attributes = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false) as AssemblyTitleAttribute[]; try { string title = attributes[0].Title; assembly.CreateInstance(title + ".VersionedAssemblyInit"); } catch { } } // look for incompatible dll files in assemblies foreach (ModContentPack Pack in LoadedModManager.RunningModsListForReading) { string path = Path.Combine(Pack.RootDir, "VersionedAssemblies"); string path2 = Path.Combine(GenFilePaths.CoreModsFolderPath, path); DirectoryInfo directoryInfo = new DirectoryInfo(path2); if (!directoryInfo.Exists) { continue; } FileInfo[] files = directoryInfo.GetFiles("*.*", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { try { string Name = files[i].Name; if (dllFileNames.Contains(Name)) { FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(files[i].FullName); Version version = new Version(myFileVersionInfo.FileVersion); Version a = (dllFiles[Name] as DLLInfo).version; int comparision = version.CompareTo(a); if (comparision < 0) { Log.Error("[" + Pack.Name + "] contains outdated " + Name + " which conflicts with the version loaded in VersionedAssemblies"); } else if (comparision == 0) { if (Prefs.LogVerbose) { Log.Warning("[" + Pack.Name + "] contains " + Name + " which shouldn't be in assemblies when it's also loaded in VersionedAssemblies"); } } else if (comparision > 0) { Log.Warning("[" + Pack.Name + "] contains a newer " + Name + " than the newest in VersionedAssemblies"); } } } catch { } } } }