Upstream tarball 9435
[amule.git] / src / Preferences.cpp
blob2c65a8b911a2450df9a6041494d20340bfadbf56
2 //
3 // This file is part of the aMule Project.
4 //
5 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
7 //
8 // Any parts of this program derived from the xMule, lMule or eMule project,
9 // or contributed by third-party developers are copyrighted by their
10 // respective authors.
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include <wx/wx.h>
28 #include "Preferences.h"
30 #include <protocol/ed2k/Constants.h>
31 #include <common/Constants.h>
32 #include <common/DataFileVersion.h>
34 #include <wx/config.h>
35 #include <wx/dir.h>
36 #include <wx/stdpaths.h>
37 #include <wx/stopwatch.h>
38 #include <wx/tokenzr.h>
40 #include "amule.h"
41 #ifdef HAVE_CONFIG_H
42 #include "config.h" // Needed for PACKAGE_STRING
43 #endif
45 #include "CFile.h"
46 #include <common/MD5Sum.h>
47 #include "Logger.h"
48 #include <common/Format.h> // Needed for CFormat
49 #include <common/TextFile.h> // Needed for CTextFile
50 #include <common/ClientVersion.h>
52 #include "UserEvents.h"
54 #ifndef AMULE_DAEMON
55 #include <wx/valgen.h>
56 #include "muuli_wdr.h"
57 #include "StatisticsDlg.h"
58 #include "MuleColour.h"
59 #endif
61 #include "RandomFunctions.h"
62 #ifndef CLIENT_GUI
63 #include "PlatformSpecific.h" // Needed for PlatformSpecific::GetMaxConnections()
64 #endif
66 #define DEFAULT_TCP_PORT 4662
67 #define DEFAULT_UDP_PORT 4672
69 // Static variables
70 unsigned long CPreferences::s_colors[cntStatColors];
71 unsigned long CPreferences::s_colors_ref[cntStatColors];
73 CPreferences::CFGMap CPreferences::s_CfgList;
74 CPreferences::CFGList CPreferences::s_MiscList;
77 /* Proxy */
78 CProxyData CPreferences::s_ProxyData;
80 /* The rest, organize it! */
81 wxString CPreferences::s_nick;
82 uint16 CPreferences::s_maxupload;
83 uint16 CPreferences::s_maxdownload;
84 uint16 CPreferences::s_slotallocation;
85 wxString CPreferences::s_Addr;
86 uint16 CPreferences::s_port;
87 uint16 CPreferences::s_udpport;
88 bool CPreferences::s_UDPEnable;
89 uint16 CPreferences::s_maxconnections;
90 bool CPreferences::s_reconnect;
91 bool CPreferences::s_autoconnect;
92 bool CPreferences::s_autoconnectstaticonly;
93 bool CPreferences::s_UPnPEnabled;
94 bool CPreferences::s_UPnPECEnabled;
95 bool CPreferences::s_UPnPWebServerEnabled;
96 uint16 CPreferences::s_UPnPTCPPort;
97 bool CPreferences::s_autoserverlist;
98 bool CPreferences::s_deadserver;
99 CPath CPreferences::s_incomingdir;
100 CPath CPreferences::s_tempdir;
101 bool CPreferences::s_ICH;
102 uint8 CPreferences::s_depth3D;
103 bool CPreferences::s_scorsystem;
104 bool CPreferences::s_mintotray;
105 bool CPreferences::s_trayiconenabled;
106 bool CPreferences::s_addnewfilespaused;
107 bool CPreferences::s_addserversfromserver;
108 bool CPreferences::s_addserversfromclient;
109 uint16 CPreferences::s_maxsourceperfile;
110 uint16 CPreferences::s_trafficOMeterInterval;
111 uint16 CPreferences::s_statsInterval;
112 uint32 CPreferences::s_maxGraphDownloadRate;
113 uint32 CPreferences::s_maxGraphUploadRate;
114 bool CPreferences::s_confirmExit;
115 bool CPreferences::s_filterLanIP;
116 bool CPreferences::s_paranoidfilter;
117 bool CPreferences::s_IPFilterSys;
118 bool CPreferences::s_onlineSig;
119 uint16 CPreferences::s_OSUpdate;
120 uint64 CPreferences::s_totalDownloadedBytes;
121 uint64 CPreferences::s_totalUploadedBytes;
122 wxString CPreferences::s_languageID;
123 uint8 CPreferences::s_iSeeShares;
124 uint8 CPreferences::s_iToolDelayTime;
125 uint8 CPreferences::s_splitterbarPosition;
126 uint16 CPreferences::s_deadserverretries;
127 uint32 CPreferences::s_dwServerKeepAliveTimeoutMins;
128 uint8 CPreferences::s_statsMax;
129 uint8 CPreferences::s_statsAverageMinutes;
130 bool CPreferences::s_bpreviewprio;
131 bool CPreferences::s_smartidcheck;
132 uint8 CPreferences::s_smartidstate;
133 bool CPreferences::s_safeServerConnect;
134 bool CPreferences::s_startMinimized;
135 uint16 CPreferences::s_MaxConperFive;
136 bool CPreferences::s_checkDiskspace;
137 uint32 CPreferences::s_uMinFreeDiskSpace;
138 wxString CPreferences::s_yourHostname;
139 bool CPreferences::s_bVerbose;
140 bool CPreferences::s_bmanualhighprio;
141 bool CPreferences::s_btransferfullchunks;
142 bool CPreferences::s_bstartnextfile;
143 bool CPreferences::s_bstartnextfilesame;
144 bool CPreferences::s_bshowoverhead;
145 bool CPreferences::s_bDAP;
146 bool CPreferences::s_bUAP;
147 uint8_t CPreferences::s_showRatesOnTitle;
148 wxString CPreferences::s_VideoPlayer;
149 bool CPreferences::s_moviePreviewBackup;
150 bool CPreferences::s_showAllNotCats;
151 bool CPreferences::s_msgonlyfriends;
152 bool CPreferences::s_msgsecure;
153 uint8 CPreferences::s_filterlevel;
154 uint8 CPreferences::s_iFileBufferSize;
155 uint8 CPreferences::s_iQueueSize;
156 wxString CPreferences::s_datetimeformat;
157 wxString CPreferences::s_sWebPassword;
158 wxString CPreferences::s_sWebLowPassword;
159 uint16 CPreferences::s_nWebPort;
160 uint16 CPreferences::s_nWebUPnPTCPPort;
161 bool CPreferences::s_bWebEnabled;
162 bool CPreferences::s_bWebUseGzip;
163 uint32 CPreferences::s_nWebPageRefresh;
164 bool CPreferences::s_bWebLowEnabled;
165 wxString CPreferences::s_WebTemplate;
166 bool CPreferences::s_showCatTabInfos;
167 uint32 CPreferences::s_allcatType;
168 uint8 CPreferences::s_NoNeededSources;
169 bool CPreferences::s_DropFullQueueSources;
170 bool CPreferences::s_DropHighQueueRankingSources;
171 uint32 CPreferences::s_HighQueueRanking;
172 uint32 CPreferences::s_AutoDropTimer;
173 bool CPreferences::s_AcceptExternalConnections;
174 wxString CPreferences::s_ECAddr;
175 uint32 CPreferences::s_ECPort;
176 wxString CPreferences::s_ECPassword;
177 bool CPreferences::s_IPFilterClients;
178 bool CPreferences::s_IPFilterServers;
179 bool CPreferences::s_UseSrcSeeds;
180 bool CPreferences::s_ProgBar;
181 bool CPreferences::s_Percent;
182 bool CPreferences::s_SecIdent;
183 bool CPreferences::s_ExtractMetaData;
184 bool CPreferences::s_allocFullFile;
185 wxString CPreferences::s_CustomBrowser;
186 bool CPreferences::s_BrowserTab;
187 CPath CPreferences::s_OSDirectory;
188 wxString CPreferences::s_Skin;
189 bool CPreferences::s_FastED2KLinksHandler;
190 bool CPreferences::s_ToolbarOrientation;
191 bool CPreferences::s_AICHTrustEveryHash;
192 wxString CPreferences::s_CommentFilterString;
193 bool CPreferences::s_IPFilterAutoLoad;
194 wxString CPreferences::s_IPFilterURL;
195 CMD4Hash CPreferences::s_userhash;
196 bool CPreferences::s_MustFilterMessages;
197 wxString CPreferences::s_MessageFilterString;
198 bool CPreferences::s_FilterAllMessages;
199 bool CPreferences::s_FilterComments;
200 bool CPreferences::s_FilterSomeMessages;
201 bool CPreferences::s_ShowMessagesInLog;
202 bool CPreferences::s_ShareHiddenFiles;
203 bool CPreferences::s_AutoSortDownload;
204 bool CPreferences::s_NewVersionCheck;
205 bool CPreferences::s_ConnectToKad;
206 bool CPreferences::s_ConnectToED2K;
207 unsigned CPreferences::s_maxClientVersions;
208 bool CPreferences::s_DropSlowSources;
209 bool CPreferences::s_IsClientCryptLayerSupported;
210 bool CPreferences::s_bCryptLayerRequested;
211 bool CPreferences::s_IsClientCryptLayerRequired;
212 uint32 CPreferences::s_dwKadUDPKey;
213 uint8 CPreferences::s_byCryptTCPPaddingLength;
215 wxString CPreferences::s_Ed2kURL;
216 wxString CPreferences::s_KadURL;
217 bool CPreferences::s_GeoIPEnabled;
218 wxString CPreferences::s_GeoIPUpdateUrl;
222 * Template Cfg class for connecting with widgets.
224 * This template provides the base functionionality needed to syncronize a
225 * variable with a widget. However, please note that wxGenericValidator only
226 * supports a few types (int, wxString, bool and wxArrayInt), so this template
227 * can't always be used directly.
229 * Cfg_Str and Cfg_Bool are able to use this template directly, whereas Cfg_Int
230 * makes use of serveral workaround to enable it to be used with integers other
231 * than int.
233 template <typename TYPE>
234 class Cfg_Tmpl : public Cfg_Base
236 public:
238 * Constructor.
240 * @param keyname
241 * @param value
242 * @param defaultVal
244 Cfg_Tmpl( const wxString& keyname, TYPE& value, const TYPE& defaultVal )
245 : Cfg_Base( keyname ),
246 m_value( value ),
247 m_default( defaultVal ),
248 m_widget( NULL )
251 #ifndef AMULE_DAEMON
253 * Connects the Cfg to a widget.
255 * @param id The ID of the widget to be connected.
256 * @param parent The parent of the widget. Use this to speed up searches.
258 * This function works by setting the wxValidator of the class. This however
259 * poses some restrictions on which variable types can be used for this
260 * template, as noted above. It also poses some limits on the widget types,
261 * refer to the wx documentation for those.
263 virtual bool ConnectToWidget( int id, wxWindow* parent = NULL )
265 if ( id ) {
266 m_widget = wxWindow::FindWindowById( id, parent );
268 if ( m_widget ) {
269 wxGenericValidator validator( &m_value );
271 m_widget->SetValidator( validator );
273 return true;
275 } else {
276 m_widget = NULL;
279 return false;
283 /** Updates the assosiated variable, returning true on success. */
284 virtual bool TransferFromWindow()
286 if ( m_widget ) {
287 wxValidator* validator = m_widget->GetValidator();
289 if ( validator ) {
290 TYPE temp = m_value;
292 if ( validator->TransferFromWindow() ) {
293 SetChanged( temp != m_value );
295 return true;
300 return false;
303 /** Updates the assosiated widget, returning true on success. */
304 virtual bool TransferToWindow()
306 if ( m_widget ) {
307 wxValidator* validator = m_widget->GetValidator();
309 if ( validator )
310 return validator->TransferToWindow();
313 return false;
316 #endif
318 /** Sets the default value. */
319 void SetDefault(const TYPE& defaultVal)
321 m_default = defaultVal;
324 protected:
325 //! Reference to the associated variable
326 TYPE& m_value;
328 //! Default variable value
329 TYPE m_default;
331 //! Pointer to the widget assigned to the Cfg instance
332 wxWindow* m_widget;
336 /** Cfg class for wxStrings. */
337 class Cfg_Str : public Cfg_Tmpl<wxString>
339 public:
340 /** Constructor. */
341 Cfg_Str( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
342 : Cfg_Tmpl<wxString>( keyname, value, defaultVal )
345 /** Loads the string, using the specified default value. */
346 virtual void LoadFromFile(wxConfigBase* cfg)
348 cfg->Read( GetKey(), &m_value, m_default );
352 /** Saves the string to the specified wxConfig object. */
353 virtual void SaveToFile(wxConfigBase* cfg)
355 cfg->Write( GetKey(), m_value );
361 * Cfg-class for encrypting strings, for example for passwords.
363 class Cfg_Str_Encrypted : public Cfg_Str
365 public:
366 Cfg_Str_Encrypted( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
367 : Cfg_Str( keyname, value, defaultVal )
370 #ifndef AMULE_DAEMON
371 virtual bool TransferFromWindow()
373 // Shakraw: when storing value, store it encrypted here (only if changed in prefs)
374 if ( Cfg_Str::TransferFromWindow() ) {
376 // Only recalucate the hash for new, non-empty passwords
377 if ( HasChanged() && !m_value.IsEmpty() ) {
378 m_value = MD5Sum( m_value ).GetHash();
381 return true;
385 return false;
387 #endif
391 /** Cfg class for CPath. */
392 class Cfg_Path : public Cfg_Str
394 public:
395 /** Constructor. */
396 Cfg_Path(const wxString& keyname, CPath& value, const wxString& defaultVal = wxEmptyString )
397 : Cfg_Str(keyname, m_temp_path, defaultVal)
398 , m_real_path(value)
401 /** @see Cfg_Str::LoadFromFile. */
402 virtual void LoadFromFile(wxConfigBase* cfg)
404 Cfg_Str::LoadFromFile(cfg);
406 m_real_path = CPath::FromUniv(m_temp_path);
410 /** @see Cfg_Str::SaveToFile. */
411 virtual void SaveToFile(wxConfigBase* cfg)
413 m_temp_path = CPath::ToUniv(m_real_path);
415 Cfg_Str::SaveToFile(cfg);
419 /** @see Cfg_Tmpl::TransferToWindow. */
420 virtual bool TransferToWindow()
422 m_temp_path = m_real_path.GetRaw();
424 return Cfg_Str::TransferToWindow();
427 /** @see Cfg_Tmpl::TransferFromWindow. */
428 virtual bool TransferFromWindow()
430 if (Cfg_Str::TransferFromWindow()) {
431 m_real_path = CPath(m_temp_path);
432 return true;
435 return false;
438 private:
439 wxString m_temp_path;
440 CPath& m_real_path;
445 * Cfg class that takes care of integer types.
447 * This template is needed since wxValidator only supports normals ints, and
448 * wxConfig for the matter only supports longs, thus some worksarounds are
449 * needed.
451 * There are two work-arounds:
452 * 1) wxValidator only supports int*, so we need a immediate variable to act
453 * as a storage. Thus we use Cfg_Tmpl<int> as base class. Thus this class
454 * contains a integer which we use to pass the value back and forth
455 * between the widgets.
457 * 2) wxConfig uses longs to save and read values, thus we need an immediate
458 * stage when loading and saving the value.
460 template <typename TYPE>
461 class Cfg_Int : public Cfg_Tmpl<int>
463 public:
464 Cfg_Int( const wxString& keyname, TYPE& value, int defaultVal = 0 )
465 : Cfg_Tmpl<int>( keyname, m_temp_value, defaultVal ),
466 m_real_value( value ),
467 m_temp_value( value )
471 virtual void LoadFromFile(wxConfigBase* cfg)
473 long tmp = 0;
474 cfg->Read( GetKey(), &tmp, m_default );
476 // Set the temp value
477 m_temp_value = (int)tmp;
478 // Set the actual value
479 m_real_value = (TYPE)tmp;
482 virtual void SaveToFile(wxConfigBase* cfg)
484 cfg->Write( GetKey(), (long)m_real_value );
488 #ifndef AMULE_DAEMON
489 virtual bool TransferFromWindow()
491 if ( Cfg_Tmpl<int>::TransferFromWindow() ) {
492 m_real_value = (TYPE)m_temp_value;
494 return true;
497 return false;
500 virtual bool TransferToWindow()
502 m_temp_value = (int)m_real_value;
504 if ( Cfg_Tmpl<int>::TransferToWindow() ) {
506 // In order to let us update labels on slider-changes, we trigger a event
507 wxSlider *slider = dynamic_cast<wxSlider *>(m_widget);
508 if (slider) {
509 int id = m_widget->GetId();
510 int pos = slider->GetValue();
511 wxScrollEvent evt( wxEVT_SCROLL_THUMBRELEASE, id, pos );
512 m_widget->ProcessEvent( evt );
515 return true;
518 return false;
520 #endif
522 protected:
524 TYPE& m_real_value;
525 int m_temp_value;
530 * Helper function for creating new Cfg_Ints.
532 * @param keyname The cfg-key under which the item should be saved.
533 * @param value The variable to syncronize. The type of this variable defines the type used to create the Cfg_Int.
534 * @param defaultVal The default value if the key isn't found when loading the value.
535 * @return A pointer to the new Cfg_Int object. The caller is responsible for deleting it.
537 * This template-function returns a Cfg_Int of the appropriate type for the
538 * variable used as argument and should be used to avoid having to specify
539 * the integer type when adding a new Cfg_Int, since that's just increases
540 * the maintainence burden.
542 template <class TYPE>
543 Cfg_Base* MkCfg_Int( const wxString& keyname, TYPE& value, int defaultVal )
545 return new Cfg_Int<TYPE>( keyname, value, defaultVal );
550 * Cfg-class for bools.
552 class Cfg_Bool : public Cfg_Tmpl<bool>
554 public:
555 Cfg_Bool( const wxString& keyname, bool& value, bool defaultVal )
556 : Cfg_Tmpl<bool>( keyname, value, defaultVal )
560 virtual void LoadFromFile(wxConfigBase* cfg)
562 cfg->Read( GetKey(), &m_value, m_default );
565 virtual void SaveToFile(wxConfigBase* cfg)
567 cfg->Write( GetKey(), m_value );
573 * Cfg-class for uint64s, with no associated widgets.
575 class Cfg_Counter : public Cfg_Base
577 public:
578 Cfg_Counter( const wxString& keyname, uint64& value )
579 : Cfg_Base( keyname ),
580 m_value( value )
583 virtual void LoadFromFile(wxConfigBase* cfg)
585 wxString buffer;
587 cfg->Read( GetKey(), &buffer, wxT("0") );
589 uint64 tmp = 0;
590 for (unsigned int i = 0; i < buffer.Length(); ++i) {
591 if ((buffer[i] >= wxChar('0')) &&(buffer[i] <= wxChar('9'))) {
592 tmp = tmp * 10 + (buffer[i] - wxChar('0'));
593 } else {
594 tmp = 0;
595 break;
598 m_value = tmp;
601 virtual void SaveToFile(wxConfigBase* cfg)
603 wxString str = CFormat( wxT("%llu") ) % m_value;
605 cfg->Write( GetKey(), str );
609 protected:
610 uint64& m_value;
614 #ifndef AMULE_DAEMON
616 class Cfg_Colour : public Cfg_Base
618 public:
619 Cfg_Colour(const wxString& key, wxColour& colour)
620 : Cfg_Base(key),
621 m_colour(colour),
622 m_default(CMuleColour(colour).GetULong())
625 virtual void LoadFromFile(wxConfigBase* cfg)
627 long int rgb;
628 cfg->Read(GetKey(), &rgb, m_default);
629 m_colour.Set(rgb);
632 virtual void SaveToFile(wxConfigBase* cfg)
634 cfg->Write(GetKey(), static_cast<long int>(CMuleColour(m_colour).GetULong()));
637 private:
638 wxColour& m_colour;
639 long int m_default;
643 typedef struct {
644 int id;
645 bool available;
646 wxString displayname;
647 wxString name;
648 } LangInfo;
652 * The languages aMule has translation for.
654 * Add new languages here, as this list overrides the one defined in muuli.wdr
656 static LangInfo aMuleLanguages[] = {
657 { wxLANGUAGE_DEFAULT, true, wxEmptyString, wxTRANSLATE("System default") },
658 { wxLANGUAGE_ALBANIAN, true, wxEmptyString, wxTRANSLATE("Albanian") },
659 { wxLANGUAGE_ARABIC, true, wxEmptyString, wxTRANSLATE("Arabic") },
660 { wxLANGUAGE_ASTURIAN, true, wxEmptyString, wxTRANSLATE("Asturian") },
661 { wxLANGUAGE_BASQUE, true, wxEmptyString, wxTRANSLATE("Basque") },
662 { wxLANGUAGE_BULGARIAN, true, wxEmptyString, wxTRANSLATE("Bulgarian") },
663 { wxLANGUAGE_CATALAN, true, wxEmptyString, wxTRANSLATE("Catalan") },
664 { wxLANGUAGE_CHINESE_SIMPLIFIED, true, wxEmptyString, wxTRANSLATE("Chinese (Simplified)") },
665 { wxLANGUAGE_CHINESE_TRADITIONAL, true, wxEmptyString, wxTRANSLATE("Chinese (Traditional)") },
666 { wxLANGUAGE_CROATIAN, true, wxEmptyString, wxTRANSLATE("Croatian") },
667 { wxLANGUAGE_CZECH, true, wxEmptyString, wxTRANSLATE("Czech") },
668 { wxLANGUAGE_DANISH, true, wxEmptyString, wxTRANSLATE("Danish") },
669 { wxLANGUAGE_DUTCH, true, wxEmptyString, wxTRANSLATE("Dutch") },
670 { wxLANGUAGE_ENGLISH_UK, true, wxEmptyString, wxTRANSLATE("English (U.K.)") },
671 { wxLANGUAGE_ESTONIAN, true, wxEmptyString, wxTRANSLATE("Estonian") },
672 { wxLANGUAGE_FINNISH, true, wxEmptyString, wxTRANSLATE("Finnish") },
673 { wxLANGUAGE_FRENCH, true, wxEmptyString, wxTRANSLATE("French") },
674 { wxLANGUAGE_GALICIAN, true, wxEmptyString, wxTRANSLATE("Galician") },
675 { wxLANGUAGE_GERMAN, true, wxEmptyString, wxTRANSLATE("German") },
676 { wxLANGUAGE_GREEK, true, wxEmptyString, wxTRANSLATE("Greek") },
677 { wxLANGUAGE_HEBREW, true, wxEmptyString, wxTRANSLATE("Hebrew") },
678 { wxLANGUAGE_HUNGARIAN, true, wxEmptyString, wxTRANSLATE("Hungarian") },
679 { wxLANGUAGE_ITALIAN, true, wxEmptyString, wxTRANSLATE("Italian") },
680 { wxLANGUAGE_ITALIAN_SWISS, true, wxEmptyString, wxTRANSLATE("Italian (Swiss)") },
681 { wxLANGUAGE_JAPANESE, true, wxEmptyString, wxTRANSLATE("Japanese") },
682 { wxLANGUAGE_KOREAN, true, wxEmptyString, wxTRANSLATE("Korean") },
683 { wxLANGUAGE_LITHUANIAN, true, wxEmptyString, wxTRANSLATE("Lithuanian") },
684 { wxLANGUAGE_NORWEGIAN_NYNORSK, true, wxEmptyString, wxTRANSLATE("Norwegian (Nynorsk)") },
685 { wxLANGUAGE_POLISH, true, wxEmptyString, wxTRANSLATE("Polish") },
686 { wxLANGUAGE_PORTUGUESE, true, wxEmptyString, wxTRANSLATE("Portuguese") },
687 { wxLANGUAGE_PORTUGUESE_BRAZILIAN, true, wxEmptyString, wxTRANSLATE("Portuguese (Brazilian)") },
688 { wxLANGUAGE_RUSSIAN, true, wxEmptyString, wxTRANSLATE("Russian") },
689 { wxLANGUAGE_SLOVENIAN, true, wxEmptyString, wxTRANSLATE("Slovenian") },
690 { wxLANGUAGE_SPANISH, true, wxEmptyString, wxTRANSLATE("Spanish") },
691 { wxLANGUAGE_SWEDISH, true, wxEmptyString, wxTRANSLATE("Swedish") },
692 { wxLANGUAGE_TURKISH, true, wxEmptyString, wxTRANSLATE("Turkish") },
693 { wxLANGUAGE_UKRAINIAN, true, wxEmptyString, wxTRANSLATE("Ukrainian") },
697 typedef Cfg_Int<int> Cfg_PureInt;
699 class Cfg_Lang : public Cfg_PureInt
701 public:
702 Cfg_Lang()
703 : Cfg_PureInt( wxEmptyString, m_selection, 0 )
707 virtual void LoadFromFile(wxConfigBase* WXUNUSED(cfg)) {}
708 virtual void SaveToFile(wxConfigBase* WXUNUSED(cfg)) {}
711 virtual bool TransferFromWindow()
713 if ( Cfg_PureInt::TransferFromWindow() ) {
714 // find wx ID of selected language
715 int i = 0;
716 while (m_selection > 0) {
717 i++;
718 if (aMuleLanguages[i].available) {
719 m_selection--;
722 int id = aMuleLanguages[i].id;
724 // save language selection
725 thePrefs::SetLanguageID(wxLang2Str(id));
727 return true;
730 return false;
734 virtual bool TransferToWindow()
736 wxChoice *langSelector = dynamic_cast<wxChoice*>(m_widget);
737 // clear existing list
738 langSelector->Clear();
740 m_selection = 0;
741 int wxId = StrLang2wx(thePrefs::GetLanguageID());
743 // Find available languages and translate them
744 aMuleLanguages[0].displayname = wxGetTranslation(aMuleLanguages[0].name);
745 for (unsigned int i = 1; i < itemsof(aMuleLanguages); ++i)
747 // This supresses error-messages about invalid locales.
748 wxLogNull logTarget;
749 wxLocale locale_to_check;
751 InitLocale(locale_to_check, aMuleLanguages[i].id);
752 if (locale_to_check.IsOk() && locale_to_check.IsLoaded(wxT(PACKAGE))) {
753 aMuleLanguages[i].displayname = wxString(wxGetTranslation(aMuleLanguages[i].name)) + wxT(" [") + aMuleLanguages[i].name + wxT("]");
754 } else {
755 aMuleLanguages[i].available = false;
759 // Add all available languages and find the index of the selected language.
760 for ( unsigned int i = 0, j = 0; i < itemsof(aMuleLanguages); i++) {
761 if (aMuleLanguages[i].available) {
762 langSelector->Append(aMuleLanguages[i].displayname);
763 if ( aMuleLanguages[i].id == wxId ) {
764 m_selection = j;
766 j++;
770 // Restore original locale
772 wxLocale tmpLocale;
773 InitLocale(tmpLocale, theApp->m_locale.GetLanguage());
776 return Cfg_PureInt::TransferToWindow();
780 protected:
781 int m_selection;
784 #endif /* ! AMULE_DAEMON */
786 class Cfg_Skin : public Cfg_Str
788 public:
789 Cfg_Skin( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
790 : Cfg_Str( keyname, value, defaultVal ),
791 m_is_skin(false)
794 #ifndef AMULE_DAEMON
795 virtual bool TransferFromWindow()
797 if ( Cfg_Str::TransferFromWindow() ) {
798 if (m_is_skin) {
799 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
800 // "- default -" is always the first
801 if (skinSelector->GetSelection() == 0) {
802 m_value.Clear();
805 return true;
808 return false;
812 virtual bool TransferToWindow()
815 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
816 skinSelector->Clear();
818 wxString folder;
819 int flags = wxDIR_DIRS;
820 wxString filespec = wxEmptyString;
821 //#warning there has to be a better way...
822 if ( GetKey() == wxT("/SkinGUIOptions/Skin") ) {
823 folder = wxT("skins");
824 m_is_skin = true;
825 flags = wxDIR_FILES;
826 filespec = wxT("*.zip");
827 skinSelector->Append(_("- default -"));
828 } else {
829 folder = wxT("webserver");
831 wxString dirName(JoinPaths(GetConfigDir(), folder));
832 wxString Filename;
833 wxDir d;
835 if (wxDir::Exists(dirName) &&
836 d.Open(dirName) &&
837 d.GetFirst(& Filename, filespec, flags)
842 if (m_is_skin) {
843 Filename = wxT("User:") + Filename;
845 skinSelector->Append(Filename);
847 while (d.GetNext(&Filename));
850 wxString dataDir;
851 if (m_is_skin) {
852 dataDir = wxStandardPaths::Get().GetDataDir();
853 } else {
854 dataDir = wxStandardPaths::Get().GetResourcesDir();
856 #if !defined(__WXMSW__) && !defined(__WXMAC__)
857 dataDir = dataDir.BeforeLast(wxT('/')) + wxT("/amule");
858 #endif
859 wxString systemDir(JoinPaths(dataDir,folder));
861 if (wxDir::Exists(systemDir) &&
862 d.Open(systemDir) &&
863 d.GetFirst(& Filename, filespec, flags)
868 if (m_is_skin) {
869 Filename = wxT("System:") + Filename;
871 // avoid duplicates for webserver templates
872 if (skinSelector->FindString(Filename) == wxNOT_FOUND) {
873 skinSelector->Append(Filename);
876 while (d.GetNext(&Filename));
879 if ( skinSelector->GetCount() == 0 ) {
880 skinSelector->Append(_("no options available"));
883 int id = skinSelector->FindString(m_value);
884 if ( id == wxNOT_FOUND ) {
885 id = 0;
887 skinSelector->SetSelection(id);
889 return Cfg_Str::TransferToWindow();
891 #endif /* ! AMULE_DAEMON */
893 protected:
894 bool m_is_skin;
898 /// new implementation
899 CPreferences::CPreferences()
901 srand( wxGetLocalTimeMillis().GetLo() ); // we need random numbers sometimes
903 // load preferences.dat or set standart values
904 wxString fullpath(theApp->ConfigDir + wxT("preferences.dat"));
905 CFile preffile;
906 if (wxFileExists(fullpath)) {
907 if (preffile.Open(fullpath, CFile::read)) {
908 try {
909 preffile.ReadUInt8(); // Version. Value is not used.
910 s_userhash = preffile.ReadHash();
911 } catch (const CSafeIOException& e) {
912 AddDebugLogLineM(true, logGeneral,
913 wxT("Error while reading userhash: ") + e.what());
918 if (s_userhash.IsEmpty()) {
919 for (int i = 0; i < 8; i++) {
920 RawPokeUInt16(s_userhash.GetHash() + (i * 2), rand());
923 Save();
926 // Mark hash as an eMule-type hash
927 // See also CUpDownClient::GetHashType
928 s_userhash[5] = 14;
929 s_userhash[14] = 111;
931 #ifndef CLIENT_GUI
932 LoadPreferences();
933 ReloadSharedFolders();
935 // serverlist adresses
936 CTextFile slistfile;
937 if (slistfile.Open(theApp->ConfigDir + wxT("addresses.dat"), CTextFile::read)) {
938 adresses_list = slistfile.ReadLines();
940 #endif
944 // Gets called at init time
946 void CPreferences::BuildItemList( const wxString& appdir )
948 #ifndef AMULE_DAEMON
949 #define NewCfgItem(ID, COMMAND) s_CfgList[ID] = COMMAND
950 #else
951 int current_id = 0;
952 #define NewCfgItem(ID, COMMAND) s_CfgList[++current_id] = COMMAND
953 #endif /* AMULE_DAEMON */
956 * User settings
958 NewCfgItem(IDC_NICK, (new Cfg_Str( wxT("/eMule/Nick"), s_nick, wxT("http://www.aMule.org") )));
959 #ifndef AMULE_DAEMON
960 NewCfgItem(IDC_LANGUAGE, (new Cfg_Lang()));
961 #endif
964 * Browser options
966 #ifdef __WXMAC__
967 wxString customBrowser = wxT("/usr/bin/open");
968 #else
969 wxString customBrowser; // left empty
970 #endif
972 NewCfgItem(IDC_BROWSERTABS, (new Cfg_Bool( wxT("/Browser/OpenPageInTab"), s_BrowserTab, true )));
973 NewCfgItem(IDC_BROWSERSELF, (new Cfg_Str( wxT("/Browser/CustomBrowserString"), s_CustomBrowser, customBrowser )));
977 * Misc
979 NewCfgItem(IDC_QUEUESIZE, (MkCfg_Int( wxT("/eMule/QueueSizePref"), s_iQueueSize, 50 )));
982 #ifdef __DEBUG__
984 * Debugging
986 NewCfgItem(ID_VERBOSEDEBUG, (new Cfg_Bool( wxT("/eMule/VerboseDebug"), s_bVerbose, false )));
987 #endif
990 * Connection settings
992 NewCfgItem(IDC_MAXUP, (MkCfg_Int( wxT("/eMule/MaxUpload"), s_maxupload, 0 )));
993 NewCfgItem(IDC_MAXDOWN, (MkCfg_Int( wxT("/eMule/MaxDownload"), s_maxdownload, 0 )));
994 NewCfgItem(IDC_SLOTALLOC, (MkCfg_Int( wxT("/eMule/SlotAllocation"), s_slotallocation, 2 )));
995 NewCfgItem(IDC_PORT, (MkCfg_Int( wxT("/eMule/Port"), s_port, DEFAULT_TCP_PORT )));
996 NewCfgItem(IDC_UDPPORT, (MkCfg_Int( wxT("/eMule/UDPPort"), s_udpport, DEFAULT_UDP_PORT )));
997 NewCfgItem(IDC_UDPENABLE, (new Cfg_Bool( wxT("/eMule/UDPEnable"), s_UDPEnable, true )));
998 NewCfgItem(IDC_ADDRESS, (new Cfg_Str( wxT("/eMule/Address"), s_Addr, wxEmptyString)));
999 NewCfgItem(IDC_AUTOCONNECT, (new Cfg_Bool( wxT("/eMule/Autoconnect"), s_autoconnect, true )));
1000 NewCfgItem(IDC_MAXSOURCEPERFILE, (MkCfg_Int( wxT("/eMule/MaxSourcesPerFile"), s_maxsourceperfile, 300 )));
1001 NewCfgItem(IDC_MAXCON, (MkCfg_Int( wxT("/eMule/MaxConnections"), s_maxconnections, GetRecommendedMaxConnections() )));
1002 NewCfgItem(IDC_MAXCON5SEC, (MkCfg_Int( wxT("/eMule/MaxConnectionsPerFiveSeconds"), s_MaxConperFive, 20 )));
1005 * Proxy
1007 NewCfgItem(ID_PROXY_ENABLE_PROXY, (new Cfg_Bool( wxT("/Proxy/ProxyEnableProxy"), s_ProxyData.m_proxyEnable, false )));
1008 NewCfgItem(ID_PROXY_TYPE, (MkCfg_Int( wxT("/Proxy/ProxyType"), s_ProxyData.m_proxyType, 0 )));
1009 NewCfgItem(ID_PROXY_NAME, (new Cfg_Str( wxT("/Proxy/ProxyName"), s_ProxyData.m_proxyHostName, wxEmptyString )));
1010 NewCfgItem(ID_PROXY_PORT, (MkCfg_Int( wxT("/Proxy/ProxyPort"), s_ProxyData.m_proxyPort, 1080 )));
1011 NewCfgItem(ID_PROXY_ENABLE_PASSWORD, (new Cfg_Bool( wxT("/Proxy/ProxyEnablePassword"), s_ProxyData.m_enablePassword, false )));
1012 NewCfgItem(ID_PROXY_USER, (new Cfg_Str( wxT("/Proxy/ProxyUser"), s_ProxyData.m_userName, wxEmptyString )));
1013 NewCfgItem(ID_PROXY_PASSWORD, (new Cfg_Str( wxT("/Proxy/ProxyPassword"), s_ProxyData.m_password, wxEmptyString )));
1014 // These were copied from eMule config file, maybe someone with windows can complete this?
1015 // NewCfgItem(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY, (new Cfg_Bool( wxT("/Proxy/Proxy????"), s_Proxy????, false )));
1018 * Servers
1019 **/
1020 NewCfgItem(IDC_REMOVEDEAD, (new Cfg_Bool( wxT("/eMule/RemoveDeadServer"), s_deadserver, 1 )));
1021 NewCfgItem(IDC_SERVERRETRIES, (MkCfg_Int( wxT("/eMule/DeadServerRetry"), s_deadserverretries, 3 )));
1022 NewCfgItem(IDC_SERVERKEEPALIVE, (MkCfg_Int( wxT("/eMule/ServerKeepAliveTimeout"), s_dwServerKeepAliveTimeoutMins, 0 )));
1023 NewCfgItem(IDC_RECONN, (new Cfg_Bool( wxT("/eMule/Reconnect"), s_reconnect, true )));
1024 NewCfgItem(IDC_SCORE, (new Cfg_Bool( wxT("/eMule/Scoresystem"), s_scorsystem, true )));
1025 NewCfgItem(IDC_AUTOSERVER, (new Cfg_Bool( wxT("/eMule/Serverlist"), s_autoserverlist, false )));
1026 NewCfgItem(IDC_UPDATESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/AddServerListFromServer"), s_addserversfromserver, false)));
1027 NewCfgItem(IDC_UPDATESERVERCLIENT, (new Cfg_Bool( wxT("/eMule/AddServerListFromClient"), s_addserversfromclient, false )));
1028 NewCfgItem(IDC_SAFESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/SafeServerConnect"), s_safeServerConnect, false )));
1029 NewCfgItem(IDC_AUTOCONNECTSTATICONLY, (new Cfg_Bool( wxT("/eMule/AutoConnectStaticOnly"), s_autoconnectstaticonly, false )));
1030 NewCfgItem(IDC_UPNP_ENABLED, (new Cfg_Bool( wxT("/eMule/UPnPEnabled"), s_UPnPEnabled, false )));
1031 NewCfgItem(IDC_UPNPTCPPORT, (MkCfg_Int( wxT("/eMule/UPnPTCPPort"), s_UPnPTCPPort, 50000 )));
1032 NewCfgItem(IDC_SMARTIDCHECK, (new Cfg_Bool( wxT("/eMule/SmartIdCheck"), s_smartidcheck, true )));
1033 // Enabled networks
1034 NewCfgItem( IDC_NETWORKKAD, (new Cfg_Bool( wxT("/eMule/ConnectToKad"), s_ConnectToKad, true )) );
1035 NewCfgItem( IDC_NETWORKED2K, ( new Cfg_Bool( wxT("/eMule/ConnectToED2K"), s_ConnectToED2K, true ) ));
1039 * Files
1041 NewCfgItem(IDC_TEMPFILES, (new Cfg_Path( wxT("/eMule/TempDir"), s_tempdir, appdir + wxT("Temp") )));
1043 #if defined(__WXMAC__) || defined(__WXMSW__)
1044 wxString incpath = wxStandardPaths::Get().GetDocumentsDir();
1045 if (incpath.IsEmpty()) {
1046 // There is a built-in possibility for this call to fail, though I can't imagine a reason for that.
1047 incpath = appdir + wxT("Incoming");
1048 } else {
1049 incpath = JoinPaths(incpath, wxT("aMule Downloads"));
1051 #else
1052 wxString incpath = appdir + wxT("Incoming");
1053 #endif
1054 NewCfgItem(IDC_INCFILES, (new Cfg_Path( wxT("/eMule/IncomingDir"), s_incomingdir, incpath )));
1056 NewCfgItem(IDC_ICH, (new Cfg_Bool( wxT("/eMule/ICH"), s_ICH, true )));
1057 NewCfgItem(IDC_AICHTRUST, (new Cfg_Bool( wxT("/eMule/AICHTrust"), s_AICHTrustEveryHash, false )));
1058 NewCfgItem(IDC_CHECKDISKSPACE, (new Cfg_Bool( wxT("/eMule/CheckDiskspace"), s_checkDiskspace, true )));
1059 NewCfgItem(IDC_MINDISKSPACE, (MkCfg_Int( wxT("/eMule/MinFreeDiskSpace"), s_uMinFreeDiskSpace, 1 )));
1060 NewCfgItem(IDC_ADDNEWFILESPAUSED, (new Cfg_Bool( wxT("/eMule/AddNewFilesPaused"), s_addnewfilespaused, false )));
1061 NewCfgItem(IDC_PREVIEWPRIO, (new Cfg_Bool( wxT("/eMule/PreviewPrio"), s_bpreviewprio, false )));
1062 NewCfgItem(IDC_MANUALSERVERHIGHPRIO, (new Cfg_Bool( wxT("/eMule/ManualHighPrio"), s_bmanualhighprio, false )));
1063 NewCfgItem(IDC_FULLCHUNKTRANS, (new Cfg_Bool( wxT("/eMule/FullChunkTransfers"), s_btransferfullchunks, true )));
1064 NewCfgItem(IDC_STARTNEXTFILE, (new Cfg_Bool( wxT("/eMule/StartNextFile"), s_bstartnextfile, false )));
1065 NewCfgItem(IDC_STARTNEXTFILE_SAME, (new Cfg_Bool( wxT("/eMule/StartNextFileSameCat"), s_bstartnextfilesame, false )));
1066 NewCfgItem(IDC_SRCSEEDS, (new Cfg_Bool( wxT("/ExternalConnect/UseSrcSeeds"), s_UseSrcSeeds, false )));
1067 NewCfgItem(IDC_FILEBUFFERSIZE, (MkCfg_Int( wxT("/eMule/FileBufferSizePref"), s_iFileBufferSize, 16 )));
1068 NewCfgItem(IDC_DAP, (new Cfg_Bool( wxT("/eMule/DAPPref"), s_bDAP, true )));
1069 NewCfgItem(IDC_UAP, (new Cfg_Bool( wxT("/eMule/UAPPref"), s_bUAP, true )));
1070 NewCfgItem(IDC_ALLOCFULLFILE, (new Cfg_Bool( wxT("/eMule/AllocateFullFile"), s_allocFullFile, false )));
1073 * Web Server
1075 NewCfgItem(IDC_OSDIR, (new Cfg_Path( wxT("/eMule/OSDirectory"), s_OSDirectory, appdir )));
1076 NewCfgItem(IDC_ONLINESIG, (new Cfg_Bool( wxT("/eMule/OnlineSignature"), s_onlineSig, false )));
1077 NewCfgItem(IDC_OSUPDATE, (MkCfg_Int( wxT("/eMule/OnlineSignatureUpdate"), s_OSUpdate, 5 )));
1078 NewCfgItem(IDC_ENABLE_WEB, (new Cfg_Bool( wxT("/WebServer/Enabled"), s_bWebEnabled, false )));
1079 NewCfgItem(IDC_WEB_PASSWD, (new Cfg_Str_Encrypted( wxT("/WebServer/Password"), s_sWebPassword )));
1080 NewCfgItem(IDC_WEB_PASSWD_LOW, (new Cfg_Str_Encrypted( wxT("/WebServer/PasswordLow"), s_sWebLowPassword )));
1081 NewCfgItem(IDC_WEB_PORT, (MkCfg_Int( wxT("/WebServer/Port"), s_nWebPort, 4711 )));
1082 NewCfgItem(IDC_WEBUPNPTCPPORT, (MkCfg_Int( wxT("/WebServer/WebUPnPTCPPort"), s_nWebUPnPTCPPort, 50001 )));
1083 NewCfgItem(IDC_UPNP_WEBSERVER_ENABLED,
1084 (new Cfg_Bool( wxT("/WebServer/UPnPWebServerEnabled"), s_UPnPWebServerEnabled, false )));
1085 NewCfgItem(IDC_WEB_GZIP, (new Cfg_Bool( wxT("/WebServer/UseGzip"), s_bWebUseGzip, true )));
1086 NewCfgItem(IDC_ENABLE_WEB_LOW, (new Cfg_Bool( wxT("/WebServer/UseLowRightsUser"), s_bWebLowEnabled, false )));
1087 NewCfgItem(IDC_WEB_REFRESH_TIMEOUT, (MkCfg_Int( wxT("/WebServer/PageRefreshTime"), s_nWebPageRefresh, 120 )));
1088 NewCfgItem(IDC_WEBTEMPLATE, (new Cfg_Skin( wxT("/WebServer/Template"), s_WebTemplate, wxEmptyString )));
1091 * External Connections
1093 NewCfgItem(IDC_EXT_CONN_ACCEPT, (new Cfg_Bool( wxT("/ExternalConnect/AcceptExternalConnections"), s_AcceptExternalConnections, false )));
1094 NewCfgItem(IDC_EXT_CONN_IP, (new Cfg_Str( wxT("/ExternalConnect/ECAddress"), s_ECAddr, wxEmptyString )));
1095 NewCfgItem(IDC_EXT_CONN_TCP_PORT, (MkCfg_Int( wxT("/ExternalConnect/ECPort"), s_ECPort, 4712 )));
1096 NewCfgItem(IDC_EXT_CONN_PASSWD, (new Cfg_Str_Encrypted( wxT("/ExternalConnect/ECPassword"), s_ECPassword, wxEmptyString )));
1097 NewCfgItem(IDC_UPNP_EC_ENABLED, (new Cfg_Bool( wxT("/ExternalConnect/UPnPECEnabled"), s_UPnPECEnabled, false )));
1100 * GUI behavior
1102 NewCfgItem(IDC_ENABLETRAYICON, (new Cfg_Bool( wxT("/eMule/EnableTrayIcon"), s_trayiconenabled, false )));
1103 NewCfgItem(IDC_MINTRAY, (new Cfg_Bool( wxT("/eMule/MinToTray"), s_mintotray, false )));
1104 NewCfgItem(IDC_EXIT, (new Cfg_Bool( wxT("/eMule/ConfirmExit"), s_confirmExit, true )));
1105 NewCfgItem(IDC_STARTMIN, (new Cfg_Bool( wxT("/eMule/StartupMinimized"), s_startMinimized, false )));
1108 * GUI appearence
1110 NewCfgItem(IDC_3DDEPTH, (MkCfg_Int( wxT("/eMule/3DDepth"), s_depth3D, 10 )));
1111 NewCfgItem(IDC_TOOLTIPDELAY, (MkCfg_Int( wxT("/eMule/ToolTipDelay"), s_iToolDelayTime, 1 )));
1112 NewCfgItem(IDC_SHOWOVERHEAD, (new Cfg_Bool( wxT("/eMule/ShowOverhead"), s_bshowoverhead, false )));
1113 NewCfgItem(IDC_EXTCATINFO, (new Cfg_Bool( wxT("/eMule/ShowInfoOnCatTabs"), s_showCatTabInfos, true )));
1114 NewCfgItem(IDC_FED2KLH, (new Cfg_Bool( wxT("/Razor_Preferences/FastED2KLinksHandler"), s_FastED2KLinksHandler, true )));
1115 NewCfgItem(IDC_PROGBAR, (new Cfg_Bool( wxT("/ExternalConnect/ShowProgressBar"), s_ProgBar, true )));
1116 NewCfgItem(IDC_PERCENT, (new Cfg_Bool( wxT("/ExternalConnect/ShowPercent"), s_Percent, true )));
1117 NewCfgItem(IDC_SKIN, (new Cfg_Skin( wxT("/SkinGUIOptions/Skin"), s_Skin, wxEmptyString )));
1118 NewCfgItem(IDC_VERTTOOLBAR, (new Cfg_Bool( wxT("/eMule/VerticalToolbar"), s_ToolbarOrientation, false )));
1121 * External Apps
1123 NewCfgItem(IDC_VIDEOPLAYER, (new Cfg_Str( wxT("/eMule/VideoPlayer"), s_VideoPlayer, wxEmptyString )));
1124 NewCfgItem(IDC_VIDEOBACKUP, (new Cfg_Bool( wxT("/eMule/VideoPreviewBackupped"), s_moviePreviewBackup, true )));
1127 * Statistics
1129 NewCfgItem(IDC_SLIDER, (MkCfg_Int( wxT("/eMule/StatGraphsInterval"), s_trafficOMeterInterval, 3 )));
1130 NewCfgItem(IDC_SLIDER2, (MkCfg_Int( wxT("/eMule/statsInterval"), s_statsInterval, 30 )));
1131 NewCfgItem(IDC_DOWNLOAD_CAP, (MkCfg_Int( wxT("/eMule/DownloadCapacity"), s_maxGraphDownloadRate, 300 )));
1132 NewCfgItem(IDC_UPLOAD_CAP, (MkCfg_Int( wxT("/eMule/UploadCapacity"), s_maxGraphUploadRate, 100 )));
1133 NewCfgItem(IDC_SLIDER3, (MkCfg_Int( wxT("/eMule/StatsAverageMinutes"), s_statsAverageMinutes, 5 )));
1134 NewCfgItem(IDC_SLIDER4, (MkCfg_Int( wxT("/eMule/VariousStatisticsMaxValue"), s_statsMax, 100 )));
1135 NewCfgItem(IDC_CLIENTVERSIONS, (MkCfg_Int( wxT("/Statistics/MaxClientVersions"), s_maxClientVersions, 0 )));
1138 * Security
1140 NewCfgItem(IDC_SEESHARES, (MkCfg_Int( wxT("/eMule/SeeShare"), s_iSeeShares, 2 )));
1141 NewCfgItem(IDC_SECIDENT, (new Cfg_Bool( wxT("/ExternalConnect/UseSecIdent"), s_SecIdent, true )));
1142 NewCfgItem(IDC_IPFCLIENTS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterClients"), s_IPFilterClients, true )));
1143 NewCfgItem(IDC_IPFSERVERS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterServers"), s_IPFilterServers, true )));
1144 NewCfgItem(IDC_FILTERLAN, (new Cfg_Bool( wxT("/eMule/FilterLanIPs"), s_filterLanIP, true )));
1145 NewCfgItem(IDC_PARANOID, (new Cfg_Bool( wxT("/eMule/ParanoidFiltering"), s_paranoidfilter, true )));
1146 NewCfgItem(IDC_AUTOIPFILTER, (new Cfg_Bool( wxT("/eMule/IPFilterAutoLoad"), s_IPFilterAutoLoad, true )));
1147 NewCfgItem(IDC_IPFILTERURL, (new Cfg_Str( wxT("/eMule/IPFilterURL"), s_IPFilterURL, wxEmptyString )));
1148 NewCfgItem(ID_IPFILTERLEVEL, (MkCfg_Int( wxT("/eMule/FilterLevel"), s_filterlevel, 127 )));
1149 NewCfgItem(IDC_IPFILTERSYS, (new Cfg_Bool( wxT("/eMule/IPFilterSystem"), s_IPFilterSys, false )));
1151 /**
1152 * Message Filter
1154 NewCfgItem(IDC_MSGFILTER, (new Cfg_Bool( wxT("/eMule/FilterMessages"), s_MustFilterMessages, true )));
1155 NewCfgItem(IDC_MSGFILTER_ALL, (new Cfg_Bool( wxT("/eMule/FilterAllMessages"), s_FilterAllMessages, false )));
1156 NewCfgItem(IDC_MSGFILTER_NONFRIENDS, (new Cfg_Bool( wxT("/eMule/MessagesFromFriendsOnly"), s_msgonlyfriends, false )));
1157 NewCfgItem(IDC_MSGFILTER_NONSECURE, (new Cfg_Bool( wxT("/eMule/MessageFromValidSourcesOnly"), s_msgsecure, true )));
1158 NewCfgItem(IDC_MSGFILTER_WORD, (new Cfg_Bool( wxT("/eMule/FilterWordMessages"), s_FilterSomeMessages, false )));
1159 NewCfgItem(IDC_MSGWORD, (new Cfg_Str( wxT("/eMule/MessageFilter"), s_MessageFilterString, wxEmptyString )));
1160 NewCfgItem(IDC_MSGLOG, (new Cfg_Bool( wxT("/eMule/ShowMessagesInLog"), s_ShowMessagesInLog, true )));
1162 NewCfgItem(IDC_FILTERCOMMENTS, (new Cfg_Bool( wxT("/eMule/FilterComments"), s_FilterComments, false )));
1163 NewCfgItem(IDC_COMMENTWORD, (new Cfg_Str( wxT("/eMule/CommentFilter"), s_CommentFilterString, wxEmptyString )));
1166 * Hidden files sharing
1167 **/
1168 NewCfgItem(IDC_SHAREHIDDENFILES, (new Cfg_Bool( wxT("/eMule/ShareHiddenFiles"), s_ShareHiddenFiles, false )));
1171 * Auto-Sorting of downloads
1173 NewCfgItem(IDC_AUTOSORT, (new Cfg_Bool( wxT("/eMule/AutoSortDownloads"), s_AutoSortDownload, false )));
1176 * Version check
1178 NewCfgItem(IDC_NEWVERSION, (new Cfg_Bool( wxT("/eMule/NewVersionCheck"), s_NewVersionCheck, true )));
1181 * Obfuscation
1184 NewCfgItem( IDC_SUPPORT_PO, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerSupported"), s_IsClientCryptLayerSupported, true )));
1185 NewCfgItem( IDC_ENABLE_PO_OUTGOING, ( new Cfg_Bool( wxT("/Obfuscation/IsCryptLayerRequested"), s_bCryptLayerRequested, true )));
1186 NewCfgItem( IDC_ENFORCE_PO_INCOMING, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerRequired"), s_IsClientCryptLayerRequired, false )));
1187 // There is no need for GUI items for this two.
1188 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoPaddingLenght"), s_byCryptTCPPaddingLength, 254 ) );
1189 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoKadUDPKey"), s_dwKadUDPKey, GetRandomUint32() ) );
1192 * The following doesn't have an associated widget or section
1194 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Language"), s_languageID ) );
1195 s_MiscList.push_back( new Cfg_Counter( wxT("/Statistics/TotalDownloadedBytes"), s_totalDownloadedBytes ) );
1196 s_MiscList.push_back( new Cfg_Counter( wxT("/Statistics/TotalUploadedBytes"), s_totalUploadedBytes ) );
1197 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SplitterbarPosition"), s_splitterbarPosition, 75 ) );
1198 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/YourHostname"), s_yourHostname, wxEmptyString ) );
1199 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/DateTimeFormat"), s_datetimeformat, wxT("%A, %x, %X") ) );
1201 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/AllcatType"), s_allcatType, 0 ) );
1202 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/ShowAllNotCats"), s_showAllNotCats, false ) );
1204 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SmartIdState"), s_smartidstate, 0 ) );
1206 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/DropSlowSources"), s_DropSlowSources, false ) );
1208 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/KadNodesUrl"), s_KadURL, wxT("http://emule-inside.net/nodes.dat") ) );
1209 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Ed2kServersUrl"), s_Ed2kURL, wxT("http://gruk.org/server.met.gz") ) );
1210 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/ShowRatesOnTitle"), s_showRatesOnTitle, 0 ));
1212 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/GeoIPEnabled"), s_GeoIPEnabled, true ) );
1213 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/GeoLiteCountryUpdateUrl"), s_GeoIPUpdateUrl, wxT("http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz") ) );
1214 wxConfigBase::Get()->DeleteEntry(wxT("/eMule/GeoIPUpdateUrl")); // get rid of the old one for a while
1216 #ifndef AMULE_DAEMON
1217 // Colors have been moved from global prefs to CStatisticsDlg
1218 for ( int i = 0; i < cntStatColors; i++ ) {
1219 wxString str = wxString::Format(wxT("/eMule/StatColor%i"),i);
1220 s_MiscList.push_back( new Cfg_Colour( str, CStatisticsDlg::acrStat[i] ) );
1222 #endif
1224 // User events
1225 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1226 // We can't use NewCfgItem here, because we need to find these items
1227 // later, which would be impossible in amuled with NewCfgItem.
1228 // The IDs we assign here are high enough to not cause any collision
1229 // even on the daemon.
1230 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT + 1] = new Cfg_Bool(wxT("/UserEvents/") + CUserEvents::GetKey(i) + wxT("/CoreEnabled"), CUserEvents::GetCoreEnableVar(i), false);
1231 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT + 2] = new Cfg_Str(wxT("/UserEvents/") + CUserEvents::GetKey(i) + wxT("/CoreCommand"), CUserEvents::GetCoreCommandVar(i), wxEmptyString);
1232 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT + 3] = new Cfg_Bool(wxT("/UserEvents/") + CUserEvents::GetKey(i) + wxT("/GUIEnabled"), CUserEvents::GetGUIEnableVar(i), false);
1233 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT + 4] = new Cfg_Str(wxT("/UserEvents/") + CUserEvents::GetKey(i) + wxT("/GUICommand"), CUserEvents::GetGUICommandVar(i), wxEmptyString);
1238 void CPreferences::EraseItemList()
1240 while ( s_CfgList.begin() != s_CfgList.end() ) {
1241 delete s_CfgList.begin()->second;
1242 s_CfgList.erase( s_CfgList.begin() );
1245 CFGList::iterator it = s_MiscList.begin();
1246 for ( ; it != s_MiscList.end(); ) {
1247 delete *it;
1248 it = s_MiscList.erase( it );
1253 void CPreferences::LoadAllItems(wxConfigBase* cfg)
1255 #ifndef CLIENT_GUI
1256 // Preserve values from old config. The global config object may not be set yet
1257 // when BuildItemList() is called, so we need to provide defaults later - here.
1258 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletion"))) {
1259 bool ExecOnCompletion;
1260 cfg->Read(wxT("/eMule/ExecOnCompletion"), &ExecOnCompletion, false);
1261 // Assign to core command, that's the most likely it was.
1262 static_cast<Cfg_Bool*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT + 1])->SetDefault(ExecOnCompletion);
1263 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletion"));
1265 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletionCommand"))) {
1266 wxString ExecOnCompletionCommand;
1267 cfg->Read(wxT("/eMule/ExecOnCompletionCommand"), &ExecOnCompletionCommand, wxEmptyString);
1268 static_cast<Cfg_Str*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT + 2])->SetDefault(ExecOnCompletionCommand);
1269 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletionCommand"));
1271 #endif
1272 CFGMap::iterator it_a = s_CfgList.begin();
1273 for ( ; it_a != s_CfgList.end(); ++it_a ) {
1274 it_a->second->LoadFromFile( cfg );
1277 CFGList::iterator it_b = s_MiscList.begin();
1278 for ( ; it_b != s_MiscList.end(); ++it_b ) {
1279 (*it_b)->LoadFromFile( cfg );
1282 // Preserve old value of UDPDisable
1283 if (cfg->HasEntry(wxT("/eMule/UDPDisable"))) {
1284 bool UDPDisable;
1285 cfg->Read(wxT("/eMule/UDPDisable"), &UDPDisable, false);
1286 SetUDPDisable(UDPDisable);
1287 cfg->DeleteEntry(wxT("/eMule/UDPDisable"));
1290 // Preserve old value of UseSkinFiles
1291 if (cfg->HasEntry(wxT("/SkinGUIOptions/UseSkinFiles"))) {
1292 bool UseSkinFiles;
1293 cfg->Read(wxT("/SkinGUIOptions/UseSkinFiles"), &UseSkinFiles, false);
1294 if (!UseSkinFiles) {
1295 s_Skin.Clear();
1297 cfg->DeleteEntry(wxT("/SkinGUIOptions/UseSkinFiles"));
1300 #ifdef __DEBUG__
1301 // Load debug-categories
1302 int count = theLogger.GetDebugCategoryCount();
1304 for ( int i = 0; i < count; i++ ) {
1305 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1307 bool enabled = false;
1308 cfg->Read( wxT("/Debug/Cat_") + cat.GetName(), &enabled );
1310 theLogger.SetEnabled( cat.GetType(), enabled );
1312 #endif
1314 // Now do some post-processing / sanity checking on the values we just loaded
1315 CheckUlDlRatio();
1316 SetPort(s_port);
1317 if (s_byCryptTCPPaddingLength > 254) {
1318 s_byCryptTCPPaddingLength = GetRandomUint8() % 254;
1323 void CPreferences::SaveAllItems(wxConfigBase* cfg)
1325 // Save the Cfg values
1326 CFGMap::iterator it_a = s_CfgList.begin();
1327 for ( ; it_a != s_CfgList.end(); ++it_a )
1328 it_a->second->SaveToFile( cfg );
1330 CFGList::iterator it_b = s_MiscList.begin();
1331 for ( ; it_b != s_MiscList.end(); ++it_b )
1332 (*it_b)->SaveToFile( cfg );
1335 // Save debug-categories
1336 #ifdef __DEBUG__
1337 int count = theLogger.GetDebugCategoryCount();
1339 for ( int i = 0; i < count; i++ ) {
1340 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1342 cfg->Write( wxT("/Debug/Cat_") + cat.GetName(), cat.IsEnabled() );
1344 #endif
1347 void CPreferences::SetMaxUpload(uint16 in)
1349 if ( s_maxupload != in ) {
1350 s_maxupload = in;
1352 // Ensure that the ratio is upheld
1353 CheckUlDlRatio();
1358 void CPreferences::SetMaxDownload(uint16 in)
1360 if ( s_maxdownload != in ) {
1361 s_maxdownload = in;
1363 // Ensure that the ratio is upheld
1364 CheckUlDlRatio();
1369 void CPreferences::UnsetAutoServerStart()
1371 s_autoserverlist = false;
1375 // Here we slightly limit the users' ability to be a bad citizen: for very low upload rates
1376 // we force a low download rate, so as to discourage this type of leeching.
1377 // We're Open Source, and whoever wants it can do his own mod to get around this, but the
1378 // packaged product will try to enforce good behavior.
1380 // Kry note: of course, any leecher mod will be banned asap.
1381 void CPreferences::CheckUlDlRatio()
1383 // Backwards compatibility
1384 if ( s_maxupload == 0xFFFF )
1385 s_maxupload = UNLIMITED;
1387 // Backwards compatibility
1388 if ( s_maxdownload == 0xFFFF )
1389 s_maxdownload = UNLIMITED;
1391 if ( s_maxupload == UNLIMITED )
1392 return;
1394 // Enforce the limits
1395 if ( s_maxupload < 4 ) {
1396 if ( ( s_maxupload * 3 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1397 s_maxdownload = s_maxupload * 3 ;
1398 } else if ( s_maxupload < 10 ) {
1399 if ( ( s_maxupload * 4 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1400 s_maxdownload = s_maxupload * 4;
1405 void CPreferences::Save()
1407 wxString fullpath(theApp->ConfigDir + wxT("preferences.dat"));
1409 CFile preffile;
1410 if (!wxFileExists(fullpath)) {
1411 preffile.Create(fullpath);
1414 if (preffile.Open(fullpath, CFile::read_write)) {
1415 try {
1416 preffile.WriteUInt8(PREFFILE_VERSION);
1417 preffile.WriteHash(s_userhash);
1418 } catch (const CIOFailureException& e) {
1419 AddDebugLogLineM(true, logGeneral, wxT("IO failure while saving user-hash: ") + e.what());
1423 SavePreferences();
1425 #ifndef CLIENT_GUI
1426 CTextFile sdirfile;
1427 if (sdirfile.Open(theApp->ConfigDir + wxT("shareddir.dat"), CTextFile::write)) {
1428 for (size_t i = 0; i < shareddir_list.size(); ++i) {
1429 sdirfile.WriteLine(CPath::ToUniv(shareddir_list[i]), wxConvUTF8);
1433 #endif
1437 CPreferences::~CPreferences()
1439 while ( !m_CatList.empty() ) {
1440 delete m_CatList.front();
1441 m_CatList.erase( m_CatList.begin() );
1444 m_CatList.clear();
1448 int32 CPreferences::GetRecommendedMaxConnections()
1450 #ifndef CLIENT_GUI
1451 int iRealMax = PlatformSpecific::GetMaxConnections();
1452 if(iRealMax == -1 || iRealMax > 520) {
1453 return 500;
1455 if(iRealMax < 20) {
1456 return iRealMax;
1458 if(iRealMax <= 256) {
1459 return iRealMax - 10;
1461 return iRealMax - 20;
1462 #else
1463 return 500;
1464 #endif
1468 void CPreferences::SavePreferences()
1470 wxConfigBase* cfg = wxConfigBase::Get();
1472 cfg->Write( wxT("/eMule/AppVersion"), wxT(VERSION) );
1474 // Save the options
1475 SaveAllItems( cfg );
1477 // Ensure that the changes are saved to disk.
1478 cfg->Flush();
1482 void CPreferences::SaveCats()
1484 if ( GetCatCount() ) {
1485 wxConfigBase* cfg = wxConfigBase::Get();
1487 // Save the main cat.
1488 cfg->Write( wxT("/eMule/AllcatType"), (int)s_allcatType);
1490 // The first category is the default one and should not be counted
1492 cfg->Write( wxT("/General/Count"), (long)(m_CatList.size() - 1) );
1494 for ( size_t i = 1; i < m_CatList.size(); i++ ) {
1495 cfg->SetPath( wxString::Format(wxT("/Cat#%i"), i) );
1497 cfg->Write( wxT("Title"), m_CatList[i]->title );
1498 cfg->Write( wxT("Incoming"), CPath::ToUniv(m_CatList[i]->path) );
1499 cfg->Write( wxT("Comment"), m_CatList[i]->comment );
1500 cfg->Write( wxT("Color"), wxString::Format(wxT("%u"), m_CatList[i]->color) );
1501 cfg->Write( wxT("Priority"), (int)m_CatList[i]->prio );
1504 cfg->Flush();
1509 void CPreferences::LoadPreferences()
1511 LoadCats();
1515 void CPreferences::LoadCats()
1517 // default cat ... Meow! =(^.^)=
1518 Category_Struct* defaultcat = new Category_Struct;
1519 defaultcat->prio = 0;
1520 defaultcat->color = 0;
1522 AddCat( defaultcat );
1524 wxConfigBase* cfg = wxConfigBase::Get();
1526 long max = cfg->Read( wxT("/General/Count"), 0l );
1528 for ( int i = 1; i <= max ; i++ ) {
1529 cfg->SetPath( wxString::Format(wxT("/Cat#%i"), i) );
1531 Category_Struct* newcat = new Category_Struct;
1533 newcat->title = cfg->Read( wxT("Title"), wxEmptyString );
1534 newcat->path = CPath::FromUniv(cfg->Read(wxT("Incoming"), wxEmptyString));
1536 // Some sainity checking
1537 if ( newcat->title.IsEmpty() || !newcat->path.IsOk() ) {
1538 AddLogLineN(_("Invalid category found, skipping"));
1540 delete newcat;
1541 continue;
1544 newcat->comment = cfg->Read( wxT("Comment"), wxEmptyString );
1545 newcat->prio = cfg->Read( wxT("Priority"), 0l );
1546 newcat->color = StrToULong(cfg->Read(wxT("Color"), wxT("0")));
1548 AddCat(newcat);
1550 if (!newcat->path.DirExists()) {
1551 CPath::MakeDir(newcat->path);
1557 uint16 CPreferences::GetDefaultMaxConperFive()
1559 return MAXCONPER5SEC;
1563 uint32 CPreferences::AddCat(Category_Struct* cat)
1565 m_CatList.push_back( cat );
1567 return m_CatList.size() - 1;
1571 void CPreferences::RemoveCat(size_t index)
1573 if ( index < m_CatList.size() ) {
1574 CatList::iterator it = m_CatList.begin() + index;
1576 delete *it;
1578 m_CatList.erase( it );
1583 uint32 CPreferences::GetCatCount()
1585 return m_CatList.size();
1589 Category_Struct* CPreferences::GetCategory(size_t index)
1591 wxASSERT( index < m_CatList.size() );
1593 return m_CatList[index];
1597 const CPath& CPreferences::GetCatPath(uint8 index)
1599 wxASSERT( index < m_CatList.size() );
1601 return m_CatList[index]->path;
1605 uint32 CPreferences::GetCatColor(size_t index)
1607 wxASSERT( index < m_CatList.size() );
1609 return m_CatList[index]->color;
1612 Category_Struct *CPreferences::CreateCategory(
1613 const wxString& name,
1614 const CPath& path,
1615 const wxString& comment,
1616 uint32 color,
1617 uint8 prio)
1619 Category_Struct *category = new Category_Struct();
1620 category->path = path;
1621 category->title = name;
1622 category->comment = comment;
1623 category->color = color;
1624 category->prio = prio;
1626 AddCat(category);
1628 SaveCats();
1630 return category;
1633 void CPreferences::UpdateCategory(
1634 uint8 cat,
1635 const wxString& name,
1636 const CPath& path,
1637 const wxString& comment,
1638 uint32 color,
1639 uint8 prio)
1641 Category_Struct *category = m_CatList[cat];
1643 category->path = path;
1644 category->title = name;
1645 category->comment = comment;
1646 category->color = color;
1647 category->prio = prio;
1649 SaveCats();
1653 wxString CPreferences::GetBrowser()
1655 wxString cmd(s_CustomBrowser);
1656 #ifndef __WXMSW__
1657 if( s_BrowserTab ) {
1658 // This is certainly not the best way to do it, but I'm lazy
1659 if ((wxT("mozilla") == cmd.Right(7)) || (wxT("firefox") == cmd.Right(7))
1660 || (wxT("MozillaFirebird") == cmd.Right(15))) {
1661 cmd += wxT(" -remote 'openURL(%s, new-tab)'");
1663 if ((wxT("galeon") == cmd.Right(6)) || (wxT("epiphany") == cmd.Right(8))) {
1664 cmd += wxT(" -n '%s'");
1666 if (wxT("opera") == cmd.Right(5)) {
1667 cmd += wxT(" --newpage '%s'");
1669 if (wxT("netscape") == cmd.Right(8)) {
1670 cmd += wxT(" -remote 'openURLs(%s,new-tab)'");
1673 #endif /* !__WXMSW__ */
1674 return cmd;
1678 #include "ClientList.h"
1679 #include "ServerList.h"
1680 void CPreferences::SetIPFilterLevel(uint8 level)
1682 if (level != s_filterlevel) {
1683 // We only need to recheck if the new level is more restrictive
1684 bool filter = level > s_filterlevel;
1686 // Set the new access-level
1687 s_filterlevel = level;
1689 if ( filter ) {
1690 theApp->clientlist->FilterQueues();
1691 theApp->serverlist->FilterServers();
1697 void CPreferences::SetPort(uint16 val)
1699 // Warning: Check for +3, because server UDP is TCP+3
1701 if (val +3 > 65535) {
1702 AddLogLineM(true, _("TCP port can't be higher than 65532 due to server UDP socket being TCP+3"));
1703 AddLogLineM(false, wxString::Format(_("Default port will be used (%d)"),DEFAULT_TCP_PORT));
1704 s_port = DEFAULT_TCP_PORT;
1705 } else {
1706 s_port = val;
1711 void CPreferences::ReloadSharedFolders()
1713 #ifndef CLIENT_GUI
1714 shareddir_list.clear();
1716 CTextFile file;
1717 if (file.Open(theApp->ConfigDir + wxT("shareddir.dat"), CTextFile::read)) {
1718 wxArrayString lines = file.ReadLines(txtReadDefault, wxConvUTF8);
1720 for (size_t i = 0; i < lines.size(); ++i) {
1721 CPath path = CPath::FromUniv(lines[i]);
1723 if (path.DirExists()) {
1724 shareddir_list.push_back(path);
1725 } else {
1726 AddLogLineN(CFormat(_("Dropping non-existing shared directory: %s")) % path.GetRaw());
1730 #endif
1734 bool CPreferences::IsMessageFiltered(const wxString& message)
1736 if (s_FilterAllMessages) {
1737 return true;
1738 } else {
1739 if (s_FilterSomeMessages) {
1740 if (s_MessageFilterString.IsSameAs(wxT("*"))){
1741 // Filter anything
1742 return true;
1743 } else {
1744 wxStringTokenizer tokenizer( s_MessageFilterString, wxT(",") );
1745 while (tokenizer.HasMoreTokens()) {
1746 if ( message.Lower().Trim(false).Trim(true).Contains(
1747 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1748 return true;
1751 return false;
1753 } else {
1754 return false;
1760 bool CPreferences::IsCommentFiltered(const wxString& comment)
1762 if (s_FilterComments) {
1763 wxStringTokenizer tokenizer( s_CommentFilterString, wxT(",") );
1764 while (tokenizer.HasMoreTokens()) {
1765 if ( comment.Lower().Trim(false).Trim(true).Contains(
1766 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1767 return true;
1771 return false;
1774 // File_checked_for_headers