Changeset View
Changeset View
Standalone View
Standalone View
kerfuffle/cliinterface.cpp
Show First 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | 148 | { | |||
---|---|---|---|---|---|
162 | if (!destinationPath.isEmpty()) { | 162 | if (!destinationPath.isEmpty()) { | ||
163 | m_extractTempDir.reset(new QTemporaryDir()); | 163 | m_extractTempDir.reset(new QTemporaryDir()); | ||
164 | const QString absoluteDestinationPath = m_extractTempDir->path() + QLatin1Char('/') + destinationPath; | 164 | const QString absoluteDestinationPath = m_extractTempDir->path() + QLatin1Char('/') + destinationPath; | ||
165 | 165 | | |||
166 | QDir qDir; | 166 | QDir qDir; | ||
167 | qDir.mkpath(absoluteDestinationPath); | 167 | qDir.mkpath(absoluteDestinationPath); | ||
168 | 168 | | |||
169 | QObject *preservedParent = nullptr; | 169 | QObject *preservedParent = nullptr; | ||
170 | foreach (Archive::Entry *file, files) { | 170 | for (Archive::Entry *file : files) { | ||
171 | // The entries may have parent. We have to save and apply it to our new entry in order to prevent memory | 171 | // The entries may have parent. We have to save and apply it to our new entry in order to prevent memory | ||
172 | // leaks. | 172 | // leaks. | ||
173 | if (preservedParent == nullptr) { | 173 | if (preservedParent == nullptr) { | ||
174 | preservedParent = file->parent(); | 174 | preservedParent = file->parent(); | ||
175 | } | 175 | } | ||
176 | 176 | | |||
177 | const QString filePath = QDir::currentPath() + QLatin1Char('/') + file->fullPath(NoTrailingSlash); | 177 | const QString filePath = QDir::currentPath() + QLatin1Char('/') + file->fullPath(NoTrailingSlash); | ||
178 | const QString newFilePath = absoluteDestinationPath + file->fullPath(NoTrailingSlash); | 178 | const QString newFilePath = absoluteDestinationPath + file->fullPath(NoTrailingSlash); | ||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | 309 | { | |||
320 | 320 | | |||
321 | // #193908 - #222392 | 321 | // #193908 - #222392 | ||
322 | // Don't emit finished() if the job was killed quietly. | 322 | // Don't emit finished() if the job was killed quietly. | ||
323 | if (m_abortingOperation) { | 323 | if (m_abortingOperation) { | ||
324 | return; | 324 | return; | ||
325 | } | 325 | } | ||
326 | 326 | | |||
327 | if (m_operationMode == Delete || m_operationMode == Move) { | 327 | if (m_operationMode == Delete || m_operationMode == Move) { | ||
328 | QStringList removedFullPaths = entryFullPaths(m_removedFiles); | 328 | const QStringList removedFullPaths = entryFullPaths(m_removedFiles); | ||
329 | foreach (const QString &fullPath, removedFullPaths) { | 329 | for (const QString &fullPath : removedFullPaths) { | ||
330 | emit entryRemoved(fullPath); | 330 | emit entryRemoved(fullPath); | ||
331 | } | 331 | } | ||
332 | foreach (Archive::Entry *e, m_newMovedFiles) { | 332 | for (Archive::Entry *e : qAsConst(m_newMovedFiles)) { | ||
333 | emit entry(e); | 333 | emit entry(e); | ||
334 | } | 334 | } | ||
335 | m_newMovedFiles.clear(); | 335 | m_newMovedFiles.clear(); | ||
336 | } | 336 | } | ||
337 | 337 | | |||
338 | if (m_operationMode == Add && !isMultiVolume()) { | 338 | if (m_operationMode == Add && !isMultiVolume()) { | ||
339 | list(); | 339 | list(); | ||
340 | } else if (m_operationMode == List && isCorrupt()) { | 340 | } else if (m_operationMode == List && isCorrupt()) { | ||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | 449 | { | |||
450 | // Move extracted files from a QTemporaryDir to the final destination. | 450 | // Move extracted files from a QTemporaryDir to the final destination. | ||
451 | 451 | | |||
452 | QDir finalDestDir(finalDest); | 452 | QDir finalDestDir(finalDest); | ||
453 | qCDebug(ARK) << "Setting final dir to" << finalDest; | 453 | qCDebug(ARK) << "Setting final dir to" << finalDest; | ||
454 | 454 | | |||
455 | bool overwriteAll = false; | 455 | bool overwriteAll = false; | ||
456 | bool skipAll = false; | 456 | bool skipAll = false; | ||
457 | 457 | | |||
458 | foreach (const Archive::Entry *file, files) { | 458 | for (const Archive::Entry *file : files) { | ||
459 | 459 | | |||
460 | QFileInfo relEntry(file->fullPath().remove(file->rootNode)); | 460 | QFileInfo relEntry(file->fullPath().remove(file->rootNode)); | ||
461 | QFileInfo absSourceEntry(QDir::current().absolutePath() + QLatin1Char('/') + file->fullPath()); | 461 | QFileInfo absSourceEntry(QDir::current().absolutePath() + QLatin1Char('/') + file->fullPath()); | ||
462 | QFileInfo absDestEntry(finalDestDir.path() + QLatin1Char('/') + relEntry.filePath()); | 462 | QFileInfo absDestEntry(finalDestDir.path() + QLatin1Char('/') + relEntry.filePath()); | ||
463 | 463 | | |||
464 | if (absSourceEntry.isDir()) { | 464 | if (absSourceEntry.isDir()) { | ||
465 | 465 | | |||
466 | // For directories, just create the path. | 466 | // For directories, just create the path. | ||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Line(s) | 568 | { | |||
642 | 642 | | |||
643 | return true; | 643 | return true; | ||
644 | } | 644 | } | ||
645 | 645 | | |||
646 | void CliInterface::setNewMovedFiles(const QVector<Archive::Entry*> &entries, const Archive::Entry *destination, int entriesWithoutChildren) | 646 | void CliInterface::setNewMovedFiles(const QVector<Archive::Entry*> &entries, const Archive::Entry *destination, int entriesWithoutChildren) | ||
647 | { | 647 | { | ||
648 | m_newMovedFiles.clear(); | 648 | m_newMovedFiles.clear(); | ||
649 | QMap<QString, const Archive::Entry*> entryMap; | 649 | QMap<QString, const Archive::Entry*> entryMap; | ||
650 | foreach (const Archive::Entry* entry, entries) { | 650 | for (const Archive::Entry* entry : entries) { | ||
651 | entryMap.insert(entry->fullPath(), entry); | 651 | entryMap.insert(entry->fullPath(), entry); | ||
652 | } | 652 | } | ||
653 | 653 | | |||
654 | QString lastFolder; | 654 | QString lastFolder; | ||
655 | 655 | | |||
656 | QString newPath; | 656 | QString newPath; | ||
657 | int nameLength = 0; | 657 | int nameLength = 0; | ||
658 | foreach (const Archive::Entry* entry, entryMap) { | 658 | for (const Archive::Entry* entry : qAsConst(entryMap)) { | ||
659 | if (lastFolder.count() > 0 && entry->fullPath().startsWith(lastFolder)) { | 659 | if (lastFolder.count() > 0 && entry->fullPath().startsWith(lastFolder)) { | ||
660 | // Replace last moved or copied folder path with destination path. | 660 | // Replace last moved or copied folder path with destination path. | ||
661 | int charsCount = entry->fullPath().count() - lastFolder.count(); | 661 | int charsCount = entry->fullPath().count() - lastFolder.count(); | ||
662 | if (entriesWithoutChildren > 1) { | 662 | if (entriesWithoutChildren > 1) { | ||
663 | charsCount += nameLength; | 663 | charsCount += nameLength; | ||
664 | } | 664 | } | ||
665 | newPath = destination->fullPath() + entry->fullPath().right(charsCount); | 665 | newPath = destination->fullPath() + entry->fullPath().right(charsCount); | ||
666 | } else { | 666 | } else { | ||
Show All 18 Lines | |||||
685 | newEntry->setFullPath(newPath); | 685 | newEntry->setFullPath(newPath); | ||
686 | m_newMovedFiles << newEntry; | 686 | m_newMovedFiles << newEntry; | ||
687 | } | 687 | } | ||
688 | } | 688 | } | ||
689 | 689 | | |||
690 | QStringList CliInterface::extractFilesList(const QVector<Archive::Entry*> &entries) const | 690 | QStringList CliInterface::extractFilesList(const QVector<Archive::Entry*> &entries) const | ||
691 | { | 691 | { | ||
692 | QStringList filesList; | 692 | QStringList filesList; | ||
693 | foreach (const Archive::Entry *e, entries) { | 693 | for (const Archive::Entry *e : entries) { | ||
694 | filesList << escapeFileName(e->fullPath(NoTrailingSlash)); | 694 | filesList << escapeFileName(e->fullPath(NoTrailingSlash)); | ||
695 | } | 695 | } | ||
696 | 696 | | |||
697 | return filesList; | 697 | return filesList; | ||
698 | } | 698 | } | ||
699 | 699 | | |||
700 | void CliInterface::killProcess(bool emitFinished) | 700 | void CliInterface::killProcess(bool emitFinished) | ||
701 | { | 701 | { | ||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | 806 | if (handleAll) { | |||
807 | m_stdOutData.clear(); | 807 | m_stdOutData.clear(); | ||
808 | } else { | 808 | } else { | ||
809 | //because the last line might be incomplete we leave it for now | 809 | //because the last line might be incomplete we leave it for now | ||
810 | //note, this last line may be an empty string if the stdoutdata ends | 810 | //note, this last line may be an empty string if the stdoutdata ends | ||
811 | //with a newline | 811 | //with a newline | ||
812 | m_stdOutData = lines.takeLast(); | 812 | m_stdOutData = lines.takeLast(); | ||
813 | } | 813 | } | ||
814 | 814 | | |||
815 | foreach(const QByteArray& line, lines) { | 815 | for (const QByteArray& line : qAsConst(lines)) { | ||
816 | if (!line.isEmpty() || (m_listEmptyLines && m_operationMode == List)) { | 816 | if (!line.isEmpty() || (m_listEmptyLines && m_operationMode == List)) { | ||
817 | if (!handleLine(QString::fromLocal8Bit(line))) { | 817 | if (!handleLine(QString::fromLocal8Bit(line))) { | ||
818 | killProcess(); | 818 | killProcess(); | ||
819 | return; | 819 | return; | ||
820 | } | 820 | } | ||
821 | } | 821 | } | ||
822 | } | 822 | } | ||
823 | } | 823 | } | ||
824 | 824 | | |||
825 | bool CliInterface::setAddedFiles() | 825 | bool CliInterface::setAddedFiles() | ||
826 | { | 826 | { | ||
827 | QDir::setCurrent(m_tempAddDir->path()); | 827 | QDir::setCurrent(m_tempAddDir->path()); | ||
828 | foreach (const Archive::Entry *file, m_passedFiles) { | 828 | for (const Archive::Entry *file : qAsConst(m_passedFiles)) { | ||
829 | const QString oldPath = m_tempWorkingDir->path() + QLatin1Char('/') + file->fullPath(NoTrailingSlash); | 829 | const QString oldPath = m_tempWorkingDir->path() + QLatin1Char('/') + file->fullPath(NoTrailingSlash); | ||
830 | const QString newPath = m_tempAddDir->path() + QLatin1Char('/') + file->name(); | 830 | const QString newPath = m_tempAddDir->path() + QLatin1Char('/') + file->name(); | ||
831 | if (!QFile::rename(oldPath, newPath)) { | 831 | if (!QFile::rename(oldPath, newPath)) { | ||
832 | return false; | 832 | return false; | ||
833 | } | 833 | } | ||
834 | m_tempAddedFiles << new Archive::Entry(nullptr, file->name()); | 834 | m_tempAddedFiles << new Archive::Entry(nullptr, file->name()); | ||
835 | } | 835 | } | ||
836 | return true; | 836 | return true; | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 955 | { | |||
956 | Q_UNUSED(line); | 956 | Q_UNUSED(line); | ||
957 | return true; | 957 | return true; | ||
958 | } | 958 | } | ||
959 | 959 | | |||
960 | bool CliInterface::handleFileExistsMessage(const QString& line) | 960 | bool CliInterface::handleFileExistsMessage(const QString& line) | ||
961 | { | 961 | { | ||
962 | // Check for a filename and store it. | 962 | // Check for a filename and store it. | ||
963 | if (isFileExistsFileName(line)) { | 963 | if (isFileExistsFileName(line)) { | ||
964 | foreach (const QString &pattern, m_cliProps->property("fileExistsFileNameRegExp").toStringList()) { | 964 | const QStringList fileExistsFileNameRegExp = m_cliProps->property("fileExistsFileNameRegExp").toStringList(); | ||
965 | for (const QString &pattern : fileExistsFileNameRegExp) { | ||||
965 | const QRegularExpression rxFileNamePattern(pattern); | 966 | const QRegularExpression rxFileNamePattern(pattern); | ||
966 | const QRegularExpressionMatch rxMatch = rxFileNamePattern.match(line); | 967 | const QRegularExpressionMatch rxMatch = rxFileNamePattern.match(line); | ||
967 | 968 | | |||
968 | if (rxMatch.hasMatch()) { | 969 | if (rxMatch.hasMatch()) { | ||
969 | m_storedFileName = rxMatch.captured(1); | 970 | m_storedFileName = rxMatch.captured(1); | ||
970 | qCWarning(ARK) << "Detected existing file:" << m_storedFileName; | 971 | qCWarning(ARK) << "Detected existing file:" << m_storedFileName; | ||
971 | } | 972 | } | ||
972 | } | 973 | } | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
1022 | { | 1023 | { | ||
1023 | return fileName; | 1024 | return fileName; | ||
1024 | } | 1025 | } | ||
1025 | 1026 | | |||
1026 | QStringList CliInterface::entryPathDestinationPairs(const QVector<Archive::Entry*> &entriesWithoutChildren, const Archive::Entry *destination) | 1027 | QStringList CliInterface::entryPathDestinationPairs(const QVector<Archive::Entry*> &entriesWithoutChildren, const Archive::Entry *destination) | ||
1027 | { | 1028 | { | ||
1028 | QStringList pairList; | 1029 | QStringList pairList; | ||
1029 | if (entriesWithoutChildren.count() > 1) { | 1030 | if (entriesWithoutChildren.count() > 1) { | ||
1030 | foreach (const Archive::Entry *file, entriesWithoutChildren) { | 1031 | for (const Archive::Entry *file : entriesWithoutChildren) { | ||
1031 | pairList << file->fullPath(NoTrailingSlash) << destination->fullPath() + file->name(); | 1032 | pairList << file->fullPath(NoTrailingSlash) << destination->fullPath() + file->name(); | ||
1032 | } | 1033 | } | ||
1033 | } else { | 1034 | } else { | ||
1034 | pairList << entriesWithoutChildren.at(0)->fullPath(NoTrailingSlash) << destination->fullPath(NoTrailingSlash); | 1035 | pairList << entriesWithoutChildren.at(0)->fullPath(NoTrailingSlash) << destination->fullPath(NoTrailingSlash); | ||
1035 | } | 1036 | } | ||
1036 | return pairList; | 1037 | return pairList; | ||
1037 | } | 1038 | } | ||
1038 | 1039 | | |||
Show All 34 Lines | 1055 | { | |||
1073 | return true; | 1074 | return true; | ||
1074 | } | 1075 | } | ||
1075 | 1076 | | |||
1076 | QString CliInterface::multiVolumeName() const | 1077 | QString CliInterface::multiVolumeName() const | ||
1077 | { | 1078 | { | ||
1078 | QString oldSuffix = QMimeDatabase().suffixForFileName(filename()); | 1079 | QString oldSuffix = QMimeDatabase().suffixForFileName(filename()); | ||
1079 | QString name; | 1080 | QString name; | ||
1080 | 1081 | | |||
1081 | foreach (const QString &multiSuffix, m_cliProps->property("multiVolumeSuffix").toStringList()) { | 1082 | const QStringList multiVolumeSuffix = m_cliProps->property("multiVolumeSuffix").toStringList(); | ||
1083 | for (const QString &multiSuffix : multiVolumeSuffix) { | ||||
1082 | QString newSuffix = multiSuffix; | 1084 | QString newSuffix = multiSuffix; | ||
1083 | newSuffix.replace(QStringLiteral("$Suffix"), oldSuffix); | 1085 | newSuffix.replace(QStringLiteral("$Suffix"), oldSuffix); | ||
1084 | name = filename().remove(oldSuffix).append(newSuffix); | 1086 | name = filename().remove(oldSuffix).append(newSuffix); | ||
1085 | if (QFileInfo::exists(name)) { | 1087 | if (QFileInfo::exists(name)) { | ||
1086 | break; | 1088 | break; | ||
1087 | } | 1089 | } | ||
1088 | } | 1090 | } | ||
1089 | return name; | 1091 | return name; | ||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |