static void Main(string[] args) { //фиксируем размеры окна, чтобы нельзя было его изменить WindowUtility.FixeConsoleWindow(Configuration.ConsoleHeight, Configuration.ConsoleWidth); //рисуем рамку для основной панели с папками/файлами ConsoleDrawings.PrintFrameLines(0, 0, Console.WindowWidth, Configuration.MainPanelHeight); ConsoleDrawings.PrintFrameLines(0, Configuration.MainPanelHeight, Console.WindowWidth, Configuration.InfoPanelHeight); //считывание сохраненного пути с последнего сеанса работы if (File.Exists("last.state")) { using (StreamReader sr = new StreamReader("last.state")) //File.OpenText(inputFile)) { string strState = ""; try { strState = sr.ReadLine(); } catch (Exception) { CurrentPath = "C:\\"; } CurrentPath = strState; } } else { CurrentPath = "C:\\"; } ConsoleDrawings.PrintFoldersTree(CurrentPath, CurrentFoldersFiles, 1); //справка: ConsoleDrawings.PrintInformation("help - список всех поддерживаемых комманд"); bool exit = false; List <string> arguments = new List <string>(); while (!exit) { ConsoleDrawings.TakeNewCommand(); currentCommand = Console.ReadLine(); ConsoleDrawings.ClearMessageLine(); arguments.Clear();//по завершении обработки команды очищаем список аргументов, чтобы корректно обработать следующую команду arguments.AddRange(currentCommand.Split(' ')); string theCommand = arguments[0]; arguments.Remove(theCommand); switch (theCommand.ToLower().Trim()) { case "exit": SaveLastState(); exit = true; break; case "ls": LSCommand(arguments); break; case "cp": CPCommand(arguments); break; case "rm": RMCommand(arguments); break; case "file": FILECommand(arguments); break; case "help": ConsoleDrawings.PrintInformation("Поддерживаемые команды: exit; ls; cp; rm; file. Введите команду с ключом /? чтобы получить подробное описание"); break; case "": arguments.Clear(); break; default: ConsoleDrawings.PrintWarning($"Невозможно обработать команду {theCommand}"); arguments.Clear(); break; } } }
public static void PrintInformation(string rootFolder, List <FileSystemInfo> content) { ClearInformationPanel(); int positionX, positionY; positionX = 2; positionY = Configuration.MainPanelHeight + 1; Console.SetCursorPosition(positionX, positionY); positionY++; Console.ForegroundColor = infoColor; Console.BackgroundColor = textBackgroundColor; Console.WriteLine($" Путь: {rootFolder}"); DirectoryInfo di = new DirectoryInfo(rootFolder); Console.SetCursorPosition(positionX, positionY); positionY++; Console.WriteLine($" Дата создания: {di.CreationTime.ToString("dd.MM.yyyy")}"); Console.SetCursorPosition(positionX, positionY); positionY++; Console.WriteLine($" Последнее изменение: {di.LastWriteTime.ToString("dd.MM.yyyy")}"); string attributes; if (rootFolder.Length > 4) { attributes = " Атрибуты: "; if (di.Attributes.HasFlag(FileAttributes.ReadOnly)) { attributes += "Только для чтения | "; } if (di.Attributes.HasFlag(FileAttributes.Archive)) { attributes += "Архивный | "; } if (di.Attributes.HasFlag(FileAttributes.System)) { attributes += "Системный | "; } if (di.Attributes.HasFlag(FileAttributes.Hidden)) { attributes += "Скрытый | "; } if (attributes != " Атрибуты: ") { attributes = attributes.Substring(0, attributes.Length - 3); Console.SetCursorPosition(positionX, positionY); positionY++; Console.WriteLine(attributes); } } else { try { DriveInfo drive = new DriveInfo(rootFolder); Console.SetCursorPosition(positionX, positionY); positionY++; Console.WriteLine($"Доступно места на диске: {ToPrettySize(drive.AvailableFreeSpace)}"); Console.SetCursorPosition(positionX, positionY); positionY++; Console.WriteLine($" Метка диска: {drive.VolumeLabel}"); } catch (Exception) { } } //Подсчитываем размер текущей директории в потоке, чтобы можно было остановить его, в случае смены директории long fullDirSize = 0; if (CalculateFolderSize != null) { cancelTokenSource.Cancel(); } Action <object> action = (object obj) => { GetTotalSize(rootFolder, ref fullDirSize, token); string size; try { size = ToPrettySize(fullDirSize); } catch (Exception) { size = "0"; } if (fullDirSize != -1) { Console.SetCursorPosition(positionX, positionY); Console.Write(new string(' ', Configuration.ConsoleWidth - 3)); Console.SetCursorPosition(positionX, positionY); positionY++; Console.ForegroundColor = infoColor; Console.BackgroundColor = textBackgroundColor; Console.WriteLine($" Общий объем: {size}"); } ConsoleDrawings.TakeNewCommand(); }; try { cancelTokenSource = new CancellationTokenSource(); token = cancelTokenSource.Token; Console.SetCursorPosition(positionX, positionY); Console.ForegroundColor = infoColor; Console.BackgroundColor = textBackgroundColor; Console.WriteLine($" Общий объем: <расчитывается...>"); CalculateFolderSize = Task.Factory.StartNew(action, token); ConsoleDrawings.TakeNewCommand(); } catch (Exception e) { //PrintError(e.Message); } }