diff --git a/src/blackmisc/fileutils.cpp b/src/blackmisc/fileutils.cpp index 0a1b3a8a3..0fc32a0d0 100644 --- a/src/blackmisc/fileutils.cpp +++ b/src/blackmisc/fileutils.cpp @@ -62,7 +62,7 @@ namespace BlackMisc if (fileNameAndPath.isEmpty()) { return false; } QFile file(fileNameAndPath); if (!file.open(QIODevice::WriteOnly)) { return false; } - qint64 c = file.write(data); + const qint64 c = file.write(data); file.close(); return c == data.count(); } @@ -79,7 +79,7 @@ namespace BlackMisc QFile file(fileNameAndPath); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { return {}; } QTextStream stream(&file); - QString content(stream.readAll()); + const QString content(stream.readAll()); file.close(); return content; } @@ -205,8 +205,8 @@ namespace BlackMisc QString CFileUtils::normalizeFilePathToQtStandard(const QString &filePath) { if (filePath.isEmpty()) { return {}; } - QString n(filePath); - n = n.replace('\\', '/').replace("//", "/"); + QString n = QDir::cleanPath(filePath); + n = n.replace('\\', '/').replace("//", "/"); // should be done alreay by cleanPath, paranoia return n; } diff --git a/src/blackmisc/simulation/fscommon/fscommonutil.cpp b/src/blackmisc/simulation/fscommon/fscommonutil.cpp index dca26749c..354c2c23b 100644 --- a/src/blackmisc/simulation/fscommon/fscommonutil.cpp +++ b/src/blackmisc/simulation/fscommon/fscommonutil.cpp @@ -49,7 +49,7 @@ namespace BlackMisc QString fsxPath; if (CBuildConfig::isCompiledWithFsxSupport()) { - FsRegistryPathPair fsxRegistryPathPairs = + const FsRegistryPathPair fsxRegistryPathPairs = { { QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0"), QStringLiteral("AppPath") }, { QStringLiteral("HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft Games\\Flight Simulator - Steam Edition\\10.0"), QStringLiteral("AppPath") }, @@ -59,13 +59,13 @@ namespace BlackMisc for (const auto ®istryPair : fsxRegistryPathPairs) { - QSettings fsxRegistry(registryPair.first, QSettings::NativeFormat); + const QSettings fsxRegistry(registryPair.first, QSettings::NativeFormat); fsxPath = fsxRegistry.value(registryPair.second).toString().trimmed(); if (!fsxPath.isEmpty()) break; } } - return fsxPath; + return CFileUtils::normalizeFilePathToQtStandard(fsxPath); } const QString &CFsCommonUtil::fsxDirFromRegistry() @@ -76,7 +76,7 @@ namespace BlackMisc QString fsxDirImpl() { - QString dir(CFsCommonUtil::fsxDirFromRegistry()); + const QString dir(CFsCommonUtil::fsxDirFromRegistry()); if (!dir.isEmpty()) { return dir; } QStringList someDefaultDirs( { @@ -99,7 +99,7 @@ namespace BlackMisc QString fsxSimObjectsDirFromRegistryImpl() { - const QString fsxPath = CFsCommonUtil::fsxDirFromRegistry(); + const QString fsxPath = CFileUtils::normalizeFilePathToQtStandard(CFsCommonUtil::fsxDirFromRegistry()); if (fsxPath.isEmpty()) { return {}; } return CFsCommonUtil::fsxSimObjectsDirFromSimDir(fsxPath); } @@ -126,7 +126,7 @@ namespace BlackMisc QString CFsCommonUtil::fsxSimObjectsDirFromSimDir(const QString &simDir) { if (simDir.isEmpty()) { return {}; } - return CFileUtils::appendFilePaths(simDir, "SimObjects"); + return CFileUtils::appendFilePaths(CFileUtils::normalizeFilePathToQtStandard(simDir), "SimObjects"); } const QStringList &CFsCommonUtil::fsxSimObjectsExcludeDirectoryPatterns() @@ -155,7 +155,7 @@ namespace BlackMisc }; for (const auto ®istryPair : p3dRegistryPathPairs) { - QSettings p3dRegistry(registryPair.first, QSettings::NativeFormat); + const QSettings p3dRegistry(registryPair.first, QSettings::NativeFormat); p3dPath = p3dRegistry.value(registryPair.second).toString().trimmed(); if (!p3dPath.isEmpty()) break; @@ -166,7 +166,7 @@ namespace BlackMisc const QString &CFsCommonUtil::p3dDirFromRegistry() { - static const QString p3dPath(p3dDirFromRegistryImpl()); + static const QString p3dPath = CFileUtils::normalizeFilePathToQtStandard(p3dDirFromRegistryImpl()); return p3dPath; } @@ -220,7 +220,7 @@ namespace BlackMisc { // finding the user settings only works on P3D machine QStringList allPaths = CFsCommonUtil::allFsxSimObjectPaths().toList(); - const QString sod = simObjectsDir.isEmpty() ? CFsCommonUtil::fsxSimObjectsDir() : simObjectsDir; + const QString sod = CFileUtils::normalizeFilePathToQtStandard(simObjectsDir.isEmpty() ? CFsCommonUtil::fsxSimObjectsDir() : simObjectsDir); if (!sod.isEmpty() && !allPaths.contains(sod, Qt::CaseInsensitive)) { // case insensitive is important here @@ -237,7 +237,7 @@ namespace BlackMisc { // finding the user settings only works on P3D machine QStringList allPaths = CFsCommonUtil::allP3dAddOnXmlSimObjectPaths(versionHint).toList(); - const QString sod = simObjectsDir.isEmpty() ? CFsCommonUtil::p3dSimObjectsDir() : simObjectsDir; + const QString sod = CFileUtils::normalizeFilePathToQtStandard(simObjectsDir.isEmpty() ? CFsCommonUtil::p3dSimObjectsDir() : simObjectsDir); if (!sod.isEmpty() && !allPaths.contains(sod, Qt::CaseInsensitive)) { // case insensitive is important here @@ -253,7 +253,7 @@ namespace BlackMisc QString CFsCommonUtil::p3dSimObjectsDirFromSimDir(const QString &simDir) { if (simDir.isEmpty()) { return {}; } - return CFileUtils::appendFilePaths(simDir, "SimObjects"); + return CFileUtils::normalizeFilePathToQtStandard(CFileUtils::appendFilePaths(simDir, "SimObjects")); } const QStringList &CFsCommonUtil::p3dSimObjectsExcludeDirectoryPatterns() @@ -407,7 +407,7 @@ namespace BlackMisc } QString targetDir = CFileUtils::appendFilePathsAndFixUnc(simObjectDir, "Misc"); - QDir td(targetDir); + const QDir td(targetDir); if (!td.exists()) { messages.push_back(CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, u"Cannot access target directory '%1'") << targetDir);