//Получение доступных дисков private void GetDrives() { var drives = DriveInfo.GetDrives(); NodeLinkedList node = new NodeLinkedList(); for (int i = 0; i < drives.Length; i++) { node.AddNode(drives[i].RootDirectory.Name); } StartDrive = node; }
public NodeLinkedList GetCurrentList(NodeLinkedList drives, NodeLinkedList directories) { var currentList = new NodeLinkedList(); currentList.StartNode.Value = drives.StartNode.Value; var currentNode = directories.StartNode; int count = directories.GetCount(); for (int i = 0; i < count; i++) { currentList.AddNode(currentNode.Value); currentNode = currentNode.NextNode; } return(currentList); }
private void GetDirectories(NodeLinkedList drive) { var path = drive.StartNode.Value; var allDirectories = Directory.GetDirectories(path); var node = new NodeLinkedList(); for (int i = 0; i < allDirectories.Length; i++) { DirectoryInfo dir = new DirectoryInfo(allDirectories[i]); if ((dir.Attributes & FileAttributes.Hidden) == 0) { node.AddNode(allDirectories[i]); } } StartDirectory = node; }
private void GetListOfFiles(NodeLinkedList directory) { var path = directory.StartNode.Value; string[] allFiles = Directory.GetFiles(path); var node = new NodeLinkedList(); for (int i = 0; i < allFiles.Length; i++) { DirectoryInfo dir = new DirectoryInfo(allFiles[i]); if ((dir.Attributes & FileAttributes.Hidden) == 0) { node.AddNode(allFiles[i]); } } StartFiles = node; }
internal void HandleKey(ConsoleKey key) { if (key == ConsoleKey.DownArrow) { if (SubDirectories != null) { Directories directories = new Directories(currentDirectory); SubDirectories = directories.GetSubDirectories(); this.Display(); } else { currentDirectory = listOfDirectories.Dequeue(); this.Display(); } } }
public void GetSubDirs(string path, int index) { //string indent = "\t"; //for (int i = 0; i < index; i++) //{ // indent += "\t"; //} var root = Directory.GetDirectories(path); var node = new NodeLinkedList(); foreach (var dir in root) { DirectoryInfo info = new DirectoryInfo(dir); if ((info.Attributes & FileAttributes.Hidden) == 0) { node.AddNode(dir); GetSubDirs(dir.ToString(), index + 1); } } SubDirectories = node; }
//public Tree(string path) //{ // string[] currentPaths = Deserialize(path); // currentDrive = currentPaths[0]; // currentDirectory = currentPaths[1]; // currentFile = currentPaths[2]; //} ////конструктор вызывается, если на диске нет файла с сохраненными параметрами //public Tree() //{ // Drives drives = new Drives(currentDrive); // currentDrive = drives.currentDrive; //} ////Десериализация файла json //private string[] Deserialize(string path) //{ // string json = File.ReadAllText(path); // string[] currentPaths = JsonSerializer.Deserialize<string[]>(json); // return currentPaths; //} public Tree() //десериализация пустая { //получаем список дисков Drives drives = new Drives(); Drives = drives.GetDriveNames(); //директорией по-умолчанию для отображения назначаем первый диск currentDirectory = Drives; //получаем список директорий Directories directories = new Directories(currentDirectory); Directories = directories.GetDirectoryNames(); CurrentList = drives.GetCurrentList(directories); //получаем список поддиректорий //SubDirectories = directories.GetSubDirectories(); //получаем список файлов выбранного диска listOfDrives[0] Files files = new Files(currentDirectory); Files = files.GetFiles(); }
public Files(NodeLinkedList directory) { GetListOfFiles(directory); }
public Directories(NodeLinkedList drive) { GetDirectories(drive); GetSubDirs(StartDirectory.StartNode.Value, 0); }