[release] version bump to 13.0 beta1
[vuplus_xbmc] / xbmc / settings / AdvancedSettings.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include <limits.h>
22
23 #include "system.h"
24 #include "AdvancedSettings.h"
25 #include "Application.h"
26 #include "network/DNSNameCache.h"
27 #include "filesystem/File.h"
28 #include "utils/LangCodeExpander.h"
29 #include "LangInfo.h"
30 #include "profiles/ProfilesManager.h"
31 #include "settings/lib/Setting.h"
32 #include "settings/Settings.h"
33 #include "utils/StringUtils.h"
34 #include "utils/SystemInfo.h"
35 #include "utils/URIUtils.h"
36 #include "utils/XMLUtils.h"
37 #include "utils/log.h"
38 #include "filesystem/SpecialProtocol.h"
39 #include "addons/IAddon.h"
40 #include "addons/AddonManager.h"
41 #include "addons/GUIDialogAddonSettings.h"
42 #if defined(TARGET_DARWIN_IOS)
43 #include "osx/DarwinUtils.h"
44 #endif
45
46 using namespace ADDON;
47 using namespace XFILE;
48 using namespace std;
49
50 CAdvancedSettings::CAdvancedSettings()
51 {
52   m_initialized = false;
53 }
54
55 void CAdvancedSettings::OnSettingsLoaded()
56 {
57   // load advanced settings
58   Load();
59
60   // default players?
61   CLog::Log(LOGNOTICE, "Default DVD Player: %s", m_videoDefaultDVDPlayer.c_str());
62   CLog::Log(LOGNOTICE, "Default Video Player: %s", m_videoDefaultPlayer.c_str());
63   CLog::Log(LOGNOTICE, "Default Audio Player: %s", m_audioDefaultPlayer.c_str());
64
65   // setup any logging...
66   if (CSettings::Get().GetBool("debug.showloginfo"))
67   {
68     m_logLevel = std::max(m_logLevelHint, LOG_LEVEL_DEBUG_FREEMEM);
69     CLog::Log(LOGNOTICE, "Enabled debug logging due to GUI setting (%d)", m_logLevel);
70   }
71   else
72   {
73     m_logLevel = std::min(m_logLevelHint, LOG_LEVEL_DEBUG/*LOG_LEVEL_NORMAL*/);
74     CLog::Log(LOGNOTICE, "Disabled debug logging due to GUI setting. Level %d.", m_logLevel);
75   }
76   CLog::SetLogLevel(m_logLevel);
77 }
78
79 void CAdvancedSettings::OnSettingsUnloaded()
80 {
81   m_initialized = false;
82 }
83
84 void CAdvancedSettings::OnSettingChanged(const CSetting *setting)
85 {
86   if (setting == NULL)
87     return;
88
89   const std::string &settingId = setting->GetId();
90   if (settingId == "debug.showloginfo")
91     SetDebugMode(((CSettingBool*)setting)->GetValue());
92 }
93
94 void CAdvancedSettings::OnSettingAction(const CSetting *setting)
95 {
96   if (setting == NULL)
97     return;
98
99   const std::string settingId = setting->GetId();
100   if (settingId == "debug.setextraloglevel")
101   {
102     AddonPtr addon;
103     CAddonMgr::Get().GetAddon("xbmc.debug", addon);
104     CGUIDialogAddonSettings::ShowAndGetInput(addon, true);
105     SetExtraLogsFromAddon(addon.get());
106   }
107 }
108
109 void CAdvancedSettings::Initialize()
110 {
111   if (m_initialized)
112     return;
113
114   m_audioHeadRoom = 0;
115   m_ac3Gain = 12.0f;
116   m_audioApplyDrc = true;
117   m_dvdplayerIgnoreDTSinWAV = false;
118
119   //default hold time of 25 ms, this allows a 20 hertz sine to pass undistorted
120   m_limiterHold = 0.025f;
121   m_limiterRelease = 0.1f;
122
123   m_omxHWAudioDecode = false;
124   m_omxDecodeStartWithValidFrame = false;
125
126   m_karaokeSyncDelayCDG = 0.0f;
127   m_karaokeSyncDelayLRC = 0.0f;
128   m_karaokeChangeGenreForKaraokeSongs = false;
129   m_karaokeKeepDelay = true;
130   m_karaokeStartIndex = 1;
131   m_karaokeAlwaysEmptyOnCdgs = 1;
132   m_karaokeUseSongSpecificBackground = 0;
133
134   m_audioDefaultPlayer = "paplayer";
135   m_audioPlayCountMinimumPercent = 90.0f;
136   m_audioHost = "default";
137
138   m_videoSubsDelayRange = 10;
139   m_videoAudioDelayRange = 10;
140   m_videoSmallStepBackSeconds = 7;
141   m_videoSmallStepBackTries = 3;
142   m_videoSmallStepBackDelay = 300;
143   m_videoUseTimeSeeking = true;
144   m_videoTimeSeekForward = 30;
145   m_videoTimeSeekBackward = -30;
146   m_videoTimeSeekForwardBig = 600;
147   m_videoTimeSeekBackwardBig = -600;
148   m_videoPercentSeekForward = 2;
149   m_videoPercentSeekBackward = -2;
150   m_videoPercentSeekForwardBig = 10;
151   m_videoPercentSeekBackwardBig = -10;
152   m_videoBlackBarColour = 0;
153   m_videoPPFFmpegDeint = "linblenddeint";
154   m_videoPPFFmpegPostProc = "ha:128:7,va,dr";
155   m_videoDefaultPlayer = "dvdplayer";
156   m_videoDefaultDVDPlayer = "dvdplayer";
157   m_videoIgnoreSecondsAtStart = 3*60;
158   m_videoIgnorePercentAtEnd   = 8.0f;
159   m_videoPlayCountMinimumPercent = 90.0f;
160   m_videoVDPAUScaling = -1;
161   m_videoNonLinStretchRatio = 0.5f;
162   m_videoEnableHighQualityHwScalers = false;
163   m_videoAutoScaleMaxFps = 30.0f;
164   m_videoAllowMpeg4VDPAU = false;
165   m_videoAllowMpeg4VAAPI = false;  
166   m_videoDisableBackgroundDeinterlace = false;
167   m_videoCaptureUseOcclusionQuery = -1; //-1 is auto detect
168   m_videoVDPAUtelecine = false;
169   m_videoVDPAUdeintSkipChromaHD = false;
170   m_DXVACheckCompatibility = false;
171   m_DXVACheckCompatibilityPresent = false;
172   m_DXVAForceProcessorRenderer = true;
173   m_DXVANoDeintProcForProgressive = false;
174   m_videoFpsDetect = 1;
175   m_videoBusyDialogDelay_ms = 500;
176   m_stagefrightConfig.useAVCcodec = -1;
177   m_stagefrightConfig.useVC1codec = -1;
178   m_stagefrightConfig.useVPXcodec = -1;
179   m_stagefrightConfig.useMP4codec = -1;
180   m_stagefrightConfig.useMPEG2codec = -1;
181   m_stagefrightConfig.useSwRenderer = false;
182   m_stagefrightConfig.useInputDTS = false;
183
184   m_videoDefaultLatency = 0.0;
185   m_videoDisableHi10pMultithreading = false;
186
187   m_musicUseTimeSeeking = true;
188   m_musicTimeSeekForward = 10;
189   m_musicTimeSeekBackward = -10;
190   m_musicTimeSeekForwardBig = 60;
191   m_musicTimeSeekBackwardBig = -60;
192   m_musicPercentSeekForward = 1;
193   m_musicPercentSeekBackward = -1;
194   m_musicPercentSeekForwardBig = 10;
195   m_musicPercentSeekBackwardBig = -10;
196
197   m_slideshowPanAmount = 2.5f;
198   m_slideshowZoomAmount = 5.0f;
199   m_slideshowBlackBarCompensation = 20.0f;
200
201   m_songInfoDuration = 10;
202
203   m_cddbAddress = "freedb.freedb.org";
204
205   m_handleMounting = g_application.IsStandAlone();
206
207   m_fullScreenOnMovieStart = true;
208   m_cachePath = "special://temp/";
209
210   m_videoCleanDateTimeRegExp = "(.*[^ _\\,\\.\\(\\)\\[\\]\\-])[ _\\.\\(\\)\\[\\]\\-]+(19[0-9][0-9]|20[0-1][0-9])([ _\\,\\.\\(\\)\\[\\]\\-]|[^0-9]$)";
211
212   m_videoCleanStringRegExps.clear();
213   m_videoCleanStringRegExps.push_back("[ _\\,\\.\\(\\)\\[\\]\\-](ac3|dts|custom|dc|remastered|divx|divx5|dsr|dsrip|dutch|dvd|dvd5|dvd9|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|r3|r5|bd5|se|svcd|swedish|german|read.nfo|nfofix|unrated|extended|ws|telesync|ts|telecine|tc|brrip|bdrip|480p|480i|576p|576i|720p|720i|1080p|1080i|3d|hrhd|hrhdtv|hddvd|bluray|x264|h264|xvid|xvidvd|xxx|www.www|cd[1-9]|\\[.*\\])([ _\\,\\.\\(\\)\\[\\]\\-]|$)");
214   m_videoCleanStringRegExps.push_back("(\\[.*\\])");
215
216   m_moviesExcludeFromScanRegExps.clear();
217   m_moviesExcludeFromScanRegExps.push_back("-trailer");
218   m_moviesExcludeFromScanRegExps.push_back("[!-._ \\\\/]sample[-._ \\\\/]");
219   m_tvshowExcludeFromScanRegExps.push_back("[!-._ \\\\/]sample[-._ \\\\/]");
220
221   m_folderStackRegExps.clear();
222   m_folderStackRegExps.push_back("((cd|dvd|dis[ck])[0-9]+)$");
223
224   m_videoStackRegExps.clear();
225   m_videoStackRegExps.push_back("(.*?)([ _.-]*(?:cd|dvd|p(?:(?:ar)?t)|dis[ck]|d)[ _.-]*[0-9]+)(.*?)(\\.[^.]+)$");
226   m_videoStackRegExps.push_back("(.*?)([ _.-]*(?:cd|dvd|p(?:(?:ar)?t)|dis[ck]|d)[ _.-]*[a-d])(.*?)(\\.[^.]+)$");
227   m_videoStackRegExps.push_back("(.*?)([ ._-]*[a-d])(.*?)(\\.[^.]+)$");
228   // This one is a bit too greedy to enable by default.  It will stack sequels
229   // in a flat dir structure, but is perfectly safe in a dir-per-vid one.
230   //m_videoStackRegExps.push_back("(.*?)([ ._-]*[0-9])(.*?)(\\.[^.]+)$");
231
232   m_tvshowEnumRegExps.clear();
233   // foo.s01.e01, foo.s01_e01, S01E02 foo, S01 - E02
234   m_tvshowEnumRegExps.push_back(TVShowRegexp(false,"s([0-9]+)[ ._-]*e([0-9]+(?:(?:[a-i]|\\.[1-9])(?![0-9]))?)([^\\\\/]*)$"));
235   // foo.ep01, foo.EP_01
236   m_tvshowEnumRegExps.push_back(TVShowRegexp(false,"[\\._ -]()ep_?([0-9]+(?:(?:[a-i]|\\.[1-9])(?![0-9]))?)([^\\\\/]*)$"));
237   // foo.yyyy.mm.dd.* (byDate=true)
238   m_tvshowEnumRegExps.push_back(TVShowRegexp(true,"([0-9]{4})[\\.-]([0-9]{2})[\\.-]([0-9]{2})"));
239   // foo.mm.dd.yyyy.* (byDate=true)
240   m_tvshowEnumRegExps.push_back(TVShowRegexp(true,"([0-9]{2})[\\.-]([0-9]{2})[\\.-]([0-9]{4})"));
241   // foo.1x09* or just /1x09*
242   m_tvshowEnumRegExps.push_back(TVShowRegexp(false,"[\\\\/\\._ \\[\\(-]([0-9]+)x([0-9]+(?:(?:[a-i]|\\.[1-9])(?![0-9]))?)([^\\\\/]*)$"));
243   // foo.103*, 103 foo
244   m_tvshowEnumRegExps.push_back(TVShowRegexp(false,"[\\\\/\\._ -]([0-9]+)([0-9][0-9](?:(?:[a-i]|\\.[1-9])(?![0-9]))?)([\\._ -][^\\\\/]*)$"));
245   // Part I, Pt.VI
246   m_tvshowEnumRegExps.push_back(TVShowRegexp(false,"[\\/._ -]p(?:ar)?t[_. -]()([ivx]+)([._ -][^\\/]*)$"));
247
248   m_tvshowMultiPartEnumRegExp = "^[-_ex]+([0-9]+(?:(?:[a-i]|\\.[1-9])(?![0-9]))?)";
249
250   m_remoteDelay = 3;
251   m_controllerDeadzone = 0.2f;
252
253   m_playlistAsFolders = true;
254   m_detectAsUdf = false;
255
256   m_fanartRes = 1080;
257   m_imageRes = 720;
258   m_useDDSFanart = false;
259
260   m_sambaclienttimeout = 10;
261   m_sambadoscodepage = "";
262   m_sambastatfiles = true;
263
264   m_bHTTPDirectoryStatFilesize = false;
265
266   m_bFTPThumbs = false;
267
268   m_musicThumbs = "folder.jpg|Folder.jpg|folder.JPG|Folder.JPG|cover.jpg|Cover.jpg|cover.jpeg|thumb.jpg|Thumb.jpg|thumb.JPG|Thumb.JPG";
269   m_fanartImages = "fanart.jpg|fanart.png";
270
271   m_bMusicLibraryHideAllItems = false;
272   m_bMusicLibraryAllItemsOnBottom = false;
273   m_bMusicLibraryAlbumsSortByArtistThenYear = false;
274   m_bMusicLibraryCleanOnUpdate = false;
275   m_iMusicLibraryRecentlyAddedItems = 25;
276   m_strMusicLibraryAlbumFormat = "";
277   m_strMusicLibraryAlbumFormatRight = "";
278   m_prioritiseAPEv2tags = false;
279   m_musicItemSeparator = " / ";
280   m_videoItemSeparator = " / ";
281
282   m_bVideoLibraryHideAllItems = false;
283   m_bVideoLibraryAllItemsOnBottom = false;
284   m_iVideoLibraryRecentlyAddedItems = 25;
285   m_bVideoLibraryHideEmptySeries = false;
286   m_bVideoLibraryCleanOnUpdate = false;
287   m_bVideoLibraryExportAutoThumbs = false;
288   m_bVideoLibraryImportWatchedState = false;
289   m_bVideoLibraryImportResumePoint = false;
290   m_bVideoScannerIgnoreErrors = false;
291   m_iVideoLibraryDateAdded = 1; // prefer mtime over ctime and current time
292
293   m_iTuxBoxStreamtsPort = 31339;
294   m_bTuxBoxAudioChannelSelection = false;
295   m_bTuxBoxSubMenuSelection = false;
296   m_bTuxBoxPictureIcon= true;
297   m_bTuxBoxSendAllAPids= false;
298   m_iTuxBoxEpgRequestTime = 10; //seconds
299   m_iTuxBoxDefaultSubMenu = 4;
300   m_iTuxBoxDefaultRootMenu = 0; //default TV Mode
301   m_iTuxBoxZapWaitTime = 0; // Time in sec. Default 0:OFF
302   m_bTuxBoxZapstream = true;
303   m_iTuxBoxZapstreamPort = 31344;
304
305   m_iMythMovieLength = 0; // 0 == Off
306
307   m_iEpgLingerTime = 60 * 24;           /* keep 24 hours by default */
308   m_iEpgUpdateCheckInterval = 300; /* check if tables need to be updated every 5 minutes */
309   m_iEpgCleanupInterval = 900;     /* remove old entries from the EPG every 15 minutes */
310   m_iEpgActiveTagCheckInterval = 60; /* check for updated active tags every minute */
311   m_iEpgRetryInterruptedUpdateInterval = 30; /* retry an interrupted epg update after 30 seconds */
312   m_iEpgUpdateEmptyTagsInterval = 60; /* override user selectable EPG update interval for empty EPG tags */
313   m_bEpgDisplayUpdatePopup = true; /* display a progress popup while updating EPG data from clients */
314   m_bEpgDisplayIncrementalUpdatePopup = false; /* also display a progress popup while doing incremental EPG updates */
315
316   m_bEdlMergeShortCommBreaks = false;      // Off by default
317   m_iEdlMaxCommBreakLength = 8 * 30 + 10;  // Just over 8 * 30 second commercial break.
318   m_iEdlMinCommBreakLength = 3 * 30;       // 3 * 30 second commercial breaks.
319   m_iEdlMaxCommBreakGap = 4 * 30;          // 4 * 30 second commercial breaks.
320   m_iEdlMaxStartGap = 5 * 60;              // 5 minutes.
321   m_iEdlCommBreakAutowait = 0;             // Off by default
322   m_iEdlCommBreakAutowind = 0;             // Off by default
323
324   m_curlconnecttimeout = 10;
325   m_curllowspeedtime = 20;
326   m_curlretries = 2;
327   m_curlDisableIPV6 = false;      //Certain hardware/OS combinations have trouble
328                                   //with ipv6.
329
330   m_fullScreen = m_startFullScreen = false;
331   m_showExitButton = true;
332   m_splashImage = true;
333
334   m_playlistRetries = 100;
335   m_playlistTimeout = 20; // 20 seconds timeout
336   m_GLRectangleHack = false;
337   m_iSkipLoopFilter = 0;
338   m_AllowD3D9Ex = true;
339   m_ForceD3D9Ex = false;
340   m_AllowDynamicTextures = true;
341   m_RestrictCapsMask = 0;
342   m_sleepBeforeFlip = 0;
343   m_bVirtualShares = true;
344
345 //caused lots of jerks
346 //#ifdef TARGET_WINDOWS
347 //  m_ForcedSwapTime = 2.0;
348 //#else
349   m_ForcedSwapTime = 0.0;
350 //#endif
351
352   m_cpuTempCmd = "";
353   m_gpuTempCmd = "";
354 #if defined(TARGET_DARWIN)
355   // default for osx is fullscreen always on top
356   m_alwaysOnTop = true;
357 #else
358   // default for windows is not always on top
359   m_alwaysOnTop = false;
360 #endif
361
362   m_iPVRTimeCorrection             = 0;
363   m_iPVRInfoToggleInterval         = 3000;
364   m_iPVRMinVideoCacheLevel         = 5;
365   m_iPVRMinAudioCacheLevel         = 10;
366   m_bPVRCacheInDvdPlayer           = true;
367   m_bPVRChannelIconsAutoScan       = true;
368   m_bPVRAutoScanIconsUserSet       = false;
369   m_iPVRNumericChannelSwitchTimeout = 1000;
370
371   m_measureRefreshrate = false;
372
373   m_cacheMemBufferSize = 1024 * 1024 * 20;
374   m_networkBufferMode = 0; // Default (buffer all internet streams/filesystems)
375   // the following setting determines the readRate of a player data
376   // as multiply of the default data read rate
377   m_readBufferFactor = 1.0f;
378   m_addonPackageFolderSize = 200;
379
380   m_jsonOutputCompact = true;
381   m_jsonTcpPort = 9090;
382
383   m_enableMultimediaKeys = false;
384
385   m_canWindowed = true;
386   m_guiVisualizeDirtyRegions = false;
387   m_guiAlgorithmDirtyRegions = 3;
388   m_guiDirtyRegionNoFlipTimeout = 0;
389   m_logEnableAirtunes = false;
390   m_airTunesPort = 36666;
391   m_airPlayPort = 36667;
392
393   m_databaseMusic.Reset();
394   m_databaseVideo.Reset();
395
396   m_pictureExtensions = ".png|.jpg|.jpeg|.bmp|.gif|.ico|.tif|.tiff|.tga|.pcx|.cbz|.zip|.cbr|.rar|.dng|.nef|.cr2|.crw|.orf|.arw|.erf|.3fr|.dcr|.x3f|.mef|.raf|.mrw|.pef|.sr2|.rss";
397   m_musicExtensions = ".nsv|.m4a|.flac|.aac|.strm|.pls|.rm|.rma|.mpa|.wav|.wma|.ogg|.mp3|.mp2|.m3u|.mod|.amf|.669|.dmf|.dsm|.far|.gdm|.imf|.it|.m15|.med|.okt|.s3m|.stm|.sfx|.ult|.uni|.xm|.sid|.ac3|.dts|.cue|.aif|.aiff|.wpl|.ape|.mac|.mpc|.mp+|.mpp|.shn|.zip|.rar|.wv|.nsf|.spc|.gym|.adx|.dsp|.adp|.ymf|.ast|.afc|.hps|.xsp|.xwav|.waa|.wvs|.wam|.gcm|.idsp|.mpdsp|.mss|.spt|.rsd|.mid|.kar|.sap|.cmc|.cmr|.dmc|.mpt|.mpd|.rmt|.tmc|.tm8|.tm2|.oga|.url|.pxml|.tta|.rss|.cm3|.cms|.dlt|.brstm|.wtv|.mka";
398   m_videoExtensions = ".m4v|.3g2|.3gp|.nsv|.tp|.ts|.ty|.strm|.pls|.rm|.rmvb|.m3u|.m3u8|.ifo|.mov|.qt|.divx|.xvid|.bivx|.vob|.nrg|.img|.iso|.pva|.wmv|.asf|.asx|.ogm|.m2v|.avi|.bin|.dat|.mpg|.mpeg|.mp4|.mkv|.avc|.vp3|.svq3|.nuv|.viv|.dv|.fli|.flv|.rar|.001|.wpl|.zip|.vdr|.dvr-ms|.xsp|.mts|.m2t|.m2ts|.evo|.ogv|.sdp|.avs|.rec|.url|.pxml|.vc1|.h264|.rcv|.rss|.mpls|.webm|.bdmv|.wtv";
399   m_subtitlesExtensions = ".utf|.utf8|.utf-8|.sub|.srt|.smi|.rt|.txt|.ssa|.text|.ssa|.aqt|.jss|.ass|.idx|.ifo|.rar|.zip";
400   m_discStubExtensions = ".disc";
401   // internal music extensions
402   m_musicExtensions += "|.sidstream|.oggstream|.nsfstream|.asapstream|.cdda";
403   // internal video extensions
404   m_videoExtensions += "|.pvr";
405
406   m_stereoscopicflags_sbs = "3DSBS|3D.SBS|HSBS|H.SBS|H-SBS| SBS |FULL-SBS|FULL.SBS|FULLSBS|FSBS|HALF-SBS";
407   m_stereoscopicflags_tab = "3DTAB|3D.TAB|HTAB|H.TAB|3DOU|3D.OU|3D.HOU| HOU | OU |HALF-TAB";
408
409   m_logLevelHint = m_logLevel = LOG_LEVEL_NORMAL;
410   m_extraLogLevels = 0;
411
412   #if defined(TARGET_DARWIN)
413     CStdString logDir = getenv("HOME");
414     #if defined(TARGET_DARWIN_OSX)
415     logDir += "/Library/Logs/";
416     #else // ios/atv2
417     logDir += "/" + CStdString(DarwinGetXbmcRootFolder()) + "/";
418     #endif
419     m_logFolder = logDir;
420   #else
421     m_logFolder = "special://home/";              // log file location
422   #endif
423
424   m_userAgent = g_sysinfo.GetUserAgent();
425
426   m_initialized = true;
427 }
428
429 bool CAdvancedSettings::Load()
430 {
431   // NOTE: This routine should NOT set the default of any of these parameters
432   //       it should instead use the versions of GetString/Integer/Float that
433   //       don't take defaults in.  Defaults are set in the constructor above
434   Initialize(); // In case of profile switch.
435   ParseSettingsFile("special://xbmc/system/advancedsettings.xml");
436   for (unsigned int i = 0; i < m_settingsFiles.size(); i++)
437     ParseSettingsFile(m_settingsFiles[i]);
438   ParseSettingsFile(CProfilesManager::Get().GetUserDataItem("advancedsettings.xml"));
439
440   // Add the list of disc stub extensions (if any) to the list of video extensions
441   if (!m_discStubExtensions.empty())
442     m_videoExtensions += "|" + m_discStubExtensions;
443
444   return true;
445 }
446
447 void CAdvancedSettings::ParseSettingsFile(const CStdString &file)
448 {
449   CXBMCTinyXML advancedXML;
450   if (!CFile::Exists(file))
451   {
452     CLog::Log(LOGNOTICE, "No settings file to load (%s)", file.c_str());
453     return;
454   }
455
456   if (!advancedXML.LoadFile(file))
457   {
458     CLog::Log(LOGERROR, "Error loading %s, Line %d\n%s", file.c_str(), advancedXML.ErrorRow(), advancedXML.ErrorDesc());
459     return;
460   }
461
462   TiXmlElement *pRootElement = advancedXML.RootElement();
463   if (!pRootElement || strcmpi(pRootElement->Value(),"advancedsettings") != 0)
464   {
465     CLog::Log(LOGERROR, "Error loading %s, no <advancedsettings> node", file.c_str());
466     return;
467   }
468
469   // succeeded - tell the user it worked
470   CLog::Log(LOGNOTICE, "Loaded settings file from %s", file.c_str());
471
472   // Dump contents of AS.xml to debug log
473   TiXmlPrinter printer;
474   printer.SetLineBreak("\n");
475   printer.SetIndent("  ");
476   advancedXML.Accept(&printer);
477   CLog::Log(LOGNOTICE, "Contents of %s are...\n%s", file.c_str(), printer.CStr());
478
479   TiXmlElement *pElement = pRootElement->FirstChildElement("audio");
480   if (pElement)
481   {
482     XMLUtils::GetFloat(pElement, "ac3downmixgain", m_ac3Gain, -96.0f, 96.0f);
483     XMLUtils::GetInt(pElement, "headroom", m_audioHeadRoom, 0, 12);
484     XMLUtils::GetString(pElement, "defaultplayer", m_audioDefaultPlayer);
485     // 101 on purpose - can be used to never automark as watched
486     XMLUtils::GetFloat(pElement, "playcountminimumpercent", m_audioPlayCountMinimumPercent, 0.0f, 101.0f);
487
488     XMLUtils::GetBoolean(pElement, "usetimeseeking", m_musicUseTimeSeeking);
489     XMLUtils::GetInt(pElement, "timeseekforward", m_musicTimeSeekForward, 0, 6000);
490     XMLUtils::GetInt(pElement, "timeseekbackward", m_musicTimeSeekBackward, -6000, 0);
491     XMLUtils::GetInt(pElement, "timeseekforwardbig", m_musicTimeSeekForwardBig, 0, 6000);
492     XMLUtils::GetInt(pElement, "timeseekbackwardbig", m_musicTimeSeekBackwardBig, -6000, 0);
493
494     XMLUtils::GetInt(pElement, "percentseekforward", m_musicPercentSeekForward, 0, 100);
495     XMLUtils::GetInt(pElement, "percentseekbackward", m_musicPercentSeekBackward, -100, 0);
496     XMLUtils::GetInt(pElement, "percentseekforwardbig", m_musicPercentSeekForwardBig, 0, 100);
497     XMLUtils::GetInt(pElement, "percentseekbackwardbig", m_musicPercentSeekBackwardBig, -100, 0);
498
499     TiXmlElement* pAudioExcludes = pElement->FirstChildElement("excludefromlisting");
500     if (pAudioExcludes)
501       GetCustomRegexps(pAudioExcludes, m_audioExcludeFromListingRegExps);
502
503     pAudioExcludes = pElement->FirstChildElement("excludefromscan");
504     if (pAudioExcludes)
505       GetCustomRegexps(pAudioExcludes, m_audioExcludeFromScanRegExps);
506
507     XMLUtils::GetString(pElement, "audiohost", m_audioHost);
508     XMLUtils::GetBoolean(pElement, "applydrc", m_audioApplyDrc);
509     XMLUtils::GetBoolean(pElement, "dvdplayerignoredtsinwav", m_dvdplayerIgnoreDTSinWAV);
510
511     XMLUtils::GetFloat(pElement, "limiterhold", m_limiterHold, 0.0f, 100.0f);
512     XMLUtils::GetFloat(pElement, "limiterrelease", m_limiterRelease, 0.001f, 100.0f);
513   }
514
515   pElement = pRootElement->FirstChildElement("omx");
516   if (pElement)
517   {
518     XMLUtils::GetBoolean(pElement, "omxhwaudiodecode", m_omxHWAudioDecode);
519     XMLUtils::GetBoolean(pElement, "omxdecodestartwithvalidframe", m_omxDecodeStartWithValidFrame);
520   }
521
522   pElement = pRootElement->FirstChildElement("karaoke");
523   if (pElement)
524   {
525     XMLUtils::GetFloat(pElement, "syncdelaycdg", m_karaokeSyncDelayCDG, -3.0f, 3.0f); // keep the old name for comp
526     XMLUtils::GetFloat(pElement, "syncdelaylrc", m_karaokeSyncDelayLRC, -3.0f, 3.0f);
527     XMLUtils::GetBoolean(pElement, "alwaysreplacegenre", m_karaokeChangeGenreForKaraokeSongs );
528     XMLUtils::GetBoolean(pElement, "storedelay", m_karaokeKeepDelay );
529     XMLUtils::GetInt(pElement, "autoassignstartfrom", m_karaokeStartIndex, 1, 2000000000);
530     XMLUtils::GetBoolean(pElement, "nocdgbackground", m_karaokeAlwaysEmptyOnCdgs );
531     XMLUtils::GetBoolean(pElement, "lookupsongbackground", m_karaokeUseSongSpecificBackground );
532
533     TiXmlElement* pKaraokeBackground = pElement->FirstChildElement("defaultbackground");
534     if (pKaraokeBackground)
535     {
536       const char* attr = pKaraokeBackground->Attribute("type");
537       if ( attr )
538         m_karaokeDefaultBackgroundType = attr;
539
540       attr = pKaraokeBackground->Attribute("path");
541       if ( attr )
542         m_karaokeDefaultBackgroundFilePath = attr;
543     }
544   }
545
546   pElement = pRootElement->FirstChildElement("video");
547   if (pElement)
548   {
549     XMLUtils::GetString(pElement, "stereoscopicflagssbs", m_stereoscopicflags_sbs);
550     XMLUtils::GetString(pElement, "stereoscopicflagstab", m_stereoscopicflags_tab);
551     XMLUtils::GetFloat(pElement, "subsdelayrange", m_videoSubsDelayRange, 10, 600);
552     XMLUtils::GetFloat(pElement, "audiodelayrange", m_videoAudioDelayRange, 10, 600);
553     XMLUtils::GetInt(pElement, "blackbarcolour", m_videoBlackBarColour, 0, 255);
554     XMLUtils::GetString(pElement, "defaultplayer", m_videoDefaultPlayer);
555     XMLUtils::GetString(pElement, "defaultdvdplayer", m_videoDefaultDVDPlayer);
556     XMLUtils::GetBoolean(pElement, "fullscreenonmoviestart", m_fullScreenOnMovieStart);
557     // 101 on purpose - can be used to never automark as watched
558     XMLUtils::GetFloat(pElement, "playcountminimumpercent", m_videoPlayCountMinimumPercent, 0.0f, 101.0f);
559     XMLUtils::GetInt(pElement, "ignoresecondsatstart", m_videoIgnoreSecondsAtStart, 0, 900);
560     XMLUtils::GetFloat(pElement, "ignorepercentatend", m_videoIgnorePercentAtEnd, 0, 100.0f);
561
562     XMLUtils::GetInt(pElement, "smallstepbackseconds", m_videoSmallStepBackSeconds, 1, INT_MAX);
563     XMLUtils::GetInt(pElement, "smallstepbacktries", m_videoSmallStepBackTries, 1, 10);
564     XMLUtils::GetInt(pElement, "smallstepbackdelay", m_videoSmallStepBackDelay, 100, 5000); //MS
565
566     XMLUtils::GetBoolean(pElement, "usetimeseeking", m_videoUseTimeSeeking);
567     XMLUtils::GetInt(pElement, "timeseekforward", m_videoTimeSeekForward, 0, 6000);
568     XMLUtils::GetInt(pElement, "timeseekbackward", m_videoTimeSeekBackward, -6000, 0);
569     XMLUtils::GetInt(pElement, "timeseekforwardbig", m_videoTimeSeekForwardBig, 0, 6000);
570     XMLUtils::GetInt(pElement, "timeseekbackwardbig", m_videoTimeSeekBackwardBig, -6000, 0);
571
572     XMLUtils::GetInt(pElement, "percentseekforward", m_videoPercentSeekForward, 0, 100);
573     XMLUtils::GetInt(pElement, "percentseekbackward", m_videoPercentSeekBackward, -100, 0);
574     XMLUtils::GetInt(pElement, "percentseekforwardbig", m_videoPercentSeekForwardBig, 0, 100);
575     XMLUtils::GetInt(pElement, "percentseekbackwardbig", m_videoPercentSeekBackwardBig, -100, 0);
576
577     TiXmlElement* pVideoExcludes = pElement->FirstChildElement("excludefromlisting");
578     if (pVideoExcludes)
579       GetCustomRegexps(pVideoExcludes, m_videoExcludeFromListingRegExps);
580
581     pVideoExcludes = pElement->FirstChildElement("excludefromscan");
582     if (pVideoExcludes)
583       GetCustomRegexps(pVideoExcludes, m_moviesExcludeFromScanRegExps);
584
585     pVideoExcludes = pElement->FirstChildElement("excludetvshowsfromscan");
586     if (pVideoExcludes)
587       GetCustomRegexps(pVideoExcludes, m_tvshowExcludeFromScanRegExps);
588
589     pVideoExcludes = pElement->FirstChildElement("cleanstrings");
590     if (pVideoExcludes)
591       GetCustomRegexps(pVideoExcludes, m_videoCleanStringRegExps);
592
593     XMLUtils::GetString(pElement,"cleandatetime", m_videoCleanDateTimeRegExp);
594     XMLUtils::GetString(pElement,"ppffmpegdeinterlacing",m_videoPPFFmpegDeint);
595     XMLUtils::GetString(pElement,"ppffmpegpostprocessing",m_videoPPFFmpegPostProc);
596     XMLUtils::GetInt(pElement,"vdpauscaling",m_videoVDPAUScaling);
597     XMLUtils::GetFloat(pElement, "nonlinearstretchratio", m_videoNonLinStretchRatio, 0.01f, 1.0f);
598     XMLUtils::GetBoolean(pElement,"enablehighqualityhwscalers", m_videoEnableHighQualityHwScalers);
599     XMLUtils::GetFloat(pElement,"autoscalemaxfps",m_videoAutoScaleMaxFps, 0.0f, 1000.0f);
600     XMLUtils::GetBoolean(pElement,"allowmpeg4vdpau",m_videoAllowMpeg4VDPAU);
601     XMLUtils::GetBoolean(pElement,"disablehi10pmultithreading",m_videoDisableHi10pMultithreading);
602     XMLUtils::GetBoolean(pElement,"allowmpeg4vaapi",m_videoAllowMpeg4VAAPI);    
603     XMLUtils::GetBoolean(pElement, "disablebackgrounddeinterlace", m_videoDisableBackgroundDeinterlace);
604     XMLUtils::GetInt(pElement, "useocclusionquery", m_videoCaptureUseOcclusionQuery, -1, 1);
605     XMLUtils::GetBoolean(pElement,"vdpauInvTelecine",m_videoVDPAUtelecine);
606     XMLUtils::GetBoolean(pElement,"vdpauHDdeintSkipChroma",m_videoVDPAUdeintSkipChromaHD);
607
608     TiXmlElement* pStagefrightElem = pElement->FirstChildElement("stagefright");
609     if (pStagefrightElem)
610     {
611       XMLUtils::GetInt(pStagefrightElem,"useavccodec",m_stagefrightConfig.useAVCcodec, -1, 1);
612       XMLUtils::GetInt(pStagefrightElem,"usevc1codec",m_stagefrightConfig.useVC1codec, -1, 1);
613       XMLUtils::GetInt(pStagefrightElem,"usevpxcodec",m_stagefrightConfig.useVPXcodec, -1, 1);
614       XMLUtils::GetInt(pStagefrightElem,"usemp4codec",m_stagefrightConfig.useMP4codec, -1, 1);
615       XMLUtils::GetInt(pStagefrightElem,"usempeg2codec",m_stagefrightConfig.useMPEG2codec, -1, 1);
616       XMLUtils::GetBoolean(pStagefrightElem,"useswrenderer",m_stagefrightConfig.useSwRenderer);
617       XMLUtils::GetBoolean(pStagefrightElem,"useinputdts",m_stagefrightConfig.useInputDTS);
618     }
619
620     TiXmlElement* pAdjustRefreshrate = pElement->FirstChildElement("adjustrefreshrate");
621     if (pAdjustRefreshrate)
622     {
623       TiXmlElement* pRefreshOverride = pAdjustRefreshrate->FirstChildElement("override");
624       while (pRefreshOverride)
625       {
626         RefreshOverride override = {0};
627
628         float fps;
629         if (XMLUtils::GetFloat(pRefreshOverride, "fps", fps))
630         {
631           override.fpsmin = fps - 0.01f;
632           override.fpsmax = fps + 0.01f;
633         }
634
635         float fpsmin, fpsmax;
636         if (XMLUtils::GetFloat(pRefreshOverride, "fpsmin", fpsmin) &&
637             XMLUtils::GetFloat(pRefreshOverride, "fpsmax", fpsmax))
638         {
639           override.fpsmin = fpsmin;
640           override.fpsmax = fpsmax;
641         }
642
643         float refresh;
644         if (XMLUtils::GetFloat(pRefreshOverride, "refresh", refresh))
645         {
646           override.refreshmin = refresh - 0.01f;
647           override.refreshmax = refresh + 0.01f;
648         }
649
650         float refreshmin, refreshmax;
651         if (XMLUtils::GetFloat(pRefreshOverride, "refreshmin", refreshmin) &&
652             XMLUtils::GetFloat(pRefreshOverride, "refreshmax", refreshmax))
653         {
654           override.refreshmin = refreshmin;
655           override.refreshmax = refreshmax;
656         }
657
658         bool fpsCorrect     = (override.fpsmin > 0.0f && override.fpsmax >= override.fpsmin);
659         bool refreshCorrect = (override.refreshmin > 0.0f && override.refreshmax >= override.refreshmin);
660
661         if (fpsCorrect && refreshCorrect)
662           m_videoAdjustRefreshOverrides.push_back(override);
663         else
664           CLog::Log(LOGWARNING, "Ignoring malformed refreshrate override, fpsmin:%f fpsmax:%f refreshmin:%f refreshmax:%f",
665               override.fpsmin, override.fpsmax, override.refreshmin, override.refreshmax);
666
667         pRefreshOverride = pRefreshOverride->NextSiblingElement("override");
668       }
669
670       TiXmlElement* pRefreshFallback = pAdjustRefreshrate->FirstChildElement("fallback");
671       while (pRefreshFallback)
672       {
673         RefreshOverride fallback = {0};
674         fallback.fallback = true;
675
676         float refresh;
677         if (XMLUtils::GetFloat(pRefreshFallback, "refresh", refresh))
678         {
679           fallback.refreshmin = refresh - 0.01f;
680           fallback.refreshmax = refresh + 0.01f;
681         }
682
683         float refreshmin, refreshmax;
684         if (XMLUtils::GetFloat(pRefreshFallback, "refreshmin", refreshmin) &&
685             XMLUtils::GetFloat(pRefreshFallback, "refreshmax", refreshmax))
686         {
687           fallback.refreshmin = refreshmin;
688           fallback.refreshmax = refreshmax;
689         }
690
691         if (fallback.refreshmin > 0.0f && fallback.refreshmax >= fallback.refreshmin)
692           m_videoAdjustRefreshOverrides.push_back(fallback);
693         else
694           CLog::Log(LOGWARNING, "Ignoring malformed refreshrate fallback, fpsmin:%f fpsmax:%f refreshmin:%f refreshmax:%f",
695               fallback.fpsmin, fallback.fpsmax, fallback.refreshmin, fallback.refreshmax);
696
697         pRefreshFallback = pRefreshFallback->NextSiblingElement("fallback");
698       }
699     }
700
701     m_DXVACheckCompatibilityPresent = XMLUtils::GetBoolean(pElement,"checkdxvacompatibility", m_DXVACheckCompatibility);
702
703     XMLUtils::GetBoolean(pElement,"forcedxvarenderer", m_DXVAForceProcessorRenderer);
704     XMLUtils::GetBoolean(pElement,"dxvanodeintforprogressive", m_DXVANoDeintProcForProgressive);
705     //0 = disable fps detect, 1 = only detect on timestamps with uniform spacing, 2 detect on all timestamps
706     XMLUtils::GetInt(pElement, "fpsdetect", m_videoFpsDetect, 0, 2);
707
708     // controls the delay, in milliseconds, until
709     // the busy dialog is shown when starting video playback.
710     XMLUtils::GetInt(pElement, "busydialogdelayms", m_videoBusyDialogDelay_ms, 0, 1000);
711
712     // Store global display latency settings
713     TiXmlElement* pVideoLatency = pElement->FirstChildElement("latency");
714     if (pVideoLatency)
715     {
716       float refresh, refreshmin, refreshmax, delay;
717       TiXmlElement* pRefreshVideoLatency = pVideoLatency->FirstChildElement("refresh");
718
719       while (pRefreshVideoLatency)
720       {
721         RefreshVideoLatency videolatency = {0};
722
723         if (XMLUtils::GetFloat(pRefreshVideoLatency, "rate", refresh))
724         {
725           videolatency.refreshmin = refresh - 0.01f;
726           videolatency.refreshmax = refresh + 0.01f;
727         }
728         else if (XMLUtils::GetFloat(pRefreshVideoLatency, "min", refreshmin) &&
729                  XMLUtils::GetFloat(pRefreshVideoLatency, "max", refreshmax))
730         {
731           videolatency.refreshmin = refreshmin;
732           videolatency.refreshmax = refreshmax;
733         }
734         if (XMLUtils::GetFloat(pRefreshVideoLatency, "delay", delay, -600.0f, 600.0f))
735           videolatency.delay = delay;
736
737         if (videolatency.refreshmin > 0.0f && videolatency.refreshmax >= videolatency.refreshmin)
738           m_videoRefreshLatency.push_back(videolatency);
739         else
740           CLog::Log(LOGWARNING, "Ignoring malformed display latency <refresh> entry, min:%f max:%f", videolatency.refreshmin, videolatency.refreshmax);
741
742         pRefreshVideoLatency = pRefreshVideoLatency->NextSiblingElement("refresh");
743       }
744
745       // Get default global display latency
746       XMLUtils::GetFloat(pVideoLatency, "delay", m_videoDefaultLatency, -600.0f, 600.0f);
747     }
748   }
749
750   pElement = pRootElement->FirstChildElement("musiclibrary");
751   if (pElement)
752   {
753     XMLUtils::GetBoolean(pElement, "hideallitems", m_bMusicLibraryHideAllItems);
754     XMLUtils::GetInt(pElement, "recentlyaddeditems", m_iMusicLibraryRecentlyAddedItems, 1, INT_MAX);
755     XMLUtils::GetBoolean(pElement, "prioritiseapetags", m_prioritiseAPEv2tags);
756     XMLUtils::GetBoolean(pElement, "allitemsonbottom", m_bMusicLibraryAllItemsOnBottom);
757     XMLUtils::GetBoolean(pElement, "albumssortbyartistthenyear", m_bMusicLibraryAlbumsSortByArtistThenYear);
758     XMLUtils::GetBoolean(pElement, "cleanonupdate", m_bMusicLibraryCleanOnUpdate);
759     XMLUtils::GetString(pElement, "albumformat", m_strMusicLibraryAlbumFormat);
760     XMLUtils::GetString(pElement, "albumformatright", m_strMusicLibraryAlbumFormatRight);
761     XMLUtils::GetString(pElement, "itemseparator", m_musicItemSeparator);
762   }
763
764   pElement = pRootElement->FirstChildElement("videolibrary");
765   if (pElement)
766   {
767     XMLUtils::GetBoolean(pElement, "hideallitems", m_bVideoLibraryHideAllItems);
768     XMLUtils::GetBoolean(pElement, "allitemsonbottom", m_bVideoLibraryAllItemsOnBottom);
769     XMLUtils::GetInt(pElement, "recentlyaddeditems", m_iVideoLibraryRecentlyAddedItems, 1, INT_MAX);
770     XMLUtils::GetBoolean(pElement, "hideemptyseries", m_bVideoLibraryHideEmptySeries);
771     XMLUtils::GetBoolean(pElement, "cleanonupdate", m_bVideoLibraryCleanOnUpdate);
772     XMLUtils::GetString(pElement, "itemseparator", m_videoItemSeparator);
773     XMLUtils::GetBoolean(pElement, "exportautothumbs", m_bVideoLibraryExportAutoThumbs);
774     XMLUtils::GetBoolean(pElement, "importwatchedstate", m_bVideoLibraryImportWatchedState);
775     XMLUtils::GetBoolean(pElement, "importresumepoint", m_bVideoLibraryImportResumePoint);
776     XMLUtils::GetInt(pElement, "dateadded", m_iVideoLibraryDateAdded);
777   }
778
779   pElement = pRootElement->FirstChildElement("videoscanner");
780   if (pElement)
781   {
782     XMLUtils::GetBoolean(pElement, "ignoreerrors", m_bVideoScannerIgnoreErrors);
783   }
784
785   // Backward-compatibility of ExternalPlayer config
786   pElement = pRootElement->FirstChildElement("externalplayer");
787   if (pElement)
788   {
789     CLog::Log(LOGWARNING, "External player configuration has been removed from advancedsettings.xml.  It can now be configed in userdata/playercorefactory.xml");
790   }
791   pElement = pRootElement->FirstChildElement("slideshow");
792   if (pElement)
793   {
794     XMLUtils::GetFloat(pElement, "panamount", m_slideshowPanAmount, 0.0f, 20.0f);
795     XMLUtils::GetFloat(pElement, "zoomamount", m_slideshowZoomAmount, 0.0f, 20.0f);
796     XMLUtils::GetFloat(pElement, "blackbarcompensation", m_slideshowBlackBarCompensation, 0.0f, 50.0f);
797   }
798
799   pElement = pRootElement->FirstChildElement("network");
800   if (pElement)
801   {
802     XMLUtils::GetInt(pElement, "curlclienttimeout", m_curlconnecttimeout, 1, 1000);
803     XMLUtils::GetInt(pElement, "curllowspeedtime", m_curllowspeedtime, 1, 1000);
804     XMLUtils::GetInt(pElement, "curlretries", m_curlretries, 0, 10);
805     XMLUtils::GetBoolean(pElement,"disableipv6", m_curlDisableIPV6);
806     XMLUtils::GetUInt(pElement, "cachemembuffersize", m_cacheMemBufferSize);
807     XMLUtils::GetUInt(pElement, "buffermode", m_networkBufferMode, 0, 3);
808     XMLUtils::GetFloat(pElement, "readbufferfactor", m_readBufferFactor);
809   }
810
811   pElement = pRootElement->FirstChildElement("jsonrpc");
812   if (pElement)
813   {
814     XMLUtils::GetBoolean(pElement, "compactoutput", m_jsonOutputCompact);
815     XMLUtils::GetUInt(pElement, "tcpport", m_jsonTcpPort);
816   }
817
818   pElement = pRootElement->FirstChildElement("samba");
819   if (pElement)
820   {
821     XMLUtils::GetString(pElement,  "doscodepage",   m_sambadoscodepage);
822     XMLUtils::GetInt(pElement, "clienttimeout", m_sambaclienttimeout, 5, 100);
823     XMLUtils::GetBoolean(pElement, "statfiles", m_sambastatfiles);
824   }
825
826   pElement = pRootElement->FirstChildElement("httpdirectory");
827   if (pElement)
828     XMLUtils::GetBoolean(pElement, "statfilesize", m_bHTTPDirectoryStatFilesize);
829
830   pElement = pRootElement->FirstChildElement("ftp");
831   if (pElement)
832   {
833     XMLUtils::GetBoolean(pElement, "remotethumbs", m_bFTPThumbs);
834   }
835
836   pElement = pRootElement->FirstChildElement("loglevel");
837   if (pElement)
838   { // read the loglevel setting, so set the setting advanced to hide it in GUI
839     // as altering it will do nothing - we don't write to advancedsettings.xml
840     XMLUtils::GetInt(pRootElement, "loglevel", m_logLevelHint, LOG_LEVEL_NONE, LOG_LEVEL_MAX);
841     CSettingBool *setting = (CSettingBool *)CSettings::Get().GetSetting("debug.showloginfo");
842     if (setting != NULL)
843     {
844       const char* hide;
845       if (!((hide = pElement->Attribute("hide")) && strnicmp("false", hide, 4) == 0))
846         setting->SetVisible(false);
847     }
848     g_advancedSettings.m_logLevel = std::max(g_advancedSettings.m_logLevel, g_advancedSettings.m_logLevelHint);
849     CLog::SetLogLevel(g_advancedSettings.m_logLevel);
850   }
851
852   XMLUtils::GetString(pRootElement, "cddbaddress", m_cddbAddress);
853
854   //airtunes + airplay
855   XMLUtils::GetBoolean(pRootElement, "enableairtunesdebuglog", m_logEnableAirtunes);
856   XMLUtils::GetInt(pRootElement,     "airtunesport", m_airTunesPort);
857   XMLUtils::GetInt(pRootElement,     "airplayport", m_airPlayPort);  
858
859   XMLUtils::GetBoolean(pRootElement, "handlemounting", m_handleMounting);
860
861 #if defined(HAS_SDL) || defined(TARGET_WINDOWS)
862   XMLUtils::GetBoolean(pRootElement, "fullscreen", m_startFullScreen);
863 #endif
864   XMLUtils::GetBoolean(pRootElement, "splash", m_splashImage);
865   XMLUtils::GetBoolean(pRootElement, "showexitbutton", m_showExitButton);
866   XMLUtils::GetBoolean(pRootElement, "canwindowed", m_canWindowed);
867
868   XMLUtils::GetInt(pRootElement, "songinfoduration", m_songInfoDuration, 0, INT_MAX);
869   XMLUtils::GetInt(pRootElement, "playlistretries", m_playlistRetries, -1, 5000);
870   XMLUtils::GetInt(pRootElement, "playlisttimeout", m_playlistTimeout, 0, 5000);
871
872   XMLUtils::GetBoolean(pRootElement,"glrectanglehack", m_GLRectangleHack);
873   XMLUtils::GetInt(pRootElement,"skiploopfilter", m_iSkipLoopFilter, -16, 48);
874   XMLUtils::GetFloat(pRootElement, "forcedswaptime", m_ForcedSwapTime, 0.0, 100.0);
875
876   XMLUtils::GetBoolean(pRootElement,"allowd3d9ex", m_AllowD3D9Ex);
877   XMLUtils::GetBoolean(pRootElement,"forced3d9ex", m_ForceD3D9Ex);
878   XMLUtils::GetBoolean(pRootElement,"allowdynamictextures", m_AllowDynamicTextures);
879   XMLUtils::GetUInt(pRootElement,"restrictcapsmask", m_RestrictCapsMask);
880   XMLUtils::GetFloat(pRootElement,"sleepbeforeflip", m_sleepBeforeFlip, 0.0f, 1.0f);
881   XMLUtils::GetBoolean(pRootElement,"virtualshares", m_bVirtualShares);
882   XMLUtils::GetUInt(pRootElement, "packagefoldersize", m_addonPackageFolderSize);
883
884   //Tuxbox
885   pElement = pRootElement->FirstChildElement("tuxbox");
886   if (pElement)
887   {
888     XMLUtils::GetInt(pElement, "streamtsport", m_iTuxBoxStreamtsPort, 0, 65535);
889     XMLUtils::GetBoolean(pElement, "audiochannelselection", m_bTuxBoxAudioChannelSelection);
890     XMLUtils::GetBoolean(pElement, "submenuselection", m_bTuxBoxSubMenuSelection);
891     XMLUtils::GetBoolean(pElement, "pictureicon", m_bTuxBoxPictureIcon);
892     XMLUtils::GetBoolean(pElement, "sendallaudiopids", m_bTuxBoxSendAllAPids);
893     XMLUtils::GetInt(pElement, "epgrequesttime", m_iTuxBoxEpgRequestTime, 0, 3600);
894     XMLUtils::GetInt(pElement, "defaultsubmenu", m_iTuxBoxDefaultSubMenu, 1, 4);
895     XMLUtils::GetInt(pElement, "defaultrootmenu", m_iTuxBoxDefaultRootMenu, 0, 4);
896     XMLUtils::GetInt(pElement, "zapwaittime", m_iTuxBoxZapWaitTime, 0, 120);
897     XMLUtils::GetBoolean(pElement, "zapstream", m_bTuxBoxZapstream);
898     XMLUtils::GetInt(pElement, "zapstreamport", m_iTuxBoxZapstreamPort, 0, 65535);
899   }
900
901   // Myth TV
902   pElement = pRootElement->FirstChildElement("myth");
903   if (pElement)
904   {
905     XMLUtils::GetInt(pElement, "movielength", m_iMythMovieLength);
906   }
907
908   // EPG
909   pElement = pRootElement->FirstChildElement("epg");
910   if (pElement)
911   {
912     XMLUtils::GetInt(pElement, "lingertime", m_iEpgLingerTime);
913     XMLUtils::GetInt(pElement, "updatecheckinterval", m_iEpgUpdateCheckInterval);
914     XMLUtils::GetInt(pElement, "cleanupinterval", m_iEpgCleanupInterval);
915     XMLUtils::GetInt(pElement, "activetagcheckinterval", m_iEpgActiveTagCheckInterval);
916     XMLUtils::GetInt(pElement, "retryinterruptedupdateinterval", m_iEpgRetryInterruptedUpdateInterval);
917     XMLUtils::GetInt(pElement, "updateemptytagsinterval", m_iEpgUpdateEmptyTagsInterval);
918     XMLUtils::GetBoolean(pElement, "displayupdatepopup", m_bEpgDisplayUpdatePopup);
919     XMLUtils::GetBoolean(pElement, "displayincrementalupdatepopup", m_bEpgDisplayIncrementalUpdatePopup);
920   }
921
922   // EDL commercial break handling
923   pElement = pRootElement->FirstChildElement("edl");
924   if (pElement)
925   {
926     XMLUtils::GetBoolean(pElement, "mergeshortcommbreaks", m_bEdlMergeShortCommBreaks);
927     XMLUtils::GetInt(pElement, "maxcommbreaklength", m_iEdlMaxCommBreakLength, 0, 10 * 60); // Between 0 and 10 minutes
928     XMLUtils::GetInt(pElement, "mincommbreaklength", m_iEdlMinCommBreakLength, 0, 5 * 60);  // Between 0 and 5 minutes
929     XMLUtils::GetInt(pElement, "maxcommbreakgap", m_iEdlMaxCommBreakGap, 0, 5 * 60);        // Between 0 and 5 minutes.
930     XMLUtils::GetInt(pElement, "maxstartgap", m_iEdlMaxStartGap, 0, 10 * 60);               // Between 0 and 10 minutes
931     XMLUtils::GetInt(pElement, "commbreakautowait", m_iEdlCommBreakAutowait, 0, 10);        // Between 0 and 10 seconds
932     XMLUtils::GetInt(pElement, "commbreakautowind", m_iEdlCommBreakAutowind, 0, 10);        // Between 0 and 10 seconds
933   }
934
935   // picture exclude regexps
936   TiXmlElement* pPictureExcludes = pRootElement->FirstChildElement("pictureexcludes");
937   if (pPictureExcludes)
938     GetCustomRegexps(pPictureExcludes, m_pictureExcludeFromListingRegExps);
939
940   // picture extensions
941   TiXmlElement* pExts = pRootElement->FirstChildElement("pictureextensions");
942   if (pExts)
943     GetCustomExtensions(pExts, m_pictureExtensions);
944
945   // music extensions
946   pExts = pRootElement->FirstChildElement("musicextensions");
947   if (pExts)
948     GetCustomExtensions(pExts, m_musicExtensions);
949
950   // video extensions
951   pExts = pRootElement->FirstChildElement("videoextensions");
952   if (pExts)
953     GetCustomExtensions(pExts, m_videoExtensions);
954
955   // stub extensions
956   pExts = pRootElement->FirstChildElement("discstubextensions");
957   if (pExts)
958     GetCustomExtensions(pExts, m_discStubExtensions);
959
960   m_vecTokens.clear();
961   CLangInfo::LoadTokens(pRootElement->FirstChild("sorttokens"),m_vecTokens);
962
963   // TODO: Should cache path be given in terms of our predefined paths??
964   //       Are we even going to have predefined paths??
965   CStdString tmp;
966   if (XMLUtils::GetPath(pRootElement, "cachepath", tmp))
967     m_cachePath = tmp;
968   URIUtils::AddSlashAtEnd(m_cachePath);
969
970   g_LangCodeExpander.LoadUserCodes(pRootElement->FirstChildElement("languagecodes"));
971
972   // trailer matching regexps
973   TiXmlElement* pTrailerMatching = pRootElement->FirstChildElement("trailermatching");
974   if (pTrailerMatching)
975     GetCustomRegexps(pTrailerMatching, m_trailerMatchRegExps);
976
977   //everything thats a trailer is not a movie
978   m_moviesExcludeFromScanRegExps.insert(m_moviesExcludeFromScanRegExps.end(),
979                                         m_trailerMatchRegExps.begin(),
980                                         m_trailerMatchRegExps.end());
981
982   // video stacking regexps
983   TiXmlElement* pVideoStacking = pRootElement->FirstChildElement("moviestacking");
984   if (pVideoStacking)
985     GetCustomRegexps(pVideoStacking, m_videoStackRegExps);
986
987   // folder stacking regexps
988   TiXmlElement* pFolderStacking = pRootElement->FirstChildElement("folderstacking");
989   if (pFolderStacking)
990     GetCustomRegexps(pFolderStacking, m_folderStackRegExps);
991
992   //tv stacking regexps
993   TiXmlElement* pTVStacking = pRootElement->FirstChildElement("tvshowmatching");
994   if (pTVStacking)
995     GetCustomTVRegexps(pTVStacking, m_tvshowEnumRegExps);
996
997   //tv multipart enumeration regexp
998   XMLUtils::GetString(pRootElement, "tvmultipartmatching", m_tvshowMultiPartEnumRegExp);
999
1000   // path substitutions
1001   TiXmlElement* pPathSubstitution = pRootElement->FirstChildElement("pathsubstitution");
1002   if (pPathSubstitution)
1003   {
1004     m_pathSubstitutions.clear();
1005     CLog::Log(LOGDEBUG,"Configuring path substitutions");
1006     TiXmlNode* pSubstitute = pPathSubstitution->FirstChildElement("substitute");
1007     while (pSubstitute)
1008     {
1009       CStdString strFrom, strTo;
1010       TiXmlNode* pFrom = pSubstitute->FirstChild("from");
1011       if (pFrom)
1012         strFrom = CSpecialProtocol::TranslatePath(pFrom->FirstChild()->Value()).c_str();
1013       TiXmlNode* pTo = pSubstitute->FirstChild("to");
1014       if (pTo)
1015         strTo = pTo->FirstChild()->Value();
1016
1017       if (!strFrom.empty() && !strTo.empty())
1018       {
1019         CLog::Log(LOGDEBUG,"  Registering substition pair:");
1020         CLog::Log(LOGDEBUG,"    From: [%s]", strFrom.c_str());
1021         CLog::Log(LOGDEBUG,"    To:   [%s]", strTo.c_str());
1022         m_pathSubstitutions.push_back(make_pair(strFrom,strTo));
1023       }
1024       else
1025       {
1026         // error message about missing tag
1027         if (strFrom.empty())
1028           CLog::Log(LOGERROR,"  Missing <from> tag");
1029         else
1030           CLog::Log(LOGERROR,"  Missing <to> tag");
1031       }
1032
1033       // get next one
1034       pSubstitute = pSubstitute->NextSiblingElement("substitute");
1035     }
1036   }
1037
1038   XMLUtils::GetInt(pRootElement, "remotedelay", m_remoteDelay, 1, 20);
1039   XMLUtils::GetFloat(pRootElement, "controllerdeadzone", m_controllerDeadzone, 0.0f, 1.0f);
1040   XMLUtils::GetUInt(pRootElement, "fanartres", m_fanartRes, 0, 1080);
1041   XMLUtils::GetUInt(pRootElement, "imageres", m_imageRes, 0, 1080);
1042 #if !defined(TARGET_RASPBERRY_PI)
1043   XMLUtils::GetBoolean(pRootElement, "useddsfanart", m_useDDSFanart);
1044 #endif
1045   XMLUtils::GetBoolean(pRootElement, "playlistasfolders", m_playlistAsFolders);
1046   XMLUtils::GetBoolean(pRootElement, "detectasudf", m_detectAsUdf);
1047
1048   // music thumbs
1049   TiXmlElement* pThumbs = pRootElement->FirstChildElement("musicthumbs");
1050   if (pThumbs)
1051     GetCustomExtensions(pThumbs,m_musicThumbs);
1052
1053   // movie fanarts
1054   TiXmlElement* pFanart = pRootElement->FirstChildElement("fanart");
1055   if (pFanart)
1056     GetCustomExtensions(pFanart,m_fanartImages);
1057
1058   // music filename->tag filters
1059   TiXmlElement* filters = pRootElement->FirstChildElement("musicfilenamefilters");
1060   if (filters)
1061   {
1062     TiXmlNode* filter = filters->FirstChild("filter");
1063     while (filter)
1064     {
1065       if (filter->FirstChild())
1066         m_musicTagsFromFileFilters.push_back(filter->FirstChild()->ValueStr());
1067       filter = filter->NextSibling("filter");
1068     }
1069   }
1070
1071   TiXmlElement* pHostEntries = pRootElement->FirstChildElement("hosts");
1072   if (pHostEntries)
1073   {
1074     TiXmlElement* element = pHostEntries->FirstChildElement("entry");
1075     while(element)
1076     {
1077       CStdString name  = element->Attribute("name");
1078       CStdString value;
1079       if(element->GetText())
1080         value = element->GetText();
1081
1082       if(name.length() > 0 && value.length() > 0)
1083         CDNSNameCache::Add(name, value);
1084       element = element->NextSiblingElement("entry");
1085     }
1086   }
1087
1088   XMLUtils::GetString(pRootElement, "cputempcommand", m_cpuTempCmd);
1089   XMLUtils::GetString(pRootElement, "gputempcommand", m_gpuTempCmd);
1090
1091   XMLUtils::GetBoolean(pRootElement, "alwaysontop", m_alwaysOnTop);
1092
1093   TiXmlElement *pPVR = pRootElement->FirstChildElement("pvr");
1094   if (pPVR)
1095   {
1096     XMLUtils::GetInt(pPVR, "timecorrection", m_iPVRTimeCorrection, 0, 1440);
1097     XMLUtils::GetInt(pPVR, "infotoggleinterval", m_iPVRInfoToggleInterval, 0, 30000);
1098     XMLUtils::GetInt(pPVR, "minvideocachelevel", m_iPVRMinVideoCacheLevel, 0, 100);
1099     XMLUtils::GetInt(pPVR, "minaudiocachelevel", m_iPVRMinAudioCacheLevel, 0, 100);
1100     XMLUtils::GetBoolean(pPVR, "cacheindvdplayer", m_bPVRCacheInDvdPlayer);
1101     XMLUtils::GetBoolean(pPVR, "channeliconsautoscan", m_bPVRChannelIconsAutoScan);
1102     XMLUtils::GetBoolean(pPVR, "autoscaniconsuserset", m_bPVRAutoScanIconsUserSet);
1103     XMLUtils::GetInt(pPVR, "numericchannelswitchtimeout", m_iPVRNumericChannelSwitchTimeout, 50, 60000);
1104   }
1105
1106   XMLUtils::GetBoolean(pRootElement, "measurerefreshrate", m_measureRefreshrate);
1107
1108   TiXmlElement* pDatabase = pRootElement->FirstChildElement("videodatabase");
1109   if (pDatabase)
1110   {
1111     CLog::Log(LOGWARNING, "VIDEO database configuration is experimental.");
1112     XMLUtils::GetString(pDatabase, "type", m_databaseVideo.type);
1113     XMLUtils::GetString(pDatabase, "host", m_databaseVideo.host);
1114     XMLUtils::GetString(pDatabase, "port", m_databaseVideo.port);
1115     XMLUtils::GetString(pDatabase, "user", m_databaseVideo.user);
1116     XMLUtils::GetString(pDatabase, "pass", m_databaseVideo.pass);
1117     XMLUtils::GetString(pDatabase, "name", m_databaseVideo.name);
1118     XMLUtils::GetString(pDatabase, "key", m_databaseVideo.key);
1119     XMLUtils::GetString(pDatabase, "cert", m_databaseVideo.cert);
1120     XMLUtils::GetString(pDatabase, "ca", m_databaseVideo.ca);
1121     XMLUtils::GetString(pDatabase, "capath", m_databaseVideo.capath);
1122     XMLUtils::GetString(pDatabase, "ciphers", m_databaseVideo.ciphers);
1123   }
1124
1125   pDatabase = pRootElement->FirstChildElement("musicdatabase");
1126   if (pDatabase)
1127   {
1128     XMLUtils::GetString(pDatabase, "type", m_databaseMusic.type);
1129     XMLUtils::GetString(pDatabase, "host", m_databaseMusic.host);
1130     XMLUtils::GetString(pDatabase, "port", m_databaseMusic.port);
1131     XMLUtils::GetString(pDatabase, "user", m_databaseMusic.user);
1132     XMLUtils::GetString(pDatabase, "pass", m_databaseMusic.pass);
1133     XMLUtils::GetString(pDatabase, "name", m_databaseMusic.name);
1134     XMLUtils::GetString(pDatabase, "key", m_databaseMusic.key);
1135     XMLUtils::GetString(pDatabase, "cert", m_databaseMusic.cert);
1136     XMLUtils::GetString(pDatabase, "ca", m_databaseMusic.ca);
1137     XMLUtils::GetString(pDatabase, "capath", m_databaseMusic.capath);
1138     XMLUtils::GetString(pDatabase, "ciphers", m_databaseMusic.ciphers);
1139   }
1140
1141   pDatabase = pRootElement->FirstChildElement("tvdatabase");
1142   if (pDatabase)
1143   {
1144     XMLUtils::GetString(pDatabase, "type", m_databaseTV.type);
1145     XMLUtils::GetString(pDatabase, "host", m_databaseTV.host);
1146     XMLUtils::GetString(pDatabase, "port", m_databaseTV.port);
1147     XMLUtils::GetString(pDatabase, "user", m_databaseTV.user);
1148     XMLUtils::GetString(pDatabase, "pass", m_databaseTV.pass);
1149     XMLUtils::GetString(pDatabase, "name", m_databaseTV.name);
1150     XMLUtils::GetString(pDatabase, "key", m_databaseTV.key);
1151     XMLUtils::GetString(pDatabase, "cert", m_databaseTV.cert);
1152     XMLUtils::GetString(pDatabase, "ca", m_databaseTV.ca);
1153     XMLUtils::GetString(pDatabase, "capath", m_databaseTV.capath);
1154     XMLUtils::GetString(pDatabase, "ciphers", m_databaseTV.ciphers);
1155   }
1156
1157   pDatabase = pRootElement->FirstChildElement("epgdatabase");
1158   if (pDatabase)
1159   {
1160     XMLUtils::GetString(pDatabase, "type", m_databaseEpg.type);
1161     XMLUtils::GetString(pDatabase, "host", m_databaseEpg.host);
1162     XMLUtils::GetString(pDatabase, "port", m_databaseEpg.port);
1163     XMLUtils::GetString(pDatabase, "user", m_databaseEpg.user);
1164     XMLUtils::GetString(pDatabase, "pass", m_databaseEpg.pass);
1165     XMLUtils::GetString(pDatabase, "name", m_databaseEpg.name);
1166     XMLUtils::GetString(pDatabase, "key", m_databaseEpg.key);
1167     XMLUtils::GetString(pDatabase, "cert", m_databaseEpg.cert);
1168     XMLUtils::GetString(pDatabase, "ca", m_databaseEpg.ca);
1169     XMLUtils::GetString(pDatabase, "capath", m_databaseEpg.capath);
1170     XMLUtils::GetString(pDatabase, "ciphers", m_databaseEpg.ciphers);
1171   }
1172
1173   pElement = pRootElement->FirstChildElement("enablemultimediakeys");
1174   if (pElement)
1175   {
1176     XMLUtils::GetBoolean(pRootElement, "enablemultimediakeys", m_enableMultimediaKeys);
1177   }
1178   
1179   pElement = pRootElement->FirstChildElement("gui");
1180   if (pElement)
1181   {
1182     XMLUtils::GetBoolean(pElement, "visualizedirtyregions", m_guiVisualizeDirtyRegions);
1183     XMLUtils::GetInt(pElement, "algorithmdirtyregions",     m_guiAlgorithmDirtyRegions);
1184     XMLUtils::GetInt(pElement, "nofliptimeout",             m_guiDirtyRegionNoFlipTimeout);
1185   }
1186
1187   // load in the settings overrides
1188   CSettings::Get().Load(pRootElement, true);  // true to hide the settings we read in
1189 }
1190
1191 void CAdvancedSettings::Clear()
1192 {
1193   m_videoCleanStringRegExps.clear();
1194   m_moviesExcludeFromScanRegExps.clear();
1195   m_tvshowExcludeFromScanRegExps.clear();
1196   m_videoExcludeFromListingRegExps.clear();
1197   m_videoStackRegExps.clear();
1198   m_folderStackRegExps.clear();
1199   m_audioExcludeFromScanRegExps.clear();
1200   m_audioExcludeFromListingRegExps.clear();
1201   m_pictureExcludeFromListingRegExps.clear();
1202
1203   m_pictureExtensions.clear();
1204   m_musicExtensions.clear();
1205   m_videoExtensions.clear();
1206   m_discStubExtensions.clear();
1207
1208   m_logFolder.clear();
1209   m_userAgent.clear();
1210 }
1211
1212 void CAdvancedSettings::GetCustomTVRegexps(TiXmlElement *pRootElement, SETTINGS_TVSHOWLIST& settings)
1213 {
1214   TiXmlElement *pElement = pRootElement;
1215   while (pElement)
1216   {
1217     int iAction = 0; // overwrite
1218     // for backward compatibility
1219     const char* szAppend = pElement->Attribute("append");
1220     if ((szAppend && stricmp(szAppend, "yes") == 0))
1221       iAction = 1;
1222     // action takes precedence if both attributes exist
1223     const char* szAction = pElement->Attribute("action");
1224     if (szAction)
1225     {
1226       iAction = 0; // overwrite
1227       if (stricmp(szAction, "append") == 0)
1228         iAction = 1; // append
1229       else if (stricmp(szAction, "prepend") == 0)
1230         iAction = 2; // prepend
1231     }
1232     if (iAction == 0)
1233       settings.clear();
1234     TiXmlNode* pRegExp = pElement->FirstChild("regexp");
1235     int i = 0;
1236     while (pRegExp)
1237     {
1238       if (pRegExp->FirstChild())
1239       {
1240         bool bByDate = false;
1241         int iDefaultSeason = 1;
1242         if (pRegExp->ToElement())
1243         {
1244           CStdString byDate = pRegExp->ToElement()->Attribute("bydate");
1245           if(byDate && stricmp(byDate, "true") == 0)
1246           {
1247             bByDate = true;
1248           }
1249           CStdString defaultSeason = pRegExp->ToElement()->Attribute("defaultseason");
1250           if(!defaultSeason.empty())
1251           {
1252             iDefaultSeason = atoi(defaultSeason.c_str());
1253           }
1254         }
1255         CStdString regExp = pRegExp->FirstChild()->Value();
1256         if (iAction == 2)
1257           settings.insert(settings.begin() + i++, 1, TVShowRegexp(bByDate,regExp,iDefaultSeason));
1258         else
1259           settings.push_back(TVShowRegexp(bByDate,regExp,iDefaultSeason));
1260       }
1261       pRegExp = pRegExp->NextSibling("regexp");
1262     }
1263
1264     pElement = pElement->NextSiblingElement(pRootElement->Value());
1265   }
1266 }
1267
1268 void CAdvancedSettings::GetCustomRegexps(TiXmlElement *pRootElement, CStdStringArray& settings)
1269 {
1270   TiXmlElement *pElement = pRootElement;
1271   while (pElement)
1272   {
1273     int iAction = 0; // overwrite
1274     // for backward compatibility
1275     const char* szAppend = pElement->Attribute("append");
1276     if ((szAppend && stricmp(szAppend, "yes") == 0))
1277       iAction = 1;
1278     // action takes precedence if both attributes exist
1279     const char* szAction = pElement->Attribute("action");
1280     if (szAction)
1281     {
1282       iAction = 0; // overwrite
1283       if (stricmp(szAction, "append") == 0)
1284         iAction = 1; // append
1285       else if (stricmp(szAction, "prepend") == 0)
1286         iAction = 2; // prepend
1287     }
1288     if (iAction == 0)
1289       settings.clear();
1290     TiXmlNode* pRegExp = pElement->FirstChild("regexp");
1291     int i = 0;
1292     while (pRegExp)
1293     {
1294       if (pRegExp->FirstChild())
1295       {
1296         CStdString regExp = pRegExp->FirstChild()->Value();
1297         if (iAction == 2)
1298           settings.insert(settings.begin() + i++, 1, regExp);
1299         else
1300           settings.push_back(regExp);
1301       }
1302       pRegExp = pRegExp->NextSibling("regexp");
1303     }
1304
1305     pElement = pElement->NextSiblingElement(pRootElement->Value());
1306   }
1307 }
1308
1309 void CAdvancedSettings::GetCustomExtensions(TiXmlElement *pRootElement, CStdString& extensions)
1310 {
1311   CStdString extraExtensions;
1312   if (XMLUtils::GetString(pRootElement, "add", extraExtensions) && !extraExtensions.empty())
1313     extensions += "|" + extraExtensions;
1314   if (XMLUtils::GetString(pRootElement, "remove", extraExtensions) && !extraExtensions.empty())
1315   {
1316     CStdStringArray exts;
1317     StringUtils::SplitString(extraExtensions,"|",exts);
1318     for (unsigned int i=0;i<exts.size();++i)
1319     {
1320       size_t iPos = extensions.find(exts[i]);
1321       if (iPos == std::string::npos)
1322         continue;
1323       extensions.erase(iPos,exts[i].size()+1);
1324     }
1325   }
1326 }
1327
1328 void CAdvancedSettings::AddSettingsFile(const CStdString &filename)
1329 {
1330   m_settingsFiles.push_back(filename);
1331 }
1332
1333 float CAdvancedSettings::GetDisplayLatency(float refreshrate)
1334 {
1335   float delay = m_videoDefaultLatency / 1000.0f;
1336   for (int i = 0; i < (int) m_videoRefreshLatency.size(); i++)
1337   {
1338     RefreshVideoLatency& videolatency = m_videoRefreshLatency[i];
1339     if (refreshrate >= videolatency.refreshmin && refreshrate <= videolatency.refreshmax)
1340       delay = videolatency.delay / 1000.0f;
1341   }
1342
1343   return delay; // in seconds
1344 }
1345
1346 void CAdvancedSettings::SetDebugMode(bool debug)
1347 {
1348   if (debug)
1349   {
1350     int level = std::max(m_logLevelHint, LOG_LEVEL_DEBUG_FREEMEM);
1351     m_logLevel = level;
1352     CLog::SetLogLevel(level);
1353     CLog::Log(LOGNOTICE, "Enabled debug logging due to GUI setting. Level %d.", level);
1354   }
1355   else
1356   {
1357     int level = std::min(m_logLevelHint, LOG_LEVEL_DEBUG/*LOG_LEVEL_NORMAL*/);
1358     CLog::Log(LOGNOTICE, "Disabled debug logging due to GUI setting. Level %d.", level);
1359     m_logLevel = level;
1360     CLog::SetLogLevel(level);
1361   }
1362 }
1363
1364 void CAdvancedSettings::SetExtraLogsFromAddon(ADDON::IAddon* addon)
1365 {
1366   m_extraLogLevels = 0;
1367   for (int i=LOGMASKBIT;i<31;++i)
1368   {
1369     CStdString str = StringUtils::Format("bit%i", i-LOGMASKBIT+1);
1370     if (addon->GetSetting(str) == "true")
1371       m_extraLogLevels |= (1 << i);
1372   }
1373   CLog::SetExtraLogLevels(m_extraLogLevels);
1374 }