-
Notifications
You must be signed in to change notification settings - Fork 0
/
CREZ.h
executable file
·265 lines (226 loc) · 6.83 KB
/
CREZ.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* CREZ.h
*
* Created on: 19-02-2012
* Author: tomek
*/
#include <vector>
#include <wx/msgdlg.h> //wxMessageBox(...)
//#include <wx/gauge.h> //Gauge that represents a progress
#include <wx/file.h> //m_File
#ifndef CREZ_H_
#define CREZ_H_
typedef unsigned char byte;
class CREZFile {
public:
//file offset, file length, file date/time, extension, name
CREZFile(unsigned int _offset, unsigned int _length, unsigned int _datetime, wxString _ext, wxString _name);
CREZFile(wxString _name, wxString _ext, unsigned char* data, unsigned int nSize);
~CREZFile() {
if(pData != NULL)
{
delete[] pData;
}
}
void List(int nTab) {
for(int i=0; i<nTab; i++)
printf(" ");
printf("File: \"%s\" Offset: %d Length: %d\n", GetFullName().c_str(), GetOffset(), GetLength());
}
//======================
inline unsigned int GetOffset() const {
return nOffset;
}
inline unsigned int GetLength() const {
return nLength;
}
inline wxString GetExtension() const {
return strExtension;
}
inline wxString GetName() const {
return strName;
}
inline wxString GetFullName() const {
wxString strRes = GetName();
if(GetExtension() != "")
strRes += "." + GetExtension();
return strRes;
}
inline unsigned int GetDateTime() const {
return nDateTime;
}
inline unsigned char* GetData() const {
return pData;
}
inline void SetOffset(unsigned int _offset) {
nOffset = _offset;
}
inline void SetLength(unsigned int _length) {
nLength = _length;
}
inline void SetExtension(wxString _ext) {
strExtension = _ext;
}
inline void SetName(wxString _name) {
strName = _name;
}
inline void SetDateTime(unsigned int _datetime) {
nDateTime = _datetime;
}
inline void SetData(unsigned char* _pData) {
pData = _pData;
}
inline bool IsPatch() const {
return m_bIsPatch;
}
private:
unsigned int nOffset; //its offset in REZ file in bytes
unsigned int nLength; //the length of a file in bytes
unsigned int nDateTime; //unix stamp
unsigned char* pData; // the actual data of the file!
wxString strExtension;
wxString strName;
bool m_bIsPatch;
};
class CREZDir {
public:
//dir offset, dir length, dir date/time, name
CREZDir(unsigned int _offset, unsigned int _length, unsigned int _datetime, wxString _name);
CREZDir(wxString _name);
~CREZDir();
void List(int nTab) {
for(int i=0; i<nTab; i++)
printf(" ");
printf("Directory: \"%s\" Offset: %d Length: %d\n", GetName().c_str(), GetOffset(), GetLength());
for(int i=0; i<vFiles.size(); i++)
vFiles[i]->List(nTab+1);
for(int i=0; i<vDirectories.size(); i++)
vDirectories[i]->List(nTab+1);
}
unsigned int GetNodesCount() const {
unsigned int nResult = GetFilesCount();
nResult += GetDirectoriesCount();
for(int i=0; i<GetDirectoriesCount(); i++)
nResult += GetDirectory(i)->GetNodesCount();
return nResult;
}
inline int GetFilesCount() const {
return vFiles.size();
}
inline CREZFile* GetFile(int i) const {
if(i >= vFiles.size())
return NULL;
return vFiles[i];
}
inline void DeleteFile(int i) {
if(i >= vFiles.size())
return;
delete vFiles[i];
vFiles.erase(vFiles.begin()+i);
}
inline int GetDirectoriesCount() const {
return vDirectories.size();
}
inline CREZDir* GetDirectory(int i) const {
if(i >= vDirectories.size())
return NULL;
return vDirectories[i];
}
inline void DeleteDirectory(int i) {
if(i >= vDirectories.size())
return;
delete vDirectories[i];
vDirectories.erase(vDirectories.begin()+i);
}
/* bool AddFile(...) returns pointer of a file object if successfull
* uint nFileOffset
* uint nFileLength
* uint nDateTime
* char* sFileExt ( reversed! ) ( 4 bytes )
* string strFileName */
CREZFile* AddFile(unsigned int, unsigned int, unsigned int, wxString, wxString);
CREZFile* AddFile(wxString, wxString, unsigned char*, unsigned int);
/* bool AddDir(...) returns pointer of a directory object if successfull
* uint nDirOffset
* uint nDirLength
* uint nDateTime
* string strDirName */
CREZDir* AddDir(unsigned int, unsigned int, unsigned int, wxString);
CREZDir* AddDir(wxString);
inline unsigned int GetOffset() const {
return nOffset;
}
inline unsigned int GetLength() const {
return nLength;
}
inline wxString GetName() const {
return strName;
}
inline unsigned int GetDateTime() const {
return nDateTime;
}
inline void SetOffset(unsigned int _offset) {
nOffset = _offset;
}
inline void SetLength(unsigned int _length) {
nLength = _length;
}
inline void SetName(wxString _name) {
strName = _name;
}
inline void SetDateTime(unsigned int _datetime) {
nDateTime = _datetime;
}
private:
unsigned int nOffset; //its offset in REZ file in bytes
unsigned int nLength; //the length of a directory in bytes
unsigned int nDateTime; //unix stamp
wxString strName;
std::vector<CREZDir*> vDirectories;
std::vector<CREZFile*> vFiles;
};
//===================================================================================
class CREZBase {
public:
CREZBase(wxString);
virtual ~CREZBase() {
if(pRootDirectory != NULL)
delete pRootDirectory;
}
void UpdateFile(wxString strPath, unsigned char* data, unsigned int nSize);
void UpdateDir(wxString strPath);
bool Save(wxString strOutput);
CREZDir* pRootDirectory;
inline bool IsLoaded() const {
return (pRootDirectory != NULL);
}
/*
bool LoadREZ(std::string, bool bLoadData = true); //³aduje ca³y plik *.REZ do pamiêci. Je¿eli bLoadData, nie ³aduje plików z REZ'a do pamiêci
bool SaveREZ(std::string); //zapisuje strukturê danych w pamiêci w postaci pliku *.REZ na dysku
bool LoadDirectory(std::string, bool bLoadData = true); //³aduje do pamiêci ca³¹ scie¿kê z dysku ze wszystkimi folderami ( nawet pustymi ) i plikami
bool SaveDirectory(std::string); //zapisuje strukturê danych w pamiêci na dysku ( eksport )
*/
protected:
/*void SaveDirectory_ListFolder(CREZDir* pDir, wxString strDest);
void LoadDirectory_ListFolder(wxString strDir, wxString strFolderName, CREZDir* pParentDir);*/
void SaveREZ_WriteDirectory(CREZDir* pDir, wxFile*);
void LoadREZ_LoadDirectory(CREZDir* pDir);
// =============== progress bar data ===============
unsigned int m_nNodesRead;
wxFile m_File; //source file (BACKUP.REZ)
virtual void ProgressInitialize(){} //called in Save(...) method, before
virtual void ProgressUpdate(){} //called from time to time to update the progress bar or whatever
struct REZErr
{
wxString strFile;
unsigned int nID;
unsigned int nOffset;
};
enum REZ_ERROR {
RER_NO_ERROR = 0,
RER_LONG_EXT, //the extension of the file is longer than 4 characters
RER_DEC_WRONG_ID, //
};
virtual void Log(REZ_ERROR, REZErr*) {}
};
#endif /* CREZ_H_ */