Skip to content

Commit

Permalink
Internal improvements
Browse files Browse the repository at this point in the history
Catch race conditon exceptions and exceptions because of invalid config data

Closes #17
  • Loading branch information
Rookiestyle committed Jul 23, 2022
1 parent 2518ef1 commit 918e1c4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
12 changes: 12 additions & 0 deletions src/ColoredSecureTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
48 changes: 32 additions & 16 deletions src/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion version.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:
ColoredPassword:0.14.1
ColoredPassword:0.14.2
ColoredPassword!de:6
ColoredPassword!pl:2
ColoredPassword!pt:2
Expand Down

0 comments on commit 918e1c4

Please sign in to comment.