Format code using clang-format

This commit is contained in:
Luis Ángel San Martín
2019-05-30 19:46:37 +02:00
parent e0eb94e3ae
commit e3ec56aa43
356 changed files with 19824 additions and 21874 deletions

View File

@ -3,8 +3,7 @@
//WIN includes
#ifdef Q_OS_WIN
extern "C"
{
extern "C" {
#include "lib7zip/C/Alloc.h"
#include "lib7zip/C/7zTypes.h"
}
@ -12,7 +11,6 @@ extern "C"
#include "lib7zip/CPP/Common/Common.h"
#include "lib7zip/CPP/Common/MyWindows.h"
#include "lib7zip/CPP/Common/StringConvert.h"
#include "lib7zip/CPP/Common/MyInitGuid.h"
#include "lib7zip/CPP/Common/MyCom.h"
@ -33,15 +31,13 @@ extern "C"
#else
//POSIX includes
extern "C"
{
extern "C" {
#include "libp7zip/C/Alloc.h"
#include "libp7zip/C/7zTypes.h"
}
#include "libp7zip/CPP/Windows/Defs.h"
#include "libp7zip/CPP/Common/Common.h"
#include "libp7zip/CPP/Common/MyCom.h"
@ -73,7 +69,6 @@ extern "C"
#include "libp7zip/CPP/7zip/ICoder.h"
#endif
#endif // _7Z_INCLUDES_H

View File

@ -17,28 +17,28 @@
#include "7z_includes.h"
#ifdef Q_OS_WIN
#define _MY_WINAPI WINAPI
#define _MY_WINAPI WINAPI
#else
#define _MY_WINAPI
#define _MY_WINAPI
#endif
typedef quint32 (_MY_WINAPI * CreateObjectFunc)(const GUID *clsID,const GUID *interfaceID,void **outObject);
typedef quint32 (_MY_WINAPI *GetMethodPropertyFunc)(quint32 index, PROPID propID, PROPVARIANT *value);
typedef quint32 (_MY_WINAPI *GetNumberOfMethodsFunc)(quint32 *numMethods);
typedef quint32 (_MY_WINAPI *GetNumberOfFormatsFunc)(quint32 *numFormats);
typedef quint32 (_MY_WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);
typedef quint32 (_MY_WINAPI *GetHandlerPropertyFunc2)(quint32 index, PROPID propID, PROPVARIANT *value);
typedef quint32 (_MY_WINAPI *SetLargePageModeFunc)();
typedef quint32(_MY_WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);
typedef quint32(_MY_WINAPI *GetMethodPropertyFunc)(quint32 index, PROPID propID, PROPVARIANT *value);
typedef quint32(_MY_WINAPI *GetNumberOfMethodsFunc)(quint32 *numMethods);
typedef quint32(_MY_WINAPI *GetNumberOfFormatsFunc)(quint32 *numFormats);
typedef quint32(_MY_WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);
typedef quint32(_MY_WINAPI *GetHandlerPropertyFunc2)(quint32 index, PROPID propID, PROPVARIANT *value);
typedef quint32(_MY_WINAPI *SetLargePageModeFunc)();
//DEFINE_GUID(CLSID_CFormat7z,0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);
//DEFINE_GUID(IArchiveKK,0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00);
//DEFINE_GUID(IArchiveKK,0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormat7z, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatRar, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x03, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatRar5, 0X23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xCC, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatZip, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x01, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatTar, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xee, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatArj, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x04, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormat7z, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatRar, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x03, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatRar5, 0X23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0xCC, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatZip, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x01, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatTar, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xee, 0x00, 0x00);
DEFINE_GUID(CLSID_CFormatArj, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x04, 0x00, 0x00);
//unused Formats
/*DEFINE_GUID(CLSID_CFormatBZip2, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x02, 0x00, 0x00);
@ -58,14 +58,14 @@ DEFINE_GUID(CLSID_CFormatWim, 0x23170f69, 0x40c1, 0x278a, 0x10, 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,CLSID_CFormatRar5};
GUID _supportedFileFormats[] = { CLSID_CFormatRar, CLSID_CFormatZip, CLSID_CFormatTar, CLSID_CFormat7z, CLSID_CFormatArj, CLSID_CFormatRar5 };
#else
GUID _supportedFileFormats[] = {CLSID_CFormatZip,CLSID_CFormatTar,CLSID_CFormat7z,CLSID_CFormatArj};
GUID _supportedFileFormats[] = { CLSID_CFormatZip, CLSID_CFormatTar, CLSID_CFormat7z, CLSID_CFormatArj };
#endif
std::vector<GUID> supportedFileFormats (_supportedFileFormats, _supportedFileFormats + sizeof(_supportedFileFormats) / sizeof(_supportedFileFormats[0]) );
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_ISetCompressCodecsInfoX, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x61, 0x00, 0x00);
DEFINE_GUID(IID_InArchive, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00);
DEFINE_GUID(IID_ISetCompressCodecsInfoX, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x61, 0x00, 0x00);
/*#ifdef Q_OS_UNIX
DEFINE_GUID(IID_IOutStream, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00);
@ -75,13 +75,13 @@ DEFINE_GUID(IID_ISequentialInStream, 0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0
#endif*/
struct SevenZipInterface {
CreateObjectFunc createObjectFunc;
GetMethodPropertyFunc getMethodPropertyFunc;
GetNumberOfMethodsFunc getNumberOfMethodsFunc;
GetNumberOfFormatsFunc getNumberOfFormatsFunc;
GetHandlerPropertyFunc getHandlerPropertyFunc;
GetHandlerPropertyFunc2 getHandlerPropertyFunc2;
SetLargePageModeFunc setLargePageModeFunc;
CreateObjectFunc createObjectFunc;
GetMethodPropertyFunc getMethodPropertyFunc;
GetNumberOfMethodsFunc getNumberOfMethodsFunc;
GetNumberOfFormatsFunc getNumberOfFormatsFunc;
GetHandlerPropertyFunc getHandlerPropertyFunc;
GetHandlerPropertyFunc2 getHandlerPropertyFunc2;
SetLargePageModeFunc setLargePageModeFunc;
#ifdef Q_OS_UNIX
CreateObjectFunc createObjectFuncRar;
@ -89,453 +89,414 @@ struct SevenZipInterface {
GetNumberOfMethodsFunc getNumberOfMethodsFuncRar;
#endif
CMyComPtr<IInArchive> archive;
CMyComPtr<IInArchive> archive;
};
//SevenZipInterface * szInterface;
const unsigned char rar[7]={static_cast<unsigned char>(0x52), static_cast<unsigned char>(0x61), static_cast<unsigned char>(0x72), static_cast<unsigned char>(0x21), static_cast<unsigned char>(0x1A), static_cast<unsigned char>(0x07), static_cast<unsigned char>(0x00)};
const unsigned char rar5[8]={static_cast<unsigned char>(0x52), static_cast<unsigned char>(0x61), static_cast<unsigned char>(0x72), static_cast<unsigned char>(0x21), static_cast<unsigned char>(0x1A), static_cast<unsigned char>(0x07), static_cast<unsigned char>(0x01), static_cast<unsigned char>(0x00)};
const unsigned char zip[2]={static_cast<unsigned char>(0x50), static_cast<unsigned char>(0x4B)};
const unsigned char sevenz[6]={static_cast<unsigned char>(0x37), static_cast<unsigned char>(0x7A), static_cast<unsigned char>(0xBC), static_cast<unsigned char>(0xAF), static_cast<unsigned char>(0x27), static_cast<unsigned char>(0x1C)};
const unsigned char tar[6]="ustar";
const unsigned char arj[2]={static_cast<unsigned char>(0x60), static_cast<unsigned char>(0xEA)};
const unsigned char rar[7] = { static_cast<unsigned char>(0x52), static_cast<unsigned char>(0x61), static_cast<unsigned char>(0x72), static_cast<unsigned char>(0x21), static_cast<unsigned char>(0x1A), static_cast<unsigned char>(0x07), static_cast<unsigned char>(0x00) };
const unsigned char rar5[8] = { static_cast<unsigned char>(0x52), static_cast<unsigned char>(0x61), static_cast<unsigned char>(0x72), static_cast<unsigned char>(0x21), static_cast<unsigned char>(0x1A), static_cast<unsigned char>(0x07), static_cast<unsigned char>(0x01), static_cast<unsigned char>(0x00) };
const unsigned char zip[2] = { static_cast<unsigned char>(0x50), static_cast<unsigned char>(0x4B) };
const unsigned char sevenz[6] = { static_cast<unsigned char>(0x37), static_cast<unsigned char>(0x7A), static_cast<unsigned char>(0xBC), static_cast<unsigned char>(0xAF), static_cast<unsigned char>(0x27), static_cast<unsigned char>(0x1C) };
const unsigned char tar[6] = "ustar";
const unsigned char arj[2] = { static_cast<unsigned char>(0x60), static_cast<unsigned char>(0xEA) };
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
QObject(parent),sevenzLib(0),valid(false),tools(false)
CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
: QObject(parent), sevenzLib(0), valid(false), tools(false)
#ifdef Q_OS_UNIX
,isRar(false)
,
isRar(false)
#endif
{
szInterface = new SevenZipInterface;
//load functions
if(!loadFunctions())
return;
szInterface = new SevenZipInterface;
//load functions
if (!loadFunctions())
return;
tools = true;
//load file
if(szInterface->createObjectFunc != 0)
{
//QUuid CLSID_CFormat7z("23170f69-40c1-278a-1000-000110070000");
//se crea el objeto Archivo: formato,tipo,objeto
bool formatFound = false;
CInFileStream *fileSpec = new CInFileStream;
CMyComPtr<IInStream> file = fileSpec;
tools = true;
//load file
if (szInterface->createObjectFunc != 0) {
//QUuid CLSID_CFormat7z("23170f69-40c1-278a-1000-000110070000");
//se crea el objeto Archivo: formato,tipo,objeto
bool formatFound = false;
CInFileStream *fileSpec = new CInFileStream;
CMyComPtr<IInStream> file = fileSpec;
YCArchiveOpenCallback *openCallbackSpec = new YCArchiveOpenCallback;
CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;
openCallbackSpec->PasswordIsDefined = false;
// openCallbackSpec->PasswordIsDefined = true;
// openCallbackSpec->Password = L"1";
//get file type from suffix
int i=-1;
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?
CMyComPtr<IArchiveOpenCallback> openCallback = openCallbackSpec;
openCallbackSpec->PasswordIsDefined = false;
// openCallbackSpec->PasswordIsDefined = true;
// openCallbackSpec->Password = L"1";
//get file type from suffix
int i = -1;
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?
#ifdef Q_OS_UNIX
if (memcmp(magicNumber,rar,6) != 0)
{
//match suffix to GUID list
if (memcmp(magicNumber,zip,2)==0)
i=0;
else if (memcmp(magicNumber,sevenz,6)==0)
i=2;
else if (memcmp(magicNumber,arj,2)==0)
i=3;
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;
}
}
if (memcmp(magicNumber, rar, 6) != 0) {
//match suffix to GUID list
if (memcmp(magicNumber, zip, 2) == 0)
i = 0;
else if (memcmp(magicNumber, sevenz, 6) == 0)
i = 2;
else if (memcmp(magicNumber, arj, 2) == 0)
i = 3;
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
if (memcmp(magicNumber,rar,6) == 0)
if (memcmp(magicNumber,rar5,7) == 0)
i=5;
else
i=0;
else if (memcmp(magicNumber,zip,2)==0)
i=1;
else if (memcmp(magicNumber,sevenz,6)==0)
i=3;
else if (memcmp(magicNumber,arj,2)==0)
i=4;
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;
}
}
if (memcmp(magicNumber, rar, 6) == 0)
if (memcmp(magicNumber, rar5, 7) == 0)
i = 5;
else
i = 0;
else if (memcmp(magicNumber, zip, 2) == 0)
i = 1;
else if (memcmp(magicNumber, sevenz, 6) == 0)
i = 3;
else if (memcmp(magicNumber, arj, 2) == 0)
i = 4;
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
#ifdef UNICODE
if (!fileSpec->Open((LPCTSTR)filePath.toStdWString().c_str()))
if (!fileSpec->Open((LPCTSTR)filePath.toStdWString().c_str()))
#else
if (!fileSpec->Open((LPCTSTR)filePath.toStdString().c_str()))
if (!fileSpec->Open((LPCTSTR)filePath.toStdString().c_str()))
#endif
{
qDebug() << "unable to load" + filePath;
return;
}
//GUID uuid = supportedFileFormats[i];
//qDebug() << "trying : " << uuid << endl;
if (szInterface->createObjectFunc(&supportedFileFormats[i], &IID_InArchive, (void **)&szInterface->archive) == S_OK)
{
//qDebug() << "Can not open archive file : " + filePath << endl;
{
qDebug() << "unable to load" + filePath;
return;
}
if (szInterface->archive->Open(file, 0, openCallback) == S_OK)
{
valid = formatFound = true;
qDebug() << "Opened archive file : " + filePath << endl;
//GUID uuid = supportedFileFormats[i];
//qDebug() << "trying : " << uuid << endl;
if (szInterface->createObjectFunc(&supportedFileFormats[i], &IID_InArchive, (void **)&szInterface->archive) == S_OK) {
//qDebug() << "Can not open archive file : " + filePath << endl;
if (szInterface->archive->Open(file, 0, openCallback) == S_OK) {
valid = formatFound = true;
qDebug() << "Opened archive file : " + filePath << endl;
setupFilesNames();
return;
}
}
return;
}
}
#ifdef Q_OS_WIN
if(!formatFound)
{
qDebug() << "Can not open archive" << endl;
}
}
}
if (!formatFound) {
qDebug() << "Can not open archive" << endl;
}
}
}
#else
}
else
{
} else {
//RAR in macos and unix
GUID clsidRar;
if (memcmp(magicNumber,rar5,7) == 0) {
if (memcmp(magicNumber, rar5, 7) == 0) {
clsidRar = CLSID_CFormatRar5;
} else {
clsidRar = CLSID_CFormatRar;
}
isRar=true; //tell the destructor we *tried* to open a rar file!
if (szInterface->createObjectFunc(&clsidRar, &IID_InArchive, (void **)&szInterface->archive) != S_OK)
{
qDebug() << "Error creating rar archive :" + filePath;
return;
}
CMyComPtr<ISetCompressCodecsInfo> codecsInfo;
isRar = true; //tell the destructor we *tried* to open a rar file!
if (szInterface->createObjectFunc(&clsidRar, &IID_InArchive, (void **)&szInterface->archive) != S_OK) {
qDebug() << "Error creating rar archive :" + filePath;
return;
}
if (szInterface->archive->QueryInterface(IID_ISetCompressCodecsInfoX,(void **)&codecsInfo) != S_OK)
{
qDebug() << "Error getting rar codec :" + filePath;
return;
}
if (codecsInfo->SetCompressCodecsInfo(this) != S_OK)
{
qDebug() << "Error setting rar codec";
return;
}
CMyComPtr<ISetCompressCodecsInfo> codecsInfo;
if (szInterface->archive->QueryInterface(IID_ISetCompressCodecsInfoX, (void **)&codecsInfo) != S_OK) {
qDebug() << "Error getting rar codec :" + filePath;
return;
}
if (codecsInfo->SetCompressCodecsInfo(this) != S_OK) {
qDebug() << "Error setting rar codec";
return;
}
#ifdef UNICODE
if (!fileSpec->Open((LPCTSTR)filePath.toStdWString().c_str()))
if (!fileSpec->Open((LPCTSTR)filePath.toStdWString().c_str()))
#else
if (!fileSpec->Open((LPCTSTR)filePath.toStdString().c_str()))
if (!fileSpec->Open((LPCTSTR)filePath.toStdString().c_str()))
#endif
{
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;
setupFilesNames();
//isRar = true;
}
{
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;
setupFilesNames();
//isRar = true;
}
}
}
}
#endif
CompressedArchive::~CompressedArchive()
{
//always close the archive!
if (szInterface->archive)
CompressedArchive::~CompressedArchive()
{
szInterface->archive->Close();
}
//always close the archive!
if (szInterface->archive) {
szInterface->archive->Close();
}
#ifdef Q_OS_UNIX
if(isRar) //TODO: Memory leak!!!! If AddRef is not used, a crash occurs in "delete szInterface"
{
szInterface->archive->AddRef();
}
if (isRar) //TODO: Memory leak!!!! If AddRef is not used, a crash occurs in "delete szInterface"
{
szInterface->archive->AddRef();
}
#endif
delete szInterface;
delete szInterface;
#ifdef Q_OS_UNIX
delete rarLib;
delete rarLib;
#endif
delete sevenzLib;
}
delete sevenzLib;
}
bool CompressedArchive::loadFunctions()
{
//LOAD library
//TODO check if this works in OSX (7z.so instead of 7z.dylib)
// fix1: try to load "7z.so"
// fix2: rename 7z.so to 7z.dylib
if(sevenzLib == 0)
bool CompressedArchive::loadFunctions()
{
//LOAD library
//TODO check if this works in OSX (7z.so instead of 7z.dylib)
// fix1: try to load "7z.so"
// fix2: rename 7z.so to 7z.dylib
if (sevenzLib == 0) {
#if defined Q_OS_UNIX
#if defined Q_OS_MAC
rarLib = new QLibrary(QCoreApplication::applicationDirPath()+"/utils/Codecs/Rar");
#else
//check if a yacreader specific version of p7zip exists on the system
QFileInfo rarCodec(QString(LIBDIR)+"/yacreader/Codecs/Rar.so");
if (rarCodec.exists())
{
rarLib = new QLibrary(rarCodec.absoluteFilePath());
}
else
{
rarLib = new QLibrary(QString(LIBDIR)+"/p7zip/Codecs/Rar.so");
}
#endif
if(!rarLib->load())
{
qDebug() << "Error Loading Rar.so : " + rarLib->errorString() << endl;
QCoreApplication::exit(700); //TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound
return false;
}
#if defined Q_OS_MAC
rarLib = new QLibrary(QCoreApplication::applicationDirPath() + "/utils/Codecs/Rar");
#else
//check if a yacreader specific version of p7zip exists on the system
QFileInfo rarCodec(QString(LIBDIR) + "/yacreader/Codecs/Rar.so");
if (rarCodec.exists()) {
rarLib = new QLibrary(rarCodec.absoluteFilePath());
} else {
rarLib = new QLibrary(QString(LIBDIR) + "/p7zip/Codecs/Rar.so");
}
#endif
if (!rarLib->load()) {
qDebug() << "Error Loading Rar.so : " + rarLib->errorString() << endl;
QCoreApplication::exit(700); //TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound
return false;
}
#endif
#if defined Q_OS_UNIX && !defined Q_OS_MAC
QFileInfo sevenzlibrary(QString(LIBDIR)+"/yacreader/7z.so");
if (sevenzlibrary.exists())
{
sevenzLib = new QLibrary(sevenzlibrary.absoluteFilePath());
}
else
{
sevenzLib = new QLibrary(QString(LIBDIR)+"/p7zip/7z.so");
}
QFileInfo sevenzlibrary(QString(LIBDIR) + "/yacreader/7z.so");
if (sevenzlibrary.exists()) {
sevenzLib = new QLibrary(sevenzlibrary.absoluteFilePath());
} else {
sevenzLib = new QLibrary(QString(LIBDIR) + "/p7zip/7z.so");
}
#else
sevenzLib = new QLibrary(QCoreApplication::applicationDirPath()+"/utils/7z");
sevenzLib = new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
#endif
}
if(!sevenzLib->load())
{
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
return false;
}
else
{
qDebug() << "Loading functions" << endl;
}
if (!sevenzLib->load()) {
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
return false;
} else {
qDebug() << "Loading functions" << endl;
if((szInterface->createObjectFunc = (CreateObjectFunc)sevenzLib->resolve("CreateObject")) == 0)
qDebug() << "fail loading function : CreateObject" << endl;
if((szInterface->getMethodPropertyFunc = (GetMethodPropertyFunc)sevenzLib->resolve("GetMethodProperty")) == 0)
qDebug() << "fail loading function : GetMethodProperty" << endl;
if((szInterface->getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)sevenzLib->resolve("GetNumberOfMethods")) == 0)
qDebug() << "fail loading function : GetNumberOfMethods" << endl;
if((szInterface->getNumberOfFormatsFunc = (GetNumberOfFormatsFunc)sevenzLib->resolve("GetNumberOfFormats")) == 0)
qDebug() << "fail loading function : GetNumberOfFormats" << endl;
if((szInterface->getHandlerPropertyFunc = (GetHandlerPropertyFunc)sevenzLib->resolve("GetHandlerProperty")) == 0)
qDebug() << "fail loading function : GetHandlerProperty" << endl;
if((szInterface->getHandlerPropertyFunc2 = (GetHandlerPropertyFunc2)sevenzLib->resolve("GetHandlerProperty2")) == 0)
qDebug() << "fail loading function : GetHandlerProperty2" << endl;
if((szInterface->setLargePageModeFunc = (SetLargePageModeFunc)sevenzLib->resolve("SetLargePageMode")) == 0)
qDebug() << "fail loading function : SetLargePageMode" << endl;
if ((szInterface->createObjectFunc = (CreateObjectFunc)sevenzLib->resolve("CreateObject")) == 0)
qDebug() << "fail loading function : CreateObject" << endl;
if ((szInterface->getMethodPropertyFunc = (GetMethodPropertyFunc)sevenzLib->resolve("GetMethodProperty")) == 0)
qDebug() << "fail loading function : GetMethodProperty" << endl;
if ((szInterface->getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)sevenzLib->resolve("GetNumberOfMethods")) == 0)
qDebug() << "fail loading function : GetNumberOfMethods" << endl;
if ((szInterface->getNumberOfFormatsFunc = (GetNumberOfFormatsFunc)sevenzLib->resolve("GetNumberOfFormats")) == 0)
qDebug() << "fail loading function : GetNumberOfFormats" << endl;
if ((szInterface->getHandlerPropertyFunc = (GetHandlerPropertyFunc)sevenzLib->resolve("GetHandlerProperty")) == 0)
qDebug() << "fail loading function : GetHandlerProperty" << endl;
if ((szInterface->getHandlerPropertyFunc2 = (GetHandlerPropertyFunc2)sevenzLib->resolve("GetHandlerProperty2")) == 0)
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;
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;
}
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 = prop.bstrVal;
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 < (quint32)offsets.length())
translatedIndexes.append(offsets.at(i));
return true;
}
return translatedIndexes;
}
QList<QString> CompressedArchive::getFileNames()
{
return files;
}
bool CompressedArchive::isValid()
{
return valid;
}
bool CompressedArchive::toolsLoaded()
{
return tools;
}
int CompressedArchive::getNumFiles()
{
return files.length();
}
int CompressedArchive::getNumEntries()
{
quint32 numItems = 0;
szInterface->archive->GetNumberOfItems(&numItems);
return numItems;
}
QList<QByteArray> CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
{
YCArchiveExtractCallback *extractCallbackSpec = new YCArchiveExtractCallback(indexesToPages, true, delegate);
CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path
extractCallbackSpec->PasswordIsDefined = false;
QVector<quint32> currentIndexes = translateIndexes(indexes);
HRESULT result;
if(indexes.isEmpty())
result = szInterface->archive->Extract(NULL, -1, false, extractCallback);
else
result = szInterface->archive->Extract(currentIndexes.data(), currentIndexes.count(), false, extractCallback);
if (result != S_OK)
void CompressedArchive::setupFilesNames()
{
qDebug() << "Extract Error" << endl;
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 = prop.bstrVal;
const wchar_t *chars = s.operator const wchar_t *();
files.append(QString::fromWCharArray(chars));
offsets.append(i);
indexesToPages.insert(i, p);
p++;
}
}
}
return extractCallbackSpec->allFiles;
}
QByteArray CompressedArchive::getRawDataAtIndex(int index)
{
if(index>=0 && index < getNumFiles())
QVector<quint32> CompressedArchive::translateIndexes(const QVector<quint32> &indexes)
{
YCArchiveExtractCallback *extractCallbackSpec = new YCArchiveExtractCallback(indexesToPages);
QVector<quint32> translatedIndexes;
foreach (quint32 i, indexes) {
if (i < (quint32)offsets.length())
translatedIndexes.append(offsets.at(i));
}
return translatedIndexes;
}
QList<QString> CompressedArchive::getFileNames()
{
return files;
}
bool CompressedArchive::isValid()
{
return valid;
}
bool CompressedArchive::toolsLoaded()
{
return tools;
}
int CompressedArchive::getNumFiles()
{
return files.length();
}
int CompressedArchive::getNumEntries()
{
quint32 numItems = 0;
szInterface->archive->GetNumberOfItems(&numItems);
return numItems;
}
QList<QByteArray> CompressedArchive::getAllData(const QVector<quint32> &indexes, ExtractDelegate *delegate)
{
YCArchiveExtractCallback *extractCallbackSpec = new YCArchiveExtractCallback(indexesToPages, true, delegate);
CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path
extractCallbackSpec->PasswordIsDefined = false;
UInt32 indices[1];
QVector<quint32> currentIndexes = translateIndexes(indexes);
if(index < offsets.length())
indices[0] = offsets.at(index);
HRESULT result;
if (indexes.isEmpty())
result = szInterface->archive->Extract(NULL, -1, false, extractCallback);
else
indices[0] = index;
HRESULT result = szInterface->archive->Extract(indices, 1, false, extractCallback);
if (result != S_OK)
{
result = szInterface->archive->Extract(currentIndexes.data(), currentIndexes.count(), false, extractCallback);
if (result != S_OK) {
qDebug() << "Extract Error" << endl;
}
return QByteArray((char *)extractCallbackSpec->data,extractCallbackSpec->newFileSize);
return extractCallbackSpec->allFiles;
}
QByteArray CompressedArchive::getRawDataAtIndex(int index)
{
if (index >= 0 && index < getNumFiles()) {
YCArchiveExtractCallback *extractCallbackSpec = new YCArchiveExtractCallback(indexesToPages);
CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
extractCallbackSpec->Init(szInterface->archive, L""); // second parameter is output folder path
extractCallbackSpec->PasswordIsDefined = false;
UInt32 indices[1];
if (index < offsets.length())
indices[0] = offsets.at(index);
else
indices[0] = index;
HRESULT result = szInterface->archive->Extract(indices, 1, false, extractCallback);
if (result != S_OK) {
qDebug() << "Extract Error" << endl;
}
return QByteArray((char *)extractCallbackSpec->data, extractCallbackSpec->newFileSize);
}
return QByteArray();
}
return QByteArray();
}
#ifdef Q_OS_UNIX
STDMETHODIMP CompressedArchive::GetNumMethods(UInt32 *numMethods)
{
return szInterface->getNumberOfMethodsFuncRar(numMethods);
}
STDMETHODIMP CompressedArchive::GetNumMethods(UInt32 * numMethods)
{
return szInterface->getNumberOfMethodsFuncRar(numMethods);
}
STDMETHODIMP CompressedArchive::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
{
return szInterface->getMethodPropertyFuncRar(index,propID,value);
}
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);
}
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 S_OK;//szInterface->createObjectFuncRar(&CLSID_CFormatRar,interfaceID,coder);
}
STDMETHODIMP CompressedArchive::CreateEncoder(UInt32 index, const GUID *interfaceID, void **coder)
{
return S_OK; //szInterface->createObjectFuncRar(&CLSID_CFormatRar,interfaceID,coder);
}
#endif

