public void UpdateModuleOrder() { lock (padlock) { ProcessingIndex.Clear(); List <int> indexes = new List <int>(); if (moduleOrder.Count == 0) { for (int i = 0; i < Count; i++) { if (!indexes.Contains(i)) { ProcessingIndex.Add(i); modules[i].ModuleStart(); } } } else { for (int i = 0; i < moduleOrder.Count; i++) { int mindex = GetModuleIndex(moduleOrder[i].Value); if (mindex != -1) { indexes.Add(mindex); ProcessingIndex.Add(mindex); if (enabled[mindex] != moduleOrder[i].Key) { if (enabled[mindex]) { modules[mindex].ModuleStop(); } else { modules[mindex].ModuleStart(); } enabled[mindex] = moduleOrder[i].Key; } } } for (int i = 0; i < Count; i++) { if (!indexes.Contains(i)) { ProcessingIndex.Add(i); } } } moduleOrder.Clear(); for (int i = 0; i < Count; i++) { NDISModule fm = GetModule(i); moduleOrder.Add(new KeyValuePair <bool, string>(enabled[GetModuleIndex(fm.MetaData.GetMeta().Name)], fm.MetaData.GetMeta().Name)); } SaveModuleOrder(); } }
public void AddModule(NDISModule fm) { lock (padlock) { modules.Add(fm); ProcessingIndex.Add(modules.Count - 1); enabled.Add(false); } }
public void LoadModule(string file) { NDISModule mod = null; lock (loadedAssemblies) { if (file.Contains("FirewallModule.dll") || !file.Contains(".dll")) { return; } try { if (loadedMods.ContainsValue(file)) { return; } Assembly assembly; if (!loadedAssemblies.TryGetValue(file, out assembly)) { assembly = Assembly.Load(File.ReadAllBytes(file)); loadedAssemblies.Add(file, assembly); } Type[] type = assembly.GetTypes(); foreach (Type t in type) { if (typeof(NDISModule).IsAssignableFrom(t)) { mod = (NDISModule)Activator.CreateInstance(t); mod.Adapter = na; AddModule(mod); loadedMods.Add(mod.MetaData.GetMeta().Name, file); } } } catch (ArgumentException ae) { LogCenter.Instance.LogEvent(new LogEvent("Module attempted load twice.", mod)); LogCenter.Instance.LogException(ae); } catch (Exception e) { LogCenter.Instance.LogException(e); } } }