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 AddAny(path, events, wxFSWPath_Tree); }
bool wxFileSystemWatcherBase::AddTree(const wxFileName& path, int events, const wxString& filespec) { if (!path.DirExists()) return false; // OPT could be optimised if we stored information about relationships // between paths class AddTraverser : public wxDirTraverser { public: AddTraverser(wxFileSystemWatcherBase* watcher, int events, const wxString& filespec) : m_watcher(watcher), m_events(events), m_filespec(filespec) { } virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename)) { // There is no need to watch individual files as we watch the // parent directory which will notify us about any changes in them. return wxDIR_CONTINUE; } virtual wxDirTraverseResult OnDir(const wxString& dirname) { if ( m_watcher->AddAny(wxFileName::DirName(dirname), m_events, wxFSWPath_Tree, m_filespec) ) { wxLogTrace(wxTRACE_FSWATCHER, "--- AddTree adding directory '%s' ---", dirname); } return wxDIR_CONTINUE; } private: wxFileSystemWatcherBase* m_watcher; int m_events; wxString m_filespec; }; wxDir dir(path.GetFullPath()); // Prevent asserts or infinite loops in trees containing symlinks int flags = wxDIR_DIRS; if ( !path.ShouldFollowLink() ) { flags |= wxDIR_NO_FOLLOW; } AddTraverser traverser(this, events, filespec); dir.Traverse(traverser, filespec, flags); // Add the path itself explicitly as Traverse() doesn't return it. AddAny(path.GetPathWithSep(), events, wxFSWPath_Tree, filespec); return true; }
bool wxFileSystemWatcherBase::Add(const wxFileName& path, int events) { wxFSWPathType type = wxFSWPath_None; if ( path.FileExists() ) { type = wxFSWPath_File; } else if ( path.DirExists() ) { type = wxFSWPath_Dir; } else { wxLogError(_("Can't monitor non-existent path \"%s\" for changes."), path.GetFullPath()); return false; } return AddAny(path, events, type); }
bool wxFileSystemWatcherBase::Add(const wxFileName& path, int events) { wxFSWPathType type = wxFSWPath_None; if ( path.FileExists() ) { type = wxFSWPath_File; } else if ( path.DirExists() ) { type = wxFSWPath_Dir; } else { // Don't overreact to being passed a non-existent item. It may have // only just been deleted, in which case doing nothing is correct wxLogTrace(wxTRACE_FSWATCHER, "Can't monitor non-existent path \"%s\" for changes.", path.GetFullPath()); return false; } return AddAny(path, events, type); }