public string EDDInitialise(string vstr, string dllfolder, EDDDLLInterfaces.EDDDLLIF.EDDCallBacks cb) { System.Diagnostics.Debug.WriteLine("CSharpDLL Init func " + vstr + " " + dllfolder); System.IO.File.AppendAllText(@"c:\code\csharpdll.txt", Environment.NewLine + "Init " + vstr + " in " + dllfolder + Environment.NewLine); callbacks = cb; return("1.0.0.0"); }
// 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)); }
public bool Init(string ourversion, string[] optioninlist, string dllfolder, EDDDLLInterfaces.EDDDLLIF.EDDCallBacks callbacks) { string strto = ourversion + (optioninlist != null ? (';' + String.Join(";", optioninlist)) : ""); if (AssemblyMainType != null) { Version = AssemblyMainType.EDDInitialise(strto, dllfolder, callbacks); } else if (pDll != IntPtr.Zero) { IntPtr peddinit = BaseUtils.Win32.UnsafeNativeMethods.GetProcAddress(pDll, "EDDInitialise"); EDDDLLInterfaces.EDDDLLIF.EDDInitialise edinit = (EDDDLLInterfaces.EDDDLLIF.EDDInitialise)Marshal.GetDelegateForFunctionPointer( peddinit, typeof(EDDDLLInterfaces.EDDDLLIF.EDDInitialise)); Version = edinit(strto, dllfolder, callbacks); } else { Version = "!"; } bool ok = Version != null && Version.Length > 0 && Version[0] != '!'; if (ok) { var list = Version.Split(';'); Version = list[0]; if (list.Length > 1) { DLLOptions = new string[list.Length - 1]; Array.Copy(list, 1, DLLOptions, 0, list.Length - 1); } else { DLLOptions = new string[] { } }; return(true); } else { if (pDll != IntPtr.Zero) { BaseUtils.Win32.UnsafeNativeMethods.FreeLibrary(pDll); pDll = IntPtr.Zero; } } return(false); }
// 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)); }
protected override void OnShown(EventArgs e) { base.OnShown(e); screenshot.Start((a) => Invoke(a), (b) => LogLine(b), () => { if (lasthe != null) // lasthe should have name and whereami, and an indication of commander { return(new Tuple <string, string, string>(lasthe.System.Name, lasthe.WhereAmI, lasthe.Commander?.Name ?? "Unknown")); } else { return(new Tuple <string, string, string>("Unknown", "Unknown", "Unknown")); } } ); screenshot.OnScreenshot += DisplayScreenshot; EDDDLLAssemblyFinder.AssemblyFindPath = EDDOptions.Instance.DLLAppDirectory(); // any needed assemblies from here AppDomain.CurrentDomain.AssemblyResolve += EDDDLLAssemblyFinder.AssemblyResolve; DLLManager = new EDDDLLManager(); DLLCallBacks = new EDDDLLInterfaces.EDDDLLIF.EDDCallBacks(); DLLCallBacks.ver = 2; DLLCallBacks.RequestHistory = DLLRequestHistory; DLLCallBacks.RunAction = (s1, s2) => { return(false); }; DLLCallBacks.GetShipLoadout = (s) => { return(null); }; string verstring = EDDOptions.Instance.Version; string[] options = new string[] { EDDDLLInterfaces.EDDDLLIF.FLAG_HOSTNAME + "EDLITE", EDDDLLInterfaces.EDDDLLIF.FLAG_JOURNALVERSION + "2", EDDDLLInterfaces.EDDDLLIF.FLAG_CALLBACKVERSION + "2", }; string alloweddlls = EDDConfig.Instance.DLLPermissions; Tuple <string, string, string> res = DLLManager.Load(EDDOptions.Instance.DLLAppDirectory(), verstring, options, DLLCallBacks, alloweddlls); if (res.Item3.HasChars()) // new DLLs { string[] list = res.Item3.Split(','); bool changed = false; foreach (var dll in list) { if (ExtendedControls.MessageBoxTheme.Show(this, string.Format(("The following application extension DLL have been found" + Environment.NewLine + "Do you wish to allow these to be used?" + Environment.NewLine + "{0} " + Environment.NewLine ).T(EDTx.EDDiscoveryForm_DLLW), dll), "Warning".T(EDTx.Warning), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { alloweddlls = alloweddlls.AppendPrePad("+" + dll, ","); changed = true; } else { alloweddlls = alloweddlls.AppendPrePad("-" + dll, ","); } } EDDConfig.Instance.DLLPermissions = alloweddlls; if (changed) { DLLManager.UnLoad(); res = DLLManager.Load(EDDOptions.Instance.DLLAppDirectory(), verstring, options, DLLCallBacks, alloweddlls); } } if (res.Item1.HasChars()) { LogLine(string.Format("DLLs loaded: {0}".T(EDTx.EDDiscoveryForm_DLLL), res.Item1)); } if (res.Item2.HasChars()) { LogLine(string.Format("DLLs failed to load: {0}".T(EDTx.EDDiscoveryForm_DLLF), res.Item2)); } //EDDOptions.Instance.CheckRelease = true; // use this to force check for debugging Installer.CheckForNewInstallerAsync((rel) => // in thread { BeginInvoke((MethodInvoker) delegate { LogLine(string.Format("New EDDLite installer available: {0}".T(EDTx.EDDiscoveryForm_NI), rel.ReleaseName)); labelInfoBoxTop.Text = "New Release Available!".T(EDTx.EDDiscoveryForm_NRA); if (ExtendedControls.MessageBoxTheme.Show("New EDDLite Available, please upgrade!", "Warning".T(EDTx.Warning), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { System.Diagnostics.Process.Start(Properties.Resources.URLProjectReleases); } }); }); controller.Start(a => BeginInvoke(a)); }
public string EDDInitialise(string vstr, string dllfolderp, EDDDLLInterfaces.EDDDLLIF.EDDCallBacks cb) { System.Diagnostics.Debug.WriteLine("Init func " + vstr + " " + dllfolderp); string[] vopts = vstr.Split(';'); int jv = vopts.ContainsIn("JOURNALVERSION=2"); if (jv == -1 || vopts[jv].Substring(15).InvariantParseInt(0) < 2) // check journal version exists and is at 2 mininum { return("!PY Harness requires a more recent host program"); } string EDMCAppFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "EDD-EDMC"); if (!Directory.Exists(EDMCAppFolder)) { return("!PY Harness EDD-EDMC folder not found"); } callbacks = cb; storedout = Path.Combine(EDMCAppFolder, "stored.edd"); currentout = Path.Combine(EDMCAppFolder, "current.edd"); uiout = Path.Combine(EDMCAppFolder, "ui.edd"); BaseUtilsHelpers.DeleteFileNoError(storedout); BaseUtilsHelpers.DeleteFileNoError(currentout); BaseUtilsHelpers.DeleteFileNoError(uiout); string progtoexe = null; string cmdline = null; string workingdir = null; bool consolemode = false; bool runit = true; string scriptrunnerfile = Path.Combine(EDMCAppFolder, "runfrom.txt"); if (File.Exists(scriptrunnerfile)) { try { string[] lines = File.ReadAllLines(scriptrunnerfile); string[] console = lines.Where(x => x.StartsWith("CONSOLE=")).Select(x => x).ToArray(); if (console.Length == 1 && console[0].Substring(8).Equals("true", StringComparison.InvariantCultureIgnoreCase)) { consolemode = true; } string[] script = lines.Where(x => x.StartsWith("SCRIPT=")).Select(x => x).ToArray(); if (script.Length == 1) { string filename = script[0].Substring(7); if (filename.Equals("None", StringComparison.InvariantCultureIgnoreCase)) { runit = false; } else { var pythonpaths = BaseUtils.PythonLaunch.PythonLauncher(); if (pythonpaths != null) { progtoexe = consolemode ? pythonpaths.Item1 : pythonpaths.Item2; workingdir = Path.GetDirectoryName(filename); cmdline = filename; } else { return("!PY Harness Can't find a python launcher"); } } } } catch { return("!Cannot read Runfrom.txt"); } } if (runit && progtoexe == null) // if to run, and still no program { string AppFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "EDD-EDMC"); string App = Path.Combine(AppFolder, consolemode ? "eddedmc.exe" : "eddedmcwin.exe"); if (!File.Exists(App)) { return("!Cannot find application to run"); } progtoexe = App; workingdir = Path.GetDirectoryName(App); cmdline = ""; } if (progtoexe != null) // did we get one.. { pyharness = new Process(); pyharness.StartInfo.FileName = progtoexe; pyharness.StartInfo.Arguments = cmdline; pyharness.StartInfo.WorkingDirectory = workingdir; System.Diagnostics.Trace.WriteLine(string.Format("Run {0} {1} in {2}", progtoexe, cmdline, workingdir)); bool started = pyharness.Start(); if (!started) { pyharness.Dispose(); pyharness = null; return("!PY Harness could not start script"); } } System.Diagnostics.Trace.WriteLine("EDMC Harness started"); return("1.0.0.0;PLAYLASTFILELOAD"); }