From 890312272433a87491842b057d8bea3047efde08 Mon Sep 17 00:00:00 2001 From: rkotten Date: Thu, 30 Mar 2023 18:19:48 +0200 Subject: [PATCH] +fix: some more issues around "File Change Monitoring" --- lexilla/Lexilla.vcxproj | 4 +- scintilla/Scintilla.vcxproj | 4 +- src/Config/Config.cpp | 32 ++++++------ src/DynStrg.c | 98 +++++++++++++++++-------------------- src/Edit.c | 8 +-- src/Helpers.h | 6 +-- src/Notepad3.c | 82 ++++++++++++++++--------------- src/Notepad3.h | 2 +- src/Notepad3.vcxproj | 8 +-- src/TypeDefs.h | 11 ++--- 10 files changed, 126 insertions(+), 129 deletions(-) diff --git a/lexilla/Lexilla.vcxproj b/lexilla/Lexilla.vcxproj index 67be12d06..2c59086ff 100644 --- a/lexilla/Lexilla.vcxproj +++ b/lexilla/Lexilla.vcxproj @@ -136,7 +136,7 @@ v142 v143 Unicode - true + false StaticLibrary @@ -163,7 +163,7 @@ v142 v143 Unicode - true + false StaticLibrary diff --git a/scintilla/Scintilla.vcxproj b/scintilla/Scintilla.vcxproj index 5056d1196..6a2dfb707 100644 --- a/scintilla/Scintilla.vcxproj +++ b/scintilla/Scintilla.vcxproj @@ -38,7 +38,7 @@ Unicode StaticLibrary true - true + false v141 v142 v143 @@ -50,7 +50,7 @@ v141 v142 v143 - true + false Unicode diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 3a41dd4ea..798f94e2f 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -1244,36 +1244,38 @@ void LoadSettings() StrgReset(Settings2.FileDlgFilters, pPathBuffer); // handle deprecated (typo) key 'FileCheckInverval' - constexpr const int64_t defaultFCI = 2000; + constexpr const LONG64 NOTSETFCI = -111LL; + constexpr const LONG64 defaultFCI = 2000LL; constexpr const WCHAR* deprecatedKeyART = L"AutoReloadTimeout"; constexpr const WCHAR* deprecatedKeyFCI = L"FileCheckInverval"; constexpr const WCHAR* correctKeyFCI = L"FileCheckInterval"; - int const autoReload = IniSectionGetInt(IniSecSettings2, deprecatedKeyART, -111); // deprecated - if (autoReload != -111) { + LONG64 const autoReload = IniSectionGetLongLong(IniSecSettings2, deprecatedKeyART, NOTSETFCI); // deprecated + if (autoReload != NOTSETFCI) { IniSectionDelete(IniSecSettings2, deprecatedKeyART, true); // deprecated bDirtyFlag = true; } - int const dfci = IniSectionGetInt(IniSecSettings2, deprecatedKeyFCI, -111); // get deprecated typo setting - if (dfci != -111) { + LONG64 const dfci = IniSectionGetLongLong(IniSecSettings2, deprecatedKeyFCI, NOTSETFCI); // get deprecated typo setting + if (dfci != NOTSETFCI) { IniSectionDelete(IniSecSettings2, deprecatedKeyFCI, true); // deprecated wrong (typo) name bDirtyFlag = true; } - int const deprecatedFCI = max_i(autoReload, dfci); + LONG64 const adpDefaultFCI = (max_ll(autoReload, dfci) == NOTSETFCI) ? defaultFCI : + clampll(max_ll(autoReload, dfci), MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL); - Settings2.FileCheckInterval = IniSectionGetLongLong(IniSecSettings2, correctKeyFCI, deprecatedFCI); + Settings2.FileCheckInterval = clampll(IniSectionGetLongLong(IniSecSettings2, correctKeyFCI, adpDefaultFCI), MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL); if (Settings2.FileCheckInterval == defaultFCI) { - if (deprecatedFCI != defaultFCI) { - IniSectionDelete(IniSecSettings2, correctKeyFCI, true); // is default - bDirtyFlag = true; - } - } - else if (Settings2.FileCheckInterval == static_cast(deprecatedFCI)) { - IniSectionSetLongLong(IniSecSettings2, correctKeyFCI, Settings2.FileCheckInterval); + IniSectionDelete(IniSecSettings2, correctKeyFCI, true); // is default bDirtyFlag = true; } - FileWatching.FileCheckInterval = clampll(Settings2.FileCheckInterval, MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL); + else if (Settings2.FileCheckInterval == adpDefaultFCI) { + IniSectionSetLongLong(IniSecSettings2, correctKeyFCI, adpDefaultFCI); + bDirtyFlag = true; + } + + FileWatching.FileCheckInterval = Settings2.FileCheckInterval; + IniSectionGetString(IniSecSettings2, L"FileChangedIndicator", L"[@]", Settings2.FileChangedIndicator, COUNTOF(Settings2.FileChangedIndicator)); diff --git a/src/DynStrg.c b/src/DynStrg.c index ff5ec354b..34183c4e9 100644 --- a/src/DynStrg.c +++ b/src/DynStrg.c @@ -102,23 +102,23 @@ __forceinline size_t SizeOfMemStrg(LPCVOID lpMemory) { /* */ /**************************************************/ -#define limit_len(len) (((len) < STRINGW_MAX_CCH) ? (len) : (STRINGW_MAX_CCH - 1)) +__forceinline size_t limit_len(const size_t len) { return (((len) < STRINGW_MAX_CCH) ? max_s((8 / sizeof(wchar_t)), len) : (STRINGW_MAX_CCH - 1)); } __forceinline STRINGW* ToWStrg(HSTRINGW hstr) { return (STRINGW*)hstr; } -inline static void * AllocBuffer(const size_t len, bool bZeroMem) { +inline static void * AllocBuffer(const size_t len) { if (!s_hndlProcessHeap) { s_hndlProcessHeap = GetProcessHeap(); } - return AllocMemStrg(limit_len(len) * sizeof(wchar_t), bZeroMem ? HEAP_ZERO_MEMORY : 0); + return AllocMemStrg(limit_len(len) * sizeof(wchar_t), HEAP_ZERO_MEMORY); } // ---------------------------------------------------------------------------- -inline static void * ReAllocBuffer(void* pdata, const size_t len, bool bZeroMem, bool bInPlace) { +inline static void * ReAllocBuffer(void* pdata, const size_t len, bool bInPlace) { if (!s_hndlProcessHeap) { s_hndlProcessHeap = GetProcessHeap(); } - DWORD const dwFlags = (bZeroMem ? HEAP_ZERO_MEMORY : 0) | (bInPlace ? HEAP_REALLOC_IN_PLACE_ONLY : 0); + DWORD const dwFlags = HEAP_ZERO_MEMORY | (bInPlace ? HEAP_REALLOC_IN_PLACE_ONLY : 0); return ReAllocMemStrg(pdata, limit_len(len) * sizeof(wchar_t), dwFlags); } // ---------------------------------------------------------------------------- @@ -148,18 +148,16 @@ inline static void FreeBufferW(STRINGW* pstr) { } // ---------------------------------------------------------------------------- -static void ReAllocW(STRINGW* pstr, size_t len, bool bZeroMem) +static void ReAllocW(STRINGW* pstr, size_t len) { len = limit_len(len); size_t const alloc_len = len + 1; if (!pstr->data) { - pstr->data = AllocBuffer(alloc_len, bZeroMem); + pstr->data = AllocBuffer(alloc_len); if (pstr->data) { // init pstr->alloc_length = LengthOfBuffer(pstr->data); - assert("inconsistent data" && (alloc_len != (pstr->alloc_length * sizeof(wchar_t)))); + assert("inconsistent data" && (alloc_len == pstr->alloc_length)); pstr->data_length = 0; - pstr->data[len] = WCHR_NULL; // ensure terminating zero - pstr->data[0] = WCHR_NULL; // ensure empty } else { pstr->alloc_length = 0; @@ -167,17 +165,15 @@ static void ReAllocW(STRINGW* pstr, size_t len, bool bZeroMem) } } else if (pstr->alloc_length < alloc_len) { - pstr->data = ReAllocBuffer(pstr->data, alloc_len, bZeroMem, false); + pstr->data = ReAllocBuffer(pstr->data, alloc_len, false); pstr->alloc_length = LengthOfBuffer(pstr->data); - assert("inconsistent data 1" && (alloc_len != (pstr->alloc_length * sizeof(wchar_t)))); + assert("inconsistent data 1" && (alloc_len == pstr->alloc_length)); /// original memory block is moved, so data_length is not touched assert("inconsistent data 2" && (alloc_len > pstr->data_length)); pstr->data[pstr->data_length] = WCHR_NULL; // ensure terminating zero } else { - if (bZeroMem) { - ZeroMemory(&(pstr->data[pstr->data_length]), (pstr->alloc_length - pstr->data_length) * sizeof(wchar_t)); - } + ZeroMemory(&(pstr->data[pstr->data_length]), (pstr->alloc_length - pstr->data_length) * sizeof(wchar_t)); } } // ---------------------------------------------------------------------------- @@ -187,7 +183,7 @@ static void AllocCopyW(STRINGW* pstr, STRINGW* pDest, size_t copy_len, size_t co size_t new_len = copy_len + extra_len; if (0 < new_len) { - ReAllocW(pDest, new_len, true); + ReAllocW(pDest, new_len); StringCchCopyNW(pDest->data, pDest->alloc_length, (pstr->data + copy_index), copy_len); pDest->data_length = StrlenW(pstr->data); } @@ -196,7 +192,7 @@ static void AllocCopyW(STRINGW* pstr, STRINGW* pDest, size_t copy_len, size_t co static void SetCopyW(STRINGW* pstr, size_t len, LPCWSTR p) { - ReAllocW(pstr, len, false); + ReAllocW(pstr, len); if (pstr->data) { StringCchCopyNW(pstr->data, pstr->alloc_length, p, len); pstr->data_length = StrlenW(pstr->data); @@ -210,7 +206,7 @@ static void SetCopyW(STRINGW* pstr, size_t len, LPCWSTR p) static LPWSTR CopyOldDataW(STRINGW* pstr, size_t* outLen) { size_t const old_siz = StrlenW(pstr->data) + 1; - LPWSTR const ptr = AllocBuffer(old_siz, FALSE); + LPWSTR const ptr = AllocBuffer(old_siz); if (ptr) { StringCchCopyW(ptr, old_siz, pstr->data ? pstr->data : L""); *outLen = wcslen(ptr); @@ -225,7 +221,7 @@ static void FreeUnusedData(STRINGW* pstr, size_t keep_length) { size_t const new_alloc_len = max_s(keep_length + 1, pstr->data_length + 1); if ((pstr->alloc_length > new_alloc_len) ) { - pstr->data = ReAllocBuffer(pstr->data, new_alloc_len, true, false); + pstr->data = ReAllocBuffer(pstr->data, new_alloc_len, false); pstr->alloc_length = LengthOfBuffer(pstr->data); pstr->data_length = StrlenW(pstr->data); } @@ -237,7 +233,7 @@ static void CopyConcatW(STRINGW *pstr, size_t len1, LPCWSTR p1, size_t len2, LPC { size_t const new_len = len1 + len2; if (0 < new_len) { - ReAllocW(pstr, new_len, true); + ReAllocW(pstr, new_len); StringCchCopyNW(pstr->data, pstr->alloc_length, p1, len1); StringCchCatNW(pstr->data, pstr->alloc_length, p2, len2); pstr->data_length = StrlenW(pstr->data); @@ -252,7 +248,7 @@ static void ConcatW(STRINGW* pstr, size_t len, LPCWSTR p) size_t const new_len = pstr->data_length + len; if (pstr->alloc_length <= new_len) { - ReAllocW(pstr, new_len, true); // copies old data + ReAllocW(pstr, new_len); // copies old data } StringCchCatNW(pstr->data, pstr->alloc_length, p, len); pstr->data_length = StrlenW(pstr->data); @@ -410,7 +406,7 @@ static void FormatW(STRINGW* pstr, LPCWSTR fmt, va_list args) max_len += item_len; } - ReAllocW(pstr, max_len, true); + ReAllocW(pstr, max_len); StringCchVPrintfW(pstr->data, pstr->alloc_length, fmt, orig_list); pstr->data_length = StrlenW(pstr->data); @@ -429,7 +425,7 @@ static void FormatW(STRINGW* pstr, LPCWSTR fmt, va_list args) HSTRINGW STRAPI StrgCreate(LPCWSTR str) { - STRINGW *pstr = AllocBuffer(sizeof(STRINGW), true); + STRINGW *pstr = AllocBuffer(sizeof(STRINGW)); if (!pstr) return NULL; if (str) @@ -534,7 +530,7 @@ void STRAPI StrgEmpty(const HSTRINGW hstr, bool truncate) if (!pstr) return; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); return; } (pstr->data)[0] = WCHR_NULL; @@ -552,7 +548,7 @@ void STRAPI StrgSetAt(HSTRINGW hstr, const size_t index, const wchar_t ch) if (!pstr) return; if (!(pstr->data)) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } if (index >= pstr->data_length) { @@ -571,7 +567,7 @@ wchar_t STRAPI StrgGetAt(const HSTRINGW hstr, const size_t index) if (!pstr) return WCHR_NULL; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } if (index >= pstr->data_length) { @@ -632,7 +628,7 @@ size_t STRAPI StrgInsert(HSTRINGW hstr, size_t index, LPCWSTR str) if (!pstr) return STRINGW_INVALID_IDX; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } size_t const ins_len = StrlenW(str); @@ -646,7 +642,7 @@ size_t STRAPI StrgInsert(HSTRINGW hstr, size_t index, LPCWSTR str) new_len += ins_len; if (pstr->alloc_length <= new_len) { - ReAllocW(pstr, new_len, true); + ReAllocW(pstr, new_len); } wmemmove_s((pstr->data + index + ins_len), (pstr->alloc_length - index - ins_len), (pstr->data + index), (new_len - index - ins_len + 1)); @@ -664,14 +660,14 @@ size_t STRAPI StrgInsertCh(HSTRINGW hstr, size_t index, const wchar_t c) if (!pstr) return 0; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } size_t const new_len = pstr->data_length + 1; if (index >= new_len) index = new_len - 1; if (pstr->alloc_length <= new_len) { - ReAllocW(pstr, new_len, true); + ReAllocW(pstr, new_len); } wmemmove_s((pstr->data + index + 1), (pstr->alloc_length - index - 1), (pstr->data + index), (new_len - index)); @@ -689,7 +685,7 @@ size_t STRAPI StrgReplace(HSTRINGW hstr, LPCWSTR pOld, LPCWSTR pNew) if (!pstr) return 0; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } size_t const src_len = StrlenW(pOld); @@ -718,7 +714,7 @@ size_t STRAPI StrgReplace(HSTRINGW hstr, LPCWSTR pOld, LPCWSTR pNew) size_t const new_len = old_len + (repl_len - src_len) * count; if (pstr->alloc_length <= new_len) { - ReAllocW(pstr, new_len, true); + ReAllocW(pstr, new_len); } start = pstr->data; end = pstr->data + pstr->data_length; @@ -757,7 +753,7 @@ size_t STRAPI StrgReplaceCh(HSTRINGW hstr, const wchar_t chOld, const wchar_t ch if (!pstr) return 0; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } size_t count = 0; @@ -786,7 +782,7 @@ size_t STRAPI StrgRemoveCh(HSTRINGW hstr, const wchar_t chRemove) if (!pstr) return 0; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } LPWSTR source = pstr->data; @@ -819,7 +815,7 @@ size_t STRAPI StrgDelete(HSTRINGW hstr, const size_t index, size_t count) if (!pstr) return 0; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } size_t const len = pstr->data_length; @@ -849,7 +845,7 @@ int STRAPI StrgResetFromUTF8(HSTRINGW hstr, const char* str) if (!pstr || !str) return -1; int const len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0) + 1; - ReAllocW(pstr, len, true); + ReAllocW(pstr, len); int const res = MultiByteToWideChar(CP_UTF8, 0, str, -1, pstr->data, (int)pstr->alloc_length); pstr->data_length = StrlenW(pstr->data); return res; @@ -863,7 +859,7 @@ void STRAPI StrgToUpper(HSTRINGW hstr) if (!pstr) return; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } if (pstr->data) _wcsupr_s(pstr->data, pstr->data_length); @@ -877,7 +873,7 @@ void STRAPI StrgToLower(HSTRINGW hstr) if (!pstr) return; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } if (pstr->data) _wcslwr_s(pstr->data, pstr->data_length); @@ -891,7 +887,7 @@ void STRAPI StrgReverse(HSTRINGW hstr) if (!pstr) return; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } _wcsrev(pstr->data); } @@ -904,7 +900,7 @@ void STRAPI StrgTrimRight(HSTRINGW hstr, const wchar_t wch) if (!pstr) return; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } LPWSTR start = pstr->data; @@ -937,7 +933,7 @@ void STRAPI StrgTrimLeft(HSTRINGW hstr, const wchar_t wch) if (!pstr) return; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } LPWSTR start = pstr->data; @@ -1026,7 +1022,7 @@ HSTRINGW STRAPI StrgMid(HSTRINGW hstr, const size_t start, size_t count) if (!pstr) return NULL; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } if (start + count > pstr->data_length) @@ -1056,7 +1052,7 @@ HSTRINGW STRAPI StrgLeft(HSTRINGW hstr, const size_t count) if (!pstr) return NULL; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } HSTRINGW hCopy = StrgCreate(NULL); @@ -1078,7 +1074,7 @@ HSTRINGW STRAPI StrgRight(HSTRINGW hstr, const size_t count) if (!pstr) return NULL; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } HSTRINGW hCopy = StrgCreate(NULL); @@ -1115,7 +1111,7 @@ LPWSTR STRAPI StrgWriteAccessBuf(HSTRINGW hstr, size_t min_len) return NULL; if (pstr->alloc_length <= min_len) { - ReAllocW(pstr, min_len, true); + ReAllocW(pstr, min_len); } return pstr->data; } @@ -1127,15 +1123,13 @@ void STRAPI StrgSanitize(HSTRINGW hstr) if (!pstr) return; if (!pstr->data) { - ReAllocW(pstr, 0, true); + ReAllocW(pstr, 0); } // ensure buffer limits - pstr->alloc_length = LengthOfBuffer(pstr->data); - ptrdiff_t const end = (ptrdiff_t)pstr->alloc_length - 1; - if (end >= 0) { - if (pstr->data) - pstr->data[end] = WCHR_NULL; // terminating zero - } + size_t const buflen = LengthOfBuffer(pstr->data); + if (pstr->data && (buflen > 0)) + pstr->data[buflen - 1] = WCHR_NULL; + pstr->alloc_length = buflen; pstr->data_length = StrlenW(pstr->data); } // -------------------------------------------------------------------------- diff --git a/src/Edit.c b/src/Edit.c index b9bd2a1b7..a68876bd1 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -161,7 +161,7 @@ static int msgcmp(void* mqc1, void* mqc2) return 1; } -static int64_t sortcmp(void *mqc1, void *mqc2) { +static LONG64 sortcmp(void *mqc1, void *mqc2) { const CmdMessageQueue_t *const pMQC1 = (CmdMessageQueue_t *)mqc1; const CmdMessageQueue_t *const pMQC2 = (CmdMessageQueue_t *)mqc2; return (pMQC1->delay - pMQC2->delay); @@ -9682,9 +9682,9 @@ void EditToggleFolds(FOLD_ACTION action, bool bForceAll) void EditFoldClick(DocLn ln, int mode) { static struct { - DocLn ln; - int mode; - int64_t iTickCount; + DocLn ln; + int mode; + LONG64 iTickCount; } prev = { 0, 0, 0 }; bool fGotoFoldPoint = mode & FOLD_SIBLINGS; diff --git a/src/Helpers.h b/src/Helpers.h index 99971899b..30f52dcf3 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -869,14 +869,14 @@ static inline int PointSizeToFontHeight(const float fPtHeight, const HDC hdc) { // ---------------------------------------------------------------------------- -static inline int64_t GetTicks_ms() { +static inline LONG64 GetTicks_ms() { LARGE_INTEGER freq; if (!QueryPerformanceFrequency(&freq)) { - return (int64_t)GetTickCount64(); + return (LONG64)GetTickCount64(); } LARGE_INTEGER ticks; if (!QueryPerformanceCounter(&ticks)) { - return (int64_t)GetTickCount64(); + return (LONG64)GetTickCount64(); } return (ticks.QuadPart * 1000LL) / freq.QuadPart; } diff --git a/src/Notepad3.c b/src/Notepad3.c index 22e9b52bc..2ff500533 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -155,7 +155,7 @@ static int s_iAlignMode = 0; static bool s_bIsAppThemed = true; static UINT s_msgTaskbarCreated = 0; static WCHAR s_wchTitleExcerpt[MIDSZ_BUFFER] = { L'\0' }; -static int64_t s_iLastCopyTime = 0; +static LONG64 s_iLastCopyTime = 0; static bool s_bLastCopyFromMe = false; static bool s_bInMultiEditMode = false; static bool s_bCallTipEscDisabled = false; @@ -445,8 +445,8 @@ static inline void _SplitUndoTransaction() // ---------------------------------------------------------------------------- -static void _DelayClearCallTip(const int64_t delay); -static void _DelaySplitUndoTransaction(const int64_t delay); +static void _DelayClearCallTip(const LONG64 delay); +static void _DelaySplitUndoTransaction(const LONG64 delay); static void _RestoreActionSelection(const LONG token, DoAction doAct); // ---------------------------------------------------------------------------- @@ -527,7 +527,7 @@ static int msgcmp(void* mqc1, void* mqc2) #define _MQ_ms2cycl(T) (((T) + USER_TIMER_MINIMUM) / _MQ_TIMER_CYCLE) -static void _MQ_AppendCmd(CmdMessageQueue_t* const pMsgQCmd, int64_t cycles) +static void _MQ_AppendCmd(CmdMessageQueue_t* const pMsgQCmd, LONG64 cycles) { if (!pMsgQCmd) { return; } @@ -804,7 +804,6 @@ static void _InitGlobals() FocusedView.CodeFoldingAvailable = false; FocusedView.ShowCodeFolding = true; - FileWatching.flagChangeNotify = FWM_DONT_CARE; FileWatching.FileWatchingMode = FWM_DONT_CARE; FileWatching.MonitoringLog = false; @@ -1836,9 +1835,6 @@ HWND InitInstance(const HINSTANCE hInstance, int nCmdShow) Encoding_Forced(s_flagSetEncoding); switch (s_flagChangeNotify) { - case FWM_NO_INIT: - FileWatching.FileWatchingMode = Settings.FileWatchingMode; - break; case FWM_DONT_CARE: case FWM_INDICATORSILENT: case FWM_MSGBOX: @@ -1846,8 +1842,9 @@ HWND InitInstance(const HINSTANCE hInstance, int nCmdShow) case FWM_EXCLUSIVELOCK: FileWatching.FileWatchingMode = s_flagChangeNotify; break; + case FWM_NO_INIT: default: - FileWatching.FileWatchingMode = FWM_MSGBOX; + FileWatching.FileWatchingMode = Settings.FileWatchingMode; break; } @@ -3707,15 +3704,20 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam) } if (bOpened) { if (params->flagChangeNotify == FWM_MSGBOX) { - FileWatching.FileWatchingMode = FWM_DONT_CARE; + FileWatching.FileWatchingMode = FWM_MSGBOX; InstallFileWatching(true); - } else if (params->flagChangeNotify == FWM_AUTORELOAD) { - if (!FileWatching.MonitoringLog) { + } + else if (params->flagChangeNotify == FWM_AUTORELOAD) { + if (FileWatching.MonitoringLog) { PostWMCommand(Globals.hwndMain, IDM_VIEW_CHASING_DOCTAIL); - } else { - FileWatching.FileWatchingMode = FWM_AUTORELOAD; - InstallFileWatching(true); } + else { + FileWatching.FileWatchingMode = FWM_AUTORELOAD; + } + InstallFileWatching(true); + } + else if (params->flagChangeNotify == FWM_INDICATORSILENT) { + InstallFileWatching(true); } if (params->flagSetEncoding != CPI_NONE) { @@ -6210,7 +6212,6 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) _saveChgNotify = FileWatching.FileWatchingMode; } FileWatching.MonitoringLog = !FileWatching.MonitoringLog; // toggle - FileWatching.flagChangeNotify = s_flagChangeNotify; SciCall_SetReadOnly(FileWatching.MonitoringLog); if (FileWatching.MonitoringLog) { @@ -6222,7 +6223,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) SciCall_SetEndAtLastLine(false); } else { FileWatching.FileWatchingMode = _saveChgNotify; - FileWatching.FileCheckInterval = clampll(Settings2.FileCheckInterval, MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL); + FileWatching.FileCheckInterval = Settings2.FileCheckInterval; SciCall_SetEndAtLastLine(!Settings.ScrollPastEOF); } Sci_ScrollSelectionToView(); @@ -8563,7 +8564,7 @@ inline static LRESULT _MsgNotifyLean(const SCNotification *const scn, bool* bMod } } if (*bModified) { - int64_t const timeout = Settings2.UndoTransactionTimeout; + LONG64 const timeout = Settings2.UndoTransactionTimeout; if (timeout != 0LL) { if (!bInUndoRedoStep) { _DelaySplitUndoTransaction(max_ll(_MQ_IMMEDIATE, timeout)); @@ -9671,7 +9672,7 @@ static void _DelayUpdateStatusbar(const int delay, const bool bForceRedraw) // // _DelayUpdateToolbar() // -static void _DelayUpdateToolbar(const int64_t delay) +static void _DelayUpdateToolbar(const LONG64 delay) { CmdMessageQueue_t mqc = MQ_WM_CMD_INIT(Globals.hwndMain, IDT_TIMER_UPDATE_TOOLBAR, 0LL); _MQ_AppendCmd(&mqc, _MQ_ms2cycl(delay)); @@ -9682,7 +9683,7 @@ static void _DelayUpdateToolbar(const int64_t delay) // // _DelayUpdateTitlebar() // -static void _DelayUpdateTitlebar(const int64_t delay, const HWND hwnd) +static void _DelayUpdateTitlebar(const LONG64 delay, const HWND hwnd) { CmdMessageQueue_t mqc = MQ_WM_CMD_INIT(Globals.hwndMain, IDT_TIMER_UPDATE_TITLEBAR, (LPARAM)hwnd); _MQ_AppendCmd(&mqc, _MQ_ms2cycl(delay)); @@ -9693,7 +9694,7 @@ static void _DelayUpdateTitlebar(const int64_t delay, const HWND hwnd) // // _DelayClearCallTip() // -static void _DelayClearCallTip(const int64_t delay) +static void _DelayClearCallTip(const LONG64 delay) { CmdMessageQueue_t mqc = MQ_WM_CMD_INIT(Globals.hwndMain, IDT_TIMER_CLEAR_CALLTIP, 0LL); _MQ_AppendCmd(&mqc, _MQ_ms2cycl(delay)); @@ -9704,7 +9705,7 @@ static void _DelayClearCallTip(const int64_t delay) // // _DelaySplitUndoTransaction() // -static void _DelaySplitUndoTransaction(const int64_t delay) +static void _DelaySplitUndoTransaction(const LONG64 delay) { CmdMessageQueue_t mqc = MQ_WM_CMD_INIT(Globals.hwndMain, IDT_TIMER_UNDO_TRANSACTION, 0); _MQ_AppendCmd(&mqc, _MQ_ms2cycl(delay)); @@ -9715,10 +9716,10 @@ static void _DelaySplitUndoTransaction(const int64_t delay) // // MarkAllOccurrences() // -void MarkAllOccurrences(const int64_t delay, const bool bForceClear) +void MarkAllOccurrences(const LONG64 delay, const bool bForceClear) { CmdMessageQueue_t mqc = MQ_WM_CMD_INIT(Globals.hwndMain, IDT_TIMER_CALLBACK_MRKALL, bForceClear); - int64_t const timer = (delay < 0) ? Settings2.UpdateDelayMarkAllOccurrences : delay; + LONG64 const timer = (delay < 0) ? Settings2.UpdateDelayMarkAllOccurrences : delay; _MQ_AppendCmd(&mqc, _MQ_ms2cycl(timer)); } @@ -11199,10 +11200,11 @@ bool ConsistentIndentationCheck(EditFileIOStatus* status) // static inline void _ResetFileWatchingMode() { + FileWatching.FileWatchingMode = (s_flagChangeNotify != FWM_NO_INIT) ? s_flagChangeNotify : Settings.FileWatchingMode; if (FileWatching.MonitoringLog) { + FileWatching.FileWatchingMode = FWM_AUTORELOAD; PostWMCommand(Globals.hwndMain, IDM_VIEW_CHASING_DOCTAIL); } - FileWatching.FileWatchingMode = Settings.FileWatchingMode; ResetFileObservationData(true); } @@ -11252,18 +11254,20 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags) SetSaveDone(); - // Terminate file watching + // Restart file watching AutoSaveStop(); - InstallFileWatching(false); // terminate + InstallFileWatching(false); // terminate old if (Settings.ResetFileWatching) { _ResetFileWatchingMode(); } + InstallFileWatching(true); + Flags.bSettingsFileSoftLocked = false; UpdateSaveSettingsCmds(); if (SciCall_GetZoom() != 100) { ShowZoomCallTip(); } - + UndoRedoReset(); UpdateToolbar(); @@ -11420,19 +11424,14 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags) // Install watching of the current file AutoSaveStop(); - if (!bReloadFile) { - InstallFileWatching(false); // terminate previous - if (Settings.ResetFileWatching) { - _ResetFileWatchingMode(); - } + InstallFileWatching(false); // terminate previous + if (!bReloadFile && Settings.ResetFileWatching) { + _ResetFileWatchingMode(); } // consistent settings file handling (if loaded in editor) Flags.bSettingsFileSoftLocked = (Path_StrgComparePathNormalized(Paths.CurrentFile, Paths.IniFile) == 0); - ResetFileObservationData(true); - InstallFileWatching(true); - // the .LOG feature ... if (SciCall_GetTextLength() >= 4) { char tchLog[5] = { '\0', '\0', '\0', '\0', '\0' }; @@ -11513,6 +11512,10 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags) UpdateStatusbar(true); Path_Release(hopen_file); + + ResetFileObservationData(true); + InstallFileWatching(fSuccess); + return fSuccess; } @@ -12612,12 +12615,11 @@ LRESULT MsgFileChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) static inline void NotifyIfFileHasChanged() { - if (IsFileChangedFlagSet() || IsFileDeletedFlagSet() || RaiseFlagIfCurrentFileChanged()) { PostMessage(Globals.hwndMain, WM_FILECHANGEDNOTIFY, 0, 0); } // reset Timeout interval - s_FileChgObsvrData.iFileChangeNotifyTime = GetTicks_ms(); + InterlockedExchange64(&(s_FileChgObsvrData.iFileChangeNotifyTime), GetTicks_ms()); } // ---------------------------------------------------------------------------- @@ -12630,7 +12632,7 @@ static void CALLBACK WatchTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWOR UNREFERENCED_PARAMETER(uMsg); UNREFERENCED_PARAMETER(hwnd); - int64_t const diff = (GetTicks_ms() - s_FileChgObsvrData.iFileChangeNotifyTime); + LONG64 const diff = (GetTicks_ms() - InterlockedOr64(&(s_FileChgObsvrData.iFileChangeNotifyTime), 0LL)); // Directory-Observer is not notified for continuously updated (log-)files if (diff > FileWatching.FileCheckInterval) { NotifyIfFileHasChanged(); @@ -12744,7 +12746,7 @@ void InstallFileWatching(const bool bInstall) { BackgroundWorker_Start(&(s_FileChgObsvrData.worker), FileChangeObserver, &s_FileChgObsvrData); } - s_FileChgObsvrData.iFileChangeNotifyTime = GetTicks_ms(); + InterlockedExchange64(&(s_FileChgObsvrData.iFileChangeNotifyTime), GetTicks_ms()); if (Settings2.FileCheckInterval > 0) { SetTimer(Globals.hwndMain, ID_WATCHTIMER, (UINT)FileWatching.FileCheckInterval, WatchTimerProc); diff --git a/src/Notepad3.h b/src/Notepad3.h index 373f5316f..63082cade 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -126,7 +126,7 @@ void CheckAutoLoadMostRecent(); void ShowZoomCallTip(); void ShowWrapAroundCallTip(bool forwardSearch); -void MarkAllOccurrences(const int64_t delay, const bool bForceClear); +void MarkAllOccurrences(const LONG64 delay, const bool bForceClear); void UpdateToolbar(); void UpdateStatusbar(const bool bForceRedraw); diff --git a/src/Notepad3.vcxproj b/src/Notepad3.vcxproj index 5a8c96629..f2d1e436c 100644 --- a/src/Notepad3.vcxproj +++ b/src/Notepad3.vcxproj @@ -40,9 +40,9 @@ v142 v143 true - true + false false - true + false Unicode @@ -72,9 +72,9 @@ v142 v143 true - true + false false - true + false Unicode diff --git a/src/TypeDefs.h b/src/TypeDefs.h index d87e5ee86..1fa49221d 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -330,7 +330,7 @@ typedef struct CmdMessageQueue_t { UINT cmd; WPARAM wparam; LPARAM lparam; - int64_t delay; + LONG64 delay; struct CmdMessageQueue_t* next; struct CmdMessageQueue_t* prev; @@ -735,8 +735,8 @@ typedef struct SETTINGS2_T { int FileLoadWarningMB; int OpacityLevel; int FindReplaceOpacityLevel; - int64_t FileCheckInterval; - int64_t UndoTransactionTimeout; + LONG64 FileCheckInterval; + LONG64 UndoTransactionTimeout; int IMEInteraction; int SciFontQuality; int LaunchInstanceWndPosOffset; @@ -845,7 +845,7 @@ typedef struct BackgroundWorker { typedef struct FCOBSRVDATA_T { - int64_t iFileChangeNotifyTime; + volatile LONG64 iFileChangeNotifyTime; // multi-threaded WIN32_FIND_DATA fdCurFile; HANDLE hEventFileChanged; @@ -865,9 +865,8 @@ typedef struct FCOBSRVDATA_T { typedef struct FILEWATCHING_T { - FILE_WATCHING_MODE flagChangeNotify; // <-> s_flagChangeNotify; FILE_WATCHING_MODE FileWatchingMode; // <-> Settings.FileWatchingMode; - int64_t FileCheckInterval; // <-> clampll(Settings2.FileCheckInterval, MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL); + LONG64 FileCheckInterval; // <-> clampll(Settings2.FileCheckInterval, MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL); bool MonitoringLog; } FILEWATCHING_T, *PFILEWATCHING_T;