public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            if (options.ParsedArguments.Count > 0)
            {
                var programName = options.ParsedArguments[0].Value;
                var program     = Shell.FindProgramByCommand(programName);
                if (program == null)
                {
                    var msg =
                        "'{0}' is not a valid program. You can use 'help' to see help for all programs or 'help <program_name>' to see help about a specific program";
                    msg = TextUtil.ApplyNGUIColor(msg, Constants.Colors.Error);
                    TerminalUtil.ShowText(msg);
                }
                else
                {
                    ShowHelpFor(program);
                    ShowProgramsUsage();
                }
            }
            else
            {
                TerminalUtil.StartTextBatch();

                var programs = ProgramUtil.GetAvailablePrograms(DataHolder.DeviceData.CurrentDevice);
                for (int i = 0; i < programs.Count; i++)
                {
                    var program = programs[i];
                    ShowHelpFor(program);
                }

                ShowProgramsUsage();

                TerminalUtil.EndTextBatch();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Executes the dir program.
        /// </summary>
        public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            HashDir currentDir = null;

            if (options.ParsedArguments.Count == 0)
            {
                currentDir = DataHolder.DeviceData.CurrentDevice.FileSystem.CurrentDir;
            }
            else
            {
                var desiredDirPath = options.ParsedArguments[0].Value;
                if (!FileSystem.DirExists(desiredDirPath, out currentDir))
                {
                    string msg;

                    HashFile file;
                    if (FileSystem.FileExistsAndIsAvailable(desiredDirPath, out file))
                    {
                        msg = string.Format("The path '{0}' points to a file. Use 'open {0}' to open this file.",
                                            desiredDirPath);
                    }
                    else
                    {
                        msg = string.Format("The path '{0}' points nowhere. Please supply a valid path.",
                                            desiredDirPath);
                    }

                    msg = TextUtil.Error(msg);
                    TerminalUtil.ShowText(msg);
                    return;
                }
            }

            var childs = FileSystem.GetAllAvailableChild(currentDir);
            var files  = FileSystem.GetAvailableFilesFromDir(currentDir);

            if (childs.Count == 0 && files.Count == 0)
            {
                var txt = "EMPTY DIRECTORY!";
                txt = TextUtil.ApplyNGUIColor(txt, LineColor);
                TerminalUtil.ShowText(txt);
            }
            else
            {
                TerminalUtil.StartTextBatch();

                TerminalUtil.ShowText(HeaderLine.FormattedText);

                for (int i = 0; i < childs.Count; i++)
                {
                    var child = childs[i];
                    var line  = CreateLine(child.Name, "DIRECTORY", string.Empty, LineColor, TextModifiers.Italic);
                    TerminalUtil.ShowText(line.FormattedText);
                }

                for (int i = 0; i < files.Count; i++)
                {
                    var file = files[i];

                    var status = FileSystem.GetStatusString(file.Status);
                    var line   = CreateLine(file.FullName, "FILE", status, LineColor, TextModifiers.Italic);
                    TerminalUtil.ShowText(line.FormattedText);
                }

                TerminalUtil.EndTextBatch();
            }
        }
        public static void Execute(ProgramExecutionOptions options)
        {
            if (ProgramUtil.ShowHelpIfNeeded(options))
            {
                return;
            }

            if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations))
            {
                Pair <string, string> pathArg     = CommandLineUtil.FindArgumentByName(options.ParsedArguments, PathArgName);
                Pair <string, string> passwordArg = CommandLineUtil.FindArgumentByName(options.ParsedArguments, PasswordArgName);

                var path     = pathArg.Value;
                var password = passwordArg.Value;

                HashFile file = FileSystem.FindFileByPath(path);
                if (file == null)
                {
                    var msg = string.Format("The path '{0}' is not a valid file path.", path);
                    ShowErrorMessage(msg);
                }
                else
                {
                    if (file.Status != FileStatus.Encrypted)
                    {
                        var msg = string.Format("The file '{0}' is not encrypt. You can open it using 'open {0}'", path);
                        msg = TextUtil.ApplyNGUIColor(msg, Constants.Colors.Success);
                        TerminalUtil.ShowText(msg);
                    }
                    else
                    {
                        var filePassword = file.Password;
                        if (string.Equals(password, filePassword))
                        {
                            var msg = string.Format("File '{0}' decrypted successfully. Use 'open {0}' to open the file.", path);
                            msg = TextUtil.ApplyNGUIColor(msg, Constants.Colors.Success);
                            TerminalUtil.ShowText(msg);
                            FileSystem.ChangeFileStatus(file, FileStatus.Normal);
                        }
                        else
                        {
                            var msg = "Invalid password.";
                            ShowErrorMessage(msg);
                        }
                    }
                }
            }
            else
            {
                var pathResult     = (int)PathValidation.ValidationResult;
                var passwordResult = (int)PasswordValidation.ValidationResult;
                if (MathUtil.ContainsFlag(pathResult, (int)ArgValidationResult.NotFound) ||
                    MathUtil.ContainsFlag(pathResult, (int)ArgValidationResult.EmptyValue))
                {
                    var msg = "You need to supply a path. Please use 'help cracker' for more info.";
                    ShowErrorMessage(msg);
                }
                else if (MathUtil.ContainsFlag(passwordResult, (int)ArgValidationResult.NotFound) ||
                         MathUtil.ContainsFlag(passwordResult, (int)ArgValidationResult.EmptyValue))
                {
                    var msg = "You need to supply a password. Please use 'help cracker' for more info.";
                    ShowErrorMessage(msg);
                }
            }
        }