diff --git a/Versions/build.txt b/Versions/build.txt index d00491fd7..0cfbf0888 100644 --- a/Versions/build.txt +++ b/Versions/build.txt @@ -1 +1 @@ -1 +2 diff --git a/res/Notepad3.exe.manifest.conf b/res/Notepad3.exe.manifest.conf index 7d2703e62..6e1459e78 100644 --- a/res/Notepad3.exe.manifest.conf +++ b/res/Notepad3.exe.manifest.conf @@ -3,7 +3,7 @@ Notepad3 RC1 diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index ba802def1..c1ddefad2 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -74,7 +74,9 @@ static int s_iStatusbarSections[STATUS_SECTOR_COUNT] = SBS_INIT_MINUS; // ---------------------------------------------------------------------------- -constexpr bool SI_Success(const SI_Error rc) noexcept { return (rc >= SI_Error::SI_OK); }; +constexpr bool SI_Success(const SI_Error rc) noexcept { + return ((rc == SI_Error::SI_OK) || (rc == SI_Error::SI_UPDATED) || (rc == SI_Error::SI_INSERTED)); +}; // ============================================================================ @@ -97,26 +99,21 @@ extern "C" bool IsIniFileLoaded() return s_INI_Loaded; } +extern "C" void ReleaseIniFile() +{ + s_INI.Reset(); + s_INI_Loaded = false; +} + extern "C" bool SaveIniFile(LPCWSTR lpIniFilePath) { s_INI.SetSpaces(s_bSetSpaces); s_INI.SetMultiLine(s_bUseMultiLine); SI_Error const rc = s_INI.SaveFile(lpIniFilePath, s_bWriteSIG); - if (SI_Success(rc)) { - s_INI.Reset(); // done - s_INI_Loaded = false; - } + ReleaseIniFile(); return SI_Success(rc); } -extern "C" void ReleaseIniFile() -{ - s_INI.Reset(); - s_INI_Loaded = false; - s_INI.SetSpaces(s_bSetSpaces); - s_INI.SetMultiLine(s_bUseMultiLine); -} - //============================================================================= // @@ -291,6 +288,7 @@ extern "C" size_t IniFileGetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LP else { StringCchCopyW(lpReturnedString, cchReturnedString, lpDefault); } + Ini.Reset(); return StringCchLenW(lpReturnedString, cchReturnedString); } // ============================================================================ @@ -308,8 +306,8 @@ extern "C" bool IniFileSetString(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCW if (SI_Success(rc)) { rc = Ini.SaveFile(lpFilePath, s_bWriteSIG); } - Ini.Reset(); } + Ini.Reset(); return SI_Success(rc); } // ============================================================================ @@ -325,6 +323,7 @@ extern "C" int IniFileGetInt(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWSTR //assert(!bHasMultiple); return iValue; } + Ini.Reset(); return iDefault; } // ============================================================================ @@ -355,6 +354,7 @@ extern "C" bool IniFileGetBool(LPCWSTR lpFilePath, LPCWSTR lpSectionName, LPCWST //assert(!bHasMultiple); return bValue; } + Ini.Reset(); return bDefault; } // ============================================================================ @@ -633,6 +633,22 @@ extern "C" bool CreateIniFileEx(LPWSTR lpszIniFile) //============================================================================= +//============================================================================= +// +// OpenSettingsFile() +// + +bool OpenSettingsFile() +{ + if (StrIsNotEmpty(Globals.IniFile)) { + if (!IsIniFileLoaded()) { + CreateIniFile(); + LoadIniFile(Globals.IniFile); + } + } + return IsIniFileLoaded(); +} + //============================================================================= // @@ -643,7 +659,7 @@ void LoadSettings() { CFG_VERSION const _ver = StrIsEmpty(Globals.IniFile) ? CFG_VER_CURRENT : CFG_VER_NONE; - LoadIniFile(Globals.IniFile); + OpenSettingsFile(); bool bDirtyFlag = false; // do we have to save the file on done @@ -1226,10 +1242,7 @@ void LoadSettings() Globals.pMRUreplace = MRU_Create(_s_RecentReplace, (/*IsWindowsNT()*/true) ? MRU_UTF8 : 0, MRU_ITEMSFNDRPL); MRU_Load(Globals.pMRUreplace); - if (bDirtyFlag) { - SaveIniFile(Globals.IniFile); - } - ReleaseIniFile(); + CloseSettingsFile(bDirtyFlag); // Scintilla Styles Style_Load(); @@ -1238,23 +1251,6 @@ void LoadSettings() -//============================================================================= -// -// OpenSettingsFile() -// - -bool OpenSettingsFile() -{ - if (StrIsNotEmpty(Globals.IniFile)) { - if (!IsIniFileLoaded()) { - CreateIniFile(); - LoadIniFile(Globals.IniFile); - } - } - return IsIniFileLoaded(); -} - - //============================================================================= // // _SaveSettings() @@ -1268,6 +1264,13 @@ bool OpenSettingsFile() IniSectionDelete(IniSecSettings, _W(_STRG(VARNAME)), false); \ } +#define SAVE_VALUE2_IF_NOT_EQ_DEFAULT2(TYPE, VARNAME) \ + if (Settings2.VARNAME != Defaults2.VARNAME) { \ + IniSectionSet##TYPE(IniSecSettings2, _W(_STRG(VARNAME)), Settings.VARNAME); \ + } \ + else { \ + IniSectionDelete(IniSecSettings2, _W(_STRG(VARNAME)), false); \ + } static bool _SaveSettings(bool bForceSaveSettings) { @@ -1500,6 +1503,10 @@ static bool _SaveSettings(bool bForceSaveSettings) SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosX); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, CustomSchemesDlgPosY); + // -------------------------------------------------------------------------- + //const WCHAR* const IniSecSettings2 = Constants.Settings2_Section; + // -------------------------------------------------------------------------- + // -------------------------------------------------------------------------- const WCHAR* const IniSecWindow = Constants.Window_Section; // -------------------------------------------------------------------------- @@ -1594,7 +1601,7 @@ bool SaveAllSettings(bool bForceSaveSettings) } if (ok) { - ok = CloseSettingsFile(); + ok = CloseSettingsFile(true); } // separate INI files for Style-Themes @@ -1612,20 +1619,16 @@ bool SaveAllSettings(bool bForceSaveSettings) // CloseSettingsFile() // -bool CloseSettingsFile() +bool CloseSettingsFile(bool bSaveChanges) { if (!IsIniFileLoaded() || StrIsEmpty(Globals.IniFile)) { return false; } - bool const ok = SaveIniFile(Globals.IniFile); + bool const ok = bSaveChanges ? SaveIniFile(Globals.IniFile) : true; if (ok) { Globals.bIniFileFromScratch = false; } - // force filesystem cache to sync - FILE* fp = nullptr; - _wfopen_s(&fp, Globals.IniFile, L"rb"); - if (fp) { fclose(fp); } ReleaseIniFile(); return ok; @@ -1936,7 +1939,7 @@ void MRU_Save(LPMRULIST pmru) } } if (bOpendByMe) { - CloseSettingsFile(); + CloseSettingsFile(true); } } } @@ -1976,7 +1979,7 @@ bool MRU_MergeSave(LPMRULIST pmru, bool bAddFiles, bool bRelativePath, bool bUne pmruBase = NULL; if (bOpendByMe) { - CloseSettingsFile(); + CloseSettingsFile(true); } return true; } diff --git a/src/Config/Config.h b/src/Config/Config.h index f21b81f66..f1bd7d193 100644 --- a/src/Config/Config.h +++ b/src/Config/Config.h @@ -34,7 +34,7 @@ bool CreateIniFileEx(LPWSTR lpszIniFile); bool OpenSettingsFile(); void LoadSettings(); bool SaveAllSettings(bool bForceSaveSettings); -bool CloseSettingsFile(); +bool CloseSettingsFile(bool bSaveChanges); // ---------------------------------------------------------------------------- diff --git a/src/Config/SimpleIni.h b/src/Config/SimpleIni.h index 90cadda6d..915f0acc3 100644 --- a/src/Config/SimpleIni.h +++ b/src/Config/SimpleIni.h @@ -2624,6 +2624,7 @@ CSimpleIniTempl::SaveFile( #endif // __STDC_WANT_SECURE_LIB__ if (!fp) return SI_FILE; SI_Error rc = SaveFile(fp, a_bAddSignature); + fflush(fp); fclose(fp); return rc; } @@ -2684,6 +2685,7 @@ CSimpleIniTempl::SaveFile( #endif // __STDC_WANT_SECURE_LIB__ if (!fp) return SI_Error::SI_FILE; SI_Error rc = SaveFile(fp, a_bAddSignature); + fflush(fp); fclose(fp); return rc; #else // !_WIN32 (therefore SI_CONVERT_ICU) diff --git a/src/Notepad3.c b/src/Notepad3.c index 0179917b5..5a6d88373 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2168,7 +2168,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) if (Globals.hwndToolbar) { DestroyWindow(Globals.hwndToolbar); } - LoadIniFile(Globals.IniFile); + OpenSettingsFile(); bool bDirtyFlag = false; Globals.hwndToolbar = CreateWindowEx(0,TOOLBARCLASSNAME,NULL,dwToolbarStyle, @@ -2436,9 +2436,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) s_cyReBarFrame = s_bIsAppThemed ? 0 : 2; - if (bDirtyFlag) { - SaveIniFile(Globals.IniFile); - } + CloseSettingsFile(bDirtyFlag); } @@ -5449,7 +5447,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) StringCchPrintf(tchMaximized, COUNTOF(tchMaximized), L"%ix%i Maximized", ResX, ResY); StringCchPrintf(tchZoom, COUNTOF(tchZoom), L"%ix%i Zoom", ResX, ResY); - if (LoadIniFile(Globals.IniFile)) { + if (OpenSettingsFile()) { const WCHAR* const IniSecWindow = Constants.Window_Section; @@ -5482,9 +5480,8 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) else { IniSectionDelete(Constants.Settings2_Section, L"StickyWindowPosition", false); } - - SaveIniFile(Globals.IniFile); } + CloseSettingsFile(true); } break; diff --git a/src/Styles.c b/src/Styles.c index 8b632b9ce..6f8e39aca 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -799,7 +799,6 @@ void Style_ToIniSection(bool bForceAll) // // Style_ExportToFile() // - bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll) { if (StrIsEmpty(szFile)) { @@ -809,11 +808,22 @@ bool Style_ExportToFile(const WCHAR* szFile, bool bForceAll) return false; } - LoadIniFile(szFile); // reset + WCHAR szFilePathNorm[MAX_PATH] = { L'\0' }; + StringCchCopy(szFilePathNorm, COUNTOF(szFilePathNorm), szFile); + NormalizePathEx(szFilePathNorm, COUNTOF(szFilePathNorm), true, false); - Style_ToIniSection(bForceAll); - - return SaveIniFile(szFile); + bool ok = false; + if (StringCchCompareXI(szFilePathNorm, Globals.IniFile) == 0) { + ok = OpenSettingsFile(); + Style_ToIniSection(bForceAll); + ok = CloseSettingsFile(true); + } + else { + LoadIniFile(szFilePathNorm); // reset + Style_ToIniSection(bForceAll); + SaveIniFile(szFilePathNorm); + } + return ok; } diff --git a/src/VersionEx.h b/src/VersionEx.h index 2b6c1f9b1..0510c0026 100644 --- a/src/VersionEx.h +++ b/src/VersionEx.h @@ -9,7 +9,7 @@ #define VERSION_MAJOR 5 #define VERSION_MINOR 20 #define VERSION_REV 216 -#define VERSION_BUILD 1 +#define VERSION_BUILD 2 #define SCINTILLA_VER 430 #define ONIGURUMA_REGEX_VER 6.9.4 #define UCHARDET_VER 2018.09.27