13 #include <sys/sysinfo.h> 17 #include <mach/mach.h> 21 #include <sys/mount.h> 22 #include <sys/sysctl.h> 27 #include <QStringList> 41 int64_t &total, int64_t &used)
44 int64_t freespace = -1;
45 QByteArray cstr = file_on_disk.toLocal8Bit();
53 if ((
statfs(cstr.constData(), &statbuf) == 0) &&
63 freespace = freespace >> 10;
65 used = total - freespace;
71 bool extractZIP(
const QString &zipFile,
const QString &outDir)
78 LOG(VB_GENERAL, LOG_ERR,
79 QString(
"extractZIP(): Unable to open ZIP file %1")
88 LOG(VB_GENERAL, LOG_ERR,
89 QString(
"extractZIP(): Error extracting ZIP file %1")
99 bool gzipFile(
const QString &inFilename,
const QString &gzipFilename)
101 QFile infile(inFilename);
102 QFile outfile(gzipFilename);
104 if (!infile.open(QIODevice::ReadOnly))
106 LOG(VB_GENERAL, LOG_ERR, QString(
"gzipFile(): Error opening file for reading '%1'").arg(inFilename));
110 if (!outfile.open(QIODevice::WriteOnly))
112 LOG(VB_GENERAL, LOG_ERR, QString(
"gzipFile(): Error opening file for writing '%1'").arg(gzipFilename));
117 QByteArray uncompressedData = infile.readAll();
118 QByteArray compressedData =
gzipCompress(uncompressedData);
120 if (!outfile.write(compressedData))
122 LOG(VB_GENERAL, LOG_ERR, QString(
"gzipFile(): Error while writing to '%1'").arg(gzipFilename));
134 bool gunzipFile(
const QString &gzipFilename,
const QString &outFilename)
136 QFile infile(gzipFilename);
137 QFile outfile(outFilename);
139 if (!infile.open(QIODevice::ReadOnly))
141 LOG(VB_GENERAL, LOG_ERR, QString(
"gunzipFile(): Error opening file for reading '%1'").arg(gzipFilename));
145 if (!outfile.open(QIODevice::WriteOnly))
147 LOG(VB_GENERAL, LOG_ERR, QString(
"gunzipFile(): Error opening file for writing '%1'").arg(outFilename));
152 QByteArray compressedData = infile.readAll();
155 if (outfile.write(uncompressedData) < uncompressedData.size())
157 LOG(VB_GENERAL, LOG_ERR, QString(
"gunzipFile(): Error while writing to '%1'").arg(outFilename));
171 if (data.length() == 0)
174 static constexpr
int kChunkSize = 1024;
175 char out[kChunkSize];
183 strm.avail_in = data.length();
184 strm.next_in = (Bytef*)(data.data());
186 int ret = deflateInit2(&strm,
187 Z_DEFAULT_COMPRESSION,
191 Z_DEFAULT_STRATEGY );
200 strm.avail_out = kChunkSize;
201 strm.next_out = (Bytef*)(out);
203 ret = deflate(&strm, Z_FINISH);
205 Q_ASSERT(ret != Z_STREAM_ERROR);
212 (void)deflateEnd(&strm);
216 result.append(out, kChunkSize - strm.avail_out);
218 while (strm.avail_out == 0);
229 if (data.length() == 0)
232 static constexpr
int kChunkSize = 1024;
233 char out[kChunkSize];
241 strm.avail_in = data.length();
242 strm.next_in = (Bytef*)(data.data());
244 int ret = inflateInit2(&strm, 15 + 16);
253 strm.avail_out = kChunkSize;
254 strm.next_out = (Bytef*)out;
255 ret = inflate(&strm, Z_NO_FLUSH);
257 Q_ASSERT(ret != Z_STREAM_ERROR);
264 (void) deflateEnd(&strm);
268 result.append(out, kChunkSize - strm.avail_out);
270 while (strm.avail_out == 0);
272 (void) inflateEnd(& strm);
278 const QString &storageGroup,
281 QStringList strlist(cmd);
283 strlist << storageGroup;
288 if (!ok || strlist.size() < 2 || strlist[0] !=
"OK")
290 LOG(VB_GENERAL, LOG_ERR,
291 "downloadRemoteFile(): " + cmd +
" returned ERROR!");
299 const QString &storageGroup,
306 const QString &storageGroup,
bool gzipFile(const QString &inFilename, const QString &gzipFilename)
ErrorCode openArchive(const QString &filename)
ErrorCode extractAll(const QString &dirname, ExtractionOptions options=ExtractPaths)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
bool extractZIP(const QString &zipFile, const QString &outDir)
bool SendReceiveStringList(QStringList &strlist, bool quickTimeout=false, bool block=true)
Send a message to the backend and wait for a response.
int statfs(const char *path, struct statfs *buffer)
bool gunzipFile(const QString &gzipFilename, const QString &outFilename)
static QString downloadRemoteFile(const QString &cmd, const QString &url, const QString &storageGroup, const QString &filename)
PKZip 2.0 file decompression. Compatibility with later versions is not ensured as they may use unsupp...
QString RemoteDownloadFileNow(const QString &url, const QString &storageGroup, const QString &filename)
QByteArray gzipUncompress(const QByteArray &data)
QByteArray gzipCompress(const QByteArray &data)
int64_t getDiskSpace(const QString &file_on_disk, int64_t &total, int64_t &used)
QString RemoteDownloadFile(const QString &url, const QString &storageGroup, const QString &filename)
#define LOG(_MASK_, _LEVEL_, _STRING_)