| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/app/corefactory.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "corefactory.h"cxx . . $ `<file>/src/app/corefactory.h`/ |
| 5 | |
| 6 | #include "common/cryptolayer.h"cxx . . $ `<file>/src/common/cryptolayer.h`/ |
| 7 | #include "config.h"cxx . . $ `<file>/build/src/config.h`/ |
| 8 | #include "core/ccpro/ccproparser.h"cxx . . $ `<file>/src/core/ccpro/ccproparser.h`/ |
| 9 | #include "core/components/controls/cpucontrolprovider.h"cxx . . $ `<file>/src/core/components/controls/cpucontrolprovider.h`/ |
| 10 | #include "core/components/controls/gpucontrolprovider.h"cxx . . $ `<file>/src/core/components/controls/gpucontrolprovider.h`/ |
| 11 | #include "core/components/sensors/cpusensorprovider.h"cxx . . $ `<file>/src/core/components/sensors/cpusensorprovider.h`/ |
| 12 | #include "core/components/sensors/gpusensorprovider.h"cxx . . $ `<file>/src/core/components/sensors/gpusensorprovider.h`/ |
| 13 | #include "core/filecache.h"cxx . . $ `<file>/src/core/filecache.h`/ |
| 14 | #include "core/info/hwiddatasource.h"cxx . . $ `<file>/src/core/info/hwiddatasource.h`/ |
| 15 | #include "core/info/hwidtranslator.h"cxx . . $ `<file>/src/core/info/hwidtranslator.h`/ |
| 16 | #include "core/info/infoproviderregistry.h"cxx . . $ `<file>/src/core/info/infoproviderregistry.h`/ |
| 17 | #include "core/info/swinfo.h"cxx . . $ `<file>/src/core/info/swinfo.h`/ |
| 18 | #include "core/iprofileparser.h"cxx . . $ `<file>/src/core/iprofileparser.h`/ |
| 19 | #include "core/profile.h"cxx . . $ `<file>/src/core/profile.h`/ |
| 20 | #include "core/profilefactory.h"cxx . . $ `<file>/src/core/profilefactory.h`/ |
| 21 | #include "core/profileiconcache.h"cxx . . $ `<file>/src/core/profileiconcache.h`/ |
| 22 | #include "core/profilemanager.h"cxx . . $ `<file>/src/core/profilemanager.h`/ |
| 23 | #include "core/profilepartprovider.h"cxx . . $ `<file>/src/core/profilepartprovider.h`/ |
| 24 | #include "core/profilepartxmlparserprovider.h"cxx . . $ `<file>/src/core/profilepartxmlparserprovider.h`/ |
| 25 | #include "core/profilestorage.h"cxx . . $ `<file>/src/core/profilestorage.h`/ |
| 26 | #include "core/profileviewfactory.h"cxx . . $ `<file>/src/core/profileviewfactory.h`/ |
| 27 | #include "core/profilexmlparserfactory.h"cxx . . $ `<file>/src/core/profilexmlparserfactory.h`/ |
| 28 | #include "core/qmlcomponentfactory.h"cxx . . $ `<file>/src/core/qmlcomponentfactory.h`/ |
| 29 | #include "core/qmlcomponentregistry.h"cxx . . $ `<file>/src/core/qmlcomponentregistry.h`/ |
| 30 | #include "core/session.h"cxx . . $ `<file>/src/core/session.h`/ |
| 31 | #include "core/sysexplorer.h"cxx . . $ `<file>/src/core/sysexplorer.h`/ |
| 32 | #include "core/sysmodelfactory.h"cxx . . $ `<file>/src/core/sysmodelfactory.h`/ |
| 33 | #include "core/sysmodelsyncer.h"cxx . . $ `<file>/src/core/sysmodelsyncer.h`/ |
| 34 | #include "core/uifactory.h"cxx . . $ `<file>/src/core/uifactory.h`/ |
| 35 | #include "helper/helpercontrol.h"cxx . . $ `<file>/src/helper/helpercontrol.h`/ |
| 36 | #include "helper/helpermonitor.h"cxx . . $ `<file>/src/helper/helpermonitor.h`/ |
| 37 | #include "helper/helpersysctl.h"cxx . . $ `<file>/src/helper/helpersysctl.h`/ |
| 38 | #include <QStandardPaths> |
| 39 | #include <algorithm> |
| 40 | #include <cctype> |
| 41 | #include <exception> |
| 42 | #include <format> |
| 43 | #include <spdlog/spdlog.h> |
| 44 | #include <system_error> |
| 45 | #include <utility> |
| 46 | |
| 47 | namespace fs = stdcxx . . $ std/::filesystem; |
| 48 | |
| 49 | CoreFactorycxx . . $ CoreFactory#::CoreFactorycxx . . $ CoreFactory#CoreFactory(ced63f7c635d850d).() noexcept |
| 50 | : gpuVendors_cxx . . $ CoreFactory#gpuVendors_.{Vendorcxx . . $ Vendor#::AMDcxx . . $ Vendor#AMD.} |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<CoreFactorycxx . . $ CoreFactory#::Componentscxx . . $ CoreFactory#Components#> |
| 55 | CoreFactorycxx . . $ CoreFactory#::buildcxx . . $ CoreFactory#build(46e3a3b3538ceca6).(stdcxx . . $ std/::stringcxx . . $ std/string# &&appName, bool logCommands, |
| 56 | bool logProfileStack) const |
| 57 | { |
| 58 | try { |
| 59 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(appName.cbegincxx . . $ std/__cxx11/basic_string#cbegin(a865d278ca20c908).(), appName.cendcxx . . $ std/__cxx11/basic_string#cend(a865d278ca20c908).(), appName.begincxx . . $ std/__cxx11/basic_string#begin(fd29ebd65481b919).(), ::tolower); |
| 60 | |
| 61 | auto [config, cache] = standardDirectoriescxx . . $ CoreFactory#standardDirectories(e6555fd3cf7e0cb3).(); |
| 62 | createAppDirectoriescxx . . $ CoreFactory#createAppDirectories(9659f018b5074159).(appName, config, cache); |
| 63 | |
| 64 | auto cryptoLayer = stdcxx . . $ std/::make_sharedcxx . . $ std/make_shared(25752750ef11e821).<CryptoLayercxx . . $ CryptoLayer#>(); |
| 65 | auto helperControl = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<HelperControlcxx . . $ HelperControl#>(cryptoLayer); |
| 66 | |
| 67 | InfoProviderRegistrycxx . . $ InfoProviderRegistry# infoProviderRegistry; |
| 68 | auto swInfo = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<SWInfocxx . . $ SWInfo#>(); |
| 69 | swInfo->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).initializecxx . . $ SWInfo#initialize(97df72f1a8cecba1).(infoProviderRegistry.swInfoProviderscxx . . $ InfoProviderRegistry#swInfoProviders(86edd47c1472bca7).()); |
| 70 | |
| 71 | SysModelFactorycxx . . $ SysModelFactory# sysModelFactorycxx . . $ SysModelFactory#SysModelFactory(8f8ae85d037b43a3).( |
| 72 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::movecxx . . $ std/move(e35c19a1ba7baa26).(swInfo), stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<SysExplorercxx . . $ SysExplorer#>(gpuVendors_cxx . . $ CoreFactory#gpuVendors_.), |
| 73 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<HWIDTranslatorcxx . . $ HWIDTranslator#>( |
| 74 | gpuVendors_cxx . . $ CoreFactory#gpuVendors_., stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<HWIDDataSourcecxx . . $ HWIDDataSource#>(PCI_IDS_PATHcxx . . $ `build/src/config.h:9:9`!)), |
| 75 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<CPUControlProvidercxx . . $ CPUControlProvider#>(), |
| 76 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<CPUSensorProvidercxx . . $ CPUSensorProvider#>(), |
| 77 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<GPUControlProvidercxx . . $ GPUControlProvider#>(), |
| 78 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<GPUSensorProvidercxx . . $ GPUSensorProvider#>(), infoProviderRegistry, |
| 79 | infoProviderRegistry); |
| 80 | auto sysModel = sysModelFactory.buildcxx . . $ SysModelFactory#build(72b1c0099a8a0571).(); |
| 81 | |
| 82 | ProfileFactorycxx . . $ ProfileFactory# profileFactorycxx . . $ ProfileFactory#ProfileFactory(696c0b23b3ffb078).(stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ProfilePartProvidercxx . . $ ProfilePartProvider#>()); |
| 83 | auto defaultProfile = profileFactory.buildcxx . . $ ProfileFactory#build(ac9d7090b47d2396).(*cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).sysModel); |
| 84 | ProfileXMLParserFactorycxx . . $ ProfileXMLParserFactory# parserFactorycxx . . $ ProfileXMLParserFactory#ProfileXMLParserFactory(26b51e92cc85cdc9).( |
| 85 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ProfilePartXMLParserProvidercxx . . $ ProfilePartXMLParserProvider#>()); |
| 86 | auto profileParser = parserFactory.buildcxx . . $ ProfileXMLParserFactory#build(953943449e453a2b).(*cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).defaultProfile); |
| 87 | auto profileFileParser = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<CCPROParsercxx . . $ CCPROParser#>(); |
| 88 | auto iconCache = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ProfileIconCachecxx . . $ ProfileIconCache#>( |
| 89 | stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<FileCachecxx . . $ FileCache#>(cache /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). "icons"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).)); |
| 90 | auto profileManager = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ProfileManagercxx . . $ ProfileManager#>( |
| 91 | stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(defaultProfile), |
| 92 | stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ProfileStoragecxx . . $ ProfileStorage#>( |
| 93 | config /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). appNamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d). /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). "profiles"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(profileParser), |
| 94 | stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(profileFileParser), stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(iconCache))); |
| 95 | |
| 96 | auto sysModelSyncer = stdcxx . . $ std/::make_sharedcxx . . $ std/make_shared(25752750ef11e821).<SysModelSyncercxx . . $ SysModelSyncer#>( |
| 97 | stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sysModel), |
| 98 | stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<HelperSysCtlcxx . . $ HelperSysCtl#>(cryptoLayer, logCommands)); |
| 99 | |
| 100 | auto session = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<Sessioncxx . . $ Session#>( |
| 101 | sysModelSyncer, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(profileManager), |
| 102 | stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ProfileViewFactorycxx . . $ ProfileViewFactory#>(), |
| 103 | stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<HelperMonitorcxx . . $ HelperMonitor#>(cryptoLayer), logProfileStack); |
| 104 | auto uiFactory = |
| 105 | stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<UIFactorycxx . . $ UIFactory#>(stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<QMLComponentFactorycxx . . $ QMLComponentFactory#>( |
| 106 | stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<QMLComponentRegistrycxx . . $ QMLComponentRegistry#>())); |
| 107 | |
| 108 | return Componentscxx . . $ std/optional#optional(e3f0d6382bd52f24).{stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(helperControl), stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sysModelSyncer), |
| 109 | stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(session), stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(uiFactory)}; |
| 110 | } |
| 111 | catch (stdcxx . . $ std/::exception const &e) { |
| 112 | SPDLOG_WARNcxx . . $ `<external>/13613935168682455490/spdlog.h:329:13`!("Cannot create core components"); |
| 113 | SPDLOG_WARNcxx . . $ `<external>/13613935168682455490/spdlog.h:329:13`!(e.what()); |
| 114 | } |
| 115 | |
| 116 | return {cxx . . $ std/optional#optional(ced63f7c635d850d).}; |
| 117 | } |
| 118 | |
| 119 | stdcxx . . $ std/::tuplecxx . . $ std/tuple#<stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#, stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#> |
| 120 | CoreFactorycxx . . $ CoreFactory#::standardDirectoriescxx . . $ CoreFactory#standardDirectories(e6555fd3cf7e0cb3).() const |
| 121 | { |
| 122 | return {cxx . . $ std/tuple#tuple(7b0701f99332c8a8).QStandardPathscxx . . $ QStandardPaths#::standardLocationscxx . . $ QStandardPaths#standardLocations(e4a33913b0362450).(QStandardPathscxx . . $ QStandardPaths#::ConfigLocationcxx . . $ QStandardPaths#ConfigLocation.) |
| 123 | .firstcxx . . $ QList#first(19b2b6f17af048b).() |
| 124 | .toStdStringcxx . . $ QString#toStdString(219584694fe2b248).(), |
| 125 | QStandardPathscxx . . $ QStandardPaths#::standardLocationscxx . . $ QStandardPaths#standardLocations(e4a33913b0362450).(QStandardPathscxx . . $ QStandardPaths#::CacheLocationcxx . . $ QStandardPaths#CacheLocation.) |
| 126 | .firstcxx . . $ QList#first(19b2b6f17af048b).() |
| 127 | .toStdStringcxx . . $ QString#toStdString(219584694fe2b248).()}; |
| 128 | } |
| 129 | |
| 130 | void CoreFactorycxx . . $ CoreFactory#::createAppDirectoriescxx . . $ CoreFactory#createAppDirectories(9659f018b5074159).(stdcxx . . $ std/::stringcxx . . $ std/string# const &appDirectory, |
| 131 | stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const &config, |
| 132 | stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const &cache) const |
| 133 | { |
| 134 | stdcxx . . $ std/::error_codecxx . . $ std/error_code# eccxx . . $ std/error_code#error_code(ced63f7c635d850d).; |
| 135 | fs::permscxx . . $ std/filesystem/perms# dirPerms = fs::permscxx . . $ std/filesystem/perms#::owner_allcxx . . $ std/filesystem/perms#owner_all. |cxx . . $ std/filesystem/`operator|`(a75dd80e7ac4ad25). fs::permscxx . . $ std/filesystem/perms#::group_readcxx . . $ std/filesystem/perms#group_read. |cxx . . $ std/filesystem/`operator|`(a75dd80e7ac4ad25). |
| 136 | fs::permscxx . . $ std/filesystem/perms#::group_execcxx . . $ std/filesystem/perms#group_exec. |cxx . . $ std/filesystem/`operator|`(a75dd80e7ac4ad25). fs::permscxx . . $ std/filesystem/perms#::others_readcxx . . $ std/filesystem/perms#others_read. |cxx . . $ std/filesystem/`operator|`(a75dd80e7ac4ad25). |
| 137 | fs::permscxx . . $ std/filesystem/perms#::others_execcxx . . $ std/filesystem/perms#others_exec.; |
| 138 | |
| 139 | if (!fs::existscxx . . $ std/filesystem/exists(c53a6ef3278968b1).(config)) { |
| 140 | fs::create_directorycxx . . $ std/filesystem/create_directory(c53a6ef3278968b1).(config); |
| 141 | fs::permissionscxx . . $ std/filesystem/permissions(3dd45985f22e04a8).(config, dirPerms, ec); |
| 142 | if (ec.valuecxx . . $ std/error_code#value(ea6fe5115c70a13f).() != 0) |
| 143 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot set permissions for {}", config.c_str()); |
| 144 | } |
| 145 | |
| 146 | if (!fs::is_directorycxx . . $ std/filesystem/is_directory(c53a6ef3278968b1).(config)) |
| 147 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#( |
| 148 | stdcxx . . $ std/::formatcxx . . $ std/format(7a9e6f4918cdc192).("{} is not a directory"cxx . . $ std/basic_format_string#basic_format_string(edcd8b2679e9bd1a)., config.c_strcxx . . $ std/filesystem/__cxx11/path#c_str(ba32b354807b2b81).())); |
| 149 | |
| 150 | fs::pathcxx . . $ std/filesystem/__cxx11/path# appConfigDir = config /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). appDirectorycxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).; |
| 151 | if (!fs::existscxx . . $ std/filesystem/exists(c53a6ef3278968b1).(appConfigDir)) { |
| 152 | fs::create_directorycxx . . $ std/filesystem/create_directory(c53a6ef3278968b1).(appConfigDir); |
| 153 | fs::permissionscxx . . $ std/filesystem/permissions(3dd45985f22e04a8).(appConfigDir, dirPerms, ec); |
| 154 | if (ec.valuecxx . . $ std/error_code#value(ea6fe5115c70a13f).() != 0) |
| 155 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot set permissions for {}", appConfigDir.c_str()); |
| 156 | } |
| 157 | |
| 158 | if (!fs::is_directorycxx . . $ std/filesystem/is_directory(c53a6ef3278968b1).(appConfigDir)) |
| 159 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#( |
| 160 | stdcxx . . $ std/::formatcxx . . $ std/format(7a9e6f4918cdc192).("{} is not a directory"cxx . . $ std/basic_format_string#basic_format_string(edcd8b2679e9bd1a)., appConfigDir.c_strcxx . . $ std/filesystem/__cxx11/path#c_str(ba32b354807b2b81).())); |
| 161 | |
| 162 | if (!fs::existscxx . . $ std/filesystem/exists(c53a6ef3278968b1).(cache)) { |
| 163 | fs::create_directorycxx . . $ std/filesystem/create_directory(c53a6ef3278968b1).(cache); |
| 164 | fs::permissionscxx . . $ std/filesystem/permissions(3dd45985f22e04a8).(cache, dirPerms, ec); |
| 165 | if (ec.valuecxx . . $ std/error_code#value(ea6fe5115c70a13f).() != 0) |
| 166 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot set permissions for {}", cache.c_str()); |
| 167 | } |
| 168 | |
| 169 | if (!fs::is_directorycxx . . $ std/filesystem/is_directory(c53a6ef3278968b1).(cache)) |
| 170 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#(stdcxx . . $ std/::formatcxx . . $ std/format(7a9e6f4918cdc192).("{} is not a directory"cxx . . $ std/basic_format_string#basic_format_string(edcd8b2679e9bd1a)., cache.c_strcxx . . $ std/filesystem/__cxx11/path#c_str(ba32b354807b2b81).())); |
| 171 | } |