+fix: Integration and Notification of DirectoryObserver and FileChanged-Polling

This commit is contained in:
rkotten 2023-03-28 13:44:55 +02:00
parent 59490de5b5
commit dd2fd09c20
5 changed files with 112 additions and 115 deletions

View File

@ -1261,8 +1261,7 @@ void LoadSettings()
}
int const deprecatedFCI = max_i(autoReload, dfci);
Settings2.FileCheckInterval = static_cast<int64_t>(clampll(IniSectionGetLongLong(IniSecSettings2, correctKeyFCI, deprecatedFCI),
MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL));
Settings2.FileCheckInterval = IniSectionGetLongLong(IniSecSettings2, correctKeyFCI, deprecatedFCI);
if (Settings2.FileCheckInterval == defaultFCI) {
if (deprecatedFCI != defaultFCI) {
@ -1274,7 +1273,7 @@ void LoadSettings()
IniSectionSetLongLong(IniSecSettings2, correctKeyFCI, Settings2.FileCheckInterval);
bDirtyFlag = true;
}
FileWatching.FileCheckInterval = Settings2.FileCheckInterval;
FileWatching.FileCheckInterval = clampll(Settings2.FileCheckInterval, MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL);
IniSectionGetString(IniSecSettings2, L"FileChangedIndicator", L"[@]", Settings2.FileChangedIndicator, COUNTOF(Settings2.FileChangedIndicator));

View File

@ -5242,7 +5242,7 @@ void EditSortLines(HWND hwnd, int iSortFlags)
qsort(pLines, iLineCount, sizeof(SORTLINE), CmpStdRev);
}
} else { /*if (iSortFlags & SORT_SHUFFLE)*/
srand((UINT)GetTicks());
srand((UINT)GetTicks_ms());
for (DocLn i = (iLineCount - 1); i > 0; --i) {
int j = rand() % i;
SORTLINE sLine = { NULL, NULL };
@ -9691,8 +9691,8 @@ void EditFoldClick(DocLn ln, int mode)
if (!(SciCall_GetFoldLevel(ln) & SC_FOLDLEVELHEADERFLAG)) {
// Not a fold point: need to look for a double-click
if (prev.ln == ln && prev.mode == mode &&
GetTicks() - prev.iTickCount <= GetDoubleClickTime()) {
if ((prev.ln == ln) && (prev.mode == mode) &&
((GetTicks_ms() - prev.iTickCount) <= GetDoubleClickTime())) {
prev.ln = NOT_FOUND_LN; // Prevent re-triggering on a triple-click
ln = SciCall_GetFoldParent(ln);
@ -9706,7 +9706,7 @@ void EditFoldClick(DocLn ln, int mode)
// Save the info needed to match this click with the next click
prev.ln = ln;
prev.mode = mode;
prev.iTickCount = GetTicks();
prev.iTickCount = GetTicks_ms();
return;
}
}

View File

@ -63,12 +63,12 @@
#define DEFAULT_ALLOC_FLAGS (HEAP_CREATE_HARDENED)
#endif
inline LPVOID AllocMem(size_t numBytes, DWORD dwFlags)
static inline LPVOID AllocMem(size_t numBytes, DWORD dwFlags)
{
return HeapAlloc(Globals.hndlProcessHeap, (dwFlags | DEFAULT_ALLOC_FLAGS), numBytes);
}
inline LPVOID ReAllocMem(LPVOID lpMem, size_t numBytes, DWORD dwFlags)
static inline LPVOID ReAllocMem(LPVOID lpMem, size_t numBytes, DWORD dwFlags)
{
if (lpMem) {
return HeapReAlloc(Globals.hndlProcessHeap, (dwFlags | DEFAULT_ALLOC_FLAGS), lpMem, numBytes);
@ -76,7 +76,7 @@ inline LPVOID ReAllocMem(LPVOID lpMem, size_t numBytes, DWORD dwFlags)
return HeapAlloc(Globals.hndlProcessHeap, (dwFlags | DEFAULT_ALLOC_FLAGS), numBytes);
}
inline LPVOID ReAllocGrowMem(LPVOID lpMem, size_t numBytes, DWORD dwFlags)
static inline LPVOID ReAllocGrowMem(LPVOID lpMem, size_t numBytes, DWORD dwFlags)
{
if (lpMem) {
size_t const memSize = HeapSize(Globals.hndlProcessHeap, 0, lpMem);
@ -91,12 +91,12 @@ inline LPVOID ReAllocGrowMem(LPVOID lpMem, size_t numBytes, DWORD dwFlags)
return HeapAlloc(Globals.hndlProcessHeap, (dwFlags | DEFAULT_ALLOC_FLAGS), numBytes);
}
inline bool FreeMem(LPVOID lpMem)
static inline bool FreeMem(LPVOID lpMem)
{
return (lpMem ? HeapFree(Globals.hndlProcessHeap, 0, lpMem) : true);
}
inline size_t SizeOfMem(LPCVOID lpMem)
static inline size_t SizeOfMem(LPCVOID lpMem)
{
return (lpMem ? HeapSize(Globals.hndlProcessHeap, 0, lpMem) : 0);
}
@ -207,7 +207,7 @@ __forceinline bool IsAsyncKeyDown(int key) {
// ----------------------------------------------------------------------------
inline DWORD GetNumberOfProcessors()
static inline DWORD GetNumberOfProcessors()
{
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
@ -216,13 +216,14 @@ inline DWORD GetNumberOfProcessors()
// ----------------------------------------------------------------------------
inline bool Str2Int(LPCWSTR str, int *value) {
__forceinline bool Str2Int(LPCWSTR str, int* value)
{
LPWSTR end;
*value = (int)wcstol(str, &end, 10);
return (str != end);
}
inline bool Str2Float(LPCWSTR str, float* value)
__forceinline bool Str2Float(LPCWSTR str, float* value)
{
LPWSTR end;
*value = (float)wcstod(str, &end);
@ -298,7 +299,7 @@ __forceinline bool StrIsEmptyW(LPCWSTR s) {
//inline COLORREF GetBackgroundColor(HWND hwnd) { return GetBkColor(GetDC(hwnd)); }
inline int SetModeBkColor(const HDC hdc, const bool bDarkMode)
static inline int SetModeBkColor(const HDC hdc, const bool bDarkMode)
{
#ifdef D_NP3_WIN10_DARK_MODE
return SetBkColor(hdc, bDarkMode ? Settings2.DarkModeBkgColor : GetSysColor(COLOR_WINDOW));
@ -308,7 +309,7 @@ inline int SetModeBkColor(const HDC hdc, const bool bDarkMode)
#endif
}
inline int SetModeBtnFaceColor(const HDC hdc, const bool bDarkMode)
static inline int SetModeBtnFaceColor(const HDC hdc, const bool bDarkMode)
{
#ifdef D_NP3_WIN10_DARK_MODE
return SetBkColor(hdc, bDarkMode ? Settings2.DarkModeBtnFaceColor : GetSysColor(COLOR_BTNFACE));
@ -318,7 +319,7 @@ inline int SetModeBtnFaceColor(const HDC hdc, const bool bDarkMode)
#endif
}
inline COLORREF GetModeBkColor(const bool bDarkMode)
static inline COLORREF GetModeBkColor(const bool bDarkMode)
{
#ifdef D_NP3_WIN10_DARK_MODE
return bDarkMode ? Settings2.DarkModeBkgColor : (COLORREF)GetSysColor(COLOR_WINDOW);
@ -328,7 +329,7 @@ inline COLORREF GetModeBkColor(const bool bDarkMode)
#endif
}
inline COLORREF GetModeBtnfaceColor(const bool bDarkMode)
static inline COLORREF GetModeBtnfaceColor(const bool bDarkMode)
{
#ifdef D_NP3_WIN10_DARK_MODE
return bDarkMode ? Settings2.DarkModeBtnFaceColor : (COLORREF)GetSysColor(COLOR_BTNFACE);
@ -339,7 +340,7 @@ inline COLORREF GetModeBtnfaceColor(const bool bDarkMode)
}
inline int SetModeTextColor(const HDC hdc, const bool bDarkMode)
static inline int SetModeTextColor(const HDC hdc, const bool bDarkMode)
{
#ifdef D_NP3_WIN10_DARK_MODE
//return SetTextColor(hdc, bDarkMode ? Settings2.DarkModeTxtColor : GetSysColor(COLOR_WINDOWTEXT));
@ -350,7 +351,7 @@ inline int SetModeTextColor(const HDC hdc, const bool bDarkMode)
#endif
}
inline COLORREF GetModeTextColor(const bool bDarkMode)
static inline COLORREF GetModeTextColor(const bool bDarkMode)
{
#ifdef D_NP3_WIN10_DARK_MODE
//return bDarkMode ? Settings2.DarkModeTxtColor : (COLORREF)GetSysColor(COLOR_WINDOWTEXT);
@ -364,7 +365,7 @@ inline COLORREF GetModeTextColor(const bool bDarkMode)
#ifdef D_NP3_WIN10_DARK_MODE
inline INT_PTR SetDarkModeCtlColors(const HDC hdc, const bool bDarkMode)
static inline INT_PTR SetDarkModeCtlColors(const HDC hdc, const bool bDarkMode)
{
if (bDarkMode) {
SetBkColor(hdc, Settings2.DarkModeBkgColor);
@ -390,7 +391,7 @@ bool SetClipboardText(HWND hwnd, LPCWSTR pszTextW, size_t cchTextW);
// ----------------------------------------------------------------------------
inline void GetCurrentMonitorResolution(HWND hwnd, int* pCXScreen, int* pCYScreen)
static inline void GetCurrentMonitorResolution(HWND hwnd, int* pCXScreen, int* pCYScreen)
{
HMONITOR const hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi = { sizeof(MONITORINFO) };
@ -400,7 +401,7 @@ inline void GetCurrentMonitorResolution(HWND hwnd, int* pCXScreen, int* pCYScree
}
// FullHD? => 0:'==', -1:'<', +1:'>'
inline int IsFullHD(HWND hwnd, int resX, int resY)
static inline int IsFullHD(HWND hwnd, int resX, int resY)
{
int cxScreen, cyScreen;
GetCurrentMonitorResolution(hwnd, &cxScreen, &cyScreen);
@ -427,10 +428,10 @@ void BackgroundWorker_Start(BackgroundWorker* worker, _beginthreadex_proc
void BackgroundWorker_Cancel(BackgroundWorker* worker);
void BackgroundWorker_Destroy(BackgroundWorker* worker);
inline bool BackgroundWorker_Continue(BackgroundWorker* worker) {
static inline bool BackgroundWorker_Continue(BackgroundWorker* worker) {
return (worker) ? (WaitForSingleObject(worker->eventCancel, 0) != WAIT_OBJECT_0) : false;
}
inline void BackgroundWorker_End(BackgroundWorker* worker, unsigned int retcode) { if (worker) { _endthreadex(retcode); }}
static inline void BackgroundWorker_End(BackgroundWorker* worker, unsigned int retcode) { if (worker) { _endthreadex(retcode); }}
bool BitmapMergeAlpha(HBITMAP hbmp,COLORREF crDest);
@ -445,15 +446,15 @@ bool IsCmdEnabled(HWND hwnd, UINT uId);
#define SetBtn(b) ((b) ? BST_CHECKED : BST_UNCHECKED)
inline bool IsButtonChecked(HWND hwnd, int iButtonID)
__forceinline bool IsButtonChecked(HWND hwnd, int iButtonID)
{
return (IsDlgButtonChecked(hwnd, iButtonID) == BST_CHECKED);
}
inline bool IsButtonIntermediate(HWND hwnd, int iButtonID)
__forceinline bool IsButtonIntermediate(HWND hwnd, int iButtonID)
{
return (IsDlgButtonChecked(hwnd, iButtonID) == BST_INDETERMINATE);
}
inline bool IsButtonUnchecked(HWND hwnd, int iButtonID)
__forceinline bool IsButtonUnchecked(HWND hwnd, int iButtonID)
{
return (IsDlgButtonChecked(hwnd, iButtonID) == BST_UNCHECKED);
}
@ -478,7 +479,7 @@ bool SplitFilePathLineNum(LPWSTR lpszPath, int *lineNum);
bool StrLTrimI(LPWSTR pszSource,LPCWSTR pszTrimChars);
bool StrRTrimI(LPWSTR pszSource,LPCWSTR pszTrimChars);
inline bool TrimSpcA(LPSTR lpString)
static inline bool TrimSpcA(LPSTR lpString)
{
if (!lpString || !*lpString) {
return false;
@ -486,7 +487,7 @@ inline bool TrimSpcA(LPSTR lpString)
return (bool)StrTrimA(lpString, " \t\v");
};
inline bool TrimSpcW(LPWSTR lpString)
static inline bool TrimSpcW(LPWSTR lpString)
{
if (!lpString || !*lpString) {
return false;
@ -577,29 +578,29 @@ __forceinline ptrdiff_t MultiByteToWideCharEx(
// ============================================================================
inline int wcscmp_s(const wchar_t* s1, const wchar_t* s2)
__forceinline int wcscmp_s(const wchar_t* s1, const wchar_t* s2)
{
return (s1 && s2) ? wcscmp(s1, s2) : ((s1 ? 1 : (s2 ? -1 : 0)));
}
inline int wcscoll_s(const wchar_t* s1, const wchar_t* s2)
__forceinline int wcscoll_s(const wchar_t* s1, const wchar_t* s2)
{
return (s1 && s2) ? wcscoll(s1, s2) : ((s1 ? 1 : (s2 ? -1 : 0)));
}
inline int wcsicmp_s(const wchar_t* s1, const wchar_t* s2)
__forceinline int wcsicmp_s(const wchar_t* s1, const wchar_t* s2)
{
return (s1 && s2) ? _wcsicmp(s1, s2) : ((s1 ? 1 : (s2 ? -1 : 0)));
}
inline int wcsicoll_s(const wchar_t* s1, const wchar_t* s2)
__forceinline int wcsicoll_s(const wchar_t* s1, const wchar_t* s2)
{
return (s1 && s2) ? _wcsicoll(s1, s2) : ((s1 ? 1 : (s2 ? -1 : 0)));
}
// ============================================================================
inline void SwabEx(char* src, char* dest, size_t n)
static inline void SwabEx(char* src, char* dest, size_t n)
{
static int const max = (INT_MAX - (INT_MAX % 2));
@ -658,7 +659,7 @@ bool StrDelChrA(LPSTR pszSource, LPCSTR pCharsToRemove);
// inline size_t StringCchLenW(LPCWSTR s, size_t n) {
// n = (n ? n : STRSAFE_MAX_CCH); size_t len; return (size_t)(!s ? 0 : (SUCCEEDED(StringCchLengthW(s, n, &len)) ? len : n));
// }
inline size_t StringCchLenW(LPCWSTR s, size_t n)
static inline size_t StringCchLenW(LPCWSTR s, size_t n)
{
n = (n ? n : STRSAFE_MAX_CCH);
return (s ? wcsnlen_s(s, n) : 0LL);
@ -666,7 +667,7 @@ inline size_t StringCchLenW(LPCWSTR s, size_t n)
// inline size_t StringCchLenA(LPCSTR s, size_t n) {
// n = (n ? n : STRSAFE_MAX_CCH); size_t len; return (size_t)(!s ? 0 : (SUCCEEDED(StringCchLengthA(s, n, &len)) ? len : n));
// }
inline size_t StringCchLenA(LPCSTR s, size_t n)
static inline size_t StringCchLenA(LPCSTR s, size_t n)
{
n = (n ? n : STRSAFE_MAX_CCH);
return (s ? strnlen_s(s, n) : 0LL);
@ -679,12 +680,12 @@ inline size_t StringCchLenA(LPCSTR s, size_t n)
// ----------------------------------------------------------------------------
inline WCHAR* StrEndW(const WCHAR* pStart, size_t siz)
static inline WCHAR* StrEndW(const WCHAR* pStart, size_t siz)
{
// cppcheck-suppress cert-EXP05-C // Attempt to cast away const - Intended(!)
return (WCHAR*)(pStart + StringCchLenW(pStart, siz));
}
inline char* StrEndA(const char* pStart, size_t siz)
static inline char* StrEndA(const char* pStart, size_t siz)
{
// cppcheck-suppress cert-EXP05-C // Attempt to cast away const - Intended(!)
return (char*)(pStart + StringCchLenA(pStart, siz));
@ -697,7 +698,7 @@ inline char* StrEndA(const char* pStart, size_t siz)
// ----------------------------------------------------------------------------
inline void StrReplChrW(WCHAR* pStrg, const WCHAR chSearch, const WCHAR chReplace)
static inline void StrReplChrW(WCHAR* pStrg, const WCHAR chSearch, const WCHAR chReplace)
{
while (pStrg && *pStrg) {
if (*pStrg == chSearch) {
@ -706,7 +707,7 @@ inline void StrReplChrW(WCHAR* pStrg, const WCHAR chSearch, const WCHAR chReplac
++pStrg;
}
}
inline void StrReplChrA(CHAR* pStrg, const CHAR chSearch, const CHAR chReplace)
static inline void StrReplChrA(CHAR* pStrg, const CHAR chSearch, const CHAR chReplace)
{
while (pStrg && *pStrg) {
if (*pStrg == chSearch) {
@ -781,29 +782,35 @@ inline void StrReplChrA(CHAR* pStrg, const CHAR chSearch, const CHAR chReplace)
#define IsOctalDigitW(wch) (((wch) >= L'0') && ((wch) <= L'7'))
// Is the character an octal digit?
inline bool IsDigitA(const char ch) {
__forceinline bool IsDigitA(const char ch)
{
return ((ch >= '0') && (ch <= '9'));
}
inline bool IsDigitW(const WCHAR wch) {
__forceinline bool IsDigitW(const WCHAR wch)
{
return ((wch >= L'0') && (wch <= L'9'));
}
// Is the character a white space char?
inline bool IsBlankCharA(const char ch) {
__forceinline bool IsBlankCharA(const char ch)
{
return ((ch == ' ') || (ch == '\t'));
}
inline bool IsBlankCharW(const WCHAR wch) {
__forceinline bool IsBlankCharW(const WCHAR wch)
{
return ((wch == L' ') || (wch == L'\t'));
}
// no encoding for safe chars
inline bool IsAlphaNumericA(const char ch) {
__forceinline bool IsAlphaNumericA(const char ch)
{
return ((ch >= '0') && (ch <= '9')) ||
((ch >= 'a') && (ch <= 'z')) ||
((ch >= 'A') && (ch <= 'Z'));
}
inline bool IsAlphaNumericW(const WCHAR ch) {
__forceinline bool IsAlphaNumericW(const WCHAR ch)
{
return
((ch >= L'0') && (ch <= L'9')) ||
((ch >= L'a') && (ch <= L'z')) ||
@ -811,7 +818,7 @@ inline bool IsAlphaNumericW(const WCHAR ch) {
}
// If the character is an hexadecimal digit, get its value.
inline int GetHexDigitA(const char ch)
static inline int GetHexDigitA(const char ch)
{
if (ch >= '0' && ch <= '9') {
return ch - '0';
@ -825,7 +832,7 @@ inline int GetHexDigitA(const char ch)
return -1;
}
inline int GetHexDigitW(const WCHAR ch)
static inline int GetHexDigitW(const WCHAR ch)
{
if (ch >= L'0' && ch <= L'9') {
return ch - L'0';
@ -855,24 +862,23 @@ void CloseApplication();
// ----------------------------------------------------------------------------
inline int PointSizeToFontHeight(const float fPtHeight, const HDC hdc) {
static inline int PointSizeToFontHeight(const float fPtHeight, const HDC hdc) {
return -MulDiv(f2int(fPtHeight * 100.0f), GetDeviceCaps(hdc, LOGPIXELSY), 72 * SC_FONT_SIZE_MULTIPLIER);
}
// ----------------------------------------------------------------------------
static inline int64_t GetTicks() {
LARGE_INTEGER ticks;
if (!QueryPerformanceCounter(&ticks)) {
return (int64_t)GetTickCount64();
}
static inline int64_t GetTicks_ms() {
LARGE_INTEGER freq;
if (!QueryPerformanceFrequency(&freq)) {
return (int64_t)GetTickCount64();
}
ticks.QuadPart *= 1000000;
ticks.QuadPart /= freq.QuadPart;
return ticks.QuadPart;
LARGE_INTEGER ticks;
if (!QueryPerformanceCounter(&ticks)) {
return (int64_t)GetTickCount64();
}
return (ticks.QuadPart * 1000LL) / freq.QuadPart;
}
// ----------------------------------------------------------------------------

View File

@ -622,7 +622,7 @@ static inline bool IsFileDeletedFlagSet() {
return (WaitForSingleObject(s_FileChgObsvrData.hEventFileDeleted, 0) != WAIT_TIMEOUT);
}
static inline bool HasCurrentFileChanged() {
static inline bool RaiseFlagIfCurrentFileChanged() {
if (Path_IsEmpty(Paths.CurrentFile)) {
return false;
@ -1521,7 +1521,7 @@ static BOOL CALLBACK _EnumWndProc(HWND hwnd, LPARAM lParam)
if (StringCchCompareNIW(szClassName, COUNTOF(szClassName), s_wchWndClass, COUNTOF(s_wchWndClass)) == 0) {
UINT const iReuseLock = GetDlgItemInt(hwnd, IDC_REUSELOCK, NULL, FALSE);
if ((GetTicks() - iReuseLock) >= REUSEWINDOWLOCKTIMEOUT) {
if ((GetTicks_ms() - iReuseLock) >= REUSEWINDOWLOCKTIMEOUT) {
*(HWND*)lParam = hwnd;
@ -1549,7 +1549,7 @@ static BOOL CALLBACK _EnumWndProc2(HWND hwnd, LPARAM lParam)
if (StringCchCompareNIW(szClassName, COUNTOF(szClassName), s_wchWndClass, COUNTOF(s_wchWndClass)) == 0) {
UINT const iReuseLock = GetDlgItemInt(hwnd, IDC_REUSELOCK, NULL, FALSE);
if ((GetTicks() - iReuseLock) >= REUSEWINDOWLOCKTIMEOUT) {
if ((GetTicks_ms() - iReuseLock) >= REUSEWINDOWLOCKTIMEOUT) {
if (IsWindowEnabled(hwnd)) {
bContinue = FALSE;
@ -1835,11 +1835,26 @@ HWND InitInstance(const HINSTANCE hInstance, int nCmdShow)
// Source Encoding
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:
case FWM_AUTORELOAD:
case FWM_EXCLUSIVELOCK:
FileWatching.FileWatchingMode = s_flagChangeNotify;
break;
default:
FileWatching.FileWatchingMode = FWM_MSGBOX;
break;
}
// Initial FileLoad() moved in front of ShowWindow()
bool bOpened = false;
// Pathname parameter
if (s_IsThisAnElevatedRelaunch || (Path_IsNotEmpty(s_pthArgFilePath) /*&& !g_flagNewFromClipboard*/))
{
fLoadFlags |= Settings.SkipUnicodeDetection ? FLF_SkipUnicodeDetect : 0;
@ -1890,26 +1905,6 @@ HWND InitInstance(const HINSTANCE hInstance, int nCmdShow)
Path_Empty(s_pthArgFilePath, false);
if (bOpened) {
switch (s_flagChangeNotify) {
case FWM_NO_INIT:
FileWatching.FileWatchingMode = Settings.FileWatchingMode;
break;
case FWM_DONT_CARE:
case FWM_INDICATORSILENT:
case FWM_MSGBOX:
case FWM_AUTORELOAD:
case FWM_EXCLUSIVELOCK:
FileWatching.FileWatchingMode = s_flagChangeNotify;
break;
default:
FileWatching.FileWatchingMode = FWM_MSGBOX;
break;
}
if (!s_IsThisAnElevatedRelaunch) {
InstallFileWatching(true);
}
}
} else {
cpi_enc_t const forcedEncoding = Encoding_Forced(CPI_GET);
if (Encoding_IsValid(forcedEncoding)) {
@ -2204,7 +2199,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case WM_DRAWCLIPBOARD:
if (!s_bLastCopyFromMe) {
s_iLastCopyTime = GetTicks();
s_iLastCopyTime = GetTicks_ms();
} else {
s_bLastCopyFromMe = false;
}
@ -2758,7 +2753,7 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam,LPARAM lParam)
hInstance,
NULL);
SetDlgItemInt(hwnd,IDC_REUSELOCK,(UINT)GetTicks(),false);
SetDlgItemInt(hwnd,IDC_REUSELOCK,(UINT)GetTicks_ms(),false);
// Menu
//~SetMenuDefaultItem(GetSubMenu(GetMenu(hwnd),0),0);
@ -3678,7 +3673,7 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam)
// Reset Change Notify
//bPendingChangeNotify = false;
SetDlgItemInt(hwnd, IDC_REUSELOCK, (UINT)GetTicks(), false);
SetDlgItemInt(hwnd, IDC_REUSELOCK, (UINT)GetTicks_ms(), false);
if (pcds->dwData == DATA_NOTEPAD3_PARAMS) {
LPnp3params const params = AllocMem(pcds->cbData, HEAP_ZERO_MEMORY);
@ -3931,7 +3926,7 @@ LRESULT MsgFileChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
SET_FCT_GUARD(TRUE);
InstallFileWatching(false); // terminate
ResetFileObservationData(true);
DocPos const iCurPos = SciCall_GetCurrentPos();
@ -3963,6 +3958,8 @@ LRESULT MsgFileChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
} else { // file has been deleted
InstallFileWatching(false); // terminate
if (FileWatching.FileWatchingMode == FWM_MSGBOX) {
if (IsYesOkay(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY2))) {
FileSave(FSF_SaveAlways);
@ -3976,8 +3973,6 @@ LRESULT MsgFileChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
}
InstallFileWatching(true);
RESET_FCT_GUARD();
return TRUE;
}
@ -6281,11 +6276,11 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
SendWMCommand(hwnd, IDM_FILE_REVERT);
_saveChgNotify = FileWatching.FileWatchingMode;
FileWatching.FileWatchingMode = FWM_AUTORELOAD;
FileWatching.FileCheckInterval = 250LL;
FileWatching.FileCheckInterval = MIN_FC_POLL_INTERVAL << 2;
SciCall_SetEndAtLastLine(false);
} else {
FileWatching.FileWatchingMode = _saveChgNotify;
FileWatching.FileCheckInterval = Settings2.FileCheckInterval;
FileWatching.FileCheckInterval = clampll(Settings2.FileCheckInterval, MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL);
SciCall_SetEndAtLastLine(!Settings.ScrollPastEOF);
}
Sci_ScrollSelectionToView();
@ -11298,7 +11293,7 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags)
Path_Empty(Paths.CurrentFile, false);
SetDlgItemText(Globals.hwndMain, IDC_FILENAME, Path_Get(Paths.CurrentFile));
SetDlgItemInt(Globals.hwndMain, IDC_REUSELOCK, (UINT)GetTicks(), false);
SetDlgItemInt(Globals.hwndMain, IDC_REUSELOCK, (UINT)GetTicks_ms(), false);
if (!s_flagKeepTitleExcerpt) {
StringCchCopy(s_wchTitleExcerpt, COUNTOF(s_wchTitleExcerpt), L"");
}
@ -11448,7 +11443,7 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags)
Path_Reset(Paths.CurrentFile, Path_Get(hopen_file)); // dup
SetDlgItemText(Globals.hwndMain, IDC_FILENAME, Path_Get(Paths.CurrentFile));
SetDlgItemInt(Globals.hwndMain, IDC_REUSELOCK, (UINT)GetTicks(), false);
SetDlgItemInt(Globals.hwndMain, IDC_REUSELOCK, (UINT)GetTicks_ms(), false);
if (!s_flagKeepTitleExcerpt) {
StringCchCopy(s_wchTitleExcerpt, COUNTOF(s_wchTitleExcerpt), L"");
@ -11898,7 +11893,7 @@ bool FileSave(FileSaveFlags fSaveFlags)
if (!(fSaveFlags & FSF_SaveCopy)) {
Path_Swap(Paths.CurrentFile, hfile_pth);
SetDlgItemText(Globals.hwndMain, IDC_FILENAME, Path_Get(Paths.CurrentFile));
SetDlgItemInt(Globals.hwndMain, IDC_REUSELOCK, (UINT)GetTicks(), false);
SetDlgItemInt(Globals.hwndMain, IDC_REUSELOCK, (UINT)GetTicks_ms(), false);
if (!s_flagKeepTitleExcerpt) {
StringCchCopy(s_wchTitleExcerpt, COUNTOF(s_wchTitleExcerpt), L"");
}
@ -12532,7 +12527,7 @@ void CALLBACK PasteBoardTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD
UNREFERENCED_PARAMETER(idEvent);
UNREFERENCED_PARAMETER(dwTime);
if ((s_iLastCopyTime > 0) && ((GetTicks() - s_iLastCopyTime) > 200)) {
if ((s_iLastCopyTime > 0) && ((GetTicks_ms() - s_iLastCopyTime) > 200)) {
if (SciCall_CanPaste()) {
bool bAutoIndent2 = Settings.AutoIndent;
@ -12561,13 +12556,13 @@ void CALLBACK PasteBoardTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD
//=============================================================================
static inline void NotifyIfFileHasChanged(const bool forcedNotify) {
static inline void NotifyIfFileHasChanged() {
if (forcedNotify || HasCurrentFileChanged()) {
if (IsFileChangedFlagSet() || IsFileDeletedFlagSet() || RaiseFlagIfCurrentFileChanged()) {
PostMessage(Globals.hwndMain, WM_FILECHANGEDNOTIFY, 0, 0);
}
// reset Timeout interval
s_FileChgObsvrData.iFileChangeNotifyTime = GetTicks();
s_FileChgObsvrData.iFileChangeNotifyTime = GetTicks_ms();
}
// ----------------------------------------------------------------------------
@ -12580,10 +12575,10 @@ static void CALLBACK WatchTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWOR
UNREFERENCED_PARAMETER(uMsg);
UNREFERENCED_PARAMETER(hwnd);
int64_t const diff = GetTicks() - s_FileChgObsvrData.iFileChangeNotifyTime;
int64_t const diff = (GetTicks_ms() - s_FileChgObsvrData.iFileChangeNotifyTime);
// Directory-Observer is not notified for continuously updated (log-)files
if (diff > Settings2.FileCheckInterval) {
NotifyIfFileHasChanged(/*FileWatching.MonitoringLog*/ false);
if (diff > FileWatching.FileCheckInterval) {
NotifyIfFileHasChanged();
}
}
// ----------------------------------------------------------------------------
@ -12615,11 +12610,11 @@ unsigned int WINAPI FileChangeObserver(LPVOID lpParam)
break;
case WAIT_OBJECT_0:
if (pFCOBSVData->bNotifyImmediate) {
NotifyIfFileHasChanged(/*(!)*/false); // immediate notification
} else {
s_FileChgObsvrData.iFileChangeNotifyTime = GetTicks();
WatchTimerProc(NULL, 0, 0ULL, 0); // rely on FileCheckInterval
// check if current file is trigger for directory notification
if (RaiseFlagIfCurrentFileChanged()) {
if (FileWatching.FileCheckInterval <= MIN_FC_POLL_INTERVAL) {
NotifyIfFileHasChanged(); // immediate notification
}
}
FindNextChangeNotification(pFCOBSVData->hFileChanged);
break;
@ -12661,8 +12656,6 @@ void InstallFileWatching(const bool bInstall) {
bool const bExclusiveLock = (FileWatching.FileWatchingMode == FWM_EXCLUSIVELOCK);
bool const bWatchFile = (FileWatching.FileWatchingMode != FWM_DONT_CARE) && !bExclusiveLock;
s_FileChgObsvrData.bNotifyImmediate = (FileWatching.FileCheckInterval <= MIN_FC_POLL_INTERVAL);
// always release exclusive file lock in any case
if (IS_VALID_HANDLE(_hCurrFileHandle)) {
CloseHandle(_hCurrFileHandle);
@ -12696,9 +12689,9 @@ void InstallFileWatching(const bool bInstall) {
BackgroundWorker_Start(&(s_FileChgObsvrData.worker), FileChangeObserver, &s_FileChgObsvrData);
}
s_FileChgObsvrData.iFileChangeNotifyTime = (FileWatching.FileWatchingMode == FWM_AUTORELOAD) ? GetTicks() : 0;
s_FileChgObsvrData.iFileChangeNotifyTime = GetTicks_ms();
if (FileWatching.FileCheckInterval > 0) {
if (Settings2.FileCheckInterval > 0) {
SetTimer(Globals.hwndMain, ID_WATCHTIMER, (UINT)FileWatching.FileCheckInterval, WatchTimerProc);
}
else {

View File

@ -852,15 +852,14 @@ typedef struct FCOBSRVDATA_T {
HANDLE hEventFileDeleted;
HANDLE hFileChanged; // FindFirstChangeNotification()
bool bNotifyImmediate;
BackgroundWorker worker;
} FCOBSRVDATA_T, *PFCOBSRVDATA_T;
#define INIT_FCOBSRV_T { 0UL, { 0 }, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, false, { NULL, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, NULL } }
#define INIT_FCOBSRV_T { 0LL, { 0 }, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, { NULL, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, NULL } }
#define MIN_FC_POLL_INTERVAL (500UL)
#define MAX_FC_POLL_INTERVAL ((24UL * 60 * 60 * 1000) << 1) // max: 48h
#define MIN_FC_POLL_INTERVAL (500LL)
#define MAX_FC_POLL_INTERVAL ((24LL * 60 * 60 * 1000) << 1) // max: 48h
//=============================================================================
@ -868,7 +867,7 @@ typedef struct FILEWATCHING_T {
FILE_WATCHING_MODE flagChangeNotify; // <-> s_flagChangeNotify;
FILE_WATCHING_MODE FileWatchingMode; // <-> Settings.FileWatchingMode;
int64_t FileCheckInterval; // <-> Settings2.FileCheckInterval;
int64_t FileCheckInterval; // <-> clampll(Settings2.FileCheckInterval, MIN_FC_POLL_INTERVAL, MAX_FC_POLL_INTERVAL);
bool MonitoringLog;
} FILEWATCHING_T, *PFILEWATCHING_T;