From 38292de68a707eeaa2e5ece5a16084c00f8e4bef Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Wed, 18 Sep 2019 13:37:20 +0300 Subject: BareMetal: Fix auto detection of SDCC toolchain on Windows The SDCC toolchain package can be provided as 32-bit or as 64-bit installer. If the SDCC 64-bit package will be installed on the 32-bit Windows, then it will not be found in the system registry, because we use the QSettings::NativeFormat. So, we need to check the data for the 32-bit and 64-bit registry sequentially. Change-Id: I1e7711bdde173eff21a7ba84f221d505a21709ca Reviewed-by: Christian Kandeler --- src/plugins/baremetal/sdcctoolchain.cpp | 48 +++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/src/plugins/baremetal/sdcctoolchain.cpp b/src/plugins/baremetal/sdcctoolchain.cpp index b839a68fe8..a292a575d9 100644 --- a/src/plugins/baremetal/sdcctoolchain.cpp +++ b/src/plugins/baremetal/sdcctoolchain.cpp @@ -395,27 +395,41 @@ QList SdccToolChainFactory::autoDetect(const QList &al if (Utils::HostOsInfo::isWindowsHost()) { -#ifdef Q_OS_WIN64 - static const char kRegistryNode[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\SDCC"; -#else - static const char kRegistryNode[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\SDCC"; -#endif - - QSettings registry(kRegistryNode, QSettings::NativeFormat); - QString compilerPath = registry.value("Default").toString(); - if (!compilerPath.isEmpty()) { + // Tries to detect the candidate from the 32-bit + // or 64-bit system registry format. + auto probeCandidate = [](QSettings::Format format) { + QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\SDCC", + format); + QString compilerPath = registry.value("Default").toString(); + if (compilerPath.isEmpty()) + return Candidate{}; // Build full compiler path. compilerPath += "\\bin\\sdcc.exe"; const FilePath fn = FilePath::fromString( QFileInfo(compilerPath).absoluteFilePath()); - if (compilerExists(fn)) { - // Build compiler version. - const QString version = QString("%1.%2.%3").arg( - registry.value("VersionMajor").toString(), - registry.value("VersionMinor").toString(), - registry.value("VersionRevision").toString()); - candidates.push_back({fn, version}); - } + if (!compilerExists(fn)) + return Candidate{}; + // Build compiler version. + const QString version = QString("%1.%2.%3").arg( + registry.value("VersionMajor").toString(), + registry.value("VersionMinor").toString(), + registry.value("VersionRevision").toString()); + return Candidate{fn, version}; + }; + + const QSettings::Format allowedFormats[] = { + QSettings::NativeFormat, +#ifdef Q_OS_WIN + QSettings::Registry32Format, + QSettings::Registry64Format +#endif + }; + + for (const QSettings::Format format : allowedFormats) { + const auto candidate = probeCandidate(format); + if (candidate.compilerPath.isEmpty() || candidates.contains(candidate)) + continue; + candidates.push_back(candidate); } } -- cgit v1.2.1