mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Merged in selmf/yacreader/compressed-archive-testing (pull request #24)
wrapper improvements
This commit is contained in:
commit
a3935811ed
@ -223,12 +223,7 @@ exists (../compressed_archive/libp7zip) {
|
|||||||
Please check the compressed_archive folder for further instructions.)
|
Please check the compressed_archive folder for further instructions.)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
exists (../compressed_archive/unarr/unarr-master) {
|
|
||||||
message(Found unarr source-code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unix:!macx {
|
unix:!macx {
|
||||||
#set install prefix if it's empty
|
#set install prefix if it's empty
|
||||||
|
@ -285,10 +285,6 @@ exists (../compressed_archive/libp7zip) {
|
|||||||
Please check the compressed_archive folder for further instructions.)
|
Please check the compressed_archive folder for further instructions.)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
exists (../compressed_archive/unarr/unarr-master) {
|
|
||||||
message(Found unarr source code)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unix:!macx {
|
unix:!macx {
|
||||||
|
@ -122,8 +122,8 @@ void LibraryCreator::processLibrary(const QString & source, const QString & targ
|
|||||||
void LibraryCreator::run()
|
void LibraryCreator::run()
|
||||||
{
|
{
|
||||||
stopRunning = false;
|
stopRunning = false;
|
||||||
|
#ifndef use_unarr
|
||||||
//check for 7z lib
|
//check for 7z lib
|
||||||
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
||||||
QLibrary *sevenzLib = new QLibrary(QString(LIBDIR)+"/p7zip/7z.so");
|
QLibrary *sevenzLib = new QLibrary(QString(LIBDIR)+"/p7zip/7z.so");
|
||||||
#else
|
#else
|
||||||
@ -137,7 +137,7 @@ void LibraryCreator::run()
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
sevenzLib->deleteLater();
|
sevenzLib->deleteLater();
|
||||||
|
#endif
|
||||||
if(_mode == CREATOR)
|
if(_mode == CREATOR)
|
||||||
{
|
{
|
||||||
QLOG_INFO() << "Starting to create new library ( " << _source << "," << _target << ")";
|
QLOG_INFO() << "Starting to create new library ( " << _source << "," << _target << ")";
|
||||||
|
@ -92,6 +92,7 @@ void logSystemAndConfig()
|
|||||||
QLOG_INFO() << "SO : Unknown";
|
QLOG_INFO() << "SO : Unknown";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef use_unarr
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
if(QLibrary::isLibrary(QApplication::applicationDirPath()+"/utils/7z.dll"))
|
if(QLibrary::isLibrary(QApplication::applicationDirPath()+"/utils/7z.dll"))
|
||||||
#elif defined Q_OS_UNIX && !defined Q_OS_MAC
|
#elif defined Q_OS_UNIX && !defined Q_OS_MAC
|
||||||
@ -102,6 +103,9 @@ void logSystemAndConfig()
|
|||||||
QLOG_INFO() << "7z : found";
|
QLOG_INFO() << "7z : found";
|
||||||
else
|
else
|
||||||
QLOG_ERROR() << "7z : not found";
|
QLOG_ERROR() << "7z : not found";
|
||||||
|
#else
|
||||||
|
QLOG_INFO() << "using unarr decompression backend";
|
||||||
|
#endif
|
||||||
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
||||||
if(QFileInfo(QString(BINDIR)+"/qrencode").exists())
|
if(QFileInfo(QString(BINDIR)+"/qrencode").exists())
|
||||||
#else
|
#else
|
||||||
|
@ -73,6 +73,13 @@ struct SevenZipInterface {
|
|||||||
|
|
||||||
//SevenZipInterface * szInterface;
|
//SevenZipInterface * szInterface;
|
||||||
|
|
||||||
|
const char rar[7]={0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00};
|
||||||
|
const char rar5[8]={0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00};
|
||||||
|
const char zip[2]={0x50, 0x4B};
|
||||||
|
const char sevenz[6]={0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C};
|
||||||
|
const char tar[6]="ustar";
|
||||||
|
const char arj[2]={0x60, 0xEA};
|
||||||
|
|
||||||
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
|
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
|
||||||
QObject(parent),sevenzLib(0),valid(false),tools(false)
|
QObject(parent),sevenzLib(0),valid(false),tools(false)
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
@ -101,35 +108,76 @@ CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent)
|
|||||||
// openCallbackSpec->Password = L"1";
|
// openCallbackSpec->Password = L"1";
|
||||||
|
|
||||||
//get file type from suffix
|
//get file type from suffix
|
||||||
QString suffix=QFileInfo(filePath).suffix();
|
int i=-1;
|
||||||
int i;
|
QFile filex(filePath);
|
||||||
|
|
||||||
|
if (!filex.open(QIODevice::ReadOnly))
|
||||||
|
return;
|
||||||
|
QByteArray magicNumber=filex.read(8); //read first 8 bytes
|
||||||
|
|
||||||
|
//if (memcmp(magicNumber,rar5,8)==0)
|
||||||
|
//return; //rar5 is not supported
|
||||||
|
//qDebug() << memcmp(magicNumber,rar,7);
|
||||||
//TODO: this suffix matching is rather primitive - better approach?
|
//TODO: this suffix matching is rather primitive - better approach?
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
if (suffix != "cbr" && suffix != "rar")
|
if (memcmp(magicNumber,rar,6) != 0)
|
||||||
{
|
{
|
||||||
//match suffix to GUID list
|
//match suffix to GUID list
|
||||||
if (suffix == "zip" || suffix == "cbz")
|
if (memcmp(magicNumber,zip,2)==0)
|
||||||
i=0;
|
i=0;
|
||||||
else if (suffix == "tar" || suffix == "cbt")
|
else if (memcmp(magicNumber,sevenz,6)==0)
|
||||||
i=1;
|
|
||||||
else if (suffix == "7z" || suffix == "cb7")
|
|
||||||
i=2;
|
i=2;
|
||||||
else if (suffix == "arj")
|
else if (memcmp(magicNumber,arj,2)==0)
|
||||||
i=3;
|
i=3;
|
||||||
else return;
|
else
|
||||||
|
{
|
||||||
|
filex.seek(257);
|
||||||
|
magicNumber=filex.read(8);
|
||||||
|
if (memcmp(magicNumber,tar,5)==0)
|
||||||
|
i=1;
|
||||||
|
}
|
||||||
|
if (i==-1) //fallback code
|
||||||
|
{
|
||||||
|
QFileInfo fileinfo(filePath);
|
||||||
|
if (fileinfo.suffix() == "zip" || fileinfo.suffix() == "cbz")
|
||||||
|
{
|
||||||
|
i=0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
//match suffix to GUID list
|
if (memcmp(magicNumber,rar,6) == 0)
|
||||||
if (suffix == "rar" || suffix == "cbr")
|
if (memcmp(magicNumber,rar5,7) == 0)
|
||||||
i=0;
|
return;
|
||||||
else if (suffix == "zip" || suffix == "cbz")
|
else
|
||||||
|
i=0;
|
||||||
|
else if (memcmp(magicNumber,zip,2)==0)
|
||||||
i=1;
|
i=1;
|
||||||
else if (suffix == "tar" || suffix == "cbt")
|
else if (memcmp(magicNumber,sevenz,6)==0)
|
||||||
i=2;
|
|
||||||
else if (suffix == "7z" || suffix == "cb7")
|
|
||||||
i=3;
|
i=3;
|
||||||
else if (suffix == "arj")
|
else if (memcmp(magicNumber,arj,2)==0)
|
||||||
i=4;
|
i=4;
|
||||||
else return;
|
else {
|
||||||
|
filex.seek(257);
|
||||||
|
magicNumber=filex.read(8);
|
||||||
|
if (memcmp(magicNumber,tar,5)==0)
|
||||||
|
i=2;
|
||||||
|
}
|
||||||
|
if (i==-1) //fallback code
|
||||||
|
{
|
||||||
|
QFileInfo fileinfo(filePath);
|
||||||
|
if (fileinfo.suffix() == "zip" || fileinfo.suffix() == "cbz")
|
||||||
|
{
|
||||||
|
i=1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
@ -169,8 +217,10 @@ CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
isRar=true; //tell the destructor we *tried* to open a rar file!
|
if (memcmp(magicNumber,rar5,7) == 0)
|
||||||
//according to valgrind, something goes wrong here
|
return;//we don't support rar5
|
||||||
|
|
||||||
|
isRar=true; //tell the destructor we *tried* to open a rar file!
|
||||||
if (szInterface->createObjectFunc(&CLSID_CFormatRar, &IID_InArchive, (void **)&szInterface->archive) != S_OK)
|
if (szInterface->createObjectFunc(&CLSID_CFormatRar, &IID_InArchive, (void **)&szInterface->archive) != S_OK)
|
||||||
{
|
{
|
||||||
qDebug() << "Error creating rar archive :" + filePath;
|
qDebug() << "Error creating rar archive :" + filePath;
|
||||||
@ -207,7 +257,6 @@ CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent)
|
|||||||
//isRar = true;
|
//isRar = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -215,10 +264,13 @@ CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent)
|
|||||||
CompressedArchive::~CompressedArchive()
|
CompressedArchive::~CompressedArchive()
|
||||||
{
|
{
|
||||||
//always close the archive!
|
//always close the archive!
|
||||||
szInterface->archive->Close();
|
if (szInterface->archive)
|
||||||
|
{
|
||||||
|
szInterface->archive->Close();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
if(isRar) //TODO: fix this!!! Memory leak!!!! If AddRef is not used, a crash occurs in "delete szInterface"
|
if(isRar) //TODO: Memory leak!!!! If AddRef is not used, a crash occurs in "delete szInterface"
|
||||||
{
|
{
|
||||||
szInterface->archive->AddRef();
|
szInterface->archive->AddRef();
|
||||||
}
|
}
|
||||||
@ -425,6 +477,4 @@ STDMETHODIMP CompressedArchive::CreateEncoder(UInt32 index, const GUID *interfac
|
|||||||
return S_OK;//szInterface->createObjectFuncRar(&CLSID_CFormatRar,interfaceID,coder);
|
return S_OK;//szInterface->createObjectFuncRar(&CLSID_CFormatRar,interfaceID,coder);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -12,27 +12,46 @@ extern"C" {
|
|||||||
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
|
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
|
||||||
QObject(parent),valid(false),tools(true),numFiles(0),ar(NULL),stream(NULL)
|
QObject(parent),valid(false),tools(true),numFiles(0),ar(NULL),stream(NULL)
|
||||||
{
|
{
|
||||||
|
//open file
|
||||||
stream = ar_open_file(filePath.toStdString().c_str());
|
stream = ar_open_file(filePath.toStdString().c_str());
|
||||||
//try to open archive
|
if (!stream)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//open archive
|
||||||
ar = ar_open_rar_archive(stream);
|
ar = ar_open_rar_archive(stream);
|
||||||
if (!ar) ar = ar_open_zip_archive(stream, false);
|
//TODO: build unarr with 7z support and test this!
|
||||||
//if (!ar) ar = ar_open_7z_archive(stream);
|
//if (!ar) ar = ar_open_7z_archive(stream);
|
||||||
if (!ar) ar = ar_open_tar_archive(stream);
|
if (!ar) ar = ar_open_tar_archive(stream);
|
||||||
|
//zip detection is costly, so it comes last...
|
||||||
|
if (!ar) ar = ar_open_zip_archive(stream, false);
|
||||||
if (!ar)
|
if (!ar)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//initial parse
|
//initial parse
|
||||||
while (ar_parse_entry(ar))
|
while (ar_parse_entry(ar))
|
||||||
{
|
{
|
||||||
numFiles++;
|
//make sure we really got a file header
|
||||||
fileNames.append(ar_entry_get_name(ar));
|
if (ar_entry_get_size(ar) > 0)
|
||||||
offsets.append(ar_entry_get_offset(ar));
|
{
|
||||||
|
fileNames.append(ar_entry_get_name(ar));
|
||||||
|
offsets.append(ar_entry_get_offset(ar));
|
||||||
|
numFiles++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ar_at_eof(ar))
|
||||||
|
{
|
||||||
|
//fail if the initial parse didn't reach EOF
|
||||||
|
//this might be a bit too drastic
|
||||||
|
qDebug() << "Error while parsing archive";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (numFiles > 0)
|
if (numFiles > 0)
|
||||||
{
|
{
|
||||||
valid = true;
|
valid = true;
|
||||||
tools = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +73,7 @@ bool CompressedArchive::isValid()
|
|||||||
|
|
||||||
bool CompressedArchive::toolsLoaded()
|
bool CompressedArchive::toolsLoaded()
|
||||||
{
|
{
|
||||||
|
//for backwards compatibilty
|
||||||
return tools;
|
return tools;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,17 +92,17 @@ void CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDele
|
|||||||
int i=0;
|
int i=0;
|
||||||
while (i < indexes.count())
|
while (i < indexes.count())
|
||||||
{
|
{
|
||||||
if (i==0)
|
//use the offset list so we generated so we're not getting any non-page files
|
||||||
|
ar_parse_entry_at(ar, offsets.at(indexes.at(i))); //set ar_entry to start of indexes
|
||||||
|
buffer.resize(ar_entry_get_size(ar));
|
||||||
|
if (ar_entry_uncompress(ar, buffer.data(), buffer.size())) //did we extract it?
|
||||||
{
|
{
|
||||||
ar_parse_entry_at(ar, offsets.at(indexes.at(0))); //set ar_entry to start of indexes
|
delegate->fileExtracted(indexes.at(i), buffer); //return extracted file
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ar_parse_entry(ar);
|
delegate->crcError(indexes.at(i)); //we could not extract it...
|
||||||
}
|
}
|
||||||
buffer.resize(ar_entry_get_size(ar));
|
|
||||||
ar_entry_uncompress(ar, buffer.data(), buffer.size());
|
|
||||||
delegate->fileExtracted(indexes.at(i), buffer); //return extracted files :)
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,13 +113,15 @@ QByteArray CompressedArchive::getRawDataAtIndex(int index)
|
|||||||
if(index >= 0 && index < getNumFiles())
|
if(index >= 0 && index < getNumFiles())
|
||||||
{
|
{
|
||||||
ar_parse_entry_at(ar, offsets.at(index));
|
ar_parse_entry_at(ar, offsets.at(index));
|
||||||
while (ar_entry_get_size(ar)==0)
|
|
||||||
{
|
|
||||||
ar_parse_entry(ar);
|
|
||||||
}
|
|
||||||
buffer.resize(ar_entry_get_size(ar));
|
buffer.resize(ar_entry_get_size(ar));
|
||||||
ar_entry_uncompress(ar, buffer.data(), buffer.size());
|
if(ar_entry_uncompress(ar, buffer.data(), buffer.size()))
|
||||||
//return buffer;
|
{
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,31 @@ HEADERS += $$PWD/extract_delegate.h \
|
|||||||
|
|
||||||
SOURCES += $$PWD/compressed_archive.cpp \
|
SOURCES += $$PWD/compressed_archive.cpp \
|
||||||
|
|
||||||
#static build (no lib)
|
unix:!macx:exists (/usr/include/unarr.h) {
|
||||||
include(unarr.pro)
|
message(Using system provided unarr installation)
|
||||||
|
LIBS+=-lunarr
|
||||||
|
DEFINES+=use_unarr
|
||||||
|
}
|
||||||
|
else:macx:exists (../../dependencies/unarr/libunarr.dynlib) {
|
||||||
|
LIBS += -L../../dependencies/unarr/ -lunarr
|
||||||
|
DEFINES+=use_unarr
|
||||||
|
}
|
||||||
|
|
||||||
#for system libunarr.so
|
else:win32:exists (../../dependencies/unarr/unarr.dll) {
|
||||||
#LIBS+=-lunarr
|
LIBS += -L../../dependencies/unarr/ -lunarr
|
||||||
|
DEFINES+=use_unarr
|
||||||
|
}
|
||||||
|
|
||||||
|
else:exists ($$PWD/unarr-master) {
|
||||||
|
message(Found unarr source-code)
|
||||||
|
message(Unarr will be build as a part of YACReader)
|
||||||
|
|
||||||
|
#qmake based unarr build system
|
||||||
|
#this should only be used for testing or as a last resort
|
||||||
|
include(unarr.pro)
|
||||||
|
DEFINES+=use_unarr
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error(Missing dependency: unarr decrompression backend. Please install libunarr on your system\
|
||||||
|
or provide a copy of the unarr source code in compressed_archive/unarr/unarr-master)
|
||||||
|
}
|
@ -13,10 +13,6 @@ win32 {
|
|||||||
CONFIG -= embed_manifest_exe
|
CONFIG -= embed_manifest_exe
|
||||||
}
|
}
|
||||||
|
|
||||||
unix {
|
|
||||||
DEFINES += "LIBDIR=\\\"$$/usr/lib\\\""
|
|
||||||
}
|
|
||||||
|
|
||||||
!CONFIG(unarr){
|
!CONFIG(unarr){
|
||||||
include(../../compressed_archive/wrapper.pri)
|
include(../../compressed_archive/wrapper.pri)
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,7 +25,7 @@ int main(int argc, char *argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoreApplication app(argc, argv);
|
//QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
QString s(argv[1]);
|
QString s(argv[1]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user