Skip to content

Commit

Permalink
Fix a crash on macOS entering an invalid value for pool port
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoolls committed Dec 29, 2017
1 parent aaaa374 commit 5f26b06
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
21 changes: 11 additions & 10 deletions MultiMiner.Win/Forms/Configuration/PoolsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 54 additions & 2 deletions MultiMiner.Win/Forms/Configuration/PoolsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ private void coinListBox_DrawItem(object sender, DrawItemEventArgs e)
private void miningPoolBindingSource_CurrentChanged(object sender, EventArgs e)
{
PopulateWorkerNames();
PopulatePort();
}

private void PopulateWorkerNames()
Expand Down Expand Up @@ -443,13 +444,17 @@ private void userNameCombo_SelectedIndexChanged(object sender, EventArgs e)
//parse the port out for folks that paste in host:port
private void hostEdit_Validated(object sender, EventArgs e)
{
if (miningPoolBindingSource.Current != null)
ParseHostForPort();
ParseHostForPort();
}

private void ParseHostForPort()
{
MiningPool currentPool = (MiningPool)miningPoolBindingSource.Current;
if (currentPool == null)
{
return;
}

int newPort;
string newHost;

Expand Down Expand Up @@ -615,5 +620,52 @@ private bool ValidateHostText(string hostText)
}
return true;
}

// begin port handling - don't databind as it crashes on macOS when an invalid value is entered (e.g. alpha or no value - delete port)
private void portEdit_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
string portText = ((TextBox)sender).Text;
e.Cancel = !ValidatePortText(portText);
}

private bool ValidatePortText(string portText)
{
int port;
bool isValid = Int32.TryParse(portText, out port);
if (isValid)
{
return true;
}
else
{
MessageBox.Show(String.Format("The specified value '{0}' is not a valid port.", portText), "Invalid Port", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}

private void portEdit_Validated(object sender, EventArgs e)
{
MiningPool currentPool = (MiningPool)miningPoolBindingSource.Current;
if (currentPool == null)
{
return;
}

string portText = ((TextBox)sender).Text;
currentPool.Port = Int32.Parse(portText); // already know it's valid from the Validating event
}

private void PopulatePort()
{
MiningPool currentPool = (MiningPool)miningPoolBindingSource.Current;
if (currentPool == null)
{
return;
}

portEdit.Text = currentPool.Port.ToString();
}

// end port handling
}
}

0 comments on commit 5f26b06

Please sign in to comment.