Exemplo n.º 1
0
        public InstallerForm()
        {
            Icon = Icon.FromResource("icon");

            KeyDown += (sender, e) => {
                Console.WriteLine($"XXX {e.Key}");
                if (e.Key.HasFlag(Keys.Enter) && e.Modifiers.HasFlag(Keys.Control))
                {
                    Options.Visible = true;
                }
            };

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((sender, e) => {
                var ex = (Exception)e.ExceptionObject;
                Log.WriteLine("\nUnhandled error!");
                Log.WriteLine(ex.Message);
            });

            Downloader = new Downloader();
            Installer  = new Installer(Downloader, null);

            Title      = $"Mod the Gungeon Installer {Version} (core {Installer.Version})";
            ClientSize = new Size(640, 400);

            MainLayout = new DynamicLayout();

            MainLayout.BeginHorizontal();

            MainLayout.BeginVertical();
            MainLayout.Add(new Label {
                Text = "Output log"
            });
            MainLayout.Add(Log = new Log());
            MainLayout.Add(new ImageView {
                Image = Bitmap.FromResource("icon")
            }, false, false);
            MainLayout.EndVertical();

            MainLayout.BeginVertical();
            MainLayout.Add(new Label {
                Text = "Path to the Gungeon executable"
            });
            MainLayout.Add(ExeSelector = new ExeSelector());
            Installer.ChangeExePath(ExeSelector.Path);
            ExeSelector.PathChanged += (sender, e) => {
                Installer.ChangeExePath(ExeSelector.Path);
                UpdateInstallButton();
            };

            MainLayout.Add(CheckboxesLayout = new StackLayout {
                Orientation = Orientation.Horizontal,
            });

            ComponentList = new ComponentList(Downloader.Components.Values);
            Options       = new Options {
                Visible = false
            };
            ComponentList.SelectedVersionsChanged += (sender, e) => UpdateInstallButton();

            ShowCheckboxes();

            MainLayout.Add(null, false, true);
            VersionDisplay = new VersionDisplay();
            VersionDisplay.ConnectTo(ComponentList);
            MainLayout.Add(InstallButton = new Button {
                Text = "Install", Enabled = false, Size = new Size(100, -1)
            }, true, false);
            MainLayout.Add(UninstallButton = new Button {
                Text = "Uninstall", Size = new Size(100, -1)
            }, true, false);

            InstallButton.Click   += (sender, e) => Install();
            UninstallButton.Click += (sender, e) => Uninstall();

            MainLayout.EndVertical();

            Content = MainLayout;

            Log.WriteLine("Welcome!");

            var subscriber = new Logger.Subscriber((logger, loglevel, indent, str) => {
                var formatted = logger.String(loglevel, str, indent);
                Application.AsyncInvoke(() => Log.WriteLine(formatted));
            });

            Logger.Subscribe(subscriber);
        }