mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Fixed rar support in Unix systems (Rar29.so)
This commit is contained in:
parent
626e2a654e
commit
53906a450c
@ -54,6 +54,8 @@ extern "C"
|
||||
#include "libp7zip/CPP/7zip/Common/StreamObjects.h"
|
||||
#include "libp7zip/CPP/7zip/Common/StreamUtils.h"
|
||||
|
||||
#include "libp7zip/CPP/7zip/ICoder.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "libp7zip/C/Alloc.h"
|
||||
|
@ -34,10 +34,20 @@ DEFINE_GUID(CLSID_CFormatSplit, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00,
|
||||
DEFINE_GUID(CLSID_CFormatWim, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xe6, 0x00, 0x00);
|
||||
DEFINE_GUID(CLSID_CFormatZ, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x05, 0x00, 0x00);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
GUID _supportedFileFormats[] = {CLSID_CFormatRar,CLSID_CFormatZip,CLSID_CFormatTar,CLSID_CFormat7z,CLSID_CFormatArj};
|
||||
#else
|
||||
GUID _supportedFileFormats[] = {CLSID_CFormatZip,CLSID_CFormatTar,CLSID_CFormat7z,CLSID_CFormatArj};
|
||||
#endif
|
||||
std::vector<GUID> supportedFileFormats (_supportedFileFormats, _supportedFileFormats + sizeof(_supportedFileFormats) / sizeof(_supportedFileFormats[0]) );
|
||||
|
||||
DEFINE_GUID(IID_InArchive, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00);
|
||||
DEFINE_GUID(IID_InArchive, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00);
|
||||
DEFINE_GUID(IID_ISetCompressCodecsInfo, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x61, 0x00, 0x00);
|
||||
|
||||
DEFINE_GUID(IID_IOutStream, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00);
|
||||
DEFINE_GUID(IID_IInStream, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00);
|
||||
DEFINE_GUID(IID_IStreamGetSize, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00);
|
||||
DEFINE_GUID(IID_ISequentialInStream, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00);
|
||||
|
||||
struct SevenZipInterface {
|
||||
CreateObjectFunc createObjectFunc;
|
||||
@ -48,6 +58,12 @@ struct SevenZipInterface {
|
||||
GetHandlerPropertyFunc2 getHandlerPropertyFunc2;
|
||||
SetLargePageModeFunc setLargePageModeFunc;
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
CreateObjectFunc createObjectFuncRar;
|
||||
GetMethodPropertyFunc getMethodPropertyFuncRar;
|
||||
GetNumberOfMethodsFunc getNumberOfMethodsFuncRar;
|
||||
#endif
|
||||
|
||||
CMyComPtr<IInArchive> archive;
|
||||
|
||||
//---
|
||||
@ -99,15 +115,57 @@ CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent)
|
||||
}
|
||||
}
|
||||
if(!formatFound)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
qDebug() << "Can not open archive" << endl;
|
||||
#else
|
||||
if (szInterface->createObjectFunc(&CLSID_CFormatRar, &IID_InArchive, (void **)&szInterface->archive) != S_OK)
|
||||
{
|
||||
qDebug() << "Error creating rar archive :" + filePath;
|
||||
return;
|
||||
}
|
||||
|
||||
CMyComPtr<ISetCompressCodecsInfo> codecsInfo;
|
||||
if (szInterface->archive->QueryInterface(IID_ISetCompressCodecsInfo,(void **)&codecsInfo) != S_OK)
|
||||
{
|
||||
qDebug() << "Error getting rar codec :" + filePath;
|
||||
return;
|
||||
}
|
||||
|
||||
if (codecsInfo->SetCompressCodecsInfo(this) != S_OK)
|
||||
{
|
||||
qDebug() << "Error setting rar codec";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fileSpec->Open((LPCTSTR)filePath.toStdWString().data()))
|
||||
{
|
||||
qDebug() << "Error opening rar file :" + filePath;
|
||||
return;
|
||||
}
|
||||
//qDebug() << "Can not open archive file : " + filePath << endl;
|
||||
|
||||
if (szInterface->archive->Open(file, 0, openCallback) == S_OK)
|
||||
{
|
||||
valid = formatFound = true;
|
||||
}
|
||||
else
|
||||
qDebug() << "Error opening rar archive";
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CompressedArchive::~CompressedArchive()
|
||||
{
|
||||
//szInterface->fileSpec->Release();
|
||||
delete szInterface;
|
||||
delete sevenzLib;
|
||||
delete szInterface;
|
||||
#ifdef Q_OS_UNIX
|
||||
delete rarLib;
|
||||
#endif
|
||||
delete sevenzLib;
|
||||
}
|
||||
|
||||
bool CompressedArchive::loadFunctions()
|
||||
@ -117,11 +175,22 @@ bool CompressedArchive::loadFunctions()
|
||||
// fix1: try to load "7z.so"
|
||||
// fix2: rename 7z.so to 7z.dylib
|
||||
if(sevenzLib == 0)
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
rarLib = new QLibrary(QApplication::applicationDirPath()+"/utils/Codecs/Rar29");
|
||||
if(!rarLib->load())
|
||||
{
|
||||
qDebug() << "Error Loading Rar29.so : " + rarLib->errorString() << endl;
|
||||
QApplication::exit(YACReader::SevenZNotFound);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
sevenzLib = new QLibrary(QApplication::applicationDirPath()+"/utils/7z");
|
||||
}
|
||||
if(!sevenzLib->load())
|
||||
{
|
||||
qDebug() << "Loading 7z.dll : " + sevenzLib->errorString() << endl;
|
||||
QApplication::exit(YACReader::SevenZNotFound); //TODO app still crashing
|
||||
qDebug() << "Error Loading 7z.dll : " + sevenzLib->errorString() << endl;
|
||||
QApplication::exit(YACReader::SevenZNotFound);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@ -142,6 +211,15 @@ bool CompressedArchive::loadFunctions()
|
||||
qDebug() << "fail loading function : GetHandlerProperty2" << endl;
|
||||
if((szInterface->setLargePageModeFunc = (SetLargePageModeFunc)sevenzLib->resolve("SetLargePageMode")) == 0)
|
||||
qDebug() << "fail loading function : SetLargePageMode" << endl;
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
if((szInterface->createObjectFuncRar = (CreateObjectFunc)rarLib->resolve("CreateObject")) == 0)
|
||||
qDebug() << "fail loading function (rar) : CreateObject" << endl;
|
||||
if((szInterface->getMethodPropertyFuncRar = (GetMethodPropertyFunc)rarLib->resolve("GetMethodProperty")) == 0)
|
||||
qDebug() << "fail loading function (rar) : GetMethodProperty" << endl;
|
||||
if((szInterface->getNumberOfMethodsFuncRar = (GetNumberOfMethodsFunc)rarLib->resolve("GetNumberOfMethods")) == 0)
|
||||
qDebug() << "fail loading function (rar) : GetNumberOfMethods" << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -191,6 +269,7 @@ int CompressedArchive::getNumFiles()
|
||||
szInterface->archive->GetNumberOfItems(&numItems);
|
||||
return numItems;
|
||||
}
|
||||
|
||||
QList<QByteArray> CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
|
||||
{
|
||||
CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback(true,delegate);
|
||||
@ -230,5 +309,34 @@ QByteArray CompressedArchive::getRawDataAtIndex(int index)
|
||||
|
||||
return QByteArray((char *)extractCallbackSpec->data,extractCallbackSpec->newFileSize);
|
||||
}
|
||||
return QByteArray();
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
|
||||
STDMETHODIMP CompressedArchive::GetNumberOfMethods(UInt32 *numMethods)
|
||||
{
|
||||
return szInterface->getNumberOfMethodsFuncRar(numMethods);
|
||||
}
|
||||
|
||||
STDMETHODIMP CompressedArchive::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
return szInterface->getMethodPropertyFuncRar(index,propID,value);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
STDMETHODIMP CompressedArchive::CreateDecoder(UInt32 index, const GUID *interfaceID, void **coder)
|
||||
{
|
||||
NCOM::CPropVariant propVariant;
|
||||
szInterface->getMethodPropertyFuncRar(index,NMethodPropID::kDecoder,&propVariant);
|
||||
return szInterface->createObjectFuncRar((const GUID *)propVariant.bstrVal,interfaceID,coder);
|
||||
}
|
||||
|
||||
STDMETHODIMP CompressedArchive::CreateEncoder(UInt32 index, const GUID *interfaceID, void **coder)
|
||||
{
|
||||
return szInterface->createObjectFuncRar(&CLSID_CFormatRar,interfaceID,coder);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -3,6 +3,11 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
#include "libp7zip/CPP/7zip/ICoder.h"
|
||||
#include "libp7zip/CPP/Common/MyCom.h"
|
||||
#endif
|
||||
|
||||
class ExtractDelegate;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@ -26,13 +31,28 @@ class QLibrary;
|
||||
|
||||
struct SevenZipInterface;
|
||||
|
||||
class CompressedArchive : public QObject
|
||||
class MyCodecs;
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
class CompressedArchive : public QObject, public ICompressCodecsInfo, public CMyUnknownImp
|
||||
#else
|
||||
class CompressedArchive : public QObject
|
||||
#endif
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CompressedArchive(const QString & filePath, QObject *parent = 0);
|
||||
~CompressedArchive();
|
||||
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods);
|
||||
STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
|
||||
STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder);
|
||||
STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder);
|
||||
#endif
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
@ -45,10 +65,14 @@ public slots:
|
||||
private:
|
||||
SevenZipInterface * szInterface;
|
||||
QLibrary * sevenzLib;
|
||||
#ifdef Q_OS_UNIX
|
||||
QLibrary * rarLib;
|
||||
#endif
|
||||
bool loadFunctions();
|
||||
bool tools;
|
||||
bool valid;
|
||||
|
||||
friend class MyCodecs;
|
||||
};
|
||||
|
||||
#endif // COMPRESSED_ARCHIVE_H
|
||||
|
@ -102,8 +102,9 @@ HEADERS += $$PWD/compressed_archive.h \
|
||||
$$PWD/libp7zip/CPP/7zip/Common/StreamUtils.h \
|
||||
$$PWD/libp7zip/C/Alloc.h \
|
||||
$$PWD/libp7zip/CPP/7zip/Common/StreamObjects.h \
|
||||
$$PWD/libp7zip/CPP/Common/MyWindows.h
|
||||
$$PWD/libp7zip/CPP/Common/MyWindows.h \
|
||||
$$PWD/libp7zip/CPP/7zip/ICoder.h \
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user