/// <summary> /// Check if a server is still running before closing the GUI /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (!ProcessHandler.IsRunning) { return; } if (ProcessHandler.CurrentState == ServerState.Starting || ProcessHandler.CurrentState == ServerState.Running) { // if windows is shutting down or app is killed from task manager if (e.CloseReason == CloseReason.TaskManagerClosing || e.CloseReason == CloseReason.WindowsShutDown) { // make sure to stop server to prevent data loss ProcessHandler.StopServer(); return; } // ask what to do DialogResult result = MetroMessageBox.Show(this, Locale.Tr( "The server is still running. Closing it without a proper stop might result in data loss. Send stop command first?"), Locale.Tr("Server still running"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); // execute a correct action based upon user input switch (result) { case DialogResult.Yes: ProcessHandler.ServerStopped += SafeFormClose; ProcessHandler.StopServer(); e.Cancel = true; break; case DialogResult.No: // close form break; case DialogResult.Cancel: e.Cancel = true; break; } } else { // wait for server to stop ServerStopDialog serverStopDialog = new ServerStopDialog(); DialogResult result = serverStopDialog.ShowDialog(); // if waiting cancelled, don't shutdown if (result == DialogResult.Cancel) { e.Cancel = true; } } }
private void btnEmulate_Click(object sender, EventArgs e) { if (!ProcessHandler.IsRunning) { MetroMessageBox.Show(this, "The server has to be running in order to emulate output!", "Server not running", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } foreach (string line in txtLog.Text.Split(Environment.NewLine.ToCharArray()[0])) { MinecraftOutputHandler.HandleOutput(ProcessHandler.Server, line); } }