From 694c29d67be8c982b6675da8c3766369ef89edc4 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 7 Jun 2023 10:24:52 +0200 Subject: [PATCH] Utils: Get rid of Archive Use Unarchiver instead. Change-Id: I7544b36ca11578d7ae7eb8571e6fe823cf74dee1 Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: hjk --- src/libs/utils/archive.cpp | 81 -------------------------------------- src/libs/utils/archive.h | 22 ----------- 2 files changed, 103 deletions(-) diff --git a/src/libs/utils/archive.cpp b/src/libs/utils/archive.cpp index b86a7ab0b89..5086ce5358b 100644 --- a/src/libs/utils/archive.cpp +++ b/src/libs/utils/archive.cpp @@ -98,87 +98,6 @@ static std::optional resolveTool(const Tool &tool) return executable.isEmpty() ? std::nullopt : std::make_optional(resolvedTool); } -static std::optional unzipTool(const FilePath &src, const FilePath &dest) -{ - const QVector tools = toolsForFilePath(src); - for (const Tool &tool : tools) { - const std::optional resolvedTool = resolveTool(tool); - if (resolvedTool) { - Tool result = *resolvedTool; - const QString srcStr = src.path(); - const QString destStr = dest.path(); - const QString args = result.command.arguments().replace("%{src}", srcStr).replace("%{dest}", destStr); - result.command.setArguments(args); - return result; - } - } - return {}; -} - -bool Archive::supportsFile(const FilePath &filePath, QString *reason) -{ - const QVector tools = toolsForFilePath(filePath); - if (tools.isEmpty()) { - if (reason) - *reason = Tr::tr("File format not supported."); - return false; - } - if (!anyOf(tools, [tools](const Tool &t) { return resolveTool(t); })) { - if (reason) { - const QStringList execs = transform(tools, [](const Tool &tool) { - return tool.command.executable().toUserOutput(); - }); - *reason = Tr::tr("Could not find any unarchiving executable in PATH (%1).") - .arg(execs.join(", ")); - } - return false; - } - return true; -} - -Archive::Archive(const FilePath &src, const FilePath &dest) -{ - const std::optional tool = unzipTool(src, dest); - if (!tool) - return; - m_commandLine = tool->command; - m_workingDirectory = dest.absoluteFilePath(); -} - -Archive::~Archive() = default; - -bool Archive::isValid() const -{ - return !m_commandLine.isEmpty(); -} - -void Archive::unarchive() -{ - QTC_ASSERT(isValid(), return); - QTC_ASSERT(!m_process, return); - - m_workingDirectory.ensureWritableDir(); - - m_process.reset(new Process); - m_process->setProcessChannelMode(QProcess::MergedChannels); - QObject::connect(m_process.get(), &Process::readyReadStandardOutput, this, [this] { - emit outputReceived(m_process->readAllStandardOutput()); - }); - QObject::connect(m_process.get(), &Process::done, this, [this] { - const bool successfulFinish = m_process->result() == ProcessResult::FinishedWithSuccess; - if (!successfulFinish) - emit outputReceived(Tr::tr("Command failed.")); - emit finished(successfulFinish); - }); - - emit outputReceived(Tr::tr("Running %1\nin \"%2\".\n\n", "Running in ") - .arg(m_commandLine.toUserOutput(), m_workingDirectory.toUserOutput())); - - m_process->setCommand(m_commandLine); - m_process->setWorkingDirectory(m_workingDirectory); - m_process->start(); -} - expected_str Unarchiver::sourceAndCommand(const FilePath &sourceFile) { const QVector tools = toolsForFilePath(sourceFile); diff --git a/src/libs/utils/archive.h b/src/libs/utils/archive.h index b40d26c7a4b..0890bafa743 100644 --- a/src/libs/utils/archive.h +++ b/src/libs/utils/archive.h @@ -14,28 +14,6 @@ namespace Utils { -class QTCREATOR_UTILS_EXPORT Archive : public QObject -{ - Q_OBJECT -public: - Archive(const FilePath &src, const FilePath &dest); - ~Archive(); - - bool isValid() const; - void unarchive(); - - static bool supportsFile(const FilePath &filePath, QString *reason = nullptr); - -signals: - void outputReceived(const QString &output); - void finished(bool success); - -private: - CommandLine m_commandLine; - FilePath m_workingDirectory; - std::unique_ptr m_process; -}; - class QTCREATOR_UTILS_EXPORT Unarchiver : public QObject { Q_OBJECT