Utils: check windows registry for archive tools

Change-Id: I2acff0347a0bd04a808b5f4a0049263168e11f51
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
David Schulz
2020-06-12 09:07:19 +02:00
parent 29e60f0741
commit 72b35aa12b

View File

@@ -34,6 +34,7 @@
#include <QDir> #include <QDir>
#include <QPushButton> #include <QPushButton>
#include <QSettings>
#include <QTimer> #include <QTimer>
namespace { namespace {
@@ -43,28 +44,66 @@ struct Tool
QString executable; QString executable;
QStringList arguments; QStringList arguments;
QStringList supportedMimeTypes; QStringList supportedMimeTypes;
QStringList additionalSearchDirs;
}; };
const QVector<Tool> sTools = { static const QVector<Tool> &sTools()
{{"unzip"}, {"-o", "%{src}", "-d", "%{dest}"}, {"application/zip"}}, {
{{"7z"}, {"x", "-o%{dest}", "-y", "%{src}"}, {"application/zip", "application/x-7z-compressed"}}, static QVector<Tool> tools;
{{"tar"}, if (tools.isEmpty()) {
tools << Tool{{"unzip"}, {"-o", "%{src}", "-d", "%{dest}"}, {"application/zip"}, {}};
QStringList additional7ZipDirs;
if (Utils::HostOsInfo::isWindowsHost()) {
const QSettings settings64("HKEY_CURRENT_USER\\Software\\7-Zip",
QSettings::Registry64Format);
const QSettings settings32("HKEY_CURRENT_USER\\Software\\7-Zip",
QSettings::Registry32Format);
additional7ZipDirs << settings64.value("Path").toString()
<< settings32.value("Path").toString();
}
tools << Tool{{"7z"},
{"x", "-o%{dest}", "-y", "%{src}"},
{"application/zip", "application/x-7z-compressed"},
additional7ZipDirs};
tools << Tool{{"tar"},
{"xvf", "%{src}"}, {"xvf", "%{src}"},
{"application/zip", "application/x-tar", "application/x-7z-compressed"}}, {"application/zip", "application/x-tar", "application/x-7z-compressed"},
{{"tar"}, {"xvzf", "%{src}"}, {"application/x-compressed-tar"}}, {}};
{{"tar"}, {"xvJf", "%{src}"}, {"application/x-xz-compressed-tar"}}, tools << Tool{{"tar"}, {"xvzf", "%{src}"}, {"application/x-compressed-tar"}, {}};
{{"tar"}, {"xvjf", "%{src}"}, {"application/x-bzip-compressed-tar"}}, tools << Tool{{"tar"}, {"xvJf", "%{src}"}, {"application/x-xz-compressed-tar"}, {}};
{{"cmake"}, tools << Tool{{"tar"}, {"xvjf", "%{src}"}, {"application/x-bzip-compressed-tar"}, {}};
QStringList additionalCMakeDirs;
if (Utils::HostOsInfo::isWindowsHost()) {
const QSettings settings64("HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\CMake",
QSettings::Registry64Format);
const QSettings settings32("HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\CMake",
QSettings::Registry32Format);
additionalCMakeDirs << settings64.value("InstallDir").toString()
<< settings32.value("InstallDir").toString();
}
tools << Tool{{"cmake"},
{"-E", "tar", "xvf", "%{src}"}, {"-E", "tar", "xvf", "%{src}"},
{"application/zip", "application/x-tar", "application/x-7z-compressed"}}, {"application/zip", "application/x-tar", "application/x-7z-compressed"},
{{"cmake"}, {"-E", "tar", "xvzf", "%{src}"}, {"application/x-compressed-tar"}}, additionalCMakeDirs};
{{"cmake"}, {"-E", "tar", "xvJf", "%{src}"}, {"application/x-xz-compressed-tar"}}, tools << Tool{{"cmake"},
{{"cmake"}, {"-E", "tar", "xvjf", "%{src}"}, {"application/x-bzip-compressed-tar"}}, {"-E", "tar", "xvzf", "%{src}"},
}; {"application/x-compressed-tar"},
additionalCMakeDirs};
tools << Tool{{"cmake"},
{"-E", "tar", "xvJf", "%{src}"},
{"application/x-xz-compressed-tar"},
additionalCMakeDirs};
tools << Tool{{"cmake"},
{"-E", "tar", "xvjf", "%{src}"},
{"application/x-bzip-compressed-tar"},
additionalCMakeDirs};
}
return tools;
}
static QVector<Tool> toolsForMimeType(const Utils::MimeType &mimeType) static QVector<Tool> toolsForMimeType(const Utils::MimeType &mimeType)
{ {
return Utils::filtered(sTools, [mimeType](const Tool &tool) { return Utils::filtered(sTools(), [mimeType](const Tool &tool) {
return Utils::anyOf(tool.supportedMimeTypes, return Utils::anyOf(tool.supportedMimeTypes,
[mimeType](const QString &mt) { return mimeType.inherits(mt); }); [mimeType](const QString &mt) { return mimeType.inherits(mt); });
}); });
@@ -77,9 +116,10 @@ static QVector<Tool> toolsForFilePath(const Utils::FilePath &fp)
static Utils::optional<Tool> resolveTool(const Tool &tool) static Utils::optional<Tool> resolveTool(const Tool &tool)
{ {
const QString executable = Utils::Environment::systemEnvironment() const QString executable
.searchInPath( = Utils::Environment::systemEnvironment()
Utils::HostOsInfo::withExecutableSuffix(tool.executable)) .searchInPath(Utils::HostOsInfo::withExecutableSuffix(tool.executable),
Utils::transform(tool.additionalSearchDirs, &Utils::FilePath::fromString))
.toString(); .toString();
Tool resolvedTool = tool; Tool resolvedTool = tool;
resolvedTool.executable = executable; resolvedTool.executable = executable;