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!"); } }
/// <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; }
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(); } }
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; } }
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(); }
public static void Initialize() { MenuItem[] mainItems = { new MenuItem("File", new MenuItem("Dump", () => { Exit(); InfoPanel.Message("Dumping..."); Dumper.Dump(FilePanel.File.FullName, MainApp.BytesPerRow, MainApp.OffsetView); InfoPanel.Message("Done"); }), new MenuItem(), new MenuItem("Exit", () => { inMenu = false; MainApp.Exit(); }) ), /* * new MenuItem("Edit", null, * new MenuItem("Test") * ),*/ new MenuItem("Search", new MenuItem("Find byte...", () => { Exit(); Dialog.PromptFindByte(); }), new MenuItem("Find ASCII string...", () => { Exit(); Dialog.PromptSearchString(); }), new MenuItem(), new MenuItem("Goto...", () => { Exit(); Dialog.PromptGoto(); }) ), new MenuItem("View", new MenuItem("Offset view...", () => { Exit(); Dialog.PromptOffset(); }), new MenuItem(), new MenuItem("File info", () => { Exit(); InfoPanel.DisplayFileInfo(); }), new MenuItem(), new MenuItem("Refresh", () => { Exit(); FilePanel.Refresh(); }) ), /* * new MenuItem("Tools", null, * new MenuItem("Test") * ),*/ #if DEBUG new MenuItem("Debug", new MenuItem("Show Test Window", () => { Exit(); new Window("Test", new Control[] { new Label("Hello World!") }).Show(); }), new MenuItem("Goto", () => { Exit(); new Window("Goto", new Control[] { new Label("Hello World!", 1, 1), new Button("OK", 12, 3, action: () => { MainApp.Goto(0xdd);}) }).Show(); }), new MenuItem("Preferences...", () => { Exit(); new Window("Test", 50, 6, new Control[] { new Label("Setting 1:", 1, 1), new Button("OK", 12, 3) }).Show(); }) ), #endif new MenuItem("?", new MenuItem("About", () => { Exit(); Dialog.GenerateWindow( title: "About", text: $"{Program.Name} v{Program.Version}\nCopyright (c) 2015-2017 dd86k", width: 36, height: 5 ); }) ) }; // Make an array for each, remember that arrays are REFERENCED. _pos = new int[mainItems.Length]; _miw = new int[mainItems.Length]; MenuItems = new List <MenuItem>(mainItems.Length); MenuItems.AddRange(mainItems); _barlength = 0; // Get menubar's length with items for (int i = 0; i < MenuItems.Count; ++i) { MenuItem item = MenuItems[i]; _pos[i] = _barlength; _barlength += item.Text.Length + 2; int max = 0; // Get longuest string in each submenus for (int si = 0; si < item.Items.Count; si++) { MenuItem subitem = MenuItems[i].Items[si]; if (!subitem.IsSeparator) { int len = subitem.Text.Length; if (len > max) { max = len; } } } _miw[i] = max; } Draw(); }
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; } } } }