diff --git a/GUI/Popups/CustomCommands.cs b/GUI/Popups/CustomCommands.cs index 761d4c617..d2cf1ccea 100644 --- a/GUI/Popups/CustomCommands.cs +++ b/GUI/Popups/CustomCommands.cs @@ -122,10 +122,6 @@ namespace MCGalaxy.Gui.Popups { void LoadCommands(Assembly assembly) { List commands = IScripting.LoadTypes(assembly); - if (commands == null) { - Popup.Error("Error compiling files. Check logs for more details"); return; - } - for (int i = 0; i < commands.Count; i++) { Command cmd = commands[i]; diff --git a/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs b/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs index 532da8251..653d9adff 100644 --- a/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs +++ b/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs @@ -26,18 +26,11 @@ namespace MCGalaxy.Commands.Scripting { public override bool MessageBlockRestricted { get { return true; } } public override void Use(Player p, string cmdName, CommandData data) { - if (!Formatter.CheckFilenameOnly(p, cmdName)) return; - if (Command.Find(cmdName) != null) { - p.Message("That command is already loaded!"); return; - } - - string path = IScripting.CommandPath(cmdName); - if (!File.Exists(path)) { - p.Message("File &9{0} &Snot found.", path); return; - } - + if (!Formatter.CheckFilenameOnly(p, cmdName)) return; + string path = IScripting.CommandPath(cmdName); string error = IScripting.LoadCommands(path); - if (error != null) { p.Message("&W" + error); return; } + + if (error != null) { p.Message(error); return; } p.Message("Command was successfully loaded."); } diff --git a/MCGalaxy/Scripting/Scripting.cs b/MCGalaxy/Scripting/Scripting.cs index 6ade5542a..798046ae6 100644 --- a/MCGalaxy/Scripting/Scripting.cs +++ b/MCGalaxy/Scripting/Scripting.cs @@ -79,40 +79,56 @@ namespace MCGalaxy.Scripting { if (!File.Exists(AutoloadFile)) { File.Create(AutoloadFile); return; } string[] list = File.ReadAllLines(AutoloadFile); - foreach (string cmdName in list) { + foreach (string cmdName in list) + { if (cmdName.IsCommentLine()) continue; string path = CommandPath(cmdName); string error = LoadCommands(path); - if (error != null) { Logger.Log(LogType.Warning, error); continue; } - Logger.Log(LogType.SystemActivity, "AUTOLOAD: Loaded Cmd{0}.dll", cmdName); + if (error != null) { + Logger.Log(LogType.Warning, error); + } else { + Logger.Log(LogType.SystemActivity, "AUTOLOAD: Loaded Cmd{0}.dll", cmdName); + } } } - /// Loads and registers all the commands from the given .dll path. + /// Loads and registers all the commands from the given .dll path + /// If an error occurred, a string describing the error public static string LoadCommands(string path) { try { Assembly lib = LoadAssembly(path); List commands = LoadTypes(lib); + if (commands.Count == 0) return "&WNo commands in " + path; - if (commands.Count == 0) return "No commands in dll file"; - foreach (Command cmd in commands) { Command.Register(cmd); } - } catch (Exception ex) { - Logger.LogError("Error loading commands from " + path, ex); - - string file = Path.GetFileName(path); - if (ex is FileNotFoundException) { - return file + " does not exist in the DLL folder, or is missing a dependency. Details in the error log."; - } else if (ex is BadImageFormatException) { - return file + " is not a valid assembly, or has an invalid dependency. Details in the error log."; - } else if (ex is FileLoadException) { - return file + " or one of its dependencies could not be loaded. Details in the error log."; + foreach (Command cmd in commands) + { + if (Command.Find(cmd.name) != null) + return "/" + cmd.name + " is already loaded"; + + Command.Register(cmd); } - return "An unknown error occured. Details in the error log."; + } catch (Exception ex) { + return DescribeLoadError(path, ex); } return null; } + static string DescribeLoadError(string path, Exception ex) { + if (ex is FileNotFoundException) + return "File &9" + path + " &Snot found."; + + Logger.LogError("Error loading commands from " + path, ex); + string file = Path.GetFileName(path); + + if (ex is BadImageFormatException) { + return "&W" + file + " is not a valid assembly, or has an invalid dependency. Details in the error log."; + } else if (ex is FileLoadException) { + return "&W" + file + " or one of its dependencies could not be loaded. Details in the error log."; + } + return "&WAn unknown error occured. Details in the error log."; + } + public static void AutoloadPlugins() { string[] files = AtomicIO.TryGetFiles("plugins", "*.dll");