[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / settings / SettingConditions.cpp
blob1f11a4995eef0817816b1f538e9b86078af49d24
1 /*
2 * Copyright (C) 2013-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "SettingConditions.h"
11 #include "LockType.h"
12 #include "addons/AddonManager.h"
13 #include "addons/Skin.h"
14 #include "addons/addoninfo/AddonType.h"
15 #include "application/AppParams.h"
16 #include "cores/AudioEngine/Engines/ActiveAE/ActiveAESettings.h"
17 #include "ServiceBroker.h"
18 #include "GUIPassword.h"
19 #if defined(HAS_WEB_SERVER)
20 #include "network/WebServer.h"
21 #endif
22 #include "peripherals/Peripherals.h"
23 #include "profiles/ProfileManager.h"
24 #include "settings/SettingAddon.h"
25 #include "settings/SettingsComponent.h"
26 #include "utils/FontUtils.h"
27 #include "utils/StringUtils.h"
28 #include "windowing/WinSystem.h"
30 namespace
32 bool AddonHasSettings(const std::string& condition,
33 const std::string& value,
34 const SettingConstPtr& setting,
35 void* data)
37 if (setting == NULL)
38 return false;
40 std::shared_ptr<const CSettingAddon> settingAddon = std::dynamic_pointer_cast<const CSettingAddon>(setting);
41 if (settingAddon == NULL)
42 return false;
44 ADDON::AddonPtr addon;
45 if (!CServiceBroker::GetAddonMgr().GetAddon(settingAddon->GetValue(), addon,
46 settingAddon->GetAddonType(),
47 ADDON::OnlyEnabled::CHOICE_YES) ||
48 addon == NULL)
49 return false;
51 if (addon->Type() == ADDON::AddonType::SKIN)
52 return ((ADDON::CSkinInfo*)addon.get())->HasSkinFile("SkinSettings.xml");
54 return addon->CanHaveAddonOrInstanceSettings();
57 bool CheckMasterLock(const std::string& condition,
58 const std::string& value,
59 const SettingConstPtr& setting,
60 void* data)
62 return g_passwordManager.IsMasterLockUnlocked(StringUtils::EqualsNoCase(value, "true"));
65 bool HasPeripherals(const std::string& condition,
66 const std::string& value,
67 const SettingConstPtr& setting,
68 void* data)
70 return CServiceBroker::GetPeripherals().GetNumberOfPeripherals() > 0;
73 bool HasPeripheralLibraries(const std::string& condition,
74 const std::string& value,
75 const SettingConstPtr& setting,
76 void* data)
78 return CServiceBroker::GetAddonMgr().HasInstalledAddons(ADDON::AddonType::PERIPHERALDLL);
81 bool HasRumbleFeature(const std::string& condition,
82 const std::string& value,
83 const SettingConstPtr& setting,
84 void* data)
86 return CServiceBroker::GetPeripherals().SupportsFeature(PERIPHERALS::FEATURE_RUMBLE);
89 bool HasRumbleController(const std::string& condition,
90 const std::string& value,
91 const SettingConstPtr& setting,
92 void* data)
94 return CServiceBroker::GetPeripherals().HasPeripheralWithFeature(PERIPHERALS::FEATURE_RUMBLE);
97 bool HasPowerOffFeature(const std::string& condition,
98 const std::string& value,
99 const SettingConstPtr& setting,
100 void* data)
102 return CServiceBroker::GetPeripherals().SupportsFeature(PERIPHERALS::FEATURE_POWER_OFF);
105 bool HasSystemSdrPeakLuminance(const std::string& condition,
106 const std::string& value,
107 const SettingConstPtr& setting,
108 void* data)
110 return CServiceBroker::GetWinSystem()->HasSystemSdrPeakLuminance();
113 bool SupportsVideoSuperResolution(const std::string& condition,
114 const std::string& value,
115 const SettingConstPtr& setting,
116 void* data)
118 return CServiceBroker::GetWinSystem()->SupportsVideoSuperResolution();
121 bool SupportsDolbyVision(const std::string& condition,
122 const std::string& value,
123 const SettingConstPtr& setting,
124 void* data)
126 return CServiceBroker::GetWinSystem()->GetDisplayHDRCapabilities().SupportsDolbyVision();
129 bool SupportsScreenMove(const std::string& condition,
130 const std::string& value,
131 const SettingConstPtr& setting,
132 void* data)
134 return CServiceBroker::GetWinSystem()->SupportsScreenMove();
137 bool IsHDRDisplay(const std::string& condition,
138 const std::string& value,
139 const SettingConstPtr& setting,
140 void* data)
142 return CServiceBroker::GetWinSystem()->IsHDRDisplay();
145 bool IsMasterUser(const std::string& condition,
146 const std::string& value,
147 const SettingConstPtr& setting,
148 void* data)
150 return g_passwordManager.bMasterUser;
153 bool HasSubtitlesFontExtensions(const std::string& condition,
154 const std::string& value,
155 const SettingConstPtr& setting,
156 void* data)
158 auto settingStr = std::dynamic_pointer_cast<const CSettingString>(setting);
159 if (!settingStr)
160 return false;
162 return UTILS::FONT::IsSupportedFontExtension(settingStr->GetValue());
165 bool ProfileCanWriteDatabase(const std::string& condition,
166 const std::string& value,
167 const SettingConstPtr& setting,
168 void* data)
170 return CSettingConditions::GetCurrentProfile().canWriteDatabases();
173 bool ProfileCanWriteSources(const std::string& condition,
174 const std::string& value,
175 const SettingConstPtr& setting,
176 void* data)
178 return CSettingConditions::GetCurrentProfile().canWriteSources();
181 bool ProfileHasAddons(const std::string& condition,
182 const std::string& value,
183 const SettingConstPtr& setting,
184 void* data)
186 return CSettingConditions::GetCurrentProfile().hasAddons();
189 bool ProfileHasDatabase(const std::string& condition,
190 const std::string& value,
191 const SettingConstPtr& setting,
192 void* data)
194 return CSettingConditions::GetCurrentProfile().hasDatabases();
197 bool ProfileHasSources(const std::string& condition,
198 const std::string& value,
199 const SettingConstPtr& setting,
200 void* data)
202 return CSettingConditions::GetCurrentProfile().hasSources();
205 bool ProfileHasAddonManagerLocked(const std::string& condition,
206 const std::string& value,
207 const SettingConstPtr& setting,
208 void* data)
210 return CSettingConditions::GetCurrentProfile().addonmanagerLocked();
213 bool ProfileHasFilesLocked(const std::string& condition,
214 const std::string& value,
215 const SettingConstPtr& setting,
216 void* data)
218 return CSettingConditions::GetCurrentProfile().filesLocked();
221 bool ProfileHasMusicLocked(const std::string& condition,
222 const std::string& value,
223 const SettingConstPtr& setting,
224 void* data)
226 return CSettingConditions::GetCurrentProfile().musicLocked();
229 bool ProfileHasPicturesLocked(const std::string& condition,
230 const std::string& value,
231 const SettingConstPtr& setting,
232 void* data)
234 return CSettingConditions::GetCurrentProfile().picturesLocked();
237 bool ProfileHasProgramsLocked(const std::string& condition,
238 const std::string& value,
239 const SettingConstPtr& setting,
240 void* data)
242 return CSettingConditions::GetCurrentProfile().programsLocked();
245 bool ProfileHasSettingsLocked(const std::string& condition,
246 const std::string& value,
247 const SettingConstPtr& setting,
248 void* data)
250 LOCK_LEVEL::SETTINGS_LOCK slValue=LOCK_LEVEL::ALL;
251 if (StringUtils::EqualsNoCase(value, "none"))
252 slValue = LOCK_LEVEL::NONE;
253 else if (StringUtils::EqualsNoCase(value, "standard"))
254 slValue = LOCK_LEVEL::STANDARD;
255 else if (StringUtils::EqualsNoCase(value, "advanced"))
256 slValue = LOCK_LEVEL::ADVANCED;
257 else if (StringUtils::EqualsNoCase(value, "expert"))
258 slValue = LOCK_LEVEL::EXPERT;
259 return slValue <= CSettingConditions::GetCurrentProfile().settingsLockLevel();
262 bool ProfileHasVideosLocked(const std::string& condition,
263 const std::string& value,
264 const SettingConstPtr& setting,
265 void* data)
267 return CSettingConditions::GetCurrentProfile().videoLocked();
270 bool ProfileLockMode(const std::string& condition,
271 const std::string& value,
272 const SettingConstPtr& setting,
273 void* data)
275 char* tmp = nullptr;
276 LockType lock = (LockType)strtol(value.c_str(), &tmp, 0);
277 if (tmp != NULL && *tmp != '\0')
278 return false;
280 return CSettingConditions::GetCurrentProfile().getLockMode() == lock;
283 bool GreaterThan(const std::string& condition,
284 const std::string& value,
285 const SettingConstPtr& setting,
286 void* data)
288 if (setting == NULL)
289 return false;
291 std::shared_ptr<const CSettingInt> settingInt = std::dynamic_pointer_cast<const CSettingInt>(setting);
292 if (settingInt == NULL)
293 return false;
295 char* tmp = nullptr;
297 int lhs = settingInt->GetValue();
298 int rhs = StringUtils::IsInteger(value) ? (int)strtol(value.c_str(), &tmp, 0) : 0;
300 return lhs > rhs;
303 bool GreaterThanOrEqual(const std::string& condition,
304 const std::string& value,
305 const SettingConstPtr& setting,
306 void* data)
308 if (setting == NULL)
309 return false;
311 std::shared_ptr<const CSettingInt> settingInt = std::dynamic_pointer_cast<const CSettingInt>(setting);
312 if (settingInt == NULL)
313 return false;
315 char* tmp = nullptr;
317 int lhs = settingInt->GetValue();
318 int rhs = StringUtils::IsInteger(value) ? (int)strtol(value.c_str(), &tmp, 0) : 0;
320 return lhs >= rhs;
323 bool LessThan(const std::string& condition,
324 const std::string& value,
325 const SettingConstPtr& setting,
326 void* data)
328 if (setting == NULL)
329 return false;
331 std::shared_ptr<const CSettingInt> settingInt = std::dynamic_pointer_cast<const CSettingInt>(setting);
332 if (settingInt == NULL)
333 return false;
335 char* tmp = nullptr;
337 int lhs = settingInt->GetValue();
338 int rhs = StringUtils::IsInteger(value) ? (int)strtol(value.c_str(), &tmp, 0) : 0;
340 return lhs < rhs;
343 bool LessThanOrEqual(const std::string& condition,
344 const std::string& value,
345 const SettingConstPtr& setting,
346 void* data)
348 if (setting == NULL)
349 return false;
351 std::shared_ptr<const CSettingInt> settingInt = std::dynamic_pointer_cast<const CSettingInt>(setting);
352 if (settingInt == NULL)
353 return false;
355 char* tmp = nullptr;
357 int lhs = settingInt->GetValue();
358 int rhs = StringUtils::IsInteger(value) ? (int)strtol(value.c_str(), &tmp, 0) : 0;
360 return lhs <= rhs;
362 }; // anonymous namespace
364 const CProfileManager* CSettingConditions::m_profileManager = nullptr;
365 std::set<std::string> CSettingConditions::m_simpleConditions;
366 std::map<std::string, SettingConditionCheck> CSettingConditions::m_complexConditions;
368 void CSettingConditions::Initialize()
370 if (!m_simpleConditions.empty())
371 return;
373 // add simple conditions
374 m_simpleConditions.emplace("true");
375 #ifdef HAS_UPNP
376 m_simpleConditions.emplace("has_upnp");
377 #endif
378 #ifdef HAS_AIRPLAY
379 m_simpleConditions.emplace("has_airplay");
380 #endif
381 #ifdef HAVE_X11
382 m_simpleConditions.emplace("have_x11");
383 #endif
384 #ifdef HAVE_WAYLAND
385 m_simpleConditions.emplace("have_wayland");
386 #endif
387 #ifdef HAS_GL
388 m_simpleConditions.emplace("has_gl");
389 #endif
390 #ifdef HAS_GLES
391 m_simpleConditions.emplace("has_gles");
392 #endif
393 #if HAS_GLES >= 2
394 m_simpleConditions.emplace("has_glesv2");
395 #endif
396 #ifdef HAS_TIME_SERVER
397 m_simpleConditions.emplace("has_time_server");
398 #endif
399 #ifdef HAS_WEB_SERVER
400 m_simpleConditions.emplace("has_web_server");
401 #endif
402 #ifdef HAS_FILESYSTEM_SMB
403 m_simpleConditions.emplace("has_filesystem_smb");
404 #endif
405 #ifdef HAS_FILESYSTEM_NFS
406 m_simpleConditions.insert("has_filesystem_nfs");
407 #endif
408 #ifdef HAS_ZEROCONF
409 m_simpleConditions.emplace("has_zeroconf");
410 #endif
411 #ifdef HAVE_LIBVA
412 m_simpleConditions.emplace("have_libva");
413 #endif
414 #ifdef HAVE_LIBVDPAU
415 m_simpleConditions.emplace("have_libvdpau");
416 #endif
417 #ifdef TARGET_ANDROID
418 m_simpleConditions.emplace("has_mediacodec");
419 #endif
420 #ifdef TARGET_DARWIN
421 m_simpleConditions.emplace("HasVTB");
422 #endif
423 #ifdef TARGET_DARWIN_OSX
424 m_simpleConditions.emplace("have_osx");
425 #endif
426 #ifdef TARGET_DARWIN_IOS
427 m_simpleConditions.emplace("have_ios");
428 #endif
429 #ifdef TARGET_DARWIN_TVOS
430 m_simpleConditions.emplace("have_tvos");
431 #endif
432 #if defined(TARGET_WINDOWS)
433 m_simpleConditions.emplace("has_dx");
434 m_simpleConditions.emplace("hasdxva2");
435 #endif
436 #if defined(TARGET_WEBOS)
437 m_simpleConditions.emplace("have_webos");
438 #endif
440 #ifdef HAVE_LCMS2
441 m_simpleConditions.emplace("have_lcms2");
442 #endif
444 #ifdef TARGET_ANDROID
445 m_simpleConditions.emplace("isstandalone");
446 #else
447 if (CServiceBroker::GetAppParams()->IsStandAlone())
448 m_simpleConditions.emplace("isstandalone");
449 #endif
451 m_simpleConditions.emplace("has_ae_quality_levels");
453 #ifdef HAS_WEB_SERVER
454 if (CWebServer::WebServerSupportsSSL())
455 m_simpleConditions.emplace("webserver_has_ssl");
456 #endif
458 #ifdef HAVE_LIBBLURAY
459 m_simpleConditions.emplace("have_libbluray");
460 #endif
462 #ifdef HAS_CDDA_RIPPER
463 m_simpleConditions.emplace("has_cdda_ripper");
464 #endif
466 #ifdef HAS_OPTICAL_DRIVE
467 m_simpleConditions.emplace("has_optical_drive");
468 #endif
470 #ifdef HAS_XBMCHELPER
471 m_simpleConditions.emplace("has_xbmchelper");
472 #endif
474 // add complex conditions
475 m_complexConditions.emplace("addonhassettings", AddonHasSettings);
476 m_complexConditions.emplace("checkmasterlock", CheckMasterLock);
477 m_complexConditions.emplace("hasperipherals", HasPeripherals);
478 m_complexConditions.emplace("hasperipherallibraries", HasPeripheralLibraries);
479 m_complexConditions.emplace("hasrumblefeature", HasRumbleFeature);
480 m_complexConditions.emplace("hasrumblecontroller", HasRumbleController);
481 m_complexConditions.emplace("haspowerofffeature", HasPowerOffFeature);
482 m_complexConditions.emplace("hassystemsdrpeakluminance", HasSystemSdrPeakLuminance);
483 m_complexConditions.emplace("supportsscreenmove", SupportsScreenMove);
484 m_complexConditions.emplace("supportsvideosuperresolution", SupportsVideoSuperResolution);
485 m_complexConditions.emplace("supportsdolbyvision", SupportsDolbyVision);
486 m_complexConditions.emplace("ishdrdisplay", IsHDRDisplay);
487 m_complexConditions.emplace("ismasteruser", IsMasterUser);
488 m_complexConditions.emplace("hassubtitlesfontextensions", HasSubtitlesFontExtensions);
489 m_complexConditions.emplace("profilecanwritedatabase", ProfileCanWriteDatabase);
490 m_complexConditions.emplace("profilecanwritesources", ProfileCanWriteSources);
491 m_complexConditions.emplace("profilehasaddons", ProfileHasAddons);
492 m_complexConditions.emplace("profilehasdatabase", ProfileHasDatabase);
493 m_complexConditions.emplace("profilehassources", ProfileHasSources);
494 m_complexConditions.emplace("profilehasaddonmanagerlocked", ProfileHasAddonManagerLocked);
495 m_complexConditions.emplace("profilehasfileslocked", ProfileHasFilesLocked);
496 m_complexConditions.emplace("profilehasmusiclocked", ProfileHasMusicLocked);
497 m_complexConditions.emplace("profilehaspictureslocked", ProfileHasPicturesLocked);
498 m_complexConditions.emplace("profilehasprogramslocked", ProfileHasProgramsLocked);
499 m_complexConditions.emplace("profilehassettingslocked", ProfileHasSettingsLocked);
500 m_complexConditions.emplace("profilehasvideoslocked", ProfileHasVideosLocked);
501 m_complexConditions.emplace("profilelockmode", ProfileLockMode);
502 m_complexConditions.emplace("aesettingvisible", ActiveAE::CActiveAESettings::IsSettingVisible);
503 m_complexConditions.emplace("gt", GreaterThan);
504 m_complexConditions.emplace("gte", GreaterThanOrEqual);
505 m_complexConditions.emplace("lt", LessThan);
506 m_complexConditions.emplace("lte", LessThanOrEqual);
509 void CSettingConditions::Deinitialize()
511 m_profileManager = nullptr;
514 const CProfile& CSettingConditions::GetCurrentProfile()
516 if (!m_profileManager)
517 m_profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager().get();
519 if (m_profileManager)
520 return m_profileManager->GetCurrentProfile();
522 static CProfile emptyProfile;
523 return emptyProfile;
526 bool CSettingConditions::Check(const std::string& condition,
527 const std::string& value /* = "" */,
528 const SettingConstPtr& setting /* = NULL */)
530 if (m_simpleConditions.find(condition) != m_simpleConditions.end())
531 return true;
533 std::map<std::string, SettingConditionCheck>::const_iterator itCondition = m_complexConditions.find(condition);
534 if (itCondition != m_complexConditions.end())
535 return itCondition->second(condition, value, setting, NULL);
537 return Check(condition);