Пример #1
0
        public bool Parse(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                ActionType = ActionType.ShowHelp;
                return(true);
            }

            List <string> extras;

            try
            {
                extras = _options.Parse(args);
            }
            catch (Exception ex)
            {
                ErrorDetails = ex.Message;
                return(false);
            }

            if (ActionType == ActionType.ShowHelp)
            {
                return(true);
            }

            // Validation
            if (PathType == PathType.Unknown)
            {
                if (!extras.Any())
                {
                    ErrorDetails = "Must specify a directory";
                    return(false);
                }

                PathArgument = extras.First();
                extras.RemoveAt(0);

                PathType = PathType.Directory;
            }

            if (ActionType == ActionType.Unknown)
            {
                ActionType = ActionType.ShowFull;
            }

            if (ShowAllNames && ShowAllStreams)
            {
                ErrorDetails = "--allnames and --streams cannot be used together.";
                return(false);
            }

            // Cleaning
            if (PathType == PathType.Directory)
            {
                Console.WriteLine(PathArgument);
                if ((PathArgument[0] == '"' || PathArgument[0] == '\'') && PathArgument[0] == PathArgument.Last())
                {
                    // Strip quotes
                    PathArgument = PathArgument.Substring(1, PathArgument.Length - 2);
                }

                // Fixup
                if (!Path.IsPathRooted(PathArgument))
                {
                    PathArgument = Path.Combine(Environment.CurrentDirectory, PathArgument);
                }
            }

            if (!char.IsLetter(Drive))
            {
                Drive = PathArgument[0];
            }

            char[] volumes = Utils.GetAllAvailableVolumes().ToArray();

            if (!volumes.Contains(Drive))
            {
                ErrorDetails = "The volume " + Drive + " does not exist.";
                return(false);
            }

            return(true);
        }
Пример #2
0
        public bool Parse(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                ActionType = ActionType.ShowHelp;
                return(true);
            }

            try
            {
                _options.Parse(args);
            }
            catch (Exception ex)
            {
                ErrorDetails = ex.Message;
                return(false);
            }

            if (ActionType == ActionType.ShowHelp)
            {
                return(true);
            }

            // Validation
            if (PathType == PathType.Unknown)
            {
                ErrorDetails = "Must specify either a --file, --dir or an --mftid";
                return(false);
            }

            if (ActionType == ActionType.Unknown)
            {
                ErrorDetails = "Must specify an action, such as --extents, --full or --paths";
                return(false);
            }

            if (ActionType != ActionType.Unknown && PathType == PathType.Unknown)
            {
                ErrorDetails = "Must specify either a --file, --dir or --mftid for --extents, --full or --paths";
                return(false);
            }

            if (!char.IsLetter(Drive) && PathType == PathType.MftId)
            {
                ErrorDetails = "Must specify --volume when using for --mftid";
                return(false);
            }

            // Cleaning
            if (PathType == PathType.File || PathType == PathType.Directory)
            {
                if ((PathArgument[0] == '"' || PathArgument[0] == '\'') && PathArgument[0] == PathArgument.Last())
                {
                    // Strip quotes
                    PathArgument = PathArgument.Substring(1, PathArgument.Length - 2);
                }

                // Fixup
                if (!Path.IsPathRooted(PathArgument))
                {
                    PathArgument = Path.Combine(Environment.CurrentDirectory, PathArgument);
                }
            }

            if (!char.IsLetter(Drive))
            {
                Drive = PathArgument[0];
            }

            char[] volumes = Utils.GetAllAvailableVolumes().ToArray();

            if (!volumes.Contains(Drive))
            {
                ErrorDetails = "The volume " + Drive + " does not exist.";
                return(false);
            }

            return(true);
        }