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,6 +263,7 @@ CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
CompressedArchive::~CompressedArchive()
|
CompressedArchive::~CompressedArchive()
|
||||||
{
|
{
|
||||||
//always close the archive!
|
//always close the archive!
|
||||||
@ -365,16 +368,16 @@ bool CompressedArchive::loadFunctions()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> CompressedArchive::getFileNames()
|
void CompressedArchive::setupFilesNames()
|
||||||
{
|
{
|
||||||
QList<QString> files;
|
quint32 numItems = getNumEntries();
|
||||||
quint32 numItems = getNumFiles();
|
quint32 p = 0;
|
||||||
for (quint32 i = 0; i < numItems; i++)
|
for (quint32 i = 0; i < numItems; i++)
|
||||||
{
|
{
|
||||||
{
|
|
||||||
// Get name of file
|
// Get name of file
|
||||||
NWindows::NCOM::CPropVariant prop;
|
NWindows::NCOM::CPropVariant prop;
|
||||||
/*szInterface->archive->GetProperty(i, kpidIsDir, &prop);
|
szInterface->archive->GetProperty(i, kpidIsDir, &prop);
|
||||||
bool isDir;
|
bool isDir;
|
||||||
if (prop.vt == VT_BOOL)
|
if (prop.vt == VT_BOOL)
|
||||||
isDir = VARIANT_BOOLToBool(prop.boolVal);
|
isDir = VARIANT_BOOLToBool(prop.boolVal);
|
||||||
@ -382,14 +385,34 @@ QList<QString> CompressedArchive::getFileNames()
|
|||||||
isDir = false;
|
isDir = false;
|
||||||
|
|
||||||
if(!isDir)
|
if(!isDir)
|
||||||
{*/
|
{
|
||||||
szInterface->archive->GetProperty(i, kpidPath, &prop);
|
szInterface->archive->GetProperty(i, kpidPath, &prop);
|
||||||
UString s = ConvertPropVariantToString(prop);
|
UString s = ConvertPropVariantToString(prop);
|
||||||
const wchar_t * chars = s.operator const wchar_t *();
|
const wchar_t * chars = s.operator const wchar_t *();
|
||||||
files.append(QString::fromWCharArray(chars));
|
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()
|
||||||
|
{
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,6 +427,11 @@ bool CompressedArchive::toolsLoaded()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CompressedArchive::getNumFiles()
|
int CompressedArchive::getNumFiles()
|
||||||
|
{
|
||||||
|
return files.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CompressedArchive::getNumEntries()
|
||||||
{
|
{
|
||||||
quint32 numItems = 0;
|
quint32 numItems = 0;
|
||||||
szInterface->archive->GetNumberOfItems(&numItems);
|
szInterface->archive->GetNumberOfItems(&numItems);
|
||||||
@ -412,16 +440,18 @@ int CompressedArchive::getNumFiles()
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
QVector<quint32> currentIndexes = translateIndexes(indexes);
|
||||||
|
|
||||||
HRESULT result;
|
HRESULT result;
|
||||||
if(indexes.isEmpty())
|
if(indexes.isEmpty())
|
||||||
result = szInterface->archive->Extract(NULL, -1, false, extractCallback);
|
result = szInterface->archive->Extract(NULL, -1, false, extractCallback);
|
||||||
else
|
else
|
||||||
result = szInterface->archive->Extract(indexes.data(), indexes.count(), false, extractCallback);
|
result = szInterface->archive->Extract(currentIndexes.data(), currentIndexes.count(), false, extractCallback);
|
||||||
if (result != S_OK)
|
if (result != S_OK)
|
||||||
{
|
{
|
||||||
qDebug() << "Extract Error" << endl;
|
qDebug() << "Extract Error" << endl;
|
||||||
@ -434,13 +464,18 @@ 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];
|
||||||
|
|
||||||
|
if(index < offsets.length())
|
||||||
|
indices[0] = offsets.at(index);
|
||||||
|
else
|
||||||
indices[0] = index;
|
indices[0] = index;
|
||||||
|
|
||||||
HRESULT result = szInterface->archive->Extract(indices, 1, false, extractCallback);
|
HRESULT result = szInterface->archive->Extract(indices, 1, false, extractCallback);
|
||||||
if (result != S_OK)
|
if (result != S_OK)
|
||||||
{
|
{
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
if(indexesToPages.isEmpty())
|
||||||
_index = index;
|
_index = index;
|
||||||
|
else
|
||||||
|
_index = indexesToPages.value(index);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Get Name
|
// Get Name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user