Mimepart& Mime::addBinaryFile(const std::string& contentType, const std::string& filename) { std::ifstream in(filename.c_str()); if (!in) throw std::runtime_error("cannot open file \"" + filename + '"'); return addBinaryFile(contentType, filename, in); }
Core::GeneratedFiles QmlApp::generateFiles(QString *errorMessage) { Core::GeneratedFiles files; QTC_ASSERT(errorMessage, return files); errorMessage->clear(); setReplacementVariables(); const QFileInfoList templateFiles = allFilesRecursive(templateDirectory()); foreach (const QFileInfo &templateFile, templateFiles) { const QString targetSubDirectory = templateFile.path().mid(templateDirectory().length()); const QString targetDirectory = projectDirectory() + targetSubDirectory + QLatin1Char('/'); QString targetFileName = templateFile.fileName(); if (templateFile.fileName() == QLatin1String("main.pro")) { targetFileName = projectName() + QLatin1String(".pro"); m_creatorFileName = Core::BaseFileWizard::buildFileName(projectDirectory(), projectName(), QLatin1String("pro")); } else if (templateFile.fileName() == QLatin1String("main.qmlproject")) { targetFileName = projectName() + QLatin1String(".qmlproject"); m_creatorFileName = Core::BaseFileWizard::buildFileName(projectDirectory(), projectName(), QLatin1String("qmlproject")); } else if (templateFile.fileName() == QLatin1String("main.qbp")) { targetFileName = projectName() + QLatin1String(".qbp"); } else if (targetFileName == QLatin1String("template.xml") || targetFileName == QLatin1String("template.png")) { continue; } else { targetFileName = renameQmlFile(templateFile.fileName()); } if (binaryFiles().contains(templateFile.suffix())) { bool canAddBinaryFile = addBinaryFile(templateFile.absolutePath(), templateFile.fileName(), targetDirectory, targetFileName, &files, errorMessage); if (!canAddBinaryFile) return Core::GeneratedFiles(); } else { bool canAddTemplate = addTemplate(templateFile.absolutePath(), templateFile.fileName(), targetDirectory, targetFileName, &files, errorMessage); if (!canAddTemplate) return Core::GeneratedFiles(); if (templateFile.fileName() == QLatin1String("main.pro")) { files.last().setAttributes(Core::GeneratedFile::OpenProjectAttribute); } else if (templateFile.fileName() == QLatin1String("main.qmlproject")) { files.last().setAttributes(Core::GeneratedFile::OpenProjectAttribute); } else if (templateFile.fileName() == m_templateInfo.openFile) { files.last().setAttributes(Core::GeneratedFile::OpenEditorAttribute); } } } return files; }