diff --git a/KeeTrayTOTP/FormSettings.cs b/KeeTrayTOTP/FormSettings.cs index 76d9682..b3f4423 100644 --- a/KeeTrayTOTP/FormSettings.cs +++ b/KeeTrayTOTP/FormSettings.cs @@ -344,12 +344,9 @@ private void WorkerLoad_RunWorkerCompleted(object sender, RunWorkerCompletedEven else { Working(false, true); // Set controls depending on the state of action. - if (e.Result != null) + if (e.Result != null && e.Result.ToString() == "Reset") { - if (e.Result.ToString() == "Reset") - { - MessageBox.Show(Localization.Strings.SettingsDefaultValuesRestored, Localization.Strings.TrayTOTPPlugin, MessageBoxButtons.OK, MessageBoxIcon.Information); - } + MessageBox.Show(Localization.Strings.SettingsDefaultValuesRestored, Localization.Strings.TrayTOTPPlugin, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } @@ -426,12 +423,9 @@ 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 != null && e.Result.ToString() == "OK") { - if (e.Result.ToString() == "OK") - { - DialogResult = DialogResult.OK; - } + DialogResult = DialogResult.OK; } } } diff --git a/KeeTrayTOTP/FormTimeCorrection.cs b/KeeTrayTOTP/FormTimeCorrection.cs index 236b922..07d665f 100644 --- a/KeeTrayTOTP/FormTimeCorrection.cs +++ b/KeeTrayTOTP/FormTimeCorrection.cs @@ -51,24 +51,18 @@ private void FormTimeCorrection_Load(object sender, EventArgs e) { GlobalWindowManager.AddWindow(this); - Text = Localization.Strings.TimeCorrection + @" - " + Localization.Strings.TrayTOTPPlugin; //Sets the form's display text. + Text = Localization.Strings.TimeCorrection + " - " + Localization.Strings.TrayTOTPPlugin; if (_plugin.PluginHost.MainWindow.ActiveDatabase.IsOpen) { - foreach (var pe in _plugin.PluginHost.MainWindow.ActiveDatabase.RootGroup.GetEntries(true)) //Goes through all entries to find existing urls but excludes existing time corrections. + foreach (var pe in _plugin.PluginHost.MainWindow.ActiveDatabase.RootGroup.GetEntries(true)) { - if (_plugin.SettingsCheck(pe)) //Checks that settings exists for this entry. + if (_plugin.SettingsCheck(pe)) { - string[] settings = _plugin.SettingsGet(pe); //Gets the entry's totp settings. + string[] settings = _plugin.SettingsGet(pe); bool validUrl; - if (_plugin.SettingsValidate(pe, out validUrl)) //Validates the settings. + if (_plugin.SettingsValidate(pe, out validUrl) && validUrl && !ComboBoxUrlTimeCorrection.Items.Contains(settings[2]) && _plugin.TimeCorrections[settings[2]] == null) { - if (validUrl) //Makes sure the URL is also valid. - { - if (!ComboBoxUrlTimeCorrection.Items.Contains(settings[2]) && _plugin.TimeCorrections[settings[2]] == null) //Checks if not already in combobox or is an existing time correction. - { - ComboBoxUrlTimeCorrection.Items.Add(settings[2]); //Adds the URL to the combobox for quick adding. - } - } + ComboBoxUrlTimeCorrection.Items.Add(settings[2]); } } } diff --git a/KeeTrayTOTP/TrayTOTP_Plugin.cs b/KeeTrayTOTP/TrayTOTP_Plugin.cs index 11c1a62..c0c8d37 100644 --- a/KeeTrayTOTP/TrayTOTP_Plugin.cs +++ b/KeeTrayTOTP/TrayTOTP_Plugin.cs @@ -202,13 +202,10 @@ public override ToolStripMenuItem GetMenuItem(PluginMenuType type) if (PluginHost.MainWindow.GetSelectedEntriesCount() == 1) { var currentEntry = PluginHost.MainWindow.GetSelectedEntry(true); - if (SettingsCheck(currentEntry) && SeedCheck(currentEntry)) + if (SettingsCheck(currentEntry) && SeedCheck(currentEntry) && SettingsValidate(currentEntry)) { - if (SettingsValidate(currentEntry)) - { - enMenuCopyTotp.Enabled = true; - enMenuCopyTotp.Tag = currentEntry; - } + enMenuCopyTotp.Enabled = true; + enMenuCopyTotp.Tag = currentEntry; } enMenuSetupTotp.Enabled = true; @@ -581,12 +578,9 @@ private void OnTimerTick(object sender, EventArgs e) _liColumnsCount = KeePass.Program.Config.MainWindow.EntryListColumns.Count; foreach (var column in KeePass.Program.Config.MainWindow.EntryListColumns) { - if (column.Type == AceColumnType.PluginExt) + if (column.Type == AceColumnType.PluginExt && column.CustomName == Localization.Strings.TOTP) { - if (column.CustomName == Localization.Strings.TOTP) - { - _liColumnTotpVisible = true; - } + _liColumnTotpVisible = true; } } } @@ -627,40 +621,32 @@ private void OnTimerTick(object sender, EventArgs e) /// private void SprEngine_FilterCompile(object sender, SprEventArgs e) { - if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive) + if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive && e.Text.IndexOf(PluginHost.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), StringComparison.InvariantCultureIgnoreCase) >= 0) { - if (e.Text.IndexOf(PluginHost.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), StringComparison.InvariantCultureIgnoreCase) >= 0) + if (SettingsCheck(e.Context.Entry) && SeedCheck(e.Context.Entry)) { - if (SettingsCheck(e.Context.Entry) && SeedCheck(e.Context.Entry)) + if (SettingsValidate(e.Context.Entry)) { - if (SettingsValidate(e.Context.Entry)) - { - string[] settings = SettingsGet(e.Context.Entry); + string[] settings = SettingsGet(e.Context.Entry); - TOTPProvider totpGenerator = new TOTPProvider(settings, ref this.TimeCorrections); + TOTPProvider totpGenerator = new TOTPProvider(settings, ref this.TimeCorrections); - string invalidCharacters; + string invalidCharacters; - if (SeedValidate(e.Context.Entry, out invalidCharacters)) - { - e.Context.Entry.Touch(false); - string totp = totpGenerator.GenerateByByte(Base32.Decode(SeedGet(e.Context.Entry).ReadString().ExtWithoutSpaces())); - e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, PluginHost.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), totp); - } - else - { - e.Text = string.Empty; - MessageService.ShowWarning(Localization.Strings.ErrorBadSeed + invalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore()); - } - if (totpGenerator.TimeCorrectionError) - { - MessageService.ShowWarning(Localization.Strings.WarningBadURL); - } + if (SeedValidate(e.Context.Entry, out invalidCharacters)) + { + e.Context.Entry.Touch(false); + string totp = totpGenerator.GenerateByByte(Base32.Decode(SeedGet(e.Context.Entry).ReadString().ExtWithoutSpaces())); + e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, PluginHost.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), totp); } else { e.Text = string.Empty; - MessageService.ShowWarning(Localization.Strings.ErrorBadSettings); + MessageService.ShowWarning(Localization.Strings.ErrorBadSeed + invalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore()); + } + if (totpGenerator.TimeCorrectionError) + { + MessageService.ShowWarning(Localization.Strings.WarningBadURL); } } else @@ -669,6 +655,11 @@ private void SprEngine_FilterCompile(object sender, SprEventArgs e) MessageService.ShowWarning(Localization.Strings.ErrorBadSettings); } } + else + { + e.Text = string.Empty; + MessageService.ShowWarning(Localization.Strings.ErrorBadSettings); + } } }