2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "Preferences.h"
29 #include <protocol/ed2k/Constants.h>
30 #include <common/Constants.h>
31 #include <common/DataFileVersion.h>
33 #include <wx/config.h>
35 #include <wx/stdpaths.h>
36 #include <wx/stopwatch.h>
37 #include <wx/tokenzr.h>
41 #include "config.h" // Needed for PACKAGE_STRING
45 #include <common/MD5Sum.h>
47 #include <common/Format.h> // Needed for CFormat
48 #include <common/TextFile.h> // Needed for CTextFile
49 #include <common/ClientVersion.h>
51 #include "UserEvents.h"
54 #include <wx/valgen.h>
55 #include "muuli_wdr.h"
56 #include "StatisticsDlg.h"
59 #include "RandomFunctions.h"
60 #include "OtherFunctions.h"
62 #define DEFAULT_TCP_PORT 4662
65 COLORREF
CPreferences::s_colors
[cntStatColors
];
66 COLORREF
CPreferences::s_colors_ref
[cntStatColors
];
68 CPreferences::CFGMap
CPreferences::s_CfgList
;
69 CPreferences::CFGList
CPreferences::s_MiscList
;
73 CProxyData
CPreferences::s_ProxyData
;
75 /* The rest, organize it! */
76 wxString
CPreferences::s_nick
;
77 uint16
CPreferences::s_maxupload
;
78 uint16
CPreferences::s_maxdownload
;
79 uint16
CPreferences::s_slotallocation
;
80 wxString
CPreferences::s_Addr
;
81 uint16
CPreferences::s_port
;
82 uint16
CPreferences::s_udpport
;
83 bool CPreferences::s_UDPDisable
;
84 uint16
CPreferences::s_maxconnections
;
85 bool CPreferences::s_reconnect
;
86 bool CPreferences::s_autoconnect
;
87 bool CPreferences::s_autoconnectstaticonly
;
88 bool CPreferences::s_UPnPEnabled
;
89 bool CPreferences::s_UPnPECEnabled
;
90 bool CPreferences::s_UPnPWebServerEnabled
;
91 uint16
CPreferences::s_UPnPTCPPort
;
92 bool CPreferences::s_autoserverlist
;
93 bool CPreferences::s_deadserver
;
94 CPath
CPreferences::s_incomingdir
;
95 CPath
CPreferences::s_tempdir
;
96 bool CPreferences::s_ICH
;
97 uint8
CPreferences::s_depth3D
;
98 bool CPreferences::s_scorsystem
;
99 bool CPreferences::s_mintotray
;
100 bool CPreferences::s_trayiconenabled
;
101 bool CPreferences::s_addnewfilespaused
;
102 bool CPreferences::s_addserversfromserver
;
103 bool CPreferences::s_addserversfromclient
;
104 uint16
CPreferences::s_maxsourceperfile
;
105 uint16
CPreferences::s_trafficOMeterInterval
;
106 uint16
CPreferences::s_statsInterval
;
107 uint32
CPreferences::s_maxGraphDownloadRate
;
108 uint32
CPreferences::s_maxGraphUploadRate
;
109 bool CPreferences::s_confirmExit
;
110 bool CPreferences::s_filterLanIP
;
111 bool CPreferences::s_paranoidfilter
;
112 bool CPreferences::s_IPFilterSys
;
113 bool CPreferences::s_onlineSig
;
114 uint16
CPreferences::s_OSUpdate
;
115 uint64
CPreferences::s_totalDownloadedBytes
;
116 uint64
CPreferences::s_totalUploadedBytes
;
117 wxString
CPreferences::s_languageID
;
118 uint8
CPreferences::s_iSeeShares
;
119 uint8
CPreferences::s_iToolDelayTime
;
120 uint8
CPreferences::s_splitterbarPosition
;
121 uint16
CPreferences::s_deadserverretries
;
122 uint32
CPreferences::s_dwServerKeepAliveTimeoutMins
;
123 uint8
CPreferences::s_statsMax
;
124 uint8
CPreferences::s_statsAverageMinutes
;
125 bool CPreferences::s_bpreviewprio
;
126 bool CPreferences::s_smartidcheck
;
127 uint8
CPreferences::s_smartidstate
;
128 bool CPreferences::s_safeServerConnect
;
129 bool CPreferences::s_startMinimized
;
130 uint16
CPreferences::s_MaxConperFive
;
131 bool CPreferences::s_checkDiskspace
;
132 uint32
CPreferences::s_uMinFreeDiskSpace
;
133 wxString
CPreferences::s_yourHostname
;
134 bool CPreferences::s_bVerbose
;
135 bool CPreferences::s_bmanualhighprio
;
136 bool CPreferences::s_btransferfullchunks
;
137 bool CPreferences::s_bstartnextfile
;
138 bool CPreferences::s_bstartnextfilesame
;
139 bool CPreferences::s_bshowoverhead
;
140 bool CPreferences::s_bDAP
;
141 bool CPreferences::s_bUAP
;
142 bool CPreferences::s_bDisableKnownClientList
;
143 bool CPreferences::s_bDisableQueueList
;
144 bool CPreferences::s_ShowRatesOnTitle
;
145 wxString
CPreferences::s_VideoPlayer
;
146 bool CPreferences::s_moviePreviewBackup
;
147 bool CPreferences::s_indicateratings
;
148 bool CPreferences::s_showAllNotCats
;
149 bool CPreferences::s_msgonlyfriends
;
150 bool CPreferences::s_msgsecure
;
151 uint8
CPreferences::s_filterlevel
;
152 uint8
CPreferences::s_iFileBufferSize
;
153 uint8
CPreferences::s_iQueueSize
;
154 uint16
CPreferences::s_maxmsgsessions
;
155 wxString
CPreferences::s_datetimeformat
;
156 wxString
CPreferences::s_sWebPassword
;
157 wxString
CPreferences::s_sWebLowPassword
;
158 uint16
CPreferences::s_nWebPort
;
159 uint16
CPreferences::s_nWebUPnPTCPPort
;
160 bool CPreferences::s_bWebEnabled
;
161 bool CPreferences::s_bWebUseGzip
;
162 uint32
CPreferences::s_nWebPageRefresh
;
163 bool CPreferences::s_bWebLowEnabled
;
164 wxString
CPreferences::s_WebTemplate
;
165 bool CPreferences::s_showCatTabInfos
;
166 uint32
CPreferences::s_allcatType
;
167 uint8
CPreferences::s_NoNeededSources
;
168 bool CPreferences::s_DropFullQueueSources
;
169 bool CPreferences::s_DropHighQueueRankingSources
;
170 uint32
CPreferences::s_HighQueueRanking
;
171 uint32
CPreferences::s_AutoDropTimer
;
172 bool CPreferences::s_AcceptExternalConnections
;
173 wxString
CPreferences::s_ECAddr
;
174 uint32
CPreferences::s_ECPort
;
175 wxString
CPreferences::s_ECPassword
;
176 bool CPreferences::s_IPFilterClients
;
177 bool CPreferences::s_IPFilterServers
;
178 bool CPreferences::s_UseSrcSeeds
;
179 bool CPreferences::s_ProgBar
;
180 bool CPreferences::s_Percent
;
181 bool CPreferences::s_SecIdent
;
182 bool CPreferences::s_ExtractMetaData
;
183 bool CPreferences::s_AllocFullPart
;
184 bool CPreferences::s_AllocFullChunk
;
185 uint16
CPreferences::s_Browser
;
186 wxString
CPreferences::s_CustomBrowser
;
187 bool CPreferences::s_BrowserTab
;
188 CPath
CPreferences::s_OSDirectory
;
189 wxString
CPreferences::s_Skin
;
190 bool CPreferences::s_UseSkinFiles
;
191 bool CPreferences::s_FastED2KLinksHandler
;
192 bool CPreferences::s_ToolbarOrientation
;
193 bool CPreferences::s_ShowPartFileNumber
;
194 bool CPreferences::s_AICHTrustEveryHash
;
195 wxString
CPreferences::s_CommentFilterString
;
196 bool CPreferences::s_IPFilterAutoLoad
;
197 wxString
CPreferences::s_IPFilterURL
;
198 CMD4Hash
CPreferences::s_userhash
;
199 bool CPreferences::s_MustFilterMessages
;
200 wxString
CPreferences::s_MessageFilterString
;
201 bool CPreferences::s_FilterAllMessages
;
202 bool CPreferences::s_FilterComments
;
203 bool CPreferences::s_FilterSomeMessages
;
204 bool CPreferences::s_ShareHiddenFiles
;
205 bool CPreferences::s_AutoSortDownload
;
206 bool CPreferences::s_NewVersionCheck
;
207 bool CPreferences::s_ConnectToKad
;
208 bool CPreferences::s_ConnectToED2K
;
209 unsigned CPreferences::s_maxClientVersions
;
210 bool CPreferences::s_DropSlowSources
;
211 bool CPreferences::s_IsClientCryptLayerSupported
;
212 bool CPreferences::s_bCryptLayerRequested
;
213 bool CPreferences::s_IsClientCryptLayerRequired
;
214 uint32
CPreferences::s_dwKadUDPKey
;
215 uint8
CPreferences::s_byCryptTCPPaddingLength
;
217 wxString
CPreferences::s_Ed2kURL
;
218 wxString
CPreferences::s_KadURL
;
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
233 template <typename TYPE
>
234 class Cfg_Tmpl
: public Cfg_Base
244 Cfg_Tmpl( const wxString
& keyname
, TYPE
& value
, const TYPE
& defaultVal
)
245 : Cfg_Base( keyname
),
247 m_default( defaultVal
),
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
)
266 m_widget
= wxWindow::FindWindowById( id
, parent
);
269 wxGenericValidator
validator( &m_value
);
271 m_widget
->SetValidator( validator
);
283 /** Updates the assosiated variable, returning true on success. */
284 virtual bool TransferFromWindow()
287 wxValidator
* validator
= m_widget
->GetValidator();
292 if ( validator
->TransferFromWindow() ) {
293 SetChanged( temp
!= m_value
);
303 /** Updates the assosiated widget, returning true on success. */
304 virtual bool TransferToWindow()
307 wxValidator
* validator
= m_widget
->GetValidator();
310 return validator
->TransferToWindow();
318 /** Sets the default value. */
319 void SetDefault(const TYPE
& defaultVal
)
321 m_default
= defaultVal
;
325 //! Reference to the associated variable
328 //! Default variable value
331 //! Pointer to the widget assigned to the Cfg instance
336 /** Cfg class for wxStrings. */
337 class Cfg_Str
: public Cfg_Tmpl
<wxString
>
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
366 Cfg_Str_Encrypted( const wxString
& keyname
, wxString
& value
, const wxString
& defaultVal
= wxEmptyString
)
367 : Cfg_Str( keyname
, value
, defaultVal
)
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();
391 /** Cfg class for CPath. */
392 class Cfg_Path
: public Cfg_Str
396 Cfg_Path(const wxString
& keyname
, CPath
& value
, const wxString
& defaultVal
= wxEmptyString
)
397 : Cfg_Str(keyname
, m_temp_path
, defaultVal
)
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
);
439 wxString m_temp_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
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>
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
)
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
);
489 virtual bool TransferFromWindow()
491 if ( Cfg_Tmpl
<int>::TransferFromWindow() ) {
492 m_real_value
= (TYPE
)m_temp_value
;
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
);
509 int id
= m_widget
->GetId();
510 int pos
= slider
->GetValue();
511 wxScrollEvent
evt( wxEVT_SCROLL_THUMBRELEASE
, id
, pos
);
512 m_widget
->ProcessEvent( evt
);
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>
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 assisiated widgets.
575 class Cfg_Counter
: public Cfg_Base
578 Cfg_Counter( const wxString
& keyname
, uint64
& value
)
579 : Cfg_Base( keyname
),
583 virtual void LoadFromFile(wxConfigBase
* cfg
)
587 cfg
->Read( GetKey(), &buffer
, wxT("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'));
601 virtual void SaveToFile(wxConfigBase
* cfg
)
603 wxString str
= CFormat( wxT("%llu") ) % m_value
;
605 cfg
->Write( GetKey(), str
);
624 * The languages aMule has translation for.
626 * Add new languages here, as this list overrides the one defined in muuli.wdr
628 static LangInfo aMuleLanguages
[] = {
629 { wxLANGUAGE_DEFAULT
, true, wxTRANSLATE("System default") },
630 { wxLANGUAGE_ARABIC
, true, wxTRANSLATE("Arabic") },
631 { wxLANGUAGE_BASQUE
, true, wxTRANSLATE("Basque") },
632 { wxLANGUAGE_BULGARIAN
, true, wxTRANSLATE("Bulgarian") },
633 { wxLANGUAGE_CATALAN
, true, wxTRANSLATE("Catalan") },
634 { wxLANGUAGE_CHINESE_SIMPLIFIED
, true, wxTRANSLATE("Chinese (Simplified)") },
635 { wxLANGUAGE_CHINESE_TRADITIONAL
, true, wxTRANSLATE("Chinese (Traditional)") },
636 { wxLANGUAGE_CROATIAN
, true, wxTRANSLATE("Croatian") },
637 { wxLANGUAGE_CZECH
, true, wxTRANSLATE("Czech") },
638 { wxLANGUAGE_DANISH
, true, wxTRANSLATE("Danish") },
639 { wxLANGUAGE_DUTCH
, true, wxTRANSLATE("Dutch") },
640 { wxLANGUAGE_ENGLISH_UK
, true, wxTRANSLATE("English (U.K.)") },
641 // Unmaintained language file: en_US.po
642 // { wxLANGUAGE_ENGLISH_US, true, wxTRANSLATE("English (U.S.)") },
643 { wxLANGUAGE_ESTONIAN
, true, wxTRANSLATE("Estonian") },
644 { wxLANGUAGE_FINNISH
, true, wxTRANSLATE("Finnish") },
645 { wxLANGUAGE_FRENCH
, true, wxTRANSLATE("French") },
646 { wxLANGUAGE_GALICIAN
, true, wxTRANSLATE("Galician") },
647 { wxLANGUAGE_GERMAN
, true, wxTRANSLATE("German") },
648 { wxLANGUAGE_GREEK
, true, wxTRANSLATE("Greek") },
649 { wxLANGUAGE_HUNGARIAN
, true, wxTRANSLATE("Hungarian") },
650 { wxLANGUAGE_ITALIAN
, true, wxTRANSLATE("Italian") },
651 { wxLANGUAGE_ITALIAN_SWISS
, true, wxTRANSLATE("Italian (Swiss)") },
652 { wxLANGUAGE_JAPANESE
, true, wxTRANSLATE("Japanese") },
653 { wxLANGUAGE_KOREAN
, true, wxTRANSLATE("Korean") },
654 { wxLANGUAGE_LITHUANIAN
, true, wxTRANSLATE("Lithuanian") },
655 { wxLANGUAGE_NORWEGIAN_NYNORSK
, true, wxTRANSLATE("Norwegian (Nynorsk)") }, // nn_NO would be the full id
656 { wxLANGUAGE_POLISH
, true, wxTRANSLATE("Polish") },
657 { wxLANGUAGE_PORTUGUESE
, true, wxTRANSLATE("Portuguese") },
658 { wxLANGUAGE_PORTUGUESE_BRAZILIAN
, true, wxTRANSLATE("Portuguese (Brazilian)") },
659 { wxLANGUAGE_RUSSIAN
, true, wxTRANSLATE("Russian") },
660 { wxLANGUAGE_SLOVENIAN
, true, wxTRANSLATE("Slovenian") },
661 { wxLANGUAGE_SPANISH
, true, wxTRANSLATE("Spanish") },
662 { wxLANGUAGE_SWEDISH
, true, wxTRANSLATE("Swedish") },
663 // Unmaintained language file: es_MX.po
664 // { wxLANGUAGE_SPANISH_MEXICAN, true, wxTRANSLATE("Spanish (Mexican)") },
665 { wxLANGUAGE_TURKISH
, true, wxTRANSLATE("Turkish") },
666 // Yet no real support for "custom"
667 // { wxLANGUAGE_CUSTOM, true, wxTRANSLATE("Custom") },
671 bool TranslatedSort( const LangInfo
& a
, const LangInfo
& b
) {
672 return wxStricmp( wxGetTranslation( a
.name
), wxGetTranslation( b
.name
) ) < 0;
675 typedef Cfg_Int
<int> Cfg_PureInt
;
677 class Cfg_Lang
: public Cfg_PureInt
681 : Cfg_PureInt( wxEmptyString
, m_selection
, 0 )
685 virtual void LoadFromFile(wxConfigBase
* WXUNUSED(cfg
)) {}
686 virtual void SaveToFile(wxConfigBase
* WXUNUSED(cfg
)) {}
689 virtual bool TransferFromWindow()
691 if ( Cfg_PureInt::TransferFromWindow() ) {
692 // find wx ID of selected language
694 while (m_selection
> 0) {
696 if (aMuleLanguages
[i
].available
) {
700 int id
= aMuleLanguages
[i
].id
;
702 // save language selection
703 thePrefs::SetLanguageID(wxLang2Str(id
));
712 virtual bool TransferToWindow()
714 // Sort the list after the current locale
715 std::sort( aMuleLanguages
+ 1, // Dont include DEFAULT
716 aMuleLanguages
+ itemsof(aMuleLanguages
),
719 wxChoice
*langSelector
= dynamic_cast<wxChoice
*>(m_widget
);
720 // clear existing list
721 langSelector
->Clear();
724 int wxId
= StrLang2wx(thePrefs::GetLanguageID());
726 // Add all other languages in alphabetical order
727 // and find the index of the selected language.
728 for ( unsigned int i
= 0, j
= 0; i
< itemsof(aMuleLanguages
); i
++) {
729 if ((aMuleLanguages
[i
].available
= IsLocaleAvailable(aMuleLanguages
[i
].id
)) == true) {
730 langSelector
->Append( wxGetTranslation(aMuleLanguages
[i
].name
) );
731 if ( aMuleLanguages
[i
].id
== wxId
) {
738 // Restore original locale
741 InitLocale(tmpLocale
, theApp
->m_locale
.GetLanguage());
744 return Cfg_PureInt::TransferToWindow();
752 #endif /* ! AMULE_DAEMON */
754 class Cfg_Skin
: public Cfg_Str
757 // Cfg_Tmpl( const wxString& keyname, TYPE& value, const TYPE& defaultVal )
758 // : Cfg_Base( keyname ),
760 // m_default( defaultVal ),
763 // Cfg_Str( const wxString& keyname, wxString& value, const wxString& defaultVal = wxEmptyString )
764 // : Cfg_Tmpl<wxString>( keyname, value, defaultVal )
766 Cfg_Skin( const wxString
& keyname
, wxString
& value
, const wxString
& defaultVal
= wxEmptyString
)
767 : Cfg_Str( keyname
, value
, defaultVal
)
772 virtual bool TransferFromWindow()
774 if ( Cfg_Str::TransferFromWindow() ) {
782 virtual bool TransferToWindow()
785 wxChoice
*skinSelector
= dynamic_cast<wxChoice
*>(m_widget
);
786 skinSelector
->Clear();
790 int flags
= wxDIR_DIRS
;
791 wxString filespec
= wxEmptyString
;
792 //#warning there has to be a better way...
793 if ( GetKey() == wxT("/SkinGUIOptions/Skin") ) {
794 folder
= wxT("skins");
797 filespec
= wxT("*.zip");
799 folder
= wxT("webserver");
801 wxString
dirName(JoinPaths(GetConfigDir(), folder
));
805 if (wxDir::Exists(dirName
) &&
807 d
.GetFirst(& Filename
, filespec
, flags
)
813 Filename
= wxT("User:") + Filename
;
815 skinSelector
->Append(Filename
);
817 while (d
.GetNext(&Filename
));
820 wxStandardPathsBase
&spb(wxStandardPaths::Get());
822 wxString
dataDir(spb
.GetPluginsDir());
823 #elif defined(__WXMAC__)
824 wxString
dataDir(spb
.GetDataDir());
826 wxString
dataDir(spb
.GetDataDir().BeforeLast(wxT('/')) + wxT("/amule"));
828 wxString
systemDir(JoinPaths(dataDir
,folder
));
830 if (wxDir::Exists(systemDir
) &&
832 d
.GetFirst(& Filename
, filespec
, flags
)
838 Filename
= wxT("System:") + Filename
;
840 // avoid duplicates for webserver templates
841 if (skinSelector
->FindString(Filename
) == wxNOT_FOUND
) {
842 skinSelector
->Append(Filename
);
845 while (d
.GetNext(&Filename
));
848 if ( skinSelector
->GetCount() == 0 ) {
849 skinSelector
->Append(wxT("no options available"));
852 int id
= skinSelector
->FindString(m_value
);
853 if ( id
== wxNOT_FOUND
) {
856 skinSelector
->SetSelection(id
);
858 return Cfg_Str::TransferToWindow();
860 #endif /* ! AMULE_DAEMON */
865 /// new implementation
866 CPreferences::CPreferences()
868 srand( wxGetLocalTimeMillis().GetLo() ); // we need random numbers sometimes
870 // load preferences.dat or set standart values
871 wxString
fullpath(theApp
->ConfigDir
+ wxT("preferences.dat"));
873 if (wxFileExists(fullpath
)) {
874 if (preffile
.Open(fullpath
, CFile::read
)) {
876 preffile
.ReadUInt8(); // Version. Value is not used.
877 s_userhash
= preffile
.ReadHash();
878 } catch (const CSafeIOException
& e
) {
879 AddDebugLogLineM(true, logGeneral
,
880 wxT("Error while reading userhash: ") + e
.what());
885 if (s_userhash
.IsEmpty()) {
886 for (int i
= 0; i
< 8; i
++) {
887 RawPokeUInt16(s_userhash
.GetHash() + (i
* 2), rand());
893 // Mark hash as an eMule-type hash
894 // See also CUpDownClient::GetHashType
896 s_userhash
[14] = 111;
900 ReloadSharedFolders();
902 // serverlist adresses
904 if (slistfile
.Open(theApp
->ConfigDir
+ wxT("addresses.dat"), CTextFile::read
)) {
905 adresses_list
= slistfile
.ReadLines();
911 // Gets called at init time
913 void CPreferences::BuildItemList( const wxString
& appdir
)
916 #define NewCfgItem(ID, COMMAND) s_CfgList[ID] = COMMAND
919 #define NewCfgItem(ID, COMMAND) s_CfgList[++current_id] = COMMAND
920 #endif /* AMULE_DAEMON */
925 NewCfgItem(IDC_NICK
, (new Cfg_Str( wxT("/eMule/Nick"), s_nick
, wxT("http://www.aMule.org") )));
927 NewCfgItem(IDC_LANGUAGE
, (new Cfg_Lang()));
934 int browser
= 8; // this is a "magic number" and will break if
935 // more browser choices are added in the interface,
936 // but there isn't a symbolic name defined
937 wxString customBrowser
= wxT("/usr/bin/open");
940 wxString customBrowser
; // left empty
943 NewCfgItem(IDC_BROWSER
, (MkCfg_Int( wxT("/FakeCheck/Browser"), s_Browser
, browser
)));
944 NewCfgItem(IDC_BROWSERTABS
, (new Cfg_Bool( wxT("/FakeCheck/BrowserTab"), s_BrowserTab
, true )));
945 NewCfgItem(IDC_BROWSERSELF
, (new Cfg_Str( wxT("/FakeCheck/CustomBrowser"), s_CustomBrowser
, customBrowser
)));
946 NewCfgItem(IDC_QUEUESIZE
, (MkCfg_Int( wxT("/eMule/QueueSizePref"), s_iQueueSize
, 50 )));
953 NewCfgItem(ID_VERBOSEDEBUG
, (new Cfg_Bool( wxT("/eMule/VerboseDebug"), s_bVerbose
, false )));
957 * Connection settings
959 NewCfgItem(IDC_MAXUP
, (MkCfg_Int( wxT("/eMule/MaxUpload"), s_maxupload
, 0 )));
960 NewCfgItem(IDC_MAXDOWN
, (MkCfg_Int( wxT("/eMule/MaxDownload"), s_maxdownload
, 0 )));
961 NewCfgItem(IDC_SLOTALLOC
, (MkCfg_Int( wxT("/eMule/SlotAllocation"), s_slotallocation
, 2 )));
962 NewCfgItem(IDC_PORT
, (MkCfg_Int( wxT("/eMule/Port"), s_port
, DEFAULT_TCP_PORT
)));
963 NewCfgItem(IDC_UDPPORT
, (MkCfg_Int( wxT("/eMule/UDPPort"), s_udpport
, 4672 )));
964 NewCfgItem(IDC_UDPDISABLE
, (new Cfg_Bool( wxT("/eMule/UDPDisable"), s_UDPDisable
, false )));
965 NewCfgItem(IDC_ADDRESS
, (new Cfg_Str( wxT("/eMule/Address"), s_Addr
, wxEmptyString
)));
966 NewCfgItem(IDC_AUTOCONNECT
, (new Cfg_Bool( wxT("/eMule/Autoconnect"), s_autoconnect
, true )));
967 NewCfgItem(IDC_MAXSOURCEPERFILE
, (MkCfg_Int( wxT("/eMule/MaxSourcesPerFile"), s_maxsourceperfile
, 300 )));
968 NewCfgItem(IDC_MAXCON
, (MkCfg_Int( wxT("/eMule/MaxConnections"), s_maxconnections
, GetRecommendedMaxConnections() )));
969 NewCfgItem(IDC_MAXCON5SEC
, (MkCfg_Int( wxT("/eMule/MaxConnectionsPerFiveSeconds"), s_MaxConperFive
, 20 )));
974 NewCfgItem(ID_PROXY_ENABLE_PROXY
, (new Cfg_Bool( wxT("/Proxy/ProxyEnableProxy"), s_ProxyData
.m_proxyEnable
, false )));
975 NewCfgItem(ID_PROXY_TYPE
, (MkCfg_Int( wxT("/Proxy/ProxyType"), s_ProxyData
.m_proxyType
, 0 )));
976 NewCfgItem(ID_PROXY_NAME
, (new Cfg_Str( wxT("/Proxy/ProxyName"), s_ProxyData
.m_proxyHostName
, wxEmptyString
)));
977 NewCfgItem(ID_PROXY_PORT
, (MkCfg_Int( wxT("/Proxy/ProxyPort"), s_ProxyData
.m_proxyPort
, 1080 )));
978 NewCfgItem(ID_PROXY_ENABLE_PASSWORD
, (new Cfg_Bool( wxT("/Proxy/ProxyEnablePassword"), s_ProxyData
.m_enablePassword
, false )));
979 NewCfgItem(ID_PROXY_USER
, (new Cfg_Str( wxT("/Proxy/ProxyUser"), s_ProxyData
.m_userName
, wxEmptyString
)));
980 NewCfgItem(ID_PROXY_PASSWORD
, (new Cfg_Str( wxT("/Proxy/ProxyPassword"), s_ProxyData
.m_password
, wxEmptyString
)));
981 // These were copied from eMule config file, maybe someone with windows can complete this?
982 // NewCfgItem(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY, (new Cfg_Bool( wxT("/Proxy/Proxy????"), s_Proxy????, false )));
987 NewCfgItem(IDC_REMOVEDEAD
, (new Cfg_Bool( wxT("/eMule/RemoveDeadServer"), s_deadserver
, 1 )));
988 NewCfgItem(IDC_SERVERRETRIES
, (MkCfg_Int( wxT("/eMule/DeadServerRetry"), s_deadserverretries
, 2 )));
989 NewCfgItem(IDC_SERVERKEEPALIVE
, (MkCfg_Int( wxT("/eMule/ServerKeepAliveTimeout"), s_dwServerKeepAliveTimeoutMins
, 0 )));
990 NewCfgItem(IDC_RECONN
, (new Cfg_Bool( wxT("/eMule/Reconnect"), s_reconnect
, true )));
991 NewCfgItem(IDC_SCORE
, (new Cfg_Bool( wxT("/eMule/Scoresystem"), s_scorsystem
, true )));
992 NewCfgItem(IDC_AUTOSERVER
, (new Cfg_Bool( wxT("/eMule/Serverlist"), s_autoserverlist
, false )));
993 NewCfgItem(IDC_UPDATESERVERCONNECT
, (new Cfg_Bool( wxT("/eMule/AddServersFromServer"), s_addserversfromserver
, true)));
994 NewCfgItem(IDC_UPDATESERVERCLIENT
, (new Cfg_Bool( wxT("/eMule/AddServersFromClient"), s_addserversfromclient
, true )));
995 NewCfgItem(IDC_SAFESERVERCONNECT
, (new Cfg_Bool( wxT("/eMule/SafeServerConnect"), s_safeServerConnect
, false )));
996 NewCfgItem(IDC_AUTOCONNECTSTATICONLY
, (new Cfg_Bool( wxT("/eMule/AutoConnectStaticOnly"), s_autoconnectstaticonly
, false )));
997 NewCfgItem(IDC_UPNP_ENABLED
, (new Cfg_Bool( wxT("/eMule/UPnPEnabled"), s_UPnPEnabled
, false )));
998 NewCfgItem(IDC_UPNPTCPPORT
, (MkCfg_Int( wxT("/eMule/UPnPTCPPort"), s_UPnPTCPPort
, 50000 )));
999 NewCfgItem(IDC_SMARTIDCHECK
, (new Cfg_Bool( wxT("/eMule/SmartIdCheck"), s_smartidcheck
, true )));
1001 NewCfgItem( IDC_NETWORKKAD
, (new Cfg_Bool( wxT("/eMule/ConnectToKad"), s_ConnectToKad
, true )) );
1002 NewCfgItem( IDC_NETWORKED2K
, ( new Cfg_Bool( wxT("/eMule/ConnectToED2K"), s_ConnectToED2K
, true ) ));
1008 NewCfgItem(IDC_TEMPFILES
, (new Cfg_Path( wxT("/eMule/TempDir"), s_tempdir
, appdir
+ wxT("Temp") )));
1010 #if defined(__WXMAC__) || defined(__WINDOWS__)
1011 wxString incpath
= wxStandardPaths::Get().GetDocumentsDir();
1012 if (incpath
.IsEmpty()) {
1013 // There is a built-in possibility for this call to fail, though I can't imagine a reason for that.
1014 incpath
= appdir
+ wxT("Incoming");
1016 incpath
= JoinPaths(incpath
, wxT("aMule Downloads"));
1019 wxString incpath
= appdir
+ wxT("Incoming");
1021 NewCfgItem(IDC_INCFILES
, (new Cfg_Path( wxT("/eMule/IncomingDir"), s_incomingdir
, incpath
)));
1023 NewCfgItem(IDC_ICH
, (new Cfg_Bool( wxT("/eMule/ICH"), s_ICH
, true )));
1024 NewCfgItem(IDC_AICHTRUST
, (new Cfg_Bool( wxT("/eMule/AICHTrust"), s_AICHTrustEveryHash
, false )));
1025 NewCfgItem(IDC_CHECKDISKSPACE
, (new Cfg_Bool( wxT("/eMule/CheckDiskspace"), s_checkDiskspace
, true )));
1026 NewCfgItem(IDC_MINDISKSPACE
, (MkCfg_Int( wxT("/eMule/MinFreeDiskSpace"), s_uMinFreeDiskSpace
, 1 )));
1027 NewCfgItem(IDC_ADDNEWFILESPAUSED
, (new Cfg_Bool( wxT("/eMule/AddNewFilesPaused"), s_addnewfilespaused
, false )));
1028 NewCfgItem(IDC_PREVIEWPRIO
, (new Cfg_Bool( wxT("/eMule/PreviewPrio"), s_bpreviewprio
, false )));
1029 NewCfgItem(IDC_MANUALSERVERHIGHPRIO
, (new Cfg_Bool( wxT("/eMule/ManualHighPrio"), s_bmanualhighprio
, false )));
1030 NewCfgItem(IDC_FULLCHUNKTRANS
, (new Cfg_Bool( wxT("/eMule/FullChunkTransfers"), s_btransferfullchunks
, true )));
1031 NewCfgItem(IDC_STARTNEXTFILE
, (new Cfg_Bool( wxT("/eMule/StartNextFile"), s_bstartnextfile
, false )));
1032 NewCfgItem(IDC_STARTNEXTFILE_SAME
, (new Cfg_Bool( wxT("/eMule/StartNextFileSameCat"), s_bstartnextfilesame
, false )));
1033 NewCfgItem(IDC_FILEBUFFERSIZE
, (MkCfg_Int( wxT("/eMule/FileBufferSizePref"), s_iFileBufferSize
, 16 )));
1034 NewCfgItem(IDC_DAP
, (new Cfg_Bool( wxT("/eMule/DAPPref"), s_bDAP
, true )));
1035 NewCfgItem(IDC_UAP
, (new Cfg_Bool( wxT("/eMule/UAPPref"), s_bUAP
, true )));
1040 NewCfgItem(IDC_OSDIR
, (new Cfg_Path( wxT("/eMule/OSDirectory"), s_OSDirectory
, appdir
)));
1041 NewCfgItem(IDC_ONLINESIG
, (new Cfg_Bool( wxT("/eMule/OnlineSignature"), s_onlineSig
, false )));
1042 NewCfgItem(IDC_OSUPDATE
, (MkCfg_Int( wxT("/eMule/OnlineSignatureUpdate"), s_OSUpdate
, 5 )));
1043 NewCfgItem(IDC_ENABLE_WEB
, (new Cfg_Bool( wxT("/WebServer/Enabled"), s_bWebEnabled
, false )));
1044 NewCfgItem(IDC_WEB_PASSWD
, (new Cfg_Str_Encrypted( wxT("/WebServer/Password"), s_sWebPassword
)));
1045 NewCfgItem(IDC_WEB_PASSWD_LOW
, (new Cfg_Str_Encrypted( wxT("/WebServer/PasswordLow"), s_sWebLowPassword
)));
1046 NewCfgItem(IDC_WEB_PORT
, (MkCfg_Int( wxT("/WebServer/Port"), s_nWebPort
, 4711 )));
1047 NewCfgItem(IDC_WEBUPNPTCPPORT
, (MkCfg_Int( wxT("/WebServer/WebUPnPTCPPort"), s_nWebUPnPTCPPort
, 50001 )));
1048 NewCfgItem(IDC_UPNP_WEBSERVER_ENABLED
,
1049 (new Cfg_Bool( wxT("/WebServer/UPnPWebServerEnabled"), s_UPnPWebServerEnabled
, false )));
1050 NewCfgItem(IDC_WEB_GZIP
, (new Cfg_Bool( wxT("/WebServer/UseGzip"), s_bWebUseGzip
, true )));
1051 NewCfgItem(IDC_ENABLE_WEB_LOW
, (new Cfg_Bool( wxT("/WebServer/UseLowRightsUser"), s_bWebLowEnabled
, false )));
1052 NewCfgItem(IDC_WEB_REFRESH_TIMEOUT
, (MkCfg_Int( wxT("/WebServer/PageRefreshTime"), s_nWebPageRefresh
, 120 )));
1053 NewCfgItem(IDC_WEBTEMPLATE
, (new Cfg_Skin( wxT("/WebServer/Template"), s_WebTemplate
, wxEmptyString
)));
1056 * External Connections
1058 NewCfgItem(IDC_EXT_CONN_ACCEPT
, (new Cfg_Bool( wxT("/ExternalConnect/AcceptExternalConnections"), s_AcceptExternalConnections
, false )));
1059 NewCfgItem(IDC_EXT_CONN_IP
, (new Cfg_Str( wxT("/ExternalConnect/ECAddress"), s_ECAddr
, wxEmptyString
)));
1060 NewCfgItem(IDC_EXT_CONN_TCP_PORT
, (MkCfg_Int( wxT("/ExternalConnect/ECPort"), s_ECPort
, 4712 )));
1061 NewCfgItem(IDC_EXT_CONN_PASSWD
, (new Cfg_Str_Encrypted( wxT("/ExternalConnect/ECPassword"), s_ECPassword
, wxEmptyString
)));
1062 NewCfgItem(IDC_UPNP_EC_ENABLED
, (new Cfg_Bool( wxT("/ExternalConnect/UPnPECEnabled"), s_UPnPECEnabled
, false )));
1067 NewCfgItem(IDC_ENABLETRAYICON
, (new Cfg_Bool( wxT("/eMule/EnableTrayIcon"), s_trayiconenabled
, false )));
1068 NewCfgItem(IDC_MINTRAY
, (new Cfg_Bool( wxT("/eMule/MinToTray"), s_mintotray
, false )));
1069 NewCfgItem(IDC_EXIT
, (new Cfg_Bool( wxT("/eMule/ConfirmExit"), s_confirmExit
, false )));
1070 NewCfgItem(IDC_STARTMIN
, (new Cfg_Bool( wxT("/eMule/StartupMinimized"), s_startMinimized
, false )));
1075 NewCfgItem(IDC_3DDEPTH
, (MkCfg_Int( wxT("/eMule/3DDepth"), s_depth3D
, 10 )));
1076 NewCfgItem(IDC_TOOLTIPDELAY
, (MkCfg_Int( wxT("/eMule/ToolTipDelay"), s_iToolDelayTime
, 1 )));
1077 NewCfgItem(IDC_SHOWOVERHEAD
, (new Cfg_Bool( wxT("/eMule/ShowOverhead"), s_bshowoverhead
, false )));
1078 NewCfgItem(IDC_EXTCATINFO
, (new Cfg_Bool( wxT("/eMule/ShowInfoOnCatTabs"), s_showCatTabInfos
, false )));
1079 NewCfgItem(IDC_FED2KLH
, (new Cfg_Bool( wxT("/Razor_Preferences/FastED2KLinksHandler"), s_FastED2KLinksHandler
, true )));
1080 NewCfgItem(IDC_PROGBAR
, (new Cfg_Bool( wxT("/ExternalConnect/ShowProgressBar"), s_ProgBar
, true )));
1081 NewCfgItem(IDC_PERCENT
, (new Cfg_Bool( wxT("/ExternalConnect/ShowPercent"), s_Percent
, false )));
1082 NewCfgItem(IDC_USESKINFILES
, (new Cfg_Bool( wxT("/SkinGUIOptions/UseSkinFiles"), s_UseSkinFiles
, false )));
1083 NewCfgItem(IDC_SKIN
, (new Cfg_Skin( wxT("/SkinGUIOptions/Skin"), s_Skin
, wxEmptyString
)));
1084 NewCfgItem(IDC_SHOWRATEONTITLE
, (new Cfg_Bool( wxT("/eMule/ShowRatesOnTitle"), s_ShowRatesOnTitle
, false )));
1085 NewCfgItem(IDC_VERTTOOLBAR
, (new Cfg_Bool( wxT("/eMule/VerticalToolbar"), s_ToolbarOrientation
, false )));
1086 NewCfgItem(IDC_SHOWPARTFILENUMBER
,(new Cfg_Bool( wxT("/eMule/ShowPartFileNumber"), s_ShowPartFileNumber
, false )));
1091 NewCfgItem(IDC_VIDEOPLAYER
, (new Cfg_Str( wxT("/eMule/VideoPlayer"), s_VideoPlayer
, wxEmptyString
)));
1092 NewCfgItem(IDC_VIDEOBACKUP
, (new Cfg_Bool( wxT("/eMule/VideoPreviewBackupped"), s_moviePreviewBackup
, true )));
1097 NewCfgItem(IDC_SLIDER
, (MkCfg_Int( wxT("/eMule/StatGraphsInterval"), s_trafficOMeterInterval
, 3 )));
1098 NewCfgItem(IDC_SLIDER2
, (MkCfg_Int( wxT("/eMule/statsInterval"), s_statsInterval
, 30 )));
1099 NewCfgItem(IDC_DOWNLOAD_CAP
, (MkCfg_Int( wxT("/eMule/DownloadCapacity"), s_maxGraphDownloadRate
, 3 )));
1100 NewCfgItem(IDC_UPLOAD_CAP
, (MkCfg_Int( wxT("/eMule/UploadCapacity"), s_maxGraphUploadRate
, 3 )));
1101 NewCfgItem(IDC_SLIDER3
, (MkCfg_Int( wxT("/eMule/StatsAverageMinutes"), s_statsAverageMinutes
, 5 )));
1102 NewCfgItem(IDC_SLIDER4
, (MkCfg_Int( wxT("/eMule/VariousStatisticsMaxValue"), s_statsMax
, 100 )));
1103 NewCfgItem(IDC_CLIENTVERSIONS
, (MkCfg_Int( wxT("/Statistics/MaxClientVersions"), s_maxClientVersions
, 0 )));
1108 NewCfgItem(IDC_SEESHARES
, (MkCfg_Int( wxT("/eMule/SeeShare"), s_iSeeShares
, 2 )));
1109 NewCfgItem(IDC_SECIDENT
, (new Cfg_Bool( wxT("/ExternalConnect/UseSecIdent"), s_SecIdent
, true )));
1110 NewCfgItem(IDC_IPFCLIENTS
, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterClients"), s_IPFilterClients
, true )));
1111 NewCfgItem(IDC_IPFSERVERS
, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterServers"), s_IPFilterServers
, true )));
1112 NewCfgItem(IDC_FILTERLAN
, (new Cfg_Bool( wxT("/eMule/FilterLanIPs"), s_filterLanIP
, true )));
1113 NewCfgItem(IDC_PARANOID
, (new Cfg_Bool( wxT("/eMule/ParanoidFiltering"), s_paranoidfilter
, true )));
1114 NewCfgItem(IDC_AUTOIPFILTER
, (new Cfg_Bool( wxT("/eMule/IPFilterAutoLoad"), s_IPFilterAutoLoad
, true )));
1115 NewCfgItem(IDC_IPFILTERURL
, (new Cfg_Str( wxT("/eMule/IPFilterURL"), s_IPFilterURL
, wxEmptyString
)));
1116 NewCfgItem(ID_IPFILTERLEVEL
, (MkCfg_Int( wxT("/eMule/FilterLevel"), s_filterlevel
, 127 )));
1117 NewCfgItem(IDC_IPFILTERSYS
, (new Cfg_Bool( wxT("/eMule/IPFilterSystem"), s_IPFilterSys
, false )));
1122 NewCfgItem(IDC_MSGFILTER
, (new Cfg_Bool( wxT("/eMule/FilterMessages"), s_MustFilterMessages
, false )));
1123 NewCfgItem(IDC_MSGFILTER_ALL
, (new Cfg_Bool( wxT("/eMule/FilterAllMessages"), s_FilterAllMessages
, false )));
1124 NewCfgItem(IDC_MSGFILTER_NONFRIENDS
, (new Cfg_Bool( wxT("/eMule/MessagesFromFriendsOnly"), s_msgonlyfriends
, false )));
1125 NewCfgItem(IDC_MSGFILTER_NONSECURE
, (new Cfg_Bool( wxT("/eMule/MessageFromValidSourcesOnly"), s_msgsecure
, true )));
1126 NewCfgItem(IDC_MSGFILTER_WORD
, (new Cfg_Bool( wxT("/eMule/FilterWordMessages"), s_FilterSomeMessages
, false )));
1127 NewCfgItem(IDC_MSGWORD
, (new Cfg_Str( wxT("/eMule/MessageFilter"), s_MessageFilterString
, wxEmptyString
)));
1129 NewCfgItem(IDC_FILTERCOMMENTS
, (new Cfg_Bool( wxT("/eMule/FilterComments"), s_FilterComments
, false )));
1130 NewCfgItem(IDC_COMMENTWORD
, (new Cfg_Str( wxT("/eMule/CommentFilter"), s_CommentFilterString
, wxEmptyString
)));
1133 * Hidden files sharing
1135 NewCfgItem(IDC_SHAREHIDDENFILES
, (new Cfg_Bool( wxT("/eMule/ShareHiddenFiles"), s_ShareHiddenFiles
, false )));
1138 * Auto-Sorting of downloads
1140 NewCfgItem(IDC_AUTOSORT
, (new Cfg_Bool( wxT("/eMule/AutoSortDownloads"), s_AutoSortDownload
, false )));
1145 NewCfgItem(IDC_NEWVERSION
, (new Cfg_Bool( wxT("/eMule/NewVersionCheck"), s_NewVersionCheck
, false )));
1151 NewCfgItem( IDC_SUPPORT_PO
, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerSupported"), s_IsClientCryptLayerSupported
, true )));
1152 NewCfgItem( IDC_ENABLE_PO_OUTGOING
, ( new Cfg_Bool( wxT("/Obfuscation/IsCryptLayerRequested"), s_bCryptLayerRequested
, true )));
1153 NewCfgItem( IDC_ENFORCE_PO_INCOMING
, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerRequired"), s_IsClientCryptLayerRequired
, false )));
1154 // There is no need for GUI items for this two.
1155 s_MiscList
.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoPaddingLenght"), s_byCryptTCPPaddingLength
, 254 ) );
1156 s_MiscList
.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoKadUDPKey"), s_dwKadUDPKey
, GetRandomUint32() ) );
1159 * The following doesn't have an associated widget or section
1161 s_MiscList
.push_back( new Cfg_Str( wxT("/eMule/Language"), s_languageID
) );
1162 s_MiscList
.push_back( new Cfg_Counter( wxT("/Statistics/TotalDownloadedBytes"), s_totalDownloadedBytes
) );
1163 s_MiscList
.push_back( new Cfg_Counter( wxT("/Statistics/TotalUploadedBytes"), s_totalUploadedBytes
) );
1164 s_MiscList
.push_back( MkCfg_Int( wxT("/eMule/SplitterbarPosition"), s_splitterbarPosition
, 75 ) );
1165 s_MiscList
.push_back( new Cfg_Str( wxT("/eMule/YourHostname"), s_yourHostname
, wxEmptyString
) );
1166 s_MiscList
.push_back( new Cfg_Str( wxT("/eMule/DateTimeFormat"), s_datetimeformat
, wxT("%A, %x, %X") ) );
1168 s_MiscList
.push_back( new Cfg_Bool( wxT("/eMule/IndicateRatings"), s_indicateratings
, true ) );
1169 s_MiscList
.push_back( MkCfg_Int( wxT("/eMule/AllcatType"), s_allcatType
, 0 ) );
1170 s_MiscList
.push_back( new Cfg_Bool( wxT("/eMule/ShowAllNotCats"), s_showAllNotCats
, false ) );
1171 s_MiscList
.push_back( new Cfg_Bool( wxT("/eMule/DisableKnownClientList"), s_bDisableKnownClientList
, false ) );
1172 s_MiscList
.push_back( new Cfg_Bool( wxT("/eMule/DisableQueueList"), s_bDisableQueueList
, false ) );
1173 s_MiscList
.push_back( MkCfg_Int( wxT("/eMule/MaxMessageSessions"), s_maxmsgsessions
, 50 ) );
1175 s_MiscList
.push_back( MkCfg_Int( wxT("/eMule/SmartIdState"), s_smartidstate
, 0 ) );
1177 s_MiscList
.push_back( new Cfg_Bool( wxT("/eMule/DropSlowSources"), s_DropSlowSources
, false ) );
1179 s_MiscList
.push_back( new Cfg_Str( wxT("/eMule/KadNodesUrl"), s_KadURL
, wxT("http://emule-inside.net/nodes.dat") ) );
1180 s_MiscList
.push_back( new Cfg_Str( wxT("/eMule/Ed2kServersUrl"), s_Ed2kURL
, wxT("http://gruk.org/server.met.gz") ) );
1182 #ifndef AMULE_DAEMON
1183 // Colors have been moved from global prefs to CStatisticsDlg
1184 for ( int i
= 0; i
< cntStatColors
; i
++ ) {
1185 wxString str
= wxString::Format(wxT("/eMule/StatColor%i"),i
);
1187 s_MiscList
.push_back( MkCfg_Int( str
, CStatisticsDlg::acrStat
[i
], CStatisticsDlg::acrStat
[i
] ) );
1192 for (unsigned int i
= 0; i
< CUserEvents::GetCount(); ++i
) {
1193 // We can't use NewCfgItem here, because we need to find these items
1194 // later, which would be impossible in amuled with NewCfgItem.
1195 // The IDs we assign here are high enough to not cause any collision
1196 // even on the daemon.
1197 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);
1198 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
);
1199 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);
1200 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
);
1205 void CPreferences::EraseItemList()
1207 while ( s_CfgList
.begin() != s_CfgList
.end() ) {
1208 delete s_CfgList
.begin()->second
;
1209 s_CfgList
.erase( s_CfgList
.begin() );
1212 CFGList::iterator it
= s_MiscList
.begin();
1213 for ( ; it
!= s_MiscList
.end(); ) {
1215 it
= s_MiscList
.erase( it
);
1220 void CPreferences::LoadAllItems(wxConfigBase
* cfg
)
1223 // Preserve values from old config. The global config object may not be set yet
1224 // when BuildItemList() is called, so we need to provide defaults later - here.
1225 bool ExecOnCompletion
;
1226 wxString ExecOnCompletionCommand
;
1227 cfg
->Read(wxT("/eMule/ExecOnCompletion"), &ExecOnCompletion
, false);
1228 cfg
->Read(wxT("/eMule/ExecOnCompletionCommand"), &ExecOnCompletionCommand
, wxEmptyString
);
1229 // Assign to core command, that's the most likely it was.
1230 static_cast<Cfg_Bool
*>(s_CfgList
[USEREVENTS_FIRST_ID
+ CUserEvents::DownloadCompleted
* USEREVENTS_IDS_PER_EVENT
+ 1])->SetDefault(ExecOnCompletion
);
1231 static_cast<Cfg_Str
*>(s_CfgList
[USEREVENTS_FIRST_ID
+ CUserEvents::DownloadCompleted
* USEREVENTS_IDS_PER_EVENT
+ 2])->SetDefault(ExecOnCompletionCommand
);
1233 CFGMap::iterator it_a
= s_CfgList
.begin();
1234 for ( ; it_a
!= s_CfgList
.end(); ++it_a
) {
1235 it_a
->second
->LoadFromFile( cfg
);
1238 CFGList::iterator it_b
= s_MiscList
.begin();
1239 for ( ; it_b
!= s_MiscList
.end(); ++it_b
) {
1240 (*it_b
)->LoadFromFile( cfg
);
1243 // Load debug-categories
1245 int count
= CLogger::GetDebugCategoryCount();
1247 for ( int i
= 0; i
< count
; i
++ ) {
1248 const CDebugCategory
& cat
= CLogger::GetDebugCategory( i
);
1250 bool enabled
= false;
1251 cfg
->Read( wxT("/Debug/Cat_") + cat
.GetName(), &enabled
);
1253 CLogger::SetEnabled( cat
.GetType(), enabled
);
1257 // Now do some post-processing / sanity checking on the values we just loaded
1260 if (s_byCryptTCPPaddingLength
> 254) {
1261 s_byCryptTCPPaddingLength
= GetRandomUint8() % 254;
1266 void CPreferences::SaveAllItems(wxConfigBase
* cfg
)
1268 // Save the Cfg values
1269 CFGMap::iterator it_a
= s_CfgList
.begin();
1270 for ( ; it_a
!= s_CfgList
.end(); ++it_a
)
1271 it_a
->second
->SaveToFile( cfg
);
1273 CFGList::iterator it_b
= s_MiscList
.begin();
1274 for ( ; it_b
!= s_MiscList
.end(); ++it_b
)
1275 (*it_b
)->SaveToFile( cfg
);
1278 // Save debug-categories
1280 int count
= CLogger::GetDebugCategoryCount();
1282 for ( int i
= 0; i
< count
; i
++ ) {
1283 const CDebugCategory
& cat
= CLogger::GetDebugCategory( i
);
1285 cfg
->Write( wxT("/Debug/Cat_") + cat
.GetName(), cat
.IsEnabled() );
1290 void CPreferences::SetMaxUpload(uint16 in
)
1292 if ( s_maxupload
!= in
) {
1295 // Ensure that the ratio is upheld
1301 void CPreferences::SetMaxDownload(uint16 in
)
1303 if ( s_maxdownload
!= in
) {
1306 // Ensure that the ratio is upheld
1312 void CPreferences::UnsetAutoServerStart()
1314 s_autoserverlist
= false;
1318 // Here we slightly limit the users' ability to be a bad citizen: for very low upload rates
1319 // we force a low download rate, so as to discourage this type of leeching.
1320 // We're Open Source, and whoever wants it can do his own mod to get around this, but the
1321 // packaged product will try to enforce good behavior.
1323 // Kry note: of course, any leecher mod will be banned asap.
1324 void CPreferences::CheckUlDlRatio()
1326 // Backwards compatibility
1327 if ( s_maxupload
== 0xFFFF )
1328 s_maxupload
= UNLIMITED
;
1330 // Backwards compatibility
1331 if ( s_maxdownload
== 0xFFFF )
1332 s_maxdownload
= UNLIMITED
;
1334 if ( s_maxupload
== UNLIMITED
)
1337 // Enforce the limits
1338 if ( s_maxupload
< 4 ) {
1339 if ( ( s_maxupload
* 3 < s_maxdownload
) || ( s_maxdownload
== 0 ) )
1340 s_maxdownload
= s_maxupload
* 3 ;
1341 } else if ( s_maxupload
< 10 ) {
1342 if ( ( s_maxupload
* 4 < s_maxdownload
) || ( s_maxdownload
== 0 ) )
1343 s_maxdownload
= s_maxupload
* 4;
1348 void CPreferences::Save()
1350 wxString
fullpath(theApp
->ConfigDir
+ wxT("preferences.dat"));
1353 if (!wxFileExists(fullpath
)) {
1354 preffile
.Create(fullpath
);
1357 if (preffile
.Open(fullpath
, CFile::read_write
)) {
1359 preffile
.WriteUInt8(PREFFILE_VERSION
);
1360 preffile
.WriteHash(s_userhash
);
1361 } catch (const CIOFailureException
& e
) {
1362 AddDebugLogLineM(true, logGeneral
, wxT("IO failure while saving user-hash: ") + e
.what());
1370 if (sdirfile
.Open(theApp
->ConfigDir
+ wxT("shareddir.dat"), CTextFile::write
)) {
1371 for (size_t i
= 0; i
< shareddir_list
.size(); ++i
) {
1372 sdirfile
.WriteLine(CPath::ToUniv(shareddir_list
[i
]), wxConvUTF8
);
1380 CPreferences::~CPreferences()
1382 while ( !m_CatList
.empty() ) {
1383 delete m_CatList
.front();
1384 m_CatList
.erase( m_CatList
.begin() );
1391 int32
CPreferences::GetRecommendedMaxConnections()
1393 int iRealMax
= ::GetMaxConnections();
1394 if(iRealMax
== -1 || iRealMax
> 520) {
1400 if(iRealMax
<= 256) {
1401 return iRealMax
- 10;
1403 return iRealMax
- 20;
1407 void CPreferences::SavePreferences()
1409 wxConfigBase
* cfg
= wxConfigBase::Get();
1411 cfg
->Write( wxT("/eMule/AppVersion"), wxT(VERSION
) );
1414 SaveAllItems( cfg
);
1416 // Ensure that the changes are saved to disk.
1421 void CPreferences::SaveCats()
1423 if ( GetCatCount() ) {
1424 wxConfigBase
* cfg
= wxConfigBase::Get();
1426 // Save the main cat.
1427 cfg
->Write( wxT("/eMule/AllcatType"), (int)s_allcatType
);
1429 // The first category is the default one and should not be counted
1431 cfg
->Write( wxT("/General/Count"), (long)(m_CatList
.size() - 1) );
1433 for ( size_t i
= 1; i
< m_CatList
.size(); i
++ ) {
1434 cfg
->SetPath( wxString::Format(wxT("/Cat#%i"), i
) );
1436 cfg
->Write( wxT("Title"), m_CatList
[i
]->title
);
1437 cfg
->Write( wxT("Incoming"), CPath::ToUniv(m_CatList
[i
]->path
) );
1438 cfg
->Write( wxT("Comment"), m_CatList
[i
]->comment
);
1439 cfg
->Write( wxT("Color"), wxString::Format(wxT("%u"), m_CatList
[i
]->color
) );
1440 cfg
->Write( wxT("Priority"), m_CatList
[i
]->prio
);
1448 void CPreferences::LoadPreferences()
1454 void CPreferences::LoadCats()
1456 // default cat ... Meow! =(^.^)=
1457 Category_Struct
* defaultcat
= new Category_Struct
;
1458 defaultcat
->prio
= 0;
1459 defaultcat
->color
= 0;
1461 AddCat( defaultcat
);
1463 wxConfigBase
* cfg
= wxConfigBase::Get();
1465 long max
= cfg
->Read( wxT("/General/Count"), 0l );
1467 for ( int i
= 1; i
<= max
; i
++ ) {
1468 cfg
->SetPath( wxString::Format(wxT("/Cat#%i"), i
) );
1470 Category_Struct
* newcat
= new Category_Struct
;
1472 newcat
->title
= cfg
->Read( wxT("Title"), wxEmptyString
);
1473 newcat
->path
= CPath::FromUniv(cfg
->Read(wxT("Incoming"), wxEmptyString
));
1475 // Some sainity checking
1476 if ( newcat
->title
.IsEmpty() || !newcat
->path
.IsOk() ) {
1477 printf("Invalid category found, skipping\n");
1483 newcat
->comment
= cfg
->Read( wxT("Comment"), wxEmptyString
);
1484 newcat
->prio
= cfg
->Read( wxT("Priority"), 0l );
1485 newcat
->color
= StrToULong(cfg
->Read(wxT("Color"), wxT("0")));
1489 if (!newcat
->path
.DirExists()) {
1490 CPath::MakeDir(newcat
->path
);
1496 uint16
CPreferences::GetDefaultMaxConperFive()
1498 return MAXCONPER5SEC
;
1502 uint32
CPreferences::AddCat(Category_Struct
* cat
)
1504 m_CatList
.push_back( cat
);
1506 return m_CatList
.size() - 1;
1510 void CPreferences::RemoveCat(size_t index
)
1512 if ( index
< m_CatList
.size() ) {
1513 CatList::iterator it
= m_CatList
.begin() + index
;
1517 m_CatList
.erase( it
);
1522 uint32
CPreferences::GetCatCount()
1524 return m_CatList
.size();
1528 Category_Struct
* CPreferences::GetCategory(size_t index
)
1530 wxASSERT( index
< m_CatList
.size() );
1532 return m_CatList
[index
];
1536 const CPath
& CPreferences::GetCatPath(uint8 index
)
1538 wxASSERT( index
< m_CatList
.size() );
1540 return m_CatList
[index
]->path
;
1544 uint32
CPreferences::GetCatColor(size_t index
)
1546 wxASSERT( index
< m_CatList
.size() );
1548 return m_CatList
[index
]->color
;
1551 Category_Struct
*CPreferences::CreateCategory(
1552 const wxString
& name
,
1554 const wxString
& comment
,
1558 Category_Struct
*category
= new Category_Struct();
1559 category
->path
= path
;
1560 category
->title
= name
;
1561 category
->comment
= comment
;
1562 category
->color
= color
;
1563 category
->prio
= prio
;
1572 void CPreferences::UpdateCategory(
1574 const wxString
& name
,
1576 const wxString
& comment
,
1580 Category_Struct
*category
= m_CatList
[cat
];
1582 category
->path
= path
;
1583 category
->title
= name
;
1584 category
->comment
= comment
;
1585 category
->color
= color
;
1586 category
->prio
= prio
;
1591 // Jacobo221 - Several issues on the browsers:
1592 // netscape is named Netscape on some systems
1593 // MozillaFirebird is named mozilla-firebird and also firebird on some systems
1594 // Niether Galeon tabs nor epiphany tabs have been tested
1595 // Konqueror alternatives is (Open on current window, fails if no konq already open):
1596 // dcop `dcop konqueror-* | head -n1` konqueror-mainwindow#1 openURL '%s'
1597 // IMPORTANT: if you add cases to the switches and change the number which
1598 // corresponds to s_CustomBrowser, you must change the default
1599 // set for the Mac in BuildItemList, above.
1600 wxString
CPreferences::GetBrowser()
1605 switch ( s_Browser
) {
1606 case 0: cmd
= wxT("kfmclient exec '%s'"); break;
1607 case 1: cmd
= wxT("sh -c \"if ! mozilla -remote 'openURL(%s, new-tab)'; then mozilla '%s'; fi\""); break;
1608 case 2: cmd
= wxT("sh -c \"if ! firefox -remote 'openURL(%s, new-tab)'; then firefox '%s'; fi\""); break;
1609 case 3: cmd
= wxT("sh -c \"if ! MozillaFirebird -remote 'openURL(%s, new-tab)'; then MozillaFirebird '%s'; fi\""); break;
1610 case 4: cmd
= wxT("opera --newpage '%s'"); break;
1611 case 5: cmd
= wxT("sh -c \"if ! netscape -remote 'openURLs(%s,new-tab)'; then netscape '%s'; fi\""); break;
1612 case 6: cmd
= wxT("galeon -n '%s'"); break;
1613 case 7: cmd
= wxT("epiphany -n '%s'"); break;
1614 case 8: cmd
= s_CustomBrowser
; break;
1616 AddLogLineM( true, _("Unable to determine selected browser!") );
1619 switch ( s_Browser
) {
1620 case 0: cmd
= wxT("konqueror '%s'"); break;
1621 case 1: cmd
= wxT("sh -c 'mozilla %s'"); break;
1622 case 2: cmd
= wxT("firefox '%s'"); break;
1623 case 3: cmd
= wxT("MozillaFirebird '%s'"); break;
1624 case 4: cmd
= wxT("opera '%s'"); break;
1625 case 5: cmd
= wxT("netscape '%s'"); break;
1626 case 6: cmd
= wxT("galeon '%s'"); break;
1627 case 7: cmd
= wxT("epiphany '%s'"); break;
1628 case 8: cmd
= s_CustomBrowser
; break;
1630 AddLogLineM( true, _("Unable to determine selected browser!") );
1633 switch ( s_Browser
) {
1634 case 0: cmd
= wxT(""); break;
1635 case 1: cmd
= s_CustomBrowser
; break;
1637 AddLogLineM( true, _("Unable to determine selected browser!") );
1639 #endif /* !__WXMSW__ / __WXMSW__ */
1644 #include "ClientList.h"
1645 #include "ServerList.h"
1646 void CPreferences::SetIPFilterLevel(uint8 level
)
1648 if (level
!= s_filterlevel
) {
1649 // We only need to recheck if the new level is more restrictive
1650 bool filter
= level
> s_filterlevel
;
1652 // Set the new access-level
1653 s_filterlevel
= level
;
1656 theApp
->clientlist
->FilterQueues();
1657 theApp
->serverlist
->FilterServers();
1663 void CPreferences::SetPort(uint16 val
)
1665 // Warning: Check for +3, because server UDP is TCP+3
1667 if (val
+3 > 65535) {
1668 AddLogLineM(true, _("TCP port can't be higher than 65532 due to server UDP socket being TCP+3"));
1669 AddLogLineM(false, wxString::Format(_("Default port will be used (%d)"),DEFAULT_TCP_PORT
));
1670 s_port
= DEFAULT_TCP_PORT
;
1677 void CPreferences::ReloadSharedFolders()
1680 shareddir_list
.clear();
1683 if (file
.Open(theApp
->ConfigDir
+ wxT("shareddir.dat"), CTextFile::read
)) {
1684 wxArrayString lines
= file
.ReadLines(txtReadDefault
, wxConvUTF8
);
1686 for (size_t i
= 0; i
< lines
.size(); ++i
) {
1687 CPath path
= CPath::FromUniv(lines
[i
]);
1689 if (path
.DirExists()) {
1690 shareddir_list
.push_back(path
);
1692 printf("Dropping non-existing shared directory: %s\n",
1693 (const char*)unicode2char(path
.GetRaw()));
1701 bool CPreferences::IsMessageFiltered(const wxString
& message
)
1703 if (s_FilterAllMessages
) {
1706 if (s_FilterSomeMessages
) {
1707 if (s_MessageFilterString
.IsSameAs(wxT("*"))){
1711 wxStringTokenizer
tokenizer( s_MessageFilterString
, wxT(",") );
1712 while (tokenizer
.HasMoreTokens()) {
1713 if ( message
.Lower().Trim(false).Trim(true).Contains(
1714 tokenizer
.GetNextToken().Lower().Trim(false).Trim(true))) {
1727 bool CPreferences::IsCommentFiltered(const wxString
& comment
)
1729 if (s_FilterComments
) {
1730 wxStringTokenizer
tokenizer( s_CommentFilterString
, wxT(",") );
1731 while (tokenizer
.HasMoreTokens()) {
1732 if ( comment
.Lower().Trim(false).Trim(true).Contains(
1733 tokenizer
.GetNextToken().Lower().Trim(false).Trim(true))) {
1741 // File_checked_for_headers