14 using namespace swift::config;
18 QByteArray CCompressUtils::lengthHeader(qint32 size)
21 QByteArray lengthHeader;
22 QDataStream stream(&lengthHeader, QIODevice::WriteOnly);
23 stream.setByteOrder(QDataStream::BigEndian);
25 Q_ASSERT_X(lengthHeader.size() == 4, Q_FUNC_INFO,
"Wrong header size");
35 executable += CSwiftDirectories::binDirectory();
38 executable += QStringLiteral(
"7za");
42 bool CCompressUtils::zip7Uncompress(
const QString &file,
const QString &directory, QStringList *stdOutAndError)
44 const QFileInfo fi(file);
45 if (!fi.exists()) {
return false; }
46 if (!CCompressUtils::hasZip7(stdOutAndError)) {
return false; }
49 const QString d = directory.isEmpty() ? directory : win ? CFileUtils::toWindowsLocalPath(directory) : directory;
50 const QString f = win ? CFileUtils::toWindowsLocalPath(file) : file;
57 if (!d.isEmpty()) { args <<
"-o" + d; }
62 zipProcess.setArguments(args);
63 return runZip7Process(&zipProcess, stdOutAndError);
66 bool CCompressUtils::hasZip7(QStringList *stdOutAndError)
75 zipProcess.setArguments(args);
76 return runZip7Process(&zipProcess, stdOutAndError);
79 bool CCompressUtils::whichZip7(QStringList *stdOutAndError)
81 const QString cmd(
"which 7za");
83 zipProcess.start(cmd);
84 if (!zipProcess.waitForStarted()) {
return false; }
85 if (!zipProcess.waitForFinished()) {
return false; }
87 const QString pStdout = zipProcess.readAllStandardOutput();
88 const QString pStderr = zipProcess.readAllStandardError();
91 stdOutAndError->clear();
92 stdOutAndError->push_back(pStdout);
93 stdOutAndError->push_back(pStderr);
95 const int r = zipProcess.exitCode();
96 return r == 0 && pStdout.contains(
"7za", Qt::CaseInsensitive);
99 bool CCompressUtils::runZip7Process(QProcess *zipProcess, QStringList *stdOutAndError)
104 if (!zipProcess->waitForStarted())
108 stdOutAndError->push_back(
"7za");
109 stdOutAndError->push_back(
"Command not found");
115 if (!zipProcess->waitForFinished())
119 stdOutAndError->push_back(
"7za");
120 stdOutAndError->push_back(
"Process did not finish.");
127 stdOutAndError->clear();
128 const QString pStdout = zipProcess->readAllStandardOutput();
129 const QString pStderr = zipProcess->readAllStandardError();
130 stdOutAndError->push_back(pStdout);
131 stdOutAndError->push_back(pStderr);
134 return zipProcess->exitStatus() == QProcess::NormalExit;
static constexpr bool isRunningOnMacOSPlatform()
Running on MacOS platform?
static constexpr bool isRunningOnWindowsNtPlatform()
Running on Windows NT platform?
static constexpr bool isRunningOnLinuxPlatform()
Running on Linux platform?
static QByteArray lengthHeader(qint32 size)
Length header.
Free functions in swift::misc.
QString getZip7Executable()
Returns the platform specific 7za command.