Skip to content

Commit

Permalink
Add braces (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvanpoppel committed Apr 5, 2020
1 parent f6d1206 commit 15bddc9
Show file tree
Hide file tree
Showing 13 changed files with 370 additions and 53 deletions.
66 changes: 55 additions & 11 deletions KeeTrayTOTP/FormSettings.cs
Expand Up @@ -179,7 +179,11 @@ private void ToolStripButtonRefreshTimeCorrection_Click(object sender, EventArgs
ListViewTimeCorrectionList.Items.AddRange(_plugin.TimeCorrections.ToLvi());
if (!_plugin.NetworkIsConnected)
{
if (_networkWasConnected) MessageBox.Show(string.Format(Localization.Strings.SettingsNoInternetDetected, Environment.NewLine), Localization.Strings.TrayTOTPPlugin, MessageBoxButtons.OK, MessageBoxIcon.Information);
if (_networkWasConnected)
{
MessageBox.Show(string.Format(Localization.Strings.SettingsNoInternetDetected, Environment.NewLine), Localization.Strings.TrayTOTPPlugin, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

ToolStripButtonAddTimeCorrection.Enabled = false;
ToolStripButtonPropertiesTimeCorrection.Enabled = false;
_networkWasConnected = false;
Expand All @@ -194,7 +198,11 @@ private void ToolStripButtonRefreshTimeCorrection_Click(object sender, EventArgs

private void ButtonOK_Click(object sender, EventArgs e)
{
if (HasErrors()) return;
if (HasErrors())
{
return;
}

Working(true, true); //Set controls depending on the state of action.
WorkerSave.RunWorkerAsync("OK");
}
Expand All @@ -206,7 +214,11 @@ private void ButtonCancel_Click(object sender, EventArgs e)

private void ButtonApply_Click(object sender, EventArgs e)
{
if (HasErrors()) return;
if (HasErrors())
{
return;
}

Working(true, true); //Set controls depending on the state of action.
WorkerSave.RunWorkerAsync();
}
Expand All @@ -218,16 +230,36 @@ private bool HasErrors()
ErrorProviderSettings.SetError(TextBoxAutoTypeFieldName, string.Empty);
ErrorProviderSettings.SetError(ComboBoxTOTPSeedStringName, string.Empty);
ErrorProviderSettings.SetError(ComboBoxTOTPSettingsStringName, string.Empty);
if (TextBoxAutoTypeFieldName.Text.Contains("{") || TextBoxAutoTypeFieldName.Text.Contains("}")) ErrorProviderSettings.SetError(TextBoxAutoTypeFieldName, Localization.Strings.SettingsInvalidCharacter);
if (TextBoxAutoTypeFieldName.Text.Contains("{") || TextBoxAutoTypeFieldName.Text.Contains("}"))
{
ErrorProviderSettings.SetError(TextBoxAutoTypeFieldName, Localization.Strings.SettingsInvalidCharacter);
}

if (ComboBoxTOTPSeedStringName.Text == ComboBoxTOTPSettingsStringName.Text)
{
ErrorProviderSettings.SetError(ComboBoxTOTPSeedStringName, Localization.Strings.SettingsInvalidNameSetting);
ErrorProviderSettings.SetError(ComboBoxTOTPSettingsStringName, Localization.Strings.SettingsInvalidNameSeed);
}
if (ErrorProviderSettings.GetError(TextBoxAutoTypeFieldName) != string.Empty) temp = true;
if (ErrorProviderSettings.GetError(ComboBoxTOTPSeedStringName) != string.Empty) temp = true;
if (ErrorProviderSettings.GetError(ComboBoxTOTPSettingsStringName) != string.Empty) temp = true;
if (temp) ErrorProviderSettings.SetError(ButtonOK, Localization.Strings.SettingsErrors);
if (ErrorProviderSettings.GetError(TextBoxAutoTypeFieldName) != string.Empty)
{
temp = true;
}

if (ErrorProviderSettings.GetError(ComboBoxTOTPSeedStringName) != string.Empty)
{
temp = true;
}

if (ErrorProviderSettings.GetError(ComboBoxTOTPSettingsStringName) != string.Empty)
{
temp = true;
}

if (temp)
{
ErrorProviderSettings.SetError(ButtonOK, Localization.Strings.SettingsErrors);
}

return temp;
}

Expand Down Expand Up @@ -293,7 +325,10 @@ private void WorkerLoad_DoWork(object sender, DoWorkEventArgs e)
}
ComboBoxTOTPSeedStringName.Text = _plugin.PluginHost.CustomConfig.GetString(KeeTrayTOTPExt.setname_string_TOTPSeed_StringName, Localization.Strings.TOTPSeed);
ComboBoxTOTPSettingsStringName.Text = _plugin.PluginHost.CustomConfig.GetString(KeeTrayTOTPExt.setname_string_TOTPSettings_StringName, Localization.Strings.TOTPSettings);
if (WorkerLoad.CancellationPending) e.Cancel = true;
if (WorkerLoad.CancellationPending)
{
e.Cancel = true;
}
}

private void WorkerLoad_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
Expand Down Expand Up @@ -372,7 +407,10 @@ private void WorkerSave_DoWork(object sender, DoWorkEventArgs e)
//Storage
_plugin.PluginHost.CustomConfig.SetString(KeeTrayTOTPExt.setname_string_TOTPSeed_StringName, ComboBoxTOTPSeedStringName.Text);
_plugin.PluginHost.CustomConfig.SetString(KeeTrayTOTPExt.setname_string_TOTPSettings_StringName, ComboBoxTOTPSettingsStringName.Text);
if (WorkerSave.CancellationPending) e.Cancel = true;
if (WorkerSave.CancellationPending)
{
e.Cancel = true;
}
}

private void WorkerSave_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
Expand All @@ -385,7 +423,13 @@ private void WorkerSave_RunWorkerCompleted(object sender, RunWorkerCompletedEven
else
{
Working(false, true); //Set controls depending on the state of action.
if (e.Result != null) if (e.Result.ToString() == "OK") DialogResult = DialogResult.OK;
if (e.Result != null)
{
if (e.Result.ToString() == "OK")
{
DialogResult = DialogResult.OK;
}
}
}
}

Expand Down
24 changes: 20 additions & 4 deletions KeeTrayTOTP/FormTimeCorrection.cs
Expand Up @@ -154,10 +154,26 @@ private void WorkerWaitForCheck_RunWorkerCompleted(object sender, RunWorkerCompl
private void ButtonVerify_Click(object sender, EventArgs e)
{
ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, string.Empty); //Clears input errors.
if (!ComboBoxUrlTimeCorrection.Text.StartsWith("http")) ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, Localization.Strings.TcUrlMustContainHttp); //Verifies if the URL is valid.
if (!ComboBoxUrlTimeCorrection.Text.Contains("://")) ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, Localization.Strings.TcUrlInvalid); //Verifies if the URL is valid.
if (_plugin.TimeCorrections[ComboBoxUrlTimeCorrection.Text] != null) ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, Localization.Strings.TcUrlExists); //Verifies if the URL is existing.
if (ErrorProviderTimeCorrection.GetError(ComboBoxUrlTimeCorrection) != string.Empty) return; //Prevents the validation if input has an error.
if (!ComboBoxUrlTimeCorrection.Text.StartsWith("http"))
{
ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, Localization.Strings.TcUrlMustContainHttp); //Verifies if the URL is valid.
}

