void ClientManager::saveUsers() const { try { SimpleXML xml; xml.addTag("Users"); xml.stepIn(); { Lock l(cs); for(auto& i: nicks) { if(i.second.second) { xml.addTag("User"); xml.addChildAttrib("CID", i.first.toBase32()); xml.addChildAttrib("Nick", i.second.first); } } } xml.stepOut(); const string fName = getUsersFile(); File out(fName + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE); BufferedOutputStream<false> f(&out); f.write(SimpleXML::utf8Header); xml.toXML(&f); f.flush(); out.close(); File::deleteFile(fName); File::renameFile(fName + ".tmp", fName); } catch(const Exception&) { } }
void MessageManager::saveUsers() { SimpleXML xml; xml.addTag("Ignored"); xml.stepIn(); xml.addTag("Users"); xml.stepIn(); //TODO: cache this information? { RLock l(Ignorecs); for (const auto& u : ignoredUsers) { xml.addTag("User"); xml.addChildAttrib("CID", u->getCID().toBase32()); auto ou = ClientManager::getInstance()->findOnlineUser(u->getCID(), ""); if (ou) { xml.addChildAttrib("Nick", ou->getIdentity().getNick()); xml.addChildAttrib("Hub", ou->getHubUrl()); xml.addChildAttrib("LastSeen", GET_TIME()); } else { auto ofu = ClientManager::getInstance()->getOfflineUser(u->getCID()); xml.addChildAttrib("Nick", ofu ? ofu->getNick() : ""); xml.addChildAttrib("Hub", ofu ? ofu->getUrl() : ""); xml.addChildAttrib("LastSeen", ofu ? ofu->getLastSeen() : GET_TIME()); } } } xml.stepOut(); xml.stepOut(); SettingsManager::saveSettingFile(xml, CONFIG_DIR, CONFIG_NAME); }
void HighlightManager::save(SimpleXML& aXml){ aXml.addTag("Highlights"); aXml.stepIn(); for(const auto& hl: colorSettings) { aXml.addTag("Highlight"); aXml.addChildAttrib("Context", hl.getContext()); aXml.addChildAttrib("Match", Text::fromT(hl.getMatch())); aXml.addChildAttrib("Bold", hl.getBold()); aXml.addChildAttrib("Italic", hl.getItalic()); aXml.addChildAttrib("Underline", hl.getUnderline()); aXml.addChildAttrib("Strikeout", hl.getStrikeout()); aXml.addChildAttrib("CaseSensitive", hl.getCaseSensitive()); aXml.addChildAttrib("WholeLine", hl.getWholeLine()); aXml.addChildAttrib("WholeWord", hl.getWholeWord()); aXml.addChildAttrib("Popup", hl.getPopup()); aXml.addChildAttrib("Tab", hl.getTab()); aXml.addChildAttrib("PlaySound", hl.getPlaySound()); //aXml.addChildAttrib("LastLog", hl.getLog()); aXml.addChildAttrib("FlashWindow", hl.getFlashWindow() ); aXml.addChildAttrib("MatchType", hl.getMatchType()); aXml.addChildAttrib("HasFgColor", hl.getHasFgColor()); aXml.addChildAttrib("HasBgColor", hl.getHasBgColor()); aXml.addChildAttrib("FgColor", Util::toString(hl.getFgColor())); aXml.addChildAttrib("BgColor", Util::toString(hl.getBgColor())); aXml.addChildAttrib("SoundFile", hl.getSoundFile()); aXml.addChildAttrib("MatchColumn", hl.getMatchColumn()); }//end for aXml.stepOut(); }
void IpGuard::save() { Lock l(cs); SimpleXML xml; xml.addTag("IpRanges"); xml.stepIn(); for (RangeIter i = ranges.begin(); i != ranges.end(); ++i) { xml.addTag("Range"); xml.addChildAttrib("Start", Util::toString(i->start.iIP)); xml.addChildAttrib("End", Util::toString(i->end.iIP)); xml.addChildAttrib("Comment", i->name); } xml.stepOut(); try { string fname = Util::getPath(Util::PATH_USER_CONFIG) + "IPGuard.xml"; File f(fname + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE); f.write(SimpleXML::utf8Header); f.write(xml.toXML()); f.close(); File::deleteFile(fname); File::renameFile(fname + ".tmp", fname); } catch (const Exception& e) { dcdebug("IpGuard::save: %s\n", e.getError().c_str()); } }
void HighlightManager::save(SimpleXML& aXml) { aXml.addTag("Highlights"); aXml.stepIn(); ColorIter iter = colorSettings.begin(); for(; iter != colorSettings.end(); ++iter) { aXml.addTag("Highlight"); aXml.addChildAttrib("Match", Text::wideToUtf8((*iter).getMatch())); aXml.addChildAttrib("Bold", (*iter).getBold()); aXml.addChildAttrib("Italic", (*iter).getItalic()); aXml.addChildAttrib("Underline", (*iter).getUnderline()); aXml.addChildAttrib("Strikeout", (*iter).getStrikeout()); aXml.addChildAttrib("IncludeNickList", (*iter).getIncludeNickList()); aXml.addChildAttrib("CaseSensitive", (*iter).getCaseSensitive()); aXml.addChildAttrib("WholeLine", (*iter).getWholeLine()); aXml.addChildAttrib("WholeWord", (*iter).getWholeWord()); aXml.addChildAttrib("Popup", (*iter).getPopup()); aXml.addChildAttrib("Tab", (*iter).getTab()); aXml.addChildAttrib("PlaySound", (*iter).getPlaySound()); aXml.addChildAttrib("LastLog", (*iter).getLog()); aXml.addChildAttrib("FlashWindow", (*iter).getFlashWindow() ); aXml.addChildAttrib("MatchType", (*iter).getMatchType()); aXml.addChildAttrib("HasFgColor", (*iter).getHasFgColor()); aXml.addChildAttrib("HasBgColor", (*iter).getHasBgColor()); aXml.addChildAttrib("FgColor", Util::toString((*iter).getFgColor())); aXml.addChildAttrib("BgColor", Util::toString((*iter).getBgColor())); aXml.addChildAttrib("SoundFile", Text::wideToUtf8((*iter).getSoundFile())); }//end for aXml.stepOut(); }
bool WebServerManager::save(std::function<void(const string&)> aCustomErrorF) noexcept { SimpleXML xml; xml.addTag("WebServer"); xml.stepIn(); { xml.addTag("Config"); xml.stepIn(); plainServerConfig.save(xml, "Server"); tlsServerConfig.save(xml, "TLSServer"); xml.stepOut(); } fire(WebServerManagerListener::SaveSettings(), xml); xml.stepOut(); auto errorF = aCustomErrorF; if (!errorF) { // Avoid crashes if the file is saved when core is not loaded errorF = [](const string&) {}; } return SettingsManager::saveSettingFile(xml, CONFIG_DIR, CONFIG_NAME, errorF); }
/* * Save bootstrap nodes to disk */ void KBucket::saveNodes(SimpleXML& xml) { xml.addTag("Nodes"); xml.stepIn(); // get 50 random nodes to bootstrap from them next time Node::Map closestToMe; getClosestNodes(CID::generate(), closestToMe, 50, 3); for(Node::Map::const_iterator j = closestToMe.begin(); j != closestToMe.end(); j++) { const Node::Ptr& node = j->second; xml.addTag("Node"); xml.addChildAttrib("CID", node->getUser()->getCID().toBase32()); xml.addChildAttrib("type", node->getType()); xml.addChildAttrib("verified", node->isIpVerified()); if(!node->getUDPKey().key.isZero() && !node->getUDPKey().ip.empty()) { xml.addChildAttrib("key", node->getUDPKey().key.toBase32()); xml.addChildAttrib("keyIP", node->getUDPKey().ip); } StringMap params; node->getIdentity().getParams(params, Util::emptyString, false, true); for(StringMap::const_iterator i = params.begin(); i != params.end(); i++) xml.addChildAttrib(i->first, i->second); } xml.stepOut(); }
/* * Save all indexes to disk */ void IndexManager::saveIndexes(SimpleXML& xml) { xml.addTag("Files"); xml.stepIn(); Lock l(cs); for(auto i = tthList.cbegin(); i != tthList.cend(); ++i) { xml.addTag("File"); xml.addChildAttrib("TTH", i->first.toBase32()); xml.stepIn(); for(auto j = i->second.cbegin(); j != i->second.cend(); ++j) { const Source& source = *j; if(source.getPartial()) continue; // don't store partial sources xml.addTag("Source"); xml.addChildAttrib("CID", source.getCID().toBase32()); xml.addChildAttrib("I4", source.getIp()); xml.addChildAttrib("U4", source.getUdpPort()); xml.addChildAttrib("SI", source.getSize()); xml.addChildAttrib("EX", source.getExpires()); } xml.stepOut(); } xml.stepOut(); }
void RawManager::on(SettingsManagerListener::Save, SimpleXML& xml) throw() { xml.addTag("ADLSPoints"); xml.stepIn(); for(IntMap::const_iterator i = points.begin(); i != points.end(); ++i) { xml.addTag("PointsSetting"); xml.addChildAttrib("Points", i->first); xml.addChildAttrib("Action", i->second); } xml.stepOut(); }
void IgnoreManager::save(SimpleXML& aXml) { aXml.addTag("IgnoreList"); aXml.stepIn(); for(TStringHashIterC i = ignoredUsers.begin(); i != ignoredUsers.end(); ++i) { aXml.addTag("User"); aXml.addChildAttrib("Nick", Text::fromT(*i)); } aXml.stepOut(); }
void FireSettingsManager::save(string const& aFileName) { SimpleXML xml; xml.addTag("Fire"); xml.stepIn(); xml.addTag("FireSettings"); xml.stepIn(); int i; string type("type"), curType("string"); for(i=STR_FIRST; i<STR_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], get(StrSetting(i), false)); xml.addChildAttrib(type, curType); } } curType = "int"; for(i=INT_FIRST; i<INT_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], get(IntSetting(i), false)); xml.addChildAttrib(type, curType); } } curType = "int64"; for(i=INT64_FIRST; i<INT64_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], get(Int64Setting(i), false)); xml.addChildAttrib(type, curType); } } xml.stepOut(); fire(FireSettingsManagerListener::Save(), xml); // fire(FireSettingsManagerListener::Save(), &xml); try { File out(aFileName + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE); BufferedOutputStream<false> f(&out); f.write(SimpleXML::utf8Header); xml.toXML(&f); f.flush(); out.close(); File::deleteFile(aFileName); File::renameFile(aFileName + ".tmp", aFileName); } catch(const FileException&) { // ... } }
void ShareManager::save(SimpleXML& aXml) { Lock l(cs); aXml.addTag("Share"); aXml.stepIn(); for(auto& i: shares) { aXml.addTag("Directory", i.first); aXml.addChildAttrib("Virtual", i.second); } aXml.stepOut(); }
void WebShortcuts::save(SimpleXML& xml) { xml.addTag("WebShortcuts"); xml.stepIn(); for(auto i: list) { xml.addTag("WebShortcut"); xml.addChildAttrib("Name", i->name); xml.addChildAttrib("Key", i->key); xml.addChildAttrib("URL", i->url); xml.addChildAttrib("Clean", i->clean); } xml.stepOut(); }
void RSSManager::save(SimpleXML& aXml) { CFlyLock(g_csFeed); aXml.addTag("Rss"); aXml.stepIn(); for (auto i = g_feeds.cbegin(); i != g_feeds.cend(); ++i) { aXml.addTag("Feed", (*i)->getFeedURL()); aXml.addChildAttrib("Name", (*i)->getSource()); const size_t codeingT = GetCodeingByString((*i)->getCodeing()); aXml.addChildAttrib("Codeing", Util::toString(codeingT)); } aXml.stepOut(); }
void WebUserManager::on(WebServerManagerListener::SaveSettings, SimpleXML& xml_) noexcept { xml_.addTag("WebUsers"); xml_.stepIn(); { RLock l(cs); for (const auto& u : users | map_values) { xml_.addTag("WebUser"); xml_.addChildAttrib("Username", u->getUserName()); xml_.addChildAttrib("Password", u->getPassword()); xml_.addChildAttrib("LastLogin", u->getLastLogin()); xml_.addChildAttrib("Permissions", u->getPermissionsStr()); } } xml_.stepOut(); }
void ToolbarManager::save(SimpleXML& aXml) { aXml.addTag("Rebars"); aXml.stepIn(); for(ToolbarEntry::Iter i = toolbarEntries.begin(); i != toolbarEntries.end(); ++i) { aXml.addTag("Rebar"); aXml.addChildAttrib("Name", (*i)->getName()); aXml.addChildAttrib("ID", (*i)->getID()); aXml.addChildAttrib("CX", (*i)->getCX()); aXml.addChildAttrib("BreakLine", (*i)->getBreakLine()); aXml.addChildAttrib("BandCount", (*i)->getBandCount()); } aXml.stepOut(); }
void ServerConfig::save(SimpleXML& xml_, const string& aTagName) noexcept { if (!hasValidConfig()) { return; } xml_.addTag(aTagName); xml_.addChildAttrib("Port", port); }
void ADLSearchManager::save() { // Prepare xml string for saving try { SimpleXML xml; xml.addTag("ADLSearch"); xml.stepIn(); // Predicted several groups of searches to be differentiated // in multiple categories. Not implemented yet. xml.addTag("SearchGroup"); xml.stepIn(); // Save all searches for(auto& search: collection) { if(search.searchString.empty()) { continue; } xml.addTag("Search"); xml.stepIn(); xml.addTag("SearchString", search.searchString); xml.addTag("SourceType", search.SourceTypeToString(search.sourceType)); xml.addTag("DestDirectory", search.destDir); xml.addTag("IsActive", search.isActive); xml.addTag("MaxSize", search.maxFileSize); xml.addTag("MinSize", search.minFileSize); xml.addTag("SizeType", search.SizeTypeToString(search.typeFileSize)); xml.addTag("IsAutoQueue", search.isAutoQueue); xml.stepOut(); } xml.stepOut(); xml.stepOut(); // Save string to file try { File fout(getConfigFile(), File::WRITE, File::CREATE | File::TRUNCATE); fout.write(SimpleXML::utf8Header); fout.write(xml.toXML()); fout.close(); } catch(const FileException&) { } } catch(const SimpleXMLException&) { } }
void IpManager::WatchSave() { Lock l(cs); try { SimpleXML xml; xml.addTag("IPWatch"); xml.stepIn(); { xml.addTag("IPWatch"); xml.stepIn(); { for(IPWatch::Iter i = ipwatch.begin(); i != ipwatch.end(); ++i) { xml.addTag("IPWatch"); xml.addChildAttrib("Mode", (*i)->getMode()); xml.addChildAttrib("Pattern", (*i)->getPattern()); xml.addChildAttrib("Task", (*i)->getTask()); xml.addChildAttrib("Action", (*i)->getAction()); xml.addChildAttrib("DisplayCheat", (*i)->getDisplayCheat()); xml.addChildAttrib("Cheat", (*i)->getCheat()); xml.addChildAttrib("MatchType", (*i)->getMatchType()); xml.addChildAttrib("ISP", (*i)->getIsp()); } } xml.stepOut(); xml.addTag("RevisionInfo"); xml.stepIn(); { xml.addTag("Version", getIpWatchVersion()); } xml.stepOut(); } xml.stepOut(); string fname = Util::getPath(Util::PATH_USER_CONFIG) + "IPWatch.xml"; File f(fname + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE); f.write(SimpleXML::utf8Header); f.write(xml.toXML()); f.close(); File::deleteFile(fname); File::renameFile(fname + ".tmp", fname); } catch(const Exception& e) { dcdebug("IpManager::WatchSave: %s\n", e.getError().c_str()); } }
void MessageManager::save(SimpleXML& aXml) { aXml.addTag("ChatFilterItems"); aXml.stepIn(); { RLock l(Ignorecs); for (const auto& i : ChatFilterItems) { aXml.addTag("ChatFilterItem"); aXml.addChildAttrib("Nick", i.getNickPattern()); aXml.addChildAttrib("NickMethod", i.getNickMethod()); aXml.addChildAttrib("Text", i.getTextPattern()); aXml.addChildAttrib("TextMethod", i.getTextMethod()); aXml.addChildAttrib("MC", i.matchMainchat); aXml.addChildAttrib("PM", i.matchPM); aXml.addChildAttrib("Enabled", i.getEnabled()); } } aXml.stepOut(); if (dirty) saveUsers(); }
void RawManager::saveActionRaws() { try { SimpleXML xml; xml.addTag("ActionRaws"); xml.stepIn(); for(Action::ActionList::const_iterator i = actions.begin(); i != actions.end(); ++i) { xml.addTag("Action"); xml.addChildAttrib("ID", Util::toString((*i)->getId())); xml.addChildAttrib("Name", (*i)->getName()); xml.addChildAttrib("Enabled", Util::toString((*i)->getEnabled())); xml.stepIn(); for(Action::RawsList::const_iterator j = (*i)->raw.begin(); j != (*i)->raw.end(); ++j) { xml.addTag("Raw"); xml.addChildAttrib("ID", Util::toString(j->getId())); xml.addChildAttrib("Name", j->getName()); xml.addChildAttrib("Raw", j->getRaw()); xml.addChildAttrib("Time", Util::toString(j->getTime())); xml.addChildAttrib("Enabled", Util::toString(j->getEnabled())); xml.addChildAttrib("UseLua", Util::toString(j->getLua())); } xml.stepOut(); } xml.stepOut(); string fname = Util::getPath(Util::PATH_USER_CONFIG) + "Raws.xml"; File f(fname + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE); f.write(SimpleXML::utf8Header); f.write(xml.toXML()); f.close(); File::deleteFile(fname); File::renameFile(fname + ".tmp", fname); } catch(const Exception& e) { dcdebug("RawManager::saveActionRaws: %s\n", e.getError().c_str()); } }
void AutoSearch::saveToXml(SimpleXML& xml) { xml.addTag("Autosearch"); xml.addChildAttrib("Enabled", getEnabled()); xml.addChildAttrib("SearchString", getSearchString()); xml.addChildAttrib("FileType", getFileType()); xml.addChildAttrib("Action", getAction()); xml.addChildAttrib("Remove", getRemove()); xml.addChildAttrib("Target", getTarget()); xml.addChildAttrib("TargetType", getTargetType()); xml.addChildAttrib("MatcherType", getMethod()), xml.addChildAttrib("MatcherString", getMatcherString()), xml.addChildAttrib("UserMatch", getNickPattern()); xml.addChildAttrib("ExpireTime", getExpireTime()); xml.addChildAttrib("CheckAlreadyQueued", getCheckAlreadyQueued()); xml.addChildAttrib("CheckAlreadyShared", getCheckAlreadyShared()); xml.addChildAttrib("SearchDays", searchDays.to_string()); xml.addChildAttrib("StartTime", startTime.toString()); xml.addChildAttrib("EndTime", endTime.toString()); xml.addChildAttrib("LastSearchTime", Util::toString(getLastSearch())); xml.addChildAttrib("MatchFullPath", getMatchFullPath()); xml.addChildAttrib("ExcludedWords", getExcludedString()); xml.addChildAttrib("SearchInterval", Util::toString(getSearchInterval())); xml.addChildAttrib("ItemType", Util::toString(getAsType())); xml.addChildAttrib("Token", Util::toString(getToken())); xml.addChildAttrib("TimeAdded", Util::toString(getTimeAdded())); xml.addChildAttrib("Group", getGroup()); xml.addChildAttrib("UserMatcherExclude", getUserMatcherExclude()); xml.stepIn(); xml.addTag("Params"); xml.addChildAttrib("Enabled", getUseParams()); xml.addChildAttrib("CurNumber", getCurNumber()); xml.addChildAttrib("MaxNumber", getMaxNumber()); xml.addChildAttrib("MinNumberLen", getNumberLen()); xml.addChildAttrib("LastIncFinish", getLastIncFinish()); if (!getFinishedPaths().empty()) { xml.addTag("FinishedPaths"); xml.stepIn(); for (auto& p : getFinishedPaths()) { xml.addTag("Path", p.first); xml.addChildAttrib("FinishTime", p.second); } xml.stepOut(); } if (!getBundles().empty()) { xml.addTag("Bundles"); xml.stepIn(); for (const auto& b : getBundles()) { xml.addTag("Bundle", Util::toString(b->getToken())); } xml.stepOut(); } xml.stepOut(); }
void SettingsManager::save(string const& aFileName) { SimpleXML xml; xml.addTag("DCPlusPlus"); xml.stepIn(); xml.addTag("Settings"); xml.stepIn(); int i; string type("type"), curType("string"); for(i=STR_FIRST; i<STR_LAST; i++) { if(i == CONFIG_VERSION) { xml.addTag(settingTags[i], VERSIONSTRING); xml.addChildAttrib(type, curType); } else if(isSet[i]) { xml.addTag(settingTags[i], get(StrSetting(i), false)); xml.addChildAttrib(type, curType); } } curType = "int"; for(i=INT_FIRST; i<INT_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], get(IntSetting(i), false)); xml.addChildAttrib(type, curType); } } for(i=FLOAT_FIRST; i<FLOAT_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], static_cast<int>(get(FloatSetting(i), false) * 1000.)); xml.addChildAttrib(type, curType); } } curType = "int64"; for(i=INT64_FIRST; i<INT64_LAST; i++) { if(isSet[i]) { xml.addTag(settingTags[i], get(Int64Setting(i), false)); xml.addChildAttrib(type, curType); } } xml.stepOut(); xml.addTag("SearchTypes"); xml.stepIn(); for(SearchTypesIterC i = searchTypes.begin(); i != searchTypes.end(); ++i) { xml.addTag("SearchType", Util::toString(";", i->second)); xml.addChildAttrib("Id", i->first); } xml.stepOut(); fire(SettingsManagerListener::Save(), xml); try { File out(aFileName + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE); BufferedOutputStream<false> f(&out); f.write(SimpleXML::utf8Header); xml.toXML(&f); f.flush(); out.close(); File::deleteFile(aFileName); File::renameFile(aFileName + ".tmp", aFileName); } catch(const FileException&) { // ... } }
void ClientProfileManager::saveClientProfiles() { try { SimpleXML xml; xml.addTag("Profiles"); xml.stepIn(); xml.addTag("ClientProfilesV2"); xml.stepIn(); for(ClientProfile::List::const_iterator l = clientProfiles.begin(); l != clientProfiles.end(); ++l) { xml.addTag("ClientProfile"); xml.stepIn(); xml.addTag("Name", l->getName()); xml.addTag("Version", l->getVersion()); xml.addTag("Tag", l->getTag()); xml.addTag("ExtendedTag", l->getExtendedTag()); xml.addTag("Lock", l->getLock()); xml.addTag("Pk", l->getPk()); xml.addTag("Supports", l->getSupports()); xml.addTag("TestSUR", l->getTestSUR()); xml.addTag("UserConCom", l->getUserConCom()); xml.addTag("Status", l->getStatus()); xml.addTag("CheatingDescription", l->getCheatingDescription()); xml.addTag("RawToSend", Util::toString(l->getRawToSend())); //xml.addTag("TagVersion", Util::toString(l->getTagVersion())); xml.addTag("UseExtraVersion", Util::toString(l->getUseExtraVersion())); xml.addTag("CheckMismatch", Util::toString(l->getCheckMismatch())); xml.addTag("Connection", l->getConnection()); xml.addTag("Comment", l->getComment()); xml.addTag("Recheck", l->getRecheck()); xml.addTag("SkipExtended", l->getSkipExtended()); xml.stepOut(); } xml.stepOut(); xml.addTag("Params"); xml.stepIn(); for(StringMap::iterator m = params.begin(); m != params.end(); ++m) { xml.addTag("Param"); xml.addChildAttrib("Name", m->first); xml.addChildAttrib("RegExp", m->second); } xml.stepOut(); xml.stepOut(); string fname = Util::getConfigPath() + "Profiles.xml"; File f(fname + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE); f.write(SimpleXML::utf8Header); f.write(xml.toXML()); f.close(); File::deleteFile(fname); File::renameFile(fname + ".tmp", fname); } catch(const Exception& e) { dcdebug("FavoriteManager::saveClientProfiles: %s\n", e.getError().c_str()); } }
LRESULT PropPageTextStyles::onExport(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { tstring x = _T(""); if(WinUtil::browseFile(x, m_hWnd, true, x, types, defExt) == IDOK) { SimpleXML xml; xml.addTag("DCPlusPlus"); xml.stepIn(); xml.addTag("Settings"); xml.stepIn(); string type("type"), curType("string"); exportData("Font", TEXT_FONT); curType = "int"; exportData("BackgroundColor", BACKGROUND_COLOR); exportData("TextColor", TEXT_COLOR); exportData("DownloadBarColor", DOWNLOAD_BAR_COLOR); exportData("UploadBarColor", UPLOAD_BAR_COLOR); exportData("TextGeneralBackColor", TEXT_GENERAL_BACK_COLOR); exportData("TextGeneralForeColor", TEXT_GENERAL_FORE_COLOR); exportData("TextGeneralBold", TEXT_GENERAL_BOLD); exportData("TextGeneralItalic", TEXT_GENERAL_ITALIC); exportData("TextMyOwnBackColor", TEXT_MYOWN_BACK_COLOR); exportData("TextMyOwnForeColor", TEXT_MYOWN_FORE_COLOR); exportData("TextMyOwnBold", TEXT_MYOWN_BOLD); exportData("TextMyOwnItalic", TEXT_MYOWN_ITALIC); exportData("TextPrivateBackColor", TEXT_PRIVATE_BACK_COLOR); exportData("TextPrivateForeColor", TEXT_PRIVATE_FORE_COLOR); exportData("TextPrivateBold", TEXT_PRIVATE_BOLD); exportData("TextPrivateItalic", TEXT_PRIVATE_ITALIC); exportData("TextSystemBackColor", TEXT_SYSTEM_BACK_COLOR); exportData("TextSystemForeColor", TEXT_SYSTEM_FORE_COLOR); exportData("TextSystemBold", TEXT_SYSTEM_BOLD); exportData("TextSystemItalic", TEXT_SYSTEM_ITALIC); exportData("TextServerBackColor", TEXT_SERVER_BACK_COLOR); exportData("TextServerForeColor", TEXT_SERVER_FORE_COLOR); exportData("TextServerBold", TEXT_SERVER_BOLD); exportData("TextServerItalic", TEXT_SERVER_ITALIC); exportData("TextTimestampBackColor", TEXT_TIMESTAMP_BACK_COLOR); exportData("TextTimestampForeColor", TEXT_TIMESTAMP_FORE_COLOR); exportData("TextTimestampBold", TEXT_TIMESTAMP_BOLD); exportData("TextTimestampItalic", TEXT_TIMESTAMP_ITALIC); exportData("TextMyNickBackColor", TEXT_MYNICK_BACK_COLOR); exportData("TextMyNickForeColor", TEXT_MYNICK_FORE_COLOR); exportData("TextMyNickBold", TEXT_MYNICK_BOLD); exportData("TextMyNickItalic", TEXT_MYNICK_ITALIC); exportData("TextFavBackColor", TEXT_FAV_BACK_COLOR); exportData("TextFavForeColor", TEXT_FAV_FORE_COLOR); exportData("TextFavBold", TEXT_FAV_BOLD); exportData("TextFavItalic", TEXT_FAV_ITALIC); exportData("TextURLBackColor", TEXT_URL_BACK_COLOR); exportData("TextURLForeColor", TEXT_URL_FORE_COLOR); exportData("TextURLBold", TEXT_URL_BOLD); exportData("TextURLItalic", TEXT_URL_ITALIC); exportData("ProgressTextDown", PROGRESS_TEXT_COLOR_DOWN); exportData("ProgressTextUp", PROGRESS_TEXT_COLOR_UP); exportData("ErrorColor", ERROR_COLOR); exportData("ProgressOverrideColors", PROGRESS_OVERRIDE_COLORS); exportData("MenubarTwoColors", MENUBAR_TWO_COLORS); exportData("MenubarLeftColor", MENUBAR_LEFT_COLOR); exportData("MenubarRightColor", MENUBAR_RIGHT_COLOR); exportData("MenubarBumped", MENUBAR_BUMPED); exportData("Progress3DDepth", PROGRESS_3DDEPTH); exportData("ProgressOverrideColors2", PROGRESS_OVERRIDE_COLORS2); exportData("TextOPBackColor", TEXT_OP_BACK_COLOR); exportData("TextOPForeColor", TEXT_OP_FORE_COLOR); exportData("TextOPBold", TEXT_OP_BOLD); exportData("TextOPItalic", TEXT_OP_ITALIC); exportData("TextNormBackColor", TEXT_NORM_BACK_COLOR); exportData("TextNormForeColor", TEXT_NORM_FORE_COLOR); exportData("TextNormBold", TEXT_NORM_BOLD); exportData("TextNormItalic", TEXT_NORM_ITALIC); exportData("SearchAlternateColour", SEARCH_ALTERNATE_COLOUR); exportData("ProgressBackColor", PROGRESS_BACK_COLOR); exportData("ProgressCompressColor", PROGRESS_COMPRESS_COLOR); exportData("ProgressSegmentColor", PROGRESS_SEGMENT_COLOR); exportData("ColorDone", COLOR_DONE); exportData("ColorDownloaded", COLOR_DOWNLOADED); exportData("ColorRunning", COLOR_RUNNING); exportData("ReservedSlotColor", RESERVED_SLOT_COLOR); exportData("IgnoredColor", IGNORED_COLOR); exportData("FavoriteColor", FAVORITE_COLOR); exportData("NormalColour", NORMAL_COLOUR); exportData("PasiveColor", PASIVE_COLOR); exportData("OpColor", OP_COLOR); exportData("ProgressbaroDCStyle", PROGRESSBAR_ODC_STYLE); exportData("UnderlineLinks", UNDERLINE_LINKS); exportData("UnderlineDupes", UNDERLINE_DUPES); exportData("TextDupeBackColor", TEXT_DUPE_BACK_COLOR); exportData("TextDupeColor", DUPE_COLOR); exportData("TextDupeBold", TEXT_DUPE_BOLD); exportData("TextDupeItalic", TEXT_DUPE_ITALIC); exportData("TextQueueBackColor", TEXT_QUEUE_BACK_COLOR); exportData("QueueColor", QUEUE_COLOR); exportData("TextQueueBold", TEXT_QUEUE_BOLD); exportData("TextQueueItalic", TEXT_QUEUE_ITALIC); exportData("UnderlineQueue", UNDERLINE_QUEUE); //tabs exportData("tabactivebg", TAB_ACTIVE_BG); exportData("TabActiveText", TAB_ACTIVE_TEXT); exportData("TabActiveBorder", TAB_ACTIVE_BORDER); exportData("TabInactiveBg", TAB_INACTIVE_BG); exportData("TabInactiveBgDisconnected", TAB_INACTIVE_BG_DISCONNECTED); exportData("TabInactiveText", TAB_INACTIVE_TEXT); exportData("TabInactiveBorder", TAB_INACTIVE_BORDER); exportData("TabInactiveBgNotify", TAB_INACTIVE_BG_NOTIFY); exportData("TabDirtyBlend", TAB_DIRTY_BLEND); exportData("BlendTabs", BLEND_TABS); exportData("TabSize", TAB_SIZE); xml.stepOut(); if(!HighlightManager::getInstance()->emptyList()) HighlightManager::getInstance()->save(xml); /* Don't export icon stuff, user might have absolute path for toolbars. Icon packs can be included by editing the .dctheme example. curType = "string"; string empty = ""; xml.addTag("Icons"); xml.stepIn(); exportData("IconPath", ICON_PATH); xml.addTag("ToolbarImage", empty); xml.addChildAttrib(curType, curType); xml.addTag("ToolbarHot", empty); xml.addChildAttrib(type, curType); xml.stepOut(); */ try { File ff(Text::fromT(x) , File::WRITE, File::CREATE | File::TRUNCATE); BufferedOutputStream<false> f(&ff); f.write(SimpleXML::utf8Header); xml.toXML(&f); f.flush(); ff.close(); } catch(const FileException&) { // ... } } return 0; }
int __cdecl main(int argc, char* argv[]) { if(argc < 3) { return 0; } try { string tmp; File src(argv[1], File::READ, File::OPEN, false); File tgt(argv[2], File::WRITE, File::CREATE | File::TRUNCATE, false); File example(argv[3], File::WRITE, File::CREATE | File::TRUNCATE, false); string x = src.read(); x = Text::acpToUtf8(x); string::size_type k; while((k = x.find('\r')) != string::npos) { x.erase(k, 1); } StringList l = StringTokenizer<string>(x, '\n').getTokens(); StringIter i; string varStr; string varName; string start; SimpleXML ex; for(i = l.begin(); i != l.end(); ) { if( (k = i->find("// @Strings: ")) != string::npos) { varStr = i->substr(k + 13); i = l.erase(i); } else if( (k = i->find("// @Names: ")) != string::npos) { varName = i->substr(k + 11); i = l.erase(i); } else if(i->find("// @DontAdd") != string::npos) { i = l.erase(i); } else if( (k = i->find("// @Prolog: ")) != string::npos) { start += i->substr(k + 12) + "\r\n"; i = l.erase(i); } else if(i->size() < 5) { i = l.erase(i); } else { ++i; } } if(varStr.empty() || varName.empty()) { printf("No @Strings or @Names\n"); return 0; } varStr += " = {\r\n"; varName += " = {\r\n"; /* ex.addTag("Language"); ex.addChildAttrib("Name", string("Example Language")); ex.addChildAttrib("Author", string("FlylinkDC++ Development Team")); //ex.addChildAttrib("Version", string(A_VERSIONSTRING)); ex.addChildAttrib("Revision", string("1")); ex.stepIn(); */ ex.addTag("resources"); ex.stepIn(); string name; string def; string xmldef; string s; for(i = l.begin(); i != l.end(); i++) { name.clear(); s = *i; bool u = true; for(k = s.find_first_not_of(" \t"); s[k] != ','; k++) { if(s[k] == '_') { u = true; } else if(u) { name+=s[k]; u = false; } else { name+=(char)tolower(s[k]); } } k = s.find("// "); def = s.substr(k + 3); xmldef = def.substr(1, def.size() - 2); /* while( (k = xmldef.find("\\t")) != string::npos) { xmldef.replace(k, 2, "\t"); } while( (k = xmldef.find("\\r")) != string::npos) { xmldef.replace(k, 2, "\r"); } while( (k = xmldef.find("\\n")) != string::npos) { xmldef.replace(k, 2, "\n"); } while( (k = xmldef.find("\\\\")) != string::npos) { xmldef.replace(k, 2, "\\"); } */ ex.addTag("string", xmldef); ex.addChildAttrib("name", name); varStr += def + ", \r\n"; varName += '\"' + name + "\", \r\n"; } varStr.erase(varStr.size()-2, 2); varName.erase(varName.size()-2, 2); varStr += "\r\n};\r\n"; varName += "\r\n};\r\n"; tgt.write(start); tgt.write(varStr); tgt.write(varName); example.write(SimpleXML::utf8Header); example.write(ex.toXML()); } catch(const Exception& e) { printf("%s\n", e.getError().c_str()); } return 0; }
/////////////////////////////////////////////////////////////////////////////// // // Save current searches to disk // /////////////////////////////////////////////////////////////////////////////// void ADLSearchManager::Save() { // Prepare xml string for saving try { SimpleXML xml; xml.addTag("ADLSearch"); xml.stepIn(); // Predicted several groups of searches to be differentiated // in multiple categories. Not implemented yet. xml.addTag("SearchGroup"); xml.stepIn(); // Save all searches for(SearchCollection::iterator i = collection.begin(); i != collection.end(); ++i) { ADLSearch& search = *i; if(search.searchString.size() == 0) { continue; } string type = "type"; xml.addTag("Search"); xml.stepIn(); xml.addTag("SearchString", search.searchString); xml.addChildAttrib(type, string("string")); xml.addTag("SourceType", search.SourceTypeToString(search.sourceType)); xml.addChildAttrib(type, string("string")); xml.addTag("DestDirectory", search.destDir); xml.addChildAttrib(type, string("string")); xml.addTag("IsActive", search.isActive); xml.addChildAttrib(type, string("int")); xml.addTag("MaxSize", search.maxFileSize); xml.addChildAttrib(type, string("int64")); xml.addTag("MinSize", search.minFileSize); xml.addChildAttrib(type, string("int64")); xml.addTag("SizeType", search.SizeTypeToString(search.typeFileSize)); xml.addChildAttrib(type, string("string")); xml.addTag("IsAutoQueue", search.isAutoQueue); xml.addChildAttrib(type, string("int")); xml.stepOut(); } xml.stepOut(); xml.stepOut(); // Save string to file try { File fout(getConfigFile(), File::WRITE, File::CREATE | File::TRUNCATE); fout.write(SimpleXML::utf8Header); fout.write(xml.toXML()); fout.close(); } catch(const FileException&) { return; } } catch(const SimpleXMLException&) { return; } }
LRESULT PropPageTextStyles::onExport(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { tstring x = _T(""); if(WinUtil::browseFile(x, m_hWnd, true, x, types, defExt) == IDOK) { SimpleXML xml; xml.addTag("DCPlusPlus"); xml.stepIn(); xml.addTag("Settings"); xml.stepIn(); string type("type"), curType("string"); exportData("Font", TEXT_FONT); curType = "int"; exportData("BackgroundColor", BACKGROUND_COLOR); exportData("TextColor", TEXT_COLOR); exportData("DownloadBarColor", DOWNLOAD_BAR_COLOR); exportData("UploadBarColor", UPLOAD_BAR_COLOR); exportData("TextGeneralBackColor", TEXT_GENERAL_BACK_COLOR); exportData("TextGeneralForeColor", TEXT_GENERAL_FORE_COLOR); exportData("TextGeneralBold", TEXT_GENERAL_BOLD); exportData("TextGeneralItalic", TEXT_GENERAL_ITALIC); exportData("TextMyOwnBackColor", TEXT_MYOWN_BACK_COLOR); exportData("TextMyOwnForeColor", TEXT_MYOWN_FORE_COLOR); exportData("TextMyOwnBold", TEXT_MYOWN_BOLD); exportData("TextMyOwnItalic", TEXT_MYOWN_ITALIC); exportData("TextPrivateBackColor", TEXT_PRIVATE_BACK_COLOR); exportData("TextPrivateForeColor", TEXT_PRIVATE_FORE_COLOR); exportData("TextPrivateBold", TEXT_PRIVATE_BOLD); exportData("TextPrivateItalic", TEXT_PRIVATE_ITALIC); exportData("TextSystemBackColor", TEXT_SYSTEM_BACK_COLOR); exportData("TextSystemForeColor", TEXT_SYSTEM_FORE_COLOR); exportData("TextSystemBold", TEXT_SYSTEM_BOLD); exportData("TextSystemItalic", TEXT_SYSTEM_ITALIC); exportData("TextServerBackColor", TEXT_SERVER_BACK_COLOR); exportData("TextServerForeColor", TEXT_SERVER_FORE_COLOR); exportData("TextServerBold", TEXT_SERVER_BOLD); exportData("TextServerItalic", TEXT_SERVER_ITALIC); exportData("TextTimestampBackColor", TEXT_TIMESTAMP_BACK_COLOR); exportData("TextTimestampForeColor", TEXT_TIMESTAMP_FORE_COLOR); exportData("TextTimestampBold", TEXT_TIMESTAMP_BOLD); exportData("TextTimestampItalic", TEXT_TIMESTAMP_ITALIC); exportData("TextMyNickBackColor", TEXT_MYNICK_BACK_COLOR); exportData("TextMyNickForeColor", TEXT_MYNICK_FORE_COLOR); exportData("TextMyNickBold", TEXT_MYNICK_BOLD); exportData("TextMyNickItalic", TEXT_MYNICK_ITALIC); exportData("TextFavBackColor", TEXT_FAV_BACK_COLOR); exportData("TextFavForeColor", TEXT_FAV_FORE_COLOR); exportData("TextFavBold", TEXT_FAV_BOLD); exportData("TextFavItalic", TEXT_FAV_ITALIC); exportData("TextURLBackColor", TEXT_URL_BACK_COLOR); exportData("TextURLForeColor", TEXT_URL_FORE_COLOR); exportData("TextURLBold", TEXT_URL_BOLD); exportData("TextURLItalic", TEXT_URL_ITALIC); exportData("BoldAuthorsMess", BOLD_AUTHOR_MESS); exportData("ProgressTextDown", PROGRESS_TEXT_COLOR_DOWN); exportData("ProgressTextUp", PROGRESS_TEXT_COLOR_UP); exportData("ErrorColor", ERROR_COLOR); exportData("ProgressOverrideColors", PROGRESS_OVERRIDE_COLORS); exportData("MenubarTwoColors", MENUBAR_TWO_COLORS); exportData("MenubarLeftColor", MENUBAR_LEFT_COLOR); exportData("MenubarRightColor", MENUBAR_RIGHT_COLOR); exportData("MenubarBumped", MENUBAR_BUMPED); exportData("Progress3DDepth", PROGRESS_3DDEPTH); exportData("ProgressOverrideColors2", PROGRESS_OVERRIDE_COLORS2); exportData("TextOPBackColor", TEXT_OP_BACK_COLOR); exportData("TextOPForeColor", TEXT_OP_FORE_COLOR); exportData("TextOPBold", TEXT_OP_BOLD); exportData("TextOPItalic", TEXT_OP_ITALIC); exportData("SearchAlternateColour", SEARCH_ALTERNATE_COLOUR); exportData("ProgressBackColor", PROGRESS_BACK_COLOR); exportData("ProgressCompressColor", PROGRESS_COMPRESS_COLOR); exportData("ProgressSegmentColor", PROGRESS_SEGMENT_COLOR); exportData("ColorDone", COLOR_DONE); exportData("ColorDownloaded", COLOR_DOWNLOADED); exportData("ColorRunning", COLOR_RUNNING); exportData("IgnoredColor", IGNORED_COLOR); exportData("FavoriteColor", FAVORITE_COLOR); exportData("NormalColour", NORMAL_COLOUR); exportData("PasiveColor", PASIVE_COLOR); exportData("OpColor", OP_COLOR); exportData("ProgressbaroDCStyle", PROGRESSBAR_ODC_STYLE); try { File ff(Text::fromT(x) , File::WRITE, File::CREATE | File::TRUNCATE); BufferedOutputStream<false> f(&ff); f.write(SimpleXML::utf8Header); xml.toXML(&f); f.flush(); ff.close(); } catch(const FileException&) { // ... } } return 0; }