mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 21:14:33 -04:00
clang-format
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#ifndef _7Z_INCLUDES_H
|
||||
#define _7Z_INCLUDES_H
|
||||
|
||||
//WIN includes
|
||||
// WIN includes
|
||||
#ifdef Q_OS_WIN
|
||||
extern "C" {
|
||||
#include "lib7zip/C/Alloc.h"
|
||||
@ -29,7 +29,7 @@ extern "C" {
|
||||
#include "lib7zip/CPP/7zip/Common/StreamUtils.h"
|
||||
|
||||
#else
|
||||
//POSIX includes
|
||||
// POSIX includes
|
||||
|
||||
extern "C" {
|
||||
#include "libp7zip/C/Alloc.h"
|
||||
@ -41,8 +41,8 @@ extern "C" {
|
||||
#include "libp7zip/CPP/Common/Common.h"
|
||||
#include "libp7zip/CPP/Common/MyCom.h"
|
||||
|
||||
//macos
|
||||
//typedef int BOOL; ---> typedef signed char BOOL;
|
||||
// macos
|
||||
// typedef int BOOL; ---> typedef signed char BOOL;
|
||||
#include "libp7zip/CPP/include_windows/windows.h"
|
||||
#include "libp7zip/CPP/include_windows/basetyps.h"
|
||||
#include "libp7zip/CPP/include_windows/tchar.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*--------------------------------------------------------------------
|
||||
/*--------------------------------------------------------------------
|
||||
*
|
||||
* Due to issues with the dependencies checker within the IDE, it
|
||||
* sometimes fails to recompile the PCH file, if we force the IDE to
|
||||
|
@ -30,8 +30,8 @@ typedef quint32(_MY_WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *
|
||||
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(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(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);
|
||||
@ -40,7 +40,7 @@ DEFINE_GUID(CLSID_CFormatZip, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01
|
||||
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
|
||||
// unused Formats
|
||||
/*DEFINE_GUID(CLSID_CFormatBZip2, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x02, 0x00, 0x00);
|
||||
DEFINE_GUID(CLSID_CFormatCab, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0x08, 0x00, 0x00);
|
||||
DEFINE_GUID(CLSID_CFormatChm, 0x23170f69, 0x40c1, 0x278a, 0x10, 0x00, 0x00, 0x01, 0x10, 0xe9, 0x00, 0x00);
|
||||
@ -92,7 +92,7 @@ struct SevenZipInterface {
|
||||
CMyComPtr<IInArchive> archive;
|
||||
};
|
||||
|
||||
//SevenZipInterface * szInterface;
|
||||
// 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) };
|
||||
@ -109,15 +109,15 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
#endif
|
||||
{
|
||||
szInterface = new SevenZipInterface;
|
||||
//load functions
|
||||
// load functions
|
||||
if (!loadFunctions())
|
||||
return;
|
||||
|
||||
tools = true;
|
||||
//load file
|
||||
// load file
|
||||
if (szInterface->createObjectFunc != 0) {
|
||||
//QUuid CLSID_CFormat7z("23170f69-40c1-278a-1000-000110070000");
|
||||
//se crea el objeto Archivo: formato,tipo,objeto
|
||||
// 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;
|
||||
@ -128,21 +128,21 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
// openCallbackSpec->PasswordIsDefined = true;
|
||||
// openCallbackSpec->Password = L"1";
|
||||
|
||||
//get file type from suffix
|
||||
// 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
|
||||
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?
|
||||
// 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
|
||||
// match suffix to GUID list
|
||||
if (memcmp(magicNumber, zip, 2) == 0)
|
||||
i = 0;
|
||||
else if (memcmp(magicNumber, sevenz, 6) == 0)
|
||||
@ -155,7 +155,7 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
if (memcmp(magicNumber, tar, 5) == 0)
|
||||
i = 1;
|
||||
}
|
||||
if (i == -1) //fallback code
|
||||
if (i == -1) // fallback code
|
||||
{
|
||||
QFileInfo fileinfo(filePath);
|
||||
if (fileinfo.suffix() == "zip" || fileinfo.suffix() == "cbz") {
|
||||
@ -182,7 +182,7 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
if (memcmp(magicNumber, tar, 5) == 0)
|
||||
i = 2;
|
||||
}
|
||||
if (i == -1) //fallback code
|
||||
if (i == -1) // fallback code
|
||||
{
|
||||
QFileInfo fileinfo(filePath);
|
||||
if (fileinfo.suffix() == "zip" || fileinfo.suffix() == "cbz") {
|
||||
@ -203,10 +203,10 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
return;
|
||||
}
|
||||
|
||||
//GUID uuid = supportedFileFormats[i];
|
||||
//qDebug() << "trying : " << uuid << 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;
|
||||
// qDebug() << "Can not open archive file : " + filePath << endl;
|
||||
|
||||
if (szInterface->archive->Open(file, 0, openCallback) == S_OK) {
|
||||
valid = formatFound = true;
|
||||
@ -224,7 +224,7 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
}
|
||||
#else
|
||||
} else {
|
||||
//RAR in macos and unix
|
||||
// RAR in macos and unix
|
||||
GUID clsidRar;
|
||||
if (memcmp(magicNumber, rar5, 7) == 0) {
|
||||
clsidRar = CLSID_CFormatRar5;
|
||||
@ -232,7 +232,7 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
clsidRar = CLSID_CFormatRar;
|
||||
}
|
||||
|
||||
isRar = true; //tell the destructor we *tried* to open a rar file!
|
||||
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;
|
||||
@ -258,12 +258,12 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
qDebug() << "Error opening rar file :" + filePath;
|
||||
return;
|
||||
}
|
||||
//qDebug() << "Can not open archive file : " + filePath << endl;
|
||||
// qDebug() << "Can not open archive file : " + filePath << endl;
|
||||
|
||||
if (szInterface->archive->Open(file, 0, openCallback) == S_OK) {
|
||||
valid = formatFound = true;
|
||||
setupFilesNames();
|
||||
//isRar = true;
|
||||
// isRar = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -272,13 +272,13 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
|
||||
CompressedArchive::~CompressedArchive()
|
||||
{
|
||||
//always close the archive!
|
||||
// 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"
|
||||
if (isRar) // TODO: Memory leak!!!! If AddRef is not used, a crash occurs in "delete szInterface"
|
||||
{
|
||||
szInterface->archive->AddRef();
|
||||
}
|
||||
@ -293,16 +293,16 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
|
||||
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
|
||||
// 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
|
||||
// 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());
|
||||
@ -312,7 +312,7 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
#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
|
||||
QCoreApplication::exit(700); // TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
@ -329,7 +329,7 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
}
|
||||
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
|
||||
QCoreApplication::exit(700); // TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound
|
||||
return false;
|
||||
} else {
|
||||
qDebug() << "Loading functions" << endl;
|
||||
@ -496,7 +496,7 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
|
||||
STDMETHODIMP CompressedArchive::CreateEncoder(UInt32 index, const GUID *interfaceID, void **coder)
|
||||
{
|
||||
return S_OK; //szInterface->createObjectFuncRar(&CLSID_CFormatRar,interfaceID,coder);
|
||||
return S_OK; // szInterface->createObjectFuncRar(&CLSID_CFormatRar,interfaceID,coder);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -105,7 +105,7 @@ void YCArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &d
|
||||
{
|
||||
NumErrors = 0;
|
||||
_archiveHandler = archiveHandler;
|
||||
directoryPath; //unused
|
||||
directoryPath; // unused
|
||||
}
|
||||
|
||||
STDMETHODIMP YCArchiveExtractCallback::SetTotal(UInt64 /* size */)
|
||||
@ -145,9 +145,9 @@ STDMETHODIMP YCArchiveExtractCallback::GetStream(UInt32 index,
|
||||
_filePath = fullPath;
|
||||
}
|
||||
|
||||
askExtractMode; //unused
|
||||
//if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)
|
||||
//return S_OK;
|
||||
askExtractMode; // unused
|
||||
// if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)
|
||||
// return S_OK;
|
||||
|
||||
{
|
||||
// Get Attrib
|
||||
@ -184,7 +184,7 @@ STDMETHODIMP YCArchiveExtractCallback::GetStream(UInt32 index,
|
||||
}
|
||||
}
|
||||
|
||||
//se necesita conocer el tama?o del archivo para poder reservar suficiente memoria
|
||||
// se necesita conocer el tama?o del archivo para poder reservar suficiente memoria
|
||||
bool newFileSizeDefined;
|
||||
{
|
||||
// Get Size
|
||||
@ -195,7 +195,7 @@ STDMETHODIMP YCArchiveExtractCallback::GetStream(UInt32 index,
|
||||
ConvertPropVariantToUInt64(prop, newFileSize);
|
||||
}
|
||||
|
||||
//No hay que crear ning?n fichero, ni directorios intermedios
|
||||
// No hay que crear ning?n fichero, ni directorios intermedios
|
||||
/*{
|
||||
// Create folders for file
|
||||
int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);
|
||||
@ -207,7 +207,7 @@ STDMETHODIMP YCArchiveExtractCallback::GetStream(UInt32 index,
|
||||
_diskFilePath = fullProcessedPath;
|
||||
*/
|
||||
if (_processedFileInfo.isDir) {
|
||||
//NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
|
||||
// NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
|
||||
} else {
|
||||
/*NFile::NFind::CFileInfoW fi;
|
||||
if (fi.Find(fullProcessedPath))
|
||||
@ -244,7 +244,7 @@ STDMETHODIMP YCArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)
|
||||
case NArchive::NExtract::NAskMode::kTest: qDebug() <<(kTestingString); break;
|
||||
case NArchive::NExtract::NAskMode::kSkip: qDebug() <<(kSkippingString); break;
|
||||
};*/
|
||||
//qDebug() << _filePath;
|
||||
// qDebug() << _filePath;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@ -299,7 +299,7 @@ STDMETHODIMP YCArchiveExtractCallback::SetOperationResult(Int32 operationResult)
|
||||
_outFileStream.Release();
|
||||
if (_extractMode && _processedFileInfo.AttribDefined)
|
||||
NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);*/
|
||||
//qDebug() << endl;
|
||||
// qDebug() << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -11,4 +11,4 @@ public:
|
||||
virtual void unknownError(int index) = 0;
|
||||
};
|
||||
|
||||
#endif //EXTRACT_DELEGATE_H
|
||||
#endif // EXTRACT_DELEGATE_H
|
@ -9,7 +9,7 @@
|
||||
CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
: QObject(parent), tools(true), valid(false), numFiles(0), ar(NULL), stream(NULL)
|
||||
{
|
||||
//open file
|
||||
// open file
|
||||
#ifdef Q_OS_WIN
|
||||
stream = ar_open_file_w((wchar_t *)filePath.utf16());
|
||||
#else
|
||||
@ -19,23 +19,23 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
return;
|
||||
}
|
||||
|
||||
//open archive
|
||||
// open archive
|
||||
ar = ar_open_rar_archive(stream);
|
||||
//TODO: build unarr with 7z support and test this!
|
||||
// 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...
|
||||
// zip detection is costly, so it comes last...
|
||||
if (!ar)
|
||||
ar = ar_open_zip_archive(stream, false);
|
||||
if (!ar) {
|
||||
return;
|
||||
}
|
||||
|
||||
//initial parse
|
||||
// initial parse
|
||||
while (ar_parse_entry(ar)) {
|
||||
//make sure we really got a file header
|
||||
// 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));
|
||||
@ -43,8 +43,8 @@ CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
|
||||
}
|
||||
}
|
||||
if (!ar_at_eof(ar)) {
|
||||
//fail if the initial parse didn't reach EOF
|
||||
//this might be a bit too drastic
|
||||
// fail if the initial parse didn't reach EOF
|
||||
// this might be a bit too drastic
|
||||
qDebug() << "Error while parsing archive";
|
||||
return;
|
||||
}
|
||||
@ -71,7 +71,7 @@ bool CompressedArchive::isValid()
|
||||
|
||||
bool CompressedArchive::toolsLoaded()
|
||||
{
|
||||
//for backwards compatibilty
|
||||
// for backwards compatibilty
|
||||
return tools;
|
||||
}
|
||||
|
||||
@ -93,14 +93,14 @@ void CompressedArchive::getAllData(const QVector<quint32> &indexes, ExtractDeleg
|
||||
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
|
||||
// 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?
|
||||
if (ar_entry_uncompress(ar, buffer.data(), buffer.size())) // did we extract it?
|
||||
{
|
||||
delegate->fileExtracted(indexes.at(i), buffer); //return extracted file
|
||||
delegate->fileExtracted(indexes.at(i), buffer); // return extracted file
|
||||
} else {
|
||||
delegate->crcError(indexes.at(i)); //we could not extract it...
|
||||
delegate->crcError(indexes.at(i)); // we could not extract it...
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -12,4 +12,4 @@ public:
|
||||
virtual bool isCancelled() = 0;
|
||||
};
|
||||
|
||||
#endif //EXTRACT_DELEGATE_H
|
||||
#endif // EXTRACT_DELEGATE_H
|
Reference in New Issue
Block a user