Beispiel #1
0
        public static void PromptGoto()
        {
            if (FilePanel.BufferSize >= FilePanel.FileSize)
            {
                InfoPanel.Message("Not possible.");
                return;
            }

            if (FilePanel.CurrentPosition >= FilePanel.FileSize - FilePanel.BufferSize)
            {
                InfoPanel.Message("Already at the end of the file.");
                return;
            }

            long t = GetNumberFromUser("Goto:");

            if (t == -1)
            {
                FilePanel.Update();
                InfoPanel.Message("Canceled.");
                return;
            }

            if (t >= 0 && t <= FilePanel.FileSize - FilePanel.BufferSize)
            {
                MainApp.Goto(t);
            }
            else
            {
                FilePanel.Update();
                InfoPanel.Message("Position out of bound!");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Exit the menubar loop and clear all selections.
        /// </summary>
        static void Exit()
        {
            // Unselect old menubar selection
            UnfocusMenuBarItem();

            Console.ResetColor();
            FilePanel.Update();
            OffsetPanel.Initialize();
            inMenu = false;
        }
Beispiel #3
0
        static void ReadKey()
        {
            ConsoleKeyInfo ck = Console.ReadKey(true);

            oldY = Y;
            oldX = X;

            switch (ck.Key)
            {
            case ConsoleKey.Escape:
                Exit();
                return;

            case ConsoleKey.UpArrow:
                MoveUp();
                break;

            case ConsoleKey.DownArrow:
                MoveDown();
                break;

            case ConsoleKey.LeftArrow:
                MoveLeft();
                Console.ResetColor();
                OffsetPanel.Draw();
                FilePanel.Update();
                DrawSubMenu();
                break;

            case ConsoleKey.RightArrow:
                MoveRight();
                Console.ResetColor();
                OffsetPanel.Draw();
                FilePanel.Update();
                DrawSubMenu();
                break;

            case ConsoleKey.Spacebar:
            case ConsoleKey.Enter:
                SelectItem();
                break;
            }

            /*
             * This 'if' is there due to calling Exit() from the item's
             * Action, the stack pointer goes back to SelectItem, which
             * then used to call Update(). So this is a sanity check.
             */
            if (inMenu)
            {
                Update();
            }
        }
Beispiel #4
0
        public static void PromptSearchString()
        {
            if (FilePanel.CurrentPosition >= FilePanel.FileSize - FilePanel.BufferSize)
            {
                InfoPanel.Message("Already at the end of the file.");
                return;
            }

            if (FilePanel.BufferSize >= FilePanel.FileSize)
            {
                InfoPanel.Message("Not possible.");
                return;
            }

            _lastString = GetUserInput("Find data:", suggestion: _lastString);

            if (_lastString == null || _lastString.Length == 0)
            {
                FilePanel.Update();
                InfoPanel.Message("Canceled.");
                return;
            }

            FilePanel.Update();
            InfoPanel.Message("Searching...");
            long t = Finder.FindString(
                _lastString,
                FilePanel.FileIO,
                FilePanel.File,
                FilePanel.CurrentPosition + 1
                );

            switch (t)
            {
            case -1:
                InfoPanel.Message($"No results.");
                break;

            case -2:
                InfoPanel.Message($"Position out of bound.");
                break;

            case -3:
                InfoPanel.Message($"File not found!");
                break;

            default:
                MainApp.Goto(t);
                InfoPanel.Message($"Found at {t:X2}h.");
                break;
            }
        }
Beispiel #5
0
        public static void PromptOffset()
        {
            string c = GetUserInput("Hex, Dec, Oct?");

            if (c == null || c.Length < 1)
            {
                InfoPanel.Message("Canceled.");
                FilePanel.Update();
                return;
            }

            switch (c[0])
            {
            case 'H':
            case 'h':
                MainApp.OffsetView = OffsetView.Hex;
                OffsetPanel.Update();
                InfoPanel.Update();
                break;

            case 'O':
            case 'o':
                MainApp.OffsetView = OffsetView.Oct;
                OffsetPanel.Update();
                InfoPanel.Update();
                break;

            case 'D':
            case 'd':
                MainApp.OffsetView = OffsetView.Dec;
                OffsetPanel.Update();
                InfoPanel.Update();
                break;

            default:
                InfoPanel.Message("Invalid view mode!");
                break;
            }

            FilePanel.Update();
        }
Beispiel #6
0
        public static void PromptFindByte()
        {
            if (FilePanel.CurrentPosition + FilePanel.BufferSize >= FilePanel.FileSize)
            {
                InfoPanel.Message("Already at the end of the file.");
                return;
            }

            long t = GetNumberFromUser("Find byte:",
                                       suggestion: $"0x{_lastByte:X2}");

            if (t == -1)
            {
                FilePanel.Update();
                InfoPanel.Message("Canceled.");
                return;
            }

            if (t < 0 || t > byte.MaxValue)
            {
                FilePanel.Update();
                InfoPanel.Message("A value between 0 and 255 is required.");
            }
            else
            {
                FilePanel.Update();
                InfoPanel.Message("Searching...");
                long p = Finder.FindByte(
                    _lastByte = (byte)t,
                    FilePanel.FileIO,
                    FilePanel.File,
                    FilePanel.CurrentPosition + 1
                    );

                if (p > 0)
                {
                    MainApp.Goto(--p);
                    if (p > uint.MaxValue)
                    {
                        InfoPanel.Message($"Found {t:X2} at {p:X16}");
                    }
                    else
                    {
                        InfoPanel.Message($"Found {t:X2} at {p:X8}");
                    }
                }
                else
                {
                    switch (p)
                    {
                    case -1:
                        InfoPanel.Message($"No results.");
                        break;

                    case -2:
                        InfoPanel.Message($"Position out of bound.");
                        break;

                    case -3:
                        InfoPanel.Message($"File not found!");
                        break;

                    default:
                        InfoPanel.Message($"Unknown error occurred. (0x{p:X2})");
                        break;
                    }
                }
            }
        }