//------------------------------------------ // EXECUTION //----------------------------------------- #region Execution /// <summary> /// Executes this instance with result. /// </summary> /// <param name="resultString">The result to get.</param> /// <param name="appScope">The application scope to consider.</param> /// <param name="scriptVariableSet">The script variable set to use.</param> /// <param name="runtimeMode">The runtime mode to consider.</param> /// <returns>The log of execution log.</returns> public override ILog ExecuteWithResult( out string resultString, IAppScope appScope = null, IScriptVariableSet scriptVariableSet = null, RuntimeMode runtimeMode = RuntimeMode.Normal) { resultString = ""; ILog log = appScope.Check(true); if (this.Reference == null) { log.AddWarning( title: "Reference missing", description: "No reference defined in command '" + this.Key() + "'."); } else if (!log.HasErrorsOrExceptions() && this.Reference != null) { scriptVariableSet.SetValue("currentItem", this.Reference.SourceElement.GetObject()); scriptVariableSet.SetValue("currentElement", this.Reference.SourceElement); resultString = this.Reference.Get(appScope, scriptVariableSet, log)?.ToString(); } return(log); }
//------------------------------------------ // EXECUTION //----------------------------------------- #region Execution /// <summary> /// Executes this instance with result. /// </summary> /// <param name="resultString">The result to get.</param> /// <param name="appScope">The application scope to consider.</param> /// <param name="scriptVariableSet">The script variable set to use.</param> /// <param name="runtimeMode">The runtime mode to consider.</param> /// <returns>The log of execution log.</returns> public override ILog ExecuteWithResult( out string resultString, IAppScope appScope = null, IScriptVariableSet scriptVariableSet = null, RuntimeMode runtimeMode = RuntimeMode.Normal) { resultString = ""; ILog log = appScope.Check(false); if (!log.HasErrorsOrExceptions()) { if (string.IsNullOrEmpty(this._script)) { log.AddWarning( title: "Script missing", description: "No script defined in command '" + this.Key() + "'."); } else { appScope.ScriptInterpreter.Evaluate(this._script, out resultString, scriptVariableSet, log); } } return(log); }
public void GenerateMakeDependencies(ILog log) { if (File.Exists(Program.RunConfig.ppDepOutput)) { File.Delete(Program.RunConfig.ppDepOutput); } foreach (string file in fileList) { if (file.Contains(' ')) { log.AddWarning("[Make Dependencies] Included file path `{0}` contains spaces. Ignoring.", file); } } using (FileStream fileStream = File.OpenWrite(Program.RunConfig.ppDepOutput)) { using (StreamWriter output = new StreamWriter(fileStream)) { output.Write(Program.RunConfig.outputFile); foreach (string target in Program.RunConfig.ppDepTargets) { output.Write(' '); output.Write(target); } output.Write(": "); output.Write(IO.IOHelpers.GetRelativePath(Environment.CurrentDirectory, Path.GetFullPath(Program.RunConfig.inputFile))); foreach (string file in this.fileList) { if (file.Contains(' ')) { continue; } output.Write(' '); output.Write(file); } output.WriteLine(); if (Program.RunConfig.ppDepAddEmptyTargets) { foreach (string file in this.fileList) { if (file.Contains(' ')) { continue; } output.Write(file); output.WriteLine(':'); } } } } }
// ------------------------------------------ // EXECUTING // ------------------------------------------ #region Executing /// <summary> /// Executes this instance with result. /// </summary> /// <param name="resultString">The result to get.</param> /// <param name="appScope">The application scope to consider.</param> /// <param name="scriptVariableSet">The script variable set to use.</param> /// <param name="runtimeMode">The runtime mode to consider.</param> /// <returns>The log of execution log.</returns> public override ILog ExecuteWithResult( out string resultString, IAppScope appScope = null, IScriptVariableSet scriptVariableSet = null, RuntimeMode runtimeMode = RuntimeMode.Normal) { resultString = ""; ILog log = appScope.Check(true); if (string.IsNullOrEmpty(this.FileName)) { log.AddWarning( title: "File name missing", description: "No file name defined in command '" + this.Key() + "'."); } else if (!log.HasErrorsOrExceptions()) { try { Process process = new Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.FileName = this.FileName; process.StartInfo.Arguments = this.ArgumentString; process.StartInfo.WorkingDirectory = this.WorkingDirectory; process.Start(); resultString = process.StandardOutput.ReadToEnd(); process.WaitForExit(); } catch (Exception ex) { log.AddException(ex); } } return(log); }
private static ProgramRunConfig ReadProgramArguments(string[] args, ILog log) { IEnumerator <string> it = args.AsEnumerable().GetEnumerator(); if (!it.MoveNext()) { Program.PrintUsage(); return(null); } ProgramRunConfig result = new ProgramRunConfig(); // First argument is always what kind of exec we want switch (it.Current) { case "doc": result.execType = ProgramRunConfig.RunExecType.GenDoc; break; case "plusplus": result.execType = ProgramRunConfig.RunExecType.GenNppHighlight; break; case "prognotepad": result.execType = ProgramRunConfig.RunExecType.GenPNHighlight; break; case "A": case "assemble": result.execType = ProgramRunConfig.RunExecType.Assemble; break; case "D": case "disassemble": result.execType = ProgramRunConfig.RunExecType.Disassemble; break; default: log.AddError("Unknown run mode `{0}`", it.Current); return(null); } // For Assembling & Disassembling, second argument is what game we're doing that for switch (result.execType) { case ProgramRunConfig.RunExecType.Assemble: case ProgramRunConfig.RunExecType.Disassemble: if (!it.MoveNext()) { log.AddError("You need to specify a game for which to (dis)assemble!"); return(null); } result.language = it.Current; break; } // From now on, the argument order doesn't matter while (it.MoveNext()) { // -quiet if (it.Current.Equals("-quiet")) { result.quiet = true; continue; } // -raws <file> if (it.Current.Equals("-raws")) { if (!it.MoveNext()) { log.AddError("`-raws` passed without specifying a path."); return(null); } if (!result.TrySetRawsPath(it.Current)) { log.AddError("File or folder `{0}` doesn't exist.", it.Current); return(null); } continue; } // -raws:<file> if (it.Current.StartsWith("-raws:")) { string path = it.Current.Substring("-raws:".Length); if (!result.TrySetRawsPath(path)) { log.AddError("File or folder `{0}` doesn't exist.", path); return(null); } continue; } // -rawsExt <ext> if (it.Current.Equals("-rawsExt")) { if (!it.MoveNext()) { log.AddError("`-rawsExt` passed without specifying an extension."); return(null); } if (it.Current.ContainsAnyOf(Path.GetInvalidFileNameChars())) { log.AddError("`{0}` isn't valid as a file extension.", it.Current); return(null); } result.rawsExtension = it.Current; continue; } // -rawsExt:<ext> if (it.Current.StartsWith("-rawsExt:")) { string ext = it.Current.Substring("-rawsExt:".Length); if (ext.ContainsAnyOf(Path.GetInvalidFileNameChars())) { log.AddError("`{0}` isn't valid as a file extension.", ext); return(null); } result.rawsExtension = ext; continue; } // -input <file> if (it.Current.Equals("-input")) { if (!it.MoveNext()) { log.AddError("`-input` passed without specifying a file."); return(null); } if (!File.Exists(it.Current)) { log.AddError("File `{0}` doesn't exist.", it.Current); return(null); } result.inputFile = it.Current; continue; } // -input:<file> if (it.Current.StartsWith("-input:")) { string file = it.Current.Substring("-input:".Length); if (!File.Exists(file)) { log.AddError("File `{0}` doesn't exist.", file); return(null); } result.inputFile = file; continue; } // -output <file> if (it.Current.Equals("-output")) { if (!it.MoveNext()) { log.AddError("`-output` passed without specifying a file."); return(null); } if (!IsValidFileName(it.Current)) { log.AddError("`{0}` isn't a valid file name.", it.Current); return(null); } result.outputFile = it.Current; continue; } // -output:<file> if (it.Current.StartsWith("-output:")) { string file = it.Current.Substring("-output:".Length); if (!IsValidFileName(file)) { log.AddError("`{0}` isn't a valid file name", file); return(null); } result.outputFile = file; continue; } // -error <file> if (it.Current.Equals("-error")) { if (!it.MoveNext()) { log.AddError("`-error` passed without specifying a file."); return(null); } if (!IsValidFileName(it.Current)) { log.AddError("`{0}` isn't a valid file name.", it.Current); return(null); } result.errorFile = it.Current; continue; } // -error:<file> if (it.Current.StartsWith("-error:")) { string file = it.Current.Substring("-error:".Length); if (!IsValidFileName(file)) { log.AddError("`{0}` isn't a valid file name.", file); return(null); } result.errorFile = file; continue; } // special disassembly-specific parameters if (result.execType == ProgramRunConfig.RunExecType.Disassemble) { // -addEndGuards if (it.Current.Equals("-addEndGuards")) { result.addEndGuards = true; continue; } DisassemblyMode dMode; if (it.Current.TryGetEnum <DisassemblyMode> (out dMode)) { result.disassemblyMode = dMode; continue; } int dOffset; if (result.disassemblyOffset < 0 && it.Current.TryGetValue(out dOffset)) { result.disassemblyOffset = dOffset; continue; } Priority dPriority; if (it.Current.TryGetEnum <Priority> (out dPriority)) { result.disassemblyPriority = dPriority; continue; } int dSize; if (result.disassemblyMode == DisassemblyMode.Block && it.Current.TryGetValue(out dSize)) { result.disassemblySize = dSize; continue; } } // special assembly-specific parameters if (result.execType == ProgramRunConfig.RunExecType.Assemble) { // -symOutput <file> if (it.Current.Equals("-symOutput")) { if (!it.MoveNext()) { log.AddError("`-symOutput` passed without specifying a file."); return(null); } if (!IsValidFileName(it.Current)) { log.AddError("`{0}` isn't a valid file name.", it.Current); return(null); } result.symbolOutputFile = it.Current; continue; } // -symOutput:<file> if (it.Current.StartsWith("-symOutput:")) { string file = it.Current.Substring("-symOutput:".Length); if (!IsValidFileName(file)) { log.AddError("`{0}` isn't a valid file name", file); return(null); } result.symbolOutputFile = file; continue; } // -M if (it.Current.Equals("-M")) { result.ppSimulation = true; result.ppDepEnable = true; continue; } // -MM if (it.Current.Equals("-MM")) { result.ppSimulation = true; result.ppDepEnable = true; result.ppDepIgnoreSystemFiles = true; continue; } // -MD if (it.Current.Equals("-MD")) { result.ppDepEnable = true; continue; } // -MMD if (it.Current.Equals("-MMD")) { result.ppDepEnable = true; result.ppDepIgnoreSystemFiles = true; continue; } // -MG if (it.Current.Equals("-MG")) { result.ppDepIgnoreMissingFiles = true; continue; } // -MP if (it.Current.Equals("-MP")) { result.ppDepAddEmptyTargets = true; continue; } // -MF <file> if (it.Current.Equals("-MF")) { if (!it.MoveNext()) { log.AddError("`-MF` passed without specifying a file."); return(null); } if (!IsValidFileName(it.Current)) { log.AddError("`{0}` isn't a valid file name.", it.Current); return(null); } result.ppDepOutput = it.Current; continue; } // -MF:<file> if (it.Current.StartsWith("-MF:")) { string file = it.Current.Substring("-MF:".Length); if (!IsValidFileName(file)) { log.AddError("`{0}` isn't a valid file name.", file); return(null); } result.ppDepOutput = file; continue; } // -MT <name> if (it.Current.Equals("-MT")) { if (!it.MoveNext()) { log.AddError("`-MT` passed without specifying a target."); return(null); } if (it.Current.Length <= 0) { result.ppDepTargets.Clear(); } else { result.ppDepTargets.Add(it.Current); } continue; } // -MT:<name> if (it.Current.StartsWith("-MT:")) { string name = it.Current.Substring("-MT:".Length); if (name.Length <= 0) { result.ppDepTargets.Clear(); } else { result.ppDepTargets.Add(name); } continue; } } // special docgen-specific parameters if (result.execType == ProgramRunConfig.RunExecType.GenDoc) { // -docHeader <file> if (it.Current.Equals("-docHeader")) { if (!it.MoveNext()) { log.AddError("`-docHeader` passed without specifying a file."); return(null); } if (!File.Exists(it.Current)) { log.AddError("File `{0}` doesn't exist.", it.Current); return(null); } result.docHeader = it.Current; continue; } // -docHeader:<file> if (it.Current.StartsWith("-docHeader:")) { string file = it.Current.Substring("-docHeader:".Length); if (!File.Exists(file)) { log.AddError("File `{0}` doesn't exist.", file); return(null); } result.docHeader = file; continue; } // -docFooter <file> if (it.Current.Equals("-docFooter")) { if (!it.MoveNext()) { log.AddError("`-docFooter` passed without specifying a file."); return(null); } if (!File.Exists(it.Current)) { log.AddError("File `{0}` doesn't exist.", it.Current); return(null); } result.docFooter = it.Current; continue; } // -docFooter:<file> if (it.Current.StartsWith("-docFooter:")) { string file = it.Current.Substring("-docFooter:".Length); if (!File.Exists(file)) { log.AddError("File `{0}` doesn't exist.", file); return(null); } result.docFooter = file; continue; } } log.AddWarning("Unhandled parameter `{0}`. Ignoring.", it.Current); } return(result); }