void WatchDog::AddPathToWatch(const char *strPath) { #ifdef WATCHDOG_DONT_TEST_PATH return; #else CSingleLock lock(m_lock); CStdString pathToWatch(strPath); pathToWatch = _P(pathToWatch); if (pathToWatch.IsEmpty()) return; if (!IsPathWatched(pathToWatch)) { // default is unknown only for network bool isNetPath = CUtil::IsSmb(pathToWatch) || CUtil::IsUPnP(pathToWatch); m_mapPaths[pathToWatch] = (isNetPath) ? WD_UNKNOWN : WD_AVAILABLE; // for network paths we notify the browser that the path has been added if( isNetPath ) { CBrowserService* pBrowser = g_application.GetBrowserService(); pBrowser->TrackHostAvailability(pathToWatch); } } #endif }
void wxGxDiscConnection::StartWatcher(void) { //add itself wxFileName oFileName = wxFileName::DirName(wxString(m_sPath, wxConvUTF8)); wxString sPath = oFileName.GetFullPath(); if(!IsPathWatched(sPath)) { #ifdef __WXGTK__ if(!m_pWatcher->Add(oFileName, wxFSW_EVENT_ALL)) #else ifdefined __WXMSW__ if(!m_pWatcher->AddTree(oFileName, wxFSW_EVENT_ALL)) #endif { wxLogError(_("Add File system watcher failed")); } } #ifdef __WXGTK__ //add children wxGxObjectList::const_iterator iter; for(iter = GetChildren().begin(); iter != GetChildren().end(); ++iter) { wxGxObject *current = *iter; if(current) { oFileName = wxFileName::DirName(wxString(current->GetPath(), wxConvUTF8)); if(!IsPathWatched(oFileName.GetFullPath())) { if(!m_pWatcher->Add(oFileName, wxFSW_EVENT_ALL)) { wxLogError(_("Add File system watcher failed")); } } } } #endif }
void wxGxDiscConnection::OnObjectAdded(wxGxCatalogEvent& event) { wxGxObject* pGxObject = m_pCatalog->GetRegisterObject(event.GetObjectID()); if(!pGxObject) return; wxString sPath(pGxObject->GetPath(), wxConvUTF8); wxString sConnPath(GetPath(), wxConvUTF8); if(sPath.StartsWith(sConnPath)) { if(!IsPathWatched(sPath) && pGxObject->IsKindOf(wxCLASSINFO(wxGxFolder))) { wxFileName oFileName = wxFileName::DirName(sPath); m_pWatcher->Add(oFileName); } } }
void WatchDog::RemovePathFromWatch(const char *strPath) { #ifdef WATCHDOG_DONT_TEST_PATH return; #else CSingleLock lock(m_lock); CStdString pathToRemove(strPath); pathToRemove = _P(pathToRemove); CLog::Log(LOGDEBUG,"WATCHDOG: remove path [pathToRemove=%s] from watched. [OrgPath=%s]", pathToRemove.c_str(),strPath); if (!IsPathWatched(pathToRemove)) { m_mapPaths.erase(pathToRemove); } #endif }
void wxGxDiscConnection::OnFileSystemEvent(wxFileSystemWatcherEvent& event) { wxLogDebug(wxT("*** %s ***"), event.ToString().c_str()); switch(event.GetChangeType()) { case wxFSW_EVENT_CREATE: { //get object parent wxFileName oName = event.GetPath(); wxGxObjectContainer *parent = wxDynamicCast(FindGxObjectByPath(oName.GetPath()), wxGxObjectContainer); if(!parent) return; //check doubles if(parent->IsNameExist(event.GetPath().GetFullName())) return; CPLString szPath(event.GetPath().GetFullPath().mb_str(wxConvUTF8)); char **papszFileList = NULL; papszFileList = CSLAddString( papszFileList, szPath ); if(m_pCatalog) { wxArrayLong ChildrenIds; m_pCatalog->CreateChildren(parent, papszFileList, ChildrenIds); for(size_t i = 0; i < ChildrenIds.GetCount(); ++i) m_pCatalog->ObjectAdded(ChildrenIds[i]); } CSLDestroy( papszFileList ); } break; case wxFSW_EVENT_DELETE: { //search gxobject wxGxObject *current = FindGxObjectByPath(event.GetPath().GetFullPath()); if(current) { current->Destroy(); return; } } break; case wxFSW_EVENT_RENAME: { wxGxObject *current = FindGxObjectByPath(event.GetPath().GetFullPath()); if(current) { current->SetName(event.GetNewPath().GetFullName()); current->SetPath( CPLString( event.GetNewPath().GetFullPath().mb_str(wxConvUTF8) ) ); wxGIS_GXCATALOG_EVENT_ID(ObjectChanged, current->GetId()); #ifdef __WXGTK__ m_pWatcher->Remove(event.GetPath()); if(!IsPathWatched(event.GetNewPath().GetFullPath())) { m_pWatcher->Add(event.GetNewPath()); } #endif return; } } break; case wxFSW_EVENT_MODIFY: break; default: case wxFSW_EVENT_ACCESS: case wxFSW_EVENT_WARNING: case wxFSW_EVENT_ERROR: break; }; }