コード例 #1
0
        private void download_Button_Click(object sender, EventArgs e)
        {
            var node = fileList_TreeView.SelectedNode;

            if (ManagerHandler.SshHandler.RunCommand("test -f " + node.FullPath.Quotate()).ExitCode == 0)
            {
                var dialog = new SaveFileDialog();
                var ext    = node.Text.Split('.').Last();
                dialog.Filter       = $"File of type (*.{ext})|*.{ext}";
                dialog.DefaultExt   = ext;
                dialog.AddExtension = true;
                dialog.FileName     = node.Text;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    MiscTools.SpawnBackgroundWorker(() => ManagerHandler.SftpHandler.Download(node.FullPath, new FileInfo(dialog.FileName)));
                }
            }
            else
            {
                MessageBox.Show("Selected node is not a file");
            }
        }
コード例 #2
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"));
                    }
                }
            });
        }
コード例 #3
0
        private void modifyInstance_Button_Click(object sender, EventArgs e)
        {
            var modifyTypeChooser = new ModifyTypeChooser();

            if (modifyTypeChooser.ShowDialog() == DialogResult.OK)
            {
                switch (modifyTypeChooser.SelectionBox.SelectedItem)
                {
                case "Modify":
                    /*if (GetAnySelectedNode() != null)
                     * {
                     *  var modifier = new InstanceModifier();
                     *  modifier.Editor = Editor;
                     *  modifier.ManagerHandler = handler;
                     *  modifier.FullDirPath = GetAnySelectedNode().FullPath;
                     *  modifier.Show();
                     * }
                     * else
                     * {
                     *  MessageBox.Show("Select a directory in the idle instances.");
                     * }*/
                    MessageBox.Show("This is pretty broken and useless right now. You should probably just have the drive mounted and use your own text editor and other programs.");
                    break;

                case "Update":
                    if (GetAnySelectedNode() != null)
                    {
                        var  children   = GetAnySelectedNode().Nodes;
                        bool isInstance = false;
                        foreach (TreeNode child in children)
                        {
                            if (child.Text.Equals("launch.sh"))
                            {
                                isInstance = true;
                            }
                        }
                        if (isInstance)
                        {
                            var instpath = GetAnySelectedNode().FullPath;
                            var wizard   = new InstanceCreationWizard();
                            wizard.Order = new[] { CreatorTab.Start, CreatorTab.DownloadLink };
                            wizard.instanceName_TextBox.Text = instpath.Substring(MiscTools.CommonStartsWith(instpath, mcServerPath_TextBox.Text).Length);
                            wizard.BasePath = mcServerPath_TextBox.Text;

                            var chooser = new InstallTypeChooser();
                            if (chooser.ShowDialog() == DialogResult.OK)
                            {
                                switch (chooser.SelectionBox.SelectedItem)
                                {
                                case "Modded":
                                    wizard.ServerType = ServerType.Modded;
                                    break;

                                case "Spigot":
                                    wizard.ServerType = ServerType.Bukkit;
                                    break;

                                case "Bedrock":
                                    wizard.ServerType = ServerType.Bedrock;
                                    break;
                                }
                            }
                            if (wizard.ShowDialog() == DialogResult.OK)
                            {
                                if (wizard.ServerType == ServerType.Modded)
                                {
                                    wizard.ResultValues.Item1.ExcludedFiles = new[] {                                            // TODO: don't hardcode this
                                        "backups",
                                        "journeymap",
                                        "logs",
                                        "schematics",
                                        "world",
                                        "banned-ips.json",
                                        "banned-players.json",
                                        "eula.txt",
                                        "ops.json",
                                        "server.properties",
                                        "usercache.json",
                                        "usernamecache.json",
                                        "whitelist.json",
                                        "mods/aaasponge.jar",
                                        "config/sponge"
                                    }
                                }
                                ;
                                handler.UpdateInstance(wizard.ResultValues.Item1);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Select an instance in the idle instances");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Select an instance in the idle instances");
                    }
                    break;
                }
            }
        }
コード例 #4
0
 private void ServerMonitorLoop()
 {
     MiscTools.SpawnBackgroundWorker(() => CpuLoadUpdateLoop());
     MiscTools.SpawnBackgroundWorker(() => SensorsUpdateLoop());
     MiscTools.SpawnBackgroundWorker(() => TopUpdateLoop());
 }
コード例 #5
0
        public void OpenPutty(string path)
        {
            var runningScreens = SshHandler.GetRunningScreensRaw();
            var screenid       = runningScreens.Where(x => x.Replace(':', '/').EndsWith(MiscTools.DirWithoutFile(path))).FirstOrDefault();
            var proc           = PuttyOpener.OpenPutty("screen -x " + screenid.Quotate());

            proc.WaitForInputIdle();
        }
コード例 #6
0
        public void KillInstance(string path)
        {
            var runningScreens = SshHandler.GetRunningScreensRaw();
            var screenid       = runningScreens.Where(x => x.Replace(':', '/').EndsWith(MiscTools.DirWithoutFile(path))).FirstOrDefault();

            SshHandler.RunCommand("screen -S " + screenid.Quotate() + " -X quit");
        }
コード例 #7
0
        public Task StopInstance(string path)
        {
            var runningScreens = SshHandler.GetRunningScreensRaw();
            var screenid       = runningScreens.Where(x => x.Replace(':', '/').EndsWith(MiscTools.DirWithoutFile(path))).FirstOrDefault();
            var task           = new Task(() => {
                SshHandler.RunCommand(("while screen -S " + screenid.Quotate() + " -X stuff \"stop\nend\n\"").CombineCommand("do sleep 0.5; done"));
            });

            task.Start();
            return(task);
        }