View File

@ -4,11 +4,10 @@
#include <QObject>
#ifdef Q_OS_UNIX
#include "libp7zip/CPP/7zip/ICoder.h"
#include "libp7zip/CPP/Common/MyCom.h"
#include "libp7zip/CPP/7zip/ICoder.h"
#include "libp7zip/CPP/Common/MyCom.h"
#endif
class ExtractDelegate;
class QLibrary;
@ -21,54 +20,59 @@ struct SevenZipInterface;
class MyCodecs;
#ifdef Q_OS_UNIX
class CompressedArchive : public QObject, public ICompressCodecsInfo, public CMyUnknownImp
class CompressedArchive : public QObject, public ICompressCodecsInfo, public CMyUnknownImp
#else
class CompressedArchive : public QObject
class CompressedArchive : public QObject
#endif
{
Q_OBJECT
Q_OBJECT
public:
explicit CompressedArchive(const QString & filePath, QObject *parent = 0);
~CompressedArchive();
explicit CompressedArchive(const QString &filePath, QObject *parent = 0);
~CompressedArchive();
#ifdef Q_OS_UNIX
MY_UNKNOWN_IMP
STDMETHOD(GetNumMethods)(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);
STDMETHOD(GetNumMethods)
(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);
bool isRar;
#endif
signals:
public slots:
int getNumFiles();
int getNumEntries();
QList<QByteArray> getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate = 0);
QByteArray getRawDataAtIndex(int index);
QList<QString> getFileNames();
bool isValid();
bool toolsLoaded();
private:
SevenZipInterface * szInterface;
QLibrary * sevenzLib;
public slots:
int getNumFiles();
int getNumEntries();
QList<QByteArray> getAllData(const QVector<quint32> &indexes, ExtractDelegate *delegate = 0);
QByteArray getRawDataAtIndex(int index);
QList<QString> getFileNames();
bool isValid();
bool toolsLoaded();
private:
SevenZipInterface *szInterface;
QLibrary *sevenzLib;
#ifdef Q_OS_UNIX
QLibrary * rarLib;
QLibrary *rarLib;
#endif
bool loadFunctions();
bool tools;
bool valid;
bool loadFunctions();
bool tools;
bool valid;
QList<QString> files;
QList<qint32> offsets;
QMap<qint32, qint32> indexesToPages;
void setupFilesNames();
QVector<quint32> translateIndexes(const QVector<quint32> &indexes);
friend class MyCodecs;
};

