Skip to content

Commit

Permalink
Fix a few sonarqube issues (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvanpoppel committed May 9, 2020
1 parent 415615b commit 8bfe2c7
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 195 deletions.
20 changes: 12 additions & 8 deletions KeeTrayTOTP/FormAbout.cs
@@ -1,8 +1,9 @@
using System;
using KeePass.UI;
using KeeTrayTOTP.Localization;
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using KeePass.UI;

namespace KeeTrayTOTP
{
Expand All @@ -14,7 +15,7 @@ internal partial class FormAbout : Form
/// <summary>
/// Tray TOTP Support Url
/// </summary>
private static readonly Uri SupportUrl = new Uri("https://github.com/KeeTrayTOTP/KeeTrayTOTP/issues", UriKind.Absolute);
private static readonly Uri SupportUrl = new Uri(Strings.SupportUrl, UriKind.Absolute);

/// <summary>
/// Windows Form Constructor.
Expand All @@ -33,7 +34,7 @@ private void FormAbout_Load(object sender, EventArgs e)
{
GlobalWindowManager.AddWindow(this);

Text = Localization.Strings.About + " - " + Localization.Strings.TrayTOTPPlugin;
Text = Strings.About + " - " + Strings.TrayTOTPPlugin;
ListViewAbout.Items[0].SubItems.Add(AssemblyTitle);
ListViewAbout.Items[1].SubItems.Add(AssemblyCompany);
ListViewAbout.Items[2].SubItems.Add(AssemblyVersion);
Expand Down Expand Up @@ -169,7 +170,7 @@ private void ListViewAbout_MouseClick(object sender, MouseEventArgs e)
{
var hit = ListViewAbout.HitTest(e.Location);
if (hit.Item != null && hit.Item == ListViewAbout.Items[4] && hit.SubItem == ListViewAbout.Items[4].SubItems[1])
{
{
System.Diagnostics.Process.Start(SupportUrl.ToString());
}
}
Expand All @@ -194,10 +195,13 @@ private void SetHyperlinkStyle(int RowIndex, Color color)
private void ListViewAbout_MouseMove(object sender, MouseEventArgs e)
{
var hit = ListViewAbout.HitTest(e.Location);
if (hit.SubItem != null && hit.SubItem == hit.Item.SubItems[1] && hit.Item == ListViewAbout.Items[4]) {
if (hit.SubItem != null && hit.SubItem == hit.Item.SubItems[1] && hit.Item == ListViewAbout.Items[4])
{
ListViewAbout.Cursor = Cursors.Hand;
} else {
ListViewAbout.Cursor = Cursors.Default;
}
else
{
ListViewAbout.Cursor = Cursors.Default;
}
}
}
Expand Down
246 changes: 123 additions & 123 deletions KeeTrayTOTP/FormSettings.Designer.cs

Large diffs are not rendered by default.

34 changes: 14 additions & 20 deletions KeeTrayTOTP/FormSettings.cs
@@ -1,7 +1,7 @@
using System;
using KeePass.UI;
using System;
using System.ComponentModel;
using System.Windows.Forms;
using KeePass.UI;

namespace KeeTrayTOTP
{
Expand Down Expand Up @@ -376,26 +376,14 @@ private void WorkerSave_DoWork(object sender, DoWorkEventArgs e)
_plugin.Settings.AutoTypeEnable = CheckBoxAutoType.Checked;
if (CheckBoxAutoTypeFieldName.Checked)
{
string oldAutoTypeFieldName = _plugin.Settings.AutoTypeFieldName.ExtWithBrackets();
string newAutoTypeFieldName = TextBoxAutoTypeFieldName.Text.ExtWithBrackets();
KeePass.Util.Spr.SprEngine.FilterPlaceholderHints.Remove(oldAutoTypeFieldName);
if (CheckBoxAutoTypeFieldRename.Checked) //Replace existing field of custom keystrokes from all entries and all groups
if (CheckBoxAutoTypeFieldRename.Checked) // Replace existing field of custom keystrokes from all entries and all groups
{
_plugin.PluginHost.MainWindow.ActiveDatabase.RootGroup.DefaultAutoTypeSequence = _plugin.PluginHost.MainWindow.ActiveDatabase.RootGroup.DefaultAutoTypeSequence.Replace(oldAutoTypeFieldName, newAutoTypeFieldName);
foreach (var group in _plugin.PluginHost.MainWindow.ActiveDatabase.RootGroup.GetGroups(true))
{
group.DefaultAutoTypeSequence = group.DefaultAutoTypeSequence.Replace(oldAutoTypeFieldName, newAutoTypeFieldName);
foreach (var pe in group.GetEntries(false))
{
foreach (var association in pe.AutoType.Associations)
{
association.Sequence = association.Sequence.Replace(oldAutoTypeFieldName, newAutoTypeFieldName);
}
}
}
string oldAutoTypeFieldName = _plugin.Settings.AutoTypeFieldName.ExtWithBrackets();
string newAutoTypeFieldName = TextBoxAutoTypeFieldName.Text.ExtWithBrackets();

SetupAutoType(oldAutoTypeFieldName, newAutoTypeFieldName);
}
_plugin.Settings.AutoTypeFieldName = TextBoxAutoTypeFieldName.Text;
KeePass.Util.Spr.SprEngine.FilterPlaceholderHints.Add(newAutoTypeFieldName);
}
if (WorkerSave.CancellationPending) { e.Cancel = true; return; }

Expand Down Expand Up @@ -450,8 +438,14 @@ private void WorkerReset_DoWork(object sender, DoWorkEventArgs e)

// Auto Type
string newAutoTypeFieldName = Localization.Strings.TOTP.ExtWithBrackets();
KeePass.Util.Spr.SprEngine.FilterPlaceholderHints.Add(newAutoTypeFieldName);
SetupAutoType(oldAutoTypeFieldName, newAutoTypeFieldName);
}

private void SetupAutoType(string oldAutoTypeFieldName, string newAutoTypeFieldName)
{
KeePass.Util.Spr.SprEngine.FilterPlaceholderHints.Remove(oldAutoTypeFieldName);
KeePass.Util.Spr.SprEngine.FilterPlaceholderHints.Add(newAutoTypeFieldName);

_plugin.PluginHost.MainWindow.ActiveDatabase.RootGroup.DefaultAutoTypeSequence = _plugin.PluginHost.MainWindow.ActiveDatabase.RootGroup.DefaultAutoTypeSequence.Replace(oldAutoTypeFieldName, newAutoTypeFieldName);
foreach (var group in _plugin.PluginHost.MainWindow.ActiveDatabase.RootGroup.GetGroups(true))
{
Expand Down
10 changes: 4 additions & 6 deletions KeeTrayTOTP/FormTimeCorrection.cs
@@ -1,10 +1,8 @@
using System;
using KeePass.UI;
using KeeTrayTOTP.Libraries;
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using KeePass.UI;
using KeeTrayTOTP.Helpers;
using KeeTrayTOTP.Libraries;

namespace KeeTrayTOTP
{
Expand Down Expand Up @@ -139,7 +137,7 @@ private void WorkerWaitForCheck_RunWorkerCompleted(object sender, RunWorkerCompl
ButtonVerify.Enabled = true; //Enables the user to retry the URL validation.
ComboBoxUrlTimeCorrection.Enabled = true; //Enables the user to modify the last URL that was attempted to validate.
}
ButtonCancel.Enabled = true; //Enables the user to discard the last URL that was attempted to validate.
ButtonCancel.Enabled = true; //Enables the user to discard the last URL that was attempted to validate.
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion KeeTrayTOTP/ISettings.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace KeeTrayTOTP
{
Expand Down
37 changes: 2 additions & 35 deletions KeeTrayTOTP/Libraries/TOTPProvider.cs
Expand Up @@ -16,45 +16,12 @@ public class TOTPProvider
/// <summary>
/// Duration of generation of each totp, in seconds.
/// </summary>
private int _duration;
public int Duration
{
get
{
return this._duration;
}
set
{
if (value <= 0)
{
throw new Exception("Invalid Duration."); //Throws an exception if the duration is invalid as the class cannot work without it.
}

this._duration = value;
}
}
private readonly int _duration;

/// <summary>
/// Length of the generated totp.
/// </summary>
private int _length;
public int Length
{
get
{
return this._length;
}
set
{
//Throws an exception if the length is invalid as the class cannot work without it.
if (value < 4 || value > 8)
{
throw new Exception("Invalid Length.");
}

this._length = value; //Defines variable from argument.
}
}
private readonly int _length;

public Func<byte[], int, string> Encoder { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion KeeTrayTOTP/Libraries/TimeCorrectionProvider.cs
Expand Up @@ -61,7 +61,7 @@ public TimeCorrectionProvider(string url, bool enable = true)
{
if (string.IsNullOrEmpty(url))
{
throw new Exception("Invalid URL."); //Throws exception if the URL is invalid as the class cannot work without it.
throw new ArgumentException("Invalid URL.", "url");
}

Url = url; //Defines variable from argument.
Expand Down
9 changes: 9 additions & 0 deletions KeeTrayTOTP/Localization/Strings.Designer.cs

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

3 changes: 3 additions & 0 deletions KeeTrayTOTP/Localization/Strings.resx
Expand Up @@ -233,6 +233,9 @@
<data name="ShowQR" xml:space="preserve">
<value>Show QR</value>
</data>
<data name="SupportUrl" xml:space="preserve">
<value>https://github.com/KeeTrayTOTP/KeeTrayTOTP/issues</value>
</data>
<data name="SwitchTo" xml:space="preserve">
<value>Switch to {0}</value>
<comment>{0} is a database name</comment>
Expand Down
1 change: 0 additions & 1 deletion KeeTrayTOTP/Settings.cs
@@ -1,7 +1,6 @@
using KeePass.App.Configuration;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace KeeTrayTOTP
{
Expand Down

0 comments on commit 8bfe2c7

Please sign in to comment.