mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 21:14:33 -04:00
Add .gitattributes rules for text and binary handling
This commit is contained in:
@ -1,65 +1,65 @@
|
||||
#ifndef _7Z_INCLUDES_H
|
||||
#define _7Z_INCLUDES_H
|
||||
|
||||
//WIN includes
|
||||
#ifdef Q_OS_WIN
|
||||
#include "lib7zip/CPP/Common/StringConvert.h"
|
||||
#include "lib7zip/CPP/Common/MyInitGuid.h"
|
||||
#include "lib7zip/CPP/Common/MyCom.h"
|
||||
#include "lib7zip/CPP/7zip/Common/FileStreams.h"
|
||||
#include "lib7zip/CPP/7zip/Archive/IArchive.h"
|
||||
|
||||
#include "lib7zip/CPP/7zip/IStream.h"
|
||||
|
||||
#include "lib7zip/CPP/7zip/IPassword.h"
|
||||
#include "lib7zip/CPP/7zip/MyVersion.h"
|
||||
|
||||
#include "lib7zip/C/Types.h"
|
||||
|
||||
#include "lib7zip/CPP/Windows/PropVariant.h"
|
||||
#include "lib7zip/CPP/Windows/PropVariantConversions.h"
|
||||
|
||||
#include "lib7zip/CPP/7zip/Common/StreamObjects.h"
|
||||
#include "lib7zip/CPP/7zip/Common/StreamUtils.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "lib7zip/C/Alloc.h"
|
||||
}
|
||||
#else
|
||||
//POSIX includes
|
||||
#include "libp7zip/CPP/myWindows/myPrivate.h"
|
||||
#include "libp7zip/CPP/myWindows/config.h"
|
||||
|
||||
#include "libp7zip/CPP/Common/MyGuidDef.h"
|
||||
#include "libp7zip/CPP/Common/MyWindows.h"
|
||||
|
||||
#include "libp7zip/CPP/Common/StringConvert.h"
|
||||
#include "libp7zip/CPP/Common/MyInitGuid.h"
|
||||
#include "libp7zip/CPP/Common/MyCom.h"
|
||||
#include "libp7zip/CPP/7zip/Common/FileStreams.h"
|
||||
#include "libp7zip/CPP/7zip/Archive/IArchive.h"
|
||||
|
||||
#include "libp7zip/CPP/7zip/IStream.h"
|
||||
|
||||
#include "libp7zip/CPP/7zip/IPassword.h"
|
||||
#include "libp7zip/CPP/7zip/MyVersion.h"
|
||||
|
||||
#include "libp7zip/C/Types.h"
|
||||
|
||||
#include "libp7zip/CPP/Windows/Defs.h"
|
||||
#include "libp7zip/CPP/Windows/PropVariant.h"
|
||||
#include "libp7zip/CPP/Windows/PropVariantConversions.h"
|
||||
|
||||
#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"
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _7Z_INCLUDES_H
|
||||
#ifndef _7Z_INCLUDES_H
|
||||
#define _7Z_INCLUDES_H
|
||||
|
||||
//WIN includes
|
||||
#ifdef Q_OS_WIN
|
||||
#include "lib7zip/CPP/Common/StringConvert.h"
|
||||
#include "lib7zip/CPP/Common/MyInitGuid.h"
|
||||
#include "lib7zip/CPP/Common/MyCom.h"
|
||||
#include "lib7zip/CPP/7zip/Common/FileStreams.h"
|
||||
#include "lib7zip/CPP/7zip/Archive/IArchive.h"
|
||||
|
||||
#include "lib7zip/CPP/7zip/IStream.h"
|
||||
|
||||
#include "lib7zip/CPP/7zip/IPassword.h"
|
||||
#include "lib7zip/CPP/7zip/MyVersion.h"
|
||||
|
||||
#include "lib7zip/C/Types.h"
|
||||
|
||||
#include "lib7zip/CPP/Windows/PropVariant.h"
|
||||
#include "lib7zip/CPP/Windows/PropVariantConversions.h"
|
||||
|
||||
#include "lib7zip/CPP/7zip/Common/StreamObjects.h"
|
||||
#include "lib7zip/CPP/7zip/Common/StreamUtils.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "lib7zip/C/Alloc.h"
|
||||
}
|
||||
#else
|
||||
//POSIX includes
|
||||
#include "libp7zip/CPP/myWindows/myPrivate.h"
|
||||
#include "libp7zip/CPP/myWindows/config.h"
|
||||
|
||||
#include "libp7zip/CPP/Common/MyGuidDef.h"
|
||||
#include "libp7zip/CPP/Common/MyWindows.h"
|
||||
|
||||
#include "libp7zip/CPP/Common/StringConvert.h"
|
||||
#include "libp7zip/CPP/Common/MyInitGuid.h"
|
||||
#include "libp7zip/CPP/Common/MyCom.h"
|
||||
#include "libp7zip/CPP/7zip/Common/FileStreams.h"
|
||||
#include "libp7zip/CPP/7zip/Archive/IArchive.h"
|
||||
|
||||
#include "libp7zip/CPP/7zip/IStream.h"
|
||||
|
||||
#include "libp7zip/CPP/7zip/IPassword.h"
|
||||
#include "libp7zip/CPP/7zip/MyVersion.h"
|
||||
|
||||
#include "libp7zip/C/Types.h"
|
||||
|
||||
#include "libp7zip/CPP/Windows/Defs.h"
|
||||
#include "libp7zip/CPP/Windows/PropVariant.h"
|
||||
#include "libp7zip/CPP/Windows/PropVariantConversions.h"
|
||||
|
||||
#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"
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _7Z_INCLUDES_H
|
||||
|
@ -1,9 +1,9 @@
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#endif
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#endif
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*--------------------------------------------------------------------
|
||||
*
|
||||
* Due to issues with the dependencies checker within the IDE, it
|
||||
* sometimes fails to recompile the PCH file, if we force the IDE to
|
||||
* This file is auto-generated by qmake since no PRECOMPILED_SOURCE was
|
||||
* specified, and is used as the common stdafx.cpp. The file is only
|
||||
* command line compilations by nmake.
|
||||
*
|
||||
--------------------------------------------------------------------*/
|
||||
#include "StdAfx.h"
|
||||
/*--------------------------------------------------------------------
|
||||
*
|
||||
* Due to issues with the dependencies checker within the IDE, it
|
||||
* sometimes fails to recompile the PCH file, if we force the IDE to
|
||||
* This file is auto-generated by qmake since no PRECOMPILED_SOURCE was
|
||||
* specified, and is used as the common stdafx.cpp. The file is only
|
||||
* command line compilations by nmake.
|
||||
*
|
||||
--------------------------------------------------------------------*/
|
||||
#include "StdAfx.h"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,89 +1,89 @@
|
||||
#ifndef COMPRESSED_ARCHIVE_H
|
||||
#define COMPRESSED_ARCHIVE_H
|
||||
|
||||
#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
|
||||
#include "7z_includes.h"
|
||||
#define _MY_WINAPI WINAPI
|
||||
#else
|
||||
#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)();
|
||||
|
||||
class QLibrary;
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
|
||||
struct SevenZipInterface;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
#ifdef Q_OS_UNIX
|
||||
QLibrary * rarLib;
|
||||
#endif
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // COMPRESSED_ARCHIVE_H
|
||||
#ifndef COMPRESSED_ARCHIVE_H
|
||||
#define COMPRESSED_ARCHIVE_H
|
||||
|
||||
#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
|
||||
#include "7z_includes.h"
|
||||
#define _MY_WINAPI WINAPI
|
||||
#else
|
||||
#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)();
|
||||
|
||||
class QLibrary;
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
|
||||
struct SevenZipInterface;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
#ifdef Q_OS_UNIX
|
||||
QLibrary * rarLib;
|
||||
#endif
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // COMPRESSED_ARCHIVE_H
|
||||
|
@ -1,333 +1,333 @@
|
||||
#ifndef EXTRACT_CALLBACKS_H
|
||||
#define EXTRACT_CALLBACKS_H
|
||||
|
||||
#include "7z_includes.h"
|
||||
#include "extract_delegate.h"
|
||||
#include <QDebug>
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Archive Extracting callback class
|
||||
|
||||
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 *kUnsupportedMethod = "Unsupported Method";
|
||||
static const char *kCRCFailed = "CRC Failed";
|
||||
static const char *kDataError = "Data Error";
|
||||
static const char *kUnknownError = "Unknown Error";
|
||||
|
||||
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;
|
||||
}
|
||||
static HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)
|
||||
{
|
||||
return IsArchiveItemProp(archive, index, kpidIsDir, result);
|
||||
}
|
||||
|
||||
class CArchiveExtractCallback:
|
||||
public IArchiveExtractCallback,
|
||||
public ICryptoGetTextPassword,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
|
||||
|
||||
// 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);
|
||||
|
||||
// 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;
|
||||
|
||||
COutFileStream *_outFileStreamSpec;
|
||||
CMyComPtr<ISequentialOutStream> _outFileStream;
|
||||
|
||||
public:
|
||||
void Init(IInArchive *archiveHandler, const UString &directoryPath);
|
||||
|
||||
UInt64 NumErrors;
|
||||
bool PasswordIsDefined;
|
||||
QList<QByteArray> allFiles;
|
||||
UString Password;
|
||||
Byte * data;
|
||||
UInt64 newFileSize;
|
||||
QMap<qint32, qint32> indexesToPages;
|
||||
|
||||
CArchiveExtractCallback(const QMap<qint32, qint32> & indexesToPages ,bool c = false,ExtractDelegate * d = 0) : PasswordIsDefined(false),all(c),delegate(d),indexesToPages(indexesToPages) {}
|
||||
~CArchiveExtractCallback() {MidFree(data);}
|
||||
};
|
||||
|
||||
void CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)
|
||||
{
|
||||
NumErrors = 0;
|
||||
_archiveHandler = archiveHandler;
|
||||
directoryPath;//unused
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
|
||||
ISequentialOutStream **outStream, Int32 askExtractMode)
|
||||
{
|
||||
*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;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//se necesita conocer el tama<6D>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)
|
||||
newFileSize = ConvertPropVariantToUInt64(prop);
|
||||
}
|
||||
|
||||
//No hay que crear ning<6E>n fichero, ni directorios intermedios
|
||||
/*{
|
||||
// Create folders for file
|
||||
int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);
|
||||
if (slashPos >= 0)
|
||||
NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));
|
||||
}
|
||||
|
||||
UString fullProcessedPath = _directoryPath + _filePath;
|
||||
_diskFilePath = fullProcessedPath;
|
||||
*/
|
||||
if (_processedFileInfo.isDir)
|
||||
{
|
||||
//NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*NFile::NFind::CFileInfoW fi;
|
||||
if (fi.Find(fullProcessedPath))
|
||||
{
|
||||
if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
|
||||
{
|
||||
qDebug() <<(UString(kCantDeleteOutputFile) + fullProcessedPath);
|
||||
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;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 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;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)
|
||||
{
|
||||
switch(operationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kOK:
|
||||
if(all && !_processedFileInfo.isDir)
|
||||
{
|
||||
QByteArray rawData((char *)data,newFileSize);
|
||||
MidFree(data);
|
||||
data = 0;
|
||||
if(delegate != 0)
|
||||
delegate->fileExtracted(_index,rawData);
|
||||
else
|
||||
{
|
||||
allFiles.append(rawData);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
NumErrors++;
|
||||
qDebug() << " ";
|
||||
switch(operationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
|
||||
if(delegate != 0)
|
||||
delegate->unknownError(_index);
|
||||
qDebug() << kUnsupportedMethod;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kCRCError:
|
||||
if(delegate != 0)
|
||||
delegate->crcError(_index);
|
||||
qDebug() << kCRCFailed;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kDataError:
|
||||
if(delegate != 0)
|
||||
delegate->unknownError(_index);
|
||||
qDebug() << kDataError;
|
||||
break;
|
||||
default:
|
||||
if(delegate != 0)
|
||||
delegate->unknownError(_index);
|
||||
qDebug() << kUnknownError;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (_outFileStream != NULL)
|
||||
{
|
||||
if (_processedFileInfo.MTimeDefined)
|
||||
_outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);
|
||||
RINOK(_outFileStreamSpec->Close());
|
||||
}
|
||||
_outFileStream.Release();
|
||||
if (_extractMode && _processedFileInfo.AttribDefined)
|
||||
NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);*/
|
||||
//qDebug() << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::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);
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef EXTRACT_CALLBACKS_H
|
||||
#define EXTRACT_CALLBACKS_H
|
||||
|
||||
#include "7z_includes.h"
|
||||
#include "extract_delegate.h"
|
||||
#include <QDebug>
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Archive Extracting callback class
|
||||
|
||||
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 *kUnsupportedMethod = "Unsupported Method";
|
||||
static const char *kCRCFailed = "CRC Failed";
|
||||
static const char *kDataError = "Data Error";
|
||||
static const char *kUnknownError = "Unknown Error";
|
||||
|
||||
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;
|
||||
}
|
||||
static HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)
|
||||
{
|
||||
return IsArchiveItemProp(archive, index, kpidIsDir, result);
|
||||
}
|
||||
|
||||
class CArchiveExtractCallback:
|
||||
public IArchiveExtractCallback,
|
||||
public ICryptoGetTextPassword,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
|
||||
|
||||
// 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);
|
||||
|
||||
// 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;
|
||||
|
||||
COutFileStream *_outFileStreamSpec;
|
||||
CMyComPtr<ISequentialOutStream> _outFileStream;
|
||||
|
||||
public:
|
||||
void Init(IInArchive *archiveHandler, const UString &directoryPath);
|
||||
|
||||
UInt64 NumErrors;
|
||||
bool PasswordIsDefined;
|
||||
QList<QByteArray> allFiles;
|
||||
UString Password;
|
||||
Byte * data;
|
||||
UInt64 newFileSize;
|
||||
QMap<qint32, qint32> indexesToPages;
|
||||
|
||||
CArchiveExtractCallback(const QMap<qint32, qint32> & indexesToPages ,bool c = false,ExtractDelegate * d = 0) : PasswordIsDefined(false),all(c),delegate(d),indexesToPages(indexesToPages) {}
|
||||
~CArchiveExtractCallback() {MidFree(data);}
|
||||
};
|
||||
|
||||
void CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)
|
||||
{
|
||||
NumErrors = 0;
|
||||
_archiveHandler = archiveHandler;
|
||||
directoryPath;//unused
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
|
||||
ISequentialOutStream **outStream, Int32 askExtractMode)
|
||||
{
|
||||
*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;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//se necesita conocer el tama<6D>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)
|
||||
newFileSize = ConvertPropVariantToUInt64(prop);
|
||||
}
|
||||
|
||||
//No hay que crear ning<6E>n fichero, ni directorios intermedios
|
||||
/*{
|
||||
// Create folders for file
|
||||
int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);
|
||||
if (slashPos >= 0)
|
||||
NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));
|
||||
}
|
||||
|
||||
UString fullProcessedPath = _directoryPath + _filePath;
|
||||
_diskFilePath = fullProcessedPath;
|
||||
*/
|
||||
if (_processedFileInfo.isDir)
|
||||
{
|
||||
//NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*NFile::NFind::CFileInfoW fi;
|
||||
if (fi.Find(fullProcessedPath))
|
||||
{
|
||||
if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
|
||||
{
|
||||
qDebug() <<(UString(kCantDeleteOutputFile) + fullProcessedPath);
|
||||
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;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 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;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)
|
||||
{
|
||||
switch(operationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kOK:
|
||||
if(all && !_processedFileInfo.isDir)
|
||||
{
|
||||
QByteArray rawData((char *)data,newFileSize);
|
||||
MidFree(data);
|
||||
data = 0;
|
||||
if(delegate != 0)
|
||||
delegate->fileExtracted(_index,rawData);
|
||||
else
|
||||
{
|
||||
allFiles.append(rawData);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
NumErrors++;
|
||||
qDebug() << " ";
|
||||
switch(operationResult)
|
||||
{
|
||||
case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
|
||||
if(delegate != 0)
|
||||
delegate->unknownError(_index);
|
||||
qDebug() << kUnsupportedMethod;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kCRCError:
|
||||
if(delegate != 0)
|
||||
delegate->crcError(_index);
|
||||
qDebug() << kCRCFailed;
|
||||
break;
|
||||
case NArchive::NExtract::NOperationResult::kDataError:
|
||||
if(delegate != 0)
|
||||
delegate->unknownError(_index);
|
||||
qDebug() << kDataError;
|
||||
break;
|
||||
default:
|
||||
if(delegate != 0)
|
||||
delegate->unknownError(_index);
|
||||
qDebug() << kUnknownError;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (_outFileStream != NULL)
|
||||
{
|
||||
if (_processedFileInfo.MTimeDefined)
|
||||
_outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);
|
||||
RINOK(_outFileStreamSpec->Close());
|
||||
}
|
||||
_outFileStream.Release();
|
||||
if (_extractMode && _processedFileInfo.AttribDefined)
|
||||
NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);*/
|
||||
//qDebug() << endl;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CArchiveExtractCallback::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);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,14 +1,14 @@
|
||||
#ifndef EXTRACT_DELEGATE_H
|
||||
#define EXTRACT_DELEGATE_H
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
class ExtractDelegate
|
||||
{
|
||||
public:
|
||||
virtual void fileExtracted(int index, const QByteArray & rawData) = 0;
|
||||
virtual void crcError(int index) = 0;
|
||||
virtual void unknownError(int index) = 0;
|
||||
};
|
||||
|
||||
#ifndef EXTRACT_DELEGATE_H
|
||||
#define EXTRACT_DELEGATE_H
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
class ExtractDelegate
|
||||
{
|
||||
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
|
@ -1,54 +1,54 @@
|
||||
#ifndef OPEN_CALLBACKS_H
|
||||
#define OPEN_CALLBACKS_H
|
||||
|
||||
#include "7z_includes.h"
|
||||
#include <QDebug>
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Archive Open callback class
|
||||
|
||||
|
||||
class CArchiveOpenCallback:
|
||||
public IArchiveOpenCallback,
|
||||
public ICryptoGetTextPassword,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
|
||||
|
||||
STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);
|
||||
STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);
|
||||
|
||||
STDMETHOD(CryptoGetTextPassword)(BSTR *password);
|
||||
|
||||
bool PasswordIsDefined;
|
||||
UString Password;
|
||||
|
||||
CArchiveOpenCallback() : PasswordIsDefined(false) {}
|
||||
};
|
||||
|
||||
STDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveOpenCallback::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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef OPEN_CALLBACKS_H
|
||||
#define OPEN_CALLBACKS_H
|
||||
|
||||
#include "7z_includes.h"
|
||||
#include <QDebug>
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Archive Open callback class
|
||||
|
||||
|
||||
class CArchiveOpenCallback:
|
||||
public IArchiveOpenCallback,
|
||||
public ICryptoGetTextPassword,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
|
||||
|
||||
STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);
|
||||
STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);
|
||||
|
||||
STDMETHOD(CryptoGetTextPassword)(BSTR *password);
|
||||
|
||||
bool PasswordIsDefined;
|
||||
UString Password;
|
||||
|
||||
CArchiveOpenCallback() : PasswordIsDefined(false) {}
|
||||
};
|
||||
|
||||
STDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CArchiveOpenCallback::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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,133 +1,133 @@
|
||||
#include "compressed_archive.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
|
||||
#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)
|
||||
{
|
||||
//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;
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
QList<QString> CompressedArchive::getFileNames()
|
||||
{
|
||||
return fileNames;
|
||||
}
|
||||
|
||||
bool CompressedArchive::isValid()
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
|
||||
bool CompressedArchive::toolsLoaded()
|
||||
{
|
||||
//for backwards compatibilty
|
||||
return tools;
|
||||
}
|
||||
|
||||
int CompressedArchive::getNumFiles()
|
||||
{
|
||||
return numFiles;
|
||||
}
|
||||
|
||||
void CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
|
||||
{
|
||||
if (indexes.isEmpty())
|
||||
return;
|
||||
|
||||
QByteArray buffer;
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
#include "compressed_archive.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
|
||||
#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)
|
||||
{
|
||||
//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;
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
QList<QString> CompressedArchive::getFileNames()
|
||||
{
|
||||
return fileNames;
|
||||
}
|
||||
|
||||
bool CompressedArchive::isValid()
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
|
||||
bool CompressedArchive::toolsLoaded()
|
||||
{
|
||||
//for backwards compatibilty
|
||||
return tools;
|
||||
}
|
||||
|
||||
int CompressedArchive::getNumFiles()
|
||||
{
|
||||
return numFiles;
|
||||
}
|
||||
|
||||
void CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
|
||||
{
|
||||
if (indexes.isEmpty())
|
||||
return;
|
||||
|
||||
QByteArray buffer;
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
@ -1,37 +1,37 @@
|
||||
#ifndef COMPRESSED_ARCHIVE_H
|
||||
#define COMPRESSED_ARCHIVE_H
|
||||
|
||||
#include <QObject>
|
||||
#include "extract_delegate.h"
|
||||
extern"C" {
|
||||
#include <unarr.h>
|
||||
}
|
||||
|
||||
class CompressedArchive : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // COMPRESSED_ARCHIVE_H
|
||||
#ifndef COMPRESSED_ARCHIVE_H
|
||||
#define COMPRESSED_ARCHIVE_H
|
||||
|
||||
#include <QObject>
|
||||
#include "extract_delegate.h"
|
||||
extern"C" {
|
||||
#include <unarr.h>
|
||||
}
|
||||
|
||||
class CompressedArchive : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // COMPRESSED_ARCHIVE_H
|
||||
|
@ -1,15 +1,15 @@
|
||||
#ifndef EXTRACT_DELEGATE_H
|
||||
#define EXTRACT_DELEGATE_H
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#ifndef EXTRACT_DELEGATE_H
|
||||
#define EXTRACT_DELEGATE_H
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif //EXTRACT_DELEGATE_H
|
Reference in New Issue
Block a user