public static void ParseCommand(string command) { if (string.IsNullOrWhiteSpace(command)) { return; } string[] commandParts = command.Split(' '); if (commandParts.Length >= 2 && commandParts[0].ToLower() == "ls" && FMLib.isDirectoryExist(commandParts[1])) { currentDirectory = FMLib.GetFullPath(commandParts[1]); if (commandParts.Length == 4 && commandParts[2] == "-p" && Int32.TryParse(commandParts[3], out int p)) { page = p; } else { page = 1; } } if (commandParts.Length >= 2 && commandParts[0].ToLower() == "cd" && FMLib.isDirectoryExist(commandParts[1])) { currentDirectory = FMLib.GetFullPath(commandParts[1]); FMLib.ChangeDirectory(FMLib.GetFullPath(commandParts[1])); page = 1; } if (commandParts.Length == 2 && commandParts[0].ToLower() == "info") { currentInfoItem = FMLib.GetFullPath(commandParts[1]); } if (commandParts.Length == 3 && commandParts[0].ToLower() == "copy") { try { FMLib.Copy(commandParts[1], commandParts[2]); } catch (Exception ex) { WriteEvent(ex.Message); } } if (commandParts.Length == 2 && commandParts[0].ToLower() == "delete") { try { FMLib.Delete(commandParts[1]); } catch (Exception ex) { WriteEvent(ex.Message); } } }
static List <string> history = new List <string>(); // saved commands typed by user public static void Run() { LoadSettings(); string command = null; while (command != "exit") { Console.Clear(); ContentPanel content = new ContentPanel(); try { //по идее это надо заталкать в конструктор, но мы их еще не проходили, поэтому оставлю тут content.folderPath = FMLib.GetFullPath(currentDirectory); content.folderContent = FormatDirectoryListing(content.folderPath, page); } catch (Exception ex) { content.folderContent = new List <string>(); WriteEvent(ex.Message); } InfoPanel info = new InfoPanel() { path = currentInfoItem }; try { //и это тоже info.attr = FMLib.GetAttributes(info.path); info.dataTimes = FMLib.GetTimes(info.path); info.size = FMLib.GetSizeOnDisk(info.path); } catch { info = null; } ShowGUI(content, info); //command = Console.ReadLine(); command = ReadCommand(); ParseCommand(command); } SaveSettings(); }