From 918e1c4946f3785bf3a9e9b8eed462c5a51b8409 Mon Sep 17 00:00:00 2001 From: rookiestyle Date: Sat, 23 Jul 2022 11:55:38 +0200 Subject: [PATCH] Internal improvements Catch race conditon exceptions and exceptions because of invalid config data Closes #17 --- src/ColoredSecureTextBox.cs | 12 +++++++++ src/Properties/AssemblyInfo.cs | 4 +-- src/Util.cs | 48 ++++++++++++++++++++++------------ version.info | 2 +- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/ColoredSecureTextBox.cs b/src/ColoredSecureTextBox.cs index c425e19..bf3cd88 100644 --- a/src/ColoredSecureTextBox.cs +++ b/src/ColoredSecureTextBox.cs @@ -197,6 +197,18 @@ public override void EnableProtection(bool bEnable) RememberProtectionState(bEnable); return; } + try + { + //Use methods like Select, Focus sometimes results in an exception + //Happens in race conditions only when the form itself is disposed already + EnableProtectionInternal(bEnable); + } + catch { } + } + + private void EnableProtectionInternal(bool bEnable) + { + if (!IsDisposed || Disposing) return; if (bEnable) { Visible = true; diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 692a95b..feac855 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.14.1")] -[assembly: AssemblyFileVersion("0.14.1")] +[assembly: AssemblyVersion("0.14.2")] +[assembly: AssemblyFileVersion("0.14.2")] diff --git a/src/Util.cs b/src/Util.cs index 86d4e52..0ddab8f 100644 --- a/src/Util.cs +++ b/src/Util.cs @@ -136,6 +136,30 @@ public static int ColorDifferenceThreshold get { return (int)m_Config.GetLong("ColoredPassword.ColorDifferenceThreshold", 26); } } + //Some users manually change the config file + //This might result in ugly error messages / plugin behaviour otherwise + //cf. https://github.com/Rookiestyle/ColoredPassword/issues/17 + private static Color GetConfigColor(string strID, string strDefault) + { + var s = m_Config.GetString(strID, strDefault); + if (s == null) + { + PluginTools.PluginDebug.AddError("Error reading color value", 0, new string[] { "ID: " + strID }); + s = strDefault; + } + try + { + return NameToColor(s); + } + catch + { + PluginTools.PluginDebug.AddError("Error reading color value", 0, new string[] { "ID: " + strID, "Value: " + s }); + if (strID.ToLowerInvariant().Contains("back")) s = "Window"; + else s = "WindowText"; + } + return NameToColor(s); + } + public static void Read() { bool test = Testmode; @@ -145,23 +169,15 @@ public static void Read() Active = m_Config.GetBool(ConfigPrefix + "Active", true); ColorEntryView = m_Config.GetBool(ConfigPrefix + "ColorEntryView", true); ListViewKeepBackgroundColor = m_Config.GetBool(ConfigPrefix + "ListViewKeepBackgroundColor", true); - string help = m_Config.GetString(ConfigPrefix + "ForeColorDefault", "WindowText"); - ForeColorDefault = NameToColor(help); - help = m_Config.GetString(ConfigPrefix + "BackColorDefault", "Window"); - BackColorDefault = NameToColor(help); - help = m_Config.GetString(ConfigPrefix + "ForeColorDigit", "Red"); - ForeColorDigit = NameToColor(help); - help = m_Config.GetString(ConfigPrefix + "BackColorDigit", "White"); - BackColorDigit = NameToColor(help); - help = m_Config.GetString(ConfigPrefix + "ForeColorSpecial", "Green"); - ForeColorSpecial = NameToColor(help); - help = m_Config.GetString(ConfigPrefix + "BackColorSpecial", "White"); - BackColorSpecial = NameToColor(help); + ForeColorDefault = GetConfigColor(ConfigPrefix + "ForeColorDefault", "WindowText"); + BackColorDefault = GetConfigColor(ConfigPrefix + "BackColorDefault", "Window"); + ForeColorDigit = GetConfigColor(ConfigPrefix + "ForeColorDigit", "Red"); + BackColorDigit = GetConfigColor(ConfigPrefix + "BackColorDigit", "White"); + ForeColorSpecial = GetConfigColor(ConfigPrefix + "ForeColorSpecial", "Green"); + BackColorSpecial = GetConfigColor(ConfigPrefix + "BackColorSpecial", "White"); LowercaseDifferent = m_Config.GetBool(ConfigPrefix + "LowercaseDifferent", false); - help = m_Config.GetString(ConfigPrefix + "ForeColorLower", ColorToName(ForeColorDefault)); - ForeColorLower = NameToColor(help); - help = m_Config.GetString(ConfigPrefix + "BackColorLower", ColorToName(BackColorDefault)); - BackColorLower = NameToColor(help); + ForeColorLower = GetConfigColor(ConfigPrefix + "ForeColorLower", ColorToName(ForeColorDefault)); + BackColorLower = GetConfigColor(ConfigPrefix + "BackColorLower", ColorToName(BackColorDefault)); SinglePwDisplayActive = m_Config.GetBool(ConfigPrefix + "SinglePwDisplay", SinglePwDisplayActive); ColorPwGen = m_Config.GetBool(ConfigPrefix + "ColorPwGen", ColorPwGen); Testmode = test; diff --git a/version.info b/version.info index b8806ac..f076bce 100644 --- a/version.info +++ b/version.info @@ -1,5 +1,5 @@ : -ColoredPassword:0.14.1 +ColoredPassword:0.14.2 ColoredPassword!de:6 ColoredPassword!pl:2 ColoredPassword!pt:2