public static void Execute(ProgramExecutionOptions options) { if (ProgramUtil.ShowHelpIfNeeded(options)) { return; } if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations)) { var path = options.ParsedArguments[0].Value; HashDir dir; HashFile file; if (FileSystem.DirExists(path, out dir)) { FileSystem.ChangeDir(dir); } else if (FileSystem.FileExistsAndIsAvailable(path, out file)) { var msg = string.Format("The path '{0}' points to a file. Use 'open {0}' to open this file.", path); msg = TextUtil.Warning(msg); TerminalUtil.ShowText(msg); } else { var msg = string.Format("The path '{0}' points nowhere. Please supply a valid path.", path); msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } } else { string msg = null; var result = PathValidation.ValidationResult; if (MathUtil.ContainsFlag((int)result, (int)ArgValidationResult.EmptyValue)) { msg = "Please supply a path."; } else if (MathUtil.ContainsFlag((int)result, (int)ArgValidationResult.NotFound)) { msg = "Please supply a path."; } msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } }
public static void Execute(ProgramExecutionOptions options) { if (ProgramUtil.ShowHelpIfNeeded(options)) { return; } if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations)) { Pair <string, string> pathArg; // no need to validate this because the argument is required CommandLineUtil.TryGetArgumentByName(options.ParsedArguments, PathArgName, out pathArg); var path = pathArg.Value; bool openOnTerminal = CommandLineUtil.ArgumentExists(options.ParsedArguments, TerminalArgName); HashFile file; HashDir dir; if (FileSystem.FileExistsAndIsAvailable(path, out file)) { var permission = FileSystem.GetAccessPermission(file); if (permission < AccessPermission.Editable) { var msg = "You don't have permission to open this file."; msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } else { switch (file.FileType) { case HashFileType.Text: var textFile = file.Content as TextFile; OpenTextFile(file, textFile, openOnTerminal); break; case HashFileType.Image: var imageFile = file.Content as ImageFile; OpenImageFile(file, imageFile, openOnTerminal); break; default: DebugUtil.Error(string.Format("The open program can't open file type: {0}", file.FileType)); break; } } } else { string msg; if (FileSystem.DirExists(path, out dir)) { msg = "The path '{0}' points to a directory. Please use 'cd {0}' to navigate to that directory."; } else { msg = "The path '{0}' points to nowhere. Please supply a valida path."; } msg = string.Format(msg, path); msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } } else { string msg = "Please supply a file path."; msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } }
/// <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(); } }