/// <summary> /// Converts <see cref="Operation"/> to a well-formed string that can be used as command line input /// </summary> public string ToCommandLine(PathTable pathTable, bool escapeResult = false) { PathTable = pathTable; StringBuilder sb = new StringBuilder(); sb.Append(((int)OpType).ToString(System.Globalization.CultureInfo.CurrentCulture)); var orderOfArgs = new string[] { Path.IsValid?FileOrDirectoryToString(Path) : null, Content, LinkPath.IsValid ? FileOrDirectoryToString(LinkPath) : null, SymLinkFlag.ToString(), AdditionalArgs // The process as a test executable does not use the DoNotInfer field }; foreach (var arg in orderOfArgs) { sb.Append(OperationArgsDelimiter); if (arg != null) { sb.Append(arg.ToString()); } } return(escapeResult ? CommandLineEscaping.EscapeAsCommandLineWord(sb.ToString()) : sb.ToString()); }
/// <summary> /// Returns the length of a StringId when rendered to string using given <paramref name="escaping"/>. /// </summary> public int GetLength(StringId stringId, PipDataFragmentEscaping escaping) { switch (escaping) { case PipDataFragmentEscaping.CRuntimeArgumentRules: // - passing null as StringBuilder to AppendEscapedCommandLineWord is ok // - the return value of AppendEscapedCommandLineWord indicates how many characters would be appended return(CommandLineEscaping.AppendEscapedCommandLineWord(builder: null, word: Render(stringId))); case PipDataFragmentEscaping.NoEscaping: return(StringTable.GetLength(stringId)); // instead of retrieving the whole string, StringTable.GetLength is faster. default: Contract.Assert(false, I($"Unhandled fragmentEscaping: {escaping}")); return(0); } }
private static IEnumerable <string> ConvertArgumentsToStringArray(PipData pipData, PathTable pathTable) { var result = new List <string>(); foreach (PipFragment fragment in pipData) { Contract.Assume(fragment.FragmentType != PipFragmentType.Invalid); string s = string.Empty; switch (fragment.FragmentType) { case PipFragmentType.StringLiteral: s = pathTable.StringTable.GetString(fragment.GetStringIdValue()); break; case PipFragmentType.AbsolutePath: s = fragment.GetPathValue().ToString(pathTable); break; case PipFragmentType.NestedFragment: s = fragment.GetNestedFragmentValue().ToString(pathTable); break; default: Contract.Assert(false, "Unhandled fragment type"); break; } if (pipData.FragmentEscaping == PipDataFragmentEscaping.CRuntimeArgumentRules) { s = CommandLineEscaping.EscapeAsCommandLineWord(s); } s += pathTable.StringTable.GetString(pipData.FragmentSeparator); result.Add(s); } return(result); }
public string GetCommandLine() { m_commandLine = m_commandLine ?? CommandLineEscaping.EscapeAsCreateProcessApplicationName(FileName) + " " + Arguments; return(m_commandLine); }