if (!ComboBoxUrlTimeCorrection.Text.Contains("://"))
{
ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, Localization.Strings.TcUrlInvalid); //Verifies if the URL is valid.
}

if (_plugin.TimeCorrections[ComboBoxUrlTimeCorrection.Text] != null)
{
ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, Localization.Strings.TcUrlExists); //Verifies if the URL is existing.
}

if (ErrorProviderTimeCorrection.GetError(ComboBoxUrlTimeCorrection) != string.Empty)
{
return; //Prevents the validation if input has an error.
}

PictureBoxTimeCorrection.Image = ImageListErrorProvider.Images[1]; //Displays working icon.
LabelStatusTimeCorrection.Text = Localization.Strings.TcPleaseWaitVerifying; //Diplays attempt message.
ButtonVerify.Enabled = false; //Prevents the user to retry the URL validation.
Expand Down
11 changes: 11 additions & 0 deletions KeeTrayTOTP/Libraries/Base32.cs
Expand Up @@ -32,9 +32,14 @@ public static class Base32
public static string Encode(byte[] data)
{
if (data == null)
{
throw new ArgumentNullException();
}

if (data.Length == 0)
{
throw new ArgumentNullException();
}

// The output character count is calculated in 40 bit blocks. That is because the least
// common blocks size for both binary (8 bit) and base 32 (5 bit) is 40. Padding must be used
Expand Down Expand Up @@ -64,7 +69,9 @@ public static string Encode(byte[] data)

// If we didn't finish, write the last current working char.
if (currentPosition != outputCharacterCount)
{
outputBuffer[currentPosition++] = EncodingChars[workingValue];
}

// RFC 4648 specifies that padding up to the end of the next 40 bit block must be provided
// Since the outputCharacterCount does account for the paddingCharacters, fill it out.
Expand All @@ -85,13 +92,17 @@ public static string Encode(byte[] data)
public static byte[] Decode(string base32)
{
if (string.IsNullOrEmpty(base32))
{
throw new ArgumentNullException();
}

var unpaddedBase32 = base32.ToUpperInvariant().TrimEnd('=');
foreach (var c in unpaddedBase32)
{
if (EncodingChars.IndexOf(c) < 0)
{
throw new ArgumentException("Base32 contains illegal characters.");
}
}

// we have already removed the padding so this will tell us how many actual bytes there should be.
Expand Down
3 changes: 2 additions & 1 deletion KeeTrayTOTP/Libraries/QRCoder/QRCode.cs
Expand Up @@ -135,8 +135,9 @@ public Bitmap GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
}
}
else
{
gfx.FillRectangle(lightBrush, new Rectangle(x - offset, y - offset, pixelsPerModule, pixelsPerModule));

}
}
}

Expand Down
6 changes: 5 additions & 1 deletion KeeTrayTOTP/Libraries/QRCoder/QRCodeData.cs
Expand Up @@ -43,7 +43,9 @@ public QRCodeData(int version)
var size = ModulesPerSideFromVersion(version);
this.ModuleMatrix = new List<BitArray>();
for (var i = 0; i < size; i++)
{
this.ModuleMatrix.Add(new BitArray(size));
}
}
public QRCodeData(byte[] rawData, Compression compressMode)
{
Expand Down Expand Up @@ -80,7 +82,9 @@ public QRCodeData(byte[] rawData, Compression compressMode)
}

if (bytes[0] != 0x51 || bytes[1] != 0x52 || bytes[2] != 0x52)
throw new Exception("Invalid raw data file. Filetype doesn't match \"QRR\".");
{
throw new Exception("Invalid raw data file. Filetype doesn't match \"QRR\".");
}

//Set QR code version
var sideLen = (int)bytes[4];
Expand Down

0 comments on commit 15bddc9

Please sign in to comment.