diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp index 2943e55dfd3f7327b0677be4a31f20c0c0c40fab..39d4416285b7ee4e13c5c385976517d594c6917d 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp @@ -151,17 +151,30 @@ static inline bool createFile(Internal::CustomWizardFile cwFile, const QString targetPath = QDir::toNativeSeparators(targetDirectory + slash + cwFile.target); if (CustomWizardPrivate::verbose) qDebug() << "generating " << targetPath << sourcePath << fm; + + // Read contents of source file + const QFile::OpenMode openMode + = cwFile.binary ? QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text); QFile file(sourcePath); - if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) { + if (!file.open(openMode)) { *errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(sourcePath, file.errorString()); return false; } - // Field replacement on contents - const QString contentsIn = QString::fromLocal8Bit(file.readAll()); + const QByteArray contentData = file.readAll(); + file.close(); Core::GeneratedFile generatedFile; - generatedFile.setContents(Internal::CustomWizardContext::processFile(fm, contentsIn)); generatedFile.setPath(targetPath); + if (cwFile.binary) { + // Binary file: Set data. + generatedFile.setBinary(true); + generatedFile.setBinaryContents(contentData); + } else { + // Template file: Preprocess. + const QString contentsIn = QString::fromLocal8Bit(contentData); + generatedFile.setContents(Internal::CustomWizardContext::processFile(fm, contentsIn)); + } + Core::GeneratedFile::Attributes attributes = 0; if (cwFile.openEditor) attributes |= Core::GeneratedFile::OpenEditorAttribute; diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp index 6ccca0449895df5bcf8b07571c94b95abf2cafa4..67a9e5844b7e8b509b86a87f4ace3b9d7be0bdce 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp @@ -88,6 +88,7 @@ static const char filesGeneratorScriptAttributeC[] = "generatorscript"; static const char fileElementC[] = "file"; static const char fileSourceAttributeC[] = "source"; static const char fileTargetAttributeC[] = "target"; +static const char fileBinaryAttributeC[] = "binary"; enum ParseState { ParseBeginning, @@ -137,7 +138,7 @@ QString CustomWizardField::comboEntryTextKey(int i) } CustomWizardFile::CustomWizardFile() : - openEditor(false), openProject(false) + openEditor(false), openProject(false), binary(false) { } @@ -543,6 +544,7 @@ CustomWizardParameters::ParseResult file.target = attributeValue(reader, fileTargetAttributeC); file.openEditor = booleanAttributeValue(reader, customWizardFileOpenEditorAttributeC, false); file.openProject = booleanAttributeValue(reader, customWizardFileOpenProjectAttributeC, false); + file.binary = booleanAttributeValue(reader, fileBinaryAttributeC, false); if (file.target.isEmpty()) file.target = file.source; if (file.source.isEmpty()) { @@ -644,6 +646,8 @@ QString CustomWizardParameters::toString() const str << " [editor]"; if (f.openProject) str << " [project]"; + if (f.binary) + str << " [binary]"; str << '\n'; } foreach(const CustomWizardField &f, fields) { diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.h b/src/plugins/projectexplorer/customwizard/customwizardparameters.h index 732098ff35ec3421291f2262d7d7c5d24ba4298c..15c8bbb97ea49fc64043a5f5a5346d0e5afb738a 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardparameters.h +++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.h @@ -68,6 +68,7 @@ struct CustomWizardFile { QString target; bool openEditor; bool openProject; + bool binary; }; // Argument to the generator script containing placeholders to