//CFTTFile - [2020-04-13 11:57:46]
#ifndef _CFTTFILE_H_
#define _CFTTFILE_H_

#include "CFTTAsyncEvent.h"

/*
0026584E CFTTFile::~CFTTFile()
00265850 CFTTFile::~CFTTFile()
00221D2E CFTTFile::GetMemoryMappedPos()
002639DC CFTTFile::ReadAsync(void *,int64,int64,void *,CFTTAsyncEvent<TFTTFileAsyncEventData> *)
00221D42 CFTTFile::RequestFlushWrites()
00221D32 CFTTFile::UseBufferedAccess()
00263A24 CFTTFile::WriteAsync(void const*,int64,int64,void *,CFTTAsyncEvent<TFTTFileAsyncEventData> *)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
00329994
_ZTV13CFTTFile
  CFTTFile::~CFTTFile()
  CFTTFile::~CFTTFile()
  CFTTFile::Read(void *,int64)
  CFTTFile::Write(void const*,int64)
  CFTTFile::GetPos()
  CFTTFile::Seek(int64,int)
  CFTTFile::GetAttributes()
  CFTTFile::Close()
  CFTTFile::IsOpen()
  CFTTFile::ReadAsync(void *,int64,int64,void *,CFTTAsyncEvent<TFTTFileAsyncEventData> *)
  CFTTFile::WriteAsync(void const*,int64,int64,void *,CFTTAsyncEvent<TFTTFileAsyncEventData> *)
  CFTTFile::GetAsyncHandler()
  CFTTFile::GetModeFlags()
  CFTTFile::GetMemoryMappedPos()
  CFTTFile::UseBufferedAccess()
  CFTTFile::RequestFlushWrites()

CFTTFile_ZLib  0x60
CFTTFile_PAK   0x28
CFTTFile_ROM   0x20
//0x34
*/
//-------------------------------------------------------------------------------------------------
class CFTTFile;
class CFTTFile_AsyncHandler;
class CFTTFileSystem_Android;
class CFTTFileSystem_PAK;
//-------------------------------------------------------------------------------------------------
struct TFTTFileAttributes {
  int64 filesize_0;
  uint64 ullTime_8;
};
//-------------------------------------------------------------------------------------------------
enum EFTTError {
  EFTTError_0 = 0,
  EFTTError_1,
  EFTTError_2,
  EFTTError_3,
  EFTTError_4,
  EFTTError_5,
  EFTTError_6,
  EFTTError_7,
  EFTTError_8,
  EFTTError_9,
  EFTTError_10,
  EFTTError_11,
  EFTTError_12,
  EFTTError_13,
  EFTTError_14,
  EFTTError_15,
  EFTTError_16,
  EFTTError_17,
  EFTTError_18,
  EFTTError_19,
  EFTTError_20,
};
//-------------------------------------------------------------------------------------------------
//0x28
struct TFTTFileAsyncEventData {
  CFTTFile *pCFTTFile_0;
  void *buf_4;
  int64 pos_8;
  int64 len_10;
  void *pEventData_18;
  bool bWrite_1C;
  int64 result_len_20;
  //int field_24;
};
//-------------------------------------------------------------------------------------------------
//0x18
struct TFTTPakFile {
  union {
    int offset_0;  //field_24[] index offset
    char *pBuf_0;
  } pf_0;
  uint file_len_4;    //TFTTFileAttributes len file_len_4
  int file_offset_8;  //pak内偏移 file_offset_8
  uint zlib_C;        //压缩标志 这行代码能看出来 .text:00221872   LDRB R0, [R5,#0xC] @ R0 = pPakFile_20[index].field_C
  uint dTime_10;      //TFTTFileAttributes
  int field_14;
};
//-------------------------------------------------------------------------------------------------
//TFTTPakDirectory struct_0x14 0x14
struct TFTTPakDirectory {
  union {
    int offset_0;  //field_24[] index offset
    char *pBuf_0;
  } pd_0;

  int field_4;
  int field_8;

  union {
    int index_C;
    TFTTPakFile *pPakFile_C;
  } pd_C;

