From 96d04334ef68db1b700d78ae75602d082422184c Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Fri, 19 Mar 2021 08:42:40 +0100 Subject: [PATCH] BUG-2745: Fixed registering issue when a hotkey is not or wrongly configured. --- Greenshot/Forms/MainForm.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index 1a38839c8..4053b41f5 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -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); } }