private void SetPathType() { if (string.IsNullOrWhiteSpace(OriginalPath)) { Type = PathType.Unresolved; Path = ""; return; } if (PathVariables.ContainsAction(OriginalPath)) { Path = OriginalPath; Type = PathType.ActionVariable; return; } var parsedPath = PathVariables.GetReplacedPath(OriginalPath); if (!Uri.TryCreate(parsedPath, UriKind.Absolute, out var pathUri)) { TryResolvePath(parsedPath); return; } if (!pathUri.IsFile) // try to open using explorer.exe { Type = PathType.UnknownProtocol; Path = pathUri.AbsoluteUri; } else { Type = PathType.File; Path = pathUri.LocalPath; } }
public static void Start(string path, string arguments) { var resolver = new PathResolver(path); if (resolver.Type != PathType.File) throw new InvalidOperationException("Only file paths support specifying arguments."); var args = PathVariables.GetReplacedPath(arguments); OpenFile(resolver.Path, args); }
public static void Start(PathResolver path) { switch (path.Type) { case PathType.Unresolved: throw new InvalidOperationException($"Could not resolve path '{path.OriginalPath}', try specifying the protocol (e.g. 'http://')."); case PathType.File: case PathType.Directory: OpenFile(path.Path); break; case PathType.Web: case PathType.UnknownProtocol: OpenUsingExplorer(path.Path); break; case PathType.ActionVariable: PathVariables.TryExecute(path.Path); break; default: throw new ArgumentOutOfRangeException(nameof(path), path, $"'{nameof(path)}' resolved to unknown {nameof(PathType)}."); } }