本文整理汇总了C++中ReadDirectoryChangesW函数的典型用法代码示例。如果您正苦于以下问题:C++ ReadDirectoryChangesW函数的具体用法?C++ ReadDirectoryChangesW怎么用?C++ ReadDirectoryChangesW使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadDirectoryChangesW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateFile
BOOL CDirWatcher::StartWatch(HWND hNotifyWnd, LPCTSTR lpszPath)
{
m_hNotifyWnd = hNotifyWnd;
m_strPath = lpszPath;
m_hFileHandle = CreateFile(m_strPath,
FILE_LIST_DIRECTORY,
FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_OVERLAPPED,
NULL);
if (m_hFileHandle == INVALID_HANDLE_VALUE)
return FALSE;
m_hCompPort = CreateIoCompletionPort(m_hFileHandle, m_hCompPort, DWORD(this), 0);
memset(&m_overlapped, 0, sizeof(OVERLAPPED));
ReadDirectoryChangesW(m_hFileHandle, m_lpBuffer, 4096,
FALSE, FILE_NOTIFY_CHANGE_FILE_NAME, &m_dwSize, &m_overlapped, NULL);
m_hThread = CreateThread(NULL, 0, _WatchProc, (void*)this, 0, &m_dwThreadID);
return TRUE;
}
示例2: register_monitoring_entry
static BOOL
register_monitoring_entry(WDM_PEntry entry)
{
BOOL success;
DWORD bytes;
bytes = 0; // Not used because the process callback gets passed the written bytes
success = ReadDirectoryChangesW(
entry->dir_handle, // handle to directory
entry->buffer, // read results buffer
WDM_BUFFER_SIZE, // length of buffer
entry->user_data->watch_childeren, // monitoring option
entry->user_data->flags, // filter conditions
&bytes, // bytes returned
&entry->event_container, // overlapped buffer
&handle_entry_change // process callback
);
if ( ! success ) {
WDM_DEBUG("ReadDirectoryChangesW failed with error (%d): %s", GetLastError(), rb_w32_strerror(GetLastError()));
return FALSE;
}
return TRUE;
}
示例3: resman_check_watch
void resman_check_watch(struct resman *rman)
{
struct watch_dir *wdir;
unsigned int idx;
unsigned int num_handles = dynarr_size(rman->watch_handles);
if(!num_handles) {
return;
}
idx = WaitForMultipleObjectsEx(num_handles, rman->watch_handles, FALSE, 0, TRUE);
if(idx == WAIT_FAILED) {
unsigned int err = GetLastError();
fprintf(stderr, "failed to check for file modification: %u\n", err);
return;
}
if(idx >= WAIT_OBJECT_0 && idx < WAIT_OBJECT_0 + num_handles) {
if(!(wdir = rb_find(rman->wdirbyev, rman->watch_handles[idx]))) {
fprintf(stderr, "got change handle, but failed to find corresponding watch_dir!\n");
return;
}
handle_event(rman, rman->watch_handles[idx], wdir);
/* restart the watch call */
ReadDirectoryChangesW(wdir->handle, wdir->buf, RES_BUF_SIZE, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE, 0, &wdir->over, 0);
}
}
示例4: SynchronousAbort
void FileWatcher::Init(const WCHAR* fileFullPath)
{
// if the thread already exists then stop it
if (IsThreadRunning())
SynchronousAbort();
str::ReplacePtr(&filePath, fileFullPath);
WCHAR *dirPath = path::GetDir(filePath);
hDir = CreateFile(
dirPath, // pointer to the directory containing the tex files
FILE_LIST_DIRECTORY, // access (read-write) mode
FILE_SHARE_READ|FILE_SHARE_DELETE|FILE_SHARE_WRITE, // share mode
NULL, // security descriptor
OPEN_EXISTING, // how to create
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED , // file attributes
NULL); // file with attributes to copy
free(dirPath);
ZeroMemory(&overl, sizeof(overl));
ZeroMemory(buffer, sizeof(buffer));
overl.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// watch the directory
ReadDirectoryChangesW(
hDir, /* handle to directory */
&buffer[curBuffer], /* read results buffer */
sizeof(buffer[curBuffer]), /* length of buffer */
FALSE, /* monitoring option */
//FILE_NOTIFY_CHANGE_CREATION|
FILE_NOTIFY_CHANGE_LAST_WRITE, /* filter conditions */
NULL, /* bytes returned */
&overl, /* overlapped buffer */
NULL); /* completion routine */
}
示例5: free
void CDirectoryMonitor::WatchDirectoryInternal(ULONG_PTR dwParam)
{
CDirInfo *pDirInfo = NULL;
pDirInfo = reinterpret_cast<CDirInfo *>(dwParam);
if(pDirInfo->m_hDirectory == INVALID_HANDLE_VALUE)
{
free(pDirInfo->m_pData);
return;
}
pDirInfo->m_FileNotifyBuffer = (FILE_NOTIFY_INFORMATION *)malloc(PRIMARY_BUFFER_SIZE);
pDirInfo->m_bDirMonitored = ReadDirectoryChangesW(pDirInfo->m_hDirectory,
pDirInfo->m_FileNotifyBuffer,PRIMARY_BUFFER_SIZE,
pDirInfo->m_bWatchSubTree,pDirInfo->m_WatchFlags,NULL,&pDirInfo->m_Async,
CompletionRoutine);
if(!pDirInfo->m_bDirMonitored)
{
free(pDirInfo->m_FileNotifyBuffer);
CancelIo(pDirInfo->m_hDirectory);
CloseHandle(pDirInfo->m_hDirectory);
}
}
示例6: memset
void gep::DirectoryWatcher::doRead()
{
memset(&m_overlapped, 0, sizeof(m_overlapped));
ReadDirectoryChangesW(m_directoryHandle, m_buffer, GEP_ARRAY_SIZE(m_buffer),
(m_watchSubdirs == WatchSubdirs::yes),
m_filter, nullptr, &m_overlapped, nullptr);
}
示例7: start_watch
//-----------------------------------------------------------------------------
static void start_watch(struct watch_entry * watch_entry_p) {
//-----------------------------------------------------------------------------
BOOL start_read_result;
memset(&watch_entry_p->overlap, 0, sizeof(watch_entry_p->overlap));
// start an overlapped 'read' to look for a filesystem change
start_read_result = ReadDirectoryChangesW(
watch_entry_p->hDirectory,
watch_entry_p->changes_buffer,
CHANGES_BUFFER_SIZE,
TRUE,
DIRECTORY_CHANGES_FILTER,
NULL,
(LPOVERLAPPED) watch_entry_p,
NULL
);
if (!start_read_result) {
DWORD err = GetLastError();
report_error(L"ReadDirectoryChangesW", err);
/* This error is reported for a handle to a file, meaning a folder has been
recreated as a file after it was selected for backup.
*/
if (err != ERROR_INVALID_PARAMETER)
ExitProcess(10);
}
} // start_watch
示例8: TRACE
void
sbWin32FileSystemWatcher::WatchNextChange()
{
TRACE("%s", __FUNCTION__);
DWORD const flags =
FILE_NOTIFY_CHANGE_FILE_NAME |
FILE_NOTIFY_CHANGE_DIR_NAME |
FILE_NOTIFY_CHANGE_LAST_WRITE |
FILE_NOTIFY_CHANGE_CREATION;
if (mRootDirHandle != INVALID_HANDLE_VALUE) {
BOOL result =
ReadDirectoryChangesW(mRootDirHandle,
mBuffer,
BUFFER_LEN,
TRUE, // watch subdirs
flags,
NULL,
&mOverlapped,
ReadDirectoryChangesWCallbackRoutine);
if (!result) {
NS_WARNING("ERROR: Could not ReadDirectoryChangesW()");
if (mRootDirHandle != INVALID_HANDLE_VALUE) {
CloseHandle(mRootDirHandle);
mRootDirHandle = INVALID_HANDLE_VALUE;
}
}
}
}
示例9: beginMonitor
static int beginMonitor(VPLFS_MonitorHandle_t* handle)
{
// VPL_REPORT_INFO("beginMonitor called");
int rv = 0;
handle->overlapped.Internal = 0;
handle->overlapped.InternalHigh = 0;
handle->overlapped.Offset = 0;
handle->overlapped.OffsetHigh = 0;
handle->overlapped.hEvent = handle; // hEvent not used by system, used as ctx ptr.
#ifdef VPL_PLAT_IS_WINRT
// TODO: using WinRT APIs to implement file monitor
rv = VPL_ERR_NOOP;
#else
if(!ReadDirectoryChangesW(handle->hDir,
handle->pBuffer, //<--FILE_NOTIFY_INFORMATION records are put into this buffer
handle->nBufferLength,
TRUE,
FILE_NOTIFY_CHANGE_FILE_NAME|
FILE_NOTIFY_CHANGE_DIR_NAME|
FILE_NOTIFY_CHANGE_SIZE|
FILE_NOTIFY_CHANGE_LAST_WRITE|
FILE_NOTIFY_CHANGE_CREATION,
NULL, // Only defined for synchronous calls.
&handle->overlapped,
&ChDirCompletionRoutine) )
{
rv = VPLError_GetLastWinError();
}
#endif
return rv;
}
示例10: tr_watchdir_win32_thread
static unsigned int __stdcall
tr_watchdir_win32_thread (void * context)
{
const tr_watchdir_t handle = context;
tr_watchdir_win32 * const backend = BACKEND_UPCAST (tr_watchdir_get_backend (handle));
DWORD bytes_transferred;
while (tr_get_overlapped_result_ex (backend->fd, &backend->overlapped, &bytes_transferred,
INFINITE, FALSE))
{
PFILE_NOTIFY_INFORMATION info = (PFILE_NOTIFY_INFORMATION) backend->buffer;
while (info->NextEntryOffset != 0)
*((BYTE **) &info) += info->NextEntryOffset;
info->NextEntryOffset = bytes_transferred - ((BYTE *) info - (BYTE *) backend->buffer);
send (backend->notify_pipe[1], (const char *) backend->buffer, bytes_transferred, 0);
if (!ReadDirectoryChangesW (backend->fd, backend->buffer, sizeof (backend->buffer), FALSE,
WIN32_WATCH_MASK, NULL, &backend->overlapped, NULL))
{
log_error ("Failed to read directory changes");
return 0;
}
}
if (GetLastError () != ERROR_OPERATION_ABORTED)
log_error ("Failed to wait for directory changes");
return 0;
}
示例11: uv_fs_event_queue_readdirchanges
static void uv_fs_event_queue_readdirchanges(uv_loop_t* loop,
uv_fs_event_t* handle) {
assert(handle->dir_handle != INVALID_HANDLE_VALUE);
assert(!handle->req_pending);
memset(&(handle->req.u.io.overlapped), 0,
sizeof(handle->req.u.io.overlapped));
if (!ReadDirectoryChangesW(handle->dir_handle,
handle->buffer,
uv_directory_watcher_buffer_size,
(handle->flags & UV_FS_EVENT_RECURSIVE) ? TRUE : FALSE,
FILE_NOTIFY_CHANGE_FILE_NAME |
FILE_NOTIFY_CHANGE_DIR_NAME |
FILE_NOTIFY_CHANGE_ATTRIBUTES |
FILE_NOTIFY_CHANGE_SIZE |
FILE_NOTIFY_CHANGE_LAST_WRITE |
FILE_NOTIFY_CHANGE_LAST_ACCESS |
FILE_NOTIFY_CHANGE_CREATION |
FILE_NOTIFY_CHANGE_SECURITY,
NULL,
&handle->req.u.io.overlapped,
NULL)) {
/* Make this req pending reporting an error. */
SET_REQ_ERROR(&handle->req, GetLastError());
uv_insert_pending_req(loop, (uv_req_t*)&handle->req);
}
handle->req_pending = 1;
}
示例12: CreateFile
int FileSystemWatcherTask::task()
{
m_handle = CreateFile(m_path,
FILE_LIST_DIRECTORY,
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
nullptr);
if (m_handle == INVALID_HANDLE_VALUE) return -1;
Lumix::setMemory(&m_overlapped, 0, sizeof(m_overlapped));
m_overlapped.hEvent = this;
m_finished = false;
while (!m_finished)
{
PROFILE_BLOCK("Change handling");
BOOL status = ReadDirectoryChangesW(m_handle,
m_info,
sizeof(m_info),
TRUE,
READ_DIR_CHANGE_FILTER,
&m_received,
&m_overlapped,
¬if);
if (status == FALSE) break;
SleepEx(INFINITE, TRUE);
}
return 0;
}
示例13: CreateFile
DWORD WINAPI FileSystemWatcher::Routine( LPVOID lParam )
{
FileSystemWatcher* pFsw = (FileSystemWatcher*)lParam;
CString tem1,tem2;
CString str = (_T("[") + pFsw->WatchedDir + "] 开始监视!");
pFsw->hDir = CreateFile(
pFsw->WatchedDir,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL
);
if( INVALID_HANDLE_VALUE == pFsw->hDir ) return false;
char buf[ 2*(sizeof(FILE_NOTIFY_INFORMATION)+MAX_PATH) ];
FILE_NOTIFY_INFORMATION* pNotify=(FILE_NOTIFY_INFORMATION *)buf;
DWORD BytesReturned;
while(true)
{
if( ReadDirectoryChangesW( pFsw->hDir,
pNotify,
sizeof(buf),
true,
FILE_NOTIFY_CHANGE_FILE_NAME|
FILE_NOTIFY_CHANGE_DIR_NAME|
FILE_NOTIFY_CHANGE_ATTRIBUTES|
FILE_NOTIFY_CHANGE_SIZE|
FILE_NOTIFY_CHANGE_LAST_WRITE|
FILE_NOTIFY_CHANGE_LAST_ACCESS|
FILE_NOTIFY_CHANGE_CREATION|
FILE_NOTIFY_CHANGE_SECURITY,
&BytesReturned,
NULL,
NULL ) )
{
char tmp[MAX_PATH], str1[MAX_PATH], str2[MAX_PATH];
memset( tmp, 0, sizeof(tmp) );
WideCharToMultiByte( CP_ACP,0,pNotify->FileName,pNotify->FileNameLength/2,tmp,99,NULL,NULL );
strcpy_s( str1,260, tmp );
if( 0 != pNotify->NextEntryOffset )
{
PFILE_NOTIFY_INFORMATION p = (PFILE_NOTIFY_INFORMATION)((char*)pNotify+pNotify->NextEntryOffset);
memset( tmp, 0, sizeof(tmp) );
WideCharToMultiByte( CP_ACP,0,p->FileName,p->FileNameLength/2,tmp,99,NULL,NULL );
strcpy_s( str2,260, tmp );
}
tem1= str1;
tem2= str2;
pFsw->DealFunc((ACTION)pNotify->Action, tem1, tem2);
} else
{
break;
}
}
return 0;
}
示例14: CheckFileChange
VOID CFileMonitorRequest::CheckFileChange()
{
DWORD dwBytes = 0;
if ( FALSE == ReadDirectoryChangesW( m_hMonitorPath , &m_vecShareMem[0] , (DWORD)m_vecShareMem.size() , m_bRecursive , m_dwFilter ,
&dwBytes , &m_overlapped , CFileMonitorRequest::OnChangeComplete ) )
{
CWUtils::ShowDebugMsg();
}
}
示例15: MultiByteToWideChar
bool FileMon::monitor(const std::string &path) {
#ifdef WIN32
#ifdef UNICODE
wchar_t path2[512];
MultiByteToWideChar(CP_ACP,0,path.c_str(),-1,path2,512);
#else
const char *path2=path.c_str();
#endif
WatchStruct* pWatch;
size_t ptrsize = sizeof(*pWatch);
pWatch = static_cast<WatchStruct*>(HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,ptrsize));
pWatch->mDirHandle = CreateFile(path2,FILE_LIST_DIRECTORY,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,NULL,
OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,NULL);
pWatch->fileMon=this;
if(pWatch->mDirHandle != INVALID_HANDLE_VALUE) {
pWatch->mOverlapped.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
pWatch->mNotifyFilter = FILE_NOTIFY_CHANGE_CREATION|FILE_NOTIFY_CHANGE_LAST_WRITE|FILE_NOTIFY_CHANGE_FILE_NAME;
if(ReadDirectoryChangesW(
pWatch->mDirHandle,pWatch->mBuffer,sizeof(pWatch->mBuffer),FALSE,
pWatch->mNotifyFilter,NULL,&pWatch->mOverlapped,WatchCallback) != 0) {
pWatch->mDirName=path;
mWatches.insert(std::make_pair(path,pWatch));
return true;
} else {
CloseHandle(pWatch->mOverlapped.hEvent);
CloseHandle(pWatch->mDirHandle);
}
}
HeapFree(GetProcessHeap(),0,pWatch);
return false;
#endif
#ifdef LINUX
int watch = inotify_add_watch(notify,path.c_str(),IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE | IN_MOVED_FROM | IN_DELETE);
if(watch < 0) {
if(errno == ENOENT) {
std::cout << "File monitor: File/dir not found error.\n";
return false;
} else {
std::cout << "File monitor: " << strerror(errno) << std::endl;;
return false;
}
} else {
watchMap[watch]=path;
}
return true;
#endif
}