[qt_common] fix build on QuaZip <= 1.4 (#2744)
Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: #2744
This commit is contained in:
parent
fff8e2026f
commit
2a5e6f98b6
3 changed files with 82 additions and 8 deletions
|
@ -5,13 +5,14 @@
|
|||
#include "quazipfileinfo.h"
|
||||
|
||||
#include <QDirIterator>
|
||||
#include <quazipfile.h>
|
||||
|
||||
/** This is a modified version of JlCompress **/
|
||||
namespace QtCommon::Compress {
|
||||
|
||||
bool compressDir(QString fileCompressed,
|
||||
QString dir,
|
||||
const JlCompress::Options &options,
|
||||
const Options &options,
|
||||
QtCommon::QtProgressCallback callback)
|
||||
{
|
||||
// Create zip
|
||||
|
@ -56,7 +57,7 @@ bool compressDir(QString fileCompressed,
|
|||
bool compressSubDir(QuaZip *zip,
|
||||
QString dir,
|
||||
QString origDir,
|
||||
const JlCompress::Options &options,
|
||||
const Options &options,
|
||||
std::size_t total,
|
||||
std::size_t &progress,
|
||||
QtProgressCallback callback)
|
||||
|
@ -129,7 +130,7 @@ bool compressSubDir(QuaZip *zip,
|
|||
bool compressFile(QuaZip *zip,
|
||||
QString fileName,
|
||||
QString fileDest,
|
||||
const JlCompress::Options &options,
|
||||
const Options &options,
|
||||
std::size_t total,
|
||||
std::size_t &progress,
|
||||
QtCommon::QtProgressCallback callback)
|
||||
|
|
|
@ -5,12 +5,85 @@
|
|||
|
||||
#include <QDir>
|
||||
#include <QString>
|
||||
#include <JlCompress.h>
|
||||
#include "qt_common/qt_common.h"
|
||||
#include <quazip.h>
|
||||
#include <zlib.h>
|
||||
|
||||
/** This is a modified version of JlCompress **/
|
||||
namespace QtCommon::Compress {
|
||||
|
||||
class Options {
|
||||
public:
|
||||
/**
|
||||
* The enum values refer to the comments in the open function of the quazipfile.h file.
|
||||
*
|
||||
* The value is represented by two hexadecimal characters,
|
||||
* the left character indicating the compression method,
|
||||
* and the right character indicating the compression level.
|
||||
*
|
||||
* method == 0 indicates that the file is not compressed but rather stored as is.
|
||||
* method == 8(Z_DEFLATED) indicates that zlib compression is used.
|
||||
*
|
||||
* A higher value of level indicates a smaller size of the compressed file,
|
||||
* although it also implies more time consumed during the compression process.
|
||||
*/
|
||||
enum CompressionStrategy
|
||||
{
|
||||
/// Storage without compression
|
||||
Storage = 0x00, // Z_NO_COMPRESSION 0
|
||||
/// The fastest compression speed
|
||||
Fastest = 0x81, // Z_BEST_SPEED 1
|
||||
/// Relatively fast compression speed
|
||||
Faster = 0x83,
|
||||
/// Standard compression speed and ratio
|
||||
Standard = 0x86,
|
||||
/// Better compression ratio
|
||||
Better = 0x87,
|
||||
/// The best compression ratio
|
||||
Best = 0x89, // Z_BEST_COMPRESSION 9
|
||||
/// The default compression strategy, according to the open function of quazipfile.h,
|
||||
/// the value of method is Z_DEFLATED, and the value of level is Z_DEFAULT_COMPRESSION -1 (equals lvl 6)
|
||||
Default = 0xff
|
||||
};
|
||||
|
||||
public:
|
||||
explicit Options(const CompressionStrategy& strategy)
|
||||
: m_compressionStrategy(strategy) {}
|
||||
|
||||
explicit Options(const QDateTime& dateTime = QDateTime(), const CompressionStrategy& strategy = Default)
|
||||
: m_dateTime(dateTime), m_compressionStrategy(strategy) {}
|
||||
|
||||
QDateTime getDateTime() const {
|
||||
return m_dateTime;
|
||||
}
|
||||
|
||||
void setDateTime(const QDateTime &dateTime) {
|
||||
m_dateTime = dateTime;
|
||||
}
|
||||
|
||||
CompressionStrategy getCompressionStrategy() const {
|
||||
return m_compressionStrategy;
|
||||
}
|
||||
|
||||
int getCompressionMethod() const {
|
||||
return m_compressionStrategy != Default ? m_compressionStrategy >> 4 : Z_DEFLATED;
|
||||
}
|
||||
|
||||
int getCompressionLevel() const {
|
||||
return m_compressionStrategy != Default ? m_compressionStrategy & 0x0f : Z_DEFAULT_COMPRESSION;
|
||||
}
|
||||
|
||||
void setCompressionStrategy(const CompressionStrategy &strategy) {
|
||||
m_compressionStrategy = strategy;
|
||||
}
|
||||
|
||||
private:
|
||||
// If set, used as last modified on file inside the archive.
|
||||
// If compressing a directory, used for all files.
|
||||
QDateTime m_dateTime;
|
||||
CompressionStrategy m_compressionStrategy;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Compress an entire directory and report its progress.
|
||||
* @param fileCompressed Destination file
|
||||
|
@ -20,14 +93,14 @@ namespace QtCommon::Compress {
|
|||
*/
|
||||
bool compressDir(QString fileCompressed,
|
||||
QString dir,
|
||||
const JlCompress::Options& options = JlCompress::Options(),
|
||||
const Options& options = Options(),
|
||||
QtCommon::QtProgressCallback callback = {});
|
||||
|
||||
// Internal //
|
||||
bool compressSubDir(QuaZip *zip,
|
||||
QString dir,
|
||||
QString origDir,
|
||||
const JlCompress::Options &options,
|
||||
const Options &options,
|
||||
std::size_t total,
|
||||
std::size_t &progress,
|
||||
QtCommon::QtProgressCallback callback);
|
||||
|
@ -35,7 +108,7 @@ bool compressSubDir(QuaZip *zip,
|
|||
bool compressFile(QuaZip *zip,
|
||||
QString fileName,
|
||||
QString fileDest,
|
||||
const JlCompress::Options &options,
|
||||
const Options &options,
|
||||
std::size_t total,
|
||||
std::size_t &progress,
|
||||
QtCommon::QtProgressCallback callback);
|
||||
|
|
|
@ -425,7 +425,7 @@ void ExportDataDir(FrontendCommon::DataManager::DataDir data_dir,
|
|||
QFuture<bool> future = QtConcurrent::run([=]() {
|
||||
return QtCommon::Compress::compressDir(zip_dump_location,
|
||||
QString::fromStdString(dir),
|
||||
JlCompress::Options(),
|
||||
QtCommon::Compress::Options(),
|
||||
progress_callback);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue