]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/fswatcher.cpp
Fix typo in last commit
[wxWidgets.git] / src / msw / fswatcher.cpp
index 28c268e062b4f31285143295b006f5432c49a1ef..7f2bcd6e8901e465d1d8c81b8911c7ba6c9de0de 100644 (file)
@@ -108,9 +108,9 @@ bool wxFSWatcherImplMSW::DoAdd(wxSharedPtr<wxFSWatchEntryMSW> watch)
 }
 
 bool
 }
 
 bool
-wxFSWatcherImplMSW::DoRemove(wxSharedPtr<wxFSWatchEntryMSW> WXUNUSED(watch))
+wxFSWatcherImplMSW::DoRemove(wxSharedPtr<wxFSWatchEntryMSW> watch)
 {
 {
-    return true;
+    return m_iocp.ScheduleForRemoval(watch);
 }
 
 // TODO ensuring that we have not already set watch for this handle/dir?
 }
 
 // TODO ensuring that we have not already set watch for this handle/dir?
@@ -136,9 +136,32 @@ void wxFSWatcherImplMSW::SendEvent(wxFileSystemWatcherEvent& evt)
 
 bool wxFSWatcherImplMSW::DoSetUpWatch(wxFSWatchEntryMSW& watch)
 {
 
 bool wxFSWatcherImplMSW::DoSetUpWatch(wxFSWatchEntryMSW& watch)
 {
+    BOOL bWatchSubtree wxDUMMY_INITIALIZE(FALSE);
+
+    switch ( watch.GetType() )
+    {
+        case wxFSWPath_File:
+            wxLogError(_("Monitoring individual files for changes is not "
+                         "supported currently."));
+            return false;
+
+        case wxFSWPath_Dir:
+            bWatchSubtree = FALSE;
+            break;
+
+        case wxFSWPath_Tree:
+            bWatchSubtree = TRUE;
+            break;
+
+        case wxFSWPath_None:
+            wxFAIL_MSG( "Invalid watch type." );
+            return false;
+    }
+
     int flags = Watcher2NativeFlags(watch.GetFlags());
     int ret = ReadDirectoryChangesW(watch.GetHandle(), watch.GetBuffer(),
     int flags = Watcher2NativeFlags(watch.GetFlags());
     int ret = ReadDirectoryChangesW(watch.GetHandle(), watch.GetBuffer(),
-                                    wxFSWatchEntryMSW::BUFFER_SIZE, TRUE,
+                                    wxFSWatchEntryMSW::BUFFER_SIZE,
+                                    bWatchSubtree,
                                     flags, NULL,
                                     watch.GetOverlapped(), NULL);
     if (!ret)
                                     flags, NULL,
                                     watch.GetOverlapped(), NULL);
     if (!ret)
@@ -216,6 +239,11 @@ bool wxIOCPThread::ReadEvents()
     wxLogTrace( wxTRACE_FSWATCHER, "[iocp] Read entry: path='%s'",
                 watch->GetPath());
 
     wxLogTrace( wxTRACE_FSWATCHER, "[iocp] Read entry: path='%s'",
                 watch->GetPath());
 
+    // First check if we're still interested in this watch, we could have
+    // removed it in the meanwhile.
+    if ( m_iocp->CompleteRemoval(watch) )
+        return true;
+
     // extract events from buffer info our vector container
     wxVector<wxEventProcessingData> events;
     const char* memory = static_cast<const char*>(watch->GetBuffer());
     // extract events from buffer info our vector container
     wxVector<wxEventProcessingData> events;
     const char* memory = static_cast<const char*>(watch->GetBuffer());
@@ -380,4 +408,30 @@ bool wxMSWFileSystemWatcher::Init()
     return ret;
 }
 
     return ret;
 }
 
+bool
+wxMSWFileSystemWatcher::AddTree(const wxFileName& path,
+                                int events,
+                                const wxString& filter)
+{
+    if ( !filter.empty() )
+    {
+        // Use the inefficient generic version as we can only monitor
+        // everything under the given directory.
+        //
+        // Notice that it would probably be better to still monitor everything
+        // natively and filter out the changes we're not interested in.
+        return wxFileSystemWatcherBase::AddTree(path, events, filter);
+    }
+
+
+    if ( !path.DirExists() )
+    {
+        wxLogError(_("Can't monitor non-existent directory \"%s\" for changes."),
+                   path.GetFullPath());
+        return false;
+    }
+
+    return DoAdd(path, events, wxFSWPath_Tree);
+}
+
 #endif // wxUSE_FSWATCHER
 #endif // wxUSE_FSWATCHER