Subversion Repositories spk

Rev

Rev 85 | Rev 124 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 {
65 cycrow 15
	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
 
85 cycrow 41
public:
1 cycrow 42
	CCatFile ();
43
	~CCatFile ();
44
 
45
	int  Open ( CyString catfile, CyString addon, int readtype = CATREAD_CATDECRYPT, bool = true );
46
	bool DecryptData ();
47
	bool DecryptData ( unsigned char *data, size_t size );
48
	void DecryptDAT(unsigned char *buffer, size_t size);
41 cycrow 49
	void DecryptDAT(SInCatFile *pFile);
85 cycrow 50
	bool readFiles ();
1 cycrow 51
	void LoadDatFile ();
52
 
53
	bool CheckExtensionPck ( CyString filename );
54
 
53 cycrow 55
	unsigned char *readData ( CyString filename, size_t *size );
56
	unsigned char *readData ( SInCatFile *c, size_t *size );
1 cycrow 57
	SInCatFile *FindData ( CyString filename );
58
	bool ReadFileToData ( CyString filename );
59
	bool ReadFileToData ( SInCatFile *c );
60
 
61
	bool MarkRemoveFile ( SInCatFile *f );
62
	bool MarkRemoveFile ( CyString filename );
63
 
64
	int GetEndOffset();
65
	int GetNumFiles () { return m_lFiles.size(); }
66
	SInCatFile *GetFile ( int num ) { return m_lFiles.Get(num); }
67
 
41 cycrow 68
	unsigned char *UnpackFile ( SInCatFile *c, size_t *size);
1 cycrow 69
 
70
	static bool Opened(int error, bool allowCreate = true);
71
	bool RemoveFile ( SInCatFile *f );
72
	bool RemoveFile ( CyString filename );
73
	bool WriteCatFile ();
52 cycrow 74
	bool AppendFile(const Utils::String &sFilename, const Utils::String &to, bool pck = true, bool bXor = true, Utils::String *sChangeTo = NULL);
1 cycrow 75
	bool AppendData ( unsigned char *data, size_t size, CyString to, bool pck = true, bool bXor = true );
76
	bool AddData ( CyString catfile, unsigned char *data, size_t size, CyString to, bool pck = true, bool create = true );
77
 
78
	CyString ChangeExtension ( CyString f );
79
	CLinkList<SInCatFile> *GetFiles() { return &m_lFiles; }
80
 
81
	bool ExtractFile ( CyString filename, CyString to = NullString, bool preserve = false );
82
	bool ExtractFile ( SInCatFile *f, CyString to = NullString, bool preserve = false );
83
	bool ExtractAll (CyString dir);
84
 
85
	void ClearError () { m_iError = CATERR_NONE; m_sError = ""; }
86
	int Error () { return m_iError; }
87
	CyString ErrorString() { return m_sError; }
88
	CyString GetErrorString ();
85 cycrow 89
 
90
	const Utils::String &internalDatFilename() const;
91
	const Utils::String &catFilename() { return m_fCatFile.fullFilename(); }
92
	const Utils::String &datFilename() { return m_fDatFile.fullFilename(); }
93
 
1 cycrow 94
	bool WriteFromCat ( CyString catfile, CyString file );
95
	bool WriteFromCat ( CCatFile *fcat, CyString file );
96
 
97
	void FindFiles(CyStringList *list, CyString filemask);
98
 
41 cycrow 99
 
1 cycrow 100
private:
85 cycrow 101
	void _clearFiles();
41 cycrow 102
	int _checkFiletype(const unsigned char *pBuffer, int iSize);
1 cycrow 103
	void RemoveData ();
104
 
105
	CFileIO m_fCatFile;
106
	CFileIO m_fDatFile;
107
 
108
	unsigned char *m_sData;
109
	size_t m_lSize;
110
	char m_iDataType;
111
 
112
	CLinkList<SInCatFile> m_lFiles;
113
	CyString m_sError;
114
	CyString m_sAddonDir;
115
 
85 cycrow 116
	Utils::String _sReadFilename;
1 cycrow 117
	int m_iError;
118
 
119
	bool m_bCreate;
53 cycrow 120
	bool m_bCatChanged;
1 cycrow 121
};
122
 
123
#endif //__CATFILE_H__