View File

@ -12,9 +12,9 @@ using namespace NWindows;
static const wchar_t *kCantDeleteOutputFile = L"ERROR: Can not delete output file ";
static const char *kTestingString = "Testing ";
static const char *kExtractingString = "Extracting ";
static const char *kSkippingString = "Skipping ";
static const char *kTestingString = "Testing ";
static const char *kExtractingString = "Extracting ";
static const char *kSkippingString = "Skipping ";
static const char *kUnsupportedMethod = "Unsupported Method";
static const char *kCRCFailed = "CRC Failed";
@ -25,179 +25,178 @@ static const wchar_t *kEmptyFileAlias = L"[Content]";
static HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)
{
NCOM::CPropVariant prop;
RINOK(archive->GetProperty(index, propID, &prop));
if (prop.vt == VT_BOOL)
result = VARIANT_BOOLToBool(prop.boolVal);
else if (prop.vt == VT_EMPTY)
result = false;
else
return E_FAIL;
return S_OK;
NCOM::CPropVariant prop;
RINOK(archive->GetProperty(index, propID, &prop));
if (prop.vt == VT_BOOL)
result = VARIANT_BOOLToBool(prop.boolVal);
else if (prop.vt == VT_EMPTY)
result = false;
else
return E_FAIL;
return S_OK;
}
static HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)
{
return IsArchiveItemProp(archive, index, kpidIsDir, result);
return IsArchiveItemProp(archive, index, kpidIsDir, result);
}
class YCArchiveExtractCallback:
public IArchiveExtractCallback,
public ICryptoGetTextPassword,
public CMyUnknownImp
class YCArchiveExtractCallback : public IArchiveExtractCallback,
public ICryptoGetTextPassword,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
// IProgress
STDMETHOD(SetTotal)(UInt64 size);
STDMETHOD(SetCompleted)(const UInt64 *completeValue);
// IProgress
STDMETHOD(SetTotal)
(UInt64 size);
STDMETHOD(SetCompleted)
(const UInt64 *completeValue);
// IArchiveExtractCallback
STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);
STDMETHOD(PrepareOperation)(Int32 askExtractMode);
STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);
// IArchiveExtractCallback
STDMETHOD(GetStream)
(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);
STDMETHOD(PrepareOperation)
(Int32 askExtractMode);
STDMETHOD(SetOperationResult)
(Int32 resultEOperationResult);
// ICryptoGetTextPassword
STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);
// ICryptoGetTextPassword
STDMETHOD(CryptoGetTextPassword)
(BSTR *aPassword);
private:
CMyComPtr<IInArchive> _archiveHandler;
UString _directoryPath; // Output directory
UString _filePath; // name inside arcvhive
UString _diskFilePath; // full path to file on disk
bool _extractMode;
bool all;
ExtractDelegate * delegate;
UInt32 _index;
struct CProcessedFileInfo
{
FILETIME MTime;
UInt32 Attrib;
bool isDir;
bool AttribDefined;
bool MTimeDefined;
} _processedFileInfo;
CMyComPtr<IInArchive> _archiveHandler;
UString _directoryPath; // Output directory
UString _filePath; // name inside arcvhive
UString _diskFilePath; // full path to file on disk
bool _extractMode;
bool all;
ExtractDelegate *delegate;
UInt32 _index;
struct CProcessedFileInfo {
FILETIME MTime;
UInt32 Attrib;
bool isDir;
bool AttribDefined;
bool MTimeDefined;
} _processedFileInfo;
COutFileStream *_outFileStreamSpec;
CMyComPtr<ISequentialOutStream> _outFileStream;
COutFileStream *_outFileStreamSpec;
CMyComPtr<ISequentialOutStream> _outFileStream;
public:
void Init(IInArchive *archiveHandler, const UString &directoryPath);
void Init(IInArchive *archiveHandler, const UString &directoryPath);
UInt64 NumErrors;
bool PasswordIsDefined;
QList<QByteArray> allFiles;
UString Password;
Byte * data;
UInt64 newFileSize;
QMap<qint32, qint32> indexesToPages;
UInt64 NumErrors;
bool PasswordIsDefined;
QList<QByteArray> allFiles;
UString Password;
Byte *data;
UInt64 newFileSize;
QMap<qint32, qint32> indexesToPages;
YCArchiveExtractCallback(const QMap<qint32, qint32> & indexesToPages ,bool c = false,ExtractDelegate * d = 0) : PasswordIsDefined(false),all(c),delegate(d),indexesToPages(indexesToPages) {}
~YCArchiveExtractCallback() {MidFree(data);}
YCArchiveExtractCallback(const QMap<qint32, qint32> &indexesToPages, bool c = false, ExtractDelegate *d = 0)
: PasswordIsDefined(false), all(c), delegate(d), indexesToPages(indexesToPages) {}
~YCArchiveExtractCallback() { MidFree(data); }
};
void YCArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)
{
NumErrors = 0;
_archiveHandler = archiveHandler;
directoryPath;//unused
NumErrors = 0;
_archiveHandler = archiveHandler;
directoryPath; //unused
}
STDMETHODIMP YCArchiveExtractCallback::SetTotal(UInt64 /* size */)
{
return S_OK;
return S_OK;
}
STDMETHODIMP YCArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)
{
return S_OK;
return S_OK;
}
STDMETHODIMP YCArchiveExtractCallback::GetStream(UInt32 index,
ISequentialOutStream **outStream, Int32 askExtractMode)
ISequentialOutStream **outStream, Int32 askExtractMode)
{
*outStream = 0;
_outFileStream.Release();
*outStream = 0;
_outFileStream.Release();
if(indexesToPages.isEmpty())
_index = index;
else
_index = indexesToPages.value(index);
{
// Get Name
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));
UString fullPath;
if (prop.vt == VT_EMPTY)
fullPath = kEmptyFileAlias;
if (indexesToPages.isEmpty())
_index = index;
else
{
if (prop.vt != VT_BSTR)
return E_FAIL;
fullPath = prop.bstrVal;
}
_filePath = fullPath;
}
_index = indexesToPages.value(index);
askExtractMode;//unused
//if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)
{
// Get Name
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));
UString fullPath;
if (prop.vt == VT_EMPTY)
fullPath = kEmptyFileAlias;
else {
if (prop.vt != VT_BSTR)
return E_FAIL;
fullPath = prop.bstrVal;
}
_filePath = fullPath;
}
askExtractMode; //unused
//if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)
//return S_OK;
{
// Get Attrib
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));
if (prop.vt == VT_EMPTY)
{
_processedFileInfo.Attrib = 0;
_processedFileInfo.AttribDefined = false;
}
else
{
if (prop.vt != VT_UI4)
return E_FAIL;
_processedFileInfo.Attrib = prop.ulVal;
_processedFileInfo.AttribDefined = true;
}
}
RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir));
{
// Get Modified Time
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));
_processedFileInfo.MTimeDefined = false;
switch(prop.vt)
{
case VT_EMPTY:
// _processedFileInfo.MTime = _utcMTimeDefault;
break;
case VT_FILETIME:
_processedFileInfo.MTime = prop.filetime;
_processedFileInfo.MTimeDefined = true;
break;
default:
return E_FAIL;
// Get Attrib
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));
if (prop.vt == VT_EMPTY) {
_processedFileInfo.Attrib = 0;
_processedFileInfo.AttribDefined = false;
} else {
if (prop.vt != VT_UI4)
return E_FAIL;
_processedFileInfo.Attrib = prop.ulVal;
_processedFileInfo.AttribDefined = true;
}
}
}
RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir));
//se necesita conocer el tama?o del archivo para poder reservar suficiente memoria
bool newFileSizeDefined;
{
// Get Size
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));
newFileSizeDefined = (prop.vt != VT_EMPTY);
if (newFileSizeDefined)
ConvertPropVariantToUInt64(prop, newFileSize);
}
{
// Get Modified Time
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));
_processedFileInfo.MTimeDefined = false;
switch (prop.vt) {
case VT_EMPTY:
// _processedFileInfo.MTime = _utcMTimeDefault;
break;
case VT_FILETIME:
_processedFileInfo.MTime = prop.filetime;
_processedFileInfo.MTimeDefined = true;
break;
default:
return E_FAIL;
}
}
//No hay que crear ning?n fichero, ni directorios intermedios
/*{
//se necesita conocer el tama?o del archivo para poder reservar suficiente memoria
bool newFileSizeDefined;
{
// Get Size
NCOM::CPropVariant prop;
RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));
newFileSizeDefined = (prop.vt != VT_EMPTY);
if (newFileSizeDefined)
ConvertPropVariantToUInt64(prop, newFileSize);
}
//No hay que crear ning?n fichero, ni directorios intermedios
/*{
// Create folders for file
int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);
if (slashPos >= 0)
@ -207,13 +206,10 @@ STDMETHODIMP YCArchiveExtractCallback::GetStream(UInt32 index,
UString fullProcessedPath = _directoryPath + _filePath;
_diskFilePath = fullProcessedPath;
*/
if (_processedFileInfo.isDir)
{
//NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
}
else
{
/*NFile::NFind::CFileInfoW fi;
if (_processedFileInfo.isDir) {
//NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
} else {
/*NFile::NFind::CFileInfoW fi;
if (fi.Find(fullProcessedPath))
{
if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
@ -222,87 +218,78 @@ STDMETHODIMP YCArchiveExtractCallback::GetStream(UInt32 index,
return E_ABORT;
}
}*/
if(newFileSizeDefined)
{
CBufPtrSeqOutStream *outStreamSpec = new CBufPtrSeqOutStream;
CMyComPtr<CBufPtrSeqOutStream> outStreamLocal(outStreamSpec);
data = (Byte *)MidAlloc(newFileSize);
outStreamSpec->Init(data, newFileSize);
*outStream = outStreamLocal.Detach();
}
else
{
}
}
return S_OK;
if (newFileSizeDefined) {
CBufPtrSeqOutStream *outStreamSpec = new CBufPtrSeqOutStream;
CMyComPtr<CBufPtrSeqOutStream> outStreamLocal(outStreamSpec);
data = (Byte *)MidAlloc(newFileSize);
outStreamSpec->Init(data, newFileSize);
*outStream = outStreamLocal.Detach();
} else {
}
}
return S_OK;
}
STDMETHODIMP YCArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)
{
_extractMode = false;
switch (askExtractMode)
{
case NArchive::NExtract::NAskMode::kExtract: _extractMode = true; break;
};
/* switch (askExtractMode)
_extractMode = false;
switch (askExtractMode) {
case NArchive::NExtract::NAskMode::kExtract:
_extractMode = true;
break;
};
/* switch (askExtractMode)
{
case NArchive::NExtract::NAskMode::kExtract: qDebug() << (kExtractingString); break;
case NArchive::NExtract::NAskMode::kTest: qDebug() <<(kTestingString); break;
case NArchive::NExtract::NAskMode::kSkip: qDebug() <<(kSkippingString); break;
};*/
//qDebug() << _filePath;
return S_OK;
//qDebug() << _filePath;
return S_OK;
}
STDMETHODIMP YCArchiveExtractCallback::SetOperationResult(Int32 operationResult)
{
switch(operationResult)
{
switch (operationResult) {
case NArchive::NExtract::NOperationResult::kOK:
if(all && !_processedFileInfo.isDir)
{
QByteArray rawData((char *)data,newFileSize);
if (all && !_processedFileInfo.isDir) {
QByteArray rawData((char *)data, newFileSize);
MidFree(data);
data = 0;
if(delegate != 0)
delegate->fileExtracted(_index,rawData);
else
{
if (delegate != 0)
delegate->fileExtracted(_index, rawData);
else {
allFiles.append(rawData);
}
}
break;
default:
{
NumErrors++;
qDebug() << " ";
switch(operationResult)
{
break;
default: {
NumErrors++;
qDebug() << " ";
switch (operationResult) {
case NArchive::NExtract::NOperationResult::kUnsupportedMethod:
if(delegate != 0)
delegate->unknownError(_index);
qDebug() << kUnsupportedMethod;
break;
if (delegate != 0)
delegate->unknownError(_index);
qDebug() << kUnsupportedMethod;
break;
case NArchive::NExtract::NOperationResult::kCRCError:
if(delegate != 0)
delegate->crcError(_index);
qDebug() << kCRCFailed;
break;
if (delegate != 0)
delegate->crcError(_index);
qDebug() << kCRCFailed;
break;
case NArchive::NExtract::NOperationResult::kDataError:
if(delegate != 0)
delegate->unknownError(_index);
qDebug() << kDataError;
break;
if (delegate != 0)
delegate->unknownError(_index);
qDebug() << kDataError;
break;
default:
if(delegate != 0)
delegate->unknownError(_index);
qDebug() << kUnknownError;
}
if (delegate != 0)
delegate->unknownError(_index);
qDebug() << kUnknownError;
}
}
}
/*
}
/*
if (_outFileStream != NULL)
{
if (_processedFileInfo.MTimeDefined)
@ -312,22 +299,20 @@ STDMETHODIMP YCArchiveExtractCallback::SetOperationResult(Int32 operationResult)
_outFileStream.Release();
if (_extractMode && _processedFileInfo.AttribDefined)
NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);*/
//qDebug() << endl;
return S_OK;
//qDebug() << endl;
return S_OK;
}
STDMETHODIMP YCArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)
{
if (!PasswordIsDefined)
{
// You can ask real password here from user
// Password = GetPassword(OutStream);
// PasswordIsDefined = true;
qDebug() << "Password is not defined" << endl;
return E_ABORT;
}
return StringToBstr(Password, password);
if (!PasswordIsDefined) {
// You can ask real password here from user
// Password = GetPassword(OutStream);
// PasswordIsDefined = true;
qDebug() << "Password is not defined" << endl;
return E_ABORT;
}
return StringToBstr(Password, password);
}
#endif

View File

@ -5,10 +5,10 @@
class ExtractDelegate
{
public:
virtual void fileExtracted(int index, const QByteArray & rawData) = 0;
virtual void crcError(int index) = 0;
virtual void unknownError(int index) = 0;
public:
virtual void fileExtracted(int index, const QByteArray &rawData) = 0;
virtual void crcError(int index) = 0;
virtual void unknownError(int index) = 0;
};
#endif //EXTRACT_DELEGATE_H

View File

@ -6,49 +6,48 @@
//////////////////////////////////////////////////////////////
// Archive Open callback class
class YCArchiveOpenCallback:
public IArchiveOpenCallback,
public ICryptoGetTextPassword,
public CMyUnknownImp
class YCArchiveOpenCallback : public IArchiveOpenCallback,
public ICryptoGetTextPassword,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);
STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);
STDMETHOD(SetTotal)
(const UInt64 *files, const UInt64 *bytes);
STDMETHOD(SetCompleted)
(const UInt64 *files, const UInt64 *bytes);
STDMETHOD(CryptoGetTextPassword)(BSTR *password);
STDMETHOD(CryptoGetTextPassword)
(BSTR *password);
bool PasswordIsDefined;
UString Password;
bool PasswordIsDefined;
UString Password;
YCArchiveOpenCallback() : PasswordIsDefined(false) {}
YCArchiveOpenCallback()
: PasswordIsDefined(false) {}
};
STDMETHODIMP YCArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)
{
return S_OK;
return S_OK;
}
STDMETHODIMP YCArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)
{
return S_OK;
return S_OK;
}
STDMETHODIMP YCArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)
{
if (!PasswordIsDefined)
{
// You can ask real password here from user
// Password = GetPassword(OutStream);
// PasswordIsDefined = true;
qDebug() << "Password is not defined" << endl;
return E_ABORT;
}
return StringToBstr(Password, password);
if (!PasswordIsDefined) {
// You can ask real password here from user
// Password = GetPassword(OutStream);
// PasswordIsDefined = true;
qDebug() << "Password is not defined" << endl;
return E_ABORT;
}
return StringToBstr(Password, password);
}
#endif

