Пример #1
0
 static void ShowDrives(Walls walls)
 {
     walls.Draw();
     string[,] dInfo = GetDrivesInfo();
     if (dInfo == null)
     {
         return;
     }
     int[] colW = Str.GetColumnsWidth(dInfo);
     Console.SetCursorPosition(Const.left, Const.top);
     for (int i = 0; i < dInfo.GetLength(1); i++)
     {
         if (i == 1)//Пустая строка после заголовка
         {
             Console.WriteLine();
             Console.SetCursorPosition(Const.left, Console.CursorTop);
         }
         for (int k = 0; k < dInfo.GetLength(0); k++)
         {
             Console.Write(dInfo[k, i].PadRight(colW[k] + 2));
         }
         Console.WriteLine();
         Console.SetCursorPosition(Const.left, Console.CursorTop);
     }
     ShowInfo("");
 }
Пример #2
0
        static void ShowDirectory(DirectoryInfo startPathInfo, Walls walls)
        {
            walls.Draw();
            Console.SetCursorPosition(Const.left, Const.top);
            Console.WriteLine(Str.GetTitle());
            int           linesOnPage = Properties.Settings.Default.StringsOnPage;
            List <bool>   listIsDir   = new List <bool>();//Признак папки для выделения цветом
            List <string> listForShow = new List <string>();

            try
            {
                System.IO.DirectoryInfo[] subDirs = startPathInfo.GetDirectories();
                System.IO.FileInfo[]      files   = startPathInfo.GetFiles("*.*");
                for (int i = 0; i < subDirs.Count(); i++)
                {
                    listForShow.Add(GetDirFileString(0, subDirs[i]));
                    listIsDir.Add(true);
                    System.IO.DirectoryInfo[] subDirs2;
                    try
                    {
                        subDirs2 = subDirs[i].GetDirectories();
                    }
                    catch (Exception)
                    {
                        subDirs2 = new System.IO.DirectoryInfo[0];
                    }
                    System.IO.FileInfo[] files2;
                    try
                    {
                        files2 = subDirs[i].GetFiles("*.*");
                    }
                    catch (Exception)
                    {
                        files2 = new System.IO.FileInfo[0];
                    }
                    if (Properties.Settings.Default.Level)
                    {
                        FillDirList(listForShow, listIsDir, subDirs2, files2, walls);
                    }
                }
                for (int i = 0; i < files.Length; i++)
                {
                    listForShow.Add(GetDirFileString(0, files[i]));
                    listIsDir.Add(false);
                }
                int totalPages = listForShow.Count / linesOnPage;
                if ((listForShow.Count + listForShow.Count) % linesOnPage != 0)
                {
                    totalPages++;
                }
                Console.ForegroundColor = ConsoleColor.White;
                int pNum = 0;
                ShowList(pNum, totalPages, listForShow, listIsDir, linesOnPage, walls);
            }
            catch (Exception e)
            {
                ShowAndSaveError(e.Message, true);
            }
        }
Пример #3
0
        static void FillDirList(List <string> listForShow, List <bool> listIsDir, System.IO.DirectoryInfo[] dirs, System.IO.FileInfo[] files, Walls walls)
        {
            int mode        = Properties.Settings.Default.ViewMode;
            int linesOnPage = Properties.Settings.Default.StringsOnPage;

            for (int i = 0; i < dirs.Length; i++)
            {
                listForShow.Add(GetDirFileString(1, dirs[i]));
                listIsDir.Add(true);//Это папка
            }
            for (int i = 0; i < files.Length; i++)
            {
                listForShow.Add(GetDirFileString(1, files[i]));
                listIsDir.Add(false);//Это файл
            }
        }
