private int ResolveNonQuoted(string value, string workingDir, out string fullCommandPath) { if (PathResolveHelper.IsAbsolutePath(value)) { return(ResolveAbsoluteNonQuoted(value, out fullCommandPath)); } else { return(ResolveRelativeNonQuoted(value, workingDir, out fullCommandPath)); } }
private static bool SeachOnPath(string path, out string fullPath) { StringBuilder sb = new StringBuilder(path, PathResolveHelper.MaxPath); if (NativeMethods.PathFindOnPath(sb, null)) { var mbpath = sb.ToString(); if (PathResolveHelper.Exists(mbpath, out fullPath)) { return(true); } } fullPath = null; return(false); }
private static int ResolveAbsoluteNonQuoted(string value, out string fullCommandPath) { foreach (var segment in GetSegments(value)) { bool relaxed = segment.HasExtension || segment.Final; if (PathResolveHelper.TryResolveAbsolutePath(segment.Path, segment.HasExtension, relaxed, out fullCommandPath)) { return(segment.Index); } } fullCommandPath = null; return(-1); }
protected static IEnumerable <PathSegment> GetSegments(string value) { int startIx = 0; while (startIx < value.Length && char.IsWhiteSpace(value[startIx])) { startIx++; } int endIx = value.Length - 1; while (endIx >= 0 && char.IsWhiteSpace(value[endIx])) { endIx--; } for (; startIx < endIx; startIx++) { if (char.IsWhiteSpace(value[startIx])) { var segment = value.Substring(0, startIx); var hasExtension = PathResolveHelper.HasWhatLookLikeExtesion(segment); yield return(new PathSegment { Path = segment, HasExtension = PathResolveHelper.HasWhatLookLikeExtesion(segment), Index = startIx - 1 }); if (hasExtension) { yield break; } } } yield return(new PathSegment { Path = value, HasExtension = PathResolveHelper.HasWhatLookLikeExtesion(value), Final = true, Index = value.Length - 1 }); }
private static bool TrySeachInPath(string path, string fileName, string extension, out string fullPath) { StringBuilder sb = new StringBuilder(PathResolveHelper.MaxPath); NativeMethods.SearchPath(path, fileName, extension, sb.Capacity, sb, out var ptr); if (ptr != IntPtr.Zero) { if (PathResolveHelper.Exists(sb.ToString(), out fullPath)) { return(true); } } fullPath = null; return(false); }
private int ResolveQuoted(string value, string workingDir, out string fullCommandPath) { fullCommandPath = null; if (value.Length == 1) { return(-1); } var closeIx = value.IndexOf('"', 1); if (closeIx == -1) { return(-1); } value = value.Substring(1, closeIx - 1); if (string.IsNullOrEmpty(value)) { return(-1); } if (PathResolveHelper.IsAbsolutePath(value)) { var hasExtesion = PathResolveHelper.HasWhatLookLikeExtesion(value); if (PathResolveHelper.TryResolveAbsolutePath(value, hasExtesion, true, out fullCommandPath)) { return(closeIx); } } else { if (ResolveRelativeQuoted(value, workingDir, out fullCommandPath)) { return(closeIx); } } return(-1); }
private static bool TryResolveRelative(string path, string workingDir, out string fullPath) { bool hasExt = PathResolveHelper.HasWhatLookLikeExtesion(path); var self = Enumerable.Repeat(string.Empty, 1); var extesions = hasExt ? self : PathResolveHelper.PathExt.Concat(self); foreach (var extension in extesions) { if (TrySeachInPath(workingDir, path, extension, out fullPath)) { return(true); } if (TrySeachInPath(null, path, extension, out fullPath)) { return(true); } } fullPath = null; return(false); }