Assembly CompileCommands(string path) { ICompiler compiler = GetCompiler(path); if (compiler == null) { Popup.Warning("Unsupported file '" + path + "'"); return(null); } ConsoleHelpPlayer p = new ConsoleHelpPlayer(); CompilerResults result = ScriptingOperations.Compile(p, compiler, "Command", new[] { path }, null); if (result != null) { return(result.CompiledAssembly); } Popup.Error(Colors.StripUsed(p.Messages)); return(null); }
void btnLoad_Click(object sender, EventArgs e) { string fileName; using (FileDialog dialog = new OpenFileDialog()) { dialog.RestoreDirectory = true; dialog.Filter = "Accepted File Types (*.cs, *.vb, *.dll)|*.cs;*.vb;*.dll|C# Source (*.cs)|*.cs|Visual Basic Source (*.vb)|*.vb|.NET Assemblies (*.dll)|*.dll"; if (dialog.ShowDialog() != DialogResult.OK) { return; } fileName = dialog.FileName; } if (fileName.CaselessEnds(".dll")) { Assembly lib = IScripting.LoadAssembly(fileName); LoadCommands(lib); return; } ICompiler engine = fileName.CaselessEnds(".cs") ? ICompiler.CS : ICompiler.VB; if (!File.Exists(fileName)) { return; } ConsoleHelpPlayer p = new ConsoleHelpPlayer(); CompilerResults result = engine.Compile(fileName, null); if (result.Errors.HasErrors) { ICompiler.SummariseErrors(result, p); string body = "\r\n\r\n" + Colors.StripUsed(p.Messages); Popup.Error("Compilation error. See logs/errors/compiler.log for more details." + body); return; } LoadCommands(result.CompiledAssembly); }
Assembly CompileCommands(string path) { ICompiler compiler = GetCompiler(path); if (compiler == null) { Popup.Warning("Unsupported file '" + path + "'"); return(null); } ConsoleHelpPlayer p = new ConsoleHelpPlayer(); CompilerResults result = compiler.Compile(path, null); if (!result.Errors.HasErrors) { return(result.CompiledAssembly); } ICompiler.SummariseErrors(result, p); string body = "\r\n\r\n" + Colors.StripUsed(p.Messages); Popup.Error("Compilation error. See logs/errors/compiler.log for more details." + body); return(null); }
void btnLoad_Click(object sender, EventArgs e) { List <Command> commands = null; string fileName; using (FileDialog dialog = new OpenFileDialog()) { dialog.RestoreDirectory = true; dialog.Filter = "Accepted File Types (*.cs, *.vb, *.dll)|*.cs;*.vb;*.dll|C# Source (*.cs)|*.cs|Visual Basic Source (*.vb)|*.vb|.NET Assemblies (*.dll)|*.dll"; if (dialog.ShowDialog() != DialogResult.OK) { return; } fileName = dialog.FileName; } if (fileName.CaselessEnds(".dll")) { byte[] data = File.ReadAllBytes(fileName); Assembly lib = Assembly.Load(data); commands = IScripting.LoadTypes <Command>(lib); } else { IScripting engine = fileName.CaselessEnds(".cs") ? IScripting.CS : IScripting.VB; if (!File.Exists(fileName)) { return; } ConsoleHelpPlayer p = new ConsoleHelpPlayer(); CompilerParameters args = new CompilerParameters(); args.GenerateInMemory = true; CompilerResults result = engine.Compile(fileName, args, p); if (result.Errors.HasErrors) { string body = "\r\n\r\n" + Colors.StripUsed(p.Messages); Popup.Error("Compilation error. See logs/errors/compiler.log for more details." + body); return; } commands = IScripting.LoadTypes <Command>(result.CompiledAssembly); } 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]; if (lstCommands.Items.Contains(cmd.name)) { Popup.Warning("Command " + cmd.name + " already exists, so was not loaded"); continue; } lstCommands.Items.Add(cmd.name); Command.Register(cmd); Logger.Log(LogType.SystemActivity, "Added " + cmd.name + " to commands"); } }