diff --git a/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs b/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs index 58eb408a6..ee6890f50 100644 --- a/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs +++ b/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Scripting { p.Message("That command is already loaded!"); return; } - string path = IScripting.DllPath(cmdName); + string path = IScripting.CommandPath(cmdName); if (!File.Exists(path)) { p.Message("File &9{0} &Snot found.", path); return; } diff --git a/MCGalaxy/Commands/Scripting/CmdCompile.cs b/MCGalaxy/Commands/Scripting/CmdCompile.cs index 7ee5155ee..1f4c00b04 100644 --- a/MCGalaxy/Commands/Scripting/CmdCompile.cs +++ b/MCGalaxy/Commands/Scripting/CmdCompile.cs @@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.Scripting { } string srcPath = engine.SourcePath(args[0]); - string dstPath = IScripting.DllPath(args[0]); + string dstPath = IScripting.CommandPath(args[0]); if (!File.Exists(srcPath)) { p.Message("File &9{0} &Snot found.", srcPath); return; } @@ -51,7 +51,7 @@ namespace MCGalaxy.Commands.Scripting { p.Message("Command compiled successfully."); } else { ICompiler.SummariseErrors(results, p); - p.Message("&WCompilation error. See " + IScripting.ErrorPath + " for more information."); + p.Message("&WCompilation error. See " + ICompiler.ErrorPath + " for more information."); } } diff --git a/MCGalaxy/Commands/Scripting/CmdPlugin.cs b/MCGalaxy/Commands/Scripting/CmdPlugin.cs index 6b5d18a26..b748b5eec 100644 --- a/MCGalaxy/Commands/Scripting/CmdPlugin.cs +++ b/MCGalaxy/Commands/Scripting/CmdPlugin.cs @@ -69,20 +69,20 @@ namespace MCGalaxy.Commands.Scripting { p.Message("Plugin compiled successfully."); } else { ICompiler.SummariseErrors(results, p); - p.Message("&WCompilation error. See " + IScripting.ErrorPath + " for more information."); + p.Message("&WCompilation error. See " + ICompiler.ErrorPath + " for more information."); } } static void LoadPlugin(Player p, string name) { string path = IScripting.PluginPath(name); - if (File.Exists(path)) { - if (Plugin.Load(path, false)) { - p.Message("Plugin loaded successfully."); - } else { - p.Message("&WError loading plugin. See error logs for more information."); - } + if (!File.Exists(path)) { + p.Message("File &9{0} &Snot found.", path); return; + } + + if (IScripting.LoadPlugin(path, false)) { + p.Message("Plugin loaded successfully."); } else { - p.Message("File &9{0} &Snot found.", path); + p.Message("&WError loading plugin. See error logs for more information."); } } diff --git a/MCGalaxy/Plugins/PluginManager.cs b/MCGalaxy/Plugins/PluginManager.cs index e2b520463..a34764bb8 100644 --- a/MCGalaxy/Plugins/PluginManager.cs +++ b/MCGalaxy/Plugins/PluginManager.cs @@ -27,22 +27,6 @@ namespace MCGalaxy { public abstract partial class Plugin { internal static List core = new List(); public static List all = new List(); - - /// Loads all plugins from the given path. - public static bool Load(string path, bool startup) { - try { - Assembly lib = IScripting.LoadAssembly(path); - List plugins = IScripting.LoadTypes(lib); - - foreach (Plugin plugin in plugins) { - if (!Load(plugin, startup)) return false; - } - return true; - } catch (Exception ex) { - Logger.LogError("Error loading plugins from " + path, ex); - return false; - } - } public static bool Load(Plugin p, bool startup) { try { @@ -92,13 +76,7 @@ namespace MCGalaxy { public static void LoadAll() { LoadCorePlugin(new CorePlugin()); LoadCorePlugin(new NotesPlugin()); - - if (Directory.Exists("plugins")) { - string[] files = Directory.GetFiles("plugins", "*.dll"); - foreach (string path in files) { Load(path, true); } - } else { - Directory.CreateDirectory("plugins"); - } + IScripting.AutoloadPlugins(); } static void LoadCorePlugin(Plugin plugin) { diff --git a/MCGalaxy/Scripting/Scripting.cs b/MCGalaxy/Scripting/Scripting.cs index 0af34e229..1c4d7bfd5 100644 --- a/MCGalaxy/Scripting/Scripting.cs +++ b/MCGalaxy/Scripting/Scripting.cs @@ -30,12 +30,10 @@ namespace MCGalaxy.Scripting { public static class IScripting { public const string AutoloadFile = "text/cmdautoload.txt"; - public const string SourceDir = "extra/commands/source/"; public const string DllDir = "extra/commands/dll/"; - public const string ErrorPath = "logs/errors/compiler.log"; - public static string DllPath(string cmdName) { return DllDir + "Cmd" + cmdName + ".dll"; } - public static string PluginPath(string name) { return "plugins/" + name + ".dll"; } + public static string CommandPath(string name) { return DllDir + "Cmd" + name + ".dll"; } + public static string PluginPath(string name) { return "plugins/" + name + ".dll"; } /// Constructs instances of all types which derive from T in the given assembly. /// The list of constructed instances. @@ -67,6 +65,7 @@ namespace MCGalaxy.Scripting { } } + /// Loads the given assembly from disc (and associated .pdb debug data) public static Assembly LoadAssembly(string path) { byte[] data = File.ReadAllBytes(path); byte[] debug = GetDebugData(path); @@ -75,12 +74,12 @@ namespace MCGalaxy.Scripting { public static void AutoloadCommands() { - if (!File.Exists(AutoloadFile)) { File.Create(AutoloadFile); return; } + if (!File.Exists(AutoloadFile)) { File.Create(AutoloadFile); return; } string[] list = File.ReadAllLines(AutoloadFile); foreach (string cmdName in list) { if (cmdName.IsCommentLine()) continue; - string path = DllPath(cmdName); + string path = CommandPath(cmdName); string error = LoadCommands(path); if (error != null) { Logger.Log(LogType.Warning, error); continue; } @@ -88,7 +87,7 @@ namespace MCGalaxy.Scripting { } } - /// Loads and registers all the commands in the given dll. + /// Loads and registers all the commands from the given .dll path. public static string LoadCommands(string path) { try { Assembly lib = LoadAssembly(path); @@ -111,14 +110,38 @@ namespace MCGalaxy.Scripting { } return null; } + + + public static void AutoloadPlugins() { + if (Directory.Exists("plugins")) { + string[] files = Directory.GetFiles("plugins", "*.dll"); + foreach (string path in files) { LoadPlugin(path, true); } + } else { + Directory.CreateDirectory("plugins"); + } + } + + /// Loads all plugins from the given .dll path. + public static bool LoadPlugin(string path, bool auto) { + try { + Assembly lib = LoadAssembly(path); + List plugins = IScripting.LoadTypes(lib); + + foreach (Plugin plugin in plugins) { + if (!Plugin.Load(plugin, auto)) return false; + } + return true; + } catch (Exception ex) { + Logger.LogError("Error loading plugins from " + path, ex); + return false; + } + } } /// Compiles source code files from a particular language into a .dll file. public abstract class ICompiler { - public const string AutoloadFile = "text/cmdautoload.txt"; public const string SourceDir = "extra/commands/source/"; - public const string DllDir = "extra/commands/dll/"; public const string ErrorPath = "logs/errors/compiler.log"; protected CodeDomProvider compiler; @@ -143,8 +166,6 @@ namespace MCGalaxy.Scripting { } } - public static string DllPath(string cmdName) { return DllDir + "Cmd" + cmdName + ".dll"; } - public static string PluginPath(string name) { return "plugins/" + name + ".dll"; } public string SourcePath(string cmdName) { return SourceDir + "Cmd" + cmdName + Ext; } public void CreateNew(string path, string cmdName) { diff --git a/MCGalaxy/Server/Maintenance/ZipReader.cs b/MCGalaxy/Server/Maintenance/ZipReader.cs index d0d662972..8e303b88b 100644 --- a/MCGalaxy/Server/Maintenance/ZipReader.cs +++ b/MCGalaxy/Server/Maintenance/ZipReader.cs @@ -191,7 +191,7 @@ namespace MCGalaxy { int filenameLen = r.ReadUInt16(); int extraLen = r.ReadUInt16(); int commentLen = r.ReadUInt16(); - r.ReadUInt16(); // disk number + r.ReadUInt16(); // disc number r.ReadUInt16(); // internal attributes r.ReadUInt32(); // external attributes entry.LocalHeaderOffset = r.ReadUInt32(); @@ -220,27 +220,27 @@ namespace MCGalaxy { r.ReadInt64(); // zip64 end of central dir size r.ReadUInt16(); // version r.ReadUInt16(); // version - r.ReadUInt32(); // disk number - r.ReadUInt32(); // disk number of central directory + r.ReadUInt32(); // disc number + r.ReadUInt32(); // disc number of central directory numEntries = (int)r.ReadInt64(); - r.ReadInt64(); // num entries on disk + r.ReadInt64(); // num entries on disc r.ReadInt64(); // central dir size centralDirOffset = r.ReadInt64(); } void ReadZip64EndOfCentralDirectoryLocator() { BinaryReader r = reader; - r.ReadUInt32(); // disk number of zip64 end of central directory + r.ReadUInt32(); // disc number of zip64 end of central directory zip64EndOffset = reader.ReadInt64(); - r.ReadUInt32(); // total number of disks + r.ReadUInt32(); // total number of discs } void ReadEndOfCentralDirectoryRecord() { BinaryReader r = reader; - r.ReadUInt16(); // disk number - r.ReadUInt16(); // disk number of start + r.ReadUInt16(); // disc number + r.ReadUInt16(); // disc number of start numEntries = r.ReadUInt16(); - r.ReadUInt16(); // num entries on disk + r.ReadUInt16(); // num entries on disc r.ReadUInt32(); // cental dir size centralDirOffset = r.ReadUInt32(); r.ReadUInt16(); // comment length diff --git a/MCGalaxy/Server/Maintenance/ZipWriter.cs b/MCGalaxy/Server/Maintenance/ZipWriter.cs index d01c1d935..fb2143b7b 100644 --- a/MCGalaxy/Server/Maintenance/ZipWriter.cs +++ b/MCGalaxy/Server/Maintenance/ZipWriter.cs @@ -245,7 +245,7 @@ namespace MCGalaxy { w.Write((ushort)entry.Filename.Length); w.Write(extraLen); w.Write((ushort)0); // file comment length - w.Write((ushort)0); // disk number + w.Write((ushort)0); // disc number w.Write((ushort)0); // internal attributes w.Write(0); // external attributes w.Write((uint)entry.LocalHeaderOffset); @@ -275,8 +275,8 @@ namespace MCGalaxy { w.Write(zip64EndDataSize); w.Write(ver_zip64); w.Write(ver_zip64); - w.Write(0); // disk number - w.Write(0); // disk number of central directory + w.Write(0); // disc number + w.Write(0); // disc number of central directory w.Write((long)numEntries); w.Write((long)numEntries); w.Write(centralDirSize); @@ -286,16 +286,16 @@ namespace MCGalaxy { void WriteZip64EndOfCentralDirectoryLocator() { BinaryWriter w = writer; w.Write(ZipEntry.SigZip64Loc); - w.Write(0); // disk number of zip64 end of central directory + w.Write(0); // disc number of zip64 end of central directory w.Write(zip64EndOffset); - w.Write(1); // total number of disks + w.Write(1); // total number of discs } void WriteEndOfCentralDirectoryRecord() { BinaryWriter w = writer; w.Write(ZipEntry.SigEnd); - w.Write((ushort)0); // disk number - w.Write((ushort)0); // disk number of start + w.Write((ushort)0); // disc number + w.Write((ushort)0); // disc number of start w.Write((ushort)numEntries); w.Write((ushort)numEntries); w.Write((uint)centralDirSize); diff --git a/MCGalaxy/Server/Server.cs b/MCGalaxy/Server/Server.cs index 5ad788bb0..5f9a11772 100644 --- a/MCGalaxy/Server/Server.cs +++ b/MCGalaxy/Server/Server.cs @@ -150,7 +150,7 @@ namespace MCGalaxy { EnsureDirectoryExists(Paths.ImportsDir); EnsureDirectoryExists("blockdefs"); EnsureDirectoryExists(IScripting.DllDir); - EnsureDirectoryExists(IScripting.SourceDir); + EnsureDirectoryExists(ICompiler.SourceDir); } static void EnsureDirectoryExists(string dir) {