  union {
    int index_10;  //pPakFile_20 index
    TFTTPakDirectory *pPAKDir_10;
  } pd_10;
};
//-------------------------------------------------------------------------------------------------
class CFTTFile {
public:
  virtual ~CFTTFile();  //0026584E 00265850
  virtual int64 Read(void *buf, int64 buflen) = 0;
  virtual int64 Write(void const *buf, int64 buflen) = 0;
  virtual int64 GetPos() = 0;
  virtual int64 Seek(int64 dpos, int whence) = 0;
  virtual TFTTFileAttributes *GetAttributes() = 0;
  virtual bool Close() = 0;
  virtual bool IsOpen() = 0;
  virtual int ReadAsync(void *a3, int64 a4, int64 a5, void *a6, CFTTAsyncEvent<TFTTFileAsyncEventData> *a7);         //002639DC
  virtual int WriteAsync(void const *a3, int64 a4, int64 a5, void *a6, CFTTAsyncEvent<TFTTFileAsyncEventData> *a7);  //00263A24
  virtual CFTTFile_AsyncHandler *GetAsyncHandler() = 0;
  virtual int GetModeFlags() = 0;
  virtual void *GetMemoryMappedPos() const { return nullptr; };  //00221D2E
  virtual bool UseBufferedAccess() const;                        //00221D32
  virtual bool RequestFlushWrites() { return false; };           //00221D42

  EFTTError errCode_4;
};
//-------------------------------------------------------------------------------------------------
/*
002656F8 CFTTFile_AsyncHandler::~CFTTFile_AsyncHandler()

_ZTV23CFTTFile_AsyncImmediate
  CFTTFile_AsyncHandler::~CFTTFile_AsyncHandler()
  CFTTFile_AsyncImmediate::~CFTTFile_AsyncImmediate()
  CFTTFile_AsyncImmediate::ReadAsync(CFTTFile *,void *,      long long,long long,void *,CFTTAsyncEvent<TFTTFileAsyncEventData> *)
  CFTTFile_AsyncImmediate::WriteAsync(CFTTFile *,void const*,long long,long long,void *,CFTTAsyncEvent<TFTTFileAsyncEventData> *)
*/

class CFTTFile_AsyncHandler {
public:
  CFTTFile_AsyncHandler();
  virtual ~CFTTFile_AsyncHandler();
  virtual bool ReadAsync(CFTTFile *pCFTTFile,
                         void *pbuf,
                         int64 read_pos,
                         int64 read_len,
                         void *pDat,
                         CFTTAsyncEvent<TFTTFileAsyncEventData> *pEventData) = 0;

  virtual bool WriteAsync(CFTTFile *pCFTTFile,
                          void const *pbuf,
                          int64 write_pos,
                          int64 write_len,
                          void *pDat,
                          CFTTAsyncEvent<TFTTFileAsyncEventData> *pEventData) = 0;
};

/*
CFTTFile
CFTTFile_Buffered

CFTTFile_Android
CFTTFile_AndroidDocs
CFTTFile_AndroidMemMap
CFTTFile_PAK
CFTTFile_RAM
CFTTFile_ROM
CFTTFile_ZLib

CFTTFile_AsyncHandler
CFTTFile_AsyncImmediate
CFTTFile_AsyncQueue

CFTTFileIterator_Android
CFTTFileIterator_PAK

CFTTFileSystem
CFTTFileSystem_APKX
CFTTFileSystem_Android
CFTTFileSystem_PAK

 union {
    bool bOpen_8;  //.text:0026C266   STRB R0, [R4,#8] 这儿表时存在 bOpen_8 变量
                   //.text:0026CCBE   STRB R0, [R4,#8] @ uf_8.bOpen_8 = true;
    CFTTFile *pFile_8;

    //描述CFTTFile_ROM 文件当前位置
    int32_t len_8;  //void* CFTTFile_ROM::GetMemoryMappedPos() 这个函数证明存在len_8 这个成员变量
    TFTTPakFile *pPakFile_8;
  } uf_8;

  union {
    int mod_C;              //CFTTFile_PAK -> current pos
    z_streamp z_streamp_C;  //CFTTFile_ZLib -> zlib streamp
  } uf_C;

  union {
    int align;
    int64 len_10;
    struct {
      TFTTFileAttributes *pArrt_10;  //.text:00264B88 020   STR R0, [R4,#0x10] 这儿证明枚举中存在这个变量
      bool isCopyBuf_14;
      bool isCopyAttr_15;
    } rom_attr_info;

    struct {
      CFTTFileSystem_Android *pFileSystem_Android;
      int field_14;
    } android_info;

    struct {
      int field_10;
      CFTTFileSystem_Android *pFileSystem_14;
    } android_docs_info;

    struct {
      CFTTFileSystem_PAK *pFileSystem_PAK;
    } pak;
  } uf_10;


*/

#endif  //_CFTTFILE_H_