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

@ -421,33 +421,47 @@ namespace LilithPort {
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; break;
case CT_CLIENT: case CT_CLIENT:
radioButtonClient->Checked = true; radioButtonClient->Checked = true;
numericUpDownOpenPort->Enabled = false; numericUpDownOpenPort->Enabled = false;
break; break;
} }
bool error = false;
try {
textBoxServerName->Text = gcnew String(MTOPTION.SERVER_NAME); textBoxServerName->Text = gcnew String(MTOPTION.SERVER_NAME);
textBoxIP->Text = gcnew String(MTOPTION.CONNECTION_IP); textBoxIP->Text = gcnew String(MTOPTION.CONNECTION_IP);
numericUpDownOpenPort->Value = MTOPTION.OPEN_PORT;
textBoxName->Text = gcnew String(MTOPTION.NAME); textBoxName->Text = gcnew String(MTOPTION.NAME);
numericUpDownPort->Value = MTOPTION.PORT;
numericUpDownMaxConnection->Value = MTOPTION.MAX_CONNECTION;
textBoxComment->Text = gcnew String(MTOPTION.COMMENT); textBoxComment->Text = gcnew String(MTOPTION.COMMENT);
textBoxWelcome->Text = gcnew String(MTOPTION.WELCOME); 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;
}
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);
}
}
System::Void StartupForm_Shown(System::Object^ sender, System::EventArgs^ e) { System::Void StartupForm_Shown(System::Object^ sender, System::EventArgs^ e) {
buttonOK->Focus(); buttonOK->Focus();