Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update the data onscreen from <see cref="DisplayBuffer"/>.
        /// </summary>
        public static void Update()
        {
            int width = Console.WindowWidth - 1;

            long len = File.Length, pos = FileIO.Position;

            //TODO: Check if we can do a little pointer-play with the buffer.

            int d = 0, bpr = MainApp.BytesPerRow;

            StringBuilder
                line  = new StringBuilder(width),
                ascii = new StringBuilder(bpr);

            OffsetPanel.Update();

            Console.SetCursorPosition(0, StartPosition);
            for (int i = 0; i < DisplayBuffer.Length; i += bpr)
            {
                line.Clear();
                switch (MainApp.OffsetView)
                {
                default:
                    line.Append($"{pos + i:X8}  ");
                    break;

                case OffsetView.Dec:
                    line.Append($"{pos + i:D8}  ");
                    break;

                case OffsetView.Oct:
                    line.Append($"{MainApp.ToOct(pos + i, 8)}  ");
                    break;
                }

                ascii.Clear();
                if (pos + i + bpr < len)
                {
                    for (int bi = 0; bi < bpr; ++bi, ++d)
                    {
                        line.Append($"{DisplayBuffer[d]:X2} ");
                        ascii.Append(DisplayBuffer[d].ToAscii());
                    }

                    Console.Write(line.ToString());
                    Console.Write(' '); // In case of "over FFFF_FFFFh" padding
                    Console.Write(ascii.ToString());
                    Console.WriteLine(' ');
                }
                else
                {
                    long h = len - (pos + i);

                    for (int bi = 0; bi < h; ++bi, ++d)
                    {
                        line.Append($"{DisplayBuffer[d]:X2} ");
                        ascii.Append(DisplayBuffer[d].ToAscii());
                    }

                    Console.Write(line.ToString());
                    Console.SetCursorPosition(Console.WindowWidth - bpr - 5, Console.CursorTop);
                    Console.Write(ascii.ToString());
                    return;
                }
            }
        }