View File

@ -6,128 +6,116 @@
#include "extract_delegate.h"
#include <unarr.h>
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
QObject(parent),tools(true),valid(false),numFiles(0),ar(NULL),stream(NULL)
CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
: QObject(parent), tools(true), valid(false), numFiles(0), ar(NULL), stream(NULL)
{
//open file
#ifdef Q_OS_WIN
stream = ar_open_file_w((wchar_t *)filePath.utf16());
#else
stream = ar_open_file(filePath.toLocal8Bit().constData());
#endif
if (!stream)
{
return;
}
//open file
#ifdef Q_OS_WIN
stream = ar_open_file_w((wchar_t *)filePath.utf16());
#else
stream = ar_open_file(filePath.toLocal8Bit().constData());
#endif
if (!stream) {
return;
}
//open archive
ar = ar_open_rar_archive(stream);
//TODO: build unarr with 7z support and test this!
//if (!ar) ar = ar_open_7z_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)
{
return;
}
//open archive
ar = ar_open_rar_archive(stream);
//TODO: build unarr with 7z support and test this!
//if (!ar) ar = ar_open_7z_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) {
return;
}
//initial parse
while (ar_parse_entry(ar))
{
//make sure we really got a file header
if (ar_entry_get_size(ar) > 0)
{
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)
{
valid = true;
}
//initial parse
while (ar_parse_entry(ar)) {
//make sure we really got a file header
if (ar_entry_get_size(ar) > 0) {
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) {
valid = true;
}
}
CompressedArchive::~CompressedArchive()
{
ar_close_archive(ar);
ar_close(stream);
ar_close_archive(ar);
ar_close(stream);
}
QList<QString> CompressedArchive::getFileNames()
{
return fileNames;
return fileNames;
}
bool CompressedArchive::isValid()
{
return valid;
return valid;
}
bool CompressedArchive::toolsLoaded()
{
//for backwards compatibilty
return tools;
//for backwards compatibilty
return tools;
}
int CompressedArchive::getNumFiles()
{
return numFiles;
return numFiles;
}
void CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
void CompressedArchive::getAllData(const QVector<quint32> &indexes, ExtractDelegate *delegate)
{
if (indexes.isEmpty())
return;
if (indexes.isEmpty())
return;
QByteArray buffer;
QByteArray buffer;
int i=0;
while (i < indexes.count())
{
if(delegate == nullptr || delegate->isCancelled())
{
int i = 0;
while (i < indexes.count()) {
if (delegate == nullptr || delegate->isCancelled()) {
return;
}
//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?
{
delegate->fileExtracted(indexes.at(i), buffer); //return extracted file
}
else
{
delegate->crcError(indexes.at(i)); //we could not extract it...
}
i++;
}
//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?
{
delegate->fileExtracted(indexes.at(i), buffer); //return extracted file
} else {
delegate->crcError(indexes.at(i)); //we could not extract it...
}
i++;
}
}
QByteArray CompressedArchive::getRawDataAtIndex(int index)
{
QByteArray buffer;
if(index >= 0 && index < getNumFiles())
{
ar_parse_entry_at(ar, offsets.at(index));
buffer.resize(ar_entry_get_size(ar));
if(ar_entry_uncompress(ar, buffer.data(), buffer.size()))
{
return buffer;
}
else
{
return QByteArray();
}
}
QByteArray buffer;
if (index >= 0 && index < getNumFiles()) {
ar_parse_entry_at(ar, offsets.at(index));
buffer.resize(ar_entry_get_size(ar));
if (ar_entry_uncompress(ar, buffer.data(), buffer.size())) {
return buffer;
} else {
return QByteArray();
}
}
return buffer;
}

View File

@ -3,35 +3,35 @@
#include <QObject>
#include "extract_delegate.h"
extern"C" {
extern "C" {
#include <unarr.h>
}
class CompressedArchive : public QObject
{
Q_OBJECT
Q_OBJECT
public:
explicit CompressedArchive(const QString & filePath, QObject *parent = 0);
~CompressedArchive();
explicit CompressedArchive(const QString &filePath, QObject *parent = 0);
~CompressedArchive();
signals:
public slots:
int getNumFiles();
void getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate=0);
QByteArray getRawDataAtIndex(int index);
QList<QString> getFileNames();
bool isValid();
bool toolsLoaded();
private:
bool tools;
bool valid;
QList<QString> fileNames;
int numFiles;
ar_archive *ar;
ar_stream *stream;
QList<qint64> offsets;
public slots:
int getNumFiles();
void getAllData(const QVector<quint32> &indexes, ExtractDelegate *delegate = 0);
QByteArray getRawDataAtIndex(int index);
QList<QString> getFileNames();
bool isValid();
bool toolsLoaded();
private:
bool tools;
bool valid;
QList<QString> fileNames;
int numFiles;
ar_archive *ar;
ar_stream *stream;
QList<qint64> offsets;
};
#endif // COMPRESSED_ARCHIVE_H

View File

@ -5,11 +5,11 @@
class ExtractDelegate
{
public:
virtual void fileExtracted(int index, const QByteArray & rawData) = 0;
virtual void crcError(int index) = 0;
virtual void unknownError(int index) = 0;
virtual bool isCancelled() = 0;
public:
virtual void fileExtracted(int index, const QByteArray &rawData) = 0;
virtual void crcError(int index) = 0;
virtual void unknownError(int index) = 0;
virtual bool isCancelled() = 0;
};
#endif //EXTRACT_DELEGATE_H