Exemplo n.º 1
0
        //Display Current Directory, files and folders and selected file
        public static void Display()
        {
            State.activeScreen = (int)State.screens.FILESYSTEM;
            Console.Clear();
            Console.SetCursorPosition(0, 0);
            Console.CursorVisible = false;

            try
            {
                //Sort and combine Directories and files
                files = CombineArrays(State.currentPath);

                /*foreach (var item in files)
                 * {
                 *  Console.WriteLine(item);
                 * };
                 *
                 * SetBufferSize DOESNT WORKK IN UNIX
                 * if (files.Length > Console.WindowHeight)
                 * {
                 *  Console.SetBufferSize( Console.WindowWidth, files.Length + Console.WindowHeight );
                 * }
                 * else
                 * {
                 *  Console.SetBufferSize( Console.WindowWidth,  Console.WindowHeight );
                 * }
                 */

                Console.SetCursorPosition(0, Console.WindowTop + 5);

                if (Tools.IsEmpty(files))
                {
                    writer.WriteLine("    (empty)");
                }
                //Output all files and folders
                for (int i = 0; i < files.Length; i++)
                {
                    string copiedIndicator;
                    if (Tools.selectionRegister.Contains(files[i]))
                    {
                        copiedIndicator = "*";
                    }
                    else
                    {
                        copiedIndicator = " ";
                    };
                    if (State.cursorPosY == i)
                    {
                        FileAttributes attr = File.GetAttributes(files[i]);
                        if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            writer.WriteLine(" ->" + copiedIndicator + "> " + ShortenFileName(Path.GetFileName(files[i]), 26) + "\\");
                            State.selectedFile = Path.GetFullPath(files[i]);
                        }
                        else
                        {
                            writer.WriteLine(" ->" + copiedIndicator + "{0,-40}{1,16}", ShortenFileName(Path.GetFileNameWithoutExtension(files[i]), 26)
                                             + Path.GetExtension(files[i]), Tools.DisplayFileSize(files[i]));
                            State.selectedFile = Path.GetFullPath(files[i]);
                        }
                    }
                    else if (State.cursorPosY != i)
                    {
                        FileAttributes attr = File.GetAttributes(files[i]);
                        if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            writer.WriteLine("   " + copiedIndicator + "> " + ShortenFileName(Path.GetFileName(files[i]), 26) + "\\");
                        }
                        else
                        {
                            writer.WriteLine("   " + copiedIndicator + "{0,-40}{1,16}", ShortenFileName(Path.GetFileNameWithoutExtension(files[i]), 26)
                                             + Path.GetExtension(files[i]), Tools.DisplayFileSize(files[i]));
                        }
                    }
                }
                WatchFileSystem.RefreshWatcherPath();
            }
            catch (UnauthorizedAccessException)
            {
                Console.Clear();
                SetCursorToPreviousPosition();
                State.currentPath = Directory.GetParent(State.currentPath).ToString();
                Display();
                Tools.DisplayError(new Exception("Access Denied"));
            }

            writer.Flush();
            Console.SetCursorPosition(0, State.cursorPosY);

            //Clear top of window and Write Current Directory
            ClearBlock(Console.WindowTop, Console.WindowTop + 5);
            Console.SetCursorPosition(0, Console.WindowTop);
            WriteCurrentPath();

            if (Console.BufferWidth > 94)
            {
                new ConsoleDisplayChild();
            }
            //new FilePreview();
        }
Exemplo n.º 2
0
        //Display Current Directory, files and folders and selected file
        public static void Display()
        {
            State.activeScreen = (int)State.screens.FILESYSTEM;
            Console.Clear();
            Console.SetCursorPosition(0, 0);
            Console.CursorVisible = false;

            try
            {
                //Sort and combine Directories and Files
                files = CombineArrays(State.currentPath);
                //Create file chunk sizes to fit in window
                fileChunks = ChunkerizeFiles(files);

                Console.SetCursorPosition(0, Console.WindowTop + 5);

                if (Tools.IsEmpty(files))
                {
                    writer.WriteLine("    (empty)");
                }
                else
                {
                    //Output all files and folders
                    currentChunkFiles = fileChunks[State.currentFileChunk];

                    for (int j = 0; j < currentChunkFiles.Length; j++)
                    {
                        string copiedIndicator;
                        if (Tools.selectionRegister.Contains(currentChunkFiles[j]))
                        {
                            copiedIndicator = "*";
                        }
                        else
                        {
                            copiedIndicator = " ";
                        };
                        if (State.cursorPosY == j)
                        {
                            FileAttributes attr = File.GetAttributes(currentChunkFiles[j]);
                            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                            {
                                writer.WriteLine(" ->" + copiedIndicator + "> " + ShortenFileName(Path.GetFileName(currentChunkFiles[j]), 26) + "\\");
                                State.selectedFile = Path.GetFullPath(currentChunkFiles[j]);
                            }
                            else
                            {
                                writer.WriteLine(" ->" + copiedIndicator + "{0,-40}{1,16}", ShortenFileName(Path.GetFileNameWithoutExtension(currentChunkFiles[j]), 26)
                                                 + Path.GetExtension(currentChunkFiles[j]), Tools.DisplayFileSize(currentChunkFiles[j]));
                                State.selectedFile = Path.GetFullPath(currentChunkFiles[j]);
                            }
                        }
                        else if (State.cursorPosY != j)
                        {
                            FileAttributes attr = File.GetAttributes(currentChunkFiles[j]);
                            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                            {
                                writer.WriteLine("   " + copiedIndicator + "> " + ShortenFileName(Path.GetFileName(currentChunkFiles[j]), 26) + "\\");
                            }
                            else
                            {
                                writer.WriteLine("   " + copiedIndicator + "{0,-40}{1,16}", ShortenFileName(Path.GetFileNameWithoutExtension(currentChunkFiles[j]), 26)
                                                 + Path.GetExtension(currentChunkFiles[j]), Tools.DisplayFileSize(currentChunkFiles[j]));
                            }
                        }
                    }
                }
                WatchFileSystem.RefreshWatcherPath();
            }
            catch (UnauthorizedAccessException)
            {
                Console.Clear();
                SetCursorToPreviousPosition();
                State.currentPath = Directory.GetParent(State.currentPath).ToString();
                Display();
                Tools.DisplayError(new Exception("Access Denied"));
            }
            catch (IndexOutOfRangeException e)
            {
                Tools.DisplayError(e);
            }

            writer.Flush();
            Console.SetCursorPosition(0, State.cursorPosY);

            //Clear top of window and Write Current Directory
            ClearBlock(Console.WindowTop, Console.WindowTop + 5);
            Console.SetCursorPosition(0, Console.WindowTop);
            WriteCurrentPath();

            if (Console.BufferWidth > 94)
            {
                new ConsoleDisplayChild();
            }
            //new FilePreview();
        }