BUG-2745: Fixed registering issue when a hotkey is not or wrongly configured.

This commit is contained in:
Robin Krom 2021-03-19 08:42:40 +01:00
commit 96d04334ef
No known key found for this signature in database
GPG key ID: BCC01364F1371490

View file

@ -532,21 +532,26 @@ namespace Greenshot.Forms {
private static bool RegisterWrapper(StringBuilder failedKeys, string functionName, string configurationKey, HotKeyHandler handler, bool ignoreFailedRegistration) {
IniValue hotkeyValue = _conf.Values[configurationKey];
var hotkeyStringValue = hotkeyValue.Value?.ToString();
if (string.IsNullOrEmpty(hotkeyStringValue))
{
return true;
}
try {
bool success = RegisterHotkey(failedKeys, functionName, hotkeyValue.Value.ToString(), handler);
bool success = RegisterHotkey(failedKeys, functionName, hotkeyStringValue, handler);
if (!success && ignoreFailedRegistration) {
LOG.DebugFormat("Ignoring failed hotkey registration for {0}, with value '{1}', resetting to 'None'.", functionName, hotkeyValue);
LOG.DebugFormat("Ignoring failed hotkey registration for {0}, with value '{1}', resetting to 'None'.", functionName, hotkeyStringValue);
_conf.Values[configurationKey].Value = Keys.None.ToString();
_conf.IsDirty = true;
}
return success;
} catch (Exception ex) {
LOG.Warn(ex);
LOG.WarnFormat("Restoring default hotkey for {0}, stored under {1} from '{2}' to '{3}'", functionName, configurationKey, hotkeyValue.Value, hotkeyValue.Attributes.DefaultValue);
LOG.WarnFormat("Restoring default hotkey for {0}, stored under {1} from '{2}' to '{3}'", functionName, configurationKey, hotkeyStringValue, hotkeyValue.Attributes.DefaultValue);
// when getting an exception the key wasn't found: reset the hotkey value
hotkeyValue.UseValueOrDefault(null);
hotkeyValue.ContainingIniSection.IsDirty = true;
return RegisterHotkey(failedKeys, functionName, hotkeyValue.Value.ToString(), handler);
return RegisterHotkey(failedKeys, functionName, hotkeyStringValue, handler);
}
}