bool CImportDialog::ImportSites(TiXmlElement* pSitesToImport, TiXmlElement* pExistingSites) { for (TiXmlElement* pImportFolder = pSitesToImport->FirstChildElement("Folder"); pImportFolder; pImportFolder = pImportFolder->NextSiblingElement("Folder")) { wxString name = GetTextElement_Trimmed(pImportFolder, "Name"); if (name == _T("")) name = GetTextElement_Trimmed(pImportFolder); if (name == _T("")) continue; wxString newName = name; int i = 2; TiXmlElement* pFolder; while (!(pFolder = GetFolderWithName(pExistingSites, newName))) { newName = wxString::Format(_T("%s %d"), name.c_str(), i++); } ImportSites(pImportFolder, pFolder); } for (TiXmlElement* pImportSite = pSitesToImport->FirstChildElement("Server"); pImportSite; pImportSite = pImportSite->NextSiblingElement("Server")) { wxString name = GetTextElement_Trimmed(pImportSite, "Name"); if (name == _T("")) name = GetTextElement_Trimmed(pImportSite); if (name == _T("")) continue; // Find free name wxString newName = name; int i = 2; while (HasEntryWithName(pExistingSites, newName)) { newName = wxString::Format(_T("%s %d"), name.c_str(), i++); } TiXmlElement* pServer = pExistingSites->InsertEndChild(*pImportSite)->ToElement(); AddTextElement(pServer, "Name", newName, true); AddTextElement(pServer, newName); } return true; }
bool CImportDialog::ImportLegacySites(TiXmlElement* pSitesToImport, TiXmlElement* pExistingSites) { for (TiXmlElement* pImportFolder = pSitesToImport->FirstChildElement("Folder"); pImportFolder; pImportFolder = pImportFolder->NextSiblingElement("Folder")) { wxString name = GetTextAttribute(pImportFolder, "Name"); if (name == _T("")) continue; wxString newName = name; int i = 2; TiXmlElement* pFolder; while (!(pFolder = GetFolderWithName(pExistingSites, newName))) { newName = wxString::Format(_T("%s %d"), name.c_str(), i++); } ImportLegacySites(pImportFolder, pFolder); } for (TiXmlElement* pImportSite = pSitesToImport->FirstChildElement("Site"); pImportSite; pImportSite = pImportSite->NextSiblingElement("Site")) { wxString name = GetTextAttribute(pImportSite, "Name"); if (name == _T("")) continue; wxString host = GetTextAttribute(pImportSite, "Host"); if (host == _T("")) continue; int port = GetAttributeInt(pImportSite, "Port"); if (port < 1 || port > 65535) continue; int serverType = GetAttributeInt(pImportSite, "ServerType"); if (serverType < 0 || serverType > 4) continue; int protocol; switch (serverType) { default: case 0: protocol = 0; break; case 1: protocol = 3; break; case 2: case 4: protocol = 4; break; case 3: protocol = 1; break; } bool dontSavePass = GetAttributeInt(pImportSite, "DontSavePass") == 1; int logontype = GetAttributeInt(pImportSite, "Logontype"); if (logontype < 0 || logontype > 2) continue; if (logontype == 2) logontype = 4; if (logontype == 1 && dontSavePass) logontype = 2; wxString user = GetTextAttribute(pImportSite, "User"); wxString pass = DecodeLegacyPassword(GetTextAttribute(pImportSite, "Pass")); wxString account = GetTextAttribute(pImportSite, "Account"); if (logontype && user == _T("")) continue; // Find free name wxString newName = name; int i = 2; while (HasEntryWithName(pExistingSites, newName)) { newName = wxString::Format(_T("%s %d"), name.c_str(), i++); } TiXmlElement* pServer = pExistingSites->LinkEndChild(new TiXmlElement("Server"))->ToElement(); AddTextElement(pServer, newName); AddTextElement(pServer, "Host", host); AddTextElement(pServer, "Port", port); AddTextElement(pServer, "Protocol", protocol); AddTextElement(pServer, "Logontype", logontype); AddTextElement(pServer, "User", user); AddTextElement(pServer, "Pass", pass); AddTextElement(pServer, "Account", account); } return true; }