// search directory for *.dll, // return loaded, failed, new dlls not in the allowed/disallowed list // alloweddisallowed list is +allowed,-disallowed.. // all Csharp assembly DLLs are loaded - only ones implementing *EDDClass class causes it to be added to the DLL list // only normal DLLs implementing EDDInitialise are kept loaded public Tuple <string, string, string> Load(string dlldirectory, string ourversion, string[] inoptions, EDDDLLInterfaces.EDDDLLIF.EDDCallBacks callbacks, string alloweddisallowed) { string loaded = ""; string failed = ""; string newdlls = ""; if (!Directory.Exists(dlldirectory)) { failed = "DLL Folder does not exist"; } else { FileInfo[] allFiles = Directory.EnumerateFiles(dlldirectory, "*.dll", SearchOption.TopDirectoryOnly).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray(); string[] allowedfiles = alloweddisallowed.Split(','); foreach (FileInfo f in allFiles) { EDDDLLCaller caller = new EDDDLLCaller(); System.Diagnostics.Debug.WriteLine("Try to load " + f.FullName); string filename = System.IO.Path.GetFileNameWithoutExtension(f.FullName); bool isallowed = alloweddisallowed.Equals("All", StringComparison.InvariantCultureIgnoreCase) || allowedfiles.Contains("+" + filename, StringComparer.InvariantCultureIgnoreCase); if (isallowed) // if allowed.. { if (caller.Load(f.FullName)) // if loaded okay { if (caller.Init(ourversion, inoptions, dlldirectory, callbacks)) // must init { DLLs.Add(caller); loaded = loaded.AppendPrePad(filename, ","); } else { string errstr = caller.Version.HasChars() ? (": " + caller.Version.Substring(1)) : ""; failed = failed.AppendPrePad(filename + errstr, ","); } } } else { if (!allowedfiles.Contains("-" + filename, StringComparer.InvariantCultureIgnoreCase)) // is not disallowed, its new, ask { newdlls = newdlls.AppendPrePad(filename, ","); } } } } return(new Tuple <string, string, string>(loaded, failed, newdlls)); }
// return loaded, failed, notallowed public Tuple <string, string, string> Load(string directory, string ourversion, string dllfolder, EDDDLLIF.EDDCallBacks callbacks, string allowed) { string loaded = ""; string failed = ""; string notallowed = ""; if (!Directory.Exists(directory)) { failed = "DLL Folder does not exist"; } else { FileInfo[] allFiles = Directory.EnumerateFiles(directory, "*.dll", SearchOption.TopDirectoryOnly).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray(); string[] allowedfiles = allowed.Split(','); foreach (FileInfo f in allFiles) { string filename = System.IO.Path.GetFileNameWithoutExtension(f.FullName); EDDDLLCaller caller = new EDDDLLCaller(); if (caller.Load(f.FullName)) // if loaded (meaning it loaded, and its got EDDInitialise) { if (allowed.Equals("All", StringComparison.InvariantCultureIgnoreCase) || allowedfiles.Contains(filename, StringComparer.InvariantCultureIgnoreCase)) // if allowed.. { if (caller.Init(ourversion, dllfolder, callbacks)) // must init { dlls.Add(caller); loaded = loaded.AppendPrePad(caller.Name, ","); } else { string errstr = caller.Version.HasChars() ? (": " + caller.Version.Substring(1)) : ""; failed = failed.AppendPrePad(caller.Name + errstr, ","); } } else { notallowed = notallowed.AppendPrePad(caller.Name, ","); } } } } return(new Tuple <string, string, string>(loaded, failed, notallowed)); }
// search directory for *.dll, // return loaded, failed, new dlls not in the allowed/disallowed list, disabled // alloweddisallowed list is +allowed,-disallowed.. // all Csharp assembly DLLs are loaded - only ones implementing *EDDClass class causes it to be added to the DLL list // only normal DLLs implementing EDDInitialise are kept loaded public Tuple <string, string, string, string> Load(string[] dlldirectories, bool[] disallowautomatically, string ourversion, string[] inoptions, EDDDLLInterfaces.EDDDLLIF.EDDCallBacks callbacks, ref string alloweddisallowed) { string loaded = ""; string failed = ""; string disabled = ""; string newdlls = ""; for (int i = 0; i < dlldirectories.Length; i++) { var dlldirectory = dlldirectories[i]; if (dlldirectory != null) { if (!Directory.Exists(dlldirectory)) { failed = failed.AppendPrePad("DLL Folder " + dlldirectory + " does not exist", ","); } else { FileInfo[] allFiles = Directory.EnumerateFiles(dlldirectory, "*.dll", SearchOption.TopDirectoryOnly).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray(); string[] allowedfiles = alloweddisallowed.Split(','); foreach (FileInfo f in allFiles) { EDDDLLCaller caller = new EDDDLLCaller(); System.Diagnostics.Debug.WriteLine("Try to load " + f.FullName); string filename = System.IO.Path.GetFileNameWithoutExtension(f.FullName); bool isallowed = alloweddisallowed.Equals("All", StringComparison.InvariantCultureIgnoreCase) || allowedfiles.Contains("+" + f.FullName, StringComparer.InvariantCultureIgnoreCase) || // full name is now used allowedfiles.Contains("+" + filename, StringComparer.InvariantCultureIgnoreCase); // filename previously used bool isdisallowed = allowedfiles.Contains("-" + f.FullName, StringComparer.InvariantCultureIgnoreCase) || // full name is now used allowedfiles.Contains("-" + filename, StringComparer.InvariantCultureIgnoreCase); // filename previously used if (isdisallowed) // disallowed { disabled = disabled.AppendPrePad(f.FullName, ","); } else if (isallowed) // if allowed.. { if (caller.Load(f.FullName)) // if loaded okay { if (caller.Init(ourversion, inoptions, dlldirectory, callbacks)) // must init { DLLs.Add(caller); loaded = loaded.AppendPrePad(filename, ","); // just use short name for reporting } else { string errstr = caller.Version.HasChars() ? (": " + caller.Version.Substring(1)) : ""; failed = failed.AppendPrePad(f.FullName + errstr, ","); // long name for failure } } } else { if (disallowautomatically[i]) { alloweddisallowed = alloweddisallowed.AppendPrePad("-" + f.FullName, ","); disabled = disabled.AppendPrePad(f.FullName, ","); } else { newdlls = newdlls.AppendPrePad(f.FullName, ","); } } } } } } return(new Tuple <string, string, string, string>(loaded, failed, newdlls, disabled)); }