diff --git a/plugins/appwizard/appwizardplugin.h b/plugins/appwizard/appwizardplugin.h --- a/plugins/appwizard/appwizardplugin.h +++ b/plugins/appwizard/appwizardplugin.h @@ -47,7 +47,7 @@ ProjectTemplatesModel* model(); QString createProject(const ApplicationInfo& ); - bool unpackArchive(const KArchiveDirectory *dir, const QString &dest); + bool unpackArchive(const KArchiveDirectory* dir, const QString& dest, const QStringList& skipList = {}); bool copyFileAndExpandMacros(const QString &source, const QString &dest); ProjectTemplatesModel* m_templatesModel; diff --git a/plugins/appwizard/appwizardplugin.cpp b/plugins/appwizard/appwizardplugin.cpp --- a/plugins/appwizard/appwizardplugin.cpp +++ b/plugins/appwizard/appwizardplugin.cpp @@ -275,8 +275,42 @@ } } - if ( !unpackArchive( arch->directory(), unpackDir ) ) - { + // estimate metadata files which should not be copied + QStringList metaDataFileNames; + + // try by same name + const KArchiveEntry *templateEntry = + arch->directory()->entry(templateName + QLatin1String(".kdevtemplate")); + + // but could be different name, if e.g. downloaded, so make a guess + if (!templateEntry || !templateEntry->isFile()) { + for (const auto& entryName : arch->directory()->entries()) { + if (entryName.endsWith(QLatin1String(".kdevtemplate"))) { + templateEntry = arch->directory()->entry(entryName); + break; + } + } + } + + if (templateEntry && templateEntry->isFile()) { + metaDataFileNames << templateEntry->name(); + + // check if a preview file is to be ignored + const KArchiveFile *templateFile = static_cast(templateEntry); + QTemporaryDir temporaryDir; + templateFile->copyTo(temporaryDir.path()); + + KConfig config(temporaryDir.path() + QLatin1Char('/') + templateEntry->name()); + KConfigGroup group(&config, "General"); + if (group.hasKey("Icon")) { + const KArchiveEntry* iconEntry = arch->directory()->entry(group.readEntry("Icon")); + if (iconEntry && iconEntry->isFile()) { + metaDataFileNames << iconEntry->name(); + } + } + } + + if (!unpackArchive(arch->directory(), unpackDir, metaDataFileNames)) { QString errorMsg = i18n("Could not create new project"); vcsError(errorMsg, tmpdir, QUrl::fromLocalFile(unpackDir)); return QString(); @@ -363,7 +397,7 @@ return projectFileName; } -bool AppWizardPlugin::unpackArchive(const KArchiveDirectory *dir, const QString &dest) +bool AppWizardPlugin::unpackArchive(const KArchiveDirectory* dir, const QString& dest, const QStringList& skipList) { qCDebug(PLUGIN_APPWIZARD) << "unpacking dir:" << dir->name() << "to" << dest; const QStringList entries = dir->entries(); @@ -381,8 +415,10 @@ foreach (const QString& entry, entries) { - if (entry.endsWith(QLatin1String(".kdevtemplate"))) + if (skipList.contains(entry)) { continue; + } + if (dir->entry(entry)->isDirectory()) { const KArchiveDirectory *file = (KArchiveDirectory *)dir->entry(entry);