CSiteManagerItemData_Site* CSiteManager::ReadServerElement(TiXmlElement *pElement) { CServer server; if (!::GetServer(pElement, server)) return 0; if (server.GetName().empty()) return 0; CSiteManagerItemData_Site* data = new CSiteManagerItemData_Site(server); TiXmlHandle handle(pElement); TiXmlText* comments = handle.FirstChildElement("Comments").FirstChild().Text(); if (comments) data->m_comments = ConvLocal(comments->Value()); TiXmlText* localDir = handle.FirstChildElement("LocalDir").FirstChild().Text(); if (localDir) data->m_localDir = ConvLocal(localDir->Value()); TiXmlText* remoteDir = handle.FirstChildElement("RemoteDir").FirstChild().Text(); if (remoteDir) data->m_remoteDir.SetSafePath(ConvLocal(remoteDir->Value())); if (!data->m_localDir.empty() && !data->m_remoteDir.IsEmpty()) data->m_sync = GetTextElementBool(pElement, "SyncBrowsing", false); return data; }
bool CRemoteDataObject::SetData(size_t len, const void* buf) { char* data = (char*)buf; if (data[len - 1] != 0) return false; if (!m_xmlFile.ParseData(data)) return false; TiXmlElement* pElement = m_xmlFile.GetElement(); if (!pElement || !(pElement = pElement->FirstChildElement("RemoteDataObject"))) return false; m_processId = GetTextElementInt(pElement, "ProcessId", -1); if (m_processId == -1) return false; TiXmlElement* pServer = pElement->FirstChildElement("Server"); if (!pServer || !::GetServer(pServer, m_server)) return false; wxString path = GetTextElement(pElement, "Path"); if (path == _T("") || !m_path.SetSafePath(path)) return false; m_fileList.clear(); TiXmlElement* pFiles = pElement->FirstChildElement("Files"); if (!pFiles) return false; for (TiXmlElement* pFile = pFiles->FirstChildElement("File"); pFile; pFile = pFile->NextSiblingElement("File")) { t_fileInfo info; info.name = GetTextElement(pFile, "Name"); if (info.name == _T("")) return false; const int dir = GetTextElementInt(pFile, "Dir", -1); if (dir == -1) return false; info.dir = dir == 1; info.size = GetTextElementLongLong(pFile, "Size", -2); if (info.size <= -2) return false; info.link = GetTextElementBool(pFile, "Link", false); m_fileList.push_back(info); } return true; }
void CBookmarksDialog::LoadGlobalBookmarks() { CInterProcessMutex mutex(MUTEX_GLOBALBOOKMARKS); CXmlFile file(wxGetApp().GetSettingsFile(_T("bookmarks"))); TiXmlElement* pDocument = file.Load(); if (!pDocument) { wxMessageBoxEx(file.GetError(), _("Error loading xml file"), wxICON_ERROR); return; } for (TiXmlElement *pBookmark = pDocument->FirstChildElement("Bookmark"); pBookmark; pBookmark = pBookmark->NextSiblingElement("Bookmark")) { wxString name; wxString local_dir; wxString remote_dir_raw; CServerPath remote_dir; name = GetTextElement(pBookmark, "Name"); if (name.empty()) continue; local_dir = GetTextElement(pBookmark, "LocalDir"); remote_dir_raw = GetTextElement(pBookmark, "RemoteDir"); if (!remote_dir_raw.empty()) { if (!remote_dir.SetSafePath(remote_dir_raw)) continue; } if (local_dir.empty() && remote_dir.empty()) continue; bool sync; if (local_dir.empty() || remote_dir.empty()) sync = false; else sync = GetTextElementBool(pBookmark, "SyncBrowsing"); CBookmarkItemData *data = new CBookmarkItemData(local_dir, remote_dir, sync); m_pTree->AppendItem(m_bookmarks_global, name, 1, 1, data); } m_pTree->SortChildren(m_bookmarks_global); }
bool CBookmarksDialog::GetBookmark(const wxString &name, wxString &local_dir, CServerPath &remote_dir, bool &sync) { CInterProcessMutex mutex(MUTEX_GLOBALBOOKMARKS); CXmlFile file(wxGetApp().GetSettingsFile(_T("bookmarks"))); TiXmlElement* pDocument = file.Load(); if (!pDocument) { wxMessageBoxEx(file.GetError(), _("Error loading xml file"), wxICON_ERROR); return false; } for (TiXmlElement *pBookmark = pDocument->FirstChildElement("Bookmark"); pBookmark; pBookmark = pBookmark->NextSiblingElement("Bookmark")) { wxString remote_dir_raw; if (name != GetTextElement(pBookmark, "Name")) continue; local_dir = GetTextElement(pBookmark, "LocalDir"); remote_dir_raw = GetTextElement(pBookmark, "RemoteDir"); if (!remote_dir_raw.empty()) { if (!remote_dir.SetSafePath(remote_dir_raw)) return false; } if (local_dir.empty() && remote_dir_raw.empty()) return false; if (local_dir.empty() || remote_dir_raw.empty()) sync = false; else sync = GetTextElementBool(pBookmark, "SyncBrowsing", false); return true; } return false; }
CSiteManagerItemData_Site* CSiteManager::GetSiteByPath(wxString sitePath) { wxChar c = sitePath[0]; if (c != '0' && c != '1') { wxMessageBox(_("Site path has to begin with 0 or 1."), _("Invalid site path")); return 0; } sitePath = sitePath.Mid(1); // We have to synchronize access to sitemanager.xml so that multiple processed don't write // to the same file or one is reading while the other one writes. CInterProcessMutex mutex(MUTEX_SITEMANAGER); CXmlFile file; TiXmlElement* pDocument = 0; if (c == '0') pDocument = file.Load(_T("sitemanager")); else { const wxString& defaultsDir = wxGetApp().GetDefaultsDir(); if (defaultsDir == _T("")) { wxMessageBox(_("Site does not exist."), _("Invalid site path")); return 0; } wxFileName name(defaultsDir, _T("fzdefaults.xml")); pDocument = file.Load(name); } if (!pDocument) { wxMessageBox(file.GetError(), _("Error loading xml file"), wxICON_ERROR); return 0; } TiXmlElement* pElement = pDocument->FirstChildElement("Servers"); if (!pElement) { wxMessageBox(_("Site does not exist."), _("Invalid site path")); return 0; } std::list<wxString> segments; if (!UnescapeSitePath(sitePath, segments) || segments.empty()) { wxMessageBox(_("Site path is malformed."), _("Invalid site path")); return 0; } TiXmlElement* pChild = GetElementByPath(pElement, segments); if (!pChild) { wxMessageBox(_("Site does not exist."), _("Invalid site path")); return 0; } TiXmlElement* pBookmark; if (!strcmp(pChild->Value(), "Bookmark")) { pBookmark = pChild; pChild = pChild->Parent()->ToElement(); segments.pop_back(); } else pBookmark = 0; CSiteManagerItemData_Site* data = ReadServerElement(pChild); if (!data) { wxMessageBox(_("Could not read server item."), _("Invalid site path")); return 0; } if (pBookmark) { TiXmlHandle handle(pBookmark); wxString localPath; CServerPath remotePath; TiXmlText* localDir = handle.FirstChildElement("LocalDir").FirstChild().Text(); if (localDir) localPath = ConvLocal(localDir->Value()); TiXmlText* remoteDir = handle.FirstChildElement("RemoteDir").FirstChild().Text(); if (remoteDir) remotePath.SetSafePath(ConvLocal(remoteDir->Value())); if (!localPath.empty() && !remotePath.IsEmpty()) { data->m_sync = GetTextElementBool(pBookmark, "SyncBrowsing", false); } else data->m_sync = false; data->m_localDir = localPath; data->m_remoteDir = remotePath; } data->m_path = BuildPath( c, segments ); return data; }
bool CSiteManager::Load(TiXmlElement *pElement, CSiteManagerXmlHandler* pHandler) { wxASSERT(pElement); wxASSERT(pHandler); for (TiXmlElement* pChild = pElement->FirstChildElement(); pChild; pChild = pChild->NextSiblingElement()) { if (!strcmp(pChild->Value(), "Folder")) { wxString name = GetTextElement_Trimmed(pChild); if (name.empty()) continue; const bool expand = GetTextAttribute(pChild, "expanded") != _T("0"); if (!pHandler->AddFolder(name, expand)) return false; Load(pChild, pHandler); if (!pHandler->LevelUp()) return false; } else if (!strcmp(pChild->Value(), "Server")) { CSiteManagerItemData_Site* data = ReadServerElement(pChild); if (data) { pHandler->AddSite(data); // Bookmarks for (TiXmlElement* pBookmark = pChild->FirstChildElement("Bookmark"); pBookmark; pBookmark = pBookmark->NextSiblingElement("Bookmark")) { TiXmlHandle handle(pBookmark); wxString name = GetTextElement_Trimmed(pBookmark, "Name"); if (name.empty()) continue; CSiteManagerItemData* data = new CSiteManagerItemData(CSiteManagerItemData::BOOKMARK); TiXmlText* localDir = handle.FirstChildElement("LocalDir").FirstChild().Text(); if (localDir) data->m_localDir = GetTextElement(pBookmark, "LocalDir"); TiXmlText* remoteDir = handle.FirstChildElement("RemoteDir").FirstChild().Text(); if (remoteDir) data->m_remoteDir.SetSafePath(ConvLocal(remoteDir->Value())); if (data->m_localDir.empty() && data->m_remoteDir.IsEmpty()) { delete data; continue; } if (!data->m_localDir.empty() && !data->m_remoteDir.IsEmpty()) data->m_sync = GetTextElementBool(pBookmark, "SyncBrowsing", false); pHandler->AddBookmark(name, data); } if (!pHandler->LevelUp()) return false; } } } return true; }