#pragma once

#include "../KbUnArc.h"

class KbUnLha : public KbUnArc
{
private:
    struct LzhInfo
    {
        KPI_FILEINFO fi;
        UINT64  qwCompressedOffset;//圧縮データの開始位置
        wchar_t szMethod[6];         //圧縮法(-lh0-, -lh5-, etc...) (fi.cszMethod==szMethod)
        wchar_t pszFileName[1];      //格納ファイル名(fi.cszFileName==pszFileName)
    };
    HANDLE     m_hHeap;
    IKpiFile  *m_pFile;
    LzhInfo  **m_ppLzhInfo;
    DWORD      m_dwCount;
    DWORD      m_dwCapacity;

    LzhInfo* __fastcall ReadLzhHeader(void);
    virtual ~KbUnLha(void);
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);

    KbUnLha(UnArcConfig *pConfig);
};
