From 2e2248e80e30243d638fe3b8a4a01ca71039301a Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Fri, 13 Oct 2023 20:48:08 +0200 Subject: [PATCH] CMakePM: Allow invalid file characters as part of preset names The fact that Qt Creator uses the preset name to create a directory and then import the directory is an implementation detail. This changeset will allow characters like ":" to be part of the preset name. Task-number: QTCREATORBUG-29643 Change-Id: I84a224b78eb3d2233f80d9bdb8bf4478471349b0 Reviewed-by: Alessandro Portale --- .../cmakeprojectimporter.cpp | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp index 6455ad3ea26..583729ee933 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp @@ -104,6 +104,40 @@ CMakeProjectImporter::CMakeProjectImporter(const FilePath &path, const CMakeProj } +using CharToHexList = QList>; +static const CharToHexList &charToHexList() +{ + static const CharToHexList list = { + {"<", "{3C}"}, + {">", "{3E}"}, + {":", "{3A}"}, + {"\"", "{22}"}, + {"\\", "{5C}"}, + {"/", "{2F}"}, + {"|", "{7C}"}, + {"?", "{3F}"}, + {"*", "{2A}"}, + }; + + return list; +} + +static QString presetNameToFileName(const QString &name) +{ + QString fileName = name; + for (const auto &p : charToHexList()) + fileName.replace(p.first, p.second); + return fileName; +} + +static QString fileNameToPresetName(const QString &fileName) +{ + QString name = fileName; + for (const auto &p : charToHexList()) + name.replace(p.second, p.first); + return name; +} + FilePaths CMakeProjectImporter::importCandidates() { FilePaths candidates; @@ -129,7 +163,8 @@ FilePaths CMakeProjectImporter::importCandidates() continue; } - const FilePath configPresetDir = m_presetsTempDir.filePath(configPreset.name); + const FilePath configPresetDir = m_presetsTempDir.filePath( + presetNameToFileName(configPreset.name)); configPresetDir.createDir(); candidates << configPresetDir; @@ -638,7 +673,7 @@ QList CMakeProjectImporter::examineDirectory(const FilePath &importPath, if (importPath.isChildOf(m_presetsTempDir.path())) { auto data = std::make_unique(); - const QString presetName = importPath.fileName(); + const QString presetName = fileNameToPresetName(importPath.fileName()); PresetsDetails::ConfigurePreset configurePreset = Utils::findOrDefault(m_project->presetsData().configurePresets, [presetName](const PresetsDetails::ConfigurePreset &preset) {