#define PAK_FILENAME_SIZE 160
#define PAK_FLAGS_FILENAME 0x00000020
#define DEFAULT_BUFFER 1000
#define FILE_TMP_BUFFER 4096

#define CLEAN_FILES 1
#define CLEAN_PAKINFO 2
#define CLEAN_TREE 4
#define CLEAN_ALL (CLEAN_FILES | CLEAN_PAKINFO | CLEAN_TREE)

#define SELECT_MODE_EXTRACT 1
#define SELECT_MODE_REPLACE 2

typedef struct
{
	DWORD fileExt;
	HANDLE containerFile; // The file that contains the file (INVALID_HANDLE_VALUE is pakFile)
	DWORD fileOffset;
	DWORD fileSize;
	DWORD pathId;
	DWORD fileId;
	DWORD titleId;
	DWORD reserved;
	DWORD flags;
	TCHAR inPakFileName[PAK_FILENAME_SIZE];
	BOOL niceName;
	DWORD displayId;
	TCHAR displayFileName[PAK_FILENAME_SIZE];
} PAKEntry;

typedef struct
{
	std::vector <PAKEntry> files;
	TCHAR pakFileName[DEFAULT_BUFFER];
	HANDLE pakFile;
	TCHAR pabFileName[DEFAULT_BUFFER];
	HANDLE pabFile;
	BOOL isBigEndian;
	DWORD platform;
} PAKReturn;

typedef struct
{
	DWORD qbKey;
	DWORD pointerString;
} DBGBinEntry;

BOOL ReadPakFiles(HWND hDlg, PAKReturn *pakInfo);
BOOL MakeTree(HINSTANCE hInstance, HWND hDlg, PAKReturn *pakInfo);
BOOL ExploreSelectedItem(HWND hDlg, PAKReturn *pakInfo, DWORD mode);
BOOL FreePakInfo(HWND hDlg, PAKReturn *pakInfo, DWORD cleanFlags);
BOOL ExtractSingleFile(HWND hDlg, PAKReturn *pakInfo, LPARAM numItem);
BOOL ReplaceSingleFile(HWND hDlg, PAKReturn *pakInfo, LPARAM numItem);
BOOL SavePakFiles(HWND hDlg, PAKReturn *pakInfo);
BOOL ReOpenPakAndPab(HWND hDlg, PAKReturn *pakInfo);
int searchQbKeyDbg(const void *a, const void *b);
BOOL ReadDbgInfo(HWND hDlg, PAKReturn *pakInfo);