fix: NONE vs EMPTY INI file handling, remove styling empty sections

This commit is contained in:
Rainer Kottenhoff 2026-04-14 13:32:18 +02:00
parent 0a3f969c3d
commit fa27fdd60d
4 changed files with 23 additions and 5 deletions

View File

@ -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);

View File

@ -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);
// ----------------------------------------------------------------------------

View File

@ -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 {

View File

@ -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;
}