/// <summary>Creates a script by file name.</summary> /// <param name="scriptName">The name of the script file to execute.</param> /// <param name="system">The command system to get the script for.</param> /// <param name="status">A status output.</param> /// <returns>A command script, or null of the file does not exist.</returns> public static CommandScript GetByFileName(string scriptName, ScriptEngine system, out string status) { try { string fileName = system.ScriptsFolder + "/" + scriptName + "." + system.FileExtension; CommandScript script = ScriptParser.SeparateCommands(scriptName, system.Context.ReadTextFile(fileName), system); if (script == null) { status = "Failed To Parse"; } else { status = "Valid"; } return(script); } catch (System.IO.FileNotFoundException) { status = "File Not Found"; return(null); } catch (Exception ex) { FreneticScriptUtilities.CheckException(ex); system.Context.BadOutput("Generating script for file '" + scriptName + "': " + ex.ToString()); status = "Internal Exception"; return(null); } }
/// <summary>Get a binary tag relevant to the specified input, erroring on the command system if invalid input is given (Returns null in that case).</summary> /// <param name="dat">The TagData used to construct this BinaryTag.</param> /// <param name="input">The input text to create binary data from.</param> /// <returns>The binary tag.</returns> public static BinaryTag For(TagData dat, string input) { try { return(new BinaryTag(StringToBytes(input))); } catch (Exception ex) { FreneticScriptUtilities.CheckException(ex); dat.Error("Invalid binary data: '" + input + "'!"); return(null); } }
/// <summary>Run this command stack.</summary> /// <param name="queue">The queue to run under.</param> /// <param name="runnable">The runnable to run.</param> /// <returns>Whether to continue looping.</returns> public CommandStackRetVal Run(CommandQueue queue, CompiledCommandRunnable runnable) { runnable.CurrentQueue = queue; try { runnable.Run(queue); runnable.Index++; if (queue.Delayable && ((queue.Wait > 0f) || queue.WaitingOn != null)) { return(CommandStackRetVal.BREAK); } runnable.Callback?.Invoke(); if (queue.RunningStack.Count == 0) { return(CommandStackRetVal.BREAK); } if (queue.RunningStack.Peek() != runnable) { return(CommandStackRetVal.CONTINUE); } if (runnable.Index >= Entries.Length) { queue.RunningStack.Pop(); } if (queue.RunningStack.Count == 0) { return(CommandStackRetVal.STOP); } return(CommandStackRetVal.CONTINUE); } catch (Exception ex) { FreneticScriptUtilities.CheckException(ex); if (!(ex is ErrorInducedException eie && string.IsNullOrEmpty(eie.Message))) { try { if (ex is ErrorInducedException) { queue.HandleError(Entries[runnable.Index], ex.Message); } else { queue.HandleError(Entries[runnable.Index], "Internal exception:\n------\n" + ex.ToString() + "\n------"); } } catch (Exception ex2) { if (ex2 is ThreadAbortException) { throw; } if (ex2 is not ErrorInducedException) { string message = ex2.ToString(); if (runnable.Debug <= DebugMode.MINIMAL) { queue.Engine.Context.BadOutput(message); if (queue.Outputsystem != null) { queue.Outputsystem.Invoke(message, MessageType.BAD); } runnable.Index = Entries.Length + 1; queue.RunningStack.Clear(); } } } } if (queue.RunningStack.Count > 0) { if (queue.RunningStack.Peek() == runnable) { queue.RunningStack.Pop(); } return(CommandStackRetVal.CONTINUE); } return(CommandStackRetVal.STOP); } finally { runnable.CurrentQueue = null; } }