forked from qt-creator/qt-creator
Utils: Get rid of Archive
Use Unarchiver instead. Change-Id: I7544b36ca11578d7ae7eb8571e6fe823cf74dee1 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -98,87 +98,6 @@ static std::optional<Tool> resolveTool(const Tool &tool)
|
|||||||
return executable.isEmpty() ? std::nullopt : std::make_optional(resolvedTool);
|
return executable.isEmpty() ? std::nullopt : std::make_optional(resolvedTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::optional<Tool> unzipTool(const FilePath &src, const FilePath &dest)
|
|
||||||
{
|
|
||||||
const QVector<Tool> tools = toolsForFilePath(src);
|
|
||||||
for (const Tool &tool : tools) {
|
|
||||||
const std::optional<Tool> 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<Tool> 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<QStringList>(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> 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 <cmd> in <workingdirectory>")
|
|
||||||
.arg(m_commandLine.toUserOutput(), m_workingDirectory.toUserOutput()));
|
|
||||||
|
|
||||||
m_process->setCommand(m_commandLine);
|
|
||||||
m_process->setWorkingDirectory(m_workingDirectory);
|
|
||||||
m_process->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
expected_str<Unarchiver::SourceAndCommand> Unarchiver::sourceAndCommand(const FilePath &sourceFile)
|
expected_str<Unarchiver::SourceAndCommand> Unarchiver::sourceAndCommand(const FilePath &sourceFile)
|
||||||
{
|
{
|
||||||
const QVector<Tool> tools = toolsForFilePath(sourceFile);
|
const QVector<Tool> tools = toolsForFilePath(sourceFile);
|
||||||
|
@@ -14,28 +14,6 @@
|
|||||||
|
|
||||||
namespace Utils {
|
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<Process> m_process;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT Unarchiver : public QObject
|
class QTCREATOR_UTILS_EXPORT Unarchiver : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Reference in New Issue
Block a user