private void CheckCustomAssemblies() { var processed = CustomAssemblies.Select(dll => dll.Key).ToList(); Configuration?.Current?.CustomAssemblies?.ForEach(dll => { string dllPath = dll; try { dllPath = Path.Combine(SaveGameModPath, dll).NormalizePath(); if (!CustomAssemblies.ContainsKey(dllPath)) { LoadCustomAssembly(dllPath); } else { processed.Remove(dllPath); } } catch (Exception error) { Log?.Invoke($"CheckCustomAssemblies: {dll} ({dllPath}) -> {error}", LogLevel.Error); } }); processed.ForEach(dll => CustomAssemblies.TryRemove(dll, out var customAssembly)); }
public override Task InitializeAsync() { BuildDate = Assembly.GetExecutingAssembly().GetCustomAttribute <BuildDateAttribute>()?.Date ?? default; foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().DistinctBy(x => x.FullName)) { if (!assembly.FullName.Contains("Administrator") && !assembly.FullName.Contains("System") && !assembly.FullName.Contains("Microsoft") && !assembly.FullName.Contains("netstandard") && !assembly.FullName.Contains("DynamicMethods") && !assembly.FullName.Contains("Linq")) { CustomAssemblies.Add(assembly); } } return(base.InitializeAsync()); }
private void LoadCustomAssembly(string dll) { string dllPath = dll; try { dllPath = Path.Combine(SaveGameModPath, dll).NormalizePath(); Log?.Invoke($"CustomAssemblyLoad: {dll} ({dllPath})", LogLevel.Message); var loadedAssembly = Assembly.LoadFile(dllPath); CustomAssembly current = null; CustomAssemblies.AddOrUpdate(dllPath, current = new CustomAssembly() { FullAssemblyDllName = dllPath, LoadedAssembly = loadedAssembly }, (d, a) => { current = a; a.LoadedAssembly = loadedAssembly; return(a); }); } catch (Exception error) { Log?.Invoke($"CustomAssemblyLoad: {dll} ({dllPath}) -> {error}", LogLevel.Error); } }