Bundle LZMA SDK for .edz extraction; drop 7z CLI dependency (M3)

Replaces the QProcess->7z shim with the public-domain LZMA SDK (23.01) 7-Zip
reader, vendored under sources/import/edz/lzma/ (decode-only subset). New
edzsevenzip.cpp wraps SzArEx_Open/SzArEx_Extract and writes entries via Qt, so
EdzArchive no longer needs an external 7-Zip at runtime. Enables the C language
in CMake for the vendored sources.

Verified: the bundled decoder extracts all three ifm sample .edz and the
generated elements still match the Python oracle exactly (byte-correct decode),
with no 7z on the path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Shane Ringrose
2026-06-20 07:49:14 +12:00
parent f4ff6c81f9
commit e4b4ba875b
64 changed files with 14706 additions and 83 deletions
+3 -74
View File
@@ -17,11 +17,11 @@
*/
#include "edzarchive.h"
#include "edzsevenzip.h"
#include <QDir>
#include <QDirIterator>
#include <QFileInfo>
#include <QProcess>
#include <QStandardPaths>
#include <QTemporaryDir>
EdzArchive::EdzArchive() = default;
@@ -48,7 +48,7 @@ bool EdzArchive::extract(const QString &edz_path)
return false;
}
if (!extractWithSevenZipCli(fi.absoluteFilePath(), m_dir->path())) {
if (!sevenZipExtract(fi.absoluteFilePath(), m_dir->path(), m_error)) {
return false;
}
@@ -81,74 +81,3 @@ QString EdzArchive::errorString() const
{
return m_error;
}
/**
M0 backend: run a 7-Zip command-line tool to extract the archive.
Placeholder for a bundled decompressor in a later milestone.
*/
bool EdzArchive::extractWithSevenZipCli(const QString &edz_path,
const QString &dest)
{
const QString exe = findSevenZip();
if (exe.isEmpty()) {
m_error = QStringLiteral(
"7-Zip not found. A .edz is a 7z archive; install 7-Zip or "
"put 7z on PATH.");
return false;
}
QProcess proc;
proc.start(exe, QStringList{QStringLiteral("x"), edz_path,
QStringLiteral("-o%1").arg(dest),
QStringLiteral("-y")});
if (!proc.waitForStarted()) {
m_error = QStringLiteral("Could not start 7-Zip: %1").arg(exe);
return false;
}
proc.waitForFinished(-1);
if (proc.exitStatus() != QProcess::NormalExit || proc.exitCode() != 0) {
QString detail;
const QString out = QString::fromLocal8Bit(proc.readAllStandardOutput());
for (const QString &line : out.split('\n')) {
const QString t = line.trimmed();
if (t.startsWith(QStringLiteral("ERROR"))
|| t.startsWith(QStringLiteral("Cannot"))
|| t.startsWith(QStringLiteral("Can't"))) {
detail += (detail.isEmpty() ? QString() : QStringLiteral(" ")) + t;
}
}
if (detail.isEmpty()) {
detail = QStringLiteral("7-Zip exit code %1").arg(proc.exitCode());
}
m_error = QStringLiteral("7-Zip could not extract the archive: %1")
.arg(detail);
return false;
}
return true;
}
/** Locate a 7-Zip executable: PATH first, then the usual install locations. */
QString EdzArchive::findSevenZip()
{
for (const QString &name : {QStringLiteral("7z"), QStringLiteral("7za"),
QStringLiteral("7zr")}) {
const QString found = QStandardPaths::findExecutable(name);
if (!found.isEmpty()) {
return found;
}
}
const QStringList candidates {
QStringLiteral("C:/Program Files/7-Zip/7z.exe"),
QStringLiteral("C:/Program Files (x86)/7-Zip/7z.exe"),
QStringLiteral("/usr/bin/7z"),
QStringLiteral("/usr/local/bin/7z"),
QStringLiteral("/opt/homebrew/bin/7z"),
};
for (const QString &c : candidates) {
if (QFileInfo::exists(c)) {
return c;
}
}
return QString();
}