Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#ifndef __CATFILE_H__
#define __CATFILE_H__
#include "File.h"
#include "File_IO.h"
#include "lists.h"
#include "spkdll.h"
enum {CATERR_NONE, CATERR_NODATFILE, CATERR_NOCATFILE, CATERR_FILEEMPTY, CATERR_READCAT, CATERR_DECRYPT, CATERR_MISMATCH, CATERR_NOFILE, CATERR_CANTREAD, CATERR_CANTCREATEDIR, CATERR_INVALIDDEST,
CATERR_CREATED};
enum {CATFILE_NONE, CATFILE_READ, CATFILE_DECYPTED};
enum {CATREAD_JUSTCONTENTS, CATREAD_CAT, CATREAD_CATDECRYPT, CATREAD_DAT};
typedef struct SInCatFile {
struct SInCatFile () { lSize = 0; sData = 0; lOffset = 0; bDelete = false; }
CyString sFile;
size_t lSize;
unsigned char *sData;
size_t lOffset;
bool bDelete;
} SInCatFile;
unsigned char SPKEXPORT *PCKData ( unsigned char *data, size_t oldsize, size_t *newsize, bool bXor = true );
class SPKEXPORT CCatFile
{
public:
static CyString PckChangeExtension ( CyString f );
static CyString RenameFileExtension(SInCatFile *f);
static bool IsAddonDir(CyString dir);
CCatFile ();
~CCatFile ();
int Open ( CyString catfile, CyString addon, int readtype = CATREAD_CATDECRYPT, bool = true );
bool DecryptData ();
bool DecryptData ( unsigned char *data, size_t size );
void DecryptDAT(unsigned char *buffer, size_t size);
bool ReadFiles ();
void LoadDatFile ();
CyString GetCatFilename() { return m_fCatFile.GetFullFilename(); }
bool CheckExtensionPck ( CyString filename );
bool CheckPackedExtension ( CyString filename );
CyStringList *GetTShipsEntries();
CyString GetTShipsEntry(CyString id);
unsigned char *ReadData ( CyString filename, size_t *size );
unsigned char *ReadData ( SInCatFile *c, size_t *size );
SInCatFile *FindData ( CyString filename );
bool ReadFileToData ( CyString filename );
bool ReadFileToData ( SInCatFile *c );
bool MarkRemoveFile ( SInCatFile *f );
bool MarkRemoveFile ( CyString filename );
int GetEndOffset();
int GetNumFiles () { return m_lFiles.size(); }
SInCatFile *GetFile ( int num ) { return m_lFiles.Get(num); }
unsigned char *UnpackFile ( SInCatFile *c, size_t *size, bool forcepck );
static bool Opened(int error, bool allowCreate = true);
bool RemoveFile ( SInCatFile *f );
bool RemoveFile ( CyString filename );
bool WriteCatFile ();
bool AppendFile ( CyString filename, CyString to, bool pck = true, bool bXor = true );
bool AppendData ( unsigned char *data, size_t size, CyString to, bool pck = true, bool bXor = true );
bool AddData ( CyString catfile, unsigned char *data, size_t size, CyString to, bool pck = true, bool create = true );
void WriteFiles ();
CyString ChangeExtension ( CyString f );
CLinkList<SInCatFile> *GetFiles() { return &m_lFiles; }
bool ExtractFile ( CyString filename, CyString to = NullString, bool preserve = false );
bool ExtractFile ( SInCatFile *f, CyString to = NullString, bool preserve = false );
bool ExtractAll (CyString dir);
void ClearError () { m_iError = CATERR_NONE; m_sError = ""; }
int Error () { return m_iError; }
CyString ErrorString() { return m_sError; }
CyString GetErrorString ();
bool WriteFromCat ( CyString catfile, CyString file );
bool WriteFromCat ( CCatFile *fcat, CyString file );
void FindFiles(CyStringList *list, CyString filemask);
private:
void RemoveData ();
CFileIO m_fCatFile;
CFileIO m_fDatFile;
unsigned char *m_sData;
size_t m_lSize;
char m_iDataType;
CLinkList<SInCatFile> m_lFiles;
CyString m_sError;
CyString m_sAddonDir;
int m_iError;
bool m_bCreate;
};
#endif //__CATFILE_H__