public void LoadEntry(SettingsEntry entry, string section, string key) { try { if (!m_mutex.WaitOne(2000)) { Logger.Warn("Failed to acquire settings lock"); return; } } catch (AbandonedMutexException) { // Ignore; this might be a previous instance that crashed } try { const int len = 255; var must_migrate = false; var tmp = new StringBuilder(len); var result = NativeMethods.GetPrivateProfileString(section, key, entry.ToString(), tmp, len, FullPath); if (result == 0) { // Compatibility code for keys that moved from the "global" // to the "composing" or "tweaks" section. if (section != "global") { result = NativeMethods.GetPrivateProfileString("global", key, entry.ToString(), tmp, len, FullPath); if (result == 0) { return; } must_migrate = true; } } // This may throw, but will be caught gracefully entry.LoadString(tmp.ToString()); if (must_migrate) { NativeMethods.WritePrivateProfileString("global", key, null, FullPath); NativeMethods.WritePrivateProfileString(section, key, entry.ToString(), FullPath); } } catch (Exception ex) { Logger.Warn(ex, $"Failed to load settings entry {section}.{key}"); } finally { // Ensure the mutex is always released even if an // exception is thrown m_mutex.ReleaseMutex(); } }
private static void LoadEntry(SettingsEntry entry, string section, string key) { try { if (!m_mutex.WaitOne(2000)) { return; } } catch (AbandonedMutexException) { /* Ignore; this might be a previous instance that crashed */ } try { const int len = 255; var tmp = new StringBuilder(len); var result = NativeMethods.GetPrivateProfileString(section, key, "", tmp, len, GetConfigFile()); if (result == 0) { return; } entry.LoadString(tmp.ToString()); } finally { // Ensure the mutex is always released even if an // exception is thrown m_mutex.ReleaseMutex(); } }
private static void LoadEntry(SettingsEntry entry, string section, string key) { try { if (!m_mutex.WaitOne(2000)) { return; } } catch (AbandonedMutexException) { /* Ignore; this might be a previous instance that crashed */ } try { const int len = 255; var migrated = false; var tmp = new StringBuilder(len); var result = NativeMethods.GetPrivateProfileString(section, key, "", tmp, len, GetConfigFile()); if (result == 0) { // Compatibility code for keys that moved from the "global" // to the "composing" or "tweaks" section. if (section != "global") { result = NativeMethods.GetPrivateProfileString("global", key, "", tmp, len, GetConfigFile()); if (result == 0) { return; } migrated = true; } } entry.LoadString(tmp.ToString()); if (migrated) { NativeMethods.WritePrivateProfileString("global", key, null, GetConfigFile()); NativeMethods.WritePrivateProfileString(section, key, entry.ToString(), GetConfigFile()); } } finally { // Ensure the mutex is always released even if an // exception is thrown m_mutex.ReleaseMutex(); } }
static Settings() { Language = new SettingsEntry <string>(GlobalSection, "language", ""); ComposeKey = new SettingsEntry <Key>(GlobalSection, "compose_key", m_default_compose_key); ResetDelay = new SettingsEntry <int>(GlobalSection, "reset_delay", -1); CaseInsensitive = new SettingsEntry <bool>(GlobalSection, "case_insensitive", false); DiscardOnInvalid = new SettingsEntry <bool>(GlobalSection, "discard_on_invalid", false); BeepOnInvalid = new SettingsEntry <bool>(GlobalSection, "beep_on_invalid", false); KeepOriginalKey = new SettingsEntry <bool>(GlobalSection, "keep_original_key", false); InsertZwsp = new SettingsEntry <bool>(GlobalSection, "insert_zwsp", false); EmulateCapsLock = new SettingsEntry <bool>(GlobalSection, "emulate_capslock", false); ShiftDisablesCapsLock = new SettingsEntry <bool>(GlobalSection, "shift_disables_capslock", false); }
static Settings() { Language = new SettingsEntry <string>(GlobalSection, "language", ""); ComposeKeys = new SettingsEntry <KeySequence>(GlobalSection, "compose_key", new KeySequence()); ResetDelay = new SettingsEntry <int>(GlobalSection, "reset_delay", -1); Disabled = new SettingsEntry <bool>(GlobalSection, "disabled", false); UnicodeInput = new SettingsEntry <bool>(GlobalSection, "unicode_input", true); CaseInsensitive = new SettingsEntry <bool>(GlobalSection, "case_insensitive", false); DiscardOnInvalid = new SettingsEntry <bool>(GlobalSection, "discard_on_invalid", false); BeepOnInvalid = new SettingsEntry <bool>(GlobalSection, "beep_on_invalid", false); KeepOriginalKey = new SettingsEntry <bool>(GlobalSection, "keep_original_key", false); InsertZwsp = new SettingsEntry <bool>(GlobalSection, "insert_zwsp", false); EmulateCapsLock = new SettingsEntry <bool>(GlobalSection, "emulate_capslock", false); ShiftDisablesCapsLock = new SettingsEntry <bool>(GlobalSection, "shift_disables_capslock", false); CapsLockCapitalizes = new SettingsEntry <bool>(GlobalSection, "capslock_capitalizes", false); }
static Settings() { Language = new SettingsEntry<string>(GlobalSection, "language", ""); ComposeKey = new SettingsEntry<Key>(GlobalSection, "compose_key", m_default_compose_key); ResetDelay = new SettingsEntry<int>(GlobalSection, "reset_delay", -1); Disabled = new SettingsEntry<bool>(GlobalSection, "disabled", false); UnicodeInput = new SettingsEntry<bool>(GlobalSection, "unicode_input", true); CaseInsensitive = new SettingsEntry<bool>(GlobalSection, "case_insensitive", false); DiscardOnInvalid = new SettingsEntry<bool>(GlobalSection, "discard_on_invalid", false); BeepOnInvalid = new SettingsEntry<bool>(GlobalSection, "beep_on_invalid", false); KeepOriginalKey = new SettingsEntry<bool>(GlobalSection, "keep_original_key", false); InsertZwsp = new SettingsEntry<bool>(GlobalSection, "insert_zwsp", false); EmulateCapsLock = new SettingsEntry<bool>(GlobalSection, "emulate_capslock", false); ShiftDisablesCapsLock = new SettingsEntry<bool>(GlobalSection, "shift_disables_capslock", false); CapsLockCapitalizes = new SettingsEntry<bool>(GlobalSection, "capslock_capitalizes", false); }