| 1 | 
           cycrow | 
           1 | 
           #ifndef __CATFILE_H__
  | 
        
        
            | 
            | 
           2 | 
           #define __CATFILE_H__
  | 
        
        
            | 
            | 
           3 | 
              | 
        
        
            | 
            | 
           4 | 
           #include "File.h"
  | 
        
        
            | 
            | 
           5 | 
           #include "File_IO.h"
  | 
        
        
            | 
            | 
           6 | 
           #include "lists.h"
  | 
        
        
            | 
            | 
           7 | 
           #include "spkdll.h"
  | 
        
        
            | 
            | 
           8 | 
              | 
        
        
            | 
            | 
           9 | 
           enum {CATERR_NONE, CATERR_NODATFILE, CATERR_NOCATFILE, CATERR_FILEEMPTY, CATERR_READCAT, CATERR_DECRYPT, CATERR_MISMATCH, CATERR_NOFILE, CATERR_CANTREAD, CATERR_CANTCREATEDIR, CATERR_INVALIDDEST,
  | 
        
        
           | 51 | 
           cycrow | 
           10 | 
           		CATERR_CREATED, CATERR_MALLOC};
  | 
        
        
           | 1 | 
           cycrow | 
           11 | 
           enum {CATFILE_NONE, CATFILE_READ, CATFILE_DECYPTED};
  | 
        
        
            | 
            | 
           12 | 
           enum {CATREAD_JUSTCONTENTS, CATREAD_CAT, CATREAD_CATDECRYPT, CATREAD_DAT};
  | 
        
        
            | 
            | 
           13 | 
              | 
        
        
            | 
            | 
           14 | 
           typedef struct SInCatFile {
  | 
        
        
           | 41 | 
           cycrow | 
           15 | 
           	struct SInCatFile () { lSize = 0; sData = 0; lOffset = 0; bDelete = false; bDecrypted = false; }
  | 
        
        
           | 1 | 
           cycrow | 
           16 | 
           	CyString sFile;
  | 
        
        
            | 
            | 
           17 | 
           	size_t lSize;
  | 
        
        
            | 
            | 
           18 | 
           	unsigned char  *sData;
  | 
        
        
            | 
            | 
           19 | 
           	size_t lOffset;
  | 
        
        
            | 
            | 
           20 | 
           	bool	bDelete;
  | 
        
        
           | 41 | 
           cycrow | 
           21 | 
           	bool	bDecrypted;
  | 
        
        
           | 1 | 
           cycrow | 
           22 | 
           } SInCatFile;
  | 
        
        
            | 
            | 
           23 | 
              | 
        
        
            | 
            | 
           24 | 
           unsigned char SPKEXPORT *PCKData ( unsigned char *data, size_t oldsize, size_t *newsize, bool bXor = true );
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
           class SPKEXPORT CCatFile
  | 
        
        
            | 
            | 
           27 | 
           {
  | 
        
        
            | 
            | 
           28 | 
           public:
  | 
        
        
           | 41 | 
           cycrow | 
           29 | 
           	enum CatFiletype {
  | 
        
        
            | 
            | 
           30 | 
           		FILETYPE_PLAIN,
  | 
        
        
            | 
            | 
           31 | 
           		FILETYPE_DEFLATE,
  | 
        
        
            | 
            | 
           32 | 
           		FILETYPE_PCK,
  | 
        
        
            | 
            | 
           33 | 
           	};
  | 
        
        
            | 
            | 
           34 | 
              | 
        
        
            | 
            | 
           35 | 
           public:
  | 
        
        
           | 1 | 
           cycrow | 
           36 | 
           	static CyString PckChangeExtension ( CyString f );
  | 
        
        
            | 
            | 
           37 | 
           	static CyString RenameFileExtension(SInCatFile *f);
  | 
        
        
            | 
            | 
           38 | 
           	static bool IsAddonDir(CyString dir);
  | 
        
        
           | 58 | 
           cycrow | 
           39 | 
           	static bool CheckPackedExtension(const Utils::String &sFilename);
  | 
        
        
           | 1 | 
           cycrow | 
           40 | 
              | 
        
        
            | 
            | 
           41 | 
           	CCatFile ();
  | 
        
        
            | 
            | 
           42 | 
           	~CCatFile ();
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
           	int  Open ( CyString catfile, CyString addon, int readtype = CATREAD_CATDECRYPT, bool = true );
  | 
        
        
            | 
            | 
           45 | 
           	bool DecryptData ();
  | 
        
        
            | 
            | 
           46 | 
           	bool DecryptData ( unsigned char *data, size_t size );
  | 
        
        
            | 
            | 
           47 | 
           	void DecryptDAT(unsigned char *buffer, size_t size);
  | 
        
        
           | 41 | 
           cycrow | 
           48 | 
           	void DecryptDAT(SInCatFile *pFile);
  | 
        
        
           | 1 | 
           cycrow | 
           49 | 
           	bool ReadFiles ();
  | 
        
        
            | 
            | 
           50 | 
           	void LoadDatFile ();
  | 
        
        
            | 
            | 
           51 | 
           	CyString GetCatFilename() { return m_fCatFile.GetFullFilename(); }
  | 
        
        
            | 
            | 
           52 | 
              | 
        
        
            | 
            | 
           53 | 
           	bool CheckExtensionPck ( CyString filename );
  | 
        
        
            | 
            | 
           54 | 
           	CyStringList *GetTShipsEntries();
  | 
        
        
            | 
            | 
           55 | 
           	CyString GetTShipsEntry(CyString id);
  | 
        
        
            | 
            | 
           56 | 
              | 
        
        
           | 53 | 
           cycrow | 
           57 | 
           	unsigned char *readData ( CyString filename, size_t *size );
  | 
        
        
            | 
            | 
           58 | 
           	unsigned char *readData ( SInCatFile *c, size_t *size );
  | 
        
        
           | 1 | 
           cycrow | 
           59 | 
           	SInCatFile *FindData ( CyString filename );
  | 
        
        
            | 
            | 
           60 | 
           	bool ReadFileToData ( CyString filename );
  | 
        
        
            | 
            | 
           61 | 
           	bool ReadFileToData ( SInCatFile *c );
  | 
        
        
            | 
            | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
           	bool MarkRemoveFile ( SInCatFile *f );
  | 
        
        
            | 
            | 
           64 | 
           	bool MarkRemoveFile ( CyString filename );
  | 
        
        
            | 
            | 
           65 | 
              | 
        
        
            | 
            | 
           66 | 
           	int GetEndOffset();
  | 
        
        
            | 
            | 
           67 | 
           	int GetNumFiles () { return m_lFiles.size(); }
  | 
        
        
            | 
            | 
           68 | 
           	SInCatFile *GetFile ( int num ) { return m_lFiles.Get(num); }
  | 
        
        
            | 
            | 
           69 | 
              | 
        
        
           | 41 | 
           cycrow | 
           70 | 
           	unsigned char *UnpackFile ( SInCatFile *c, size_t *size);
  | 
        
        
           | 1 | 
           cycrow | 
           71 | 
              | 
        
        
            | 
            | 
           72 | 
           	static bool Opened(int error, bool allowCreate = true);
  | 
        
        
            | 
            | 
           73 | 
           	bool RemoveFile ( SInCatFile *f );
  | 
        
        
            | 
            | 
           74 | 
           	bool RemoveFile ( CyString filename );
  | 
        
        
            | 
            | 
           75 | 
           	bool WriteCatFile ();
  | 
        
        
           | 52 | 
           cycrow | 
           76 | 
           	bool AppendFile(const Utils::String &sFilename, const Utils::String &to, bool pck = true, bool bXor = true, Utils::String *sChangeTo = NULL);
  | 
        
        
           | 1 | 
           cycrow | 
           77 | 
           	bool AppendData ( unsigned char *data, size_t size, CyString to, bool pck = true, bool bXor = true );
  | 
        
        
            | 
            | 
           78 | 
           	bool AddData ( CyString catfile, unsigned char *data, size_t size, CyString to, bool pck = true, bool create = true );
  | 
        
        
            | 
            | 
           79 | 
              | 
        
        
            | 
            | 
           80 | 
           	CyString ChangeExtension ( CyString f );
  | 
        
        
            | 
            | 
           81 | 
           	CLinkList<SInCatFile> *GetFiles() { return &m_lFiles; }
  | 
        
        
            | 
            | 
           82 | 
              | 
        
        
            | 
            | 
           83 | 
           	bool ExtractFile ( CyString filename, CyString to = NullString, bool preserve = false );
  | 
        
        
            | 
            | 
           84 | 
           	bool ExtractFile ( SInCatFile *f, CyString to = NullString, bool preserve = false );
  | 
        
        
            | 
            | 
           85 | 
           	bool ExtractAll (CyString dir);
  | 
        
        
            | 
            | 
           86 | 
              | 
        
        
            | 
            | 
           87 | 
           	void ClearError () { m_iError = CATERR_NONE; m_sError = ""; }
  | 
        
        
            | 
            | 
           88 | 
           	int Error () { return m_iError; }
  | 
        
        
            | 
            | 
           89 | 
           	CyString ErrorString() { return m_sError; }
  | 
        
        
            | 
            | 
           90 | 
           	CyString GetErrorString ();
  | 
        
        
            | 
            | 
           91 | 
              | 
        
        
            | 
            | 
           92 | 
           	bool WriteFromCat ( CyString catfile, CyString file );
  | 
        
        
            | 
            | 
           93 | 
           	bool WriteFromCat ( CCatFile *fcat, CyString file );
  | 
        
        
            | 
            | 
           94 | 
              | 
        
        
            | 
            | 
           95 | 
           	void FindFiles(CyStringList *list, CyString filemask);
  | 
        
        
            | 
            | 
           96 | 
              | 
        
        
           | 41 | 
           cycrow | 
           97 | 
              | 
        
        
           | 1 | 
           cycrow | 
           98 | 
           private:
  | 
        
        
           | 41 | 
           cycrow | 
           99 | 
           	int _checkFiletype(const unsigned char *pBuffer, int iSize);
  | 
        
        
           | 1 | 
           cycrow | 
           100 | 
           	void RemoveData ();
  | 
        
        
            | 
            | 
           101 | 
              | 
        
        
            | 
            | 
           102 | 
           	CFileIO m_fCatFile;
  | 
        
        
            | 
            | 
           103 | 
           	CFileIO m_fDatFile;
  | 
        
        
            | 
            | 
           104 | 
              | 
        
        
            | 
            | 
           105 | 
           	unsigned char *m_sData;
  | 
        
        
            | 
            | 
           106 | 
           	size_t m_lSize;
  | 
        
        
            | 
            | 
           107 | 
           	char m_iDataType;
  | 
        
        
            | 
            | 
           108 | 
              | 
        
        
            | 
            | 
           109 | 
           	CLinkList<SInCatFile> m_lFiles;
  | 
        
        
            | 
            | 
           110 | 
           	CyString m_sError;
  | 
        
        
            | 
            | 
           111 | 
           	CyString m_sAddonDir;
  | 
        
        
            | 
            | 
           112 | 
              | 
        
        
            | 
            | 
           113 | 
           	int m_iError;
  | 
        
        
            | 
            | 
           114 | 
              | 
        
        
            | 
            | 
           115 | 
           	bool m_bCreate;
  | 
        
        
           | 53 | 
           cycrow | 
           116 | 
           	bool m_bCatChanged;
  | 
        
        
           | 1 | 
           cycrow | 
           117 | 
           };
  | 
        
        
            | 
            | 
           118 | 
              | 
        
        
            | 
            | 
           119 | 
           #endif //__CATFILE_H__
  |