Subversion Repositories spk

Rev

Rev 101 | Rev 125 | 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; }
124 cycrow 16
	Utils::String sFile;
1 cycrow 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:
124 cycrow 36
	static Utils::String PckChangeExtension(const Utils::String &f);
37
	static Utils::String RenameFileExtension(SInCatFile *f);
1 cycrow 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
 
124 cycrow 53
	bool checkExtensionPck(const Utils::String &filename) const;
1 cycrow 54
 
53 cycrow 55
	unsigned char *readData ( CyString filename, size_t *size );
56
	unsigned char *readData ( SInCatFile *c, size_t *size );
124 cycrow 57
	SInCatFile *FindData(CyString filename);
58
	SInCatFile *findData(const Utils::String &filename) const;
1 cycrow 59
	bool ReadFileToData ( CyString filename );
60
	bool ReadFileToData ( SInCatFile *c );
61
 
62
	bool MarkRemoveFile ( SInCatFile *f );
63
	bool MarkRemoveFile ( CyString filename );
64
 
65
	int GetEndOffset();
124 cycrow 66
	size_t GetNumFiles() const;
67
	SInCatFile *GetFile(unsigned int num) const;
1 cycrow 68
 
41 cycrow 69
	unsigned char *UnpackFile ( SInCatFile *c, size_t *size);
1 cycrow 70
 
71
	static bool Opened(int error, bool allowCreate = true);
124 cycrow 72
	bool removeFile(SInCatFile *f);
73
	bool removeFile(const Utils::String &filename);
1 cycrow 74
	bool WriteCatFile ();
52 cycrow 75
	bool AppendFile(const Utils::String &sFilename, const Utils::String &to, bool pck = true, bool bXor = true, Utils::String *sChangeTo = NULL);
1 cycrow 76
	bool AppendData ( unsigned char *data, size_t size, CyString to, bool pck = true, bool bXor = true );
77
	bool AddData ( CyString catfile, unsigned char *data, size_t size, CyString to, bool pck = true, bool create = true );
78
 
79
	CyString ChangeExtension ( CyString f );
124 cycrow 80
	std::vector<SInCatFile *> *GetFiles() const;
1 cycrow 81
 
82
	bool ExtractFile ( CyString filename, CyString to = NullString, bool preserve = false );
83
	bool ExtractFile ( SInCatFile *f, CyString to = NullString, bool preserve = false );
84
	bool ExtractAll (CyString dir);
85
 
124 cycrow 86
	void clearError () { m_iError = CATERR_NONE; _sError.clear(); }
87
	int error () const { return m_iError; }
88
	const Utils::String &errorString() const { return _sError; }
89
	Utils::String getErrorString () const;
85 cycrow 90
 
91
	const Utils::String &internalDatFilename() const;
124 cycrow 92
	const Utils::String &catFilename() const { return m_fCatFile.fullFilename(); }
93
	const Utils::String &datFilename() const { return m_fDatFile.fullFilename(); }
85 cycrow 94
 
1 cycrow 95
	bool WriteFromCat ( CyString catfile, CyString file );
96
	bool WriteFromCat ( CCatFile *fcat, CyString file );
97
 
98
	void FindFiles(CyStringList *list, CyString filemask);
99
 
41 cycrow 100
 
1 cycrow 101
private:
85 cycrow 102
	void _clearFiles();
41 cycrow 103
	int _checkFiletype(const unsigned char *pBuffer, int iSize);
1 cycrow 104
	void RemoveData ();
105
 
106
	CFileIO m_fCatFile;
107
	CFileIO m_fDatFile;
108
 
109
	unsigned char *m_sData;
110
	size_t m_lSize;
111
	char m_iDataType;
112
 
124 cycrow 113
	std::vector<SInCatFile *> *_lFiles;
114
	Utils::String _sError;
115
	Utils::String _sAddonDir;
1 cycrow 116
 
85 cycrow 117
	Utils::String _sReadFilename;
1 cycrow 118
	int m_iError;
119
 
120
	bool m_bCreate;
53 cycrow 121
	bool m_bCatChanged;
1 cycrow 122
};
123
 
124
#endif //__CATFILE_H__