Cleanups
This commit is contained in:
@@ -30,36 +30,31 @@ static void CALLBACK current_directory_monitor_callback (DWORD error, DWORD nByt
|
||||
}
|
||||
|
||||
bool notify = false;
|
||||
// Analysis of the modifications
|
||||
// Analysis of the modifications. Let only parsed file extensions emit a notify, not PP3 changes
|
||||
do {
|
||||
Glib::ustring fname = "";
|
||||
int strLen = 0;
|
||||
|
||||
// Get a pointer to the first change record...
|
||||
pInfo = (FILE_NOTIFY_INFORMATION*) &monData->file_notify_buffer[dwOffset];
|
||||
|
||||
char fnameC[(MAX_PATH+1)*2] = {0};
|
||||
strLen = WideCharToMultiByte(CP_UTF8,0,pInfo->FileName,pInfo->FileNameLength/sizeof(WCHAR),fnameC,sizeof(fnameC),0,0);
|
||||
int strLen = WideCharToMultiByte(CP_UTF8,0,pInfo->FileName,pInfo->FileNameLength/sizeof(WCHAR),fnameC,sizeof(fnameC),0,0);
|
||||
fnameC[strLen] = 0;
|
||||
fname = fnameC;
|
||||
Glib::ustring fname = fnameC;
|
||||
|
||||
// See http://msdn.microsoft.com/en-us/library/aa364391(v=vs.85).aspx for available event type if necessary
|
||||
if (options.has_retained_extention(fname))
|
||||
notify = true;
|
||||
|
||||
// More than one change may happen at the same time. Load the next change and continue...
|
||||
// More than one change may happen at the same time. Load the next change and continue...
|
||||
dwOffset += pInfo->NextEntryOffset;
|
||||
}
|
||||
while (pInfo->NextEntryOffset != 0);
|
||||
} while (!notify && pInfo->NextEntryOffset != 0);
|
||||
|
||||
// ReadDirectoryChangesW sometimes emits multiple events per change (one for each change type)
|
||||
// To make sure it's not flooding update, this gets filtered.
|
||||
time_t curTime= ::time(NULL);
|
||||
if (notify && monData->listener && ::difftime(curTime, monData->lastTimeUpdateDir)>1.0) {
|
||||
DWORD curTick = GetTickCount();
|
||||
if (notify && monData->listener && (curTick-monData->lastTimeUpdateTick)>500) {
|
||||
monData->lastTimeUpdateTick = curTick;
|
||||
monData->listener->winDirChanged ();
|
||||
monData->lastTimeUpdateDir = curTime;
|
||||
}
|
||||
|
||||
|
||||
ReadDirectoryChangesW (monData->hDirectory,
|
||||
monData->file_notify_buffer,
|
||||
monData->buffer_allocated_bytes,
|
||||
@@ -72,7 +67,7 @@ static void CALLBACK current_directory_monitor_callback (DWORD error, DWORD nByt
|
||||
current_directory_monitor_callback);
|
||||
}
|
||||
|
||||
WinDirMonitor::WinDirMonitor (Glib::ustring dirName, WinDirChangeListener* listener) : monData(NULL) {
|
||||
WinDirMonitor::WinDirMonitor (Glib::ustring dirName, WinDirChangeListener* listener) : monData(NULL) {
|
||||
wchar_t* wdirname = (wchar_t*)g_utf8_to_utf16 (dirName.c_str(), -1, NULL, NULL, NULL);
|
||||
HANDLE hDirectory = CreateFileW (wdirname, FILE_LIST_DIRECTORY,FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL);
|
||||
g_free (wdirname);
|
||||
@@ -84,9 +79,8 @@ WinDirMonitor::WinDirMonitor (Glib::ustring dirName, WinDirChangeListener* liste
|
||||
monData->buffer_allocated_bytes = 32768;
|
||||
monData->file_notify_buffer = new char [monData->buffer_allocated_bytes];
|
||||
monData->hDirectory = hDirectory;
|
||||
monData->lastTimeUpdateDir = ::time(NULL);
|
||||
monData->lastTimeUpdateTick = GetTickCount();
|
||||
|
||||
// printf ("mondata=%d\n", monData);
|
||||
ReadDirectoryChangesW (monData->hDirectory,
|
||||
monData->file_notify_buffer,
|
||||
monData->buffer_allocated_bytes,
|
||||
|
Reference in New Issue
Block a user