Improve error handling in startup and closing

This commit is contained in:
oldmud0 2016-02-27 10:31:23 -06:00
parent 7245dee9d1
commit c07a0536a2
2 changed files with 41 additions and 24 deletions

View file

@ -1520,6 +1520,9 @@ private: System::Windows::Forms::ContextMenu^ contextMenuStrip2;
} }
void WriteMessage(String^ msg, Color color){ 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){ if(richTextBoxLog->InvokeRequired){
WriteMessageDelegate^ wmd = gcnew WriteMessageDelegate(this, &MainForm::WriteMessage); WriteMessageDelegate^ wmd = gcnew WriteMessageDelegate(this, &MainForm::WriteMessage);
richTextBoxLog->Invoke(wmd, msg, color); richTextBoxLog->Invoke(wmd, msg, color);

View file

@ -418,35 +418,49 @@ namespace LilithPort {
textBoxComment->MaxLength = MAX_NAME; textBoxComment->MaxLength = MAX_NAME;
switch(MTOPTION.CONNECTION_TYPE){ switch(MTOPTION.CONNECTION_TYPE){
case CT_SERVER: case CT_SERVER:
default: default:
radioButtonServer->Checked = true; radioButtonServer->Checked = true;
numericUpDownPort->Enabled = false;
numericUpDownPort->Enabled = false; break;
break; case CT_HOST:
case CT_HOST: radioButtonHost->Checked = true;
radioButtonHost->Checked = true; break;
case CT_CLIENT:
break; radioButtonClient->Checked = true;
case CT_CLIENT: numericUpDownOpenPort->Enabled = false;
radioButtonClient->Checked = true; break;
numericUpDownOpenPort->Enabled = false;
break;
} }
textBoxServerName->Text = gcnew String(MTOPTION.SERVER_NAME); bool error = false;
textBoxIP->Text = gcnew String(MTOPTION.CONNECTION_IP);
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) { System::Void StartupForm_Shown(System::Object^ sender, System::EventArgs^ e) {