Bug Summary

File:rootdir/src/Preferences.cpp
Warning:line 442, column 16
This statement is never executed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Preferences.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/src -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/lib/llvm-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I .. -D USE_WX_EXTENSIONS -I /usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.2 -I /usr/include/wx-3.2 -D _FILE_OFFSET_BITS=64 -D WXUSINGDLL -D __WXGTK__ -D wxUSE_GUI=0 -I /usr/include/upnp -D ENABLE_UPNP=1 -I ./libs -I libs -I ./include -D AMULE_DAEMON -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-register -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2025-01-17-210641-60100-1 -x c++ Preferences.cpp
1//
2// This file is part of the aMule Project.
3//
4// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5// Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6//
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
9// respective authors.
10//
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.
15//
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.
20//
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
24//
25
26#include <wx/wx.h>
27#include "Preferences.h"
28
29#include <protocol/ed2k/Constants.h>
30#include <common/Constants.h>
31#include <common/DataFileVersion.h>
32
33#include <wx/config.h>
34#include <wx/dir.h>
35#include <wx/stdpaths.h>
36#include <wx/stopwatch.h>
37#include <wx/tokenzr.h>
38#include <wx/utils.h> // Needed for wxBusyCursor
39
40#include "amule.h"
41#include "config.h" // Needed for PACKAGE_STRING
42
43#include "CFile.h"
44#include <common/MD5Sum.h>
45#include "Logger.h"
46#include <common/Format.h> // Needed for CFormat
47#include <common/TextFile.h> // Needed for CTextFile
48#include <common/ClientVersion.h>
49
50#include "UserEvents.h"
51
52#ifndef AMULE_DAEMON1
53#include <wx/valgen.h>
54#include "muuli_wdr.h"
55#include "StatisticsDlg.h"
56#include "MuleColour.h"
57#endif
58
59#ifndef CLIENT_GUI
60#include "RandomFunctions.h"
61#include "PlatformSpecific.h" // Needed for PlatformSpecific::GetMaxConnections()
62#include "SharedFileList.h" // Needed for theApp->sharedfiles->Reload()
63#endif
64
65// Needed for IP filtering prefs
66#include "ClientList.h"
67#include "ServerList.h"
68#include "GuiEvents.h"
69
70#define DEFAULT_TCP_PORT4662 4662
71#define DEFAULT_UDP_PORT4672 4672
72
73// Static variables
74unsigned long CPreferences::s_colors[cntStatColors];
75unsigned long CPreferences::s_colors_ref[cntStatColors];
76
77CPreferences::CFGMap CPreferences::s_CfgList;
78CPreferences::CFGList CPreferences::s_MiscList;
79
80wxString CPreferences::s_configDir;
81
82/* Proxy */
83CProxyData CPreferences::s_ProxyData;
84
85/* The rest, organize it! */
86wxString CPreferences::s_nick;
87Cfg_Lang_Base * CPreferences::s_cfgLang;
88uint16 CPreferences::s_maxupload;
89uint16 CPreferences::s_maxdownload;
90uint16 CPreferences::s_slotallocation;
91wxString CPreferences::s_Addr;
92uint16 CPreferences::s_port;
93uint16 CPreferences::s_udpport;
94bool CPreferences::s_UDPEnable;
95uint16 CPreferences::s_maxconnections;
96bool CPreferences::s_reconnect;
97bool CPreferences::s_autoconnect;
98bool CPreferences::s_autoconnectstaticonly;
99bool CPreferences::s_UPnPEnabled;
100bool CPreferences::s_UPnPECEnabled;
101bool CPreferences::s_UPnPWebServerEnabled;
102uint16 CPreferences::s_UPnPTCPPort;
103bool CPreferences::s_autoserverlist;
104bool CPreferences::s_deadserver;
105CPath CPreferences::s_incomingdir;
106CPath CPreferences::s_tempdir;
107bool CPreferences::s_ICH;
108uint8 CPreferences::s_depth3D;
109bool CPreferences::s_scorsystem;
110bool CPreferences::s_hideonclose;
111bool CPreferences::s_mintotray;
112bool CPreferences::s_notify;
113bool CPreferences::s_trayiconenabled;
114bool CPreferences::s_addnewfilespaused;
115bool CPreferences::s_addserversfromserver;
116bool CPreferences::s_addserversfromclient;
117uint16 CPreferences::s_maxsourceperfile;
118uint16 CPreferences::s_trafficOMeterInterval;
119uint16 CPreferences::s_statsInterval;
120uint32 CPreferences::s_maxGraphDownloadRate;
121uint32 CPreferences::s_maxGraphUploadRate;
122bool CPreferences::s_confirmExit;
123bool CPreferences::s_filterLanIP;
124bool CPreferences::s_paranoidfilter;
125bool CPreferences::s_IPFilterSys;
126bool CPreferences::s_onlineSig;
127uint16 CPreferences::s_OSUpdate;
128wxString CPreferences::s_languageID;
129uint8 CPreferences::s_iSeeShares;
130uint8 CPreferences::s_iToolDelayTime;
131uint8 CPreferences::s_splitterbarPosition;
132uint16 CPreferences::s_deadserverretries;
133uint32 CPreferences::s_dwServerKeepAliveTimeoutMins;
134uint8 CPreferences::s_statsMax;
135uint8 CPreferences::s_statsAverageMinutes;
136bool CPreferences::s_bpreviewprio;
137bool CPreferences::s_smartidcheck;
138uint8 CPreferences::s_smartidstate;
139bool CPreferences::s_safeServerConnect;
140bool CPreferences::s_startMinimized;
141uint16 CPreferences::s_MaxConperFive;
142bool CPreferences::s_checkDiskspace;
143uint32 CPreferences::s_uMinFreeDiskSpace;
144wxString CPreferences::s_yourHostname;
145bool CPreferences::s_bVerbose;
146bool CPreferences::s_bVerboseLogfile;
147bool CPreferences::s_bmanualhighprio;
148bool CPreferences::s_bstartnextfile;
149bool CPreferences::s_bstartnextfilesame;
150bool CPreferences::s_bstartnextfilealpha;
151bool CPreferences::s_bshowoverhead;
152bool CPreferences::s_bDAP;
153bool CPreferences::s_bUAP;
154#ifndef __SVN__
155bool CPreferences::s_showVersionOnTitle;
156#endif
157uint8_t CPreferences::s_showRatesOnTitle;
158wxString CPreferences::s_VideoPlayer;
159bool CPreferences::s_showAllNotCats;
160bool CPreferences::s_msgonlyfriends;
161bool CPreferences::s_msgsecure;
162uint8 CPreferences::s_filterlevel;
163uint8 CPreferences::s_iFileBufferSize;
164uint8 CPreferences::s_iQueueSize;
165wxString CPreferences::s_datetimeformat;
166wxString CPreferences::s_sWebPath;
167wxString CPreferences::s_sWebPassword;
168wxString CPreferences::s_sWebLowPassword;
169uint16 CPreferences::s_nWebPort;
170uint16 CPreferences::s_nWebUPnPTCPPort;
171bool CPreferences::s_bWebEnabled;
172bool CPreferences::s_bWebUseGzip;
173uint32 CPreferences::s_nWebPageRefresh;
174bool CPreferences::s_bWebLowEnabled;
175wxString CPreferences::s_WebTemplate;
176bool CPreferences::s_showCatTabInfos;
177AllCategoryFilter CPreferences::s_allcatFilter;
178bool CPreferences::s_AcceptExternalConnections;
179wxString CPreferences::s_ECAddr;
180uint32 CPreferences::s_ECPort;
181wxString CPreferences::s_ECPassword;
182bool CPreferences::s_TransmitOnlyUploadingClients;
183bool CPreferences::s_IPFilterClients;
184bool CPreferences::s_IPFilterServers;
185bool CPreferences::s_UseSrcSeeds;
186bool CPreferences::s_ProgBar;
187bool CPreferences::s_Percent;
188bool CPreferences::s_SecIdent;
189bool CPreferences::s_ExtractMetaData;
190bool CPreferences::s_allocFullFile;
191bool CPreferences::s_createFilesSparse;
192wxString CPreferences::s_CustomBrowser;
193bool CPreferences::s_BrowserTab;
194CPath CPreferences::s_OSDirectory;
195wxString CPreferences::s_Skin;
196bool CPreferences::s_FastED2KLinksHandler;
197bool CPreferences::s_ToolbarOrientation;
198bool CPreferences::s_AICHTrustEveryHash;
199wxString CPreferences::s_CommentFilterString;
200bool CPreferences::s_IPFilterAutoLoad;
201wxString CPreferences::s_IPFilterURL;
202CMD4Hash CPreferences::s_userhash;
203bool CPreferences::s_MustFilterMessages;
204wxString CPreferences::s_MessageFilterString;
205bool CPreferences::s_FilterAllMessages;
206bool CPreferences::s_FilterComments;
207bool CPreferences::s_FilterSomeMessages;
208bool CPreferences::s_ShowMessagesInLog;
209bool CPreferences::s_IsAdvancedSpamfilterEnabled;
210bool CPreferences::s_IsChatCaptchaEnabled;
211bool CPreferences::s_ShareHiddenFiles;
212bool CPreferences::s_AutoSortDownload;
213bool CPreferences::s_NewVersionCheck;
214bool CPreferences::s_ConnectToKad;
215bool CPreferences::s_ConnectToED2K;
216unsigned CPreferences::s_maxClientVersions;
217bool CPreferences::s_DropSlowSources;
218bool CPreferences::s_IsClientCryptLayerSupported;
219bool CPreferences::s_bCryptLayerRequested;
220bool CPreferences::s_IsClientCryptLayerRequired;
221uint32 CPreferences::s_dwKadUDPKey;
222uint8 CPreferences::s_byCryptTCPPaddingLength;
223
224wxString CPreferences::s_Ed2kURL;
225wxString CPreferences::s_KadURL;
226bool CPreferences::s_GeoIPEnabled;
227wxString CPreferences::s_GeoIPUpdateUrl;
228bool CPreferences::s_preventSleepWhileDownloading;
229wxString CPreferences::s_StatsServerName;
230wxString CPreferences::s_StatsServerURL;
231
232/**
233 * Template Cfg class for connecting with widgets.
234 *
235 * This template provides the base functionality needed to synchronize a
236 * variable with a widget. However, please note that wxGenericValidator only
237 * supports a few types (int, wxString, bool and wxArrayInt), so this template
238 * can't always be used directly.
239 *
240 * Cfg_Str and Cfg_Bool are able to use this template directly, whereas Cfg_Int
241 * makes use of several workaround to enable it to be used with integers other
242 * than int.
243 */
244template <typename TYPE>
245class Cfg_Tmpl : public Cfg_Base
246{
247public:
248 /**
249 * Constructor.
250 *
251 * @param keyname
252 * @param value
253 * @param defaultVal
254 */
255 Cfg_Tmpl( const wxString& keyname, TYPE& value, const TYPE& defaultVal )
256 : Cfg_Base( keyname ),
257 m_value( value ),
258 m_default( defaultVal ),
259 m_widget( NULL__null )
260 {}
261
262#ifndef AMULE_DAEMON1
263 /**
264 * Connects the Cfg to a widget.
265 *
266 * @param id The ID of the widget to be connected.
267 * @param parent The parent of the widget. Use this to speed up searches.
268 *
269 * This function works by setting the wxValidator of the class. This however
270 * poses some restrictions on which variable types can be used for this
271 * template, as noted above. It also poses some limits on the widget types,
272 * refer to the wx documentation for those.
273 */
274 virtual bool ConnectToWidget( int id, wxWindow* parent = NULL__null )
275 {
276 if ( id ) {
277 m_widget = wxWindow::FindWindowById( id, parent );
278
279 if ( m_widget ) {
280 wxGenericValidator validator( &m_value );
281
282 m_widget->SetValidator( validator );
283
284 return true;
285 }
286 } else {
287 m_widget = NULL__null;
288 }
289
290 return false;
291 }
292
293
294 /** Updates the associated variable, returning true on success. */
295 virtual bool TransferFromWindow()
296 {
297 if ( m_widget ) {
298 wxValidator* validator = m_widget->GetValidator();
299
300 if ( validator ) {
301 TYPE temp = m_value;
302
303 if ( validator->TransferFromWindow() ) {
304 SetChanged( temp != m_value );
305
306 return true;
307 }
308 }
309 }
310
311 return false;
312 }
313
314 /** Updates the associated widget, returning true on success. */
315 virtual bool TransferToWindow()
316 {
317 if ( m_widget ) {
318 wxValidator* validator = m_widget->GetValidator();
319
320 if ( validator )
321 return validator->TransferToWindow();
322 }
323
324 return false;
325 }
326
327#endif
328
329 /** Sets the default value. */
330 void SetDefault(const TYPE& defaultVal)
331 {
332 m_default = defaultVal;
333 }
334
335protected:
336 //! Reference to the associated variable
337 TYPE& m_value;
338
339 //! Default variable value
340 TYPE m_default;
341
342 //! Pointer to the widget assigned to the Cfg instance
343 wxWindow* m_widget;
344};
345
346
347/** Cfg class for wxStrings. */
348class Cfg_Str : public Cfg_Tmpl<wxString>
349{
350public:
351 /** Constructor. */
352 Cfg_Str( const wxString& keyname, wxString& value, const wxString& defaultVal = EmptyString )
353 : Cfg_Tmpl<wxString>( keyname, value, defaultVal )
354 {}
355
356 /** Loads the string, using the specified default value. */
357 virtual void LoadFromFile(wxConfigBase* cfg)
358 {
359 cfg->Read( GetKey(), &m_value, m_default );
360 }
361
362
363 /** Saves the string to the specified wxConfig object. */
364 virtual void SaveToFile(wxConfigBase* cfg)
365 {
366 cfg->Write( GetKey(), m_value );
367 }
368};
369
370
371/**
372 * Cfg-class for encrypting strings, for example for passwords.
373 */
374class Cfg_Str_Encrypted : public Cfg_Str
375{
376public:
377 Cfg_Str_Encrypted( const wxString& keyname, wxString& value, const wxString& defaultVal = EmptyString )
378 : Cfg_Str( keyname, value, defaultVal )
379 {}
380
381#ifndef AMULE_DAEMON1
382 virtual bool TransferFromWindow()
383 {
384 // Shakraw: when storing value, store it encrypted here (only if changed in prefs)
385 if ( Cfg_Str::TransferFromWindow() ) {
386
387 // Only recalucate the hash for new, non-empty passwords
388 if ( HasChanged() && !m_value.IsEmpty() ) {
389 m_value = MD5Sum( m_value ).GetHash();
390 }
391
392 return true;
393 }
394
395
396 return false;
397 }
398#endif
399};
400
401
402/** Cfg class for CPath. */
403class Cfg_Path : public Cfg_Str
404{
405public:
406 /** Constructor. */
407 Cfg_Path(const wxString& keyname, CPath& value, const wxString& defaultVal = EmptyString )
408 : Cfg_Str(keyname, m_temp_path, defaultVal)
409 , m_real_path(value)
410 {}
411
412 /** @see Cfg_Str::LoadFromFile. */
413 virtual void LoadFromFile(wxConfigBase* cfg)
414 {
415 Cfg_Str::LoadFromFile(cfg);
416
417 m_real_path = CPath::FromUniv(m_temp_path);
418 }
419
420
421 /** @see Cfg_Str::SaveToFile. */
422 virtual void SaveToFile(wxConfigBase* cfg)
423 {
424 m_temp_path = CPath::ToUniv(m_real_path);
425
426 Cfg_Str::SaveToFile(cfg);
427 }
428
429
430 /** @see Cfg_Tmpl::TransferToWindow. */
431 virtual bool TransferToWindow()
432 {
433 m_temp_path = m_real_path.GetRaw();
434
435 return Cfg_Str::TransferToWindow();
436 }
437
438 /** @see Cfg_Tmpl::TransferFromWindow. */
439 virtual bool TransferFromWindow()
440 {
441 if (Cfg_Str::TransferFromWindow()) {
442 m_real_path = CPath(m_temp_path);
This statement is never executed
443 return true;
444 }
445
446 return false;
447 }
448
449private:
450 wxString m_temp_path;
451 CPath& m_real_path;
452};
453
454
455/**
456 * Cfg class that takes care of integer types.
457 *
458 * This template is needed since wxValidator only supports normals ints, and
459 * wxConfig for the matter only supports longs, thus some worksarounds are
460 * needed.
461 *
462 * There are two work-arounds:
463 * 1) wxValidator only supports int*, so we need a immediate variable to act
464 * as a storage. Thus we use Cfg_Tmpl<int> as base class. Thus this class
465 * contains a integer which we use to pass the value back and forth
466 * between the widgets.
467 *
468 * 2) wxConfig uses longs to save and read values, thus we need an immediate
469 * stage when loading and saving the value.
470 */
471template <typename TYPE>
472class Cfg_Int : public Cfg_Tmpl<int>
473{
474public:
475 Cfg_Int( const wxString& keyname, TYPE& value, int defaultVal = 0 )
476 : Cfg_Tmpl<int>( keyname, m_temp_value, defaultVal ),
477 m_real_value( value ),
478 m_temp_value( value )
479 {}
480
481
482 virtual void LoadFromFile(wxConfigBase* cfg)
483 {
484 long tmp = 0;
485 cfg->Read( GetKey(), &tmp, m_default );
486
487 // Set the temp value
488 m_temp_value = (int)tmp;
489 // Set the actual value
490 m_real_value = (TYPE)tmp;
491 }
492
493 virtual void SaveToFile(wxConfigBase* cfg)
494 {
495 cfg->Write( GetKey(), (long)m_real_value );
496 }
497
498
499#ifndef AMULE_DAEMON1
500 virtual bool TransferFromWindow()
501 {
502 if ( Cfg_Tmpl<int>::TransferFromWindow() ) {
503 m_real_value = (TYPE)m_temp_value;
504
505 return true;
506 }
507
508 return false;
509 }
510
511 virtual bool TransferToWindow()
512 {
513 m_temp_value = (int)m_real_value;
514
515 if ( Cfg_Tmpl<int>::TransferToWindow() ) {
516
517 // In order to let us update labels on slider-changes, we trigger a event
518 wxSlider *slider = dynamic_cast<wxSlider *>(m_widget);
519 if (slider) {
520 int id = m_widget->GetId();
521 int pos = slider->GetValue();
522 wxScrollEvent evt( wxEVT_SCROLL_THUMBRELEASE, id, pos );
523 m_widget->GetEventHandler()->ProcessEvent( evt );
524 }
525
526 return true;
527 }
528
529 return false;
530 }
531#endif
532
533protected:
534
535 TYPE& m_real_value;
536 int m_temp_value;
537};
538
539
540/**
541 * Helper function for creating new Cfg_Ints.
542 *
543 * @param keyname The cfg-key under which the item should be saved.
544 * @param value The variable to synchronize. The type of this variable defines the type used to create the Cfg_Int.
545 * @param defaultVal The default value if the key isn't found when loading the value.
546 * @return A pointer to the new Cfg_Int object. The caller is responsible for deleting it.
547 *
548 * This template-function returns a Cfg_Int of the appropriate type for the
549 * variable used as argument and should be used to avoid having to specify
550 * the integer type when adding a new Cfg_Int, since that's just increases
551 * the maintenance burden.
552 */
553template <class TYPE>
554Cfg_Base* MkCfg_Int( const wxString& keyname, TYPE& value, int defaultVal )
555{
556 return new Cfg_Int<TYPE>( keyname, value, defaultVal );
557}
558
559
560/**
561 * Cfg-class for bools.
562 */
563class Cfg_Bool : public Cfg_Tmpl<bool>
564{
565public:
566 Cfg_Bool( const wxString& keyname, bool& value, bool defaultVal )
567 : Cfg_Tmpl<bool>( keyname, value, defaultVal )
568 {}
569
570
571 virtual void LoadFromFile(wxConfigBase* cfg)
572 {
573 cfg->Read( GetKey(), &m_value, m_default );
574 }
575
576 virtual void SaveToFile(wxConfigBase* cfg)
577 {
578 cfg->Write( GetKey(), m_value );
579 }
580};
581
582
583#ifndef AMULE_DAEMON1
584
585class Cfg_Colour : public Cfg_Base
586{
587 public:
588 Cfg_Colour(const wxString& key, wxColour& colour)
589 : Cfg_Base(key),
590 m_colour(colour),
591 m_default(CMuleColour(colour).GetULong())
592 {}
593
594 virtual void LoadFromFile(wxConfigBase* cfg)
595 {
596 long int rgb;
597 cfg->Read(GetKey(), &rgb, m_default);
598 m_colour.Set(rgb);
599 }
600
601 virtual void SaveToFile(wxConfigBase* cfg)
602 {
603 cfg->Write(GetKey(), static_cast<long int>(CMuleColour(m_colour).GetULong()));
604 }
605
606 private:
607 wxColour& m_colour;
608 long int m_default;
609};
610
611
612typedef struct {
613 int id;
614 bool available;
615 wxString displayname;
616 wxString name;
617} LangInfo;
618
619
620/**
621 * The languages aMule has translation for.
622 *
623 * Add new languages here.
624 * Then activate the test code in Cfg_Lang::UpdateChoice below!
625 */
626static LangInfo aMuleLanguages[] = {
627 { wxLANGUAGE_DEFAULT, true, wxEmptyString, wxTRANSLATE("System default")"System default" },
628 { wxLANGUAGE_ALBANIAN, false, wxEmptyString, wxTRANSLATE("Albanian")"Albanian" },
629 { wxLANGUAGE_ARABIC, false, wxEmptyString, wxTRANSLATE("Arabic")"Arabic" },
630 { wxLANGUAGE_ASTURIAN, false, wxEmptyString, wxTRANSLATE("Asturian")"Asturian" },
631 { wxLANGUAGE_BASQUE, false, wxEmptyString, wxTRANSLATE("Basque")"Basque" },
632 { wxLANGUAGE_BULGARIAN, false, wxEmptyString, wxTRANSLATE("Bulgarian")"Bulgarian" },
633 { wxLANGUAGE_CATALAN, false, wxEmptyString, wxTRANSLATE("Catalan")"Catalan" },
634 { wxLANGUAGE_CHINESE_SIMPLIFIED, false, wxEmptyString, wxTRANSLATE("Chinese (Simplified)")"Chinese (Simplified)" },
635 { wxLANGUAGE_CHINESE_TRADITIONAL, false, wxEmptyString, wxTRANSLATE("Chinese (Traditional)")"Chinese (Traditional)" },
636 { wxLANGUAGE_CROATIAN, false, wxEmptyString, wxTRANSLATE("Croatian")"Croatian" },
637 { wxLANGUAGE_CZECH, false, wxEmptyString, wxTRANSLATE("Czech")"Czech" },
638 { wxLANGUAGE_DANISH, false, wxEmptyString, wxTRANSLATE("Danish")"Danish" },
639 { wxLANGUAGE_DUTCH, false, wxEmptyString, wxTRANSLATE("Dutch")"Dutch" },
640 { wxLANGUAGE_ENGLISH, false, wxEmptyString, wxTRANSLATE("English (U.K.)")"English (U.K.)" },
641 { wxLANGUAGE_ESTONIAN, false, wxEmptyString, wxTRANSLATE("Estonian")"Estonian" },
642 { wxLANGUAGE_FINNISH, false, wxEmptyString, wxTRANSLATE("Finnish")"Finnish" },
643 { wxLANGUAGE_FRENCH, false, wxEmptyString, wxTRANSLATE("French")"French" },
644 { wxLANGUAGE_GALICIAN, false, wxEmptyString, wxTRANSLATE("Galician")"Galician" },
645 { wxLANGUAGE_GERMAN, false, wxEmptyString, wxTRANSLATE("German")"German" },
646 { wxLANGUAGE_GREEK, false, wxEmptyString, wxTRANSLATE("Greek")"Greek" },
647 { wxLANGUAGE_HEBREW, false, wxEmptyString, wxTRANSLATE("Hebrew")"Hebrew" },
648 { wxLANGUAGE_HUNGARIAN, false, wxEmptyString, wxTRANSLATE("Hungarian")"Hungarian" },
649 { wxLANGUAGE_ITALIAN, false, wxEmptyString, wxTRANSLATE("Italian")"Italian" },
650 { wxLANGUAGE_ITALIAN_SWISS, false, wxEmptyString, wxTRANSLATE("Italian (Swiss)")"Italian (Swiss)" },
651 { wxLANGUAGE_JAPANESE, false, wxEmptyString, wxTRANSLATE("Japanese")"Japanese" },
652 { wxLANGUAGE_KOREAN, false, wxEmptyString, wxTRANSLATE("Korean")"Korean" },
653 { wxLANGUAGE_LITHUANIAN, false, wxEmptyString, wxTRANSLATE("Lithuanian")"Lithuanian" },
654 { wxLANGUAGE_NORWEGIAN_NYNORSK, false, wxEmptyString, wxTRANSLATE("Norwegian (Nynorsk)")"Norwegian (Nynorsk)" },
655 { wxLANGUAGE_POLISH, false, wxEmptyString, wxTRANSLATE("Polish")"Polish" },
656 { wxLANGUAGE_PORTUGUESE, false, wxEmptyString, wxTRANSLATE("Portuguese")"Portuguese" },
657 { wxLANGUAGE_PORTUGUESE_BRAZILIAN, false, wxEmptyString, wxTRANSLATE("Portuguese (Brazilian)")"Portuguese (Brazilian)" },
658 { wxLANGUAGE_ROMANIAN, false, wxEmptyString, wxTRANSLATE("Romanian")"Romanian" },
659 { wxLANGUAGE_RUSSIAN, false, wxEmptyString, wxTRANSLATE("Russian")"Russian" },
660 { wxLANGUAGE_SLOVENIAN, false, wxEmptyString, wxTRANSLATE("Slovenian")"Slovenian" },
661 { wxLANGUAGE_SPANISH, false, wxEmptyString, wxTRANSLATE("Spanish")"Spanish" },
662 { wxLANGUAGE_SWEDISH, false, wxEmptyString, wxTRANSLATE("Swedish")"Swedish" },
663 { wxLANGUAGE_TURKISH, false, wxEmptyString, wxTRANSLATE("Turkish")"Turkish" },
664 { wxLANGUAGE_UKRAINIAN, false, wxEmptyString, wxTRANSLATE("Ukrainian")"Ukrainian" },
665};
666
667
668typedef Cfg_Int<int> Cfg_PureInt;
669
670class Cfg_Lang : public Cfg_PureInt, public Cfg_Lang_Base
671{
672public:
673 // cppcheck-suppress uninitMemberVar m_selection, m_langSelector
674 Cfg_Lang()
675 : Cfg_PureInt( wxEmptyString, m_selection, 0 )
676 {
677 m_languagesReady = false;
678 m_changePos = 0;
679 }
680
681 virtual void LoadFromFile(wxConfigBase* WXUNUSED(cfg)) {}
682 virtual void SaveToFile(wxConfigBase* WXUNUSED(cfg)) {}
683
684
685 virtual bool TransferFromWindow()
686 {
687 if (!m_languagesReady) {
688 return true; // nothing changed, no problem
689 }
690
691 if ( Cfg_PureInt::TransferFromWindow() ) {
692 // find wx ID of selected language
693 int i = 0;
694 while (m_selection > 0) {
695 i++;
696 if (aMuleLanguages[i].available) {
697 m_selection--;
698 }
699 }
700 int id = aMuleLanguages[i].id;
701
702 // save language selection
703 thePrefs::SetLanguageID(wxLang2Str(id));
704
705 return true;
706 }
707
708 return false;
709 }
710
711
712 virtual bool TransferToWindow()
713 {
714 m_langSelector = dynamic_cast<wxChoice*>(m_widget); // doesn't work in ctor!
715 if (m_languagesReady) {
716 FillChoice();
717 } else {
718 int wxId = StrLang2wx(thePrefs::GetLanguageID());
719 m_langSelector->Clear();
720 m_selection = 0;
721 for (uint32 i = 0; i < itemsof(aMuleLanguages)(sizeof(aMuleLanguages) / sizeof(aMuleLanguages[0])); i++) {
722 if ( aMuleLanguages[i].id == wxId ) {
723 m_langSelector->Append(wxString(wxGetTranslation(aMuleLanguages[i].name)) + wxT(" [")L" [" + aMuleLanguages[i].name + wxT("]")L"]");
724 break;
725 }
726 }
727 m_langSelector->Append(_("Change Language")wxGetTranslation(("Change Language")));
728 m_changePos = m_langSelector->GetCount() - 1;
729 }
730
731 return Cfg_PureInt::TransferToWindow();
732 }
733
734 virtual void UpdateChoice(int pos)
735 {
736 if (!m_languagesReady && pos == m_changePos) {
737 // Find available languages and translate them.
738 // This is only done when the user selects "Change Language"
739 // Language is changed rarely, and the go-through-all locales takes a considerable
740 // time when the settings dialog is opened for the first time.
741 wxBusyCursor busyCursor;
742 aMuleLanguages[0].displayname = wxGetTranslation(aMuleLanguages[0].name);
743
744 // This suppresses error-messages about invalid locales
745 for (unsigned int i = 1; i < itemsof(aMuleLanguages)(sizeof(aMuleLanguages) / sizeof(aMuleLanguages[0])); ++i) {
746 if ((aMuleLanguages[i].id > wxLANGUAGE_USER_DEFINED) || wxLocale::IsAvailable(aMuleLanguages[i].id)) {
747 wxLogNull logTarget;
748 wxLocale locale_to_check;
749 InitLocale(locale_to_check, aMuleLanguages[i].id);
750 if (locale_to_check.IsOk() && locale_to_check.IsLoaded(wxT(PACKAGE)L"amule")) {
751 aMuleLanguages[i].displayname = wxString(wxGetTranslation(aMuleLanguages[i].name)) + wxT(" [")L" [" + aMuleLanguages[i].name + wxT("]")L"]";
752 aMuleLanguages[i].available = true;
753#if 0
754 // Check for language problems
755 // Activate this code temporarily after messing with the languages!
756 int wxid = StrLang2wx(wxLang2Str(aMuleLanguages[i].id));
757 if (wxid != aMuleLanguages[i].id) {
758 AddDebugLogLineN(logGeneral, CFormat(wxT("Language problem for %s : aMule id %d != wx id %d"))do {} while (false)
759 % aMuleLanguages[i].name % aMuleLanguages[i].id % wxid)do {} while (false);
760 }
761#endif
762 }
763 }
764 }
765 // Restore original locale
766 wxLocale tmpLocale;
767 InitLocale(tmpLocale, theApp->m_locale.GetLanguage());
768 FillChoice();
769 if (m_langSelector->GetCount() == 1) {
770 wxMessageBox(_("There are no translations installed for aMule")wxGetTranslation(("There are no translations installed for aMule"
))
, _("No languages available")wxGetTranslation(("No languages available")), wxICON_INFORMATION0x00000800 | wxOK0x00000004);
771 }
772 m_langSelector->SetSelection(m_selection);
773 m_languagesReady = true;
774 }
775 }
776
777protected:
778 int m_selection;
779
780private:
781 void FillChoice()
782 {
783 int wxId = StrLang2wx(thePrefs::GetLanguageID());
784 m_langSelector->Clear();
785 // Add all available languages and find the index of the selected language.
786 for ( unsigned int i = 0, j = 0; i < itemsof(aMuleLanguages)(sizeof(aMuleLanguages) / sizeof(aMuleLanguages[0])); i++) {
787 if (aMuleLanguages[i].available) {
788 m_langSelector->Append(aMuleLanguages[i].displayname);
789 if ( aMuleLanguages[i].id == wxId ) {
790 m_selection = j;
791 }
792 j++;
793 }
794 }
795 }
796
797 bool m_languagesReady; // true: all translations calculated
798 int m_changePos;
799 wxChoice * m_langSelector;
800};
801
802#endif /* ! AMULE_DAEMON */
803
804void Cfg_Lang_Base::UpdateChoice(int) {} // dummy
805
806class Cfg_Skin : public Cfg_Str
807{
808public:
809 Cfg_Skin( const wxString& keyname, wxString& value, const wxString& defaultVal = EmptyString )
810 : Cfg_Str( keyname, value, defaultVal ),
811 m_is_skin(false)
812 {}
813
814#ifndef AMULE_DAEMON1
815 virtual bool TransferFromWindow()
816 {
817 if ( Cfg_Str::TransferFromWindow() ) {
818 if (m_is_skin) {
819 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
820 // "- default -" is always the first
821 if (skinSelector->GetSelection() == 0) {
822 m_value.Clear();
823 }
824 }
825 return true;
826 }
827
828 return false;
829 }
830
831
832 virtual bool TransferToWindow()
833 {
834
835 wxChoice *skinSelector = dynamic_cast<wxChoice*>(m_widget);
836 skinSelector->Clear();
837
838 wxString folder;
839 int flags = wxDIR_DIRS;
840 wxString filespec;
841 wxString defaultSelection = _("- default -")wxGetTranslation(("- default -"));
842//#warning there has to be a better way...
843 if ( GetKey() == wxT("/SkinGUIOptions/Skin")L"/SkinGUIOptions/Skin" ) {
844 folder = wxT("skins")L"skins";
845 m_is_skin = true;
846 flags = wxDIR_FILES;
847 filespec = wxT("*.zip")L"*.zip";
848 skinSelector->Append(defaultSelection);
849 } else {
850 folder = wxT("webserver")L"webserver";
851 }
852 wxString dirName(JoinPaths(thePrefs::GetConfigDir(), folder));
853 wxString Filename;
854 wxDir d;
855
856 if (wxDir::Exists(dirName) &&
857 d.Open(dirName) &&
858 d.GetFirst(& Filename, filespec, flags)
859 )
860 {
861 do
862 {
863 if (m_is_skin) {
864 Filename = wxT("User:")L"User:" + Filename;
865 }
866 skinSelector->Append(Filename);
867 }
868 while (d.GetNext(&Filename));
869 }
870
871 wxString dataDir;
872 if (m_is_skin) {
873 dataDir = wxStandardPaths::Get().GetDataDir();
874 } else {
875 dataDir = wxStandardPaths::Get().GetResourcesDir();
876 }
877#if !defined(__WINDOWS__) && !defined(__WXMAC__)
878 dataDir = dataDir.BeforeLast(wxT('/')L'/') + wxT("/amule")L"/amule";
879#endif
880 wxString systemDir(JoinPaths(dataDir,folder));
881
882 if (wxDir::Exists(systemDir) &&
883 d.Open(systemDir) &&
884 d.GetFirst(& Filename, filespec, flags)
885 )
886 {
887 do
888 {
889 if (m_is_skin) {
890 Filename = wxT("System:")L"System:" + Filename;
891 }
892 // avoid duplicates for webserver templates
893 if (skinSelector->FindString(Filename) == wxNOT_FOUND(-1)) {
894 skinSelector->Append(Filename);
895 }
896 }
897 while (d.GetNext(&Filename));
898 }
899
900 if ( skinSelector->GetCount() == 0 ) {
901 skinSelector->Append(_("no options available")wxGetTranslation(("no options available")));
902 }
903
904 int id = skinSelector->FindString(m_value);
905 if ( id == wxNOT_FOUND(-1) ) {
906 id = 0;
907 if (m_is_skin) {
908 m_value = defaultSelection;
909 }
910 }
911 skinSelector->SetSelection(id);
912
913 return Cfg_Str::TransferToWindow();
914 }
915#endif /* ! AMULE_DAEMON */
916
917 protected:
918 bool m_is_skin;
919};
920
921
922/// new implementation
923CPreferences::CPreferences()
924{
925 srand( wxGetLocalTimeMillis().GetLo() ); // we need random numbers sometimes
926
927 // load preferences.dat or set standard values
928 wxString fullpath(s_configDir + wxT("preferences.dat")L"preferences.dat");
929 CFile preffile;
930 if (wxFileExists(fullpath)) {
931 if (preffile.Open(fullpath, CFile::read)) {
932 try {
933 preffile.ReadUInt8(); // Version. Value is not used.
934 s_userhash = preffile.ReadHash();
935 } catch (const CSafeIOException& e) {
936 AddDebugLogLineC(logGeneral,theLogger.AddLogLine(L"Preferences.cpp", 937, true, logGeneral
, L"Error while reading userhash: " + e.what())
937 wxT("Error while reading userhash: ") + e.what())theLogger.AddLogLine(L"Preferences.cpp", 937, true, logGeneral
, L"Error while reading userhash: " + e.what())
;
938 }
939 }
940 }
941
942 if (s_userhash.IsEmpty()) {
943 for (int i = 0; i < 8; i++) {
944 RawPokeUInt16(s_userhash.GetHash() + (i * 2), rand());
945 }
946
947 Save();
948 }
949
950 // Mark hash as an eMule-type hash
951 // See also CUpDownClient::GetHashType
952 s_userhash[5] = 14;
953 s_userhash[14] = 111;
954
955#ifndef CLIENT_GUI
956 LoadPreferences();
957 ReloadSharedFolders();
958
959 // serverlist addresses
960 CTextFile slistfile;
961 if (slistfile.Open(s_configDir + wxT("addresses.dat")L"addresses.dat", CTextFile::read)) {
962 adresses_list = slistfile.ReadLines();
963 }
964#endif
965}
966
967//
968// Gets called at init time
969//
970void CPreferences::BuildItemList( const wxString& appdir )
971{
972#ifndef AMULE_DAEMON1
973 #define NewCfgItem(ID, COMMAND)s_CfgList[++current_id] = COMMAND s_CfgList[ID] = COMMAND
974#else
975 int current_id = 0;
976 #define NewCfgItem(ID, COMMAND)s_CfgList[++current_id] = COMMAND s_CfgList[++current_id] = COMMAND
977#endif /* AMULE_DAEMON */
978
979 /**
980 * User settings
981 **/
982 NewCfgItem(IDC_NICK, (new Cfg_Str( wxT("/eMule/Nick"), s_nick, wxT("http://www.aMule.org") )))s_CfgList[++current_id] = (new Cfg_Str( L"/eMule/Nick", s_nick
, L"http://www.aMule.org" ))
;
983#ifndef AMULE_DAEMON1
984 Cfg_Lang * cfgLang = new Cfg_Lang();
985 s_cfgLang = cfgLang;
986 NewCfgItem(IDC_LANGUAGE, cfgLang)s_CfgList[++current_id] = cfgLang;
987#endif
988
989 /**
990 * Browser options
991 **/
992 #ifdef __WXMAC__
993 wxString customBrowser = wxT("/usr/bin/open")L"/usr/bin/open";
994 #else
995 wxString customBrowser; // left empty
996 #endif
997
998 NewCfgItem(IDC_BROWSERTABS, (new Cfg_Bool( wxT("/Browser/OpenPageInTab"), s_BrowserTab, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/Browser/OpenPageInTab"
, s_BrowserTab, true ))
;
999 NewCfgItem(IDC_BROWSERSELF, (new Cfg_Str( wxT("/Browser/CustomBrowserString"), s_CustomBrowser, customBrowser )))s_CfgList[++current_id] = (new Cfg_Str( L"/Browser/CustomBrowserString"
, s_CustomBrowser, customBrowser ))
;
1000
1001
1002 /**
1003 * Misc
1004 **/
1005 NewCfgItem(IDC_QUEUESIZE, (MkCfg_Int( wxT("/eMule/QueueSizePref"), s_iQueueSize, 50 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/QueueSizePref"
, s_iQueueSize, 50 ))
;
1006
1007
1008#ifdef __DEBUG__
1009 /**
1010 * Debugging
1011 **/
1012 NewCfgItem(ID_VERBOSEDEBUG, (new Cfg_Bool( wxT("/eMule/VerboseDebug"), s_bVerbose, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/VerboseDebug"
, s_bVerbose, false ))
;
1013 NewCfgItem(ID_VERBOSEDEBUGLOGFILE, (new Cfg_Bool( wxT("/eMule/VerboseDebugLogfile"), s_bVerboseLogfile, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/VerboseDebugLogfile"
, s_bVerboseLogfile, false ))
;
1014#endif
1015
1016 /**
1017 * Connection settings
1018 **/
1019 NewCfgItem(IDC_MAXUP, (MkCfg_Int( wxT("/eMule/MaxUpload"), s_maxupload, 0 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/MaxUpload", s_maxupload
, 0 ))
;
1020 NewCfgItem(IDC_MAXDOWN, (MkCfg_Int( wxT("/eMule/MaxDownload"), s_maxdownload, 0 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/MaxDownload", s_maxdownload
, 0 ))
;
1021 NewCfgItem(IDC_SLOTALLOC, (MkCfg_Int( wxT("/eMule/SlotAllocation"), s_slotallocation, 2 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/SlotAllocation"
, s_slotallocation, 2 ))
;
1022 NewCfgItem(IDC_PORT, (MkCfg_Int( wxT("/eMule/Port"), s_port, DEFAULT_TCP_PORT )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/Port", s_port,
4662 ))
;
1023 NewCfgItem(IDC_UDPPORT, (MkCfg_Int( wxT("/eMule/UDPPort"), s_udpport, DEFAULT_UDP_PORT )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/UDPPort", s_udpport
, 4672 ))
;
1024 NewCfgItem(IDC_UDPENABLE, (new Cfg_Bool( wxT("/eMule/UDPEnable"), s_UDPEnable, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/UDPEnable",
s_UDPEnable, true ))
;
1025 NewCfgItem(IDC_ADDRESS, (new Cfg_Str( wxT("/eMule/Address"), s_Addr, wxEmptyString)))s_CfgList[++current_id] = (new Cfg_Str( L"/eMule/Address", s_Addr
, wxEmptyString))
;
1026 NewCfgItem(IDC_AUTOCONNECT, (new Cfg_Bool( wxT("/eMule/Autoconnect"), s_autoconnect, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/Autoconnect"
, s_autoconnect, true ))
;
1027 NewCfgItem(IDC_MAXSOURCEPERFILE, (MkCfg_Int( wxT("/eMule/MaxSourcesPerFile"), s_maxsourceperfile, 300 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/MaxSourcesPerFile"
, s_maxsourceperfile, 300 ))
;
1028 NewCfgItem(IDC_MAXCON, (MkCfg_Int( wxT("/eMule/MaxConnections"), s_maxconnections, GetRecommendedMaxConnections() )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/MaxConnections"
, s_maxconnections, GetRecommendedMaxConnections() ))
;
1029 NewCfgItem(IDC_MAXCON5SEC, (MkCfg_Int( wxT("/eMule/MaxConnectionsPerFiveSeconds"), s_MaxConperFive, 20 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/MaxConnectionsPerFiveSeconds"
, s_MaxConperFive, 20 ))
;
1030
1031 /**
1032 * Proxy
1033 **/
1034 NewCfgItem(ID_PROXY_ENABLE_PROXY, (new Cfg_Bool( wxT("/Proxy/ProxyEnableProxy"), s_ProxyData.m_proxyEnable, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/Proxy/ProxyEnableProxy"
, s_ProxyData.m_proxyEnable, false ))
;
1035 NewCfgItem(ID_PROXY_TYPE, (MkCfg_Int( wxT("/Proxy/ProxyType"), s_ProxyData.m_proxyType, 0 )))s_CfgList[++current_id] = (MkCfg_Int( L"/Proxy/ProxyType", s_ProxyData
.m_proxyType, 0 ))
;
1036 NewCfgItem(ID_PROXY_NAME, (new Cfg_Str( wxT("/Proxy/ProxyName"), s_ProxyData.m_proxyHostName, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Str( L"/Proxy/ProxyName", s_ProxyData
.m_proxyHostName, wxEmptyString ))
;
1037 NewCfgItem(ID_PROXY_PORT, (MkCfg_Int( wxT("/Proxy/ProxyPort"), s_ProxyData.m_proxyPort, 1080 )))s_CfgList[++current_id] = (MkCfg_Int( L"/Proxy/ProxyPort", s_ProxyData
.m_proxyPort, 1080 ))
;
1038 NewCfgItem(ID_PROXY_ENABLE_PASSWORD, (new Cfg_Bool( wxT("/Proxy/ProxyEnablePassword"), s_ProxyData.m_enablePassword, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/Proxy/ProxyEnablePassword"
, s_ProxyData.m_enablePassword, false ))
;
1039 NewCfgItem(ID_PROXY_USER, (new Cfg_Str( wxT("/Proxy/ProxyUser"), s_ProxyData.m_userName, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Str( L"/Proxy/ProxyUser", s_ProxyData
.m_userName, wxEmptyString ))
;
1040 NewCfgItem(ID_PROXY_PASSWORD, (new Cfg_Str( wxT("/Proxy/ProxyPassword"), s_ProxyData.m_password, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Str( L"/Proxy/ProxyPassword"
, s_ProxyData.m_password, wxEmptyString ))
;
1041// These were copied from eMule config file, maybe someone with windows can complete this?
1042// NewCfgItem(ID_PROXY_AUTO_SERVER_CONNECT_WITHOUT_PROXY, (new Cfg_Bool( wxT("/Proxy/Proxy????"), s_Proxy????, false )));
1043
1044 /**
1045 * Servers
1046 **/
1047 NewCfgItem(IDC_REMOVEDEAD, (new Cfg_Bool( wxT("/eMule/RemoveDeadServer"), s_deadserver, 1 )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/RemoveDeadServer"
, s_deadserver, 1 ))
;
1048 NewCfgItem(IDC_SERVERRETRIES, (MkCfg_Int( wxT("/eMule/DeadServerRetry"), s_deadserverretries, 3 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/DeadServerRetry"
, s_deadserverretries, 3 ))
;
1049 NewCfgItem(IDC_SERVERKEEPALIVE, (MkCfg_Int( wxT("/eMule/ServerKeepAliveTimeout"), s_dwServerKeepAliveTimeoutMins, 0 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/ServerKeepAliveTimeout"
, s_dwServerKeepAliveTimeoutMins, 0 ))
;
1050 NewCfgItem(IDC_RECONN, (new Cfg_Bool( wxT("/eMule/Reconnect"), s_reconnect, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/Reconnect",
s_reconnect, true ))
;
1051 NewCfgItem(IDC_SCORE, (new Cfg_Bool( wxT("/eMule/Scoresystem"), s_scorsystem, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/Scoresystem"
, s_scorsystem, true ))
;
1052 NewCfgItem(IDC_AUTOSERVER, (new Cfg_Bool( wxT("/eMule/Serverlist"), s_autoserverlist, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/Serverlist"
, s_autoserverlist, false ))
;
1053 NewCfgItem(IDC_UPDATESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/AddServerListFromServer"), s_addserversfromserver, false)))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/AddServerListFromServer"
, s_addserversfromserver, false))
;
1054 NewCfgItem(IDC_UPDATESERVERCLIENT, (new Cfg_Bool( wxT("/eMule/AddServerListFromClient"), s_addserversfromclient, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/AddServerListFromClient"
, s_addserversfromclient, false ))
;
1055 NewCfgItem(IDC_SAFESERVERCONNECT, (new Cfg_Bool( wxT("/eMule/SafeServerConnect"), s_safeServerConnect, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/SafeServerConnect"
, s_safeServerConnect, false ))
;
1056 NewCfgItem(IDC_AUTOCONNECTSTATICONLY, (new Cfg_Bool( wxT("/eMule/AutoConnectStaticOnly"), s_autoconnectstaticonly, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/AutoConnectStaticOnly"
, s_autoconnectstaticonly, false ))
;
1057 NewCfgItem(IDC_UPNP_ENABLED, (new Cfg_Bool( wxT("/eMule/UPnPEnabled"), s_UPnPEnabled, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/UPnPEnabled"
, s_UPnPEnabled, false ))
;
1058 NewCfgItem(IDC_UPNPTCPPORT, (MkCfg_Int( wxT("/eMule/UPnPTCPPort"), s_UPnPTCPPort, 50000 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/UPnPTCPPort", s_UPnPTCPPort
, 50000 ))
;
1059 NewCfgItem(IDC_SMARTIDCHECK, (new Cfg_Bool( wxT("/eMule/SmartIdCheck"), s_smartidcheck, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/SmartIdCheck"
, s_smartidcheck, true ))
;
1060 // Enabled networks
1061 NewCfgItem( IDC_NETWORKKAD, (new Cfg_Bool( wxT("/eMule/ConnectToKad"), s_ConnectToKad, true )) )s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ConnectToKad"
, s_ConnectToKad, true ))
;
1062 NewCfgItem( IDC_NETWORKED2K, ( new Cfg_Bool( wxT("/eMule/ConnectToED2K"), s_ConnectToED2K, true ) ))s_CfgList[++current_id] = ( new Cfg_Bool( L"/eMule/ConnectToED2K"
, s_ConnectToED2K, true ) )
;
1063
1064
1065 /**
1066 * Files
1067 **/
1068 NewCfgItem(IDC_TEMPFILES, (new Cfg_Path( wxT("/eMule/TempDir"), s_tempdir, appdir + wxT("Temp") )))s_CfgList[++current_id] = (new Cfg_Path( L"/eMule/TempDir", s_tempdir
, appdir + L"Temp" ))
;
1069
1070 #if defined(__WXMAC__) || defined(__WINDOWS__)
1071 wxString incpath = wxStandardPaths::Get().GetDocumentsDir();
1072 if (incpath.IsEmpty()) {
1073 // There is a built-in possibility for this call to fail, though I can't imagine a reason for that.
1074 incpath = appdir + wxT("Incoming")L"Incoming";
1075 } else {
1076 incpath = JoinPaths(incpath, wxT("aMule Downloads")L"aMule Downloads");
1077 }
1078 #else
1079 wxString incpath = appdir + wxT("Incoming")L"Incoming";
1080 #endif
1081 NewCfgItem(IDC_INCFILES, (new Cfg_Path( wxT("/eMule/IncomingDir"), s_incomingdir, incpath )))s_CfgList[++current_id] = (new Cfg_Path( L"/eMule/IncomingDir"
, s_incomingdir, incpath ))
;
1082
1083 NewCfgItem(IDC_ICH, (new Cfg_Bool( wxT("/eMule/ICH"), s_ICH, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ICH", s_ICH
, true ))
;
1084 NewCfgItem(IDC_AICHTRUST, (new Cfg_Bool( wxT("/eMule/AICHTrust"), s_AICHTrustEveryHash, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/AICHTrust",
s_AICHTrustEveryHash, false ))
;
1085 NewCfgItem(IDC_CHECKDISKSPACE, (new Cfg_Bool( wxT("/eMule/CheckDiskspace"), s_checkDiskspace, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/CheckDiskspace"
, s_checkDiskspace, true ))
;
1086 NewCfgItem(IDC_MINDISKSPACE, (MkCfg_Int( wxT("/eMule/MinFreeDiskSpace"), s_uMinFreeDiskSpace, 1 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/MinFreeDiskSpace"
, s_uMinFreeDiskSpace, 1 ))
;
1087 NewCfgItem(IDC_ADDNEWFILESPAUSED, (new Cfg_Bool( wxT("/eMule/AddNewFilesPaused"), s_addnewfilespaused, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/AddNewFilesPaused"
, s_addnewfilespaused, false ))
;
1088 NewCfgItem(IDC_PREVIEWPRIO, (new Cfg_Bool( wxT("/eMule/PreviewPrio"), s_bpreviewprio, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/PreviewPrio"
, s_bpreviewprio, false ))
;
1089 NewCfgItem(IDC_MANUALSERVERHIGHPRIO, (new Cfg_Bool( wxT("/eMule/ManualHighPrio"), s_bmanualhighprio, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ManualHighPrio"
, s_bmanualhighprio, false ))
;
1090 NewCfgItem(IDC_STARTNEXTFILE, (new Cfg_Bool( wxT("/eMule/StartNextFile"), s_bstartnextfile, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/StartNextFile"
, s_bstartnextfile, false ))
;
1091 NewCfgItem(IDC_STARTNEXTFILE_SAME, (new Cfg_Bool( wxT("/eMule/StartNextFileSameCat"), s_bstartnextfilesame, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/StartNextFileSameCat"
, s_bstartnextfilesame, false ))
;
1092 NewCfgItem(IDC_STARTNEXTFILE_ALPHA, (new Cfg_Bool( wxT("/eMule/StartNextFileAlpha"), s_bstartnextfilealpha, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/StartNextFileAlpha"
, s_bstartnextfilealpha, false ))
;
1093 NewCfgItem(IDC_SRCSEEDS, (new Cfg_Bool( wxT("/ExternalConnect/UseSrcSeeds"), s_UseSrcSeeds, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/ExternalConnect/UseSrcSeeds"
, s_UseSrcSeeds, false ))
;
1094 NewCfgItem(IDC_FILEBUFFERSIZE, (MkCfg_Int( wxT("/eMule/FileBufferSizePref"), s_iFileBufferSize, 16 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/FileBufferSizePref"
, s_iFileBufferSize, 16 ))
;
1095 NewCfgItem(IDC_DAP, (new Cfg_Bool( wxT("/eMule/DAPPref"), s_bDAP, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/DAPPref", s_bDAP
, true ))
;
1096 NewCfgItem(IDC_UAP, (new Cfg_Bool( wxT("/eMule/UAPPref"), s_bUAP, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/UAPPref", s_bUAP
, true ))
;
1097 NewCfgItem(IDC_ALLOCFULLFILE, (new Cfg_Bool( wxT("/eMule/AllocateFullFile"), s_allocFullFile, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/AllocateFullFile"
, s_allocFullFile, false ))
;
1098
1099 /**
1100 * Web Server
1101 */
1102 NewCfgItem(IDC_OSDIR, (new Cfg_Path( wxT("/eMule/OSDirectory"), s_OSDirectory, appdir )))s_CfgList[++current_id] = (new Cfg_Path( L"/eMule/OSDirectory"
, s_OSDirectory, appdir ))
;
1103 NewCfgItem(IDC_ONLINESIG, (new Cfg_Bool( wxT("/eMule/OnlineSignature"), s_onlineSig, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/OnlineSignature"
, s_onlineSig, false ))
;
1104 NewCfgItem(IDC_OSUPDATE, (MkCfg_Int( wxT("/eMule/OnlineSignatureUpdate"), s_OSUpdate, 5 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/OnlineSignatureUpdate"
, s_OSUpdate, 5 ))
;
1105 NewCfgItem(IDC_ENABLE_WEB, (new Cfg_Bool( wxT("/WebServer/Enabled"), s_bWebEnabled, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/WebServer/Enabled"
, s_bWebEnabled, false ))
;
1106 NewCfgItem(IDC_WEB_PASSWD, (new Cfg_Str_Encrypted( wxT("/WebServer/Password"), s_sWebPassword )))s_CfgList[++current_id] = (new Cfg_Str_Encrypted( L"/WebServer/Password"
, s_sWebPassword ))
;
1107 NewCfgItem(IDC_WEB_PASSWD_LOW, (new Cfg_Str_Encrypted( wxT("/WebServer/PasswordLow"), s_sWebLowPassword )))s_CfgList[++current_id] = (new Cfg_Str_Encrypted( L"/WebServer/PasswordLow"
, s_sWebLowPassword ))
;
1108 NewCfgItem(IDC_WEB_PORT, (MkCfg_Int( wxT("/WebServer/Port"), s_nWebPort, 4711 )))s_CfgList[++current_id] = (MkCfg_Int( L"/WebServer/Port", s_nWebPort
, 4711 ))
;
1109 NewCfgItem(IDC_WEBUPNPTCPPORT, (MkCfg_Int( wxT("/WebServer/WebUPnPTCPPort"), s_nWebUPnPTCPPort, 50001 )))s_CfgList[++current_id] = (MkCfg_Int( L"/WebServer/WebUPnPTCPPort"
, s_nWebUPnPTCPPort, 50001 ))
;
1110 NewCfgItem(IDC_UPNP_WEBSERVER_ENABLED,s_CfgList[++current_id] = (new Cfg_Bool( L"/WebServer/UPnPWebServerEnabled"
, s_UPnPWebServerEnabled, false ))
1111 (new Cfg_Bool( wxT("/WebServer/UPnPWebServerEnabled"), s_UPnPWebServerEnabled, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/WebServer/UPnPWebServerEnabled"
, s_UPnPWebServerEnabled, false ))
;
1112 NewCfgItem(IDC_WEB_GZIP, (new Cfg_Bool( wxT("/WebServer/UseGzip"), s_bWebUseGzip, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/WebServer/UseGzip"
, s_bWebUseGzip, true ))
;
1113 NewCfgItem(IDC_ENABLE_WEB_LOW, (new Cfg_Bool( wxT("/WebServer/UseLowRightsUser"), s_bWebLowEnabled, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/WebServer/UseLowRightsUser"
, s_bWebLowEnabled, false ))
;
1114 NewCfgItem(IDC_WEB_REFRESH_TIMEOUT, (MkCfg_Int( wxT("/WebServer/PageRefreshTime"), s_nWebPageRefresh, 120 )))s_CfgList[++current_id] = (MkCfg_Int( L"/WebServer/PageRefreshTime"
, s_nWebPageRefresh, 120 ))
;
1115 NewCfgItem(IDC_WEBTEMPLATE, (new Cfg_Skin( wxT("/WebServer/Template"), s_WebTemplate, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Skin( L"/WebServer/Template"
, s_WebTemplate, wxEmptyString ))
;
1116
1117 /**
1118 * External Connections
1119 */
1120 NewCfgItem(IDC_EXT_CONN_ACCEPT, (new Cfg_Bool( wxT("/ExternalConnect/AcceptExternalConnections"), s_AcceptExternalConnections, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/ExternalConnect/AcceptExternalConnections"
, s_AcceptExternalConnections, false ))
;
1121 NewCfgItem(IDC_EXT_CONN_IP, (new Cfg_Str( wxT("/ExternalConnect/ECAddress"), s_ECAddr, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Str( L"/ExternalConnect/ECAddress"
, s_ECAddr, wxEmptyString ))
;
1122 NewCfgItem(IDC_EXT_CONN_TCP_PORT, (MkCfg_Int( wxT("/ExternalConnect/ECPort"), s_ECPort, 4712 )))s_CfgList[++current_id] = (MkCfg_Int( L"/ExternalConnect/ECPort"
, s_ECPort, 4712 ))
;
1123 NewCfgItem(IDC_EXT_CONN_PASSWD, (new Cfg_Str_Encrypted( wxT("/ExternalConnect/ECPassword"), s_ECPassword, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Str_Encrypted( L"/ExternalConnect/ECPassword"
, s_ECPassword, wxEmptyString ))
;
1124 NewCfgItem(IDC_UPNP_EC_ENABLED, (new Cfg_Bool( wxT("/ExternalConnect/UPnPECEnabled"), s_UPnPECEnabled, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/ExternalConnect/UPnPECEnabled"
, s_UPnPECEnabled, false ))
;
1125
1126 /**
1127 * GUI behavior
1128 **/
1129 NewCfgItem(IDC_MACHIDEONCLOSE, (new Cfg_Bool( wxT("/GUI/HideOnClose"), s_hideonclose, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/GUI/HideOnClose",
s_hideonclose, false ))
;
1130 NewCfgItem(IDC_ENABLETRAYICON, (new Cfg_Bool( wxT("/eMule/EnableTrayIcon"), s_trayiconenabled, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/EnableTrayIcon"
, s_trayiconenabled, false ))
;
1131 NewCfgItem(IDC_MINTRAY, (new Cfg_Bool( wxT("/eMule/MinToTray"), s_mintotray, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/MinToTray",
s_mintotray, false ))
;
1132 NewCfgItem(IDC_NOTIF, (new Cfg_Bool( wxT("/eMule/Notifications"), s_notify, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/Notifications"
, s_notify, false ))
;
1133 NewCfgItem(IDC_EXIT, (new Cfg_Bool( wxT("/eMule/ConfirmExit"), s_confirmExit, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ConfirmExit"
, s_confirmExit, true ))
;
1134 NewCfgItem(IDC_STARTMIN, (new Cfg_Bool( wxT("/eMule/StartupMinimized"), s_startMinimized, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/StartupMinimized"
, s_startMinimized, false ))
;
1135
1136 /**
1137 * GUI appearance
1138 **/
1139 NewCfgItem(IDC_3DDEPTH, (MkCfg_Int( wxT("/eMule/3DDepth"), s_depth3D, 10 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/3DDepth", s_depth3D
, 10 ))
;
1140 NewCfgItem(IDC_TOOLTIPDELAY, (MkCfg_Int( wxT("/eMule/ToolTipDelay"), s_iToolDelayTime, 1 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/ToolTipDelay",
s_iToolDelayTime, 1 ))
;
1141 NewCfgItem(IDC_SHOWOVERHEAD, (new Cfg_Bool( wxT("/eMule/ShowOverhead"), s_bshowoverhead, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ShowOverhead"
, s_bshowoverhead, false ))
;
1142 NewCfgItem(IDC_EXTCATINFO, (new Cfg_Bool( wxT("/eMule/ShowInfoOnCatTabs"), s_showCatTabInfos, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ShowInfoOnCatTabs"
, s_showCatTabInfos, true ))
;
1143 NewCfgItem(IDC_FED2KLH, (new Cfg_Bool( wxT("/Razor_Preferences/FastED2KLinksHandler"), s_FastED2KLinksHandler, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/Razor_Preferences/FastED2KLinksHandler"
, s_FastED2KLinksHandler, true ))
;
1144 NewCfgItem(IDC_PROGBAR, (new Cfg_Bool( wxT("/ExternalConnect/ShowProgressBar"), s_ProgBar, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/ExternalConnect/ShowProgressBar"
, s_ProgBar, true ))
;
1145 NewCfgItem(IDC_PERCENT, (new Cfg_Bool( wxT("/ExternalConnect/ShowPercent"), s_Percent, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/ExternalConnect/ShowPercent"
, s_Percent, true ))
;
1146 NewCfgItem(IDC_SKIN, (new Cfg_Skin( wxT("/SkinGUIOptions/Skin"), s_Skin, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Skin( L"/SkinGUIOptions/Skin"
, s_Skin, wxEmptyString ))
;
1147 NewCfgItem(IDC_VERTTOOLBAR, (new Cfg_Bool( wxT("/eMule/VerticalToolbar"), s_ToolbarOrientation, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/VerticalToolbar"
, s_ToolbarOrientation, false ))
;
1148 NewCfgItem(IDC_SHOW_COUNTRY_FLAGS, (new Cfg_Bool( wxT("/eMule/GeoIPEnabled"), s_GeoIPEnabled, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/GeoIPEnabled"
, s_GeoIPEnabled, true ))
;
1149#ifndef __SVN__
1150 NewCfgItem(IDC_SHOWVERSIONONTITLE, (new Cfg_Bool( wxT("/eMule/ShowVersionOnTitle"), s_showVersionOnTitle, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ShowVersionOnTitle"
, s_showVersionOnTitle, false ))
;
1151#endif
1152
1153 /**
1154 * External Apps
1155 */
1156 NewCfgItem(IDC_VIDEOPLAYER, (new Cfg_Str( wxT("/eMule/VideoPlayer"), s_VideoPlayer, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Str( L"/eMule/VideoPlayer"
, s_VideoPlayer, wxEmptyString ))
;
1157
1158 /**
1159 * Statistics
1160 **/
1161 NewCfgItem(IDC_SLIDER, (MkCfg_Int( wxT("/eMule/StatGraphsInterval"), s_trafficOMeterInterval, 3 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/StatGraphsInterval"
, s_trafficOMeterInterval, 3 ))
;
1162 NewCfgItem(IDC_SLIDER2, (MkCfg_Int( wxT("/eMule/statsInterval"), s_statsInterval, 30 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/statsInterval"
, s_statsInterval, 30 ))
;
1163 NewCfgItem(IDC_DOWNLOAD_CAP, (MkCfg_Int( wxT("/eMule/DownloadCapacity"), s_maxGraphDownloadRate, 300 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/DownloadCapacity"
, s_maxGraphDownloadRate, 300 ))
;
1164 NewCfgItem(IDC_UPLOAD_CAP, (MkCfg_Int( wxT("/eMule/UploadCapacity"), s_maxGraphUploadRate, 100 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/UploadCapacity"
, s_maxGraphUploadRate, 100 ))
;
1165 NewCfgItem(IDC_SLIDER3, (MkCfg_Int( wxT("/eMule/StatsAverageMinutes"), s_statsAverageMinutes, 5 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/StatsAverageMinutes"
, s_statsAverageMinutes, 5 ))
;
1166 NewCfgItem(IDC_SLIDER4, (MkCfg_Int( wxT("/eMule/VariousStatisticsMaxValue"), s_statsMax, 100 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/VariousStatisticsMaxValue"
, s_statsMax, 100 ))
;
1167 NewCfgItem(IDC_CLIENTVERSIONS, (MkCfg_Int( wxT("/Statistics/MaxClientVersions"), s_maxClientVersions, 0 )))s_CfgList[++current_id] = (MkCfg_Int( L"/Statistics/MaxClientVersions"
, s_maxClientVersions, 0 ))
;
1168
1169 /**
1170 * Security
1171 **/
1172 NewCfgItem(IDC_SEESHARES, (MkCfg_Int( wxT("/eMule/SeeShare"), s_iSeeShares, 2 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/SeeShare", s_iSeeShares
, 2 ))
;
1173 NewCfgItem(IDC_SECIDENT, (new Cfg_Bool( wxT("/ExternalConnect/UseSecIdent"), s_SecIdent, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/ExternalConnect/UseSecIdent"
, s_SecIdent, true ))
;
1174 NewCfgItem(IDC_IPFCLIENTS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterClients"), s_IPFilterClients, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/ExternalConnect/IpFilterClients"
, s_IPFilterClients, true ))
;
1175 NewCfgItem(IDC_IPFSERVERS, (new Cfg_Bool( wxT("/ExternalConnect/IpFilterServers"), s_IPFilterServers, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/ExternalConnect/IpFilterServers"
, s_IPFilterServers, true ))
;
1176 NewCfgItem(IDC_FILTERLAN, (new Cfg_Bool( wxT("/eMule/FilterLanIPs"), s_filterLanIP, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/FilterLanIPs"
, s_filterLanIP, true ))
;
1177 NewCfgItem(IDC_PARANOID, (new Cfg_Bool( wxT("/eMule/ParanoidFiltering"), s_paranoidfilter, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ParanoidFiltering"
, s_paranoidfilter, true ))
;
1178 NewCfgItem(IDC_AUTOIPFILTER, (new Cfg_Bool( wxT("/eMule/IPFilterAutoLoad"), s_IPFilterAutoLoad, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/IPFilterAutoLoad"
, s_IPFilterAutoLoad, true ))
;
1179 NewCfgItem(IDC_IPFILTERURL, (new Cfg_Str( wxT("/eMule/IPFilterURL"), s_IPFilterURL, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Str( L"/eMule/IPFilterURL"
, s_IPFilterURL, wxEmptyString ))
;
1180 NewCfgItem(ID_IPFILTERLEVEL, (MkCfg_Int( wxT("/eMule/FilterLevel"), s_filterlevel, 127 )))s_CfgList[++current_id] = (MkCfg_Int( L"/eMule/FilterLevel", s_filterlevel
, 127 ))
;
1181 NewCfgItem(IDC_IPFILTERSYS, (new Cfg_Bool( wxT("/eMule/IPFilterSystem"), s_IPFilterSys, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/IPFilterSystem"
, s_IPFilterSys, false ))
;
1182
1183 /**
1184 * Message Filter
1185 **/
1186 NewCfgItem(IDC_MSGFILTER, (new Cfg_Bool( wxT("/eMule/FilterMessages"), s_MustFilterMessages, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/FilterMessages"
, s_MustFilterMessages, true ))
;
1187 NewCfgItem(IDC_MSGFILTER_ALL, (new Cfg_Bool( wxT("/eMule/FilterAllMessages"), s_FilterAllMessages, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/FilterAllMessages"
, s_FilterAllMessages, false ))
;
1188 NewCfgItem(IDC_MSGFILTER_NONFRIENDS, (new Cfg_Bool( wxT("/eMule/MessagesFromFriendsOnly"), s_msgonlyfriends, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/MessagesFromFriendsOnly"
, s_msgonlyfriends, false ))
;
1189 NewCfgItem(IDC_MSGFILTER_NONSECURE, (new Cfg_Bool( wxT("/eMule/MessageFromValidSourcesOnly"), s_msgsecure, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/MessageFromValidSourcesOnly"
, s_msgsecure, true ))
;
1190 NewCfgItem(IDC_MSGFILTER_WORD, (new Cfg_Bool( wxT("/eMule/FilterWordMessages"), s_FilterSomeMessages, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/FilterWordMessages"
, s_FilterSomeMessages, false ))
;
1191 NewCfgItem(IDC_MSGWORD, (new Cfg_Str( wxT("/eMule/MessageFilter"), s_MessageFilterString, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Str( L"/eMule/MessageFilter"
, s_MessageFilterString, wxEmptyString ))
;
1192 NewCfgItem(IDC_MSGLOG, (new Cfg_Bool( wxT("/eMule/ShowMessagesInLog"), s_ShowMessagesInLog, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ShowMessagesInLog"
, s_ShowMessagesInLog, true ))
;
1193 //Todo NewCfgItem(IDC_MSGADVSPAM, (new Cfg_Bool( wxT("/eMule/AdvancedSpamFilter"), s_IsAdvancedSpamfilterEnabled, true )));
1194 //Todo NewCfgItem(IDC_MSGCAPTCHA, (new Cfg_Bool( wxT("/eMule/MessageUseCaptchas"), s_IsChatCaptchaEnabled, true )));
1195 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/AdvancedSpamFilter")L"/eMule/AdvancedSpamFilter", s_IsAdvancedSpamfilterEnabled, true ) );
1196 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/MessageUseCaptchas")L"/eMule/MessageUseCaptchas", s_IsChatCaptchaEnabled, true ) );
1197
1198 NewCfgItem(IDC_FILTERCOMMENTS, (new Cfg_Bool( wxT("/eMule/FilterComments"), s_FilterComments, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/FilterComments"
, s_FilterComments, false ))
;
1199 NewCfgItem(IDC_COMMENTWORD, (new Cfg_Str( wxT("/eMule/CommentFilter"), s_CommentFilterString, wxEmptyString )))s_CfgList[++current_id] = (new Cfg_Str( L"/eMule/CommentFilter"
, s_CommentFilterString, wxEmptyString ))
;
1200
1201 /**
1202 * Hidden files sharing
1203 **/
1204 NewCfgItem(IDC_SHAREHIDDENFILES, (new Cfg_Bool( wxT("/eMule/ShareHiddenFiles"), s_ShareHiddenFiles, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/ShareHiddenFiles"
, s_ShareHiddenFiles, false ))
;
1205
1206 /**
1207 * Auto-Sorting of downloads
1208 **/
1209 NewCfgItem(IDC_AUTOSORT, (new Cfg_Bool( wxT("/eMule/AutoSortDownloads"), s_AutoSortDownload, false )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/AutoSortDownloads"
, s_AutoSortDownload, false ))
;
1210
1211 /**
1212 * Version check
1213 **/
1214 NewCfgItem(IDC_NEWVERSION, (new Cfg_Bool( wxT("/eMule/NewVersionCheck"), s_NewVersionCheck, true )))s_CfgList[++current_id] = (new Cfg_Bool( L"/eMule/NewVersionCheck"
, s_NewVersionCheck, true ))
;
1215
1216 /**
1217 * Obfuscation
1218 **/
1219 NewCfgItem( IDC_SUPPORT_PO, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerSupported"), s_IsClientCryptLayerSupported, true )))s_CfgList[++current_id] = ( new Cfg_Bool( L"/Obfuscation/IsClientCryptLayerSupported"
, s_IsClientCryptLayerSupported, true ))
;
1220 NewCfgItem( IDC_ENABLE_PO_OUTGOING, ( new Cfg_Bool( wxT("/Obfuscation/IsCryptLayerRequested"), s_bCryptLayerRequested, true )))s_CfgList[++current_id] = ( new Cfg_Bool( L"/Obfuscation/IsCryptLayerRequested"
, s_bCryptLayerRequested, true ))
;
1221 NewCfgItem( IDC_ENFORCE_PO_INCOMING, ( new Cfg_Bool( wxT("/Obfuscation/IsClientCryptLayerRequired"), s_IsClientCryptLayerRequired, false )))s_CfgList[++current_id] = ( new Cfg_Bool( L"/Obfuscation/IsClientCryptLayerRequired"
, s_IsClientCryptLayerRequired, false ))
;
1222#ifndef CLIENT_GUI
1223 // There is no need for GUI items for this two.
1224 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoPaddingLenght")L"/Obfuscation/CryptoPaddingLenght", s_byCryptTCPPaddingLength, 254 ) );
1225 s_MiscList.push_back( MkCfg_Int( wxT("/Obfuscation/CryptoKadUDPKey")L"/Obfuscation/CryptoKadUDPKey", s_dwKadUDPKey, GetRandomUint32() ) );
1226#endif
1227
1228 /**
1229 * Power management
1230 **/
1231 NewCfgItem( IDC_PREVENT_SLEEP, ( new Cfg_Bool( wxT("/PowerManagement/PreventSleepWhileDownloading"), s_preventSleepWhileDownloading, false )))s_CfgList[++current_id] = ( new Cfg_Bool( L"/PowerManagement/PreventSleepWhileDownloading"
, s_preventSleepWhileDownloading, false ))
;
1232
1233 /**
1234 * The following doesn't have an associated widget or section
1235 **/
1236 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Language")L"/eMule/Language", s_languageID ) );
1237 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SplitterbarPosition")L"/eMule/SplitterbarPosition", s_splitterbarPosition, 75 ) );
1238 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/YourHostname")L"/eMule/YourHostname", s_yourHostname, wxEmptyString ) );
1239 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/DateTimeFormat")L"/eMule/DateTimeFormat", s_datetimeformat, wxT("%A, %x, %X")L"%A, %x, %X" ) );
1240
1241 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/AllcatType")L"/eMule/AllcatType", s_allcatFilter, 0 ) );
1242 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/ShowAllNotCats")L"/eMule/ShowAllNotCats", s_showAllNotCats, false ) );
1243
1244 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/SmartIdState")L"/eMule/SmartIdState", s_smartidstate, 0 ) );
1245
1246 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/DropSlowSources")L"/eMule/DropSlowSources", s_DropSlowSources, false ) );
1247
1248 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/KadNodesUrl")L"/eMule/KadNodesUrl", s_KadURL, wxT("http://upd.emule-security.org/nodes.dat")L"http://upd.emule-security.org/nodes.dat" ) );
1249 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/Ed2kServersUrl")L"/eMule/Ed2kServersUrl", s_Ed2kURL, wxT("http://upd.emule-security.org/server.met")L"http://upd.emule-security.org/server.met" ) );
1250 s_MiscList.push_back( MkCfg_Int( wxT("/eMule/ShowRatesOnTitle")L"/eMule/ShowRatesOnTitle", s_showRatesOnTitle, 0 ));
1251
1252 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/GeoLiteCountryUpdateUrl")L"/eMule/GeoLiteCountryUpdateUrl", s_GeoIPUpdateUrl, wxT("http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz")L"http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz" ) );
1253 wxConfigBase::Get()->DeleteEntry(wxT("/eMule/GeoIPUpdateUrl")L"/eMule/GeoIPUpdateUrl"); // get rid of the old one for a while
1254
1255 s_MiscList.push_back( new Cfg_Str( wxT("/WebServer/Path")L"/WebServer/Path", s_sWebPath, wxT("amuleweb")L"amuleweb" ) );
1256
1257 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/StatsServerName")L"/eMule/StatsServerName", s_StatsServerName, wxT("Shorty's ED2K stats")L"Shorty's ED2K stats" ) );
1258 s_MiscList.push_back( new Cfg_Str( wxT("/eMule/StatsServerURL")L"/eMule/StatsServerURL", s_StatsServerURL, wxT("http://ed2k.shortypower.dyndns.org/?hash=")L"http://ed2k.shortypower.dyndns.org/?hash=" ) );
1259
1260 s_MiscList.push_back( new Cfg_Bool( wxT("/ExternalConnect/TransmitOnlyUploadingClients")L"/ExternalConnect/TransmitOnlyUploadingClients", s_TransmitOnlyUploadingClients, false ) );
1261 s_MiscList.push_back( new Cfg_Bool( wxT("/eMule/CreateSparseFiles")L"/eMule/CreateSparseFiles", s_createFilesSparse, true ) );
1262
1263#ifndef AMULE_DAEMON1
1264 // Colors have been moved from global prefs to CStatisticsDlg
1265 for ( int i = 0; i < cntStatColors; i++ ) {
1266 wxString str = CFormat(wxT("/eMule/StatColor%i")L"/eMule/StatColor%i") % i;
1267 s_MiscList.push_back( new Cfg_Colour( str, CStatisticsDlg::acrStat[i] ) );
1268 }
1269#endif
1270
1271 // User events
1272 for (unsigned int i = 0; i < CUserEvents::GetCount(); ++i) {
1273 // We can't use NewCfgItem here, because we need to find these items
1274 // later, which would be impossible in amuled with NewCfgItem.
1275 // The IDs we assign here are high enough to not cause any collision
1276 // even on the daemon.
1277 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT5 + 1] = new Cfg_Bool(wxT("/UserEvents/")L"/UserEvents/" + CUserEvents::GetKey(i) + wxT("/CoreEnabled")L"/CoreEnabled", CUserEvents::GetCoreEnableVar(i), false);
1278 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT5 + 2] = new Cfg_Str(wxT("/UserEvents/")L"/UserEvents/" + CUserEvents::GetKey(i) + wxT("/CoreCommand")L"/CoreCommand", CUserEvents::GetCoreCommandVar(i), wxEmptyString);
1279 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT5 + 3] = new Cfg_Bool(wxT("/UserEvents/")L"/UserEvents/" + CUserEvents::GetKey(i) + wxT("/GUIEnabled")L"/GUIEnabled", CUserEvents::GetGUIEnableVar(i), false);
1280 s_CfgList[USEREVENTS_FIRST_ID + i * USEREVENTS_IDS_PER_EVENT5 + 4] = new Cfg_Str(wxT("/UserEvents/")L"/UserEvents/" + CUserEvents::GetKey(i) + wxT("/GUICommand")L"/GUICommand", CUserEvents::GetGUICommandVar(i), wxEmptyString);
1281 }
1282}
1283
1284
1285void CPreferences::EraseItemList()
1286{
1287 while ( s_CfgList.begin() != s_CfgList.end() ) {
1288 delete s_CfgList.begin()->second;
1289 s_CfgList.erase( s_CfgList.begin() );
1290 }
1291
1292 CFGList::iterator it = s_MiscList.begin();
1293 for ( ; it != s_MiscList.end(); ) {
1294 delete *it;
1295 it = s_MiscList.erase( it );
1296 }
1297}
1298
1299
1300void CPreferences::LoadAllItems(wxConfigBase* cfg)
1301{
1302#ifndef CLIENT_GUI
1303 // Preserve values from old config. The global config object may not be set yet
1304 // when BuildItemList() is called, so we need to provide defaults later - here.
1305 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletion")L"/eMule/ExecOnCompletion")) {
1306 bool ExecOnCompletion;
1307 cfg->Read(wxT("/eMule/ExecOnCompletion")L"/eMule/ExecOnCompletion", &ExecOnCompletion, false);
1308 // Assign to core command, that's the most likely it was.
1309 static_cast<Cfg_Bool*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT5 + 1])->SetDefault(ExecOnCompletion);
1310 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletion")L"/eMule/ExecOnCompletion");
1311 }
1312 if (cfg->HasEntry(wxT("/eMule/ExecOnCompletionCommand")L"/eMule/ExecOnCompletionCommand")) {
1313 wxString ExecOnCompletionCommand;
1314 cfg->Read(wxT("/eMule/ExecOnCompletionCommand")L"/eMule/ExecOnCompletionCommand", &ExecOnCompletionCommand, wxEmptyString);
1315 static_cast<Cfg_Str*>(s_CfgList[USEREVENTS_FIRST_ID + CUserEvents::DownloadCompleted * USEREVENTS_IDS_PER_EVENT5 + 2])->SetDefault(ExecOnCompletionCommand);
1316 cfg->DeleteEntry(wxT("/eMule/ExecOnCompletionCommand")L"/eMule/ExecOnCompletionCommand");
1317 }
1318#endif
1319 CFGMap::iterator it_a = s_CfgList.begin();
1320 for ( ; it_a != s_CfgList.end(); ++it_a ) {
1321 it_a->second->LoadFromFile( cfg );
1322 }
1323
1324 CFGList::iterator it_b = s_MiscList.begin();
1325 for ( ; it_b != s_MiscList.end(); ++it_b ) {
1326 (*it_b)->LoadFromFile( cfg );
1327 }
1328
1329 // Preserve old value of UDPDisable
1330 if (cfg->HasEntry(wxT("/eMule/UDPDisable")L"/eMule/UDPDisable")) {
1331 bool UDPDisable;
1332 cfg->Read(wxT("/eMule/UDPDisable")L"/eMule/UDPDisable", &UDPDisable, false);
1333 SetUDPDisable(UDPDisable);
1334 cfg->DeleteEntry(wxT("/eMule/UDPDisable")L"/eMule/UDPDisable");
1335 }
1336
1337 // Preserve old value of UseSkinFiles
1338 if (cfg->HasEntry(wxT("/SkinGUIOptions/UseSkinFiles")L"/SkinGUIOptions/UseSkinFiles")) {
1339 bool UseSkinFiles;
1340 cfg->Read(wxT("/SkinGUIOptions/UseSkinFiles")L"/SkinGUIOptions/UseSkinFiles", &UseSkinFiles, false);
1341 if (!UseSkinFiles) {
1342 s_Skin.Clear();
1343 }
1344 cfg->DeleteEntry(wxT("/SkinGUIOptions/UseSkinFiles")L"/SkinGUIOptions/UseSkinFiles");
1345 }
1346
1347#ifdef __DEBUG__
1348 // Load debug-categories
1349 int count = theLogger.GetDebugCategoryCount();
1350
1351 for ( int i = 0; i < count; i++ ) {
1352 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1353
1354 bool enabled = false;
1355 cfg->Read( wxT("/Debug/Cat_")L"/Debug/Cat_" + cat.GetName(), &enabled );
1356
1357 theLogger.SetEnabled( cat.GetType(), enabled );
1358 }
1359#endif
1360
1361 // Now do some post-processing / sanity checking on the values we just loaded
1362#ifndef CLIENT_GUI
1363 CheckUlDlRatio();
1364 SetPort(s_port);
1365 if (s_byCryptTCPPaddingLength > 254) {
1366 s_byCryptTCPPaddingLength = GetRandomUint8() % 254;
1367 }
1368 SetSlotAllocation(s_slotallocation);
1369#endif
1370}
1371
1372
1373void CPreferences::SaveAllItems(wxConfigBase* cfg)
1374{
1375 // Save the Cfg values
1376 CFGMap::iterator it_a = s_CfgList.begin();
1377 for ( ; it_a != s_CfgList.end(); ++it_a )
1378 it_a->second->SaveToFile( cfg );
1379
1380 CFGList::iterator it_b = s_MiscList.begin();
1381 for ( ; it_b != s_MiscList.end(); ++it_b )
1382 (*it_b)->SaveToFile( cfg );
1383
1384
1385// Save debug-categories
1386#ifdef __DEBUG__
1387 int count = theLogger.GetDebugCategoryCount();
1388
1389 for ( int i = 0; i < count; i++ ) {
1390 const CDebugCategory& cat = theLogger.GetDebugCategory( i );
1391
1392 cfg->Write( wxT("/Debug/Cat_")L"/Debug/Cat_" + cat.GetName(), cat.IsEnabled() );
1393 }
1394#endif
1395}
1396
1397void CPreferences::SetMaxUpload(uint16 in)
1398{
1399 if ( s_maxupload != in ) {
1400 s_maxupload = in;
1401
1402 // Ensure that the ratio is upheld
1403 CheckUlDlRatio();
1404 }
1405}
1406
1407
1408void CPreferences::SetMaxDownload(uint16 in)
1409{
1410 if ( s_maxdownload != in ) {
1411 s_maxdownload = in;
1412
1413 // Ensure that the ratio is upheld
1414 CheckUlDlRatio();
1415 }
1416}
1417
1418
1419void CPreferences::UnsetAutoServerStart()
1420{
1421 s_autoserverlist = false;
1422}
1423
1424
1425// Here we slightly limit the users' ability to be a bad citizen: for very low upload rates
1426// we force a low download rate, so as to discourage this type of leeching.
1427// We're Open Source, and whoever wants it can do his own mod to get around this, but the
1428// packaged product will try to enforce good behavior.
1429//
1430// Kry note: of course, any leecher mod will be banned asap.
1431void CPreferences::CheckUlDlRatio()
1432{
1433 // Backwards compatibility
1434 if ( s_maxupload == 0xFFFF )
1435 s_maxupload = UNLIMITED;
1436
1437 // Backwards compatibility
1438 if ( s_maxdownload == 0xFFFF )
1439 s_maxdownload = UNLIMITED;
1440
1441 if ( s_maxupload == UNLIMITED )
1442 return;
1443
1444 // Enforce the limits
1445 if ( s_maxupload < 4 ) {
1446 if ( ( s_maxupload * 3 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1447 s_maxdownload = s_maxupload * 3 ;
1448 } else if ( s_maxupload < 10 ) {
1449 if ( ( s_maxupload * 4 < s_maxdownload ) || ( s_maxdownload == 0 ) )
1450 s_maxdownload = s_maxupload * 4;
1451 }
1452}
1453
1454
1455void CPreferences::Save()
1456{
1457 wxString fullpath(s_configDir + wxT("preferences.dat")L"preferences.dat");
1458
1459 CFile preffile;
1460 if (!wxFileExists(fullpath)) {
1461 preffile.Create(fullpath);
1462 }
1463
1464 if (preffile.Open(fullpath, CFile::read_write)) {
1465 try {
1466 preffile.WriteUInt8(PREFFILE_VERSION);
1467 preffile.WriteHash(s_userhash);
1468 } catch (const CIOFailureException& e) {
1469 AddDebugLogLineC(logGeneral, wxT("IO failure while saving user-hash: ") + e.what())theLogger.AddLogLine(L"Preferences.cpp", 1469, true, logGeneral
, L"IO failure while saving user-hash: " + e.what())
;
1470 }
1471 }
1472
1473 SavePreferences();
1474
1475 #ifndef CLIENT_GUI
1476 CTextFile sdirfile;
1477 if (sdirfile.Open(s_configDir + wxT("shareddir.dat")L"shareddir.dat", CTextFile::write)) {
1478 for (size_t i = 0; i < shareddir_list.size(); ++i) {
1479 sdirfile.WriteLine(shareddir_list[i].GetRaw(), wxConvUTF8wxGet_wxConvUTF8());
1480 }
1481
1482 }
1483 #endif
1484}
1485
1486
1487CPreferences::~CPreferences()
1488{
1489 DeleteContents(m_CatList);
1490}
1491
1492
1493int32 CPreferences::GetRecommendedMaxConnections()
1494{
1495#ifndef CLIENT_GUI
1496 int iRealMax = PlatformSpecific::GetMaxConnections();
1497 if(iRealMax == -1 || iRealMax > 520) {
1498 return 500;
1499 }
1500 if(iRealMax < 20) {
1501 return iRealMax;
1502 }
1503 if(iRealMax <= 256) {
1504 return iRealMax - 10;
1505 }
1506 return iRealMax - 20;
1507#else
1508 return 500;
1509#endif
1510}
1511
1512
1513void CPreferences::SavePreferences()
1514{
1515 wxConfigBase* cfg = wxConfigBase::Get();
1516
1517 cfg->Write( wxT("/eMule/AppVersion")L"/eMule/AppVersion", wxT(VERSION)L"SVN" );
1518
1519 // Save the options
1520 SaveAllItems( cfg );
1521
1522 // Ensure that the changes are saved to disk.
1523 cfg->Flush();
1524}
1525
1526
1527void CPreferences::SaveCats()
1528{
1529 if ( GetCatCount() ) {
1530 wxConfigBase* cfg = wxConfigBase::Get();
1531
1532 // Save the main cat.
1533 cfg->Write( wxT("/eMule/AllcatType")L"/eMule/AllcatType", (int)s_allcatFilter);
1534
1535 // The first category is the default one and should not be counted
1536
1537 cfg->Write( wxT("/General/Count")L"/General/Count", (long)(m_CatList.size() - 1) );
1538
1539 uint32 maxcat = m_CatList.size();
1540 for (uint32 i = 1; i < maxcat; i++) {
1541 cfg->SetPath(CFormat(wxT("/Cat#%i")L"/Cat#%i") % i);
1542
1543 cfg->Write( wxT("Title")L"Title", m_CatList[i]->title );
1544 cfg->Write( wxT("Incoming")L"Incoming", CPath::ToUniv(m_CatList[i]->path) );
1545 cfg->Write( wxT("Comment")L"Comment", m_CatList[i]->comment );
1546 cfg->Write( wxT("Color")L"Color", wxString(CFormat(wxT("%u")L"%u") % m_CatList[i]->color));
1547 cfg->Write( wxT("Priority")L"Priority", (int)m_CatList[i]->prio );
1548 }
1549 // remove deleted cats from config
1550 while (cfg->DeleteGroup(CFormat(wxT("/Cat#%i")L"/Cat#%i") % maxcat++)) {}
1551
1552 cfg->Flush();
1553 }
1554}
1555
1556
1557void CPreferences::LoadPreferences()
1558{
1559 LoadCats();
1560}
1561
1562
1563void CPreferences::LoadCats()
1564{
1565 // default cat ... Meow! =(^.^)=
1566 Category_Struct* defaultcat = new Category_Struct;
1567 defaultcat->prio = 0;
1568 defaultcat->color = 0;
1569
1570 AddCat( defaultcat );
1571
1572 wxConfigBase* cfg = wxConfigBase::Get();
1573
1574 long max = cfg->Read( wxT("/General/Count")L"/General/Count", 0l );
1575
1576 for ( int i = 1; i <= max ; i++ ) {
1577 cfg->SetPath(CFormat(wxT("/Cat#%i")L"/Cat#%i") % i);
1578
1579 Category_Struct* newcat = new Category_Struct;
1580
1581 newcat->title = cfg->Read( wxT("Title")L"Title", wxEmptyString );
1582 newcat->path = CPath::FromUniv(cfg->Read(wxT("Incoming")L"Incoming", wxEmptyString));
1583
1584 // Some sanity checking
1585 if ( newcat->title.IsEmpty() || !newcat->path.IsOk() ) {
1586 AddLogLineN(_("Invalid category found, skipping"))theLogger.AddLogLine(L"Preferences.cpp", 1586, false, logStandard
, wxGetTranslation(("Invalid category found, skipping")))
;
1587
1588 delete newcat;
1589 continue;
1590 }
1591
1592 newcat->comment = cfg->Read( wxT("Comment")L"Comment", wxEmptyString );
1593 newcat->prio = cfg->Read( wxT("Priority")L"Priority", 0l );
1594 newcat->color = StrToULong(cfg->Read(wxT("Color")L"Color", wxT("0")L"0"));
1595
1596 AddCat(newcat);
1597
1598 if (!newcat->path.DirExists()) {
1599 CPath::MakeDir(newcat->path);
1600 }
1601 }
1602}
1603
1604
1605uint16 CPreferences::GetDefaultMaxConperFive()
1606{
1607 return MAXCONPER5SEC20;
1608}
1609
1610
1611uint32 CPreferences::AddCat(Category_Struct* cat)
1612{
1613 m_CatList.push_back( cat );
1614
1615 return m_CatList.size() - 1;
1616}
1617
1618
1619void CPreferences::RemoveCat(size_t index)
1620{
1621 if ( index < m_CatList.size() ) {
1622 CatList::iterator it = m_CatList.begin() + index;
1623
1624 delete *it;
1625
1626 m_CatList.erase( it );
1627
1628 // remove cat directory from shares
1629 theApp->sharedfiles->Reload();
1630 }
1631}
1632
1633
1634uint32 CPreferences::GetCatCount()
1635{
1636 return m_CatList.size();
1637}
1638
1639
1640Category_Struct* CPreferences::GetCategory(size_t index)
1641{
1642 wxASSERT( index < m_CatList.size() )do { if ( index < m_CatList.size() ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("Preferences.cpp", 1642, __FUNCTION__
, "index < m_CatList.size()", (const char*)__null), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
1643
1644 return m_CatList[index];
1645}
1646
1647
1648const CPath& CPreferences::GetCatPath(uint8 index)
1649{
1650 wxASSERT( index < m_CatList.size() )do { if ( index < m_CatList.size() ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("Preferences.cpp", 1650, __FUNCTION__
, "index < m_CatList.size()", (const char*)__null), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
1651
1652 return m_CatList[index]->path;
1653}
1654
1655
1656uint32 CPreferences::GetCatColor(size_t index)
1657{
1658 wxASSERT( index < m_CatList.size() )do { if ( index < m_CatList.size() ) { } else if ( wxTheAssertHandler
&& (wxOnAssert("Preferences.cpp", 1658, __FUNCTION__
, "index < m_CatList.size()", (const char*)__null), wxTrapInAssert
) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while
( (void)0, 0 )
;
1659
1660 return m_CatList[index]->color;
1661}
1662
1663bool CPreferences::CreateCategory(
1664 Category_Struct *& category,
1665 const wxString& name,
1666 const CPath& path,
1667 const wxString& comment,
1668 uint32 color,
1669 uint8 prio)
1670{
1671 category = new Category_Struct();
1672 category->path = thePrefs::GetIncomingDir(); // set a default in case path is invalid
1673 uint32 cat = AddCat(category);
1674 return UpdateCategory(cat, name, path, comment, color, prio);
1675}
1676
1677bool CPreferences::UpdateCategory(
1678 uint8 cat,
1679 const wxString& name,
1680 const CPath& path,
1681 const wxString& comment,
1682 uint32 color,
1683 uint8 prio)
1684{
1685 Category_Struct *category = m_CatList[cat];
1686
1687 // return true if path is ok, false if not
1688 bool ret = true;
1689 if (!path.IsOk() || (!path.DirExists() && !CPath::MakeDir(path))) {
1690 ret = false;
1691 // keep path as it was
1692 } else if (category->path != path) {
1693 // path changed: reload shared files, adding files in the new path and removing those from the old path
1694 category->path = path;
1695 theApp->sharedfiles->Reload();
1696 }
1697 category->title = name;
1698 category->comment = comment;
1699 category->color = color;
1700 category->prio = prio;
1701
1702 SaveCats();
1703 return ret;
1704}
1705
1706
1707wxString CPreferences::GetBrowser()
1708{
1709 wxString cmd(s_CustomBrowser);
1710#ifndef __WINDOWS__
1711 if( s_BrowserTab ) {
1712 // This is certainly not the best way to do it, but I'm lazy
1713 if ((wxT("mozilla")L"mozilla" == cmd.Right(7)) || (wxT("firefox")L"firefox" == cmd.Right(7))
1714 || (wxT("MozillaFirebird")L"MozillaFirebird" == cmd.Right(15))) {
1715 cmd += wxT(" -remote 'openURL(%s, new-tab)'")L" -remote 'openURL(%s, new-tab)'";
1716 }
1717 if ((wxT("galeon")L"galeon" == cmd.Right(6)) || (wxT("epiphany")L"epiphany" == cmd.Right(8))) {
1718 cmd += wxT(" -n '%s'")L" -n '%s'";
1719 }
1720 if (wxT("opera")L"opera" == cmd.Right(5)) {
1721 cmd += wxT(" --newpage '%s'")L" --newpage '%s'";
1722 }
1723 if (wxT("netscape")L"netscape" == cmd.Right(8)) {
1724 cmd += wxT(" -remote 'openURLs(%s,new-tab)'")L" -remote 'openURLs(%s,new-tab)'";
1725 }
1726 }
1727#endif /* !__WINDOWS__ */
1728 return cmd;
1729}
1730
1731void CPreferences::SetFilteringClients(bool val)
1732{
1733 if (val != s_IPFilterClients) {
1734 s_IPFilterClients = val;
1735 if (val) {
1736 theApp->clientlist->FilterQueues();
1737 }
1738 }
1739}
1740
1741void CPreferences::SetFilteringServers(bool val)
1742{
1743 if (val != s_IPFilterServers) {
1744 s_IPFilterServers = val;
1745 if (val) {
1746 theApp->serverlist->FilterServers();
1747 }
1748 }
1749}
1750
1751void CPreferences::SetIPFilterLevel(uint8 level)
1752{
1753 if (level != s_filterlevel) {
1754 // Set the new access-level
1755 s_filterlevel = level;
1756#ifndef CLIENT_GUI
1757 // and reload the filter
1758 NotifyAlways_IPFilter_Reload()MuleNotify::DoNotifyAlways(&MuleNotify::IPFilter_Reload);
1759#endif
1760 }
1761}
1762
1763void CPreferences::SetPort(uint16 val)
1764{
1765 // Warning: Check for +3, because server UDP is TCP+3
1766
1767 if (val +3 > 65535) {
1768 AddLogLineC(_("TCP port can't be higher than 65532 due to server UDP socket being TCP+3"))theLogger.AddLogLine(L"Preferences.cpp", 1768, true, logStandard
, wxGetTranslation(("TCP port can't be higher than 65532 due to server UDP socket being TCP+3"
)))
;
1769 AddLogLineN(CFormat(_("Default port will be used (%d)")) % DEFAULT_TCP_PORT)theLogger.AddLogLine(L"Preferences.cpp", 1769, false, logStandard
, CFormat(wxGetTranslation(("Default port will be used (%d)")
)) % 4662)
;
1770 s_port = DEFAULT_TCP_PORT4662;
1771 } else {
1772 s_port = val;
1773 }
1774}
1775
1776
1777void CPreferences::ReloadSharedFolders()
1778{
1779#ifndef CLIENT_GUI
1780 shareddir_list.clear();
1781
1782 CTextFile file;
1783 if (file.Open(s_configDir + wxT("shareddir.dat")L"shareddir.dat", CTextFile::read)) {
1784 wxArrayString lines = file.ReadLines(txtReadDefault, wxConvUTF8wxGet_wxConvUTF8());
1785
1786 for (size_t i = 0; i < lines.size(); ++i) {
1787 CPath path(lines[i]);
1788
1789 if (path.DirExists()) {
1790 shareddir_list.push_back(path);
1791 } else {
1792 AddLogLineN(CFormat(_("Dropping non-existing shared directory: %s")) % path.GetPrintable())theLogger.AddLogLine(L"Preferences.cpp", 1792, false, logStandard
, CFormat(wxGetTranslation(("Dropping non-existing shared directory: %s"
))) % path.GetPrintable())
;
1793 }
1794 }
1795 }
1796#endif
1797}
1798
1799
1800bool CPreferences::IsMessageFiltered(const wxString& message)
1801{
1802 if (s_FilterAllMessages) {
1803 return true;
1804 } else {
1805 if (s_FilterSomeMessages) {
1806 if (s_MessageFilterString.IsSameAs(wxT("*")L"*")){
1807 // Filter anything
1808 return true;
1809 } else {
1810 wxStringTokenizer tokenizer( s_MessageFilterString, wxT(",")L"," );
1811 while (tokenizer.HasMoreTokens()) {
1812 if ( message.Lower().Trim(false).Trim(true).Contains(
1813 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1814 return true;
1815 }
1816 }
1817 return false;
1818 }
1819 } else {
1820 return false;
1821 }
1822 }
1823}
1824
1825
1826bool CPreferences::IsCommentFiltered(const wxString& comment)
1827{
1828 if (s_FilterComments) {
1829 wxStringTokenizer tokenizer( s_CommentFilterString, wxT(",")L"," );
1830 while (tokenizer.HasMoreTokens()) {
1831 if ( comment.Lower().Trim(false).Trim(true).Contains(
1832 tokenizer.GetNextToken().Lower().Trim(false).Trim(true))) {
1833 return true;
1834 }
1835 }
1836 }
1837 return false;
1838}
1839
1840wxString CPreferences::GetLastHTTPDownloadURL(uint8 t)
1841{
1842 wxConfigBase* cfg = wxConfigBase::Get();
1843 wxString key = CFormat(wxT("/HTTPDownload/URL_%d")L"/HTTPDownload/URL_%d") % t;
1844 return cfg->Read(key, wxEmptyString);
1845}
1846
1847void CPreferences::SetLastHTTPDownloadURL(uint8 t, const wxString& val)
1848{
1849 wxConfigBase* cfg = wxConfigBase::Get();
1850 wxString key = CFormat(wxT("/HTTPDownload/URL_%d")L"/HTTPDownload/URL_%d") % t;
1851 cfg->Write(key, val);
1852}
1853
1854// File_checked_for_headers