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(); } }