/// <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(); } }