diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index d6f3e9b82..8bbfeebda 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -588,6 +588,12 @@ extern "C" bool IniSectionClear(LPCWSTR lpSectionName, bool bRemoveEmpty) } // ============================================================================ +extern "C" int IniSectionGetKeyCount(LPCWSTR lpSectionName) +{ + return s_INI.GetSectionSize(lpSectionName); +} +// ============================================================================ + extern "C" bool IniClearAllSections(LPCWSTR lpPrefix, bool bRemoveEmpty) { CSimpleIni::TNamesDepend Sections; @@ -1177,8 +1183,6 @@ void LoadSettings() { WCHAR tchKeyName[MIDSZ_BUFFER] = { L'\0' }; - CFG_VERSION const _ver = Path_IsEmpty(Paths.IniFile) ? CFG_VER_CURRENT : CFG_VER_NONE; - auto* const pPathBuffer = (wchar_t*)AllocMem(PATHLONG_MAX_CCH * sizeof(wchar_t), HEAP_ZERO_MEMORY); bool bDirtyFlag = false; // do we have to save the file on done @@ -1190,8 +1194,8 @@ void LoadSettings() const WCHAR* const IniSecSettings2 = Constants.Settings2_Section; // -------------------------------------------------------------------------- - // prerequisites - Globals.iCfgVersionRead = IniSectionGetInt(IniSecSettings, L"SettingsVersion", _ver); + // prerequisites - assume current version if SettingsVersion is not defined + Globals.iCfgVersionRead = IniSectionGetInt(IniSecSettings, L"SettingsVersion", CFG_VER_CURRENT); Defaults.SaveSettings = Path_IsNotEmpty(Paths.IniFile); Settings.SaveSettings = Defaults.SaveSettings && IniSectionGetBool(IniSecSettings, L"SaveSettings", Defaults.SaveSettings); @@ -2401,6 +2405,10 @@ bool SaveAllSettings(bool bForceSaveSettings) if (ok) { + if (Globals.bIniFileFromScratch) { + IniSectionSetString(_W(SAPPNAME), NULL, NULL); + } + _SaveSettings(bForceSaveSettings); if (Globals.bCanSaveIniFile) { @@ -2436,6 +2444,8 @@ bool SaveAllSettings(bool bForceSaveSettings) ok = (ok ? CloseSettingsFile(__func__, true) : true); + Globals.bIniFileFromScratch = false; // INI has content now + // maybe separate INI files for Style-Themes if (Globals.uCurrentThemeIndex > 0) { Style_SaveSettings(bForceSaveSettings); diff --git a/src/Config/Config.h b/src/Config/Config.h index 1430f9d95..e5425e3e6 100644 --- a/src/Config/Config.h +++ b/src/Config/Config.h @@ -97,6 +97,7 @@ inline bool IniSectionSetPos(LPCWSTR lpSectionName, LPCWSTR lpKeyName, DocPos po // bool IniSectionDelete(LPCWSTR lpSectionName, LPCWSTR lpKeyName, bool bRemoveEmpty); bool IniSectionClear(LPCWSTR lpSectionName, bool bRemoveEmpty); +int IniSectionGetKeyCount(LPCWSTR lpSectionName); bool IniClearAllSections(LPCWSTR lpPrefix, bool bRemoveEmpty); // ---------------------------------------------------------------------------- diff --git a/src/MuiLanguage.c b/src/MuiLanguage.c index 4feb3f830..21c39390f 100644 --- a/src/MuiLanguage.c +++ b/src/MuiLanguage.c @@ -185,7 +185,7 @@ void SetMuiLanguage(const unsigned muiLngIndex) { StringCchCopyW(Settings2.PreferredLanguageLocaleName, COUNTOF(Settings2.PreferredLanguageLocaleName), pLocaleName); - if (Globals.bCanSaveIniFile) { + if (Globals.bCanSaveIniFile && !Globals.bIniFileFromScratch) { if (StrCmpIW(Settings2.PreferredLanguageLocaleName, Default_PreferredLanguageLocaleName) != 0) { IniFileSetString(Paths.IniFile, Constants.Settings2_Section, SettingName, Settings2.PreferredLanguageLocaleName); } else { diff --git a/src/Styles.c b/src/Styles.c index 2abad7453..40b4a4713 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -1154,6 +1154,13 @@ bool Style_ToIniSection(bool bForceAll) IniSectionDelete(L"Default Text", NULL, true); IniSectionDelete(L"2nd Default Text", NULL, true); + // remove empty lexer sections (preserve canonical order for non-empty ones) + for (int iLexer = 0; iLexer < COUNTOF(g_pLexArray); ++iLexer) { + if (IniSectionGetKeyCount(g_pLexArray[iLexer]->pszName) == 0) { + IniSectionClear(g_pLexArray[iLexer]->pszName, true); + } + } + return true; }