#pragma once

#include "../KbUnArc.h"
#include "unrarsrc/dll.hpp"
//---------------------------------------------------------------------------
class KbUnRar:public KbUnArc
{
private:
    struct RarInfo
    {
        KPI_FILEINFO fi;
        BYTE    *pData;
        UINT64  qwDataSize;
        wchar_t  szFileName[1];
    };
    IKpiFile   *m_pFile;
    HANDLE      m_hArc;
    RAROpenArchiveDataEx m_ArchiveData;
    HANDLE      m_hHeap;
    RarInfo   **m_ppRarInfo;
    DWORD       m_dwCount;
    DWORD       m_dwCapacity;
    UINT64      m_qwTotalSize;
    virtual ~KbUnRar(void);
    static int CALLBACK ProcessDataProc(UINT msg, LPARAM UserData, LPARAM P1, LPARAM P2);
    int __fastcall ProcessDataProcInternal(UINT msg, LPARAM P1, LPARAM P2);
public:
    BOOL __fastcall Open(IKpiFile *pFile, IKpiFolder *pFolder, const wchar_t *cszOutputPath);

    BOOL WINAPI GetArchiveInfo(const KPI_ARCHIVEINFO **ppArchiveInfo);
    BOOL WINAPI EnumFileInfo(DWORD dwIndex, const KPI_FILEINFO **ppFileInfo);
    BOOL WINAPI Extract(DWORD dwIndex, IKpiFile **ppFile, UINT64 qwSize);

    KbUnRar(UnArcConfig *pConfig);
};
 