#pragma once

#include "kpi_impl.h"
#include "kpi_unarc.h"
//#include "kpi_file.h"
//////////////////////////////////////////////////////////////////////////////
class KbKpiPartialFile : public KbKpiFileImpl
{//IKpiFile の一部分だけを扱う。
 //無圧縮アーカイブなどで使う。
private:
    wchar_t   m_szFileName[MAX_PATH];
    IKpiFile *m_pFile;
    UINT64    m_qwCurrentPos;
    UINT64    m_qwStartOffset;
    UINT64    m_qwEndOffset;
    UINT64    m_qwSize;
    KbKpiPartialFile(void);
    virtual ~KbKpiPartialFile(void);
public:
    KbKpiPartialFile(IKpiFile *pFile, 
                     UINT64    qwStartOffset,
                     UINT64    qwEndOffset,
                     const wchar_t *cszFileName);
    //IKpiFile 派生
    DWORD  WINAPI GetFileName(wchar_t *pszName, DWORD dwSize);
    BOOL   WINAPI GetRealFileW(const wchar_t **ppszFileName);
    BOOL   WINAPI GetBuffer(const BYTE **ppBuffer, size_t *pstSize);
    DWORD  WINAPI Read(void *pBuffer, DWORD dwSize);
    UINT64 WINAPI Seek(__int64 i64Pos, DWORD dwOrigin);
    UINT64 WINAPI GetSize(void);
};
//////////////////////////////////////////////////////////////////////////////
class KbUnArc: public KbKpiUnknownImpl<IKpiUnArc>
{
public:
    struct UnArcConfig {
        UINT64 qwLimitArc;  //アーカイブファイルのサイズ制限
        UINT64 qwLimitTotal;//全展開後のサイズ制限
        IKpiConfig *pConfig;
    };
    //static size_t __fastcall GetLimitSizeToMemory(void);//メモリ上に展開する最大サイズ
    virtual BOOL __fastcall Open(IKpiFile *pFile, IKpiFolder *pFolder, const wchar_t *cszTempPath) = 0;
protected:
    wchar_t     m_szOutputPath[MAX_PATH];
    KPI_ARCHIVEINFO m_ArchiveInfo;
    UnArcConfig m_Config;
    KbUnArc(UnArcConfig *pArcConfig);
    virtual ~KbUnArc(void);
    DWORD WINAPI UpdateConfig(void *pvReserved){return 0;}
};
//////////////////////////////////////////////////////////////////////////////
bool __fastcall kbDirectoryExists(const wchar_t* cszName);
bool __fastcall kbFileExists(const wchar_t* cszName);
bool __fastcall kbCreateDir(const wchar_t *cszPath);
void __fastcall kbSlashToBSlash(wchar_t *pszPath);
void __fastcall kbBSlashToSlash(wchar_t *pszPath);
