mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Adjust to rebase.
Took 7 minutes
This commit is contained in:
parent
e08f28b110
commit
be00edd581
14 changed files with 1315 additions and 1283 deletions
|
|
@ -32,6 +32,7 @@ set(cockatrice_SOURCES
|
|||
src/interface/widgets/dialogs/dlg_forgot_password_challenge.cpp
|
||||
src/interface/widgets/dialogs/dlg_forgot_password_request.cpp
|
||||
src/interface/widgets/dialogs/dlg_forgot_password_reset.cpp
|
||||
src/interface/widgets/dialogs/dlg_import_precons.cpp
|
||||
src/interface/widgets/dialogs/dlg_load_deck.cpp
|
||||
src/interface/widgets/dialogs/dlg_load_deck_from_clipboard.cpp
|
||||
src/interface/widgets/dialogs/dlg_load_deck_from_website.cpp
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
#include "dlg_import_precons.h"
|
||||
|
||||
#include "../deck/deck_loader.h"
|
||||
#include "../../deck_loader/deck_loader.h"
|
||||
#include "../settings/cache_settings.h"
|
||||
#include "libcockatrice/deck_list/deck_list_card_node.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
|
|
@ -11,7 +12,7 @@
|
|||
#include <QNetworkReply>
|
||||
#include <QPushButton>
|
||||
#include <QTemporaryDir>
|
||||
#include <decklist.h>
|
||||
#include <libcockatrice/deck_list/deck_list.h>
|
||||
|
||||
#ifdef HAS_LZMA
|
||||
#include "../../src/utility/external/lzma/decompress.h"
|
||||
|
|
@ -309,7 +310,7 @@ bool LoadPreconsPage::parsePreconsFromByteArray(const QByteArray &data, QString
|
|||
|
||||
qInfo() << "Importing '" << deckName << "' from" << shortName;
|
||||
|
||||
auto *precon = new DeckLoader();
|
||||
auto *precon = new DeckLoader(this);
|
||||
|
||||
for (const auto &cardVal : mainBoard) {
|
||||
QJsonObject cardObj = cardVal.toObject();
|
||||
|
|
@ -319,20 +320,20 @@ bool LoadPreconsPage::parsePreconsFromByteArray(const QByteArray &data, QString
|
|||
int count = cardObj.value("count").toInt();
|
||||
QString scryfallId = cardObj.value("identifiers").toObject().value("scryfallId").toString();
|
||||
|
||||
DecklistCardNode *addedCard = precon->addCard(name, "main", -1, setCode, number, scryfallId);
|
||||
DecklistCardNode *addedCard = precon->getDeckList()->addCard(name, "main", -1, setCode, number, scryfallId);
|
||||
if (count != 1) {
|
||||
addedCard->setNumber(count);
|
||||
}
|
||||
}
|
||||
|
||||
precon->setName(deckName);
|
||||
precon->getDeckList()->setName(deckName);
|
||||
|
||||
QJsonArray commanderArray = preconData.value("commander").toArray();
|
||||
if (!commanderArray.isEmpty()) {
|
||||
QJsonObject commanderObj = commanderArray.first().toObject();
|
||||
QString commanderName = commanderObj.value("name").toString();
|
||||
QString commanderId = commanderObj.value("identifiers").toObject().value("scryfallId").toString();
|
||||
precon->setBannerCard(QPair<QString, QString>(commanderName, commanderId));
|
||||
precon->getDeckList()->setBannerCard({commanderName, commanderId});
|
||||
} else {
|
||||
qInfo() << "No commander data found.";
|
||||
}
|
||||
|
|
@ -340,7 +341,7 @@ bool LoadPreconsPage::parsePreconsFromByteArray(const QByteArray &data, QString
|
|||
QString dirPath = QDir::cleanPath(folderPath + QDir::separator() + deckType + QDir::separator() +
|
||||
QString::number(releaseYear) + QDir::separator() + shortName);
|
||||
|
||||
QString fullPath = QDir(dirPath).filePath(precon->getName());
|
||||
QString fullPath = QDir(dirPath).filePath(precon->getDeckList()->getName());
|
||||
|
||||
QDir dir;
|
||||
if (!dir.exists(dirPath)) {
|
||||
|
|
@ -350,7 +351,7 @@ bool LoadPreconsPage::parsePreconsFromByteArray(const QByteArray &data, QString
|
|||
}
|
||||
}
|
||||
|
||||
if (precon->getCardList().length() > 1) {
|
||||
if (precon->getDeckList()->getCardList().length() > 1) {
|
||||
precon->saveToFile(fullPath + ".cod", DeckLoader::CockatriceFormat);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
#include "../main.h"
|
||||
#include "logger.h"
|
||||
#include "version_string.h"
|
||||
#include "widgets/dialogs/dlg_import_precons.h"
|
||||
#include "widgets/utility/get_text_with_max.h"
|
||||
|
||||
#include <QAction>
|
||||
|
|
|
|||
394
cockatrice/src/utility/external/lzma/decompress.cpp
vendored
394
cockatrice/src/utility/external/lzma/decompress.cpp
vendored
|
|
@ -9,242 +9,236 @@
|
|||
* You can do whatever you want with this file.
|
||||
*/
|
||||
|
||||
|
||||
#include <lzma.h>
|
||||
#include <QDebug>
|
||||
|
||||
#include "decompress.h"
|
||||
|
||||
XzDecompressor::XzDecompressor(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
#include <QDebug>
|
||||
#include <lzma.h>
|
||||
|
||||
XzDecompressor::XzDecompressor(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool XzDecompressor::decompress(QBuffer *in, QBuffer *out)
|
||||
{
|
||||
lzma_stream strm = LZMA_STREAM_INIT;
|
||||
bool success;
|
||||
lzma_stream strm = LZMA_STREAM_INIT;
|
||||
bool success;
|
||||
|
||||
if (!init_decoder(&strm)) {
|
||||
return false;
|
||||
}
|
||||
if (!init_decoder(&strm)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
success = internal_decompress(&strm, in, out);
|
||||
success = internal_decompress(&strm, in, out);
|
||||
|
||||
// Free the memory allocated for the decoder. This only needs to be
|
||||
// done after the last file.
|
||||
lzma_end(&strm);
|
||||
// Free the memory allocated for the decoder. This only needs to be
|
||||
// done after the last file.
|
||||
lzma_end(&strm);
|
||||
|
||||
return success;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool XzDecompressor::init_decoder(lzma_stream *strm)
|
||||
{
|
||||
// Initialize a .xz decoder. The decoder supports a memory usage limit
|
||||
// and a set of flags.
|
||||
//
|
||||
// The memory usage of the decompressor depends on the settings used
|
||||
// to compress a .xz file. It can vary from less than a megabyte to
|
||||
// a few gigabytes, but in practice (at least for now) it rarely
|
||||
// exceeds 65 MiB because that's how much memory is required to
|
||||
// decompress files created with "xz -9". Settings requiring more
|
||||
// memory take extra effort to use and don't (at least for now)
|
||||
// provide significantly better compression in most cases.
|
||||
//
|
||||
// Memory usage limit is useful if it is important that the
|
||||
// decompressor won't consume gigabytes of memory. The need
|
||||
// for limiting depends on the application. In this example,
|
||||
// no memory usage limiting is used. This is done by setting
|
||||
// the limit to UINT64_MAX.
|
||||
//
|
||||
// The .xz format allows concatenating compressed files as is:
|
||||
//
|
||||
// echo foo | xz > foobar.xz
|
||||
// echo bar | xz >> foobar.xz
|
||||
//
|
||||
// When decompressing normal standalone .xz files, LZMA_CONCATENATED
|
||||
// should always be used to support decompression of concatenated
|
||||
// .xz files. If LZMA_CONCATENATED isn't used, the decoder will stop
|
||||
// after the first .xz stream. This can be useful when .xz data has
|
||||
// been embedded inside another file format.
|
||||
//
|
||||
// Flags other than LZMA_CONCATENATED are supported too, and can
|
||||
// be combined with bitwise-or. See lzma/container.h
|
||||
// (src/liblzma/api/lzma/container.h in the source package or e.g.
|
||||
// /usr/include/lzma/container.h depending on the install prefix)
|
||||
// for details.
|
||||
lzma_ret ret = lzma_stream_decoder(
|
||||
strm, UINT64_MAX, LZMA_CONCATENATED);
|
||||
// Initialize a .xz decoder. The decoder supports a memory usage limit
|
||||
// and a set of flags.
|
||||
//
|
||||
// The memory usage of the decompressor depends on the settings used
|
||||
// to compress a .xz file. It can vary from less than a megabyte to
|
||||
// a few gigabytes, but in practice (at least for now) it rarely
|
||||
// exceeds 65 MiB because that's how much memory is required to
|
||||
// decompress files created with "xz -9". Settings requiring more
|
||||
// memory take extra effort to use and don't (at least for now)
|
||||
// provide significantly better compression in most cases.
|
||||
//
|
||||
// Memory usage limit is useful if it is important that the
|
||||
// decompressor won't consume gigabytes of memory. The need
|
||||
// for limiting depends on the application. In this example,
|
||||
// no memory usage limiting is used. This is done by setting
|
||||
// the limit to UINT64_MAX.
|
||||
//
|
||||
// The .xz format allows concatenating compressed files as is:
|
||||
//
|
||||
// echo foo | xz > foobar.xz
|
||||
// echo bar | xz >> foobar.xz
|
||||
//
|
||||
// When decompressing normal standalone .xz files, LZMA_CONCATENATED
|
||||
// should always be used to support decompression of concatenated
|
||||
// .xz files. If LZMA_CONCATENATED isn't used, the decoder will stop
|
||||
// after the first .xz stream. This can be useful when .xz data has
|
||||
// been embedded inside another file format.
|
||||
//
|
||||
// Flags other than LZMA_CONCATENATED are supported too, and can
|
||||
// be combined with bitwise-or. See lzma/container.h
|
||||
// (src/liblzma/api/lzma/container.h in the source package or e.g.
|
||||
// /usr/include/lzma/container.h depending on the install prefix)
|
||||
// for details.
|
||||
lzma_ret ret = lzma_stream_decoder(strm, UINT64_MAX, LZMA_CONCATENATED);
|
||||
|
||||
// Return successfully if the initialization went fine.
|
||||
if (ret == LZMA_OK)
|
||||
return true;
|
||||
// Return successfully if the initialization went fine.
|
||||
if (ret == LZMA_OK)
|
||||
return true;
|
||||
|
||||
// Something went wrong. The possible errors are documented in
|
||||
// lzma/container.h (src/liblzma/api/lzma/container.h in the source
|
||||
// package or e.g. /usr/include/lzma/container.h depending on the
|
||||
// install prefix).
|
||||
//
|
||||
// Note that LZMA_MEMLIMIT_ERROR is never possible here. If you
|
||||
// specify a very tiny limit, the error will be delayed until
|
||||
// the first headers have been parsed by a call to lzma_code().
|
||||
const char *msg;
|
||||
switch (ret) {
|
||||
case LZMA_MEM_ERROR:
|
||||
msg = "Memory allocation failed";
|
||||
break;
|
||||
// Something went wrong. The possible errors are documented in
|
||||
// lzma/container.h (src/liblzma/api/lzma/container.h in the source
|
||||
// package or e.g. /usr/include/lzma/container.h depending on the
|
||||
// install prefix).
|
||||
//
|
||||
// Note that LZMA_MEMLIMIT_ERROR is never possible here. If you
|
||||
// specify a very tiny limit, the error will be delayed until
|
||||
// the first headers have been parsed by a call to lzma_code().
|
||||
const char *msg;
|
||||
switch (ret) {
|
||||
case LZMA_MEM_ERROR:
|
||||
msg = "Memory allocation failed";
|
||||
break;
|
||||
|
||||
case LZMA_OPTIONS_ERROR:
|
||||
msg = "Unsupported decompressor flags";
|
||||
break;
|
||||
case LZMA_OPTIONS_ERROR:
|
||||
msg = "Unsupported decompressor flags";
|
||||
break;
|
||||
|
||||
default:
|
||||
// This is most likely LZMA_PROG_ERROR indicating a bug in
|
||||
// this program or in liblzma. It is inconvenient to have a
|
||||
// separate error message for errors that should be impossible
|
||||
// to occur, but knowing the error code is important for
|
||||
// debugging. That's why it is good to print the error code
|
||||
// at least when there is no good error message to show.
|
||||
msg = "Unknown error, possibly a bug";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// This is most likely LZMA_PROG_ERROR indicating a bug in
|
||||
// this program or in liblzma. It is inconvenient to have a
|
||||
// separate error message for errors that should be impossible
|
||||
// to occur, but knowing the error code is important for
|
||||
// debugging. That's why it is good to print the error code
|
||||
// at least when there is no good error message to show.
|
||||
msg = "Unknown error, possibly a bug";
|
||||
break;
|
||||
}
|
||||
|
||||
qDebug() << "Error initializing the decoder:" << msg << "(error code " << ret << ")";
|
||||
return false;
|
||||
qDebug() << "Error initializing the decoder:" << msg << "(error code " << ret << ")";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool XzDecompressor::internal_decompress(lzma_stream *strm, QBuffer *in, QBuffer *out)
|
||||
{
|
||||
// When LZMA_CONCATENATED flag was used when initializing the decoder,
|
||||
// we need to tell lzma_code() when there will be no more input.
|
||||
// This is done by setting action to LZMA_FINISH instead of LZMA_RUN
|
||||
// in the same way as it is done when encoding.
|
||||
//
|
||||
// When LZMA_CONCATENATED isn't used, there is no need to use
|
||||
// LZMA_FINISH to tell when all the input has been read, but it
|
||||
// is still OK to use it if you want. When LZMA_CONCATENATED isn't
|
||||
// used, the decoder will stop after the first .xz stream. In that
|
||||
// case some unused data may be left in strm->next_in.
|
||||
lzma_action action = LZMA_RUN;
|
||||
// When LZMA_CONCATENATED flag was used when initializing the decoder,
|
||||
// we need to tell lzma_code() when there will be no more input.
|
||||
// This is done by setting action to LZMA_FINISH instead of LZMA_RUN
|
||||
// in the same way as it is done when encoding.
|
||||
//
|
||||
// When LZMA_CONCATENATED isn't used, there is no need to use
|
||||
// LZMA_FINISH to tell when all the input has been read, but it
|
||||
// is still OK to use it if you want. When LZMA_CONCATENATED isn't
|
||||
// used, the decoder will stop after the first .xz stream. In that
|
||||
// case some unused data may be left in strm->next_in.
|
||||
lzma_action action = LZMA_RUN;
|
||||
|
||||
uint8_t inbuf[BUFSIZ];
|
||||
uint8_t outbuf[BUFSIZ];
|
||||
qint64 bytesAvailable;
|
||||
uint8_t inbuf[BUFSIZ];
|
||||
uint8_t outbuf[BUFSIZ];
|
||||
qint64 bytesAvailable;
|
||||
|
||||
strm->next_in = NULL;
|
||||
strm->avail_in = 0;
|
||||
strm->next_out = outbuf;
|
||||
strm->avail_out = sizeof(outbuf);
|
||||
while (true) {
|
||||
if (strm->avail_in == 0) {
|
||||
strm->next_in = inbuf;
|
||||
bytesAvailable = in->bytesAvailable();
|
||||
if(bytesAvailable == 0) {
|
||||
// Once the end of the input file has been reached,
|
||||
// we need to tell lzma_code() that no more input
|
||||
// will be coming. As said before, this isn't required
|
||||
// if the LZMA_CONCATENATED flag isn't used when
|
||||
// initializing the decoder.
|
||||
action = LZMA_FINISH;
|
||||
} else if(bytesAvailable >= BUFSIZ) {
|
||||
in->read((char*) inbuf, BUFSIZ);
|
||||
strm->avail_in = BUFSIZ;
|
||||
} else {
|
||||
in->read((char*) inbuf, bytesAvailable);
|
||||
strm->avail_in = bytesAvailable;
|
||||
}
|
||||
}
|
||||
strm->next_in = NULL;
|
||||
strm->avail_in = 0;
|
||||
strm->next_out = outbuf;
|
||||
strm->avail_out = sizeof(outbuf);
|
||||
while (true) {
|
||||
if (strm->avail_in == 0) {
|
||||
strm->next_in = inbuf;
|
||||
bytesAvailable = in->bytesAvailable();
|
||||
if (bytesAvailable == 0) {
|
||||
// Once the end of the input file has been reached,
|
||||
// we need to tell lzma_code() that no more input
|
||||
// will be coming. As said before, this isn't required
|
||||
// if the LZMA_CONCATENATED flag isn't used when
|
||||
// initializing the decoder.
|
||||
action = LZMA_FINISH;
|
||||
} else if (bytesAvailable >= BUFSIZ) {
|
||||
in->read((char *)inbuf, BUFSIZ);
|
||||
strm->avail_in = BUFSIZ;
|
||||
} else {
|
||||
in->read((char *)inbuf, bytesAvailable);
|
||||
strm->avail_in = bytesAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
lzma_ret ret = lzma_code(strm, action);
|
||||
lzma_ret ret = lzma_code(strm, action);
|
||||
|
||||
if (strm->avail_out == 0 || ret == LZMA_STREAM_END) {
|
||||
qint64 write_size = sizeof(outbuf) - strm->avail_out;
|
||||
if (strm->avail_out == 0 || ret == LZMA_STREAM_END) {
|
||||
qint64 write_size = sizeof(outbuf) - strm->avail_out;
|
||||
|
||||
if (out->write((char *) outbuf, write_size) != write_size) {
|
||||
qDebug() << "Write error";
|
||||
return false;
|
||||
}
|
||||
if (out->write((char *)outbuf, write_size) != write_size) {
|
||||
qDebug() << "Write error";
|
||||
return false;
|
||||
}
|
||||
|
||||
strm->next_out = outbuf;
|
||||
strm->avail_out = sizeof(outbuf);
|
||||
}
|
||||
strm->next_out = outbuf;
|
||||
strm->avail_out = sizeof(outbuf);
|
||||
}
|
||||
|
||||
if (ret != LZMA_OK) {
|
||||
// Once everything has been decoded successfully, the
|
||||
// return value of lzma_code() will be LZMA_STREAM_END.
|
||||
//
|
||||
// It is important to check for LZMA_STREAM_END. Do not
|
||||
// assume that getting ret != LZMA_OK would mean that
|
||||
// everything has gone well or that when you aren't
|
||||
// getting more output it must have successfully
|
||||
// decoded everything.
|
||||
if (ret == LZMA_STREAM_END)
|
||||
return true;
|
||||
if (ret != LZMA_OK) {
|
||||
// Once everything has been decoded successfully, the
|
||||
// return value of lzma_code() will be LZMA_STREAM_END.
|
||||
//
|
||||
// It is important to check for LZMA_STREAM_END. Do not
|
||||
// assume that getting ret != LZMA_OK would mean that
|
||||
// everything has gone well or that when you aren't
|
||||
// getting more output it must have successfully
|
||||
// decoded everything.
|
||||
if (ret == LZMA_STREAM_END)
|
||||
return true;
|
||||
|
||||
// It's not LZMA_OK nor LZMA_STREAM_END,
|
||||
// so it must be an error code. See lzma/base.h
|
||||
// (src/liblzma/api/lzma/base.h in the source package
|
||||
// or e.g. /usr/include/lzma/base.h depending on the
|
||||
// install prefix) for the list and documentation of
|
||||
// possible values. Many values listen in lzma_ret
|
||||
// enumeration aren't possible in this example, but
|
||||
// can be made possible by enabling memory usage limit
|
||||
// or adding flags to the decoder initialization.
|
||||
const char *msg;
|
||||
switch (ret) {
|
||||
case LZMA_MEM_ERROR:
|
||||
msg = "Memory allocation failed";
|
||||
break;
|
||||
// It's not LZMA_OK nor LZMA_STREAM_END,
|
||||
// so it must be an error code. See lzma/base.h
|
||||
// (src/liblzma/api/lzma/base.h in the source package
|
||||
// or e.g. /usr/include/lzma/base.h depending on the
|
||||
// install prefix) for the list and documentation of
|
||||
// possible values. Many values listen in lzma_ret
|
||||
// enumeration aren't possible in this example, but
|
||||
// can be made possible by enabling memory usage limit
|
||||
// or adding flags to the decoder initialization.
|
||||
const char *msg;
|
||||
switch (ret) {
|
||||
case LZMA_MEM_ERROR:
|
||||
msg = "Memory allocation failed";
|
||||
break;
|
||||
|
||||
case LZMA_FORMAT_ERROR:
|
||||
// .xz magic bytes weren't found.
|
||||
msg = "The input is not in the .xz format";
|
||||
break;
|
||||
case LZMA_FORMAT_ERROR:
|
||||
// .xz magic bytes weren't found.
|
||||
msg = "The input is not in the .xz format";
|
||||
break;
|
||||
|
||||
case LZMA_OPTIONS_ERROR:
|
||||
// For example, the headers specify a filter
|
||||
// that isn't supported by this liblzma
|
||||
// version (or it hasn't been enabled when
|
||||
// building liblzma, but no-one sane does
|
||||
// that unless building liblzma for an
|
||||
// embedded system). Upgrading to a newer
|
||||
// liblzma might help.
|
||||
//
|
||||
// Note that it is unlikely that the file has
|
||||
// accidentally became corrupt if you get this
|
||||
// error. The integrity of the .xz headers is
|
||||
// always verified with a CRC32, so
|
||||
// unintentionally corrupt files can be
|
||||
// distinguished from unsupported files.
|
||||
msg = "Unsupported compression options";
|
||||
break;
|
||||
case LZMA_OPTIONS_ERROR:
|
||||
// For example, the headers specify a filter
|
||||
// that isn't supported by this liblzma
|
||||
// version (or it hasn't been enabled when
|
||||
// building liblzma, but no-one sane does
|
||||
// that unless building liblzma for an
|
||||
// embedded system). Upgrading to a newer
|
||||
// liblzma might help.
|
||||
//
|
||||
// Note that it is unlikely that the file has
|
||||
// accidentally became corrupt if you get this
|
||||
// error. The integrity of the .xz headers is
|
||||
// always verified with a CRC32, so
|
||||
// unintentionally corrupt files can be
|
||||
// distinguished from unsupported files.
|
||||
msg = "Unsupported compression options";
|
||||
break;
|
||||
|
||||
case LZMA_DATA_ERROR:
|
||||
msg = "Compressed file is corrupt";
|
||||
break;
|
||||
case LZMA_DATA_ERROR:
|
||||
msg = "Compressed file is corrupt";
|
||||
break;
|
||||
|
||||
case LZMA_BUF_ERROR:
|
||||
// Typically this error means that a valid
|
||||
// file has got truncated, but it might also
|
||||
// be a damaged part in the file that makes
|
||||
// the decoder think the file is truncated.
|
||||
// If you prefer, you can use the same error
|
||||
// message for this as for LZMA_DATA_ERROR.
|
||||
msg = "Compressed file is truncated or "
|
||||
"otherwise corrupt";
|
||||
break;
|
||||
case LZMA_BUF_ERROR:
|
||||
// Typically this error means that a valid
|
||||
// file has got truncated, but it might also
|
||||
// be a damaged part in the file that makes
|
||||
// the decoder think the file is truncated.
|
||||
// If you prefer, you can use the same error
|
||||
// message for this as for LZMA_DATA_ERROR.
|
||||
msg = "Compressed file is truncated or "
|
||||
"otherwise corrupt";
|
||||
break;
|
||||
|
||||
default:
|
||||
// This is most likely LZMA_PROG_ERROR.
|
||||
msg = "Unknown error, possibly a bug";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// This is most likely LZMA_PROG_ERROR.
|
||||
msg = "Unknown error, possibly a bug";
|
||||
break;
|
||||
}
|
||||
|
||||
qDebug() << "Decoder error:" << msg << "(error code " << ret << ")";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
qDebug() << "Decoder error:" << msg << "(error code " << ret << ")";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
#ifndef XZ_DECOMPRESS_H
|
||||
#define XZ_DECOMPRESS_H
|
||||
|
||||
#include <lzma.h>
|
||||
#include <QBuffer>
|
||||
#include <lzma.h>
|
||||
|
||||
class XzDecompressor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
XzDecompressor(QObject *parent = 0);
|
||||
~XzDecompressor() { };
|
||||
~XzDecompressor() {};
|
||||
bool decompress(QBuffer *in, QBuffer *out);
|
||||
|
||||
private:
|
||||
bool init_decoder(lzma_stream *strm);
|
||||
bool internal_decompress(lzma_stream *strm, QBuffer *in, QBuffer *out);
|
||||
|
|
|
|||
12
cockatrice/src/utility/external/qt-json/json.cpp
vendored
12
cockatrice/src/utility/external/qt-json/json.cpp
vendored
|
|
@ -113,7 +113,7 @@ QByteArray Json::serialize(const QVariant &data, bool &success)
|
|||
else if ((data.typeId() == QMetaType::Type::QVariantList) ||
|
||||
(data.typeId() == QMetaType::Type::QStringList)) // variant is a list?
|
||||
#else
|
||||
else if ((data.type() == QVariant::List) || (data.type() == QVariant::StringList)) // variant is a list?
|
||||
else if ((data.type() == QVariant::List) || (data.type() == QVariant::StringList)) // variant is a list?
|
||||
#endif
|
||||
{
|
||||
QList<QByteArray> values;
|
||||
|
|
@ -132,7 +132,7 @@ QByteArray Json::serialize(const QVariant &data, bool &success)
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
else if ((data.typeId() == QMetaType::Type::QVariantHash)) // variant is a list?
|
||||
#else
|
||||
else if (data.type() == QVariant::Hash) // variant is a hash?
|
||||
else if (data.type() == QVariant::Hash) // variant is a hash?
|
||||
#endif
|
||||
{
|
||||
const QVariantHash vhash = data.toHash();
|
||||
|
|
@ -158,7 +158,7 @@ QByteArray Json::serialize(const QVariant &data, bool &success)
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
else if ((data.typeId() == QMetaType::Type::QVariantMap)) // variant is a list?
|
||||
#else
|
||||
else if (data.type() == QVariant::Map) // variant is a map?
|
||||
else if (data.type() == QVariant::Map) // variant is a map?
|
||||
#endif
|
||||
{
|
||||
const QVariantMap vmap = data.toMap();
|
||||
|
|
@ -189,7 +189,7 @@ QByteArray Json::serialize(const QVariant &data, bool &success)
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
else if (data.typeId() == QMetaType::Type::Double)
|
||||
#else
|
||||
else if (data.type() == QVariant::Double) // double?
|
||||
else if (data.type() == QVariant::Double) // double?
|
||||
#endif
|
||||
{
|
||||
str = QByteArray::number(data.toDouble(), 'g', 20);
|
||||
|
|
@ -200,7 +200,7 @@ QByteArray Json::serialize(const QVariant &data, bool &success)
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
else if (data.typeId() == QMetaType::Type::Bool)
|
||||
#else
|
||||
else if (data.type() == QVariant::Bool) // boolean value?
|
||||
else if (data.type() == QVariant::Bool) // boolean value?
|
||||
#endif
|
||||
{
|
||||
str = data.toBool() ? "true" : "false";
|
||||
|
|
@ -208,7 +208,7 @@ QByteArray Json::serialize(const QVariant &data, bool &success)
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
else if (data.typeId() == QMetaType::Type::ULongLong)
|
||||
#else
|
||||
else if (data.type() == QVariant::ULongLong) // large unsigned number?
|
||||
else if (data.type() == QVariant::ULongLong) // large unsigned number?
|
||||
#endif
|
||||
{
|
||||
str = QByteArray::number(data.value<qulonglong>());
|
||||
|
|
|
|||
287
cockatrice/src/utility/external/qt-json/json.h
vendored
287
cockatrice/src/utility/external/qt-json/json.h
vendored
|
|
@ -1,28 +1,28 @@
|
|||
/* Copyright 2011 Eeli Reilin. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL EELI REILIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL EELI REILIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation
|
||||
* are those of the authors and should not be interpreted as representing
|
||||
* The views and conclusions contained in the software and documentation
|
||||
* are those of the authors and should not be interpreted as representing
|
||||
* official policies, either expressed or implied, of Eeli Reilin.
|
||||
*/
|
||||
|
||||
|
|
@ -33,8 +33,8 @@
|
|||
#ifndef JSON_H
|
||||
#define JSON_H
|
||||
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
namespace QtJson
|
||||
{
|
||||
|
|
@ -44,18 +44,18 @@ namespace QtJson
|
|||
*/
|
||||
enum JsonToken
|
||||
{
|
||||
JsonTokenNone = 0,
|
||||
JsonTokenCurlyOpen = 1,
|
||||
JsonTokenCurlyClose = 2,
|
||||
JsonTokenSquaredOpen = 3,
|
||||
JsonTokenSquaredClose = 4,
|
||||
JsonTokenColon = 5,
|
||||
JsonTokenComma = 6,
|
||||
JsonTokenString = 7,
|
||||
JsonTokenNumber = 8,
|
||||
JsonTokenTrue = 9,
|
||||
JsonTokenFalse = 10,
|
||||
JsonTokenNull = 11
|
||||
JsonTokenNone = 0,
|
||||
JsonTokenCurlyOpen = 1,
|
||||
JsonTokenCurlyClose = 2,
|
||||
JsonTokenSquaredOpen = 3,
|
||||
JsonTokenSquaredClose = 4,
|
||||
JsonTokenColon = 5,
|
||||
JsonTokenComma = 6,
|
||||
JsonTokenString = 7,
|
||||
JsonTokenNumber = 8,
|
||||
JsonTokenTrue = 9,
|
||||
JsonTokenFalse = 10,
|
||||
JsonTokenNull = 11
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -66,139 +66,134 @@ enum JsonToken
|
|||
*/
|
||||
class Json
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Parse a JSON string
|
||||
*
|
||||
* \param json The JSON data
|
||||
*/
|
||||
static QVariant parse(const QString &json);
|
||||
public:
|
||||
/**
|
||||
* Parse a JSON string
|
||||
*
|
||||
* \param json The JSON data
|
||||
*/
|
||||
static QVariant parse(const QString &json);
|
||||
|
||||
/**
|
||||
* Parse a JSON string
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param success The success of the parsing
|
||||
*/
|
||||
static QVariant parse(const QString &json, bool &success);
|
||||
/**
|
||||
* Parse a JSON string
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param success The success of the parsing
|
||||
*/
|
||||
static QVariant parse(const QString &json, bool &success);
|
||||
|
||||
/**
|
||||
* This method generates a textual JSON representation
|
||||
*
|
||||
* \param data The JSON data generated by the parser.
|
||||
* \param success The success of the serialization
|
||||
*/
|
||||
static QByteArray serialize(const QVariant &data);
|
||||
/**
|
||||
* This method generates a textual JSON representation
|
||||
*
|
||||
* \param data The JSON data generated by the parser.
|
||||
* \param success The success of the serialization
|
||||
*/
|
||||
static QByteArray serialize(const QVariant &data);
|
||||
|
||||
/**
|
||||
* This method generates a textual JSON representation
|
||||
*
|
||||
* \param data The JSON data generated by the parser.
|
||||
* \param success The success of the serialization
|
||||
*
|
||||
* \return QByteArray Textual JSON representation
|
||||
*/
|
||||
static QByteArray serialize(const QVariant &data, bool &success);
|
||||
/**
|
||||
* This method generates a textual JSON representation
|
||||
*
|
||||
* \param data The JSON data generated by the parser.
|
||||
* \param success The success of the serialization
|
||||
*
|
||||
* \return QByteArray Textual JSON representation
|
||||
*/
|
||||
static QByteArray serialize(const QVariant &data, bool &success);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Parses a value starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The start index
|
||||
* \param success The success of the parse process
|
||||
*
|
||||
* \return QVariant The parsed value
|
||||
*/
|
||||
static QVariant parseValue(const QString &json, int &index,
|
||||
bool &success);
|
||||
private:
|
||||
/**
|
||||
* Parses a value starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The start index
|
||||
* \param success The success of the parse process
|
||||
*
|
||||
* \return QVariant The parsed value
|
||||
*/
|
||||
static QVariant parseValue(const QString &json, int &index, bool &success);
|
||||
|
||||
/**
|
||||
* Parses an object starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The start index
|
||||
* \param success The success of the object parse
|
||||
*
|
||||
* \return QVariant The parsed object map
|
||||
*/
|
||||
static QVariant parseObject(const QString &json, int &index,
|
||||
bool &success);
|
||||
/**
|
||||
* Parses an object starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The start index
|
||||
* \param success The success of the object parse
|
||||
*
|
||||
* \return QVariant The parsed object map
|
||||
*/
|
||||
static QVariant parseObject(const QString &json, int &index, bool &success);
|
||||
|
||||
/**
|
||||
* Parses an array starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
* \param success The success of the array parse
|
||||
*
|
||||
* \return QVariant The parsed variant array
|
||||
*/
|
||||
static QVariant parseArray(const QString &json, int &index,
|
||||
bool &success);
|
||||
/**
|
||||
* Parses an array starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
* \param success The success of the array parse
|
||||
*
|
||||
* \return QVariant The parsed variant array
|
||||
*/
|
||||
static QVariant parseArray(const QString &json, int &index, bool &success);
|
||||
|
||||
/**
|
||||
* Parses a string starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
* \param success The success of the string parse
|
||||
*
|
||||
* \return QVariant The parsed string
|
||||
*/
|
||||
static QVariant parseString(const QString &json, int &index,
|
||||
bool &success);
|
||||
/**
|
||||
* Parses a string starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
* \param success The success of the string parse
|
||||
*
|
||||
* \return QVariant The parsed string
|
||||
*/
|
||||
static QVariant parseString(const QString &json, int &index, bool &success);
|
||||
|
||||
/**
|
||||
* Parses a number starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
*
|
||||
* \return QVariant The parsed number
|
||||
*/
|
||||
static QVariant parseNumber(const QString &json, int &index);
|
||||
/**
|
||||
* Parses a number starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
*
|
||||
* \return QVariant The parsed number
|
||||
*/
|
||||
static QVariant parseNumber(const QString &json, int &index);
|
||||
|
||||
/**
|
||||
* Get the last index of a number starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
*
|
||||
* \return The last index of the number
|
||||
*/
|
||||
static int lastIndexOfNumber(const QString &json, int index);
|
||||
/**
|
||||
* Get the last index of a number starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
*
|
||||
* \return The last index of the number
|
||||
*/
|
||||
static int lastIndexOfNumber(const QString &json, int index);
|
||||
|
||||
/**
|
||||
* Skip unwanted whitespace symbols starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The start index
|
||||
*/
|
||||
static void eatWhitespace(const QString &json, int &index);
|
||||
/**
|
||||
* Skip unwanted whitespace symbols starting from index
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The start index
|
||||
*/
|
||||
static void eatWhitespace(const QString &json, int &index);
|
||||
|
||||
/**
|
||||
* Check what token lies ahead
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
*
|
||||
* \return int The upcoming token
|
||||
*/
|
||||
static int lookAhead(const QString &json, int index);
|
||||
/**
|
||||
* Check what token lies ahead
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
*
|
||||
* \return int The upcoming token
|
||||
*/
|
||||
static int lookAhead(const QString &json, int index);
|
||||
|
||||
/**
|
||||
* Get the next JSON token
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
*
|
||||
* \return int The next JSON token
|
||||
*/
|
||||
static int nextToken(const QString &json, int &index);
|
||||
/**
|
||||
* Get the next JSON token
|
||||
*
|
||||
* \param json The JSON data
|
||||
* \param index The starting index
|
||||
*
|
||||
* \return int The next JSON token
|
||||
*/
|
||||
static int nextToken(const QString &json, int &index);
|
||||
};
|
||||
|
||||
} // namespace QtJson
|
||||
|
||||
} //end namespace
|
||||
|
||||
#endif //JSON_H
|
||||
#endif // JSON_H
|
||||
|
|
|
|||
328
cockatrice/src/utility/external/zip/unzip.cpp
vendored
Executable file → Normal file
328
cockatrice/src/utility/external/zip/unzip.cpp
vendored
Executable file → Normal file
|
|
@ -26,6 +26,7 @@
|
|||
**********************************************************************/
|
||||
|
||||
#include "unzip.h"
|
||||
|
||||
#include "unzip_p.h"
|
||||
#include "zipentry_p.h"
|
||||
|
||||
|
|
@ -64,7 +65,8 @@
|
|||
\value UnZip::CreateDirFailed Could not create a directory.
|
||||
\value UnZip::InvalidDevice A null device has been passed as parameter.
|
||||
\value UnZip::InvalidArchive This is not a valid (or supported) ZIP archive.
|
||||
\value UnZip::HeaderConsistencyError Local header record info does not match with the central directory record info. The archive may be corrupted.
|
||||
\value UnZip::HeaderConsistencyError Local header record info does not match with the central directory record info.
|
||||
The archive may be corrupted.
|
||||
|
||||
\value UnZip::Skip Internal use only.
|
||||
\value UnZip::SkipAll Internal use only.
|
||||
|
|
@ -133,11 +135,10 @@
|
|||
#define UNZIP_VERSION 0x14
|
||||
|
||||
//! CRC32 routine
|
||||
#define CRC32(c, b) crcTable[((int)c^b) & 0xff] ^ (c >> 8)
|
||||
#define CRC32(c, b) crcTable[((int)c ^ b) & 0xff] ^ (c >> 8)
|
||||
|
||||
OSDAB_BEGIN_NAMESPACE(Zip)
|
||||
|
||||
|
||||
/************************************************************************
|
||||
ZipEntry
|
||||
*************************************************************************/
|
||||
|
|
@ -153,39 +154,28 @@ UnZip::ZipEntry::ZipEntry()
|
|||
encrypted = false;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
Private interface
|
||||
*************************************************************************/
|
||||
|
||||
//! \internal
|
||||
UnzipPrivate::UnzipPrivate() :
|
||||
password(),
|
||||
skipAllEncrypted(false),
|
||||
headers(0),
|
||||
device(0),
|
||||
file(0),
|
||||
uBuffer(0),
|
||||
crcTable(0),
|
||||
cdOffset(0),
|
||||
eocdOffset(0),
|
||||
cdEntryCount(0),
|
||||
unsupportedEntryCount(0),
|
||||
comment()
|
||||
UnzipPrivate::UnzipPrivate()
|
||||
: password(), skipAllEncrypted(false), headers(0), device(0), file(0), uBuffer(0), crcTable(0), cdOffset(0),
|
||||
eocdOffset(0), cdEntryCount(0), unsupportedEntryCount(0), comment()
|
||||
{
|
||||
uBuffer = (unsigned char*) buffer1;
|
||||
crcTable = (quint32*) get_crc_table();
|
||||
uBuffer = (unsigned char *)buffer1;
|
||||
crcTable = (quint32 *)get_crc_table();
|
||||
}
|
||||
|
||||
//! \internal
|
||||
void UnzipPrivate::deviceDestroyed(QObject*)
|
||||
void UnzipPrivate::deviceDestroyed(QObject *)
|
||||
{
|
||||
qDebug("Unexpected device destruction detected.");
|
||||
do_closeArchive();
|
||||
}
|
||||
|
||||
//! \internal Parses a Zip archive.
|
||||
UnZip::ErrorCode UnzipPrivate::openArchive(QIODevice* dev)
|
||||
UnZip::ErrorCode UnzipPrivate::openArchive(QIODevice *dev)
|
||||
{
|
||||
Q_ASSERT(!device);
|
||||
Q_ASSERT(dev);
|
||||
|
|
@ -197,7 +187,7 @@ UnZip::ErrorCode UnzipPrivate::openArchive(QIODevice* dev)
|
|||
|
||||
device = dev;
|
||||
if (device != file)
|
||||
connect(device, SIGNAL(destroyed(QObject*)), this, SLOT(deviceDestroyed(QObject*)));
|
||||
connect(device, SIGNAL(destroyed(QObject *)), this, SLOT(deviceDestroyed(QObject *)));
|
||||
|
||||
UnZip::ErrorCode ec;
|
||||
|
||||
|
|
@ -228,7 +218,7 @@ UnZip::ErrorCode UnzipPrivate::openArchive(QIODevice* dev)
|
|||
}
|
||||
}
|
||||
|
||||
if (! (buffer1[0] == 'P' && buffer1[1] == 'K' && buffer1[2] == 0x01 && buffer1[3] == 0x02) )
|
||||
if (!(buffer1[0] == 'P' && buffer1[1] == 'K' && buffer1[2] == 0x01 && buffer1[3] == 0x02))
|
||||
break;
|
||||
|
||||
if ((ec = parseCentralDirectoryRecord()) != UnZip::Ok)
|
||||
|
|
@ -262,7 +252,7 @@ UnZip::ErrorCode UnzipPrivate::openArchive(QIODevice* dev)
|
|||
file name (variable size)
|
||||
extra field (variable size)
|
||||
*/
|
||||
UnZip::ErrorCode UnzipPrivate::parseLocalHeaderRecord(const QString& path, const ZipEntryP& entry)
|
||||
UnZip::ErrorCode UnzipPrivate::parseLocalHeaderRecord(const QString &path, const ZipEntryP &entry)
|
||||
{
|
||||
Q_ASSERT(device);
|
||||
|
||||
|
|
@ -302,8 +292,7 @@ UnZip::ErrorCode UnzipPrivate::parseLocalHeaderRecord(const QString& path, const
|
|||
checkFailed = entry.modDate[0] != uBuffer[UNZIP_LH_OFF_MODD];
|
||||
if (!checkFailed)
|
||||
checkFailed = entry.modDate[1] != uBuffer[UNZIP_LH_OFF_MODD + 1];
|
||||
if (!hasDataDescriptor)
|
||||
{
|
||||
if (!hasDataDescriptor) {
|
||||
if (!checkFailed)
|
||||
checkFailed = entry.crc != getULong(uBuffer, UNZIP_LH_OFF_CRC32);
|
||||
if (!checkFailed)
|
||||
|
|
@ -361,11 +350,9 @@ UnZip::ErrorCode UnzipPrivate::parseLocalHeaderRecord(const QString& path, const
|
|||
}
|
||||
|
||||
// DD: crc, compressed size, uncompressed size
|
||||
if (
|
||||
entry.crc != getULong((unsigned char*)buffer2, UNZIP_DD_OFF_CRC32) ||
|
||||
entry.szComp != getULong((unsigned char*)buffer2, UNZIP_DD_OFF_CSIZE) ||
|
||||
entry.szUncomp != getULong((unsigned char*)buffer2, UNZIP_DD_OFF_USIZE)
|
||||
)
|
||||
if (entry.crc != getULong((unsigned char *)buffer2, UNZIP_DD_OFF_CRC32) ||
|
||||
entry.szComp != getULong((unsigned char *)buffer2, UNZIP_DD_OFF_CSIZE) ||
|
||||
entry.szUncomp != getULong((unsigned char *)buffer2, UNZIP_DD_OFF_USIZE))
|
||||
return UnZip::HeaderConsistencyError;
|
||||
}
|
||||
|
||||
|
|
@ -403,7 +390,7 @@ UnZip::ErrorCode UnzipPrivate::seekToCentralDirectory()
|
|||
if (length < UNZIP_EOCD_SIZE)
|
||||
return UnZip::InvalidArchive;
|
||||
|
||||
if (!device->seek( offset ))
|
||||
if (!device->seek(offset))
|
||||
return UnZip::SeekFailed;
|
||||
|
||||
if (device->read(buffer1, UNZIP_EOCD_SIZE) != UNZIP_EOCD_SIZE)
|
||||
|
|
@ -416,22 +403,22 @@ UnZip::ErrorCode UnzipPrivate::seekToCentralDirectory()
|
|||
eocdOffset = offset;
|
||||
} else {
|
||||
qint64 read;
|
||||
char* p = 0;
|
||||
char *p = 0;
|
||||
|
||||
offset -= UNZIP_EOCD_SIZE;
|
||||
|
||||
if (offset <= 0)
|
||||
return UnZip::InvalidArchive;
|
||||
|
||||
if (!device->seek( offset ))
|
||||
if (!device->seek(offset))
|
||||
return UnZip::SeekFailed;
|
||||
|
||||
while ((read = device->read(buffer1, UNZIP_EOCD_SIZE)) >= 0) {
|
||||
if ( (p = strstr(buffer1, "PK\5\6")) != 0) {
|
||||
if ((p = strstr(buffer1, "PK\5\6")) != 0) {
|
||||
// Seek to the start of the EOCD record so we can read it fully
|
||||
// Yes... we could simply read the missing bytes and append them to the buffer
|
||||
// but this is far easier so heck it!
|
||||
device->seek( offset + (p - buffer1) );
|
||||
device->seek(offset + (p - buffer1));
|
||||
eocdFound = true;
|
||||
eocdOffset = offset + (p - buffer1);
|
||||
|
||||
|
|
@ -447,7 +434,7 @@ UnZip::ErrorCode UnzipPrivate::seekToCentralDirectory()
|
|||
if (offset <= 0)
|
||||
return UnZip::InvalidArchive;
|
||||
|
||||
if (!device->seek( offset ))
|
||||
if (!device->seek(offset))
|
||||
return UnZip::SeekFailed;
|
||||
}
|
||||
}
|
||||
|
|
@ -456,13 +443,13 @@ UnZip::ErrorCode UnzipPrivate::seekToCentralDirectory()
|
|||
return UnZip::InvalidArchive;
|
||||
|
||||
// Parse EOCD to locate CD offset
|
||||
offset = getULong((const unsigned char*)buffer1, UNZIP_EOCD_OFF_CDOFF + 4);
|
||||
offset = getULong((const unsigned char *)buffer1, UNZIP_EOCD_OFF_CDOFF + 4);
|
||||
|
||||
cdOffset = offset;
|
||||
|
||||
cdEntryCount = getUShort((const unsigned char*)buffer1, UNZIP_EOCD_OFF_ENTRIES + 4);
|
||||
cdEntryCount = getUShort((const unsigned char *)buffer1, UNZIP_EOCD_OFF_ENTRIES + 4);
|
||||
|
||||
quint16 commentLength = getUShort((const unsigned char*)buffer1, UNZIP_EOCD_OFF_COMMLEN + 4);
|
||||
quint16 commentLength = getUShort((const unsigned char *)buffer1, UNZIP_EOCD_OFF_COMMLEN + 4);
|
||||
if (commentLength != 0) {
|
||||
QByteArray c = device->read(commentLength);
|
||||
if (c.size() != commentLength)
|
||||
|
|
@ -472,7 +459,7 @@ UnZip::ErrorCode UnzipPrivate::seekToCentralDirectory()
|
|||
}
|
||||
|
||||
// Seek to the start of the CD record
|
||||
if (!device->seek( cdOffset ))
|
||||
if (!device->seek(cdOffset))
|
||||
return UnZip::SeekFailed;
|
||||
|
||||
return UnZip::Ok;
|
||||
|
|
@ -561,14 +548,14 @@ UnZip::ErrorCode UnzipPrivate::parseCentralDirectoryRecord()
|
|||
if (v.length() == 2)
|
||||
v.insert(1, QLatin1Char('.'));
|
||||
v = QString::fromLatin1("Unsupported PKZip version (%1). Skipping file: %2")
|
||||
.arg(v, filename.isEmpty() ? QString::fromLatin1("<undefined>") : filename);
|
||||
.arg(v, filename.isEmpty() ? QString::fromLatin1("<undefined>") : filename);
|
||||
qDebug() << v.toLatin1().constData();
|
||||
skipEntry = true;
|
||||
}
|
||||
|
||||
if (skipEntry) {
|
||||
if (ec == UnZip::Ok) {
|
||||
if (!device->seek( device->pos() + skipLength ))
|
||||
if (!device->seek(device->pos() + skipLength))
|
||||
ec = UnZip::SeekFailed;
|
||||
unsupportedEntryCount++;
|
||||
}
|
||||
|
|
@ -576,7 +563,7 @@ UnZip::ErrorCode UnzipPrivate::parseCentralDirectoryRecord()
|
|||
return ec;
|
||||
}
|
||||
|
||||
ZipEntryP* h = new ZipEntryP;
|
||||
ZipEntryP *h = new ZipEntryP;
|
||||
h->compMethod = compMethod;
|
||||
|
||||
h->gpFlag[0] = buffer1[UNZIP_CD_OFF_GPFLAG];
|
||||
|
|
@ -594,7 +581,7 @@ UnZip::ErrorCode UnzipPrivate::parseCentralDirectoryRecord()
|
|||
|
||||
// Skip extra field (if any)
|
||||
if (szExtra != 0) {
|
||||
if (!device->seek( device->pos() + szExtra )) {
|
||||
if (!device->seek(device->pos() + szExtra)) {
|
||||
delete h;
|
||||
return UnZip::SeekFailed;
|
||||
}
|
||||
|
|
@ -613,7 +600,7 @@ UnZip::ErrorCode UnzipPrivate::parseCentralDirectoryRecord()
|
|||
h->lhOffset = getULong(uBuffer, UNZIP_CD_OFF_LHOFFSET);
|
||||
|
||||
if (!headers)
|
||||
headers = new QMap<QString, ZipEntryP*>();
|
||||
headers = new QMap<QString, ZipEntryP *>();
|
||||
headers->insert(filename, h);
|
||||
|
||||
return UnZip::Ok;
|
||||
|
|
@ -659,8 +646,10 @@ void UnzipPrivate::do_closeArchive()
|
|||
}
|
||||
|
||||
//! \internal
|
||||
UnZip::ErrorCode UnzipPrivate::extractFile(const QString& path, const ZipEntryP& entry,
|
||||
const QDir& dir, UnZip::ExtractionOptions options)
|
||||
UnZip::ErrorCode UnzipPrivate::extractFile(const QString &path,
|
||||
const ZipEntryP &entry,
|
||||
const QDir &dir,
|
||||
UnZip::ExtractionOptions options)
|
||||
{
|
||||
QString name(path);
|
||||
QString dirname;
|
||||
|
|
@ -742,9 +731,11 @@ UnZip::ErrorCode UnzipPrivate::extractFile(const QString& path, const ZipEntryP&
|
|||
}
|
||||
|
||||
//! \internal
|
||||
UnZip::ErrorCode UnzipPrivate::extractStoredFile(
|
||||
const quint32 szComp, quint32** keys, quint32& myCRC, QIODevice* outDev,
|
||||
UnZip::ExtractionOptions options)
|
||||
UnZip::ErrorCode UnzipPrivate::extractStoredFile(const quint32 szComp,
|
||||
quint32 **keys,
|
||||
quint32 &myCRC,
|
||||
QIODevice *outDev,
|
||||
UnZip::ExtractionOptions options)
|
||||
{
|
||||
const bool verify = (options & UnZip::VerifyOnly);
|
||||
const bool isEncrypted = keys != 0;
|
||||
|
|
@ -757,7 +748,7 @@ UnZip::ErrorCode UnzipPrivate::extractStoredFile(
|
|||
qint64 read;
|
||||
quint64 tot = 0;
|
||||
|
||||
while ( (read = device->read(buffer1, cur < rep ? UNZIP_READ_BUFFER : rem)) > 0 ) {
|
||||
while ((read = device->read(buffer1, cur < rep ? UNZIP_READ_BUFFER : rem)) > 0) {
|
||||
if (isEncrypted)
|
||||
decryptBytes(*keys, buffer1, read);
|
||||
|
||||
|
|
@ -773,15 +764,15 @@ UnZip::ErrorCode UnzipPrivate::extractStoredFile(
|
|||
break;
|
||||
}
|
||||
|
||||
return (read < 0)
|
||||
? UnZip::ReadFailed
|
||||
: UnZip::Ok;
|
||||
return (read < 0) ? UnZip::ReadFailed : UnZip::Ok;
|
||||
}
|
||||
|
||||
//! \internal
|
||||
UnZip::ErrorCode UnzipPrivate::inflateFile(
|
||||
const quint32 szComp, quint32** keys, quint32& myCRC, QIODevice* outDev,
|
||||
UnZip::ExtractionOptions options)
|
||||
UnZip::ErrorCode UnzipPrivate::inflateFile(const quint32 szComp,
|
||||
quint32 **keys,
|
||||
quint32 &myCRC,
|
||||
QIODevice *outDev,
|
||||
UnZip::ExtractionOptions options)
|
||||
{
|
||||
const bool verify = (options & UnZip::VerifyOnly);
|
||||
const bool isEncrypted = keys != 0;
|
||||
|
|
@ -805,7 +796,7 @@ UnZip::ErrorCode UnzipPrivate::inflateFile(
|
|||
int zret;
|
||||
|
||||
// Use inflateInit2 with negative windowBits to get raw decompression
|
||||
if ( (zret = inflateInit2_(&zstr, -MAX_WBITS, ZLIB_VERSION, sizeof(z_stream))) != Z_OK )
|
||||
if ((zret = inflateInit2_(&zstr, -MAX_WBITS, ZLIB_VERSION, sizeof(z_stream))) != Z_OK)
|
||||
return UnZip::ZlibError;
|
||||
|
||||
int szDecomp;
|
||||
|
|
@ -826,24 +817,24 @@ UnZip::ErrorCode UnzipPrivate::inflateFile(
|
|||
|
||||
cur++;
|
||||
|
||||
zstr.avail_in = (uInt) read;
|
||||
zstr.next_in = (Bytef*) buffer1;
|
||||
zstr.avail_in = (uInt)read;
|
||||
zstr.next_in = (Bytef *)buffer1;
|
||||
|
||||
// Run inflate() on input until output buffer not full
|
||||
do {
|
||||
zstr.avail_out = UNZIP_READ_BUFFER;
|
||||
zstr.next_out = (Bytef*) buffer2;;
|
||||
zstr.next_out = (Bytef *)buffer2;
|
||||
;
|
||||
|
||||
zret = inflate(&zstr, Z_NO_FLUSH);
|
||||
|
||||
switch (zret) {
|
||||
case Z_NEED_DICT:
|
||||
case Z_DATA_ERROR:
|
||||
case Z_MEM_ERROR:
|
||||
inflateEnd(&zstr);
|
||||
return UnZip::WriteFailed;
|
||||
default:
|
||||
;
|
||||
case Z_NEED_DICT:
|
||||
case Z_DATA_ERROR:
|
||||
case Z_MEM_ERROR:
|
||||
inflateEnd(&zstr);
|
||||
return UnZip::WriteFailed;
|
||||
default:;
|
||||
}
|
||||
|
||||
szDecomp = UNZIP_READ_BUFFER - zstr.avail_out;
|
||||
|
|
@ -854,7 +845,7 @@ UnZip::ErrorCode UnzipPrivate::inflateFile(
|
|||
}
|
||||
}
|
||||
|
||||
myCRC = crc32(myCRC, (const Bytef*) buffer2, szDecomp);
|
||||
myCRC = crc32(myCRC, (const Bytef *)buffer2, szDecomp);
|
||||
|
||||
} while (zstr.avail_out == 0);
|
||||
|
||||
|
|
@ -865,8 +856,10 @@ UnZip::ErrorCode UnzipPrivate::inflateFile(
|
|||
}
|
||||
|
||||
//! \internal \p outDev is null if the VerifyOnly option is set
|
||||
UnZip::ErrorCode UnzipPrivate::extractFile(const QString& path, const ZipEntryP& entry,
|
||||
QIODevice* outDev, UnZip::ExtractionOptions options)
|
||||
UnZip::ErrorCode UnzipPrivate::extractFile(const QString &path,
|
||||
const ZipEntryP &entry,
|
||||
QIODevice *outDev,
|
||||
UnZip::ExtractionOptions options)
|
||||
{
|
||||
const bool verify = (options & UnZip::VerifyOnly);
|
||||
|
||||
|
|
@ -889,11 +882,10 @@ UnZip::ErrorCode UnzipPrivate::extractFile(const QString& path, const ZipEntryP&
|
|||
quint32 szComp = entry.szComp;
|
||||
if (entry.isEncrypted()) {
|
||||
UnZip::ErrorCode e = testPassword(keys, path, entry);
|
||||
if (e != UnZip::Ok)
|
||||
{
|
||||
if (e != UnZip::Ok) {
|
||||
qDebug() << QString("Unable to decrypt %1").arg(path);
|
||||
return e;
|
||||
}//! Encryption header size
|
||||
} //! Encryption header size
|
||||
szComp -= UNZIP_LOCAL_ENC_HEADER_SIZE; // remove encryption header size
|
||||
}
|
||||
|
||||
|
|
@ -904,7 +896,7 @@ UnZip::ErrorCode UnzipPrivate::extractFile(const QString& path, const ZipEntryP&
|
|||
}
|
||||
|
||||
quint32 myCRC = crc32(0L, Z_NULL, 0);
|
||||
quint32* k = keys;
|
||||
quint32 *k = keys;
|
||||
|
||||
UnZip::ErrorCode ec = UnZip::Ok;
|
||||
if (entry.compMethod == 0) {
|
||||
|
|
@ -920,7 +912,7 @@ UnZip::ErrorCode UnzipPrivate::extractFile(const QString& path, const ZipEntryP&
|
|||
}
|
||||
|
||||
//! \internal Creates a new directory and all the needed parent directories.
|
||||
bool UnzipPrivate::createDirectory(const QString& path)
|
||||
bool UnzipPrivate::createDirectory(const QString &path)
|
||||
{
|
||||
QDir d(path);
|
||||
if (!d.exists() && !d.mkpath(path)) {
|
||||
|
|
@ -934,12 +926,12 @@ bool UnzipPrivate::createDirectory(const QString& path)
|
|||
/*!
|
||||
\internal Reads an quint32 (4 bytes) from a byte array starting at given offset.
|
||||
*/
|
||||
quint32 UnzipPrivate::getULong(const unsigned char* data, quint32 offset) const
|
||||
quint32 UnzipPrivate::getULong(const unsigned char *data, quint32 offset) const
|
||||
{
|
||||
quint32 res = (quint32) data[offset];
|
||||
res |= (((quint32)data[offset+1]) << 8);
|
||||
res |= (((quint32)data[offset+2]) << 16);
|
||||
res |= (((quint32)data[offset+3]) << 24);
|
||||
quint32 res = (quint32)data[offset];
|
||||
res |= (((quint32)data[offset + 1]) << 8);
|
||||
res |= (((quint32)data[offset + 2]) << 16);
|
||||
res |= (((quint32)data[offset + 3]) << 24);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -947,16 +939,16 @@ quint32 UnzipPrivate::getULong(const unsigned char* data, quint32 offset) const
|
|||
/*!
|
||||
\internal Reads an quint64 (8 bytes) from a byte array starting at given offset.
|
||||
*/
|
||||
quint64 UnzipPrivate::getULLong(const unsigned char* data, quint32 offset) const
|
||||
quint64 UnzipPrivate::getULLong(const unsigned char *data, quint32 offset) const
|
||||
{
|
||||
quint64 res = (quint64) data[offset];
|
||||
res |= (((quint64)data[offset+1]) << 8);
|
||||
res |= (((quint64)data[offset+2]) << 16);
|
||||
res |= (((quint64)data[offset+3]) << 24);
|
||||
res |= (((quint64)data[offset+1]) << 32);
|
||||
res |= (((quint64)data[offset+2]) << 40);
|
||||
res |= (((quint64)data[offset+3]) << 48);
|
||||
res |= (((quint64)data[offset+3]) << 56);
|
||||
quint64 res = (quint64)data[offset];
|
||||
res |= (((quint64)data[offset + 1]) << 8);
|
||||
res |= (((quint64)data[offset + 2]) << 16);
|
||||
res |= (((quint64)data[offset + 3]) << 24);
|
||||
res |= (((quint64)data[offset + 1]) << 32);
|
||||
res |= (((quint64)data[offset + 2]) << 40);
|
||||
res |= (((quint64)data[offset + 3]) << 48);
|
||||
res |= (((quint64)data[offset + 3]) << 56);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -964,9 +956,9 @@ quint64 UnzipPrivate::getULLong(const unsigned char* data, quint32 offset) const
|
|||
/*!
|
||||
\internal Reads an quint16 (2 bytes) from a byte array starting at given offset.
|
||||
*/
|
||||
quint16 UnzipPrivate::getUShort(const unsigned char* data, quint32 offset) const
|
||||
quint16 UnzipPrivate::getUShort(const unsigned char *data, quint32 offset) const
|
||||
{
|
||||
return (quint16) data[offset] | (((quint16)data[offset+1]) << 8);
|
||||
return (quint16)data[offset] | (((quint16)data[offset + 1]) << 8);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -981,7 +973,7 @@ int UnzipPrivate::decryptByte(quint32 key2) const
|
|||
/*!
|
||||
\internal Update the encryption keys with the next byte of plain text
|
||||
*/
|
||||
void UnzipPrivate::updateKeys(quint32* keys, int c) const
|
||||
void UnzipPrivate::updateKeys(quint32 *keys, int c) const
|
||||
{
|
||||
keys[0] = CRC32(keys[0], c);
|
||||
keys[1] += keys[0] & 0xff;
|
||||
|
|
@ -993,7 +985,7 @@ void UnzipPrivate::updateKeys(quint32* keys, int c) const
|
|||
\internal Initialize the encryption keys and the random header according to
|
||||
the given password.
|
||||
*/
|
||||
void UnzipPrivate::initKeys(const QString& pwd, quint32* keys) const
|
||||
void UnzipPrivate::initKeys(const QString &pwd, quint32 *keys) const
|
||||
{
|
||||
keys[0] = 305419896L;
|
||||
keys[1] = 591751049L;
|
||||
|
|
@ -1001,7 +993,7 @@ void UnzipPrivate::initKeys(const QString& pwd, quint32* keys) const
|
|||
|
||||
QByteArray pwdBytes = pwd.toLatin1();
|
||||
int sz = pwdBytes.size();
|
||||
const char* ascii = pwdBytes.data();
|
||||
const char *ascii = pwdBytes.data();
|
||||
|
||||
for (int i = 0; i < sz; ++i)
|
||||
updateKeys(keys, (int)ascii[i]);
|
||||
|
|
@ -1012,7 +1004,7 @@ void UnzipPrivate::initKeys(const QString& pwd, quint32* keys) const
|
|||
The \p file parameter can be used in the user interface or for debugging purposes
|
||||
as it is the name of the encrypted file for wich the password is being tested.
|
||||
*/
|
||||
UnZip::ErrorCode UnzipPrivate::testPassword(quint32* keys, const QString&_file, const ZipEntryP& header)
|
||||
UnZip::ErrorCode UnzipPrivate::testPassword(quint32 *keys, const QString &_file, const ZipEntryP &header)
|
||||
{
|
||||
Q_UNUSED(_file);
|
||||
Q_ASSERT(device);
|
||||
|
|
@ -1032,7 +1024,7 @@ UnZip::ErrorCode UnzipPrivate::testPassword(quint32* keys, const QString&_file,
|
|||
/*!
|
||||
\internal Tests a set of keys on the encryption header.
|
||||
*/
|
||||
bool UnzipPrivate::testKeys(const ZipEntryP& header, quint32* keys)
|
||||
bool UnzipPrivate::testKeys(const ZipEntryP &header, quint32 *keys)
|
||||
{
|
||||
char lastByte;
|
||||
|
||||
|
|
@ -1051,7 +1043,7 @@ bool UnzipPrivate::testKeys(const ZipEntryP& header, quint32* keys)
|
|||
/*!
|
||||
\internal Decrypts an array of bytes long \p read.
|
||||
*/
|
||||
void UnzipPrivate::decryptBytes(quint32* keys, char* buffer, qint64 read)
|
||||
void UnzipPrivate::decryptBytes(quint32 *keys, char *buffer, qint64 read)
|
||||
{
|
||||
for (int i = 0; i < (int)read; ++i)
|
||||
updateKeys(keys, buffer[i] ^= decryptByte(keys[2]));
|
||||
|
|
@ -1081,7 +1073,6 @@ QDateTime UnzipPrivate::convertDateTime(const unsigned char date[2], const unsig
|
|||
return dt;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
Public interface
|
||||
*************************************************************************/
|
||||
|
|
@ -1113,7 +1104,7 @@ bool UnZip::isOpen() const
|
|||
/*!
|
||||
Opens a zip archive and reads the files list. Closes any previously opened archive.
|
||||
*/
|
||||
UnZip::ErrorCode UnZip::openArchive(const QString& filename)
|
||||
UnZip::ErrorCode UnZip::openArchive(const QString &filename)
|
||||
{
|
||||
closeArchive();
|
||||
|
||||
|
|
@ -1140,7 +1131,7 @@ UnZip::ErrorCode UnZip::openArchive(const QString& filename)
|
|||
Closes any previously opened archive.
|
||||
\warning The class takes DOES NOT take ownership of the device.
|
||||
*/
|
||||
UnZip::ErrorCode UnZip::openArchive(QIODevice* device)
|
||||
UnZip::ErrorCode UnZip::openArchive(QIODevice *device)
|
||||
{
|
||||
closeArchive();
|
||||
|
||||
|
|
@ -1170,25 +1161,56 @@ QString UnZip::archiveComment() const
|
|||
*/
|
||||
QString UnZip::formatError(UnZip::ErrorCode c) const
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case Ok: return QCoreApplication::translate("UnZip", "ZIP operation completed successfully."); break;
|
||||
case ZlibInit: return QCoreApplication::translate("UnZip", "Failed to initialize or load zlib library."); break;
|
||||
case ZlibError: return QCoreApplication::translate("UnZip", "zlib library error."); break;
|
||||
case OpenFailed: return QCoreApplication::translate("UnZip", "Unable to create or open file."); break;
|
||||
case PartiallyCorrupted: return QCoreApplication::translate("UnZip", "Partially corrupted archive. Some files might be extracted."); break;
|
||||
case Corrupted: return QCoreApplication::translate("UnZip", "Corrupted archive."); break;
|
||||
case WrongPassword: return QCoreApplication::translate("UnZip", "Wrong password."); break;
|
||||
case NoOpenArchive: return QCoreApplication::translate("UnZip", "No archive has been created yet."); break;
|
||||
case FileNotFound: return QCoreApplication::translate("UnZip", "File or directory does not exist."); break;
|
||||
case ReadFailed: return QCoreApplication::translate("UnZip", "File read error."); break;
|
||||
case WriteFailed: return QCoreApplication::translate("UnZip", "File write error."); break;
|
||||
case SeekFailed: return QCoreApplication::translate("UnZip", "File seek error."); break;
|
||||
case CreateDirFailed: return QCoreApplication::translate("UnZip", "Unable to create a directory."); break;
|
||||
case InvalidDevice: return QCoreApplication::translate("UnZip", "Invalid device."); break;
|
||||
case InvalidArchive: return QCoreApplication::translate("UnZip", "Invalid or incompatible zip archive."); break;
|
||||
case HeaderConsistencyError: return QCoreApplication::translate("UnZip", "Inconsistent headers. Archive might be corrupted."); break;
|
||||
default: ;
|
||||
switch (c) {
|
||||
case Ok:
|
||||
return QCoreApplication::translate("UnZip", "ZIP operation completed successfully.");
|
||||
break;
|
||||
case ZlibInit:
|
||||
return QCoreApplication::translate("UnZip", "Failed to initialize or load zlib library.");
|
||||
break;
|
||||
case ZlibError:
|
||||
return QCoreApplication::translate("UnZip", "zlib library error.");
|
||||
break;
|
||||
case OpenFailed:
|
||||
return QCoreApplication::translate("UnZip", "Unable to create or open file.");
|
||||
break;
|
||||
case PartiallyCorrupted:
|
||||
return QCoreApplication::translate("UnZip", "Partially corrupted archive. Some files might be extracted.");
|
||||
break;
|
||||
case Corrupted:
|
||||
return QCoreApplication::translate("UnZip", "Corrupted archive.");
|
||||
break;
|
||||
case WrongPassword:
|
||||
return QCoreApplication::translate("UnZip", "Wrong password.");
|
||||
break;
|
||||
case NoOpenArchive:
|
||||
return QCoreApplication::translate("UnZip", "No archive has been created yet.");
|
||||
break;
|
||||
case FileNotFound:
|
||||
return QCoreApplication::translate("UnZip", "File or directory does not exist.");
|
||||
break;
|
||||
case ReadFailed:
|
||||
return QCoreApplication::translate("UnZip", "File read error.");
|
||||
break;
|
||||
case WriteFailed:
|
||||
return QCoreApplication::translate("UnZip", "File write error.");
|
||||
break;
|
||||
case SeekFailed:
|
||||
return QCoreApplication::translate("UnZip", "File seek error.");
|
||||
break;
|
||||
case CreateDirFailed:
|
||||
return QCoreApplication::translate("UnZip", "Unable to create a directory.");
|
||||
break;
|
||||
case InvalidDevice:
|
||||
return QCoreApplication::translate("UnZip", "Invalid device.");
|
||||
break;
|
||||
case InvalidArchive:
|
||||
return QCoreApplication::translate("UnZip", "Invalid or incompatible zip archive.");
|
||||
break;
|
||||
case HeaderConsistencyError:
|
||||
return QCoreApplication::translate("UnZip", "Inconsistent headers. Archive might be corrupted.");
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
|
||||
return QCoreApplication::translate("UnZip", "Unknown error.");
|
||||
|
|
@ -1197,7 +1219,7 @@ QString UnZip::formatError(UnZip::ErrorCode c) const
|
|||
/*!
|
||||
Returns true if the archive contains a file with the given path and name.
|
||||
*/
|
||||
bool UnZip::contains(const QString& file) const
|
||||
bool UnZip::contains(const QString &file) const
|
||||
{
|
||||
return d->headers ? d->headers->contains(file) : false;
|
||||
}
|
||||
|
|
@ -1219,9 +1241,8 @@ QList<UnZip::ZipEntry> UnZip::entryList() const
|
|||
if (!d->headers)
|
||||
return list;
|
||||
|
||||
for (QMap<QString,ZipEntryP*>::ConstIterator it = d->headers->constBegin();
|
||||
it != d->headers->constEnd(); ++it) {
|
||||
const ZipEntryP* entry = it.value();
|
||||
for (QMap<QString, ZipEntryP *>::ConstIterator it = d->headers->constBegin(); it != d->headers->constEnd(); ++it) {
|
||||
const ZipEntryP *entry = it.value();
|
||||
Q_ASSERT(entry != 0);
|
||||
|
||||
ZipEntry z;
|
||||
|
|
@ -1256,7 +1277,7 @@ UnZip::ErrorCode UnZip::verifyArchive()
|
|||
/*!
|
||||
Extracts the whole archive to a directory.
|
||||
*/
|
||||
UnZip::ErrorCode UnZip::extractAll(const QString& dirname, ExtractionOptions options)
|
||||
UnZip::ErrorCode UnZip::extractAll(const QString &dirname, ExtractionOptions options)
|
||||
{
|
||||
return extractAll(QDir(dirname), options);
|
||||
}
|
||||
|
|
@ -1265,7 +1286,7 @@ UnZip::ErrorCode UnZip::extractAll(const QString& dirname, ExtractionOptions opt
|
|||
Extracts the whole archive to a directory.
|
||||
Stops extraction at the first error.
|
||||
*/
|
||||
UnZip::ErrorCode UnZip::extractAll(const QDir& dir, ExtractionOptions options)
|
||||
UnZip::ErrorCode UnZip::extractAll(const QDir &dir, ExtractionOptions options)
|
||||
{
|
||||
// this should only happen if we didn't call openArchive() yet
|
||||
if (!d->device)
|
||||
|
|
@ -1276,10 +1297,10 @@ UnZip::ErrorCode UnZip::extractAll(const QDir& dir, ExtractionOptions options)
|
|||
|
||||
ErrorCode ec = Ok;
|
||||
|
||||
QMap<QString,ZipEntryP*>::ConstIterator it = d->headers->constBegin();
|
||||
const QMap<QString,ZipEntryP*>::ConstIterator end = d->headers->constEnd();
|
||||
QMap<QString, ZipEntryP *>::ConstIterator it = d->headers->constBegin();
|
||||
const QMap<QString, ZipEntryP *>::ConstIterator end = d->headers->constEnd();
|
||||
while (it != end) {
|
||||
ZipEntryP* entry = it.value();
|
||||
ZipEntryP *entry = it.value();
|
||||
Q_ASSERT(entry != 0);
|
||||
if ((entry->isEncrypted()) && d->skipAllEncrypted) {
|
||||
++it;
|
||||
|
|
@ -1289,20 +1310,19 @@ UnZip::ErrorCode UnZip::extractAll(const QDir& dir, ExtractionOptions options)
|
|||
bool skip = false;
|
||||
ec = d->extractFile(it.key(), *entry, dir, options);
|
||||
switch (ec) {
|
||||
case Corrupted:
|
||||
qDebug() << "Corrupted entry" << it.key();
|
||||
break;
|
||||
case CreateDirFailed:
|
||||
break;
|
||||
case Skip:
|
||||
skip = true;
|
||||
break;
|
||||
case SkipAll:
|
||||
skip = true;
|
||||
d->skipAllEncrypted = true;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
case Corrupted:
|
||||
qDebug() << "Corrupted entry" << it.key();
|
||||
break;
|
||||
case CreateDirFailed:
|
||||
break;
|
||||
case Skip:
|
||||
skip = true;
|
||||
break;
|
||||
case SkipAll:
|
||||
skip = true;
|
||||
d->skipAllEncrypted = true;
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
|
||||
if (ec != Ok && !skip) {
|
||||
|
|
@ -1318,7 +1338,7 @@ UnZip::ErrorCode UnZip::extractAll(const QDir& dir, ExtractionOptions options)
|
|||
/*!
|
||||
Extracts a single file to a directory.
|
||||
*/
|
||||
UnZip::ErrorCode UnZip::extractFile(const QString& filename, const QString& dirname, ExtractionOptions options)
|
||||
UnZip::ErrorCode UnZip::extractFile(const QString &filename, const QString &dirname, ExtractionOptions options)
|
||||
{
|
||||
return extractFile(filename, QDir(dirname), options);
|
||||
}
|
||||
|
|
@ -1326,16 +1346,16 @@ UnZip::ErrorCode UnZip::extractFile(const QString& filename, const QString& dirn
|
|||
/*!
|
||||
Extracts a single file to a directory.
|
||||
*/
|
||||
UnZip::ErrorCode UnZip::extractFile(const QString& filename, const QDir& dir, ExtractionOptions options)
|
||||
UnZip::ErrorCode UnZip::extractFile(const QString &filename, const QDir &dir, ExtractionOptions options)
|
||||
{
|
||||
if (!d->device)
|
||||
return NoOpenArchive;
|
||||
if (!d->headers)
|
||||
return FileNotFound;
|
||||
|
||||
QMap<QString,ZipEntryP*>::Iterator itr = d->headers->find(filename);
|
||||
QMap<QString, ZipEntryP *>::Iterator itr = d->headers->find(filename);
|
||||
if (itr != d->headers->end()) {
|
||||
ZipEntryP* entry = itr.value();
|
||||
ZipEntryP *entry = itr.value();
|
||||
Q_ASSERT(entry != 0);
|
||||
return d->extractFile(itr.key(), *entry, dir, options);
|
||||
}
|
||||
|
|
@ -1346,7 +1366,7 @@ UnZip::ErrorCode UnZip::extractFile(const QString& filename, const QDir& dir, Ex
|
|||
/*!
|
||||
Extracts a single file to a directory.
|
||||
*/
|
||||
UnZip::ErrorCode UnZip::extractFile(const QString& filename, QIODevice* outDev, ExtractionOptions options)
|
||||
UnZip::ErrorCode UnZip::extractFile(const QString &filename, QIODevice *outDev, ExtractionOptions options)
|
||||
{
|
||||
if (!d->device)
|
||||
return NoOpenArchive;
|
||||
|
|
@ -1355,9 +1375,9 @@ UnZip::ErrorCode UnZip::extractFile(const QString& filename, QIODevice* outDev,
|
|||
if (!outDev)
|
||||
return InvalidDevice;
|
||||
|
||||
QMap<QString,ZipEntryP*>::Iterator itr = d->headers->find(filename);
|
||||
QMap<QString, ZipEntryP *>::Iterator itr = d->headers->find(filename);
|
||||
if (itr != d->headers->end()) {
|
||||
ZipEntryP* entry = itr.value();
|
||||
ZipEntryP *entry = itr.value();
|
||||
Q_ASSERT(entry != 0);
|
||||
return d->extractFile(itr.key(), *entry, outDev, options);
|
||||
}
|
||||
|
|
@ -1369,7 +1389,7 @@ UnZip::ErrorCode UnZip::extractFile(const QString& filename, QIODevice* outDev,
|
|||
Extracts a list of files.
|
||||
Stops extraction at the first error (but continues if a file does not exist in the archive).
|
||||
*/
|
||||
UnZip::ErrorCode UnZip::extractFiles(const QStringList& filenames, const QString& dirname, ExtractionOptions options)
|
||||
UnZip::ErrorCode UnZip::extractFiles(const QStringList &filenames, const QString &dirname, ExtractionOptions options)
|
||||
{
|
||||
if (!d->device)
|
||||
return NoOpenArchive;
|
||||
|
|
@ -1394,7 +1414,7 @@ UnZip::ErrorCode UnZip::extractFiles(const QStringList& filenames, const QString
|
|||
Extracts a list of files.
|
||||
Stops extraction at the first error (but continues if a file does not exist in the archive).
|
||||
*/
|
||||
UnZip::ErrorCode UnZip::extractFiles(const QStringList& filenames, const QDir& dir, ExtractionOptions options)
|
||||
UnZip::ErrorCode UnZip::extractFiles(const QStringList &filenames, const QDir &dir, ExtractionOptions options)
|
||||
{
|
||||
if (!d->device)
|
||||
return NoOpenArchive;
|
||||
|
|
@ -1417,7 +1437,7 @@ UnZip::ErrorCode UnZip::extractFiles(const QStringList& filenames, const QDir& d
|
|||
/*!
|
||||
Remove/replace this method to add your own password retrieval routine.
|
||||
*/
|
||||
void UnZip::setPassword(const QString& pwd)
|
||||
void UnZip::setPassword(const QString &pwd)
|
||||
{
|
||||
d->password = pwd;
|
||||
}
|
||||
|
|
|
|||
96
cockatrice/src/utility/external/zip/unzip_p.h
vendored
Executable file → Normal file
96
cockatrice/src/utility/external/zip/unzip_p.h
vendored
Executable file → Normal file
|
|
@ -47,7 +47,7 @@
|
|||
|
||||
// zLib authors suggest using larger buffers (128K or 256K) for (de)compression (especially for inflate())
|
||||
// we use a 256K buffer here - if you want to use this code on a pre-iceage mainframe please change it ;)
|
||||
#define UNZIP_READ_BUFFER (256*1024)
|
||||
#define UNZIP_READ_BUFFER (256 * 1024)
|
||||
|
||||
OSDAB_BEGIN_NAMESPACE(Zip)
|
||||
|
||||
|
|
@ -56,72 +56,80 @@ class UnzipPrivate : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UnzipPrivate();
|
||||
UnzipPrivate();
|
||||
|
||||
// Replace this with whatever else you use to store/retrieve the password.
|
||||
QString password;
|
||||
// Replace this with whatever else you use to store/retrieve the password.
|
||||
QString password;
|
||||
|
||||
bool skipAllEncrypted;
|
||||
bool skipAllEncrypted;
|
||||
|
||||
QMap<QString,ZipEntryP*>* headers;
|
||||
QMap<QString, ZipEntryP *> *headers;
|
||||
|
||||
QIODevice* device;
|
||||
QFile* file;
|
||||
QIODevice *device;
|
||||
QFile *file;
|
||||
|
||||
char buffer1[UNZIP_READ_BUFFER];
|
||||
char buffer2[UNZIP_READ_BUFFER];
|
||||
char buffer1[UNZIP_READ_BUFFER];
|
||||
char buffer2[UNZIP_READ_BUFFER];
|
||||
|
||||
unsigned char* uBuffer;
|
||||
const quint32* crcTable;
|
||||
unsigned char *uBuffer;
|
||||
const quint32 *crcTable;
|
||||
|
||||
// Central Directory (CD) offset
|
||||
quint32 cdOffset;
|
||||
// End of Central Directory (EOCD) offset
|
||||
quint32 eocdOffset;
|
||||
// Central Directory (CD) offset
|
||||
quint32 cdOffset;
|
||||
// End of Central Directory (EOCD) offset
|
||||
quint32 eocdOffset;
|
||||
|
||||
// Number of entries in the Central Directory (as to the EOCD record)
|
||||
quint16 cdEntryCount;
|
||||
// Number of entries in the Central Directory (as to the EOCD record)
|
||||
quint16 cdEntryCount;
|
||||
|
||||
// The number of detected entries that have been skipped because of a non compatible format
|
||||
quint16 unsupportedEntryCount;
|
||||
// The number of detected entries that have been skipped because of a non compatible format
|
||||
quint16 unsupportedEntryCount;
|
||||
|
||||
QString comment;
|
||||
QString comment;
|
||||
|
||||
UnZip::ErrorCode openArchive(QIODevice* device);
|
||||
UnZip::ErrorCode openArchive(QIODevice *device);
|
||||
|
||||
UnZip::ErrorCode seekToCentralDirectory();
|
||||
UnZip::ErrorCode parseCentralDirectoryRecord();
|
||||
UnZip::ErrorCode parseLocalHeaderRecord(const QString& path, const ZipEntryP& entry);
|
||||
UnZip::ErrorCode seekToCentralDirectory();
|
||||
UnZip::ErrorCode parseCentralDirectoryRecord();
|
||||
UnZip::ErrorCode parseLocalHeaderRecord(const QString &path, const ZipEntryP &entry);
|
||||
|
||||
void closeArchive();
|
||||
void closeArchive();
|
||||
|
||||
UnZip::ErrorCode extractFile(const QString& path, const ZipEntryP& entry, const QDir& dir, UnZip::ExtractionOptions options);
|
||||
UnZip::ErrorCode extractFile(const QString& path, const ZipEntryP& entry, QIODevice* device, UnZip::ExtractionOptions options);
|
||||
UnZip::ErrorCode
|
||||
extractFile(const QString &path, const ZipEntryP &entry, const QDir &dir, UnZip::ExtractionOptions options);
|
||||
UnZip::ErrorCode
|
||||
extractFile(const QString &path, const ZipEntryP &entry, QIODevice *device, UnZip::ExtractionOptions options);
|
||||
|
||||
UnZip::ErrorCode testPassword(quint32* keys, const QString&_file, const ZipEntryP& header);
|
||||
bool testKeys(const ZipEntryP& header, quint32* keys);
|
||||
UnZip::ErrorCode testPassword(quint32 *keys, const QString &_file, const ZipEntryP &header);
|
||||
bool testKeys(const ZipEntryP &header, quint32 *keys);
|
||||
|
||||
bool createDirectory(const QString& path);
|
||||
bool createDirectory(const QString &path);
|
||||
|
||||
inline void decryptBytes(quint32* keys, char* buffer, qint64 read);
|
||||
inline void decryptBytes(quint32 *keys, char *buffer, qint64 read);
|
||||
|
||||
inline quint32 getULong(const unsigned char* data, quint32 offset) const;
|
||||
inline quint64 getULLong(const unsigned char* data, quint32 offset) const;
|
||||
inline quint16 getUShort(const unsigned char* data, quint32 offset) const;
|
||||
inline int decryptByte(quint32 key2) const;
|
||||
inline void updateKeys(quint32* keys, int c) const;
|
||||
inline void initKeys(const QString& pwd, quint32* keys) const;
|
||||
inline quint32 getULong(const unsigned char *data, quint32 offset) const;
|
||||
inline quint64 getULLong(const unsigned char *data, quint32 offset) const;
|
||||
inline quint16 getUShort(const unsigned char *data, quint32 offset) const;
|
||||
inline int decryptByte(quint32 key2) const;
|
||||
inline void updateKeys(quint32 *keys, int c) const;
|
||||
inline void initKeys(const QString &pwd, quint32 *keys) const;
|
||||
|
||||
inline QDateTime convertDateTime(const unsigned char date[2], const unsigned char time[2]) const;
|
||||
inline QDateTime convertDateTime(const unsigned char date[2], const unsigned char time[2]) const;
|
||||
|
||||
private slots:
|
||||
void deviceDestroyed(QObject*);
|
||||
void deviceDestroyed(QObject *);
|
||||
|
||||
private:
|
||||
UnZip::ErrorCode extractStoredFile(const quint32 szComp, quint32** keys,
|
||||
quint32& myCRC, QIODevice* outDev, UnZip::ExtractionOptions options);
|
||||
UnZip::ErrorCode inflateFile(const quint32 szComp, quint32** keys,
|
||||
quint32& myCRC, QIODevice* outDev, UnZip::ExtractionOptions options);
|
||||
UnZip::ErrorCode extractStoredFile(const quint32 szComp,
|
||||
quint32 **keys,
|
||||
quint32 &myCRC,
|
||||
QIODevice *outDev,
|
||||
UnZip::ExtractionOptions options);
|
||||
UnZip::ErrorCode inflateFile(const quint32 szComp,
|
||||
quint32 **keys,
|
||||
quint32 &myCRC,
|
||||
QIODevice *outDev,
|
||||
UnZip::ExtractionOptions options);
|
||||
void do_closeArchive();
|
||||
};
|
||||
|
||||
|
|
|
|||
1148
cockatrice/src/utility/external/zip/zip.cpp
vendored
Executable file → Normal file
1148
cockatrice/src/utility/external/zip/zip.cpp
vendored
Executable file → Normal file
File diff suppressed because it is too large
Load diff
132
cockatrice/src/utility/external/zip/zip.h
vendored
Executable file → Normal file
132
cockatrice/src/utility/external/zip/zip.h
vendored
Executable file → Normal file
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
#include <zlib/zlib.h>
|
||||
|
||||
class QIODevice;
|
||||
|
|
@ -48,36 +47,45 @@ class ZipPrivate;
|
|||
class OSDAB_ZIP_EXPORT Zip
|
||||
{
|
||||
public:
|
||||
enum ErrorCode
|
||||
{
|
||||
Ok,
|
||||
ZlibInit,
|
||||
ZlibError,
|
||||
FileExists,
|
||||
OpenFailed,
|
||||
NoOpenArchive,
|
||||
FileNotFound,
|
||||
ReadFailed,
|
||||
WriteFailed,
|
||||
enum ErrorCode
|
||||
{
|
||||
Ok,
|
||||
ZlibInit,
|
||||
ZlibError,
|
||||
FileExists,
|
||||
OpenFailed,
|
||||
NoOpenArchive,
|
||||
FileNotFound,
|
||||
ReadFailed,
|
||||
WriteFailed,
|
||||
SeekFailed,
|
||||
InternalError
|
||||
};
|
||||
};
|
||||
|
||||
enum CompressionLevel
|
||||
{
|
||||
Store,
|
||||
Deflate1 = 1, Deflate2, Deflate3, Deflate4,
|
||||
Deflate5, Deflate6, Deflate7, Deflate8, Deflate9,
|
||||
AutoCPU, AutoMIME, AutoFull
|
||||
};
|
||||
enum CompressionLevel
|
||||
{
|
||||
Store,
|
||||
Deflate1 = 1,
|
||||
Deflate2,
|
||||
Deflate3,
|
||||
Deflate4,
|
||||
Deflate5,
|
||||
Deflate6,
|
||||
Deflate7,
|
||||
Deflate8,
|
||||
Deflate9,
|
||||
AutoCPU,
|
||||
AutoMIME,
|
||||
AutoFull
|
||||
};
|
||||
|
||||
enum CompressionOption
|
||||
{
|
||||
enum CompressionOption
|
||||
{
|
||||
/*! Does not preserve absolute paths in the zip file when adding a
|
||||
file or directory (default) */
|
||||
RelativePaths = 0x0001,
|
||||
RelativePaths = 0x0001,
|
||||
/*! Preserve absolute paths */
|
||||
AbsolutePaths = 0x0002,
|
||||
AbsolutePaths = 0x0002,
|
||||
/*! Do not store paths. All the files are put in the (evtl. user defined)
|
||||
root of the zip file */
|
||||
IgnorePaths = 0x0004,
|
||||
|
|
@ -95,60 +103,54 @@ public:
|
|||
this flag.
|
||||
*/
|
||||
CheckForDuplicates = 0x0040
|
||||
};
|
||||
Q_DECLARE_FLAGS(CompressionOptions, CompressionOption)
|
||||
};
|
||||
Q_DECLARE_FLAGS(CompressionOptions, CompressionOption)
|
||||
|
||||
Zip();
|
||||
virtual ~Zip();
|
||||
Zip();
|
||||
virtual ~Zip();
|
||||
|
||||
bool isOpen() const;
|
||||
bool isOpen() const;
|
||||
|
||||
void setPassword(const QString& pwd);
|
||||
void clearPassword();
|
||||
QString password() const;
|
||||
void setPassword(const QString &pwd);
|
||||
void clearPassword();
|
||||
QString password() const;
|
||||
|
||||
ErrorCode createArchive(const QString& file, bool overwrite = true);
|
||||
ErrorCode createArchive(QIODevice* device);
|
||||
ErrorCode createArchive(const QString &file, bool overwrite = true);
|
||||
ErrorCode createArchive(QIODevice *device);
|
||||
|
||||
QString archiveComment() const;
|
||||
void setArchiveComment(const QString& comment);
|
||||
QString archiveComment() const;
|
||||
void setArchiveComment(const QString &comment);
|
||||
|
||||
ErrorCode addDirectoryContents(const QString& path,
|
||||
CompressionLevel level = AutoFull);
|
||||
ErrorCode addDirectoryContents(const QString& path, const QString& root,
|
||||
CompressionLevel level = AutoFull);
|
||||
ErrorCode addDirectoryContents(const QString &path, CompressionLevel level = AutoFull);
|
||||
ErrorCode addDirectoryContents(const QString &path, const QString &root, CompressionLevel level = AutoFull);
|
||||
|
||||
ErrorCode addDirectory(const QString& path,
|
||||
CompressionLevel level = AutoFull);
|
||||
ErrorCode addDirectory(const QString& path, const QString& root,
|
||||
CompressionLevel level = AutoFull);
|
||||
ErrorCode addDirectory(const QString& path, const QString& root,
|
||||
CompressionOptions options, CompressionLevel level = AutoFull,
|
||||
int* addedFiles = 0);
|
||||
ErrorCode addDirectory(const QString &path, CompressionLevel level = AutoFull);
|
||||
ErrorCode addDirectory(const QString &path, const QString &root, CompressionLevel level = AutoFull);
|
||||
ErrorCode addDirectory(const QString &path,
|
||||
const QString &root,
|
||||
CompressionOptions options,
|
||||
CompressionLevel level = AutoFull,
|
||||
int *addedFiles = 0);
|
||||
|
||||
ErrorCode addFile(const QString& path,
|
||||
CompressionLevel level = AutoFull);
|
||||
ErrorCode addFile(const QString& path, const QString& root,
|
||||
CompressionLevel level = AutoFull);
|
||||
ErrorCode addFile(const QString& path, const QString& root,
|
||||
CompressionOptions options,
|
||||
CompressionLevel level = AutoFull);
|
||||
ErrorCode addFile(const QString &path, CompressionLevel level = AutoFull);
|
||||
ErrorCode addFile(const QString &path, const QString &root, CompressionLevel level = AutoFull);
|
||||
ErrorCode
|
||||
addFile(const QString &path, const QString &root, CompressionOptions options, CompressionLevel level = AutoFull);
|
||||
|
||||
ErrorCode addFiles(const QStringList& paths,
|
||||
CompressionLevel level = AutoFull);
|
||||
ErrorCode addFiles(const QStringList& paths, const QString& root,
|
||||
CompressionLevel level = AutoFull);
|
||||
ErrorCode addFiles(const QStringList& paths, const QString& root,
|
||||
CompressionOptions options,
|
||||
CompressionLevel level = AutoFull,
|
||||
int* addedFiles = 0);
|
||||
ErrorCode addFiles(const QStringList &paths, CompressionLevel level = AutoFull);
|
||||
ErrorCode addFiles(const QStringList &paths, const QString &root, CompressionLevel level = AutoFull);
|
||||
ErrorCode addFiles(const QStringList &paths,
|
||||
const QString &root,
|
||||
CompressionOptions options,
|
||||
CompressionLevel level = AutoFull,
|
||||
int *addedFiles = 0);
|
||||
|
||||
ErrorCode closeArchive();
|
||||
ErrorCode closeArchive();
|
||||
|
||||
QString formatError(ErrorCode c) const;
|
||||
QString formatError(ErrorCode c) const;
|
||||
|
||||
private:
|
||||
ZipPrivate* d;
|
||||
ZipPrivate *d;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Zip::CompressionOptions)
|
||||
|
|
|
|||
97
cockatrice/src/utility/external/zip/zip_p.h
vendored
Executable file → Normal file
97
cockatrice/src/utility/external/zip/zip_p.h
vendored
Executable file → Normal file
|
|
@ -45,14 +45,13 @@
|
|||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
#include <zlib/zconf.h>
|
||||
|
||||
/*!
|
||||
zLib authors suggest using larger buffers (128K or 256K) for (de)compression (especially for inflate())
|
||||
we use a 256K buffer here - if you want to use this code on a pre-iceage mainframe please change it ;)
|
||||
zLib authors suggest using larger buffers (128K or 256K) for (de)compression (especially for inflate())
|
||||
we use a 256K buffer here - if you want to use this code on a pre-iceage mainframe please change it ;)
|
||||
*/
|
||||
#define ZIP_READ_BUFFER (256*1024)
|
||||
#define ZIP_READ_BUFFER (256 * 1024)
|
||||
|
||||
OSDAB_BEGIN_NAMESPACE(Zip)
|
||||
|
||||
|
|
@ -64,67 +63,77 @@ public:
|
|||
// uLongf from zconf.h
|
||||
typedef uLongf crc_t;
|
||||
|
||||
ZipPrivate();
|
||||
virtual ~ZipPrivate();
|
||||
ZipPrivate();
|
||||
virtual ~ZipPrivate();
|
||||
|
||||
QMap<QString,ZipEntryP*>* headers;
|
||||
QMap<QString, ZipEntryP *> *headers;
|
||||
|
||||
QIODevice* device;
|
||||
QFile* file;
|
||||
QIODevice *device;
|
||||
QFile *file;
|
||||
|
||||
char buffer1[ZIP_READ_BUFFER];
|
||||
char buffer2[ZIP_READ_BUFFER];
|
||||
char buffer1[ZIP_READ_BUFFER];
|
||||
char buffer2[ZIP_READ_BUFFER];
|
||||
|
||||
unsigned char* uBuffer;
|
||||
unsigned char *uBuffer;
|
||||
|
||||
const crc_t* crcTable;
|
||||
const crc_t *crcTable;
|
||||
|
||||
QString comment;
|
||||
QString password;
|
||||
QString comment;
|
||||
QString password;
|
||||
|
||||
Zip::ErrorCode createArchive(QIODevice* device);
|
||||
Zip::ErrorCode closeArchive();
|
||||
void reset();
|
||||
Zip::ErrorCode createArchive(QIODevice *device);
|
||||
Zip::ErrorCode closeArchive();
|
||||
void reset();
|
||||
|
||||
bool zLibInit();
|
||||
bool zLibInit();
|
||||
|
||||
bool containsEntry(const QFileInfo& info) const;
|
||||
bool containsEntry(const QFileInfo &info) const;
|
||||
|
||||
Zip::ErrorCode addDirectory(const QString& path, const QString& root,
|
||||
Zip::CompressionOptions options, Zip::CompressionLevel level,
|
||||
int hierarchyLevel, int* addedFiles = 0);
|
||||
Zip::ErrorCode addFiles(const QStringList& paths, const QString& root,
|
||||
Zip::CompressionOptions options, Zip::CompressionLevel level,
|
||||
int* addedFiles);
|
||||
Zip::ErrorCode addDirectory(const QString &path,
|
||||
const QString &root,
|
||||
Zip::CompressionOptions options,
|
||||
Zip::CompressionLevel level,
|
||||
int hierarchyLevel,
|
||||
int *addedFiles = 0);
|
||||
Zip::ErrorCode addFiles(const QStringList &paths,
|
||||
const QString &root,
|
||||
Zip::CompressionOptions options,
|
||||
Zip::CompressionLevel level,
|
||||
int *addedFiles);
|
||||
|
||||
Zip::ErrorCode createEntry(const QFileInfo& file, const QString& root,
|
||||
Zip::CompressionLevel level);
|
||||
Zip::CompressionLevel detectCompressionByMime(const QString& ext);
|
||||
Zip::ErrorCode createEntry(const QFileInfo &file, const QString &root, Zip::CompressionLevel level);
|
||||
Zip::CompressionLevel detectCompressionByMime(const QString &ext);
|
||||
|
||||
inline quint32 updateChecksum(const quint32& crc, const quint32& val) const;
|
||||
inline quint32 updateChecksum(const quint32 &crc, const quint32 &val) const;
|
||||
|
||||
inline void encryptBytes(quint32* keys, char* buffer, qint64 read);
|
||||
inline void encryptBytes(quint32 *keys, char *buffer, qint64 read);
|
||||
|
||||
inline void setULong(quint32 v, char* buffer, unsigned int offset);
|
||||
inline void updateKeys(quint32* keys, int c) const;
|
||||
inline void initKeys(quint32* keys) const;
|
||||
inline void setULong(quint32 v, char *buffer, unsigned int offset);
|
||||
inline void updateKeys(quint32 *keys, int c) const;
|
||||
inline void initKeys(quint32 *keys) const;
|
||||
inline int decryptByte(quint32 key2) const;
|
||||
|
||||
inline QString extractRoot(const QString& p, Zip::CompressionOptions o);
|
||||
inline QString extractRoot(const QString &p, Zip::CompressionOptions o);
|
||||
|
||||
private slots:
|
||||
void deviceDestroyed(QObject*);
|
||||
void deviceDestroyed(QObject *);
|
||||
|
||||
private:
|
||||
int compressionStrategy(const QString& path, QIODevice& file) const;
|
||||
Zip::ErrorCode deflateFile(const QFileInfo& fileInfo,
|
||||
quint32& crc, qint64& written, const Zip::CompressionLevel& level, quint32** keys);
|
||||
Zip::ErrorCode storeFile(const QString& path, QIODevice& file,
|
||||
quint32& crc, qint64& written, quint32** keys);
|
||||
Zip::ErrorCode compressFile(const QString& path, QIODevice& file,
|
||||
quint32& crc, qint64& written, const Zip::CompressionLevel& level, quint32** keys);
|
||||
int compressionStrategy(const QString &path, QIODevice &file) const;
|
||||
Zip::ErrorCode deflateFile(const QFileInfo &fileInfo,
|
||||
quint32 &crc,
|
||||
qint64 &written,
|
||||
const Zip::CompressionLevel &level,
|
||||
quint32 **keys);
|
||||
Zip::ErrorCode storeFile(const QString &path, QIODevice &file, quint32 &crc, qint64 &written, quint32 **keys);
|
||||
Zip::ErrorCode compressFile(const QString &path,
|
||||
QIODevice &file,
|
||||
quint32 &crc,
|
||||
qint64 &written,
|
||||
const Zip::CompressionLevel &level,
|
||||
quint32 **keys);
|
||||
Zip::ErrorCode do_closeArchive();
|
||||
Zip::ErrorCode writeEntry(const QString& fileName, const ZipEntryP* h, quint32& szCentralDir);
|
||||
Zip::ErrorCode writeEntry(const QString &fileName, const ZipEntryP *h, quint32 &szCentralDir);
|
||||
Zip::ErrorCode writeCentralDir(quint32 offCentralDir, quint32 szCentralDir);
|
||||
};
|
||||
|
||||
|
|
|
|||
54
cockatrice/src/utility/external/zip/zipentry_p.h
vendored
Executable file → Normal file
54
cockatrice/src/utility/external/zip/zipentry_p.h
vendored
Executable file → Normal file
|
|
@ -47,43 +47,39 @@ OSDAB_BEGIN_NAMESPACE(Zip)
|
|||
class ZipEntryP
|
||||
{
|
||||
public:
|
||||
ZipEntryP() :
|
||||
lhOffset(0),
|
||||
dataOffset(0),
|
||||
gpFlag(),
|
||||
compMethod(0),
|
||||
modTime(),
|
||||
modDate(),
|
||||
crc(0),
|
||||
szComp(0),
|
||||
szUncomp(0),
|
||||
absolutePath(),
|
||||
fileSize(0),
|
||||
lhEntryChecked(false)
|
||||
ZipEntryP()
|
||||
: lhOffset(0), dataOffset(0), gpFlag(), compMethod(0), modTime(), modDate(), crc(0), szComp(0), szUncomp(0),
|
||||
absolutePath(), fileSize(0), lhEntryChecked(false)
|
||||
{
|
||||
gpFlag[0] = gpFlag[1] = 0;
|
||||
modTime[0] = modTime[1] = 0;
|
||||
modDate[0] = modDate[1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
quint32 lhOffset; // Offset of the local header record for this entry
|
||||
mutable quint32 dataOffset; // Offset of the file data for this entry
|
||||
unsigned char gpFlag[2]; // General purpose flag
|
||||
quint16 compMethod; // Compression method
|
||||
unsigned char modTime[2]; // Last modified time
|
||||
unsigned char modDate[2]; // Last modified date
|
||||
quint32 crc; // CRC32
|
||||
quint32 szComp; // Compressed file size
|
||||
quint32 szUncomp; // Uncompressed file size
|
||||
QString comment; // File comment
|
||||
quint32 lhOffset; // Offset of the local header record for this entry
|
||||
mutable quint32 dataOffset; // Offset of the file data for this entry
|
||||
unsigned char gpFlag[2]; // General purpose flag
|
||||
quint16 compMethod; // Compression method
|
||||
unsigned char modTime[2]; // Last modified time
|
||||
unsigned char modDate[2]; // Last modified date
|
||||
quint32 crc; // CRC32
|
||||
quint32 szComp; // Compressed file size
|
||||
quint32 szUncomp; // Uncompressed file size
|
||||
QString comment; // File comment
|
||||
|
||||
QString absolutePath; // Internal use
|
||||
qint64 fileSize; // Internal use
|
||||
QString absolutePath; // Internal use
|
||||
qint64 fileSize; // Internal use
|
||||
|
||||
mutable bool lhEntryChecked; // Is true if the local header record for this entry has been parsed
|
||||
mutable bool lhEntryChecked; // Is true if the local header record for this entry has been parsed
|
||||
|
||||
inline bool isEncrypted() const { return gpFlag[0] & 0x01; }
|
||||
inline bool hasDataDescriptor() const { return gpFlag[0] & 0x08; }
|
||||
inline bool isEncrypted() const
|
||||
{
|
||||
return gpFlag[0] & 0x01;
|
||||
}
|
||||
inline bool hasDataDescriptor() const
|
||||
{
|
||||
return gpFlag[0] & 0x08;
|
||||
}
|
||||
};
|
||||
|
||||
OSDAB_END_NAMESPACE
|
||||
|
|
|
|||
26
cockatrice/src/utility/external/zip/zipglobal.h
vendored
Executable file → Normal file
26
cockatrice/src/utility/external/zip/zipglobal.h
vendored
Executable file → Normal file
|
|
@ -39,23 +39,29 @@
|
|||
*/
|
||||
|
||||
#ifndef OSDAB_ZIP_LIB
|
||||
# define OSDAB_ZIP_EXPORT
|
||||
#define OSDAB_ZIP_EXPORT
|
||||
#else
|
||||
# if defined(OSDAB_ZIP_BUILD_LIB)
|
||||
# define OSDAB_ZIP_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define OSDAB_ZIP_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#if defined(OSDAB_ZIP_BUILD_LIB)
|
||||
#define OSDAB_ZIP_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define OSDAB_ZIP_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef OSDAB_NAMESPACE
|
||||
#define OSDAB_BEGIN_NAMESPACE(ModuleName) namespace Osdab { namespace ModuleName {
|
||||
#define OSDAB_BEGIN_NAMESPACE(ModuleName) \
|
||||
namespace Osdab \
|
||||
{ \
|
||||
namespace ModuleName \
|
||||
{
|
||||
#else
|
||||
#define OSDAB_BEGIN_NAMESPACE(ModuleName)
|
||||
#endif
|
||||
|
||||
#ifdef OSDAB_NAMESPACE
|
||||
#define OSDAB_END_NAMESPACE } }
|
||||
#define OSDAB_END_NAMESPACE \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define OSDAB_END_NAMESPACE
|
||||
#endif
|
||||
|
|
@ -69,8 +75,8 @@
|
|||
OSDAB_BEGIN_NAMESPACE(Zip)
|
||||
|
||||
OSDAB_ZIP_EXPORT int OSDAB_ZIP_MANGLE(currentUtcOffset)();
|
||||
OSDAB_ZIP_EXPORT QDateTime OSDAB_ZIP_MANGLE(fromFileTimestamp)(const QDateTime& dateTime);
|
||||
OSDAB_ZIP_EXPORT bool OSDAB_ZIP_MANGLE(setFileTimestamp)(const QString& fileName, const QDateTime& dateTime);
|
||||
OSDAB_ZIP_EXPORT QDateTime OSDAB_ZIP_MANGLE(fromFileTimestamp)(const QDateTime &dateTime);
|
||||
OSDAB_ZIP_EXPORT bool OSDAB_ZIP_MANGLE(setFileTimestamp)(const QString &fileName, const QDateTime &dateTime);
|
||||
|
||||
OSDAB_END_NAMESPACE
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue