| 427 | } |
| 428 | |
| 429 | bool AppWizardPlugin::unpackArchive(const KArchiveDirectory* dir, const QString& dest, const QStringList& skipList) |
| 430 | { |
| 431 | qCDebug(PLUGIN_APPWIZARD) << "unpacking dir:" << dir->name() << "to" << dest; |
| 432 | const QStringList entries = dir->entries(); |
| 433 | qCDebug(PLUGIN_APPWIZARD) << "entries:" << entries.join(QLatin1Char(',')); |
| 434 | |
| 435 | //This extra tempdir is needed just for the files that have special names, |
| 436 | //which may contain macros also files contain content with macros. So the |
| 437 | //easiest way to extract the files from the archive and then rename them |
| 438 | //and replace the macros is to use a tempdir and copy the file (and |
| 439 | //replacing while copying). This also allows one to easily remove all files, |
| 440 | //by just unlinking the tempdir |
| 441 | QTemporaryDir tdir; |
| 442 | |
| 443 | bool ret = true; |
| 444 | |
| 445 | for (const auto& entryName : entries) { |
| 446 | if (skipList.contains(entryName)) { |
| 447 | continue; |
| 448 | } |
| 449 | |
| 450 | const auto entry = dir->entry(entryName); |
| 451 | if (entry->isDirectory()) { |
| 452 | const auto* subdir = static_cast<const KArchiveDirectory*>(entry); |
| 453 | const QString newdest = dest + QLatin1Char('/') + KMacroExpander::expandMacros(subdir->name(), m_variables); |
| 454 | if( !QFileInfo::exists( newdest ) ) |
| 455 | { |
| 456 | QDir::root().mkdir( newdest ); |
| 457 | } |
| 458 | ret |= unpackArchive(subdir, newdest); |
| 459 | } |
| 460 | else if (entry->isFile()) { |
| 461 | const auto* file = static_cast<const KArchiveFile*>(entry); |
| 462 | file->copyTo(tdir.path()); |
| 463 | const QString destName = dest + QLatin1Char('/') + file->name(); |
| 464 | if (!copyFileAndExpandMacros(QDir::cleanPath(tdir.path() + QLatin1Char('/') + file->name()), |
| 465 | KMacroExpander::expandMacros(destName, m_variables))) |
| 466 | { |
| 467 | KMessageBox::error(nullptr, i18n("The file %1 cannot be created.", dest)); |
| 468 | return false; |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | tdir.remove(); |
| 473 | return ret; |
| 474 | } |
| 475 | |
| 476 | bool AppWizardPlugin::copyFileAndExpandMacros(const QString &source, const QString &dest) |
| 477 | { |