Subversion Repositories spk

Rev

Rev 83 | Rev 101 | 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
	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 ();
85 cycrow 91
 
92
	const Utils::String &internalDatFilename() const;
93
	const Utils::String &catFilename() { return m_fCatFile.fullFilename(); }
94
	const Utils::String &datFilename() { return m_fDatFile.fullFilename(); }
95
 
1 cycrow 96
	bool WriteFromCat ( CyString catfile, CyString file );
97
	bool WriteFromCat ( CCatFile *fcat, CyString file );
98
 
99
	void FindFiles(CyStringList *list, CyString filemask);
100
 
41 cycrow 101
 
1 cycrow 102
private:
85 cycrow 103
	void _clearFiles();
41 cycrow 104
	int _checkFiletype(const unsigned char *pBuffer, int iSize);
1 cycrow 105
	void RemoveData ();
106
 
107
	CFileIO m_fCatFile;
108
	CFileIO m_fDatFile;
109
 
110
	unsigned char *m_sData;
111
	size_t m_lSize;
112
	char m_iDataType;
113
 
114
	CLinkList<SInCatFile> m_lFiles;
115
	CyString m_sError;
116
	CyString m_sAddonDir;
117
 
85 cycrow 118
	Utils::String _sReadFilename;
1 cycrow 119
	int m_iError;
120
 
121
	bool m_bCreate;
53 cycrow 122
	bool m_bCatChanged;
1 cycrow 123
};
124
 
125
#endif //__CATFILE_H__