示例#1
0
        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();
        }
示例#2
0
文件: Program.cs 项目: dd86k/0xdd
        static int Main(string[] args)
        {
#if DEBUG
            // Used for debugging within Visual Studio (vshost)
            args = new string[] { "image.jpg" };
            //args = new string[] { "/o", "J", "image.jpg" };
            //args = new string[] { "test.txt" };
            //args = new string[] { "zero" };
#endif

            if (args.Length == 0)
            {
                // Future reminder:
                // New buffer in editing mode if no arguments
                ShowHelp();
                return(0);
            }

            // Defaults
            string entry = args[args.Length - 1];
            MainApp.BytesPerRow = 0;
            MainApp.OffsetView  = OffsetView.Hex;
            bool dump = false;

            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i])
                {
                case "-o":
                case "/o":
                    switch (args[i + 1][0])
                    {
                    case 'h':
                    case 'H':
                        MainApp.OffsetView = OffsetView.Hex;
                        break;

                    case 'd':
                    case 'D':
                        MainApp.OffsetView = OffsetView.Dec;
                        break;

                    case 'o':
                    case 'O':
                        MainApp.OffsetView = OffsetView.Oct;
                        break;

                    default:
                        Console.WriteLine(
                            ErrorCode.CLI_InvalidOffsetView
                            .GetMessage(args[i + 1])
                            );
#if DEBUG
                        Console.ReadLine();
#endif
                        return(ErrorCode.CLI_InvalidOffsetView.ToInt());
                    }
                    break;

                case "-w":
                case "/w":
                {
                    int b = MainApp.BytesPerRow;
                    if (char.ToLower(args[i + 1][0]) != 'a')         // Automatic, in case to overwrite settings
                    {
                        MainApp.BytesPerRow = 0;
                    }
                    else if (!int.TryParse(args[i + 1], out b))
                    {
                        Console.WriteLine(
                            ErrorCode.CLI_InvalidWidth
                            .GetMessage(args[i + 1])
                            );
#if DEBUG
                        Console.ReadLine();
#endif
                        return(ErrorCode.CLI_InvalidWidth.ToInt());
                    }
                    MainApp.BytesPerRow = b;
                }
                break;

                case "-dump":
                case "/dump":
                    dump = true;
                    break;

                case "/?":
                case "-h":
                case "-help":
                case "--help":
                    ShowHelp();
                    return(0);

                case "-v":
                case "/ver":
                case "--version":
                    ShowVersion();
                    return(0);
                }
            }

            if (dump)
            {
                Console.Write("Dumping file... ");
                ErrorCode err = Dumper.Dump(entry, MainApp.BytesPerRow, MainApp.OffsetView);

                Console.WriteLine(err.GetMessage());

                return(err.ToInt());
            }
            else
            {
#if DEBUG
                // I want Visual Studio to catch the exceptions!
                MainApp.Open(entry);

                ErrorCode e = MainApp.LastError;

                Console.Clear();
                Console.WriteLine(
                    $"ERROR: {e} - {e.GetMessage()} (0x{e.ToInt():X8})"
                    );
                Console.ReadKey();
                return(e.ToInt());
#else
                try
                {
                    MainApp.Open(entry);

                    if (MainApp.LastError != ErrorCode.Success)
                    {
                        Console.WriteLine(MainApp.LastError.GetMessage());
                    }

                    return(MainApp.LastError.ToInt());
                }
                catch (Exception e)
                {
                    Abort(e);
                }

                return(0);
#endif
            }
        }