Beispiel #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            var cfg = Config.ReadConfigFile("config.json");

            cfg = cfg == null ? new ConfigObject() : cfg;
            if (cfg.Hostname.IsNullOrWhiteSpace())
            {
                var result = TextPrompt.Prompt("Enter the hostname (IP Address)", "Hostname", false, false);
                if (result == null)
                {
                    Environment.Exit(1);
                }
                cfg.Hostname = result;
            }
            if (cfg.Username.IsNullOrWhiteSpace())
            {
                var result = TextPrompt.Prompt("Enter the username", "Username", false, false);
                if (result == null)
                {
                    Environment.Exit(1);
                }
                cfg.Username = result;
            }
            if (cfg.Port == 0)
            {
                var result = TextPrompt.Prompt("Enter the port (default 22)", "Port", false, false);
                if (result == null)
                {
                    Environment.Exit(1);
                }
                int resultInt;
                if (!int.TryParse(result, out resultInt))
                {
                    Environment.Exit(1);
                }
                cfg.Port = resultInt;
            }
            if (cfg.Password.IsNullOrWhiteSpace())
            {
                cfg.Password = TextPrompt.Prompt("Enter the password", "Password", true, true);
            }

            if (!cfg.ModpackDownloaderExeName.IsNullOrWhiteSpace())
            {
                ModpackDownloaderExeName = cfg.ModpackDownloaderExeName;
            }

            if (!cfg.BungeeCordHandlerExeName.IsNullOrWhiteSpace())
            {
                BungeeCordHandlerExeName = cfg.BungeeCordHandlerExeName;
            }


            mountPoint_TextBox.Text     = cfg.MountPoint;
            remoteLocation_TextBox.Text = cfg.RemoteLocation;

            Editor = cfg.Editor;

            if (!cfg.ServerPath.IsNullOrWhiteSpace())
            {
                mcServerPath_TextBox.Text = cfg.ServerPath;
            }

            handler = new ServerManagerHandler(cfg);

            EventHandler <Renci.SshNet.Common.ExceptionEventArgs> sshError = (s, e2) =>
            {
                MessageBox.Show("An error has occurred: " + e2.Exception.Message);
                Console.Error.WriteLine(e2.Exception.ToString());
                connected_ToolStripLabel.Text = ((BaseClient)s).IsConnected ? "Connected" : "Failed to connect";
            };

            handler.SshHandler._Client.ErrorOccurred  += sshError;
            handler.SftpHandler._Client.ErrorOccurred += sshError;

            // so now visual studio wants to complain about you... but you work fine... and what about the stuff after it?
            MiscTools.SpawnBackgroundWorker(() => this.Invoke((MethodInvoker)(() => connected_ToolStripLabel.Text = handler.Connect() ? "Connected" : "Failed to connect")), () => {
                if (handler.IsConnected) // things to run as soon as connected
                {
                    mcServerPath_TextBox.Text = handler.SshHandler.RealPath(mcServerPath_TextBox.Text);
                    RefreshViews();
                    if (cfg.ExpandAllOnStart)
                    {
                        idleInstances_TreeView.ExpandAllExcept(x => x.EndsWith("launch.sh"));
                        runningInstances_TreeView.ExpandAllExcept(x => x.EndsWith("launch.sh"));
                    }
                }
            });
        }
Beispiel #2
0
        private void deleteInstances_Button_Click(object sender, EventArgs e)
        {
            if (idleInstances_TreeView.SelectedNode != null)
            {
                var toRemove = idleInstances_TreeView.SelectedNode.FullPath;
                if (MessageBox.Show(this, "Are you using BungeeCord? If using it, you must select the INSTANCE, not a containing folder", "BungeeCord", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    var bungeeLocation = mcServerPath_TextBox.Text.BetterPathJoinSlash(TextPrompt.Prompt("Type the BungeeCord instance location", "BungeeCord", false, false));

                    var configpath = bungeeLocation.BetterPathJoinSlash("config.yml");

                    if (handler.SftpHandler._Client.Exists(configpath))
                    {
                        List <string> file = new List <string>(handler.SftpHandler._Client.ReadAllLines(configpath));

                        var shortname     = toRemove.Split('/').Last().Replace(' ', '_');
                        var instanceIndex = file.IndexOf("  " + shortname + ":");

                        if (instanceIndex < 0)
                        {
                            MessageBox.Show("Instance wasn't found in BungeeCord config!");
                        }
                        else
                        {
                            var instanceDefinitionLength = 4;
                            for (int i = 0; i < instanceDefinitionLength; i++)
                            {
                                file.RemoveAt(instanceIndex);
                            }

                            // because sftp writealllines doesn't overwrite the entire file
                            handler.SftpHandler._Client.DeleteFile(configpath);

                            handler.SftpHandler._Client.WriteAllLines(configpath, file);

                            handler.SshHandler.RunCommand("rm -rf " + toRemove);
                            RefreshViews();
                        }
                    }
                    else
                    {
                        MessageBox.Show("It's not a BungeeCord instance or there's no config.yml");
                    }
                }
                else
                {
                    if (MessageBox.Show("Do you REALLY want to delete this PERMANENTLY?", "Are you sure?", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        if (MessageBox.Show("Do you REALLY REALLY want to delete this PERMANENTLY?", "Are you REALLY sure?", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            if (MessageBox.Show("It's PERMANENT. Do you REALLY want to do this?", "ARE YOU REALLY SURE?", MessageBoxButtons.OKCancel) == DialogResult.OK)
                            {
                                if (MessageBox.Show("By clicking OK, the instance tree will be PERMANENTLY DELETED. THIS IS YOUR LAST CHANCE TO CLICK CANCEL.", "THIS IS YOUR LAST CHANCE!", MessageBoxButtons.OKCancel) == DialogResult.OK)
                                {
                                    handler.SshHandler.RunCommand("rm -rf " + toRemove);
                                    RefreshViews();
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Select a directory in the idle instances.");
            }
        }