1 /* Copyright (C) 2007, 2008 The SpringLobby Team. All rights reserved. */
2 //
3 // Class: Settings
4 //
5 
6 #include "settings.h"
7 
8 #include "springsettings/se_utils.h"
9 #include "helper/wxTranslationHelper.h"
10 #include "helper/slconfig.h"
11 #include "defines.h" //to get HAVEWX??
12 
13 #include <wx/filename.h>
14 #include <wx/filefn.h>
15 #include <wx/intl.h>
16 #include <wx/stdpaths.h>
17 #include <wx/filename.h>
18 #include <wx/colour.h>
19 #include <wx/cmndata.h>
20 #include <wx/font.h>
21 #include <wx/log.h>
22 #include <wx/wfstream.h>
23 #include <wx/settings.h>
24 #include <wx/tokenzr.h>
25 #ifdef HAVE_WX29
26 	#include <wx/colourdata.h>
27 #endif
28 #include <set>
29 #include <lslutils/misc.h>
30 #include <lslutils/globalsmanager.h>
31 #include <lslunitsync/c_api.h>
32 #include <lslunitsync/unitsync.h>
33 
34 #include "nonportable.h"
35 #include "utils/conversion.h"
36 #include "utils/debug.h"
37 #include "utils/platform.h"
38 #include "uiutils.h"
39 #include "playback/playbackfiltervalues.h"
40 #include "customlistctrl.h"
41 #include "springsettings/presets.h"
42 #include "helper/sortutil.h"
43 #include "mainwindow.h"
44 #ifdef SL_DUMMY_COL
45     #include "utils/customdialogs.h"
46 #endif
47 #include "utils/pathlistfactory.h"
48 
49 #ifdef __WXMSW__
50 	#define BIN_EXT _T(".exe")
51 #else
52 	#define BIN_EXT wxEmptyString
53 #endif
54 
55 const wxChar sep = wxFileName::GetPathSeparator();
56 const wxString sepstring = wxString(sep);
57 
58 SLCONFIG("/General/SettingsVersion", SETTINGS_VERSION, "version of settings file");
59 SLCONFIG("/General/CacheVersion", CACHE_VERSION, "version of used cache");
60 SLCONFIG("/General/firstrun", true, "true if app is run first time");
61 
62 
63 
sett()64 Settings& sett()
65 {
66     static LSL::Util::LineInfo<Settings> m( AT );
67     static LSL::Util::GlobalObjectHolder<Settings, LSL::Util::LineInfo<Settings> > m_sett( m );
68 	return m_sett;
69 }
70 
Settings()71 Settings::Settings()
72 {
73 	m_config = &cfg();
74 }
75 
~Settings()76 Settings::~Settings()
77 {
78 }
79 
80 
Setup(wxTranslationHelper * translationhelper)81 void Settings::Setup(wxTranslationHelper* translationhelper)
82 {
83 	SetSettingsStandAlone( false );
84 
85 	long settversion = cfg().ReadLong(_T("/General/SettingsVersion"));
86 	long cacheversion = cfg().ReadLong(_T( "/General/CacheVersion" ));
87 
88 	const wxString userConfigDir = GetConfigfileDir();
89 	if ( IsFirstRun() && !wxDirExists( userConfigDir ) ) {
90 		wxMkdir( userConfigDir );
91 	}
92 	if ( (cacheversion < CACHE_VERSION) && !IsFirstRun() ) {
93 		if ( wxDirExists( GetCachePath() )  ) {
94 			wxLogWarning( _T("erasing old cache ver %d (app cache ver %d)"), cacheversion, CACHE_VERSION );
95 			wxString file = wxFindFirstFile( GetCachePath() + wxFILE_SEP_PATH + _T("*") );
96 			while ( !file.empty() ) {
97 				wxRemoveFile( file );
98 				file = wxFindNextFile();
99 			}
100 		}
101 		// after resetting cache, set current cache version
102 		cfg().Write( _T( "/General/CacheVersion" ), CACHE_VERSION );
103 	}
104 
105 	if ( !cfg().ReadBool(_T("/General/firstrun") )) {
106 		ConvertSettings(translationhelper, settversion);
107 	}
108 
109 	if ( ShouldAddDefaultServerSettings() || ( settversion < 14 && GetServers().Count() < 2  ) )
110 		SetDefaultServerSettings();
111 
112 	if ( ShouldAddDefaultChannelSettings() ) {
113 		AddChannelJoin( _T("main"), wxEmptyString );
114 		AddChannelJoin( _T("newbies"), wxEmptyString );
115 		if ( translationhelper ) {
116 			if ( translationhelper->GetLocale() ) {
117 				wxString localecode = translationhelper->GetLocale()->GetCanonicalName();
118 				if ( localecode.Find(_T("_")) != -1 ) localecode = localecode.BeforeFirst(_T('_'));
119 				AddChannelJoin( localecode, wxEmptyString ); // add locale's language code to autojoin
120 			}
121 		}
122 	}
123 }
124 
ConvertSettings(wxTranslationHelper * translationhelper,long settversion)125 void Settings::ConvertSettings(wxTranslationHelper* translationhelper, long settversion)
126 {
127 	if( settversion < 19 ) {
128 		//the dummy column hack was removed on win
129 		m_config->DeleteGroup(_T("/GUI/ColumnWidths/"));
130 	}
131 	if ( settversion < 22 ) {
132 		if ( translationhelper ) {
133 			// add locale's language code to autojoin
134 			if ( translationhelper->GetLocale() ) {
135 				wxString localecode = translationhelper->GetLocale()->GetCanonicalName();
136 				if ( localecode.Find(_T("_")) != -1 ) localecode = localecode.BeforeFirst(_T('_'));
137 				if ( localecode == _T("en") ) // we'll skip en for now, maybe in the future we'll reactivate it
138 					AddChannelJoin( localecode, wxEmptyString );
139 			}
140 		}
141 	}
142 	if ( settversion < 23 ) {
143 		ConvertLists();
144 	}
145 	if ( settversion < 24 ) {
146 		DeleteServer( _T("Backup server") );
147 		DeleteServer( _T("Backup server 1") );
148 		DeleteServer( _T("Backup server 2") );
149 		SetDefaultServerSettings();
150 	}
151 	if ( settversion < 25 ) {
152 		SetDisableSpringVersionCheck(false);
153 	}
154 	if ( settversion < 26 ) { // language id before was stored by index, now its stored by the id
155 		cfg().Write(_T("/General/LanguageID"), 0);
156 	}
157 	// after updating, set current version
158 	m_config->Write(_T("/General/SettingsVersion"), SETTINGS_VERSION);
159 }
160 
FinalConfigPath() const161 wxString Settings::FinalConfigPath() const
162 {
163 	return m_config->GetFilePath();
164 }
165 
166 //! @brief Saves the settings to file
SaveSettings()167 void Settings::SaveSettings()
168 {
169 	m_config->Write( _T( "/General/firstrun" ), false );
170 	m_config->SaveFile();
171 }
172 
IsFirstRun()173 bool Settings::IsFirstRun()
174 {
175 	return m_config->ReadBool( _T( "/General/firstrun" ) );
176 }
177 
178 
GetLobbyWriteDir()179 wxString Settings::GetLobbyWriteDir()
180 {
181 	//FIXME: make configureable
182 	return GetConfigfileDir();
183 }
184 
185 
UseOldSpringLaunchMethod()186 bool Settings::UseOldSpringLaunchMethod()
187 {
188 	return m_config->Read( _T( "/Spring/UseOldLaunchMethod" ), 0l );
189 }
190 
GetNoUDP()191 bool Settings::GetNoUDP()
192 {
193 	return m_config->Read( _T( "/General/NoUDP" ), 0l );
194 }
195 
SetNoUDP(bool value)196 void Settings::SetNoUDP( bool value )
197 {
198 	m_config->Write( _T( "/General/NoUDP" ), value );
199 }
200 
GetClientPort()201 int Settings::GetClientPort()
202 {
203 	return m_config->Read( _T( "/General/ClientPort" ), 0l );
204 }
205 
SetClientPort(int value)206 void Settings::SetClientPort( int value )
207 {
208 	m_config->Write( _T( "/General/ClientPort" ), value );
209 }
210 
GetShowIPAddresses()211 bool Settings::GetShowIPAddresses()
212 {
213 	return m_config->Read( _T( "/General/ShowIP" ), 0l );
214 }
215 
SetShowIPAddresses(bool value)216 void Settings::SetShowIPAddresses( bool value )
217 {
218 	m_config->Write( _T( "/General/ShowIP" ), value );
219 }
220 
SetOldSpringLaunchMethod(bool value)221 void Settings::SetOldSpringLaunchMethod( bool value )
222 {
223 	m_config->Write( _T( "/Spring/UseOldLaunchMethod" ), value );
224 }
225 
226 
GetHTTPMaxParallelDownloads()227 int Settings::GetHTTPMaxParallelDownloads()
228 {
229 	return m_config->Read(_T("/General/ParallelHTTPCount"),3);
230 }
SetHTTPMaxParallelDownloads(int value)231 void Settings::SetHTTPMaxParallelDownloads(int value)
232 {
233 	m_config->Write(_T("/General/ParallelHTTPCount"),value);
234 }
235 
236 
237 
GetWebBrowserUseDefault()238 bool Settings::GetWebBrowserUseDefault()
239 {
240 	// See note on ambiguities, in wx/confbase.h near line 180.
241 	bool useDefault;
242 	m_config->Read( _T( "/General/WebBrowserUseDefault" ), &useDefault, DEFSETT_WEB_BROWSER_USE_DEFAULT );
243 	return useDefault;
244 }
245 
SetWebBrowserUseDefault(bool useDefault)246 void Settings::SetWebBrowserUseDefault( bool useDefault )
247 {
248 	m_config->Write( _T( "/General/WebBrowserUseDefault" ), useDefault );
249 }
250 
GetWebBrowserPath()251 wxString Settings::GetWebBrowserPath()
252 {
253 	return m_config->Read( _T( "/General/WebBrowserPath" ), wxEmptyString );
254 }
255 
256 
SetWebBrowserPath(const wxString & path)257 void Settings::SetWebBrowserPath( const wxString& path )
258 {
259 	m_config->Write( _T( "/General/WebBrowserPath" ), path );
260 }
261 
262 
GetCachePath()263 wxString Settings::GetCachePath()
264 {
265 	wxString path = GetLobbyWriteDir() + sepstring + _T( "cache" ) + sep;
266 	if ( !wxFileName::DirExists( path ) ) {
267 		if ( !wxFileName::Mkdir(  path, 0755  ) ) return wxEmptyString;
268 	}
269 	return path;
270 }
271 
ShouldAddDefaultServerSettings()272 bool Settings::ShouldAddDefaultServerSettings()
273 {
274 	return !m_config->Exists( _T( "/Server" ) );
275 }
276 
277 //! @brief Restores default settings
SetDefaultServerSettings()278 void Settings::SetDefaultServerSettings()
279 {
280 	SetServer(  DEFSETT_DEFAULT_SERVER_NAME,  DEFSETT_DEFAULT_SERVER_HOST, DEFSETT_DEFAULT_SERVER_PORT );
281 	SetServer( _T( "Backup server 1" ), _T( "lobby1.springlobby.info" ), 8200 );
282 	SetServer( _T( "Backup server 2" ), _T( "lobby2.springlobby.info" ), 8200 );
283 	SetServer( _T( "Test server" ), _T( "lobby.springrts.com" ), 7000 );
284 	SetDefaultServer( DEFSETT_DEFAULT_SERVER_NAME );
285 }
286 
287 //! @brief Checks if the server name/alias exists in the settings
ServerExists(const wxString & server_name)288 bool Settings::ServerExists( const wxString& server_name )
289 {
290 	return m_config->Exists( _T( "/Server/Servers/" ) + server_name );
291 }
292 
293 
294 //! @brief Get the name/alias of the default server.
295 //!
296 //! @note Normally this will be the previously selected server. But at first run it will be a server that is set as the default.
GetDefaultServer()297 wxString Settings::GetDefaultServer()
298 {
299     wxString serv = DEFSETT_DEFAULT_SERVER_NAME;
300     return m_config->Read( _T("/Server/Default"), serv );
301 }
302 
303 
304 //! @brief Set the name/alias of the default server.
305 //!
306 //! @param server_name the server name/alias
307 //! @see GetDefaultServer()
SetDefaultServer(const wxString & server_name)308 void   Settings::SetDefaultServer( const wxString& server_name )
309 {
310 	m_config->Write( _T( "/Server/Default" ),  server_name );
311 }
312 
313 
314 //! @brief Get hostname of a server.
315 //!
316 //! @param server_name the server name/alias
GetServerHost(const wxString & server_name)317 wxString Settings::GetServerHost( const wxString& server_name )
318 {
319     wxString host = DEFSETT_DEFAULT_SERVER_HOST;
320     return m_config->Read( _T("/Server/Servers/")+ server_name +_T("/Host"), host );
321 }
322 
323 
324 //! @brief Set hostname of a server.
325 //!
326 //! @param server_name the server name/alias
327 //! @param the host url address
328 //! @param the port where the service is run
SetServer(const wxString & server_name,const wxString & url,int port)329 void   Settings::SetServer( const wxString& server_name, const wxString& url, int port )
330 {
331 	m_config->Write( _T( "/Server/Servers/" ) + server_name + _T( "/Host" ), url );
332 	m_config->Write( _T( "/Server/Servers/" ) + server_name + _T( "/Port" ), port );
333 }
334 
335 //! @brief Deletes a server from the list.
336 //!
337 //! @param server_name the server name/alias
DeleteServer(const wxString & server_name)338 void Settings::DeleteServer( const wxString& server_name )
339 {
340 	m_config->DeleteGroup( _T( "/Server/Servers/" ) + server_name );
341 }
342 
343 
344 //! @brief Get port number of a server.
345 //!
346 //! @param server_name the server name/alias
GetServerPort(const wxString & server_name)347 int    Settings::GetServerPort( const wxString& server_name )
348 {
349 	return m_config->Read( _T( "/Server/Servers/" ) + server_name + _T( "/Port" ), DEFSETT_DEFAULT_SERVER_PORT );
350 }
351 
352 //! @brief Get list of server aliases
GetServers()353 wxArrayString Settings::GetServers()
354 {
355 	return cfg().GetGroupList( _T( "/Server/Servers/" ) );
356 }
357 
358 
359 //! @brief Get nickname of the default account for a server.
360 //!
361 //! @param server_name the server name/alias
GetServerAccountNick(const wxString & server_name)362 wxString Settings::GetServerAccountNick( const wxString& server_name )
363 {
364 	return m_config->Read( _T( "/Server/Servers/" ) + server_name + _T( "/Nick" ), wxEmptyString ) ;
365 }
366 
367 
368 //! @brief Set nickname of the default account for a server.
369 //!
370 //! @param server_name the server name/alias
371 //! @param value the vaule to be set
SetServerAccountNick(const wxString & server_name,const wxString & value)372 void Settings::SetServerAccountNick( const wxString& server_name, const wxString& value )
373 {
374 	m_config->Write( _T( "/Server/Servers/" ) + server_name + _T( "/Nick" ), value );
375 }
376 
377 
378 //! @brief Get password of the default account for a server.
379 //!
380 //! @param server_name the server name/alias
381 //! @todo Implement
GetServerAccountPass(const wxString & server_name)382 wxString Settings::GetServerAccountPass( const wxString& server_name )
383 {
384 	return m_config->Read( _T( "/Server/Servers/" ) + server_name + _T( "/Pass" ), wxEmptyString );
385 }
386 
387 
388 //! @brief Set password of the default account for a server.
389 //!
390 //! @param server_name the server name/alias
391 //! @param value the vaule to be set
392 //! @todo Implement
SetServerAccountPass(const wxString & server_name,const wxString & value)393 void   Settings::SetServerAccountPass( const wxString& server_name, const wxString& value )
394 {
395 	m_config->Write( _T( "/Server/Servers/" ) + server_name + _T( "/Pass" ), value );
396 }
397 
398 
399 //! @brief Get if the password should be saved for a default server account.
400 //!
401 //! @param server_name the server name/alias
402 //! @todo Implement
GetServerAccountSavePass(const wxString & server_name)403 bool   Settings::GetServerAccountSavePass( const wxString& server_name )
404 {
405 	return m_config->Read( _T( "/Server/Servers/" ) + server_name + _T( "/savepass" ), ( long int )false );
406 }
407 
408 
409 //! @brief Set if the password should be saved for a default server account.
410 //!
411 //! @param server_name the server name/alias
412 //! @param value the vaule to be set
413 //! @todo Implement
SetServerAccountSavePass(const wxString & server_name,const bool value)414 void Settings::SetServerAccountSavePass( const wxString& server_name, const bool value )
415 {
416 	m_config->Write( _T( "/Server/Servers/" ) + server_name + _T( "/savepass" ), ( long int )value );
417 }
418 
419 
GetNumChannelsJoin()420 int Settings::GetNumChannelsJoin()
421 {
422 	return cfg().GetGroupCount( _T( "/Channels/AutoJoin" ) );
423 }
424 
AddChannelJoin(const wxString & channel,const wxString & key)425 void Settings::AddChannelJoin( const wxString& channel , const wxString& key )
426 {
427 	int index = GetNumChannelsJoin();
428 
429 	m_config->Write( wxFormat( _T( "/Channels/AutoJoin/Channel%d/Name" ) ) % index, channel );
430 	m_config->Write( wxFormat( _T( "/Channels/AutoJoin/Channel%d/Password" ) ) % index, key );
431 }
432 
433 
RemoveChannelJoin(const wxString & channel)434 void Settings::RemoveChannelJoin( const wxString& channel )
435 {
436 	int index = GetChannelJoinIndex( channel );
437 	if ( index == -1 ) return;
438 	int total = GetNumChannelsJoin();
439 	m_config->DeleteGroup( _T( "/Channels/AutoJoin/Channel" ) + TowxString( index ) );
440 	m_config->RenameGroup( _T( "/Channels/AutoJoin/Channel" ) + TowxString( total - 1 ), _T( "/Channels/AutoJoin/Channel" ) + TowxString( index ) );
441 }
442 
RemoveAllChannelsJoin()443 void Settings::RemoveAllChannelsJoin()
444 {
445 	m_config->DeleteGroup( _T( "/Channels/AutoJoin" ) );
446 }
447 
448 
GetChannelJoinIndex(const wxString & name)449 int Settings::GetChannelJoinIndex( const wxString& name )
450 {
451 	int numchannels = GetNumChannelsJoin();
452 	int ret = -1;
453 	for ( int i = 0; i < numchannels; i++ )
454 	{
455 		if ( m_config->Read( wxFormat( _T( "/Channels/AutoJoin/Channel%d/Name" ) ) % i, wxEmptyString ) == name ) ret = i;
456 	}
457 	return ret;
458 }
459 
GetChannelsJoin()460 std::vector<ChannelJoinInfo> Settings::GetChannelsJoin()
461 {
462 	std::vector<ChannelJoinInfo> ret;
463 //	int num = GetNumChannelsJoin();
464 	wxArrayString channels = cfg().GetGroupList( _T("/Channels/AutoJoin/") );
465 	slConfig::PathGuard pathguard( m_config, _T("/Channels/AutoJoin/") );
466 	for ( size_t i = 0; i < channels.Count(); ++i )
467 	{
468 		if( !channels[i].StartsWith( _T("Channel") ) )
469 			continue;
470 		ChannelJoinInfo info;
471 		info.name = m_config->Read( channels[i] + _T("/Name" ) );
472 		info.password = m_config->Read( channels[i] + _T("/Password" ) );
473 		ret.push_back( info );
474 	}
475 	return ret;
476 }
477 
ShouldAddDefaultChannelSettings()478 bool Settings::ShouldAddDefaultChannelSettings()
479 {
480 	return !m_config->Exists( _T( "/Channels" ) );
481 }
482 
483 
484 
485 // ========================================================
486 
AutoFindSpringBin()487 wxString Settings::AutoFindSpringBin()
488 {
489 	wxPathList pl;
490 
491 	pl.AddEnvList( _T( "%ProgramFiles%" ) );
492 	pl.AddEnvList( _T( "PATH" ) );
493 
494     pl = PathlistFactory::AdditionalSearchPaths( pl );
495 
496 	return pl.FindValidPath( SPRING_BIN );
497 }
498 
AutoFindUnitSync(wxPathList pl) const499 wxString Settings::AutoFindUnitSync(wxPathList pl) const
500 {
501 	wxString retpath = pl.FindValidPath( _T( "unitsync" ) + GetLibExtension() );
502 	if ( retpath.IsEmpty() )
503 		retpath = pl.FindValidPath( _T( "libunitsync" ) + GetLibExtension() );
504 	return retpath;
505 }
506 
GetSpringVersionList() const507 std::map<wxString, LSL::SpringBundle> Settings::GetSpringVersionList() const
508 {
509 	return m_spring_versions;
510 }
511 
LocateSystemInstalledSpring(LSL::SpringBundle & bundle)512 bool LocateSystemInstalledSpring(LSL::SpringBundle& bundle)
513 {
514 	wxPathList paths = PathlistFactory::ConfigFileSearchPaths();
515 	for (const auto path: paths) {
516 		if (bundle.AutoComplete(STD_STRING(path))) {
517 			return true;
518 		}
519 	}
520 	return false;
521 }
522 
523 
RefreshSpringVersionList(bool autosearch,const LSL::SpringBundle * additionalbundle)524 void Settings::RefreshSpringVersionList(bool autosearch, const LSL::SpringBundle* additionalbundle)
525 {
526 /*
527 FIXME: move to LSL's GetSpringVersionList() which does:
528 
529 	1. search system installed spring + unitsync (both paths independant)
530 	2. search for user installed spring + unitsync (assume bundled)
531 	3. search / validate paths from config
532 	4. search path / unitsync given from user input
533 
534 needs to change to sth like: GetSpringVersionList(std::list<LSL::Bundle>)
535 
536 */
537 	wxLogDebugFunc( wxEmptyString );
538 	std::list<LSL::SpringBundle> usync_paths;
539 
540 	if (additionalbundle != NULL) {
541 		usync_paths.push_back(*additionalbundle);
542 	}
543 	if (autosearch) {
544 		LSL::SpringBundle systembundle;
545 		if (LocateSystemInstalledSpring(systembundle)) {
546 			usync_paths.push_back(systembundle);
547 		}
548 
549 		wxPathList ret;
550 		wxPathList paths = PathlistFactory::AdditionalSearchPaths(ret);
551 		const wxString springbin(SPRING_BIN);
552 		for (const auto path: paths) {
553 			LSL::SpringBundle bundle;
554 			bundle.path = STD_STRING(path);
555 			usync_paths.push_back(bundle);
556 		}
557 	}
558 
559 	wxArrayString list = cfg().GetGroupList( _T( "/Spring/Paths" ) );
560 	const int count = list.GetCount();
561 	for ( int i = 0; i < count; i++ ) {
562 		LSL::SpringBundle bundle;
563 		bundle.unitsync = STD_STRING(GetUnitSync(list[i]));
564 		bundle.spring = STD_STRING(GetSpringBinary(list[i]));
565 		bundle.version = STD_STRING(list[i]);
566 		usync_paths.push_back(bundle);
567 	}
568 
569 	cfg().DeleteGroup(_T("/Spring/Paths"));
570 
571 	m_spring_versions.clear();
572 	try {
573 		const auto versions = LSL::susynclib().GetSpringVersionList( usync_paths );
574 		for(const auto pair : versions) {
575 			const LSL::SpringBundle& bundle = pair.second;
576 			const wxString version = TowxString(bundle.version);
577 			m_spring_versions[version] = bundle;
578 			SetSpringBinary(version, TowxString(bundle.spring));
579 			SetUnitSync(version, TowxString(bundle.unitsync));
580 			SetBundle(version, TowxString(bundle.path));
581 		}
582 	} catch (const std::runtime_error& e) {
583 		wxLogError(wxString::Format(_T("Couldn't get list of spring versions: %s"), e.what()));
584 	} catch ( ...) {
585 		wxLogError(_T("Unknown Execption caught in Settings::RefreshSpringVersionList"));
586 	}
587 }
588 
GetCurrentUsedSpringIndex()589 wxString Settings::GetCurrentUsedSpringIndex()
590 {
591     return m_config->Read( _T( "/Spring/CurrentIndex" ), _T( "default" ) );
592 }
593 
SetUsedSpringIndex(const wxString & index)594 void Settings::SetUsedSpringIndex( const wxString& index )
595 {
596     m_config->Write( _T( "/Spring/CurrentIndex" ), TowxString(index) );
597 }
598 
599 
DeleteSpringVersionbyIndex(const wxString & index)600 void Settings::DeleteSpringVersionbyIndex( const wxString& index )
601 {
602 	m_config->DeleteGroup( _T( "/Spring/Paths/" ) + index );
603 	if ( GetCurrentUsedSpringIndex() == index ) SetUsedSpringIndex( wxEmptyString );
604 }
605 
GetCurrentUsedDataDir()606 wxString Settings::GetCurrentUsedDataDir()
607 {
608 	wxString dir;
609 	if ( LSL::susynclib().IsLoaded() )
610 	{
611         if ( LSL::susynclib().VersionSupports( LSL::USYNC_GetDataDir ) )
612             dir = TowxString(LSL::susynclib().GetSpringDataDir());
613         else
614             dir = TowxString(LSL::susynclib().GetSpringConfigString("SpringData", ""));
615 	}
616 #ifdef __WXMSW__
617 	if ( dir.IsEmpty() )
618         dir = GetExecutableFolder(); // fallback
619 #else
620 	if ( dir.IsEmpty() )
621         dir = wxFileName::GetHomeDir() + sepstring + _T( ".spring" ); // fallback
622 #endif
623 	wxString stripped;
624 	if ( dir.EndsWith(sepstring,&stripped) ) return stripped;
625 	return dir;
626 }
627 
628 
GetCurrentUsedSpringBinary()629 wxString Settings::GetCurrentUsedSpringBinary()
630 {
631 	return GetSpringBinary( GetCurrentUsedSpringIndex() );
632 }
633 
GetCurrentUsedUnitSync()634 wxString Settings::GetCurrentUsedUnitSync()
635 {
636 	return GetUnitSync( GetCurrentUsedSpringIndex() );
637 }
638 
GetCurrentUsedSpringConfigFilePath()639 wxString Settings::GetCurrentUsedSpringConfigFilePath()
640 {
641 	wxString path;
642 	try {
643 		path = TowxString(LSL::susynclib().GetConfigFilePath());
644 	} catch ( std::runtime_error& e) {
645 		wxLogError( wxString::Format( _T("Couldn't get SpringConfigFilePath, exception caught:\n %s"), e.what()  ) );
646 	}
647 	return path;
648 }
649 
GetUnitSync(const wxString & index)650 wxString Settings::GetUnitSync( const wxString& index )
651 {
652 	return m_config->Read( _T( "/Spring/Paths/" ) + index + _T( "/UnitSyncPath" ), AutoFindUnitSync() );
653 }
654 
655 
GetSpringBinary(const wxString & index)656 wxString Settings::GetSpringBinary( const wxString& index )
657 {
658 	return m_config->Read( _T( "/Spring/Paths/" ) + index + _T( "/SpringBinPath" ), AutoFindSpringBin() );
659 }
660 
SetUnitSync(const wxString & index,const wxString & path)661 void Settings::SetUnitSync( const wxString& index, const wxString& path )
662 {
663 	m_config->Write( _T( "/Spring/Paths/" ) + index + _T( "/UnitSyncPath" ), path );
664 }
665 
SetSpringBinary(const wxString & index,const wxString & path)666 void Settings::SetSpringBinary( const wxString& index, const wxString& path )
667 {
668 	m_config->Write( _T( "/Spring/Paths/" ) + index + _T( "/SpringBinPath" ), path );
669 }
670 
SetBundle(const wxString & index,const wxString & path)671 void Settings::SetBundle( const wxString& index, const wxString& path )
672 {
673 	m_config->Write( _T( "/Spring/Paths/" ) + index + _T( "/SpringBundlePath" ), path );
674 }
675 
676 // ===================================================
677 
GetChatLogEnable()678 bool Settings::GetChatLogEnable()
679 {
680 	if ( !m_config->Exists( _T( "/ChatLog/chatlog_enable" ) ) ) SetChatLogEnable( true );
681 	return m_config->Read( _T( "/ChatLog/chatlog_enable" ), true );
682 }
683 
684 
SetChatLogEnable(const bool value)685 void Settings::SetChatLogEnable( const bool value )
686 {
687 	m_config->Write( _T( "/ChatLog/chatlog_enable" ), value );
688 }
689 
690 
GetChatLogLoc()691 wxString Settings::GetChatLogLoc()
692 {
693 	wxString path = GetLobbyWriteDir() +  sepstring + _T( "chatlog" );
694 	if ( !wxFileName::DirExists( path ) )
695 	{
696 		if ( !wxFileName::Mkdir(  path, 0755  ) ) return wxEmptyString;
697 	}
698 	return path;
699 }
700 
701 
GetLastHostDescription()702 wxString Settings::GetLastHostDescription()
703 {
704 	return m_config->Read( _T( "/Hosting/LastDescription" ), wxEmptyString );
705 }
706 
707 
GetLastHostMod()708 wxString Settings::GetLastHostMod()
709 {
710 	return m_config->Read( _T( "/Hosting/LastMod" ), wxEmptyString );
711 }
712 
713 
GetLastHostPassword()714 wxString Settings::GetLastHostPassword()
715 {
716 	return m_config->Read( _T( "/Hosting/LastPassword" ), wxEmptyString );
717 }
718 
719 
GetLastHostPort()720 int Settings::GetLastHostPort()
721 {
722 	return m_config->Read( _T( "/Hosting/LastPort" ), DEFSETT_SPRING_PORT );
723 }
724 
725 
GetLastHostPlayerNum()726 int Settings::GetLastHostPlayerNum()
727 {
728 	return m_config->Read( _T( "/Hosting/LastPlayerNum" ), 4 );
729 }
730 
731 
GetLastHostNATSetting()732 int Settings::GetLastHostNATSetting()
733 {
734 	return m_config->Read( _T( "/Hosting/LastNATSetting" ), ( long )0 );
735 }
736 
737 
GetLastHostMap()738 wxString Settings::GetLastHostMap()
739 {
740 	return m_config->Read( _T( "/Hosting/LastMap" ), wxEmptyString );
741 }
742 
GetLastRankLimit()743 int Settings::GetLastRankLimit()
744 {
745 	return m_config->Read( _T( "/Hosting/LastRank" ), 0l );
746 }
747 
GetTestHostPort()748 bool Settings::GetTestHostPort()
749 {
750 	return m_config->Read( _T( "/Hosting/TestHostPort" ), 0l );
751 }
752 
GetLastAutolockStatus()753 bool Settings::GetLastAutolockStatus()
754 {
755 	return m_config->Read( _T( "/Hosting/LastAutoLock" ), true );
756 }
757 
GetLastHostRelayedMode()758 bool Settings::GetLastHostRelayedMode()
759 {
760 	return m_config->Read( _T( "/Hosting/LastRelayedMode" ), 0l );
761 }
762 
GetBattleLastColour()763 wxColour Settings::GetBattleLastColour()
764 {
765 	return  wxColour( m_config->Read( _T( "/Hosting/MyLastColour" ), _T( "#FFFF00" ) ) );
766 }
767 
768 
SetBattleLastColour(const wxColour & col)769 void Settings::SetBattleLastColour( const wxColour& col )
770 {
771 	m_config->Write( _T( "/Hosting/MyLastColour" ), col.GetAsString( wxC2S_HTML_SYNTAX ) );
772 }
773 
SetLastHostDescription(const wxString & value)774 void Settings::SetLastHostDescription( const wxString& value )
775 {
776 	m_config->Write( _T( "/Hosting/LastDescription" ), value );
777 }
778 
779 
SetLastHostMod(const wxString & value)780 void Settings::SetLastHostMod( const wxString& value )
781 {
782 	m_config->Write( _T( "/Hosting/LastMod" ), value );
783 }
784 
785 
SetLastHostPassword(const wxString & value)786 void Settings::SetLastHostPassword( const wxString& value )
787 {
788 	m_config->Write( _T( "/Hosting/LastPassword" ), value );
789 }
790 
791 
SetLastHostPort(int value)792 void Settings::SetLastHostPort( int value )
793 {
794 	m_config->Write( _T( "/Hosting/LastPort" ), value );
795 }
796 
797 
SetLastHostPlayerNum(int value)798 void Settings::SetLastHostPlayerNum( int value )
799 {
800 	m_config->Write( _T( "/Hosting/LastPlayerNum" ), value );
801 }
802 
803 
SetLastHostNATSetting(int value)804 void Settings::SetLastHostNATSetting( int value )
805 {
806 	m_config->Write( _T( "/Hosting/LastNATSetting" ), value );
807 }
808 
809 
SetLastHostMap(const wxString & value)810 void Settings::SetLastHostMap( const wxString& value )
811 {
812 	m_config->Write( _T( "/Hosting/LastMap" ), value );
813 }
814 
SetLastRankLimit(int rank)815 void Settings::SetLastRankLimit( int rank )
816 {
817 	m_config->Write( _T( "/Hosting/LastRank" ), rank );
818 }
819 
SetLastAI(const wxString & ai)820 void Settings::SetLastAI( const wxString& ai )
821 {
822 	m_config->Write( _T( "/SinglePlayer/LastAI" ), ai );
823 }
824 
SetLastBattleId(int battleId)825 void Settings::SetLastBattleId(int battleId)
826 {
827 	m_config->Write( _T( "/Hosting/MyLastBattleId" ), battleId);
828 }
829 
SetLastScriptPassword(const wxString & scriptPassword)830 void Settings::SetLastScriptPassword( const wxString& scriptPassword )
831 {
832 	m_config->Write( _T( "/Hosting/MyLastScriptPassword" ), scriptPassword );
833 }
834 
SetTestHostPort(bool value)835 void Settings::SetTestHostPort( bool value )
836 {
837 	m_config->Write( _T( "/Hosting/TestHostPort" ), value );
838 }
839 
SetLastAutolockStatus(bool value)840 void Settings::SetLastAutolockStatus( bool value )
841 {
842 	m_config->Write( _T( "/Hosting/LastAutoLock" ), value );
843 }
844 
SetLastHostRelayedMode(bool value)845 void Settings::SetLastHostRelayedMode( bool value )
846 {
847 	m_config->Write( _T( "/Hosting/LastRelayedMode" ), value );
848 }
849 
SetHostingPreset(const wxString & name,int optiontype,std::map<wxString,wxString> options)850 void Settings::SetHostingPreset( const wxString& name, int optiontype, std::map<wxString, wxString> options )
851 {
852 	m_config->DeleteGroup( _T( "/Hosting/Preset/" ) + name + _T( "/" ) + TowxString( optiontype ) );
853 	for ( std::map<wxString, wxString>::const_iterator it = options.begin(); it != options.end(); ++it )
854 	{
855 		m_config->Write( _T( "/Hosting/Preset/" ) + name + _T( "/" ) + TowxString( optiontype ) + _T( "/" ) + it->first , it->second );
856 	}
857 }
858 
GetHostingPreset(const wxString & name,int optiontype)859 std::map<wxString, wxString> Settings::GetHostingPreset( const wxString& name, int optiontype )
860 {
861 	wxString path_base = _T( "/Hosting/Preset/" ) + name + _T( "/" ) + TowxString( optiontype );
862 	std::map<wxString, wxString> ret;
863 	wxArrayString list = cfg().GetEntryList( path_base );
864 
865 	slConfig::PathGuard pathGuard ( m_config, path_base );
866 
867 	int count = list.GetCount();
868 	for ( int i = 0; i < count; i ++ )
869 	{
870 		wxString keyname = list[i];
871 		wxString val = m_config->Read( keyname );
872 		ret[keyname] = val;
873 	}
874 	return ret;
875 }
876 
877 
GetPresetList()878 wxArrayString Settings::GetPresetList()
879 {
880 	return cfg().GetGroupList( _T( "/Hosting/Preset" ) );
881 }
882 
883 
DeletePreset(const wxString & name)884 void Settings::DeletePreset( const wxString& name )
885 {
886 	m_config->DeleteGroup( _T( "/Hosting/Preset/" ) + name );
887 
888 	//delete mod default preset associated
889 	wxArrayString list = cfg().GetEntryList( _T( "/Hosting/ModDefaultPreset" ) );
890 	int count = list.GetCount();
891 	for ( int i = 0; i < count; i ++ )
892 	{
893 		wxString keyname = list[i];
894 		if ( m_config->Read( keyname ) == name ) m_config->DeleteEntry( keyname );
895 	}
896 }
897 
898 
GetModDefaultPresetName(const wxString & modname)899 wxString Settings::GetModDefaultPresetName( const wxString& modname )
900 {
901 	return m_config->Read( _T( "/Hosting/ModDefaultPreset/" ) + modname );
902 }
903 
904 
SetModDefaultPresetName(const wxString & modname,const wxString & presetname)905 void Settings::SetModDefaultPresetName( const wxString& modname, const wxString& presetname )
906 {
907 	m_config->Write( _T( "/Hosting/ModDefaultPreset/" ) + modname, presetname );
908 }
909 
910 
SetBalanceMethod(int value)911 void Settings::SetBalanceMethod( int value )
912 {
913 	m_config->Write( _T( "/Hosting/BalanceMethod" ), value );
914 }
GetBalanceMethod()915 int Settings::GetBalanceMethod()
916 {
917 	return m_config->Read( _T( "/Hosting/BalanceMethod" ), 1l );
918 }
919 
SetBalanceClans(bool value)920 void Settings::SetBalanceClans( bool value )
921 {
922 	m_config->Write( _T( "/Hosting/BalanceClans" ), value );
923 }
GetBalanceClans()924 bool Settings::GetBalanceClans()
925 {
926 	return m_config->Read( _T( "/Hosting/BalanceClans" ), true );
927 }
928 
SetBalanceStrongClans(bool value)929 void Settings::SetBalanceStrongClans( bool value )
930 {
931 	m_config->Write( _T( "/Hosting/BalanceStrongClans" ), value );
932 }
933 
GetBalanceStrongClans()934 bool Settings::GetBalanceStrongClans()
935 {
936 	return m_config->Read( _T( "/Hosting/BalanceStrongClans" ), 0l );
937 }
938 
SetBalanceGrouping(int value)939 void Settings::SetBalanceGrouping( int value )
940 {
941 	m_config->Write( _T( "/Hosting/BalanceGroupingSize" ), value );
942 }
943 
GetBalanceGrouping()944 int Settings::GetBalanceGrouping()
945 {
946 	return m_config->Read( _T( "/Hosting/BalanceGroupingSize" ), 0l );
947 }
948 
949 
SetFixIDMethod(int value)950 void Settings::SetFixIDMethod( int value )
951 {
952 	m_config->Write( _T( "/Hosting/FixIDMethod" ), value );
953 }
GetFixIDMethod()954 int Settings::GetFixIDMethod()
955 {
956 	return m_config->Read( _T( "/Hosting/FixIDMethod" ), 1l );
957 }
958 
SetFixIDClans(bool value)959 void Settings::SetFixIDClans( bool value )
960 {
961 	m_config->Write( _T( "/Hosting/FixIDClans" ), value );
962 }
GetFixIDClans()963 bool Settings::GetFixIDClans()
964 {
965 	return m_config->Read( _T( "/Hosting/FixIDClans" ), true );
966 }
967 
SetFixIDStrongClans(bool value)968 void Settings::SetFixIDStrongClans( bool value )
969 {
970 	m_config->Write( _T( "/Hosting/FixIDStrongClans" ), value );
971 }
972 
GetFixIDStrongClans()973 bool Settings::GetFixIDStrongClans()
974 {
975 	return m_config->Read( _T( "/Hosting/FixIDStrongClans" ), 0l );
976 }
977 
SetFixIDGrouping(int value)978 void Settings::SetFixIDGrouping( int value )
979 {
980 	m_config->Write( _T( "/Hosting/FixIDGroupingSize" ), value );
981 }
982 
GetFixIDGrouping()983 int Settings::GetFixIDGrouping()
984 {
985 	return m_config->Read( _T( "/Hosting/FixIDGroupingSize" ), 0l );
986 }
987 
988 
GetLastAI()989 wxString Settings::GetLastAI()
990 {
991 	return m_config->Read( _T( "/SinglePlayer/LastAI" ), wxEmptyString );
992 }
993 
GetLastBattleId()994 int Settings::GetLastBattleId()
995 {
996 	return m_config->Read( _T( "/Hosting/MyLastBattleId" ), -1 );
997 }
998 
GetLastScriptPassword()999 wxString Settings::GetLastScriptPassword()
1000 {
1001 	return m_config->Read( _T( "/Hosting/MyLastScriptPassword" ), wxEmptyString );
1002 }
1003 
SetDisplayJoinLeave(bool display,const wxString & channel)1004 void Settings::SetDisplayJoinLeave( bool display, const wxString& channel  )
1005 {
1006 	m_config->Write( _T( "/Channels/DisplayJoinLeave/" )  + channel, display );
1007 }
1008 
GetDisplayJoinLeave(const wxString & channel)1009 bool Settings::GetDisplayJoinLeave( const wxString& channel  )
1010 {
1011     return m_config->Read( _T( "/Channels/DisplayJoinLeave/" ) +  channel, 0l );
1012 }
1013 
1014 
SetChatHistoryLenght(int historylines)1015 void Settings::SetChatHistoryLenght( int historylines )
1016 {
1017 	m_config->Write( _T( "/Chat/HistoryLinesLenght" ), historylines );
1018 }
1019 
1020 
GetChatHistoryLenght()1021 int Settings::GetChatHistoryLenght()
1022 {
1023 	return m_config->Read( _T( "/Chat/HistoryLinesLenght" ), 1000l );
1024 }
1025 
1026 
SetChatPMSoundNotificationEnabled(bool enabled)1027 void Settings::SetChatPMSoundNotificationEnabled( bool enabled )
1028 {
1029 	m_config->Write( _T( "/Chat/PMSound" ), enabled );
1030 }
1031 
1032 
GetChatPMSoundNotificationEnabled()1033 bool Settings::GetChatPMSoundNotificationEnabled()
1034 {
1035 	return m_config->Read( _T( "/Chat/PMSound" ), 1l );
1036 }
1037 
ConvertOldRGBFormat(wxString color)1038 wxColour ConvertOldRGBFormat( wxString color )
1039 {
1040 	long R = 0, G = 0, B = 0;
1041 	color.BeforeFirst( _T( ' ' ) ).ToLong( &R );
1042 	color = color.AfterFirst( _T( ' ' ) );
1043 	color.BeforeFirst( _T( ' ' ) ).ToLong( &G );
1044 	color = color.AfterFirst( _T( ' ' ) );
1045 	color.BeforeFirst( _T( ' ' ) ).ToLong( &B );
1046 	return wxColour( R % 256, G % 256, B % 256 );
1047 }
1048 
GetChatColorNormal()1049 wxColour Settings::GetChatColorNormal()
1050 {
1051 	return wxColour( m_config->Read( _T( "/Chat/Colour/Normal" ), _T( "#000000" ) ) );
1052 }
1053 
SetChatColorNormal(wxColour value)1054 void Settings::SetChatColorNormal( wxColour value )
1055 {
1056 	m_config->Write( _T( "/Chat/Colour/Normal" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1057 }
1058 
1059 
GetChatColorBackground()1060 wxColour Settings::GetChatColorBackground()
1061 {
1062 	return wxColour( m_config->Read( _T( "/Chat/Colour/Background" ), _T( "#FFFFFF" ) ) );
1063 }
1064 
SetChatColorBackground(wxColour value)1065 void Settings::SetChatColorBackground( wxColour value )
1066 {
1067 	m_config->Write( _T( "/Chat/Colour/Background" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1068 }
1069 
GetChatColorHighlight()1070 wxColour Settings::GetChatColorHighlight()
1071 {
1072 	return wxColour( m_config->Read( _T( "/Chat/Colour/Highlight" ), _T( "#FF0000" ) ) );
1073 }
1074 
SetChatColorHighlight(wxColour value)1075 void Settings::SetChatColorHighlight( wxColour value )
1076 {
1077 	m_config->Write( _T( "/Chat/Colour/Highlight" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1078 }
1079 
GetChatColorMine()1080 wxColour Settings::GetChatColorMine()
1081 {
1082 	return wxColour( m_config->Read( _T( "/Chat/Colour/Mine" ), _T( "#8A8A8A" ) ) );
1083 }
1084 
SetChatColorMine(wxColour value)1085 void Settings::SetChatColorMine( wxColour value )
1086 {
1087 	m_config->Write( _T( "/Chat/Colour/Mine" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1088 }
1089 
GetChatColorNotification()1090 wxColour Settings::GetChatColorNotification()
1091 {
1092 	return wxColour( m_config->Read( _T( "/Chat/Colour/Notification" ), _T( "#FF2828" ) ) );
1093 }
1094 
SetChatColorNotification(wxColour value)1095 void Settings::SetChatColorNotification( wxColour value )
1096 {
1097 	m_config->Write( _T( "/Chat/Colour/Notification" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1098 }
1099 
GetChatColorAction()1100 wxColour Settings::GetChatColorAction()
1101 {
1102 	return wxColour( m_config->Read( _T( "/Chat/Colour/Action" ), _T( "#E600FF" ) ) );
1103 }
1104 
SetChatColorAction(wxColour value)1105 void Settings::SetChatColorAction( wxColour value )
1106 {
1107 	m_config->Write( _T( "/Chat/Colour/Action" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1108 }
1109 
GetChatColorServer()1110 wxColour Settings::GetChatColorServer()
1111 {
1112 	return wxColour( m_config->Read( _T( "/Chat/Colour/Server" ), _T( "#005080" ) ) );
1113 }
1114 
SetChatColorServer(wxColour value)1115 void Settings::SetChatColorServer( wxColour value )
1116 {
1117 	m_config->Write( _T( "/Chat/Colour/Server" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1118 }
1119 
GetChatColorClient()1120 wxColour Settings::GetChatColorClient()
1121 {
1122 	return wxColour( m_config->Read( _T( "/Chat/Colour/Client" ), _T( "#14C819" ) ) );
1123 }
1124 
SetChatColorClient(wxColour value)1125 void Settings::SetChatColorClient( wxColour value )
1126 {
1127 	m_config->Write( _T( "/Chat/Colour/Client" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1128 }
1129 
GetChatColorJoinPart()1130 wxColour Settings::GetChatColorJoinPart()
1131 {
1132 	return wxColour( m_config->Read( _T( "/Chat/Colour/JoinPart" ), _T( "#42CC42" ) ) );
1133 }
1134 
SetChatColorJoinPart(wxColour value)1135 void Settings::SetChatColorJoinPart( wxColour value )
1136 {
1137 	m_config->Write( _T( "/Chat/Colour/JoinPart" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1138 }
1139 
GetChatColorError()1140 wxColour Settings::GetChatColorError()
1141 {
1142 	return wxColour( m_config->Read( _T( "/Chat/Colour/Error" ), _T( "#800000" ) ) );
1143 }
1144 
SetChatColorError(wxColour value)1145 void Settings::SetChatColorError( wxColour value )
1146 {
1147 	m_config->Write( _T( "/Chat/Colour/Error" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1148 }
1149 
GetChatColorTime()1150 wxColour Settings::GetChatColorTime()
1151 {
1152 	return wxColour( m_config->Read( _T( "/Chat/Colour/Time" ), _T( "#64648C" ) ) );
1153 }
1154 
SetChatColorTime(wxColour value)1155 void Settings::SetChatColorTime( wxColour value )
1156 {
1157 	m_config->Write( _T( "/Chat/Colour/Time" ), value.GetAsString( wxC2S_CSS_SYNTAX ) );
1158 }
1159 
GetChatFont()1160 wxFont Settings::GetChatFont()
1161 {
1162 	wxString info = m_config->Read( _T( "/Chat/Font" ), wxEmptyString );
1163 	if ( info != wxEmptyString ) {
1164 		wxFont f;
1165 		f.SetNativeFontInfo( info );
1166 		return f;
1167 	}
1168 	else {
1169 		wxFont f( 8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL );
1170 		return f;
1171 	}
1172 }
1173 
SetChatFont(wxFont value)1174 void Settings::SetChatFont( wxFont value )
1175 {
1176 	m_config->Write( _T( "/Chat/Font" ), value.GetNativeFontInfoDesc() );
1177 }
1178 
1179 
GetSmartScrollEnabled()1180 bool Settings::GetSmartScrollEnabled()
1181 {
1182 	return m_config->Read( _T( "/Chat/SmartScrollEnabled" ), true );
1183 }
1184 
SetSmartScrollEnabled(bool value)1185 void Settings::SetSmartScrollEnabled( bool value ) {
1186 	m_config->Write( _T( "/Chat/SmartScrollEnabled" ), value );
1187 }
1188 
GetAlwaysAutoScrollOnFocusLost()1189 bool Settings::GetAlwaysAutoScrollOnFocusLost()
1190 {
1191 	return m_config->Read( _T( "/Chat/AlwaysAutoScrollOnFocusLost" ), true );
1192 }
1193 
SetAlwaysAutoScrollOnFocusLost(bool value)1194 void Settings::SetAlwaysAutoScrollOnFocusLost( bool value )
1195 {
1196 	m_config->Write( _T( "/Chat/AlwaysAutoScrollOnFocusLost" ), value );
1197 }
1198 
SetUseIrcColors(bool value)1199 void Settings::SetUseIrcColors( bool value )
1200 {
1201 	m_config->Write( _T( "/Chat/UseIrcColors" ), value );
1202 }
1203 
GetUseIrcColors()1204 bool Settings::GetUseIrcColors()
1205 {
1206 	return m_config->Read( _T( "/Chat/UseIrcColors" ), true );
1207 }
1208 
setFromList(const wxArrayString & list,const wxString & path)1209 void Settings::setFromList(const wxArrayString& list, const wxString& path)
1210 {
1211     wxString string;
1212     for ( unsigned int i = 0; i < list.GetCount(); i++ )
1213         string << list[i] << _T( ";" );
1214     m_config->Write( path, string );
1215 }
1216 
getFromList(const wxString & path)1217 wxArrayString Settings::getFromList(const wxString& path)
1218 {
1219     return wxStringTokenize( m_config->Read( path, wxString() ), _T(";") );
1220 }
1221 
SetHighlightedWords(const wxArrayString & words)1222 void Settings::SetHighlightedWords( const wxArrayString& words )
1223 {
1224     setFromList( words, _T("/Chat/HighlightedWords") );
1225 }
1226 
GetHighlightedWords()1227 wxArrayString Settings::GetHighlightedWords()
1228 {
1229     return getFromList( _T("/Chat/HighlightedWords") );
1230 }
1231 
ConvertLists()1232 void Settings::ConvertLists()
1233 {
1234     const wxArrayString current_hl = cfg().GetEntryList( _T( "/Chat/HighlightedWords" ) );
1235     m_config->DeleteGroup( _T( "/Chat/HighlightedWords" ) );
1236     SaveSettings();
1237     SetHighlightedWords( current_hl );
1238     SaveSettings();
1239 }
1240 
SetRequestAttOnHighlight(const bool req)1241 void Settings::SetRequestAttOnHighlight( const bool req )
1242 {
1243 	m_config->Write( _T( "/Chat/ReqAttOnHighlight" ), req );
1244 }
1245 
GetRequestAttOnHighlight()1246 bool Settings::GetRequestAttOnHighlight( )
1247 {
1248 	return m_config->Read( _T( "/Chat/ReqAttOnHighlight" ), 0l );
1249 }
1250 
1251 
GetBattleLastAutoStartState()1252 bool Settings::GetBattleLastAutoStartState()
1253 {
1254 	return m_config->Read( _T( "/Hosting/AutoStart" ) , 0l );
1255 }
1256 
SetBattleLastAutoStartState(bool value)1257 void Settings::SetBattleLastAutoStartState( bool value )
1258 {
1259 	m_config->Write( _T( "/Hosting/AutoStart" ), value );
1260 }
1261 
GetBattleLastAutoControlState()1262 bool Settings::GetBattleLastAutoControlState()
1263 {
1264 	return m_config->Read( _T( "/Hosting/AutoControl" ) , 0l );
1265 }
1266 
SetBattleLastAutoControlState(bool value)1267 void Settings::SetBattleLastAutoControlState( bool value )
1268 {
1269 	m_config->Write( _T( "/Hosting/AutoControl" ), value );
1270 }
1271 
GetBattleLastAutoSpectTime()1272 int Settings::GetBattleLastAutoSpectTime()
1273 {
1274 	return m_config->Read( _T( "/Hosting/AutoSpectTime" ) , 0l );
1275 }
1276 
SetBattleLastAutoSpectTime(int value)1277 void Settings::SetBattleLastAutoSpectTime( int value )
1278 {
1279 	m_config->Write( _T( "/Hosting/AutoSpectTime" ) , value );
1280 }
1281 
GetBattleLastAutoAnnounceDescription()1282 bool Settings::GetBattleLastAutoAnnounceDescription()
1283 {
1284 	return m_config->Read( _T( "/Hosting/AutoAnnounceDescription" ) , 0l );
1285 }
1286 
SetBattleLastAutoAnnounceDescription(bool value)1287 void Settings::SetBattleLastAutoAnnounceDescription( bool value )
1288 {
1289 	m_config->Write( _T( "/Hosting/AutoAnnounceDescription" ) , value );
1290 }
1291 
SetBattleLastSideSel(const wxString & modname,int sidenum)1292 void Settings::SetBattleLastSideSel( const wxString& modname, int sidenum )
1293 {
1294 	m_config->Write(_T("/Battle/Sides/" + modname), sidenum);
1295 }
1296 
GetBattleLastSideSel(const wxString & modname)1297 int Settings::GetBattleLastSideSel( const wxString& modname )
1298 {
1299 	if (modname.IsEmpty())
1300 		return 0;
1301 	return m_config->Read( _T("/Battle/Sides/" + modname), 0l );
1302 }
1303 
SetMapLastStartPosType(const wxString & mapname,const wxString & startpostype)1304 void Settings::SetMapLastStartPosType( const wxString& mapname, const wxString& startpostype )
1305 {
1306 	m_config->Write( _T( "/Hosting/MapLastValues/" ) + mapname + _T( "/startpostype" ), startpostype );
1307 }
1308 
SetMapLastRectPreset(const wxString & mapname,std::vector<Settings::SettStartBox> rects)1309 void Settings::SetMapLastRectPreset( const wxString& mapname, std::vector<Settings::SettStartBox> rects )
1310 {
1311 	wxString basepath = _T( "/Hosting/MapLastValues/" ) + mapname + _T( "/Rects" );
1312 	m_config->DeleteGroup( basepath );
1313 	for ( std::vector<Settings::SettStartBox>::const_iterator itor = rects.begin(); itor != rects.end(); ++itor )
1314 	{
1315 		SettStartBox box = *itor;
1316 		wxString additionalpath = basepath + _T( "/Rect" ) + TowxString( box.ally ) + _T( "/" );
1317 		m_config->Write( additionalpath + _T( "TopLeftX" ), box.topx );
1318 		m_config->Write( additionalpath + _T( "TopLeftY" ), box.topy );
1319 		m_config->Write( additionalpath + _T( "BottomRightX" ), box.bottomx );
1320 		m_config->Write( additionalpath + _T( "BottomRightY" ), box.bottomy );
1321 		m_config->Write( additionalpath + _T( "AllyTeam" ), box.ally );
1322 	}
1323 }
1324 
GetMapLastStartPosType(const wxString & mapname)1325 wxString Settings::GetMapLastStartPosType( const wxString& mapname )
1326 {
1327 	return m_config->Read( _T( "/Hosting/MapLastValues/" ) + mapname + _T( "/startpostype" ), wxEmptyString );
1328 }
1329 
GetMapLastRectPreset(const wxString & mapname)1330 std::vector<Settings::SettStartBox> Settings::GetMapLastRectPreset( const wxString& mapname )
1331 {
1332 	wxString basepath = _T( "/Hosting/MapLastValues/" ) + mapname + _T( "/Rects" );
1333 	wxArrayString boxes = cfg().GetGroupList( basepath );
1334 	std::vector<Settings::SettStartBox> ret;
1335 	for ( unsigned int i = 0; i < boxes.GetCount(); i++ )
1336 	{
1337 		wxString additionalpath = basepath + _T( "/" ) + boxes[i] + _T( "/" );
1338 		SettStartBox box;
1339 		box.topx = m_config->Read( additionalpath + _T( "TopLeftX" ), -1 );
1340 		box.topy = m_config->Read( additionalpath + _T( "TopLeftY" ), -1 );
1341 		box.bottomx = m_config->Read( additionalpath + _T( "BottomRightX" ), -1 );
1342 		box.bottomy = m_config->Read( additionalpath + _T( "BottomRightY" ), -1 );
1343 		box.ally = m_config->Read( additionalpath + _T( "AllyTeam" ), -1 );
1344 		ret.push_back( box );
1345 	}
1346 	return ret;
1347 }
1348 
GetDisableSpringVersionCheck()1349 bool Settings::GetDisableSpringVersionCheck()
1350 {
1351 	bool ret;
1352 	m_config->Read( _T( "/Spring/DisableVersionCheck" ), &ret, false );
1353 	return ret;
1354 }
1355 
SetDisableSpringVersionCheck(bool disable)1356 void Settings::SetDisableSpringVersionCheck(bool disable)
1357 {
1358     m_config->Write( _T( "/Spring/DisableVersionCheck" ), ( bool )disable );
1359 }
1360 
1361 
GetTempStorage()1362 wxString Settings::GetTempStorage()
1363 {
1364 	return wxFileName::GetTempDir();
1365 }
1366 
1367 
SetShowTooltips(bool show)1368 void Settings::SetShowTooltips( bool show )
1369 {
1370 	m_config->Write( _T( "/GUI/ShowTooltips" ), show );
1371 }
1372 
GetShowTooltips()1373 bool Settings::GetShowTooltips()
1374 {
1375 	return m_config->Read( _T( "/GUI/ShowTooltips" ), 1l );
1376 }
1377 
RemoveLayouts()1378 void Settings::RemoveLayouts()
1379 {
1380 	m_config->DeleteEntry(_T("/GUI/DefaultLayout"));
1381 	m_config->DeleteGroup(_T("/Layout"));
1382 	m_config->DeleteGroup(_T("/GUI/AUI"));
1383 }
1384 
SetColumnWidth(const wxString & list_name,const int column_ind,const int column_width)1385 void Settings::SetColumnWidth( const wxString& list_name, const int column_ind, const int column_width )
1386 {
1387 	m_config->Write( _T( "GUI/ColumnWidths/" ) + list_name + _T( "/" ) + TowxString( column_ind ), column_width );
1388 }
1389 
GetColumnWidth(const wxString & list_name,const int column)1390 int Settings::GetColumnWidth( const wxString& list_name, const int column )
1391 {
1392 	const int orgwidth = m_config->Read( _T( "/GUI/ColumnWidths/" ) + list_name + _T( "/" ) + TowxString( column ), columnWidthUnset );
1393 	int width = orgwidth;
1394 	if ( orgwidth > -1 ) //-3 is unset, -2 and -1 used for auto size by wx
1395 		width = std::max ( width, int( Settings::columnWidthMinimum ) ); //removing the temporary creation here gives me undefined ref error (koshi)
1396 	return width;
1397 }
1398 
SaveCustomColors(const wxColourData & _cdata,const wxString & paletteName)1399 void Settings::SaveCustomColors( const wxColourData& _cdata, const wxString& paletteName  )
1400 {
1401 	//note 16 colors is wx limit
1402 	wxColourData cdata = _cdata;
1403 	for ( int i = 0; i < 16; ++i )
1404 	{
1405 		wxColour col = cdata.GetCustomColour( i );
1406 		if ( !col.IsOk() )
1407 			col = wxColour ( 255, 255, 255 );
1408 		m_config->Write( _T( "/CustomColors/" ) + paletteName + _T( "/" ) + TowxString( i ),  col.GetAsString( wxC2S_HTML_SYNTAX ) ) ;
1409 	}
1410 }
1411 
GetCustomColors(const wxString & paletteName)1412 wxColourData Settings::GetCustomColors( const wxString& paletteName )
1413 {
1414 	wxColourData cdata;
1415 	//note 16 colors is wx limit
1416 	for ( int i = 0; i < 16; ++i )
1417 	{
1418 		wxColour col( m_config->Read( _T( "/CustomColors/" ) + paletteName + _T( "/" ) + TowxString( i ), wxColour ( 255, 255, 255 ).GetAsString( wxC2S_HTML_SYNTAX ) ) );
1419 		cdata.SetCustomColour( i, col );
1420 	}
1421 
1422 	return cdata;
1423 }
1424 
GetReplayFilterValues(const wxString & profile_name)1425 PlaybackListFilterValues Settings::GetReplayFilterValues( const wxString& profile_name )
1426 {
1427 	PlaybackListFilterValues filtervalues;
1428 	filtervalues.duration =         m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/duration" ), wxEmptyString );
1429 	filtervalues.map =               m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/map" ), wxEmptyString );
1430 	filtervalues.map_show =         m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/map_show" ), 0L );
1431 	filtervalues.filesize  =        m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/filesize" ), wxEmptyString );
1432 	filtervalues.filesize_mode  =   m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/filesize_mode" ), _T( ">" ) );
1433 	filtervalues.duration_mode  =   m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/duration_mode" ), _T( ">" ) );
1434 	filtervalues.mod =              m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/mod" ), wxEmptyString );
1435 	filtervalues.mod_show =         m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/mod_show" ), 0L );
1436 	filtervalues.player_mode =      m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/player_mode" ), _T( "=" ) );
1437 	filtervalues.player_num  =      m_config->Read( _T( "/ReplayFilter/" ) + profile_name + _T( "/player_num" ), _T( "All" ) );
1438 
1439 	return filtervalues;
1440 }
1441 
SetReplayFilterValues(const PlaybackListFilterValues & filtervalues,const wxString & profile_name)1442 void Settings::SetReplayFilterValues( const PlaybackListFilterValues& filtervalues, const wxString& profile_name )
1443 {
1444 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/duration" ), filtervalues.duration );
1445 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/map" ), filtervalues.map );
1446 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/map_show" ), filtervalues.map_show );
1447 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/filesize" ), filtervalues.filesize );
1448 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/filesize_mode" ), filtervalues.filesize_mode );
1449 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/duration_mode" ), filtervalues.duration_mode );
1450 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/mod" ), filtervalues.mod );
1451 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/mod_show" ), filtervalues.mod_show );
1452 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/player_mode" ), filtervalues.player_mode );
1453 	m_config->Write( _T( "/ReplayFilter/" ) + profile_name + _T( "/player_num" ), filtervalues.player_num );
1454 	m_config->Write( _T( "/ReplayFilter/lastprofile" ), profile_name );
1455 }
1456 
GetReplayFilterActivState() const1457 bool Settings::GetReplayFilterActivState() const
1458 {
1459 	return m_config->Read( _T( "/ReplayFilter/Active" ) , 0l );
1460 }
1461 
SetReplayFilterActivState(const bool state)1462 void Settings::SetReplayFilterActivState( const bool state )
1463 {
1464 	m_config->Write( _T( "/ReplayFilter/Active" ) , state );
1465 }
1466 
GetLastReplayFilterProfileName()1467 wxString Settings::GetLastReplayFilterProfileName()
1468 {
1469 	return  m_config->Read( _T( "/ReplayFilter/lastprofile" ), _T( "default" ) );
1470 }
GetLastRelayedHost()1471 wxString Settings::GetLastRelayedHost()
1472 {
1473     return  m_config->Read(_T("/General/RelayHost"),wxEmptyString);
1474 }
SetLastRelayedHost(wxString relhost)1475 void Settings::SetLastRelayedHost(wxString relhost)
1476 {
1477     m_config->Write(_T("/General/RelayHost"),relhost);
1478 }
SetCompletionMethod(CompletionMethod method)1479 void Settings::SetCompletionMethod( CompletionMethod method )
1480 {
1481 	m_config->Write( _T( "/General/CompletionMethod" ), ( int )method );
1482 }
GetCompletionMethod() const1483 Settings::CompletionMethod Settings::GetCompletionMethod(  ) const
1484 {
1485 	return  ( CompletionMethod )m_config->Read( _T( "/General/CompletionMethod" ), ( int )MatchExact );
1486 }
1487 
1488 
GetHorizontalSortkeyIndex()1489 unsigned int Settings::GetHorizontalSortkeyIndex()
1490 {
1491 	return m_config->Read( _T( "/GUI/MapSelector/HorizontalSortkeyIndex" ), 0l );
1492 }
1493 
SetHorizontalSortkeyIndex(const unsigned int idx)1494 void Settings::SetHorizontalSortkeyIndex( const unsigned int idx )
1495 {
1496 	m_config->Write( _T( "/GUI/MapSelector/HorizontalSortkeyIndex" ), ( int ) idx );
1497 }
1498 
GetVerticalSortkeyIndex()1499 unsigned int Settings::GetVerticalSortkeyIndex()
1500 {
1501 	return m_config->Read( _T( "/GUI/MapSelector/VerticalSortkeyIndex" ), 0l );
1502 }
1503 
SetVerticalSortkeyIndex(const unsigned int idx)1504 void Settings::SetVerticalSortkeyIndex( const unsigned int idx )
1505 {
1506 	m_config->Write( _T( "/GUI/MapSelector/VerticalSortkeyIndex" ), ( int ) idx );
1507 }
1508 
GetHorizontalSortorder()1509 bool Settings::GetHorizontalSortorder()
1510 {
1511 	return m_config->Read( _T( "/GUI/MapSelector/HorizontalSortorder" ), 0l );
1512 }
1513 
SetHorizontalSortorder(const bool order)1514 void Settings::SetHorizontalSortorder( const bool order )
1515 {
1516 	m_config->Write( _T( "/GUI/MapSelector/HorizontalSortorder" ), order );
1517 }
1518 
GetVerticalSortorder()1519 bool Settings::GetVerticalSortorder()
1520 {
1521 	return m_config->Read( _T( "/GUI/MapSelector/VerticalSortorder" ), 0l );
1522 }
1523 
SetVerticalSortorder(const bool order)1524 void Settings::SetVerticalSortorder( const bool order )
1525 {
1526 	m_config->Write( _T( "/GUI/MapSelector/VerticalSortorder" ), order );
1527 }
1528 
SetMapSelectorFollowsMouse(bool value)1529 void Settings::SetMapSelectorFollowsMouse( bool value )
1530 {
1531 	m_config->Write( _T( "/GUI/MapSelector/SelectionFollowsMouse" ), value );
1532 }
1533 
GetMapSelectorFollowsMouse()1534 bool Settings::GetMapSelectorFollowsMouse()
1535 {
1536 	return m_config->Read( _T( "/GUI/MapSelector/SelectionFollowsMouse" ), 0l );
1537 }
1538 
GetMapSelectorFilterRadio()1539 unsigned int Settings::GetMapSelectorFilterRadio()
1540 {
1541 	return m_config->Read( _T( "/GUI/MapSelector/FilterRadio" ), 0l );
1542 }
1543 
SetMapSelectorFilterRadio(const unsigned int val)1544 void Settings::SetMapSelectorFilterRadio( const unsigned int val )
1545 {
1546 	m_config->Write( _T( "/GUI/MapSelector/FilterRadio" ), ( int ) val );
1547 }
1548 
1549 //////////////////////////////////////////////////////////////////////////////
1550 ///                            SpringSettings                              ///
1551 //////////////////////////////////////////////////////////////////////////////
1552 
1553 
getMode()1554 long Settings::getMode()
1555 {
1556 	return m_config->Read( _T( "/SpringSettings/mode" ), SET_MODE_SIMPLE );
1557 }
1558 
setMode(long mode)1559 void Settings::setMode( long mode )
1560 {
1561 	m_config->Write( _T( "/SpringSettings/mode" ), mode );
1562 }
1563 
getDisableWarning()1564 bool Settings::getDisableWarning()
1565 {
1566 	return m_config->Read( _T( "/SpringSettings/disableWarning" ), 0l );
1567 }
1568 
setDisableWarning(bool disable)1569 void Settings::setDisableWarning( bool disable )
1570 {
1571 	m_config->Write( _T( "/SpringSettings/disableWarning" ), disable );
1572 }
1573 
1574 
getSimpleRes()1575 wxString Settings::getSimpleRes()
1576 {
1577 	wxString def = vl_Resolution_Str[1];
1578 	m_config->Read( _T( "/SpringSettings/SimpleRes" ), &def );
1579 	return def;
1580 }
setSimpleRes(wxString res)1581 void Settings::setSimpleRes( wxString res )
1582 {
1583 	m_config->Write( _T( "/SpringSettings/SimpleRes" ), res );
1584 }
1585 
getSimpleQuality()1586 wxString Settings::getSimpleQuality()
1587 {
1588 	wxString def = wxT( "medium" );
1589 	m_config->Read( _T( "/SpringSettings/SimpleQuality" ), &def );
1590 	return def;
1591 }
1592 
setSimpleQuality(wxString qual)1593 void Settings::setSimpleQuality( wxString qual )
1594 {
1595 	m_config->Write( _T( "/SpringSettings/SimpleQuality" ), qual );
1596 }
1597 
getSimpleDetail()1598 wxString Settings::getSimpleDetail()
1599 {
1600 	wxString def = wxT( "medium" );
1601 	m_config->Read( _T( "/SpringSettings/SimpleDetail" ), &def );
1602 	return def;
1603 }
1604 
setSimpleDetail(wxString det)1605 void Settings::setSimpleDetail( wxString det )
1606 {
1607 	m_config->Write( _T( "/SpringSettings/SimpleDetail" ), det );
1608 }
1609 
IsSpringBin(const wxString & path)1610 bool Settings::IsSpringBin( const wxString& path )
1611 {
1612 	if ( !wxFile::Exists( path ) ) return false;
1613 	if ( !wxFileName::IsFileExecutable( path ) ) return false;
1614 	return true;
1615 }
1616 
GetSortOrder(const wxString & list_name)1617 SortOrder Settings::GetSortOrder( const wxString& list_name )
1618 {
1619 	SortOrder order;
1620 	slConfig::PathGuard pathGuard ( m_config, _T( "/UI/SortOrder/" ) + list_name + _T( "/" ) );
1621 	unsigned int entries  = m_config->GetNumberOfGroups( false ); //do not recurse
1622 	for ( unsigned int i = 0; i < entries ; i++ )
1623 	{
1624 		SortOrderItem it;
1625 		it.direction = m_config->Read( TowxString( i ) + _T( "/dir" ), 1 );
1626 		it.col = m_config->Read( TowxString( i ) + _T( "/col" ), i );
1627 		order[i] = it;
1628 	}
1629 	return order;
1630 }
1631 
SetSortOrder(const wxString & list_name,const SortOrder & order)1632 void Settings::SetSortOrder( const wxString& list_name, const SortOrder& order  )
1633 {
1634 	SortOrder::const_iterator it = order.begin();
1635 	for ( ; it != order.end(); ++it ) {
1636 		m_config->Write( _T( "/UI/SortOrder/" ) + list_name + _T( "/" ) + TowxString( it->first ) + _T( "/dir" ), it->second.direction );
1637 		m_config->Write( _T( "/UI/SortOrder/" ) + list_name + _T( "/" ) + TowxString( it->first ) + _T( "/col" ), it->second.col );
1638 	}
1639 }
1640 
GetSashPosition(const wxString & window_name)1641 int Settings::GetSashPosition( const wxString& window_name )
1642 {
1643 	return m_config->Read( _T( "/GUI/SashPostion/" ) + window_name , 200l );
1644 }
1645 
SetSashPosition(const wxString & window_name,const int pos)1646 void Settings::SetSashPosition( const wxString& window_name, const int pos )
1647 {
1648 	m_config->Write( _T( "/GUI/SashPostion/" ) + window_name , pos );
1649 }
1650 
GetSplitBRoomHorizontally()1651 bool Settings::GetSplitBRoomHorizontally()
1652 {
1653 	return m_config->Read( _T( "/GUI/SplitBRoomHorizontally" ) , 1l );
1654 }
1655 
SetSplitBRoomHorizontally(const bool vertical)1656 void Settings::SetSplitBRoomHorizontally( const bool vertical )
1657 {
1658 	m_config->Write( _T( "/GUI/SplitBRoomHorizontally" ) , vertical );
1659 }
1660 
GetEditorPath()1661 wxString Settings::GetEditorPath( )
1662 {
1663     #if defined(__WXMSW__)
1664         wxString def = wxGetOSDirectory() + sepstring + _T("system32") + sepstring + _T("notepad.exe");
1665         if ( !wxFile::Exists( def ) )
1666             def = wxEmptyString;
1667     #else
1668         wxString def = wxEmptyString;
1669     #endif
1670     return m_config->Read( _T( "/GUI/Editor" ) , def );
1671 }
1672 
SetEditorPath(const wxString & path)1673 void Settings::SetEditorPath( const wxString& path )
1674 {
1675     m_config->Write( _T( "/GUI/Editor" ) , path );
1676 }
1677 
GetShowXallTabs()1678 bool Settings::GetShowXallTabs()
1679 {
1680     return m_config->Read( _T( "/GUI/CloseOnAll" ) , 0l );
1681 }
1682 
SetShowXallTabs(bool show)1683 void Settings::SetShowXallTabs( bool show )
1684 {
1685     m_config->Write( _T( "/GUI/CloseOnAll" ) , show );
1686 }
1687 
SavePerspective(const wxString & notebook_name,const wxString & perspective_name,const wxString & layout_string)1688 void Settings::SavePerspective( const wxString& notebook_name, const wxString& perspective_name, const wxString& layout_string )
1689 {
1690 	wxString entry = wxFormat( _T( "/GUI/AUI/%s/%s" ) ) % perspective_name % notebook_name;
1691     m_config->Write( entry, layout_string );
1692 }
1693 
LoadPerspective(const wxString & notebook_name,const wxString & perspective_name)1694 wxString Settings::LoadPerspective( const wxString& notebook_name, const wxString& perspective_name )
1695 {
1696 	wxString entry = wxFormat( _T( "/GUI/AUI/%s/%s" ) ) % perspective_name % notebook_name;
1697     return m_config->Read( entry , wxEmptyString );
1698 }
1699 
GetLastPerspectiveName()1700 wxString Settings::GetLastPerspectiveName( )
1701 {
1702     return m_config->Read( _T( "/GUI/AUI/lastperspective_name" ), _T("default") );
1703 }
1704 
SetLastPerspectiveName(const wxString & name)1705 void Settings::SetLastPerspectiveName( const wxString&  name )
1706 {
1707     m_config->Write( _T( "/GUI/AUI/lastperspective_name" ), name );
1708 }
1709 
SetAutosavePerspective(bool autosave)1710 void Settings::SetAutosavePerspective( bool autosave )
1711 {
1712     m_config->Write( _T( "/GUI/AUI/autosave" ), autosave );
1713 }
1714 
GetAutosavePerspective()1715 bool Settings::GetAutosavePerspective( )
1716 {
1717     return m_config->Read( _T( "/GUI/AUI/autosave" ), 1l );
1718 }
1719 
GetPerspectives()1720 wxArrayString Settings::GetPerspectives()
1721 {
1722     wxArrayString list = cfg().GetGroupList( _T( "/GUI/AUI" ) );
1723     wxArrayString ret;
1724     for ( size_t i = 0; i < list.GetCount(); ++i) {
1725     	if ( !list[i].EndsWith( BattlePostfix ) )
1726             ret.Add( list[i] );
1727         else  {
1728             wxString stripped = list[i].Left( list[i].Len() - BattlePostfix.Len() );
1729             if ( !PerspectiveExists( stripped ) )
1730                 ret.Add( stripped );
1731         }
1732     }
1733     return ret;
1734 }
1735 
PerspectiveExists(const wxString & perspective_name)1736 bool Settings::PerspectiveExists( const wxString& perspective_name )
1737 {
1738     wxArrayString list = cfg().GetGroupList( _T( "/GUI/AUI" ) );
1739     for ( size_t i = 0; i < list.GetCount(); ++i) {
1740         if ( list[i] == perspective_name )
1741             return true;
1742     }
1743     return false;
1744 }
1745 
SetAutoloadedChatlogLinesCount(const int count)1746 void Settings::SetAutoloadedChatlogLinesCount( const int count )
1747 {
1748     m_config->Write( _T( "/GUI/AutoloadedChatlogLinesCount" ), std::abs( count ) );
1749 }
1750 
GetAutoloadedChatlogLinesCount()1751 int Settings::GetAutoloadedChatlogLinesCount( )
1752 {
1753     return m_config->Read( _T( "/GUI/AutoloadedChatlogLinesCount" ), 10l );
1754 }
1755 
SetUseNotificationPopups(const bool use)1756 void Settings::SetUseNotificationPopups( const bool use )
1757 {
1758 	m_config->Write( _T("/GUI/UseNotificationPopups"), use );
1759 }
1760 
GetUseNotificationPopups()1761 bool Settings::GetUseNotificationPopups()
1762 {
1763 	return m_config->Read( _T("/GUI/UseNotificationPopups"), true );
1764 }
1765 
SetNotificationPopupPosition(const size_t index)1766 void Settings::SetNotificationPopupPosition( const size_t index )
1767 {
1768 	m_config->Write( _T("/GUI/NotificationPopupPosition"), (long)index );
1769 }
1770 
GetNotificationPopupPosition()1771 size_t Settings::GetNotificationPopupPosition()
1772 {
1773 	return m_config->Read( _T("/GUI/NotificationPopupPosition"), (long)ScreenPosition::bottom_right );
1774 }
1775 
1776 
SetNotificationPopupDisplayTime(const unsigned int seconds)1777 void Settings::SetNotificationPopupDisplayTime( const unsigned int seconds )
1778 {
1779 	m_config->Write( _T("/GUI/NotificationPopupDisplayTime"), (long)seconds );
1780 }
1781 
GetNotificationPopupDisplayTime()1782 unsigned int Settings::GetNotificationPopupDisplayTime( )
1783 {
1784 	return m_config->Read( _T("/GUI/NotificationPopupDisplayTime"), 5l );
1785 }
1786 
1787 
GetDefaultNick()1788 wxString Settings::GetDefaultNick()
1789 {
1790 	return TowxString(LSL::usync().IsLoaded() ? LSL::usync().GetDefaultNick() : "invalid");
1791 }
1792