void FilesystemChangesRunnable::processChanges() { DWORD dwWaitStatus = WaitForSingleObject( m_dwChangeHandle, 1000 ); switch ( dwWaitStatus ) { case WAIT_OBJECT_0: { m_section->enter(); m_changeFound |= true; m_section->leave(); if ( FindNextChangeNotification( m_dwChangeHandle ) == FALSE ) { LOG( "FilesystemChangesTracker: Error (%d): FindNextChangeNotification function failed.", GetLastError() ); } break; } case WAIT_TIMEOUT: { // restart the listener if ( FindNextChangeNotification( m_dwChangeHandle ) == FALSE ) { LOG( "FilesystemChangesTracker: Error (%d): FindNextChangeNotification function failed.", GetLastError() ); } break; } } }
void __stdcall DirectoryWinAPI::onEventTriggered(void* args, BOOLEAN /*timeout*/) { HANDLE handle = (HANDLE)args; static_cast<DirectoryWinAPI*>(Directory::get())->callbacks[handle].cb->run(); FindNextChangeNotification(handle); FindNextChangeNotification(handle); //twice }
void wait() { DWORD result; while(!canceled) { Py_BEGIN_ALLOW_THREADS result = WaitForSingleObject( handle, 100 ); Py_END_ALLOW_THREADS if(result!=WAIT_TIMEOUT) { break; } } if(canceled) return; if(result==WAIT_OBJECT_0) { FindNextChangeNotification(handle); } else if(result==WAIT_ABANDONED) { canceled = true; } }
virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_TIMER: if (WaitForSingleObject(m_hFileNotify, 0) == WAIT_OBJECT_0) { m_profileList.DeleteAllItems(); ProfileEnumData ped(m_profileList, m_pd->ptszProfile); findProfiles(m_pd->ptszProfileDir, EnumProfilesForList, (LPARAM)&ped); FindNextChangeNotification(m_hFileNotify); } break; case WM_FOCUSTEXTBOX: SetFocus(m_profileList.GetHwnd()); if (m_pd->ptszProfile[0] == 0 || m_profileList.GetSelectedCount() == 0) m_profileList.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); break; case WM_SHOWWINDOW: if (wParam) CheckRun(); break; case WM_CONTEXTMENU: ExecuteMenu(lParam); break; } return CDlgBase::DlgProc(msg, wParam, lParam); }
//----------------------------------------------------------------------------- // Purpose: Update our status //----------------------------------------------------------------------------- void UpdateConfigsStatus( void ) { // Wait for notification. DWORD dwWaitStatus = WaitForSingleObject( g_dwChangeHandle, 0 ); if ( dwWaitStatus == WAIT_OBJECT_0 ) { // Something in the watched folder changed! if ( g_pMainFrame != NULL ) { // Reload the configs g_ConfigManager.LoadConfigs(); // Reparse the configurations ReloadConfigs(); } // Start the next update if ( FindNextChangeNotification( g_dwChangeHandle ) == FALSE ) { // This means that something unknown happened to our search handle! Assert( 0 ); return; } } }
void winhostext_Query() { for (int i = 0; i<_SIZE; i++) { struct DirInfo * dirInfo = notifyHandles[i]; if (dirInfo == NULL) break; if (dirInfo->notifyHandle == INVALID_HANDLE_VALUE) continue; DWORD singleWaitStatus = WaitForSingleObject(dirInfo->notifyHandle,0); if (singleWaitStatus == WAIT_OBJECT_0) { if (FindNextChangeNotification(dirInfo->notifyHandle)) { safeGuard = !safeGuard; if (safeGuard) { listProjectDirectory(); } } } else if (singleWaitStatus == WAIT_TIMEOUT) { } else { printf("\n ERROR: Unhandled dwWaitStatus.\n"); } } }
DWORD WINAPI monitor_thread(VOID *p) { char watchme[PATH_MAX]; HANDLE harr[2], fff; if(lock_engine()) { logg("^monitor_thread: failed to lock engine\n"); return 0; } snprintf(watchme, sizeof(watchme), "%s\\forcerld", dbdir); watchme[sizeof(watchme)-1] = '\0'; harr[0] = monitor_event; harr[1] = FindFirstChangeNotification(dbdir, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_FILE_NAME); unlock_engine(); if(harr[1] == INVALID_HANDLE_VALUE) { logg("^monitor_thread: failed to monitor directory changes on %s\n", dbdir); return 0; } logg("monitor_thread: watching directory changes on %s\n", dbdir); while(1) { WIN32_FIND_DATA wfd; SYSTEMTIME st; switch(WaitForMultipleObjects(2, harr, FALSE, INFINITE)) { case WAIT_OBJECT_0: logg("*monitor_thread: terminating upon request\n"); FindCloseChangeNotification(harr[1]); return 0; case WAIT_OBJECT_0 + 1: break; default: logg("*monitor_thread: unexpected wait failure - %u\n", GetLastError()); Sleep(1000); continue; } FindNextChangeNotification(harr[1]); if((fff = FindFirstFile(watchme, &wfd)) == INVALID_HANDLE_VALUE) continue; FindClose(fff); GetSystemTime(&st); SystemTimeToFileTime(&st, &wfd.ftCreationTime); if(CompareFileTime(&wfd.ftLastWriteTime, &wfd.ftCreationTime) > 0) wfd.ftLastWriteTime = wfd.ftCreationTime; if(CompareFileTime(&wfd.ftLastWriteTime, &last_chk_time) <= 0) continue; logg("monitor_thread: reload requested!\n"); Scan_ReloadDatabase(minimal_definitions); GetSystemTime(&st); SystemTimeToFileTime(&st, &last_chk_time); /* FIXME: small race here */ } }
DWORD WINAPI FileChangeNotificationThread(LPVOID lpParam) { NotificationThreadData * data = (NotificationThreadData *) lpParam; while (WaitForSingleObject(data->notificationHandle, INFINITE) == WAIT_OBJECT_0) { // reset if (FindNextChangeNotification(data->notificationHandle) == FALSE) { return 0; } // keep eating notifications until a short timeout times out for (DWORD ret = WAIT_OBJECT_0; ret == WAIT_OBJECT_0 || ret == WAIT_TIMEOUT; ret = WaitForSingleObject(data->notificationHandle, 500)) { if (ret == WAIT_TIMEOUT) { break; } if (FindNextChangeNotification(data->notificationHandle) == FALSE) { return 0; } } PostMessage(data->hwnd, WM_USER_RELOAD, 0, 0); } return 0; }
void MON_LABELS::notify_user_labels() { if (hNewUserLabels == INVALID_HANDLE_VALUE) return; // load labels at first check if (!hNewUserLabels) { start_watching_labels(); import_file(); return; } if (WaitForSingleObject(hNewUserLabels, 0) != WAIT_OBJECT_0) return; import_file(); FindNextChangeNotification(hNewUserLabels); }
static INT_PTR ServiceFileChanged(WPARAM wParam, LPARAM) { EnterCriticalSection(&csDialogCache); for (int i = 0; i < dialogCacheCount; i++) dialogCache[i].timeLastUsed = 0; LeaveCriticalSection(&csDialogCache); if ((HANDLE)wParam != NULL) FindNextChangeNotification((HANDLE)wParam); return 0; }
virtual DWORD Run() { SetThreadPriority(myHandle, THREAD_PRIORITY_IDLE); TCHAR aLocaleDir[1000]; myMan->GetLocalizationBasePath(aLocaleDir, 1000); myMonitorHandle = FindFirstChangeNotification( aLocaleDir, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE); if ( myMonitorHandle == INVALID_HANDLE_VALUE) return 1; HANDLE aObjs[2] = { myMonitorHandle, myTerminateEvent }; while (true) { DWORD aRes = WaitForMultipleObjects(2, aObjs, FALSE, INFINITE); if ( aRes == WAIT_FAILED) break; else if (aRes == WAIT_OBJECT_0 + 0) //directory change { //HACK HWND aWnd = RootWindow::FindSingleInstance(); if (aWnd == 0) break; //end HACK PostMessage(aWnd, RootWindow::WM_USER_LOADLOCALE, 0, 0); BOOL aRet = FindNextChangeNotification(myMonitorHandle); if (aRet == 0) { ATLTRACE("LocalizationDirectoryMonitorThread -- failed on FindNextChangeNotification, returning.\n"); break; } } else if (aRes == WAIT_OBJECT_0 + 1) //the terminate event occurred break; } FindCloseChangeNotification(myMonitorHandle); return 0; }
DWORD __stdcall ChangeNotifyThread(LPVOID param) { CoInitialize(NULL); CComQIPtr<IWebSite> site = (IWebSite*)param; CWebSite* pSite = ((CWebSite*)site.p); BSTR rootPath; site->get_rootPath(&rootPath); HANDLE m_hChangeHandle; m_hChangeHandle = FindFirstChangeNotification(_bstr_t(rootPath), TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE ); SysFreeString(rootPath); while (1) { DWORD nObject = MsgWaitForMultipleObjectsEx( 1, // number of handles in handle array &m_hChangeHandle, // pointer to an object-handle array INFINITE, // time-out interval in milliseconds QS_ALLEVENTS, // type of input events to wait for 0 // wait flags ); if (nObject == WAIT_OBJECT_0) { pSite->m_pRootDir->ScanFiles(TRUE, TRUE); pSite->Fire_FileTreeChanged(); } else { break; } FindNextChangeNotification(m_hChangeHandle); } FindCloseChangeNotification(m_hChangeHandle); CoUninitialize(); return 0; }
unsigned int __stdcall CMainWindow::WatcherThread( LPVOID lpvParam ) { CMainWindow * pThis = (CMainWindow*)lpvParam; DWORD dwWaitStatus; HANDLE dwChangeHandle; std::wstring monitorPath; while (pThis->threadRunning) { monitorPath = pThis->wpPath; // Watch the directory for file creation and deletion. std::wstring dirPath = monitorPath.substr(0, monitorPath.find_last_of('\\')); dwChangeHandle = FindFirstChangeNotification( dirPath.c_str(), FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE); if (dwChangeHandle != INVALID_HANDLE_VALUE) { // Change notification is set. while ((pThis->threadRunning)&&(monitorPath.compare(pThis->wpPath) == 0)) { // Wait for notification. dwWaitStatus = WaitForSingleObject(dwChangeHandle, 1000); switch (dwWaitStatus) { case WAIT_OBJECT_0: SendMessage(*pThis, WM_SETTINGCHANGE, 0, 0); break; case WAIT_TIMEOUT: // A timeout occurred if (monitorPath.compare(pThis->wpPath) != 0) { SendMessage(*pThis, WM_SETTINGCHANGE, 0, 0); } break; } FindNextChangeNotification(dwChangeHandle); } FindCloseChangeNotification(dwChangeHandle); monitorPath.clear(); } Sleep(10); } return 0; }
void Scene::Draw(float fDeltaTime) { if (GetAsyncKeyState('R') < 0 && GetForegroundWindow() == hWnd) { Reset(); } device->SetRenderTarget(0, rtMain); device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( rand(), rand(), rand() ), 1.0f, 0 ); device->BeginScene(); IDirect3DTexture9 * src = NULL; IDirect3DSurface9 * dest = NULL; IDirect3DTexture9 * res = NULL; if (parity == 0) { src = state0; dest = rtState1; res = state1; parity = 1; } else { src = state1; dest = rtState0; res = state0; parity = 0; } //step DrawFullScreenQuad(dest, stepVS, stepPS, src); //show to screen DrawFullScreenQuad(rtMain, copyVS, copyPS, res); device->EndScene(); device->Present( NULL, NULL, NULL, NULL ); //Simplest file watcher DWORD waitStatus = WaitForSingleObject(shaderDirWatcherHandle, 0); if (waitStatus == WAIT_OBJECT_0) { LoadShaders(); FindNextChangeNotification(shaderDirWatcherHandle); } }
void do_listen(fsmonitor_t *monitor) { HANDLE hChange = FindFirstChangeNotification(U2W(monitor->path), TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES); assert(hChange != INVALID_HANDLE_VALUE); printf("Listening to changes in %s\n", monitor->path); while (TRUE) { DWORD status = WaitForMultipleObjects(1, &hChange, FALSE, INFINITE); if (status == WAIT_OBJECT_0) { printf("Detected change in %s\n", monitor->path); invoke_on_main_thread((INVOKE_LATER_FUNC) fsmonitor_did_detect_change, monitor); DWORD result = FindNextChangeNotification(hChange); assert(result); } else { assert(!"WaitForMultipleObjects returned error"); } } }
bool WatcherData::updated(const Path& path) { //printf("updated %s\n", path.constData()); std::lock_guard<std::mutex> locker(updateMutex); const auto h = pathToHandle.find(path); if (h == pathToHandle.end()) { //printf("handle not found in pathToHandle\n"); return false; } FindNextChangeNotification(h->second); // notify the main thread changedPaths.insert(path); SetEvent(wakeupHandle); return true; }
JNIEXPORT jboolean JNICALL Java_net_rubygrapefruit_platform_internal_jni_FileEventFunctions_waitForNextEvent(JNIEnv *env, jclass target, jobject handle, jobject result) { watch_details_t* details = (watch_details_t*)env->GetDirectBufferAddress(handle); if (WaitForSingleObject(details->watch_handle, INFINITE) == WAIT_FAILED) { mark_failed_with_errno(env, "could not wait for change notification", result); return JNI_FALSE; } if (!FindNextChangeNotification(details->watch_handle)) { if (GetLastError() == ERROR_INVALID_HANDLE) { // Assumed closed return JNI_FALSE; } mark_failed_with_errno(env, "could not schedule next change notification", result); return JNI_FALSE; } return JNI_TRUE; }
DWORD WINAPI FileChangeWatcher::ThreadProc(LPVOID param) { FileChangeWatcher* self = static_cast<FileChangeWatcher*>(param); while (1) { HANDLE handle[2]; handle[0] = self->m_handle; handle[1] = self->m_threadEndEvent; DWORD result = WaitForMultipleObjects(2, handle, FALSE, INFINITE); if (result == WAIT_OBJECT_0) { if (self->UpdateFileAttributes()) { // Dispatch the message to event handler. if (self->m_eventHandler != NULL) { FileEvent event(self->m_fileName); self->m_eventHandler->AddPendingEvent(event); } } FindNextChangeNotification(self->m_handle); } else { break; } } return 0; }
void WatchDirModifacationProcess::VThreadProc(void) { HANDLE handles[2]; handles[0] = m_fileHandle; handles[1] = m_closeHandle; while(IsAlive()) { DWORD event = WaitForMultipleObjects(2, handles, false, INFINITE); if(event == WAIT_FAILED) { Fail(); return; } if(IsAlive() && (event == WAIT_OBJECT_0 || (event == (WAIT_OBJECT_0 + 1)))) { VOnDirModification(); FindNextChangeNotification(m_fileHandle); } } }
unsigned int WINAPI DirChangeNotifier::task() { m_hChangeDir = FindFirstChangeNotification( m_path, // directory to watch FALSE, // do not watch subtree FILE_NOTIFY_CHANGE_FILE_NAME); // watch for file names if (m_hChangeDir == INVALID_HANDLE_VALUE) { OutputDebugStringW(L"ERROR: FindFirstChangeNotification"); _endthreadex(0); return 0; } while (TRUE) { DWORD dwWaitStatus = WaitForSingleObject(m_hChangeDir, INFINITE); if (dwWaitStatus == WAIT_OBJECT_0) { if (m_fTerminate) { break; } // A file was created, renamed, or deleted in the directory. // Refresh this directory and restart the notification. if (isChecked()) { ::Info.AdvControl(&MainGuid, ACTL_SYNCHRO, 0, (void*)m_hPanel); } if (!FindNextChangeNotification(m_hChangeDir)) { OutputDebugStringW(L"ERROR: FindNextChangeNotification"); break; } } else { OutputDebugStringW(L"WaitForSingleObject"); break; } } if (!m_fTerminate) FindCloseChangeNotification(m_hChangeDir); m_hChangeDir = INVALID_HANDLE_VALUE; _endthreadex(0); return 0; }
DWORD WINAPI WatchThreadProc(LPVOID param) { pWatchInfo pInf = (pWatchInfo)param; BOOL notified = FALSE; while (TRUE) { // Don't send notifications to the application until possible bursts has calmed down if (WaitForSingleObject(pInf->hChange, 1000) == WAIT_OBJECT_0) { notified = TRUE; // Wait for next FindNextChangeNotification(pInf->hChange); } else if (notified) { // Timer event, now report the pending change PostMessage(pInf->hWnd, pInf->messageID, NULL, NULL); notified = FALSE; } } return 0; }
void AnimaApplication::NextFrame() { if( mFrameCounter==INPUT_DELAY ) mInput->Unblock(); mDeltaTime.Update(); ProcessInput(); mInput->Update( mDeltaTime.Elapsed() ); mFramerateCounter->FrameStart(); mCamera->update( mDeltaTime.Elapsed() ); mModel->Update( mDeltaTime.Elapsed() ); mRenderContext->SetViewMatrix( mCamera->ViewMatrix() ); if( WaitForSingleObject(mShadersWatcher, 0) == WAIT_OBJECT_0 ) { mRenderContext->SetShadersChanged(); FindNextChangeNotification(mShadersWatcher); } mRenderContext->RenderFrame( mModel ); mFramerateCounter->FrameEnd(); if( mRotateModel ) { mModelRotationAngle += 0.00025f; aiQuaternion rotateUpright( 0, 0, Math::Pi / 2.f ); aiQuaternion rotateY( 0, mModelRotationAngle, 0 ); mModelRotation = rotateUpright*rotateY; mModel->SetRoot( aiVector3D(0.f, 0.f, 0.f ), mModelRotation ); } ++mFrameCounter; }
bool CFileSystemMonitor::AnyChanges() { if (_scraper_directory_on_a_network_drive) { // Network mapped drives are unsupported write_log(Preferences()->debug_filesystem_monitor(), "[CFileSystemMonitor] Unsupported network mapped drive\n"); write_log(Preferences()->debug_filesystem_monitor(), "[CFileSystemMonitor] Treating as \"no changes\"\n"); return false; } // http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx dwWaitStatus = WaitForMultipleObjects( 1, // number of handles &dwChangeHandle, // handle FALSE, // bWaitAll - does not make a difference here 0); // time to wait if (dwWaitStatus == WAIT_OBJECT_0) { write_log(Preferences()->debug_filesystem_monitor(), "[CFileSystemMonitor] Scraper directoy changed.\n"); // Resetting change handle for next query // http://msdn.microsoft.com/en-us/library/windows/desktop/aa365261%28v=vs.85%29.aspx FindNextChangeNotification(dwChangeHandle); return true; } write_log(Preferences()->debug_filesystem_monitor(), "[CFileSystemMonitor] No changes in scraper directoy.\n"); return false; }
void RegesterFolderAndFileDetect() { HANDLE notify = FindFirstChangeNotification( L"D:\\test", TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_SIZE); if (notify == INVALID_HANDLE_VALUE) { assert(notify); return; } while(1) { WaitForSingleObject(notify, INFINITE); OutputDebugString(L"目录有改变\n"); FindNextChangeNotification(notify); } FindCloseChangeNotification(notify); }
DWORD WINAPI ChangeNotifyThread(NOTIFY_DATA *pnd) { HANDLE hChange; DWORD dwResult; TCHAR szDirectory[MAX_PATH]; lstrcpy(szDirectory, pnd->szFile); // get the directory name from filename if(GetFileAttributes(szDirectory) != FILE_ATTRIBUTE_DIRECTORY) { TCHAR *slash = _tcsrchr(szDirectory, _T('\\')); if(slash) *slash = '\0'; } // watch the specified directory for changes hChange = FindFirstChangeNotification(szDirectory, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE); do { HANDLE hEventList[2] = { hChange, pnd->hQuitEvent }; if((dwResult = WaitForMultipleObjects(1, hEventList, FALSE, INFINITE)) == WAIT_OBJECT_0) { PostMessage(pnd->hwndNotify, pnd->uMsg, 0, (LPARAM)pnd); } FindNextChangeNotification(hChange); } while(dwResult == WAIT_OBJECT_0); // cleanup FindCloseChangeNotification(hChange); free(pnd); return 0; }
static void watch_directory(folder_watcher* pfw) { DWORD dwWaitStatus; HANDLE dwChangeHandles[2]; TCHAR lpDrive[4]; TCHAR lpFile[_MAX_FNAME]; TCHAR lpExt[_MAX_EXT]; _tsplitpath_s(LPTSTR(pfw->get_directory().data()), lpDrive, 4, NULL, 0, lpFile, _MAX_FNAME, lpExt, _MAX_EXT); lpDrive[2] = (TCHAR)'\\'; lpDrive[3] = (TCHAR)'\0'; // Watch the directory for file creation and deletion. dwChangeHandles[0] = FindFirstChangeNotification( LPTSTR(pfw->get_directory().data()), // directory to watch TRUE, // do not watch subtree pfw->get_filter()); // watch file name changes if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) { printf("\n ERROR: FindFirstChangeNotification function failed.\n"); ExitProcess(GetLastError()); } // Watch the subtree for directory creation and deletion. dwChangeHandles[1] = FindFirstChangeNotification( lpDrive, // directory to watch TRUE, // watch the subtree FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir name changes if (dwChangeHandles[1] == INVALID_HANDLE_VALUE) { printf("\n ERROR: FindFirstChangeNotification function failed.\n"); ExitProcess(GetLastError()); } // Make a final validation check on our handles. if ((dwChangeHandles[0] == NULL) || (dwChangeHandles[1] == NULL)) { printf("\n ERROR: Unexpected NULL from FindFirstChangeNotification.\n"); ExitProcess(GetLastError()); } // Change notification is set. Now wait on both notification // handles and refresh accordingly. while (true) { // Wait for notification. //printf("\nWaiting for notification...\n"); dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, FALSE, WAIT_TIME); if (!pfw->is_running()) { break; } switch (dwWaitStatus) { case WAIT_OBJECT_0: // A file was created, renamed, or deleted in the directory. // Refresh this directory and restart the notification. //printf("fileupdate\n"); pfw->call_callback(); if (FindNextChangeNotification(dwChangeHandles[0]) == FALSE) { printf("\n ERROR: FindNextChangeNotification function failed.\n"); ExitProcess(GetLastError()); } break; case WAIT_OBJECT_0 + 1: // A directory was created, renamed, or deleted. // Refresh the tree and restart the notification. //printf("folderupdate\n"); pfw->call_callback(); if (FindNextChangeNotification(dwChangeHandles[1]) == FALSE) { printf("\n ERROR: FindNextChangeNotification function failed.\n"); ExitProcess(GetLastError()); } break; case WAIT_TIMEOUT: // A timeout occurred, this would happen if some value other // than INFINITE is used in the Wait call and no changes occur. // In a single-threaded environment you might not want an // INFINITE wait. //printf("\nNo changes in the timeout period.\n"); break; default: printf("\n ERROR: Unhandled dwWaitStatus.\n"); ExitProcess(GetLastError()); break; } } }
int CALLBACK IniRepositoryWatcherThread(int) { int result; // eax@8 HANDLE v2; // eax@24 DWORD v3; // eax@31 DWORD v4; // eax@51 char v5; // al@94 char v6; // al@99 char v7; // [sp+0h] [bp-2A0h]@7 DWORD v8; // [sp+6Ch] [bp-234h]@69 signed int v9; // [sp+70h] [bp-230h]@68 unsigned int v10; // [sp+74h] [bp-22Ch]@15 char Dst[268]; // [sp+78h] [bp-228h]@15 HANDLE hChangeHandle; // [sp+184h] [bp-11Ch]@10 HANDLE hHandle; // [sp+188h] [bp-118h]@9 char v14[4]; // [sp+18Ch] [bp-114h]@33 const CHAR Src; // [sp+190h] [bp-110h]@5 unsigned int v16; // [sp+298h] [bp-8h]@1 DWORD v17; // [sp+29Ch] [bp-4h]@33 int v18; // [sp+2A0h] [bp+0h]@1 if ( WndGetDevicesFolder((LPSTR)&Src, 0x104u, 0, 0) ) { hHandle = g_pMain->hStopMainProcessThreadEvent; while(TRUE) { hChangeHandle = FindFirstChangeNotificationA(&Src, 1, 1u); if ( hChangeHandle == INVALID_HANDLE_VALUE ) { strcpy_s(Dst, MAX_PATH, &Src); BYTE *pEnd = &Dst[strlen(Dst)]; do { while(*pEnd != '\\' && pEnd >= Dst) { --pEnd; } if(*pEnd != '\\') { return 0; } *pEnd = NULL; hChangeHandle = FindFirstChangeNotificationA(Dst, 0, 2u); } while(hChangeHandle == INVALID_HANDLE_VALUE); if(hChangeHandle == INVALID_HANDLE_VALUE) { return 0; } v17 = WaitForMultipleObjects(2u, &hChangeHandle, 0, 0xFFFFFFFFu); FindCloseChangeNotification(hChangeHandle); if ( !v17 ) { continue; } if ( v17 != 1 ) { continue; } result = 0; } else { if(hChangeHandle == INVALID_HANDLE_VALUE) { result = 0; } else { while ( 1 ) { v17 = WaitForMultipleObjects(2u, &hChangeHandle, 0, 0xFFFFFFFFu); if ( v17 ) break; if ( !WaitForSingleObject(hHandle, 0x3E8u) ) { break; } v9 = 1; if(g_pMain->dwOndemandReloadStartTime) { OnDemandReloadElapsedTime = GetTickCount() - g_pMain->dwOndemandReloadStartTime; if(OnDemandReloadElapsedTime < 5000) { v9 = 0; } } if(v9) { MainAPIBroadcastControl(5, 0, 0, 0, 1); if(IniLoadFilesFromPath((int *)&g_pMain->ModelTable, &g_pMain->ulModelCount, (void **)&g_pMain->field_1D1C, (int)&g_pMain->field_1D18, &Src, g_pGbl->dwFlags, 0)) { if(!WaitForSingleObject(hHandle, 1000) ) break; } MainAPIBroadcastControl(6, 0, 0, 0, 1); } if(!FindNextChangeNotification(hChangeHandle)) { break; } } FindCloseChangeNotification(hChangeHandle); result = 0; } } break; } } else { result = 0; } return result; }
void run() { ItemInfoMap entries; scan(entries); DWORD filter = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME; if (owner().eventMask() & DirectoryWatcher::DW_ITEM_MODIFIED) filter |= FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE; std::string path(owner().directory().path()); #if defined(POCO_WIN32_UTF8) std::wstring upath; Poco::UnicodeConverter::toUTF16(path.c_str(), upath); HANDLE hChange = FindFirstChangeNotificationW(upath.c_str(), FALSE, filter); #else HANDLE hChange = FindFirstChangeNotificationA(path.c_str(), FALSE, filter); #endif if (hChange == INVALID_HANDLE_VALUE) { try { FileImpl::handleLastErrorImpl(path); } catch (Poco::Exception& exc) { owner().scanError(&owner(), exc); } return; } bool stopped = false; while (!stopped) { try { HANDLE h[2]; h[0] = _hStopped; h[1] = hChange; switch (WaitForMultipleObjects(2, h, FALSE, INFINITE)) { case WAIT_OBJECT_0: stopped = true; break; case WAIT_OBJECT_0 + 1: { ItemInfoMap newEntries; scan(newEntries); compare(entries, newEntries); std::swap(entries, newEntries); if (FindNextChangeNotification(hChange) == FALSE) { FileImpl::handleLastErrorImpl(path); } } break; default: throw SystemException("failed to wait for directory changes"); } } catch (Poco::Exception& exc) { owner().scanError(&owner(), exc); } } FindCloseChangeNotification(hChange); }
DWORD WINAPI FileWatchWorker(LPVOID param){ DWORD dwWaitStatus; HANDLE dwChangeHandle; FileWatchController* controller = (FileWatchController *)param; LPCWSTR lpDir = controller->directory; // Watch the directory for file creation and deletion. dwChangeHandle = FindFirstChangeNotification(lpDir, FALSE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE ); wchar_t watchedDir[MAX_PATH]; memset(watchedDir, 0, MAX_PATH); wcscpy_s(watchedDir, MAX_PATH, controller->directory); // Make a final validation check on our handles. if ((dwChangeHandle == NULL)) { PostMessage(attachmentsHwnd, WM_FILE_WATCH_FAILED, 0, 0); } // Change notification is set. Now wait on both notification // handles and refresh accordingly. while (!controller->exit) { // Wait for notification. dwWaitStatus = WaitForSingleObject(dwChangeHandle, 100); switch (dwWaitStatus) { case WAIT_OBJECT_0: // A file was created, renamed, or deleted in the directory. // Refresh this directory and restart the notification. if ( controller->pause == FALSE ){ ProcessChanges(watchedDir); } if ( FindNextChangeNotification(dwChangeHandle) == FALSE ) { } break; case WAIT_TIMEOUT: /* See if the controller wants me to switch to watching a different directory * This corresponds to the user accessing a different document */ if ( wcscmp(controller->directory, watchedDir) != 0 ){ memset(watchedDir, 0, MAX_PATH); wcscpy_s(watchedDir, MAX_PATH, controller->directory); dwChangeHandle = FindFirstChangeNotification(watchedDir, FALSE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE ); } break; default: break; } } return 0; }
static INT_PTR CheckIniImportNow(WPARAM, LPARAM) { DoAutoExec(); FindNextChangeNotification(hIniChangeNotification); return 0; }