Changeset View
Changeset View
Standalone View
Standalone View
plugins/appwizard/appwizardplugin.cpp
Show First 20 Lines • Show All 269 Lines • ▼ Show 20 Line(s) | 258 | { | |||
---|---|---|---|---|---|
270 | else | 270 | else | ||
271 | { | 271 | { | ||
272 | QUrl url = KIO::upUrl(dest); | 272 | QUrl url = KIO::upUrl(dest); | ||
273 | if(!QFileInfo::exists(url.toLocalFile())) { | 273 | if(!QFileInfo::exists(url.toLocalFile())) { | ||
274 | QDir::root().mkpath(url.toLocalFile()); | 274 | QDir::root().mkpath(url.toLocalFile()); | ||
275 | } | 275 | } | ||
276 | } | 276 | } | ||
277 | 277 | | |||
278 | if ( !unpackArchive( arch->directory(), unpackDir ) ) | 278 | // estimate metadata files which should not be copied | ||
279 | { | 279 | QStringList metaDataFileNames; | ||
280 | | ||||
281 | // try by same name | ||||
282 | const KArchiveEntry *templateEntry = | ||||
283 | arch->directory()->entry(templateName + QLatin1String(".kdevtemplate")); | ||||
284 | | ||||
285 | // but could be different name, if e.g. downloaded, so make a guess | ||||
286 | if (!templateEntry || !templateEntry->isFile()) { | ||||
287 | for (const auto& entryName : arch->directory()->entries()) { | ||||
288 | if (entryName.endsWith(QLatin1String(".kdevtemplate"))) { | ||||
289 | templateEntry = arch->directory()->entry(entryName); | ||||
290 | break; | ||||
291 | } | ||||
292 | } | ||||
293 | } | ||||
294 | | ||||
295 | if (templateEntry && templateEntry->isFile()) { | ||||
296 | metaDataFileNames << templateEntry->name(); | ||||
297 | | ||||
298 | // check if a preview file is to be ignored | ||||
299 | const KArchiveFile *templateFile = static_cast<const KArchiveFile*>(templateEntry); | ||||
300 | QTemporaryDir temporaryDir; | ||||
301 | templateFile->copyTo(temporaryDir.path()); | ||||
302 | | ||||
303 | KConfig config(temporaryDir.path() + QLatin1Char('/') + templateEntry->name()); | ||||
304 | KConfigGroup group(&config, "General"); | ||||
305 | if (group.hasKey("Icon")) { | ||||
306 | const KArchiveEntry* iconEntry = arch->directory()->entry(group.readEntry("Icon")); | ||||
307 | if (iconEntry && iconEntry->isFile()) { | ||||
308 | metaDataFileNames << iconEntry->name(); | ||||
309 | } | ||||
310 | } | ||||
311 | } | ||||
312 | | ||||
313 | if (!unpackArchive(arch->directory(), unpackDir, metaDataFileNames)) { | ||||
280 | QString errorMsg = i18n("Could not create new project"); | 314 | QString errorMsg = i18n("Could not create new project"); | ||
281 | vcsError(errorMsg, tmpdir, QUrl::fromLocalFile(unpackDir)); | 315 | vcsError(errorMsg, tmpdir, QUrl::fromLocalFile(unpackDir)); | ||
282 | return QString(); | 316 | return QString(); | ||
283 | } | 317 | } | ||
284 | 318 | | |||
285 | if( !info.vcsPluginName.isEmpty() ) | 319 | if( !info.vcsPluginName.isEmpty() ) | ||
286 | { | 320 | { | ||
287 | if (!plugin) | 321 | if (!plugin) | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 372 | { | |||
358 | cfg->sync(); | 392 | cfg->sync(); | ||
359 | KConfigGroup project2 = cfg->group( "Project" ); | 393 | KConfigGroup project2 = cfg->group( "Project" ); | ||
360 | qCDebug(PLUGIN_APPWIZARD) << "kdev4 file contents:" << project2.readEntry("Name", "") << project2.readEntry("Manager", "" ); | 394 | qCDebug(PLUGIN_APPWIZARD) << "kdev4 file contents:" << project2.readEntry("Name", "") << project2.readEntry("Manager", "" ); | ||
361 | } | 395 | } | ||
362 | 396 | | |||
363 | return projectFileName; | 397 | return projectFileName; | ||
364 | } | 398 | } | ||
365 | 399 | | |||
366 | bool AppWizardPlugin::unpackArchive(const KArchiveDirectory *dir, const QString &dest) | 400 | bool AppWizardPlugin::unpackArchive(const KArchiveDirectory* dir, const QString& dest, const QStringList& skipList) | ||
367 | { | 401 | { | ||
368 | qCDebug(PLUGIN_APPWIZARD) << "unpacking dir:" << dir->name() << "to" << dest; | 402 | qCDebug(PLUGIN_APPWIZARD) << "unpacking dir:" << dir->name() << "to" << dest; | ||
369 | const QStringList entries = dir->entries(); | 403 | const QStringList entries = dir->entries(); | ||
370 | qCDebug(PLUGIN_APPWIZARD) << "entries:" << entries.join(QStringLiteral(",")); | 404 | qCDebug(PLUGIN_APPWIZARD) << "entries:" << entries.join(QStringLiteral(",")); | ||
371 | 405 | | |||
372 | //This extra tempdir is needed just for the files files have special names, | 406 | //This extra tempdir is needed just for the files files have special names, | ||
373 | //which may contain macros also files contain content with macros. So the | 407 | //which may contain macros also files contain content with macros. So the | ||
374 | //easiest way to extract the files from the archive and then rename them | 408 | //easiest way to extract the files from the archive and then rename them | ||
375 | //and replace the macros is to use a tempdir and copy the file (and | 409 | //and replace the macros is to use a tempdir and copy the file (and | ||
376 | //replacing while copying). This also allows one to easily remove all files, | 410 | //replacing while copying). This also allows one to easily remove all files, | ||
377 | //by just unlinking the tempdir | 411 | //by just unlinking the tempdir | ||
378 | QTemporaryDir tdir; | 412 | QTemporaryDir tdir; | ||
379 | 413 | | |||
380 | bool ret = true; | 414 | bool ret = true; | ||
381 | 415 | | |||
382 | foreach (const QString& entry, entries) | 416 | foreach (const QString& entry, entries) | ||
383 | { | 417 | { | ||
384 | if (entry.endsWith(QLatin1String(".kdevtemplate"))) | 418 | if (skipList.contains(entry)) { | ||
385 | continue; | 419 | continue; | ||
420 | } | ||||
421 | | ||||
386 | if (dir->entry(entry)->isDirectory()) | 422 | if (dir->entry(entry)->isDirectory()) | ||
387 | { | 423 | { | ||
388 | const KArchiveDirectory *file = (KArchiveDirectory *)dir->entry(entry); | 424 | const KArchiveDirectory *file = (KArchiveDirectory *)dir->entry(entry); | ||
389 | QString newdest = dest + '/' + KMacroExpander::expandMacros(file->name(), m_variables); | 425 | QString newdest = dest + '/' + KMacroExpander::expandMacros(file->name(), m_variables); | ||
390 | if( !QFileInfo::exists( newdest ) ) | 426 | if( !QFileInfo::exists( newdest ) ) | ||
391 | { | 427 | { | ||
392 | QDir::root().mkdir( newdest ); | 428 | QDir::root().mkdir( newdest ); | ||
393 | } | 429 | } | ||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |