static WatchedFile* NewWatchedFile(const WCHAR* filePath, const std::function<void()>& onFileChangedCb) { bool isManualCheck = PathIsNetworkPath(filePath); AutoFreeW dirPath(path::GetDir(filePath)); WatchedDir* wd = nullptr; bool newDir = false; if (!isManualCheck) { wd = FindExistingWatchedDir(dirPath); if (!wd) { wd = NewWatchedDir(dirPath); if (!wd) return nullptr; newDir = true; } } WatchedFile* wf = AllocStruct<WatchedFile>(); wf->filePath = str::Dup(filePath); wf->onFileChangedCb = onFileChangedCb; wf->watchedDir = wd; wf->isManualCheck = isManualCheck; ListInsert(&g_watchedFiles, wf); if (wf->isManualCheck) { GetFileState(filePath, &wf->fileState); AwakeWatcherThread(); } else { if (newDir) StartMonitoringDirForChanges(wf->watchedDir); } return wf; }
static WatchedFile *NewWatchedFile(const WCHAR *filePath, FileChangeObserver *observer) { bool isManualCheck = PathIsNetworkPath(filePath); ScopedMem<WCHAR> dirPath(path::GetDir(filePath)); WatchedDir *wd = nullptr; bool newDir = false; if (!isManualCheck) { wd = FindExistingWatchedDir(dirPath); if (!wd) { wd = NewWatchedDir(dirPath); if (!wd) return nullptr; newDir = true; } } WatchedFile *wf = AllocStruct<WatchedFile>(); wf->filePath = str::Dup(filePath); wf->observer = observer; wf->watchedDir = wd; wf->isManualCheck = isManualCheck; ListInsert(&g_watchedFiles, wf); if (wf->isManualCheck) { GetFileState(filePath, &wf->fileState); AwakeWatcherThread(); } else { if (newDir) StartMonitoringDirForChanges(wf->watchedDir); } return wf; }
static WatchedDir *GetOrFindDirForFile(const WCHAR *filePath) { ScopedMem<WCHAR> dirPath(path::GetDir(filePath)); WatchedDir *wd = FindExistingWatchedDir(dirPath); if (!wd) wd = NewWatchedDir(dirPath); return wd; }
static WatchedFile *NewWatchedFile(const WCHAR *filePath, FileChangeObserver *observer) { ScopedMem<WCHAR> dirPath(path::GetDir(filePath)); WatchedDir *wd = FindExistingWatchedDir(dirPath); if (!wd) wd = NewWatchedDir(dirPath); WatchedFile *wf = AllocStruct<WatchedFile>(); wf->filePath = str::Dup(filePath); wf->watchedDir = wd; wf->observer = observer; wf->token = g_currentToken++; wf->next = g_firstFile; g_firstFile = wf; return wf; }