From c07a0536a29c33a5698f26ec31218ba1bbde2116 Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Sat, 27 Feb 2016 10:31:23 -0600 Subject: [PATCH] Improve error handling in startup and closing --- LilithPort/MainForm.h | 3 ++ LilithPort/StartupForm.h | 62 ++++++++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/LilithPort/MainForm.h b/LilithPort/MainForm.h index 38617d6..a39de8c 100644 --- a/LilithPort/MainForm.h +++ b/LilithPort/MainForm.h @@ -1520,6 +1520,9 @@ private: System::Windows::Forms::ContextMenu^ contextMenuStrip2; } void WriteMessage(String^ msg, Color color){ + //Prevents an error writing to the chat log when you are closing the program + if (richTextBoxLog->IsDisposed) return; + if(richTextBoxLog->InvokeRequired){ WriteMessageDelegate^ wmd = gcnew WriteMessageDelegate(this, &MainForm::WriteMessage); richTextBoxLog->Invoke(wmd, msg, color); diff --git a/LilithPort/StartupForm.h b/LilithPort/StartupForm.h index f567929..b2dc9cf 100644 --- a/LilithPort/StartupForm.h +++ b/LilithPort/StartupForm.h @@ -418,35 +418,49 @@ namespace LilithPort { textBoxComment->MaxLength = MAX_NAME; switch(MTOPTION.CONNECTION_TYPE){ - case CT_SERVER: - default: - radioButtonServer->Checked = true; - - numericUpDownPort->Enabled = false; - break; - case CT_HOST: - radioButtonHost->Checked = true; - - break; - case CT_CLIENT: - radioButtonClient->Checked = true; - - numericUpDownOpenPort->Enabled = false; - break; + case CT_SERVER: + default: + radioButtonServer->Checked = true; + numericUpDownPort->Enabled = false; + break; + case CT_HOST: + radioButtonHost->Checked = true; + break; + case CT_CLIENT: + radioButtonClient->Checked = true; + numericUpDownOpenPort->Enabled = false; + break; } - textBoxServerName->Text = gcnew String(MTOPTION.SERVER_NAME); - textBoxIP->Text = gcnew String(MTOPTION.CONNECTION_IP); + bool error = false; + + try { + textBoxServerName->Text = gcnew String(MTOPTION.SERVER_NAME); + textBoxIP->Text = gcnew String(MTOPTION.CONNECTION_IP); + textBoxName->Text = gcnew String(MTOPTION.NAME); + textBoxComment->Text = gcnew String(MTOPTION.COMMENT); + textBoxWelcome->Text = gcnew String(MTOPTION.WELCOME); + } + catch (Exception^ e) { + error = true; + } + try { + numericUpDownOpenPort->Value = MTOPTION.OPEN_PORT; + numericUpDownPort->Value = MTOPTION.PORT; + numericUpDownMaxConnection->Value = MTOPTION.MAX_CONNECTION; + } + catch (Exception^ e) { + numericUpDownOpenPort->Value = 7500; + numericUpDownOpenPort->Value = 7500; + numericUpDownMaxConnection->Value = 4; + error = true; + } - numericUpDownOpenPort->Value = MTOPTION.OPEN_PORT; + if (error) { + MessageBox::Show(L"Some options could not be loaded correctly from the settings file. Their default values have been loaded instead.", L"Settings File Corrupt", MessageBoxButtons::OK, MessageBoxIcon::Error); + } - textBoxName->Text = gcnew String(MTOPTION.NAME); - numericUpDownPort->Value = MTOPTION.PORT; - numericUpDownMaxConnection->Value = MTOPTION.MAX_CONNECTION; - - textBoxComment->Text = gcnew String(MTOPTION.COMMENT); - textBoxWelcome->Text = gcnew String(MTOPTION.WELCOME); } System::Void StartupForm_Shown(System::Object^ sender, System::EventArgs^ e) {