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!"); } }
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 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; } } } }