/* * Copyright (C) 2001-2008 Jacek Sieka, arnetheduck on gmail point com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "stdinc.h" #include "DCPlusPlus.h" #include "SettingsManager.h" #include "SimpleXML.h" #include "Util.h" #include "File.h" #include "version.h" #include "CID.h" namespace dcpp { StringList SettingsManager::connectionSpeeds; const string SettingsManager::settingTags[] = { // Strings "Nick", "UploadSpeed", "Description", "DownloadDirectory", "EMail", "ExternalIp", "Font", "ConnectionsOrder", "ConnectionsWidths", "HubFrameOrder", "HubFrameWidths", "SearchFrameOrder", "SearchFrameWidths", "FavHubsFrameOrder", "FavHubsFrameWidths", "HublistServers", "QueueFrameOrder", "QueueFrameWidths", "PublicHubsFrameOrder", "PublicHubsFrameWidths", "UsersFrameOrder", "UsersFrameWidths", "HttpProxy", "LogDirectory", "LogFormatPostDownload", "LogFormatPostUpload", "LogFormatMainChat", "LogFormatPrivateChat", "FinishedOrder", "FinishedWidths", "TempDownloadDirectory", "BindAddress", "SocksServer", "SocksUser", "SocksPassword", "ConfigVersion", "DefaultAwayMessage", "TimeStampsFormat", "ADLSearchFrameOrder", "ADLSearchFrameWidths", "FinishedULWidths", "FinishedULOrder", "CID", "SpyFrameWidths", "SpyFrameOrder", "LogFileMainChat", "LogFilePrivateChat", "LogFileStatus", "LogFileUpload", "LogFileDownload", "LogFileSystem", "LogFormatSystem", "LogFormatStatus", "DirectoryListingFrameOrder", "DirectoryListingFrameWidths", "TLSPrivateKeyFile", "TLSCertificateFile", "TLSTrustedCertificatesPath", "BeepFile", "Language", "DownloadsOrder", "DownloadsWidth", "SENTRY", // Ints "IncomingConnections", "InPort", "Slots", "AutoFollow", "ClearSearch", "BackgroundColor", "TextColor", "UseOemMonoFont", "ShareHidden", "FilterMessages", "MinimizeToTray", "AutoSearch", "TimeStamps", "ConfirmExit", "PopupHubPms", "PopupBotPms", "IgnoreHubPms", "IgnoreBotPms", "ListDuplicates", "BufferSize", "DownloadSlots", "MaxDownloadSpeed", "LogMainChat", "LogPrivateChat", "LogDownloads", "LogUploads", "StatusInChat", "ShowJoins", "PrivateMessageBeep", "PrivateMessageBeepOpen", "UseSystemIcons", "PopupPMs", "MinUploadSpeed", "GetUserInfo", "UrlHandler", "MainWindowState", "MainWindowSizeX", "MainWindowSizeY", "MainWindowPosX", "MainWindowPosY", "AutoAway", "SocksPort", "SocksResolve", "KeepLists", "AutoKick", "QueueFrameShowTree", "CompressTransfers", "ShowProgressBars", "SFVCheck", "MaxCompression", "AntiFrag", "NoAwayMsgToBots", "SkipZeroByte", "AdlsBreakOnFirst", "HubUserCommands", "AutoSearchAutoMatch", "DownloadBarColor", "UploadBarColor", "LogSystem", "LogFilelistTransfers", "SendUnknownCommands", "MaxHashSpeed", "OpenUserCmdHelp", "GetUserCountry", "FavShowJoins", "LogStatusMessages", "ShowStatusbar", "ShowToolbar", "ShowTransferview", "PopunderPm", "PopunderFilelist", "MagnetAsk", "MagnetAction", "MagnetRegister", "AddFinishedInstantly", "DontDLAlreadyShared", "UseCTRLForLineHistory", "ConfirmHubRemoval", "OpenNewWindow", "UDPPort", "ShowLastLinesLog", "ConfirmItemRemoval", "AdcDebug", "ToggleActiveWindow", "SearchHistory", "SetMinislotSize", "MaxFilelistSize", "HighestPrioSize", "HighPrioSize", "NormalPrioSize", "LowPrioSize", "LowestPrio", "AutoDropSpeed", "AutoDropInterval", "AutoDropElapsed", "AutoDropInactivity", "AutoDropMinSources", "AutoDropFilesize", "AutoDropAll", "AutoDropFilelists", "AutoDropDisconnect", "OpenPublic", "OpenFavoriteHubs", "OpenFavoriteUsers", "OpenQueue", "OpenFinishedDownloads", "OpenFinishedUploads", "OpenSearchSpy", "OpenNetworkStatistics", "OpenNotepad", "OutgoingConnections", "NoIpOverride", "SearchOnlyFreeSlots", "LastSearchType", "BoldFinishedDownloads", "BoldFinishedUploads", "BoldQueue", "BoldHub", "BoldPm", "BoldSearch", "SocketInBuffer", "SocketOutBuffer", "OpenWaitingUsers", "BoldWaitingUsers", "OpenSystemLog", "BoldSystemLog", "AutoRefreshTime", "UseTLS", "AutoSearchLimit", "AltSortOrder", "AutoKickNoFavs", "PromptPassword", "SpyFrameIgnoreTthSearches", "DontDlAlreadyQueued", "MaxCommandLength", "AllowUntrustedHubs", "AllowUntrustedClients", "TLSPort", "FastHash", "SortFavUsersFirst", "ShowShellMenu", "MinSegmentSize", "FollowLinks", "SendBloom", "OwnerDrawnMenus", "Coral", "SENTRY", // Int64 "TotalUpload", "TotalDownload", "SENTRY" }; SettingsManager::SettingsManager() { connectionSpeeds.push_back("0.005"); connectionSpeeds.push_back("0.01"); connectionSpeeds.push_back("0.02"); connectionSpeeds.push_back("0.05"); connectionSpeeds.push_back("0.1"); connectionSpeeds.push_back("0.2"); connectionSpeeds.push_back("0.5"); connectionSpeeds.push_back("1"); connectionSpeeds.push_back("2"); connectionSpeeds.push_back("5"); connectionSpeeds.push_back("10"); connectionSpeeds.push_back("20"); connectionSpeeds.push_back("50"); connectionSpeeds.push_back("100"); for(int i=0; i 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 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 f(&out); f.write(SimpleXML::utf8Header); xml.toXML(&f); f.flush(); out.close(); File::deleteFile(aFileName); File::renameFile(aFileName + ".tmp", aFileName); } catch(const FileException&) { // ... } } } // namespace dcpp