Add trycatch for sysbot read/write, turn off auto-r/w on fail

Closes #156

turning off auto-r/w won't happen if the auto-r/w itself fails. still pops open a message saying error until you turn it off in the other window.
This commit is contained in:
Kurt
2020-05-03 13:51:26 -07:00
parent 8de7f7b506
commit 8edf0a6ec4
3 changed files with 42 additions and 11 deletions

View File

@@ -50,8 +50,9 @@ private void B_WriteCurrent_Click(object sender, EventArgs e)
try
{
var result = Injector.Write(true);
if (result != InjectionResult.Success)
WinFormsUtil.Alert(result.ToString());
if (result == InjectionResult.Success)
return;
WinFormsUtil.Alert(result.ToString());
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
@@ -59,6 +60,7 @@ private void B_WriteCurrent_Click(object sender, EventArgs e)
{
WinFormsUtil.Error(ex.Message);
}
TurnOffAuto();
}
private void B_ReadCurrent_Click(object sender, EventArgs e)
@@ -66,8 +68,9 @@ private void B_ReadCurrent_Click(object sender, EventArgs e)
try
{
var result = Injector.Read(true);
if (result != InjectionResult.Success)
WinFormsUtil.Alert(result.ToString());
if (result == InjectionResult.Success)
return;
WinFormsUtil.Alert(result.ToString());
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception ex)
@@ -75,6 +78,15 @@ private void B_ReadCurrent_Click(object sender, EventArgs e)
{
WinFormsUtil.Error(ex.Message);
}
TurnOffAuto();
}
private void TurnOffAuto()
{
if (CHK_AutoRead.Checked)
CHK_AutoRead.Checked = false;
if (CHK_AutoWrite.Checked)
CHK_AutoWrite.Checked = false;
}
private void CHK_AutoWrite_CheckedChanged(object sender, EventArgs e) => Injector.AutoInjectEnabled = CHK_AutoWrite.Checked;