mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
fixed filtering folders in compressed comic files
This commit is contained in:
parent
9c8eb75509
commit
537f8fbd76
@ -200,6 +200,7 @@ CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent)
|
|||||||
{
|
{
|
||||||
valid = formatFound = true;
|
valid = formatFound = true;
|
||||||
qDebug() << "Opened archive file : " + filePath << endl;
|
qDebug() << "Opened archive file : " + filePath << endl;
|
||||||
|
setupFilesNames();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,6 +255,7 @@ CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent)
|
|||||||
if (szInterface->archive->Open(file, 0, openCallback) == S_OK)
|
if (szInterface->archive->Open(file, 0, openCallback) == S_OK)
|
||||||
{
|
{
|
||||||
valid = formatFound = true;
|
valid = formatFound = true;
|
||||||
|
setupFilesNames();
|
||||||
//isRar = true;
|
//isRar = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,51 +263,52 @@ CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
CompressedArchive::~CompressedArchive()
|
CompressedArchive::~CompressedArchive()
|
||||||
{
|
{
|
||||||
//always close the archive!
|
//always close the archive!
|
||||||
if (szInterface->archive)
|
if (szInterface->archive)
|
||||||
{
|
{
|
||||||
szInterface->archive->Close();
|
szInterface->archive->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
if(isRar) //TODO: 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();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
delete szInterface;
|
delete szInterface;
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
delete rarLib;
|
delete rarLib;
|
||||||
#endif
|
#endif
|
||||||
delete sevenzLib;
|
delete sevenzLib;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompressedArchive::loadFunctions()
|
bool CompressedArchive::loadFunctions()
|
||||||
{
|
{
|
||||||
//LOAD library
|
//LOAD library
|
||||||
//TODO check if this works in OSX (7z.so instead of 7z.dylib)
|
//TODO check if this works in OSX (7z.so instead of 7z.dylib)
|
||||||
// fix1: try to load "7z.so"
|
// fix1: try to load "7z.so"
|
||||||
// fix2: rename 7z.so to 7z.dylib
|
// fix2: rename 7z.so to 7z.dylib
|
||||||
if(sevenzLib == 0)
|
if(sevenzLib == 0)
|
||||||
{
|
{
|
||||||
#if defined Q_OS_UNIX
|
#if defined Q_OS_UNIX
|
||||||
#if defined Q_OS_MAC
|
#if defined Q_OS_MAC
|
||||||
rarLib = new QLibrary(QCoreApplication::applicationDirPath()+"/utils/Codecs/Rar29");
|
rarLib = new QLibrary(QCoreApplication::applicationDirPath()+"/utils/Codecs/Rar29");
|
||||||
#else
|
#else
|
||||||
//check if a yacreader specific version of p7zip exists on the system
|
//check if a yacreader specific version of p7zip exists on the system
|
||||||
QFileInfo rarCodec(QString(LIBDIR)+"/yacreader/Codecs/Rar29.so");
|
QFileInfo rarCodec(QString(LIBDIR)+"/yacreader/Codecs/Rar29.so");
|
||||||
if (rarCodec.exists())
|
if (rarCodec.exists())
|
||||||
{
|
{
|
||||||
rarLib = new QLibrary(rarCodec.absoluteFilePath());
|
rarLib = new QLibrary(rarCodec.absoluteFilePath());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rarLib = new QLibrary(QString(LIBDIR)+"/p7zip/Codecs/Rar29.so");
|
rarLib = new QLibrary(QString(LIBDIR)+"/p7zip/Codecs/Rar29.so");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(!rarLib->load())
|
if(!rarLib->load())
|
||||||
{
|
{
|
||||||
qDebug() << "Error Loading Rar29.so : " + rarLib->errorString() << endl;
|
qDebug() << "Error Loading Rar29.so : " + rarLib->errorString() << endl;
|
||||||
@ -314,43 +317,43 @@ bool CompressedArchive::loadFunctions()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
||||||
QFileInfo sevenzlibrary(QString(LIBDIR)+"/yacreader/7z.so");
|
QFileInfo sevenzlibrary(QString(LIBDIR)+"/yacreader/7z.so");
|
||||||
if (sevenzlibrary.exists())
|
if (sevenzlibrary.exists())
|
||||||
{
|
{
|
||||||
sevenzLib = new QLibrary(sevenzlibrary.absoluteFilePath());
|
sevenzLib = new QLibrary(sevenzlibrary.absoluteFilePath());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sevenzLib = new QLibrary(QString(LIBDIR)+"/p7zip/7z.so");
|
sevenzLib = new QLibrary(QString(LIBDIR)+"/p7zip/7z.so");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
sevenzLib = new QLibrary(QCoreApplication::applicationDirPath()+"/utils/7z");
|
sevenzLib = new QLibrary(QCoreApplication::applicationDirPath()+"/utils/7z");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if(!sevenzLib->load())
|
if(!sevenzLib->load())
|
||||||
{
|
{
|
||||||
qDebug() << "Error Loading 7z.dll : " + sevenzLib->errorString() << endl;
|
qDebug() << "Error Loading 7z.dll : " + sevenzLib->errorString() << endl;
|
||||||
QCoreApplication::exit(700); //TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound
|
QCoreApplication::exit(700); //TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << "Loading functions" << endl;
|
qDebug() << "Loading functions" << endl;
|
||||||
|
|
||||||
if((szInterface->createObjectFunc = (CreateObjectFunc)sevenzLib->resolve("CreateObject")) == 0)
|
if((szInterface->createObjectFunc = (CreateObjectFunc)sevenzLib->resolve("CreateObject")) == 0)
|
||||||
qDebug() << "fail loading function : CreateObject" << endl;
|
qDebug() << "fail loading function : CreateObject" << endl;
|
||||||
if((szInterface->getMethodPropertyFunc = (GetMethodPropertyFunc)sevenzLib->resolve("GetMethodProperty")) == 0)
|
if((szInterface->getMethodPropertyFunc = (GetMethodPropertyFunc)sevenzLib->resolve("GetMethodProperty")) == 0)
|
||||||
qDebug() << "fail loading function : GetMethodProperty" << endl;
|
qDebug() << "fail loading function : GetMethodProperty" << endl;
|
||||||
if((szInterface->getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)sevenzLib->resolve("GetNumberOfMethods")) == 0)
|
if((szInterface->getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)sevenzLib->resolve("GetNumberOfMethods")) == 0)
|
||||||
qDebug() << "fail loading function : GetNumberOfMethods" << endl;
|
qDebug() << "fail loading function : GetNumberOfMethods" << endl;
|
||||||
if((szInterface->getNumberOfFormatsFunc = (GetNumberOfFormatsFunc)sevenzLib->resolve("GetNumberOfFormats")) == 0)
|
if((szInterface->getNumberOfFormatsFunc = (GetNumberOfFormatsFunc)sevenzLib->resolve("GetNumberOfFormats")) == 0)
|
||||||
qDebug() << "fail loading function : GetNumberOfFormats" << endl;
|
qDebug() << "fail loading function : GetNumberOfFormats" << endl;
|
||||||
if((szInterface->getHandlerPropertyFunc = (GetHandlerPropertyFunc)sevenzLib->resolve("GetHandlerProperty")) == 0)
|
if((szInterface->getHandlerPropertyFunc = (GetHandlerPropertyFunc)sevenzLib->resolve("GetHandlerProperty")) == 0)
|
||||||
qDebug() << "fail loading function : GetHandlerProperty" << endl;
|
qDebug() << "fail loading function : GetHandlerProperty" << endl;
|
||||||
if((szInterface->getHandlerPropertyFunc2 = (GetHandlerPropertyFunc2)sevenzLib->resolve("GetHandlerProperty2")) == 0)
|
if((szInterface->getHandlerPropertyFunc2 = (GetHandlerPropertyFunc2)sevenzLib->resolve("GetHandlerProperty2")) == 0)
|
||||||
qDebug() << "fail loading function : GetHandlerProperty2" << endl;
|
qDebug() << "fail loading function : GetHandlerProperty2" << endl;
|
||||||
if((szInterface->setLargePageModeFunc = (SetLargePageModeFunc)sevenzLib->resolve("SetLargePageMode")) == 0)
|
if((szInterface->setLargePageModeFunc = (SetLargePageModeFunc)sevenzLib->resolve("SetLargePageMode")) == 0)
|
||||||
qDebug() << "fail loading function : SetLargePageMode" << endl;
|
qDebug() << "fail loading function : SetLargePageMode" << endl;
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
if((szInterface->createObjectFuncRar = (CreateObjectFunc)rarLib->resolve("CreateObject")) == 0)
|
if((szInterface->createObjectFuncRar = (CreateObjectFunc)rarLib->resolve("CreateObject")) == 0)
|
||||||
@ -360,95 +363,127 @@ bool CompressedArchive::loadFunctions()
|
|||||||
if((szInterface->getNumberOfMethodsFuncRar = (GetNumberOfMethodsFunc)rarLib->resolve("GetNumberOfMethods")) == 0)
|
if((szInterface->getNumberOfMethodsFuncRar = (GetNumberOfMethodsFunc)rarLib->resolve("GetNumberOfMethods")) == 0)
|
||||||
qDebug() << "fail loading function (rar) : GetNumberOfMethods" << endl;
|
qDebug() << "fail loading function (rar) : GetNumberOfMethods" << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompressedArchive::setupFilesNames()
|
||||||
|
{
|
||||||
|
quint32 numItems = getNumEntries();
|
||||||
|
quint32 p = 0;
|
||||||
|
for (quint32 i = 0; i < numItems; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Get name of file
|
||||||
|
NWindows::NCOM::CPropVariant prop;
|
||||||
|
szInterface->archive->GetProperty(i, kpidIsDir, &prop);
|
||||||
|
bool isDir;
|
||||||
|
if (prop.vt == VT_BOOL)
|
||||||
|
isDir = VARIANT_BOOLToBool(prop.boolVal);
|
||||||
|
else if (prop.vt == VT_EMPTY)
|
||||||
|
isDir = false;
|
||||||
|
|
||||||
|
if(!isDir)
|
||||||
|
{
|
||||||
|
szInterface->archive->GetProperty(i, kpidPath, &prop);
|
||||||
|
UString s = ConvertPropVariantToString(prop);
|
||||||
|
const wchar_t * chars = s.operator const wchar_t *();
|
||||||
|
files.append(QString::fromWCharArray(chars));
|
||||||
|
offsets.append(i);
|
||||||
|
indexesToPages.insert(i,p);
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<quint32> CompressedArchive::translateIndexes(const QVector<quint32> & indexes)
|
||||||
|
{
|
||||||
|
QVector<quint32> translatedIndexes;
|
||||||
|
|
||||||
|
foreach(quint32 i, indexes)
|
||||||
|
{
|
||||||
|
if(i < offsets.length())
|
||||||
|
translatedIndexes.append(offsets.at(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return translatedIndexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> CompressedArchive::getFileNames()
|
QList<QString> CompressedArchive::getFileNames()
|
||||||
{
|
{
|
||||||
QList<QString> files;
|
return files;
|
||||||
quint32 numItems = getNumFiles();
|
|
||||||
for (quint32 i = 0; i < numItems; i++)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
// Get name of file
|
|
||||||
NWindows::NCOM::CPropVariant prop;
|
|
||||||
/*szInterface->archive->GetProperty(i, kpidIsDir, &prop);
|
|
||||||
bool isDir;
|
|
||||||
if (prop.vt == VT_BOOL)
|
|
||||||
isDir = VARIANT_BOOLToBool(prop.boolVal);
|
|
||||||
else if (prop.vt == VT_EMPTY)
|
|
||||||
isDir = false;
|
|
||||||
|
|
||||||
if(!isDir)
|
|
||||||
{*/
|
|
||||||
szInterface->archive->GetProperty(i, kpidPath, &prop);
|
|
||||||
UString s = ConvertPropVariantToString(prop);
|
|
||||||
const wchar_t * chars = s.operator const wchar_t *();
|
|
||||||
files.append(QString::fromWCharArray(chars));
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return files;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompressedArchive::isValid()
|
bool CompressedArchive::isValid()
|
||||||
{
|
{
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompressedArchive::toolsLoaded()
|
bool CompressedArchive::toolsLoaded()
|
||||||
{
|
{
|
||||||
return tools;
|
return tools;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CompressedArchive::getNumFiles()
|
int CompressedArchive::getNumFiles()
|
||||||
{
|
{
|
||||||
quint32 numItems = 0;
|
return files.length();
|
||||||
szInterface->archive->GetNumberOfItems(&numItems);
|
}
|
||||||
return numItems;
|
|
||||||
|
int CompressedArchive::getNumEntries()
|
||||||
|
{
|
||||||
|
quint32 numItems = 0;
|
||||||
|
szInterface->archive->GetNumberOfItems(&numItems);
|
||||||
|
return numItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QByteArray> CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
|
QList<QByteArray> CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
|
||||||
{
|
{
|
||||||
CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback(true,delegate);
|
CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback(indexesToPages, true, delegate);
|
||||||
CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
|
CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
|
||||||
extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path
|
extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path
|
||||||
extractCallbackSpec->PasswordIsDefined = false;
|
extractCallbackSpec->PasswordIsDefined = false;
|
||||||
|
|
||||||
HRESULT result;
|
QVector<quint32> currentIndexes = translateIndexes(indexes);
|
||||||
if(indexes.isEmpty())
|
|
||||||
result = szInterface->archive->Extract(NULL, -1, false, extractCallback);
|
HRESULT result;
|
||||||
else
|
if(indexes.isEmpty())
|
||||||
result = szInterface->archive->Extract(indexes.data(), indexes.count(), false, extractCallback);
|
result = szInterface->archive->Extract(NULL, -1, false, extractCallback);
|
||||||
if (result != S_OK)
|
else
|
||||||
{
|
result = szInterface->archive->Extract(currentIndexes.data(), currentIndexes.count(), false, extractCallback);
|
||||||
qDebug() << "Extract Error" << endl;
|
if (result != S_OK)
|
||||||
}
|
{
|
||||||
|
qDebug() << "Extract Error" << endl;
|
||||||
return extractCallbackSpec->allFiles;
|
}
|
||||||
|
|
||||||
|
return extractCallbackSpec->allFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray CompressedArchive::getRawDataAtIndex(int index)
|
QByteArray CompressedArchive::getRawDataAtIndex(int index)
|
||||||
{
|
{
|
||||||
if(index>=0 && index < getNumFiles())
|
if(index>=0 && index < getNumFiles())
|
||||||
{
|
{
|
||||||
CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;
|
CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback(indexesToPages);
|
||||||
CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
|
CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
|
||||||
extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path
|
extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path
|
||||||
extractCallbackSpec->PasswordIsDefined = false;
|
extractCallbackSpec->PasswordIsDefined = false;
|
||||||
|
|
||||||
UInt32 indices[1];
|
UInt32 indices[1];
|
||||||
indices[0] = index;
|
|
||||||
HRESULT result = szInterface->archive->Extract(indices, 1, false, extractCallback);
|
if(index < offsets.length())
|
||||||
if (result != S_OK)
|
indices[0] = offsets.at(index);
|
||||||
{
|
else
|
||||||
qDebug() << "Extract Error" << endl;
|
indices[0] = index;
|
||||||
}
|
|
||||||
|
HRESULT result = szInterface->archive->Extract(indices, 1, false, extractCallback);
|
||||||
return QByteArray((char *)extractCallbackSpec->data,extractCallbackSpec->newFileSize);
|
if (result != S_OK)
|
||||||
}
|
{
|
||||||
|
qDebug() << "Extract Error" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QByteArray((char *)extractCallbackSpec->data,extractCallbackSpec->newFileSize);
|
||||||
|
}
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ typedef quint32 (_MY_WINAPI *SetLargePageModeFunc)();
|
|||||||
class QLibrary;
|
class QLibrary;
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
struct SevenZipInterface;
|
struct SevenZipInterface;
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
int getNumFiles();
|
int getNumFiles();
|
||||||
|
int getNumEntries();
|
||||||
QList<QByteArray> getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate = 0);
|
QList<QByteArray> getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate = 0);
|
||||||
QByteArray getRawDataAtIndex(int index);
|
QByteArray getRawDataAtIndex(int index);
|
||||||
QList<QString> getFileNames();
|
QList<QString> getFileNames();
|
||||||
@ -74,6 +76,12 @@ private:
|
|||||||
bool loadFunctions();
|
bool loadFunctions();
|
||||||
bool tools;
|
bool tools;
|
||||||
bool valid;
|
bool valid;
|
||||||
|
QList<QString> files;
|
||||||
|
QList<qint32> offsets;
|
||||||
|
QMap<qint32, qint32> indexesToPages;
|
||||||
|
|
||||||
|
void setupFilesNames();
|
||||||
|
QVector<quint32> translateIndexes(const QVector<quint32> &indexes);
|
||||||
|
|
||||||
friend class MyCodecs;
|
friend class MyCodecs;
|
||||||
};
|
};
|
||||||
|
@ -90,8 +90,9 @@ public:
|
|||||||
UString Password;
|
UString Password;
|
||||||
Byte * data;
|
Byte * data;
|
||||||
UInt64 newFileSize;
|
UInt64 newFileSize;
|
||||||
|
QMap<qint32, qint32> indexesToPages;
|
||||||
|
|
||||||
CArchiveExtractCallback(bool c = false,ExtractDelegate * d = 0) : PasswordIsDefined(false),all(c),delegate(d) {}
|
CArchiveExtractCallback(const QMap<qint32, qint32> & indexesToPages ,bool c = false,ExtractDelegate * d = 0) : PasswordIsDefined(false),all(c),delegate(d),indexesToPages(indexesToPages) {}
|
||||||
~CArchiveExtractCallback() {MidFree(data);}
|
~CArchiveExtractCallback() {MidFree(data);}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -117,7 +118,11 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
|
|||||||
{
|
{
|
||||||
*outStream = 0;
|
*outStream = 0;
|
||||||
_outFileStream.Release();
|
_outFileStream.Release();
|
||||||
_index = index;
|
|
||||||
|
if(indexesToPages.isEmpty())
|
||||||
|
_index = index;
|
||||||
|
else
|
||||||
|
_index = indexesToPages.value(index);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Get Name
|
// Get Name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user