Ejemplo n.º 1
0
        //Получение доступных дисков
        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;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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();
                }
            }
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
        //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();
        }
Ejemplo n.º 8
0
 public Files(NodeLinkedList directory)
 {
     GetListOfFiles(directory);
 }
Ejemplo n.º 9
0
 public Directories(NodeLinkedList drive)
 {
     GetDirectories(drive);
     GetSubDirs(StartDirectory.StartNode.Value, 0);
 }