using System; using System.IO; using System.Collections.Generic; using Mono.Cecil; using System.Reflection; namespace ModTool.Shared { /// /// Utility for finding Assemblies. /// public class AssemblyUtility { public static List GetAssemblies(string path, Func filter = null) { List assemblies = new List(); GetAssemblies(assemblies, path, filter); return assemblies; } public static void GetAssemblies(List assemblies, string path, Func filter = null) { var assemblyFiles = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories); foreach (var assembly in assemblyFiles) { AssemblyName assemblyName; try { assemblyName = AssemblyName.GetAssemblyName(assembly); } catch (Exception e) { LogUtility.LogDebug(e.Message); continue; } string name = assemblyName.Name; if (name == "ModTool" || name.StartsWith("ModTool.")) continue; if (IsShared(assembly)) continue; if (assembly.Contains("Editor")) continue; if(filter != null && !filter(assembly)) continue; assemblies.Add(assembly); } } /// /// Is an assembly shared with the mod exporter? /// /// The assembly's file path. /// True if an assembly is shared with the mod exporter. public static bool IsShared(string path) { string name = Path.GetFileNameWithoutExtension(path); foreach (string sharedAsset in ModToolSettings.sharedAssets) { if (!sharedAsset.EndsWith(".asmdef") && !sharedAsset.EndsWith(".dll")) continue; if (Path.GetFileNameWithoutExtension(sharedAsset) == name) return true; } return false; } } }