// Constructor public Plugin(string filename) { // Initialize string shortfilename = Path.GetFileName(filename); name = Path.GetFileNameWithoutExtension(filename); General.WriteLogLine("Loading plugin \"" + name + "\" from \"" + shortfilename + "\"..."); try { // Load assembly asm = Assembly.LoadFrom(filename); } catch (Exception e) { General.ErrorLogger.Add(ErrorType.Error, "Could not load plugin \"" + shortfilename + "\", the DLL file could not be read. This file is not supposed to be in the Plugins subdirectory." + Environment.NewLine + Environment.NewLine + "Exception details: " + Environment.NewLine + e.ToString()); throw new InvalidProgramException(); } // Find the class that inherits from Plugin Type t = FindSingleClass(typeof(Plug)); if (t != null) { // Are the multiple plug classes? if (FindClasses(typeof(Plug)).Length > 1) { // Show a warning General.ErrorLogger.Add(ErrorType.Warning, "Plugin \"" + shortfilename + "\" has more than one Plug class. The following class is used to create in instance: " + t.FullName); } // Make plug instance plug = CreateObject <Plug>(t); plug.Plugin = this; // Verify revision numbers int thisrevision = General.ThisAssembly.GetName().Version.Revision; //mxd. Revision numbers should match? if (plug.StrictRevisionMatching && plug.MinimumRevision != thisrevision) { string message = shortfilename + " plugin's assembly version (" + plug.MinimumRevision + ") doesn't match main module version (" + thisrevision + ")."; if (General.ShowWarningMessage(message + Environment.NewLine + "It's strongly recommended to update the editor." + Environment.NewLine + "Program stability is not guaranteed." + Environment.NewLine + Environment.NewLine + "Continue anyway?", MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button2, false) == DialogResult.No) { General.WriteLogLine("Quiting on " + shortfilename + " module version mismatch"); General.Exit(General.Map != null); return; } else { General.ErrorLogger.Add(ErrorType.Warning, message); throw new InvalidProgramException(); } } // Verify minimum revision number if ((thisrevision != 0) && (plug.MinimumRevision > thisrevision)) { // Can't load this plugin because it is meant for a newer version General.ErrorLogger.Add(ErrorType.Error, "Could not load plugin \"" + shortfilename + "\", the Plugin is made for GZDoom Builder R" + plug.MinimumRevision + " or newer and you are running R" + thisrevision + "."); throw new InvalidProgramException(); } } else { // How can we plug something in without a plug? General.ErrorLogger.Add(ErrorType.Error, "Could not load plugin \"" + shortfilename + "\", plugin is missing the Plug class. This file is not supposed to be in the Plugins subdirectory."); throw new InvalidProgramException(); } // We have no destructor GC.SuppressFinalize(this); }
// Constructor public Plugin(string filename) { // Initialize string shortfilename = Path.GetFileName(filename).ToLowerInvariant(); name = Path.GetFileNameWithoutExtension(filename); if (shortfilename.Equals("slimdx.dll") || shortfilename.Equals("trackbar.dll") || shortfilename.Equals("sharpcompress.dll")) { throw new InvalidProgramException(); } Logger.WriteLogLine("Loading plugin '" + name + "' from '" + shortfilename + "'..."); try { // Load assembly asm = Assembly.LoadFile(filename); } catch (Exception) { General.ErrorLogger.Add(ErrorType.Error, "Could not load plugin \"" + shortfilename + "\", the DLL file could not be read. This file is not supposed to be in the Plugins subdirectory."); throw new InvalidProgramException(); } // Find the class that inherits from Plugin Type t = FindSingleClass(typeof(Plug)); if (t != null) { // Are the multiple plug classes? if (FindClasses(typeof(Plug)).Length > 1) { // Show a warning General.ErrorLogger.Add(ErrorType.Warning, "Plugin \"" + shortfilename + "\" has more than one plug. The following class is used to create in instance: " + t.FullName); } // Make plug instance plug = CreateObject <Plug>(t); plug.Plugin = this; // ano - this just doesn't really work right because of all the db2 forks floating around /* * // Verify minimum revision number * int thisrevision = General.ThisAssembly.GetName().Version.Revision; * if((thisrevision != 0) && (plug.MinimumRevision > thisrevision)) * { * // Can't load this plugin because it is meant for a newer version * General.ErrorLogger.Add(ErrorType.Error, "Could not load plugin \"" + shortfilename + "\", the Plugin is made for Doom Builder 2 core revision " + plug.MinimumRevision + " and you are running revision " + thisrevision + "."); * throw new InvalidProgramException(); * } */ } else { // How can we plug something in without a plug? General.ErrorLogger.Add(ErrorType.Error, "Could not load plugin \"" + shortfilename + "\", plugin is missing the plug. This file is not supposed to be in the Plugins subdirectory."); throw new InvalidProgramException(); } // We have no destructor GC.SuppressFinalize(this); }