Пример #4
0
        static void ShowList(int pageNum, int totalPages, List <string> ls, List <bool> listIsDir, int max, Walls walls)
        {
            int total = 0;

            for (int i = 0; i < ls.Count; i++)
            {
                if (total == max)
                {
                    pageNum++;
                    Console.SetCursorPosition(2, Const.messPosition + 1);
                    Console.WriteLine($"Страница {pageNum} из {totalPages}");
                    Console.SetCursorPosition(2, Const.messPosition + 2);
                    Console.WriteLine(Str.pressAnyKeyEsc);
                    Console.SetCursorPosition(2, Const.messPosition + 2);
                    ConsoleKeyInfo cki = Console.ReadKey();
                    if (cki.Key == ConsoleKey.Escape)
                    {
                        Console.SetCursorPosition(2, Const.messPosition + 2);
                        Console.WriteLine(Str.viewStopped);
                        return;
                    }
                    walls.Draw();
                    Console.SetCursorPosition(Const.left, Const.top);
                    Console.WriteLine(Str.GetTitle());
                    Console.SetCursorPosition(Const.left, Console.CursorTop);

                    total = 1;
                }
                Console.SetCursorPosition(Const.left, Console.CursorTop);
                if (listIsDir[i])
                {
                    Console.ForegroundColor = ConsoleColor.White;
                }
                ;
                Console.WriteLine(ls[i]);
                Console.ForegroundColor = ConsoleColor.Gray;
                total++;
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            Console.Title = Str.appTitle;
            InitSize();
            InitSettings();
            Walls walls = new Walls(Const.fieldWidth - 1, Const.fieldHeight - 1);

            Const.messPosition = walls.messPos;
            do
            {
                ShowDirectory(new DirectoryInfo(Directory.GetCurrentDirectory()), walls);
                Console.SetCursorPosition(Const.left, Const.promptPosition);
                Console.Write(Directory.GetCurrentDirectory().ToString() + Str.prompt);
                string        enterStr = Console.ReadLine();
                List <string> enters   = Commands.ParseCommand(enterStr);
                if (enters == null)
                {
                    Console.WriteLine(Str.syntaxErr);
                }
                else
                if (enters[0] != String.Empty)
                {
                    switch (Commands.GetCommandNum(enters[0]))
                    {
                    case 0:
                        walls.Draw();
                        ShowHelp();
                        ShowAndSaveError("", false);
                        break;

                    case 1: //exit
                        Properties.Settings.Default.DefaultPath = Directory.GetCurrentDirectory();
                        Properties.Settings.Default.Save();
                        return;

                    case 2: //создание папки
                        if (!Directory.Exists(enters[1]))
                        {
                            try
                            {
                                Directory.CreateDirectory(enters[1]);
                            }
                            catch (Exception e)
                            {
                                ShowAndSaveError(e.Message, true);
                            }
                        }
                        else
                        {
                            ShowAndSaveError(enters[1] + Str.dirExist, false);
                        }
                        break;

                    case 3: //смена текущей папки
                        if (enters.Count < 2)
                        {
                            ShowAndSaveError(Str.syntaxErr, false);
                            break;
                        }
                        ;
                        if (Directory.Exists(enters[1]))
                        {
                            Directory.SetCurrentDirectory(enters[1]);
                        }
                        else
                        {
                            ShowAndSaveError(enters[1] + Str.dirNotExist, false);
                        }
                        break;

                    case 4: //удаление файла
                        if (!File.Exists(enters[1]))
                        {
                            ShowAndSaveError(enters[1] + Str.fileNotExist, false);
                            break;
                        }
                        try
                        {
                            File.Delete(enters[1]);
                        }
                        catch (Exception e)
                        {
                            ShowAndSaveError(e.Message, true);
                        }
                        break;

                    case 5: //удаление папки
                        if (enters.Count != 2)
                        {
                            ShowAndSaveError(Str.syntaxErr, false);
                            break;
                        }
                        try
                        {
                            Directory.Delete(enters[1], true);
                        }
                        catch (Exception e)
                        {
                            ShowAndSaveError(e.Message, true);
                        }
                        break;

                    case 6://COPY копирование файла
                        if (enters.Count < 3)
                        {
                            ShowAndSaveError(Str.syntaxErr, false);
                            break;
                        }
                        FileCopyOrMove(false, enters[1], enters[2]);
                        break;

                    case 7://перемещение файла(-ов)
                        if (enters.Count < 3)
                        {
                            ShowAndSaveError(Str.syntaxErr, false);
                            break;
                        }
                        FileCopyOrMove(true, enters[1], enters[2]);
                        break;

                    case 8://COPYD копирование папки
                        bool recurse = enters[1].ToUpper() == Commands.keyRecurs;
                        if (recurse)
                        {
                            if (enters.Count == 4)
                            {
                                DirectoryCopy(enters[2], enters[3], recurse);     //есть параметр -r
                            }
                            else
                            {
                                ShowAndSaveError(Str.syntaxErr, false);
                            }
                        }
                        else
                        {
                            if (enters.Count == 3)
                            {
                                DirectoryCopy(enters[1], enters[2], false);    // нет параметра
                            }
                            else
                            {
                                ShowAndSaveError(Str.syntaxErr, false);
                            }
                        }
                        break;

                    case 9:    //перемещение папки
                        if (enters.Count < 3)
                        {
                            ShowAndSaveError(Str.syntaxErr, false);
                            break;
                        }
                        DirectoryInfo dirInfo = new DirectoryInfo(enters[1]);
                        if (dirInfo.Exists && Directory.Exists(enters[2]) == false)
                        {
                            try
                            {
                                dirInfo.MoveTo(enters[2]);
                            }
                            catch (Exception e)
                            {
                                ShowAndSaveError(e.Message, true);
                            }
                        }
                        else
                        {
                            ShowAndSaveError(Str.dirNameError, false);
                        }
                        break;

                    case 10:     //режим отображения
                        if (enters.Count == 1)
                        {
                            Properties.Settings.Default.ViewMode = 0;
                            break;
                        }
                        byte res;
                        bool err = false;
                        if (Byte.TryParse(enters[1], out res))
                        {
                            if (res > 0 && res < Commands.numOfViewMode + 1)
                            {
                                Properties.Settings.Default.ViewMode = res;
                            }
                            else
                            {
                                err = true;
                            }
                        }
                        else
                        {
                            err = true;
                        }
                        if (err)
                        {
                            Console.WriteLine(Str.syntaxErr);
                        }
                        break;

                    case 11:     //количество строк на странице, без параметров 10
                        if (enters.Count == 1)
                        {
                            Properties.Settings.Default.StringsOnPage = 10;
                            break;
                        }
                        byte res9;
                        bool err9 = false;
                        if (Byte.TryParse(enters[1], out res9))
                        {
                            if (res9 > 0 && res9 < byte.MaxValue)
                            {
                                Properties.Settings.Default.StringsOnPage = res9;
                            }
                            else
                            {
                                err9 = true;
                            }
                        }
                        else
                        {
                            err9 = true;
                        }
                        if (err9)
                        {
                            Console.WriteLine(Str.syntaxErr);
                        }
                        break;

                    case 12:    //Lines
                        Properties.Settings.Default.HorizLines = !Properties.Settings.Default.HorizLines;
                        break;

                    case 13:    //DirSize
                        if (enters.Count != 2)
                        {
                            ShowAndSaveError(Str.syntaxErr, false);
                            break;
                        }
                        long size;
                        try
                        {
                            size = DirSize(new DirectoryInfo(enters[1]));
                            ShowInfo(enters[1] + " : " + Str.GetSizeString(size));
                        }
                        catch (Exception e)
                        {
                            ShowAndSaveError(e.Message, true);
                        }
                        break;

                    case 14:     //DI информация о диске
                        if (enters.Count == 1)
                        {
                            ShowDrives(walls);
                        }
                        break;

                    case 15:     //отображение содержимого папки без смены текущей
                        if (enters.Count != 2)
                        {
                            ShowAndSaveError(Str.syntaxErr, false);
                            break;
                        }
                        ShowDirectory(new DirectoryInfo(enters[1]), walls);
                        ShowInfo("");
                        break;

                    case 16:    //Уровень отображения дерева
                        Properties.Settings.Default.Level = !Properties.Settings.Default.Level;
                        break;

                    case 17:    //Цвет фона
                        Properties.Settings.Default.BColor = !Properties.Settings.Default.BColor;
                        Const.backColor = Properties.Settings.Default.BColor ? ConsoleColor.Black : ConsoleColor.Blue;
                        break;

                    default:
                        walls.Draw();
                        ShowHelp();
                        ShowAndSaveError(enters[0] + Str.notCommand, false);
                        break;
                    }
                }
                Console.WriteLine();
            }while (true);
        }