void SettingsManager::load(string const& aFileName, bool main) { try { SimpleXML xml; xml.fromXML(File(aFileName, File::READ, File::OPEN).read()); xml.resetCurrentChild(); xml.stepIn(); if(xml.findChild("Settings")) { xml.stepIn(); for(int i=STR_FIRST; i<STR_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find(SENTRY) == string::npos); if(xml.findChild(attr)) set(StrSetting(i), xml.getChildData()); xml.resetCurrentChild(); } for(int i=INT_FIRST+1; i<INT_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find(SENTRY) == string::npos); if(xml.findChild(attr)) set(IntSetting(i), Util::toInt(xml.getChildData())); xml.resetCurrentChild(); } for(int i=INT64_FIRST; i<INT64_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find(SENTRY) == string::npos); if(xml.findChild(attr)) set(Int64Setting(i), Util::toInt64(xml.getChildData())); xml.resetCurrentChild(); } xml.stepOut(); } if (main) { double v = Util::toDouble(SETTING(CONFIG_VERSION)); // if(v < 0.x) { // Fix old settings here } if(v <= 0.674 || SETTING(PRIVATE_ID).length() != 39 || CID(SETTING(PRIVATE_ID)).isZero()) { set(PRIVATE_ID, CID::generate().toBase32()); // Formats changed, might as well remove these... set(LOG_FORMAT_POST_DOWNLOAD, Util::emptyString); set(LOG_FORMAT_POST_UPLOAD, Util::emptyString); set(LOG_FORMAT_MAIN_CHAT, Util::emptyString); set(LOG_FORMAT_PRIVATE_CHAT, Util::emptyString); set(LOG_FORMAT_STATUS, Util::emptyString); set(LOG_FORMAT_SYSTEM, Util::emptyString); set(LOG_FILE_MAIN_CHAT, Util::emptyString); set(LOG_FILE_STATUS, Util::emptyString); set(LOG_FILE_PRIVATE_CHAT, Util::emptyString); set(LOG_FILE_UPLOAD, Util::emptyString); set(LOG_FILE_DOWNLOAD, Util::emptyString); set(LOG_FILE_SYSTEM, Util::emptyString); } if(v <= 16) { set(HUBLIST_SERVERS, Util::emptyString); } #ifdef _DEBUG set(PRIVATE_ID, CID::generate().toBase32()); #endif setDefault(UDP_PORT, SETTING(TCP_PORT)); #ifdef PPA_INCLUDE_SSL File::ensureDirectory(SETTING(TLS_TRUSTED_CERTIFICATES_PATH)); #endif fire(SettingsManagerListener::Load(), xml); } xml.stepOut(); } catch(const Exception&) { if (main) { if(CID(SETTING(PRIVATE_ID)).isZero()) set(PRIVATE_ID, CID::generate().toBase32()); } } if (main) { if(SETTING(TCP_PORT) == 0) { set(TCP_PORT, (int)Util::rand(1025, 8000)); } if(SETTING(UDP_PORT) == 0) { set(UDP_PORT, (int)Util::rand(1025, 8000)); } if(SETTING(TLS_PORT) == 0) { set(TLS_PORT, (int)Util::rand(1025, 32000)); } } }
void SettingsManager::load(string const& aFileName) { try { SimpleXML xml; xml.fromXML(File(aFileName, File::READ, File::OPEN).read()); xml.resetCurrentChild(); xml.stepIn(); if(xml.findChild("Settings")) { xml.stepIn(); int i; for(i=STR_FIRST; i<STR_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find("SENTRY") == string::npos); if(xml.findChild(attr)) set(StrSetting(i), xml.getChildData()); xml.resetCurrentChild(); } for(i=INT_FIRST; i<INT_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find("SENTRY") == string::npos); if(xml.findChild(attr)) set(IntSetting(i), Util::toInt(xml.getChildData())); xml.resetCurrentChild(); } for(i=INT64_FIRST; i<INT64_LAST; i++) { const string& attr = settingTags[i]; dcassert(attr.find("SENTRY") == string::npos); if(xml.findChild(attr)) set(Int64Setting(i), Util::toInt64(xml.getChildData())); xml.resetCurrentChild(); } xml.stepOut(); } double v = Util::toDouble(SETTING(CONFIG_VERSION)); // if(v < 0.x) { // Fix old settings here } if(v <= 0.674 || SETTING(PRIVATE_ID).length() != 39 || CID(SETTING(PRIVATE_ID)).isZero()) { set(PRIVATE_ID, CID::generate().toBase32()); // Formats changed, might as well remove these... set(LOG_FORMAT_POST_DOWNLOAD, Util::emptyString); set(LOG_FORMAT_POST_UPLOAD, Util::emptyString); set(LOG_FORMAT_MAIN_CHAT, Util::emptyString); set(LOG_FORMAT_PRIVATE_CHAT, Util::emptyString); set(LOG_FORMAT_STATUS, Util::emptyString); set(LOG_FORMAT_SYSTEM, Util::emptyString); set(LOG_FILE_MAIN_CHAT, Util::emptyString); set(LOG_FILE_STATUS, Util::emptyString); set(LOG_FILE_PRIVATE_CHAT, Util::emptyString); set(LOG_FILE_UPLOAD, Util::emptyString); set(LOG_FILE_DOWNLOAD, Util::emptyString); set(LOG_FILE_SYSTEM, Util::emptyString); } if(SETTING(SET_MINISLOT_SIZE) < 64) set(SET_MINISLOT_SIZE, 64); if(SETTING(AUTODROP_INTERVAL) < 1) set(AUTODROP_INTERVAL, 1); if(SETTING(AUTODROP_ELAPSED) < 1) set(AUTODROP_ELAPSED, 1); if(SETTING(AUTO_SEARCH_LIMIT) > 5) set(AUTO_SEARCH_LIMIT, 5); else if(SETTING(AUTO_SEARCH_LIMIT) < 1) set(AUTO_SEARCH_LIMIT, 1); #ifdef _DEBUG set(PRIVATE_ID, CID::generate().toBase32()); #endif setDefault(UDP_PORT, SETTING(TCP_PORT)); File::ensureDirectory(SETTING(TLS_TRUSTED_CERTIFICATES_PATH)); fire(SettingsManagerListener::Load(), xml); xml.stepOut(); } catch(const Exception&) { if(CID(SETTING(PRIVATE_ID)).isZero()) set(PRIVATE_ID, CID::generate().toBase32()); } }
void ADLSearchManager::load() { // Clear current collection.clear(); // Load file as a string try { SimpleXML xml; Util::migrate(getConfigFile()); xml.fromXML(File(getConfigFile(), File::READ, File::OPEN).read()); if(xml.findChild("ADLSearch")) { xml.stepIn(); // Predicted several groups of searches to be differentiated // in multiple categories. Not implemented yet. if(xml.findChild("SearchGroup")) { xml.stepIn(); // Loop until no more searches found while(xml.findChild("Search")) { xml.stepIn(); // Found another search, load it ADLSearch search; if(xml.findChild("SearchString")) { search.searchString = xml.getChildData(); } if(xml.findChild("SourceType")) { search.sourceType = search.StringToSourceType(xml.getChildData()); } if(xml.findChild("DestDirectory")) { search.destDir = xml.getChildData(); } if(xml.findChild("IsActive")) { search.isActive = (Util::toInt(xml.getChildData()) != 0); } if(xml.findChild("MaxSize")) { search.maxFileSize = Util::toInt64(xml.getChildData()); } if(xml.findChild("MinSize")) { search.minFileSize = Util::toInt64(xml.getChildData()); } if(xml.findChild("SizeType")) { search.typeFileSize = search.StringToSizeType(xml.getChildData()); } if(xml.findChild("IsAutoQueue")) { search.isAutoQueue = (Util::toInt(xml.getChildData()) != 0); } // Add search to collection if(!search.searchString.empty()) { collection.push_back(search); } // Go to next search xml.stepOut(); } } } } catch(const SimpleXMLException&) { } catch(const FileException&) { } }
void UpdateManager::completeVersionDownload(bool manualCheck) { auto& conn = conns[CONN_VERSION]; if(!conn) { return; } ScopedFunctor([&conn] { conn.reset(); }); if (conn->buf.empty()) { failVersionDownload(STRING_F(DOWNLOAD_VERSION_FAILED, conn->status), manualCheck); return; } bool verified = !versionSig.empty() && UpdateManager::verifyVersionData(conn->buf, versionSig); if(!verified) { failVersionDownload(STRING(VERSION_VERIFY_FAILED), manualCheck); } try { SimpleXML xml; xml.fromXML(conn->buf); xml.stepIn(); //Check for updated HTTP links if(xml.findChild("Links")) { xml.stepIn(); if(xml.findChild("Homepage")) { links.homepage = xml.getChildData(); } xml.resetCurrentChild(); if(xml.findChild("Downloads")) { links.downloads = xml.getChildData(); } xml.resetCurrentChild(); if(xml.findChild("GeoIPv6")) { links.geoip6 = xml.getChildData(); } xml.resetCurrentChild(); if(xml.findChild("GeoIPv4")) { links.geoip4 = xml.getChildData(); } xml.resetCurrentChild(); if(xml.findChild("Customize")) { links.customize = xml.getChildData(); } xml.resetCurrentChild(); if(xml.findChild("Forum")) { links.discuss = xml.getChildData(); } xml.resetCurrentChild(); if(xml.findChild("Languages")) { links.language = xml.getChildData(); } xml.resetCurrentChild(); if(xml.findChild("Guides")) { links.guides = xml.getChildData(); } xml.resetCurrentChild(); if(xml.findChild("IPCheck")) { links.ipcheck4 = xml.getChildData(); } xml.resetCurrentChild(); if(xml.findChild("IPCheck6")) { links.ipcheck6 = xml.getChildData(); } xml.stepOut(); } xml.resetCurrentChild(); updater->onVersionDownloaded(xml, verified, manualCheck); } catch (const Exception& e) { failVersionDownload(STRING_F(VERSION_PARSING_FAILED, e.getError()), manualCheck); } checkAdditionalUpdates(manualCheck); }
/////////////////////////////////////////////////////////////////////////////// // // 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; } }
/////////////////////////////////////////////////////////////////////////////// // // Load old searches from disk // /////////////////////////////////////////////////////////////////////////////// void ADLSearchManager::Load() { // Clear current collection.clear(); // Load file as a string try { SimpleXML xml; Util::migrate(getConfigFile()); xml.fromXML(File(getConfigFile(), File::READ, File::OPEN).read()); if(xml.findChild("ADLSearch")) { xml.stepIn(); // Predicted several groups of searches to be differentiated // in multiple categories. Not implemented yet. if(xml.findChild("SearchGroup")) { xml.stepIn(); // Loop until no more searches found while(xml.findChild("Search")) { xml.stepIn(); // Found another search, load it ADLSearch search; if(xml.findChild("SearchString")) { search.searchString = xml.getChildData(); } if(xml.findChild("SourceType")) { search.sourceType = search.StringToSourceType(xml.getChildData()); } if(xml.findChild("DestDirectory")) { search.destDir = xml.getChildData(); } if(xml.findChild("IsActive")) { search.isActive = (Util::toInt(xml.getChildData()) != 0); } if(xml.findChild("IsForbidden")) { search.isForbidden = (Util::toInt(xml.getChildData()) != 0); } //RSX++ if(xml.findChild("OverRidePoints")) { search.overRidePoints = (Util::toInt(xml.getChildData()) != 0); } if(xml.findChild("AdlsRaw")) { search.adlsRaw = RawManager::getInstance()->getValidAction(Util::toInt(xml.getChildData())); } if(xml.findChild("KickString")) { search.kickString = xml.getChildData(); } if(xml.findChild("FromFavs")) { search.fromFavs = (Util::toInt(xml.getChildData()) != 0); } if(xml.findChild("AdlsPoints")) { search.adlsPoints = Util::toInt(xml.getChildData()); } //END if(xml.findChild("MaxSize")) { search.maxFileSize = Util::toInt64(xml.getChildData()); } if(xml.findChild("MinSize")) { search.minFileSize = Util::toInt64(xml.getChildData()); } if(xml.findChild("SizeType")) { search.typeFileSize = search.StringToSizeType(xml.getChildData()); } if(xml.findChild("IsAutoQueue")) { search.isAutoQueue = (Util::toInt(xml.getChildData()) != 0); } //RSX++ if(xml.findChild("AdlsComment")) { search.adlsComment = xml.getChildData(); } if(xml.findChild("IsCaseSensitive")) { search.isCaseSensitive = (Util::toInt(xml.getChildData()) != 0); } //END // Add search to collection if(search.searchString.size() > 0) { collection.push_back(search); } // Go to next search xml.stepOut(); } } } } catch(const SimpleXMLException&) { return; } catch(const FileException&) { return; } }
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&) { // ... } }
LRESULT PropPageTextStyles::onImport(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { tstring x = _T(""); if(WinUtil::browseFile(x, m_hWnd, false, x, types, defExt) == IDOK) { SimpleXML xml; xml.fromXML(File(Text::fromT(x), File::READ, File::OPEN).read()); xml.resetCurrentChild(); xml.stepIn(); if(xml.findChild(("Settings"))) { xml.stepIn(); importData("Font", TEXT_FONT); importData("BackgroundColor", BACKGROUND_COLOR); importData("TextColor", TEXT_COLOR); importData("DownloadBarColor", DOWNLOAD_BAR_COLOR); importData("UploadBarColor", UPLOAD_BAR_COLOR); importData("TextGeneralBackColor", TEXT_GENERAL_BACK_COLOR); importData("TextGeneralForeColor", TEXT_GENERAL_FORE_COLOR); importData("TextGeneralBold", TEXT_GENERAL_BOLD); importData("TextGeneralItalic", TEXT_GENERAL_ITALIC); importData("TextMyOwnBackColor", TEXT_MYOWN_BACK_COLOR); importData("TextMyOwnForeColor", TEXT_MYOWN_FORE_COLOR); importData("TextMyOwnBold", TEXT_MYOWN_BOLD); importData("TextMyOwnItalic", TEXT_MYOWN_ITALIC); importData("TextPrivateBackColor", TEXT_PRIVATE_BACK_COLOR); importData("TextPrivateForeColor", TEXT_PRIVATE_FORE_COLOR); importData("TextPrivateBold", TEXT_PRIVATE_BOLD); importData("TextPrivateItalic", TEXT_PRIVATE_ITALIC); importData("TextSystemBackColor", TEXT_SYSTEM_BACK_COLOR); importData("TextSystemForeColor", TEXT_SYSTEM_FORE_COLOR); importData("TextSystemBold", TEXT_SYSTEM_BOLD); importData("TextSystemItalic", TEXT_SYSTEM_ITALIC); importData("TextServerBackColor", TEXT_SERVER_BACK_COLOR); importData("TextServerForeColor", TEXT_SERVER_FORE_COLOR); importData("TextServerBold", TEXT_SERVER_BOLD); importData("TextServerItalic", TEXT_SERVER_ITALIC); importData("TextTimestampBackColor", TEXT_TIMESTAMP_BACK_COLOR); importData("TextTimestampForeColor", TEXT_TIMESTAMP_FORE_COLOR); importData("TextTimestampBold", TEXT_TIMESTAMP_BOLD); importData("TextTimestampItalic", TEXT_TIMESTAMP_ITALIC); importData("TextMyNickBackColor", TEXT_MYNICK_BACK_COLOR); importData("TextMyNickForeColor", TEXT_MYNICK_FORE_COLOR); importData("TextMyNickBold", TEXT_MYNICK_BOLD); importData("TextMyNickItalic", TEXT_MYNICK_ITALIC); importData("TextFavBackColor", TEXT_FAV_BACK_COLOR); importData("TextFavForeColor", TEXT_FAV_FORE_COLOR); importData("TextFavBold", TEXT_FAV_BOLD); importData("TextFavItalic", TEXT_FAV_ITALIC); importData("TextURLBackColor", TEXT_URL_BACK_COLOR); importData("TextURLForeColor", TEXT_URL_FORE_COLOR); importData("TextURLBold", TEXT_URL_BOLD); importData("TextURLItalic", TEXT_URL_ITALIC); importData("BoldAuthorsMess", BOLD_AUTHOR_MESS); importData("ProgressTextDown", PROGRESS_TEXT_COLOR_DOWN); importData("ProgressTextUp", PROGRESS_TEXT_COLOR_UP); importData("ErrorColor", ERROR_COLOR); importData("ProgressOverrideColors", PROGRESS_OVERRIDE_COLORS); importData("MenubarTwoColors", MENUBAR_TWO_COLORS); importData("MenubarLeftColor", MENUBAR_LEFT_COLOR); importData("MenubarRightColor", MENUBAR_RIGHT_COLOR); importData("MenubarBumped", MENUBAR_BUMPED); importData("Progress3DDepth", PROGRESS_3DDEPTH); importData("ProgressOverrideColors2", PROGRESS_OVERRIDE_COLORS2); importData("TextOPBackColor", TEXT_OP_BACK_COLOR); importData("TextOPForeColor", TEXT_OP_FORE_COLOR); importData("TextOPBold", TEXT_OP_BOLD); importData("TextOPItalic", TEXT_OP_ITALIC); importData("SearchAlternateColour", SEARCH_ALTERNATE_COLOUR); importData("ProgressBackColor", PROGRESS_BACK_COLOR); importData("ProgressCompressColor", PROGRESS_COMPRESS_COLOR); importData("ProgressSegmentColor", PROGRESS_SEGMENT_COLOR); importData("ColorDone", COLOR_DONE); importData("ColorDownloaded", COLOR_DOWNLOADED); importData("ColorRunning", COLOR_RUNNING); importData("IgnoredColor", IGNORED_COLOR); importData("FavoriteColor", FAVORITE_COLOR); importData("NormalColour", NORMAL_COLOUR); importData("PasiveColor", PASIVE_COLOR); importData("OpColor", OP_COLOR); importData("ProgressbaroDCStyle", PROGRESSBAR_ODC_STYLE); importData("ProgressbaroDCStyle", PROGRESSBAR_ODC_STYLE); } xml.resetCurrentChild(); xml.stepOut(); } SendMessage(WM_DESTROY,0,0); //SettingsManager::getInstance()->save(); PropertiesDlg::needUpdate = true; SendMessage(WM_INITDIALOG,0,0); // RefreshPreview(); return 0; }