Subversion Repositories spk

Rev

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

Rev Author Line No. Line
6 cycrow 1
// BaseFile.h: interface for the CBaseFile class.
2
//
3
//////////////////////////////////////////////////////////////////////
4
 
5
#ifndef __BASEFILE_H__
6
#define __BASEFILE_H__
7
 
8
#if _MSC_VER > 1000
9
#pragma once
10
#endif // _MSC_VER > 1000
11
 
12
#include "lists.h"
13
#include "StringList.h"
14
#include "File.h"
8 cycrow 15
#include "Utils/String.h"
6 cycrow 16
 
46 cycrow 17
#include "Package/CorePackage.h"
18
 
6 cycrow 19
#define GAME_ALL			0
20
#define GAME_X2				1
21
#define GAME_X3				2
22
#define GAME_X3TC			3
23
#define GAME_X3AP			4
24
#define GAME_XREBIRTH		5
25
#define GAME_MAX			(GAME_XREBIRTH)
26
 
27
#define FILEVERSION 4.20f
20 cycrow 28
 
6 cycrow 29
#define WRITECHUNK		50000
30
 
31
class CPackages;
32
 
33
enum {
34
	READFLAG_NONE = 0,
35
	READFLAG_NOUNCOMPRESS = 1
36
};
37
 
38
enum {SPKFILE_INVALID, SPKFILE_SINGLE, SPKFILE_MULTI, SPKFILE_SINGLESHIP, SPKFILE_OLD, SPKFILE_BASE};
39
enum {SPKREAD_ALL, SPKREAD_NODATA, SPKREAD_VALUES, SPKREAD_HEADER};
40
enum {DELETESTATE_NONE, DELETESTATE_WAITING, DELETESTATE_DONE};
41
enum {SPKINSTALL_CREATEDIRECTORY, SPKINSTALL_CREATEDIRECTORY_FAIL, SPKINSTALL_WRITEFILE, SPKINSTALL_WRITEFILE_FAIL, SPKINSTALL_DELETEFILE, SPKINSTALL_DELETEFILE_FAIL,
42
		SPKINSTALL_SKIPFILE, SPKINSTALL_REMOVEDIR, SPKINSTALL_ENABLEFILE, SPKINSTALL_DISABLEFILE, SPKINSTALL_ENABLEFILE_FAIL, SPKINSTALL_DISABLEFILE_FAIL,
43
		SPKINSTALL_UNINSTALL_MOVE, SPKINSTALL_UNINSTALL_COPY, SPKINSTALL_UNINSTALL_MOVE_FAIL, SPKINSTALL_UNINSTALL_COPY_FAIL, SPKINSTALL_UNINSTALL_REMOVE, SPKINSTALL_UNINSTALL_REMOVE_FAIL,
44
		SPKINSTALL_ORIGINAL_BACKUP, SPKINSTALL_ORIGINAL_RESTORE, SPKINSTALL_ORIGINAL_BACKUP_FAIL, SPKINSTALL_ORIGINAL_RESTORE_FAIL, SPKINSTALL_FAKEPATCH, SPKINSTALL_FAKEPATCH_FAIL, 
45
		SPKINSTALL_MISSINGFILE, SPKINSTALL_SHARED, SPKINSTALL_SHARED_FAIL, SPKINSTALL_ORPHANED, SPKINSTALL_ORPHANED_FAIL, SPKINSTALL_UNCOMPRESS_FAIL, SPKINSTALL_AUTOTEXT, SPKINSTALL_AUTOTEXT_FAIL
46
};
47
 
48
enum {PACKAGETYPE_NORMAL, PACKAGETYPE_LIBRARY, PACKAGETYPE_CUSTOMSTART, PACKAGETYPE_PATCH, PACKAGETYPE_UPDATE, PACKAGETYPE_MOD, PACKAGETYPE_SHIP, PACKAGETYPE_FAKEPATCH};
49
 
50
enum {TYPE_BASE, TYPE_SPK, TYPE_XSP, TYPE_ARCHIVE};
51
 
52
// text pages
53
#define TEXTPAGE_RACE		1266
54
#define TEXTPAGE_OBJECTS	17
55
#define TEXTPAGE_CLASS		2006
56
#define TEXTPAGE_CARGOCLASS	1999
57
 
58
 
59
// spk header struct
60
tstruct SSPKHeader {
61
	SSPKHeader () { fVersion = 0; iValueCompression = lValueCompressSize = 0; }
62
	float fVersion;
63
	int iValueCompression;
64
	unsigned long lValueCompressSize;
65
} SSPKHeader;
66
 
67
tstruct SNeededLibrary {
46 cycrow 68
	Utils::String	sName;
69
	Utils::String	sAuthor;
70
	Utils::String	sMinVersion;
6 cycrow 71
} SNeededLibrary;
72
 
73
tstruct SGameCompat {
74
	int			iGame;
46 cycrow 75
	Utils::String	sVersion;
6 cycrow 76
	int			iVersion;
77
} SGameCompat;
78
 
79
tstruct SSPKHeader2 {
80
	SSPKHeader2 () { iNumFiles = 0; lSize = 0; lFullSize = 0; }
81
	int iNumFiles;
82
	long lSize;
83
	long lFullSize;
84
	int iFileCompression;
85
	int iDataCompression;
86
} SSPKHeader2;
87
 
88
typedef struct SNames {
89
	int iLanguage;
46 cycrow 90
	Utils::String sName;
6 cycrow 91
} SNames;
92
 
93
 
46 cycrow 94
class SPKEXPORT CBaseFile : public SPK::Package::CCorePackage
6 cycrow 95
{
96
public:
13 cycrow 97
	static Utils::String ConvertGameToString(int game);
98
	static int GetGameFromString(const Utils::String &game);
6 cycrow 99
	static CyString ErrorString(int error, CyString errorStr = NullString);
100
 
101
	CBaseFile();
102
	virtual ~CBaseFile();
103
 
104
	// Get basic Settings
105
	CyString GetName ()			{ return m_sName; }
106
	CyString GetVersion ()		{ return m_sVersion; }
107
	CyString GetAuthor ()		{ return m_sAuthor; }
108
	CyString GetCreationDate ()	{ return m_sCreationDate; }
109
	virtual CyString GetFullPackageName(int language, CyString byString) { return GetFullPackageName(language, true, byString); }
110
	virtual CyString GetFullPackageName(int language, bool includeVersion = true, CyString byString = "by") 
111
	{ 
112
		CyString p;
113
		if ( language == -1 )
114
			p = m_sName;
115
		else
116
			p = GetLanguageName(language);
117
		if ( includeVersion )
118
		{
119
			p += " V";
120
			p += m_sVersion;
121
		}
122
		p += " ";
123
		p += byString + " " + m_sAuthor;
124
		return p;
125
	}
126
	CLinkList<C_File> *GetFileList() { return &m_lFiles; }
127
	C_File *GetIcon () { return m_pIconFile; }
128
	CyString GetIconExt () { return m_sIconExt; }
129
	CyString GetNameValidFile ();
130
	int GetDataCompression () { return m_SHeader2.iDataCompression; }
131
	float GetFileVersion () { return m_SHeader.fVersion; }
132
	long GetFullFileSize ();
133
	CyString GetLanguageName ( int lang );
134
	virtual CyString GetFullPackageName(CyString format, int lang);
135
	CyString GetAutosaveName();
136
	void SetAutosaveName() { m_sFilename = GetAutosaveName(); }
137
	SGameCompat *GetGameCompatability(int game);
138
	bool RemoveGameCompatability(int game);
46 cycrow 139
	void AddGameCompatability(int game, const Utils::String &version);
6 cycrow 140
	bool CheckGameCompatability(int game);
141
	bool CheckGameVersionCompatability(int game, CyString sVersion, int iVersion);
142
	bool AnyGameCompatability() { return !m_lGames.empty(); }
143
 
144
	bool AnyWebMirrors() { return !m_lMirrors.Empty(); }
145
	CyStringList *GetWebMirrors() { return &m_lMirrors; }
146
	int GetMaxWebMirrors() { return m_lMirrors.Count(); }
147
	CyString GetWebMirror(int i) { if ( i >= 0 && i < m_lMirrors.Count() ) return m_lMirrors.StringAt(i); return NullString; }
148
	void ClearWebMirrors() { m_lMirrors.Clear(); }
149
 
150
	CLinkList<C_File> *GetFileList(int type);
13 cycrow 151
	C_File *GetFirstFile(int type) const;
152
	C_File *GetNextFile(C_File *prev) const;
153
	C_File *GetPrevFile(C_File *next) const;
6 cycrow 154
 
14 cycrow 155
	virtual Utils::String CreateValuesLine () const;
6 cycrow 156
 
14 cycrow 157
	virtual bool LoadPackageData(const Utils::String &sFfirst, const Utils::String &sRest);
6 cycrow 158
	virtual bool GeneratePackagerScript(bool wildcard, CyStringList *list, bool datafile = false);
159
	virtual bool GeneratePackagerScriptFile(bool wildcard, CyStringList *list);
160
 
161
	void ConvertNormalMod(C_File *f, CyString to);
162
	void ConvertFakePatch(C_File *f);
163
	void ConvertAutoText(C_File *f);
164
	C_File *FindMatchingMod(C_File *f);
165
	void RenameFile(C_File *f, CyString baseName);
166
 
167
	// set basic settings
168
	void SetName			( CyString str ) { m_sName = str.Remove ( '|' ); m_bChanged = true; }
169
	void SetVersion			( CyString str ) { m_sVersion = str; m_bChanged = true; }
170
	void SetAuthor			( CyString str ) { m_sAuthor = str.Remove ( '|' ); m_bChanged = true; }
171
	void SetCreationDate	( CyString str ) { m_sCreationDate = str; m_bChanged = true; }
172
	void AddWebMirror		( CyString str ) { m_lMirrors.PushBack(str, "", true); m_bChanged = true; }
173
	void RemoveWebMirror	( CyString str ) { m_lMirrors.Remove(str, true); m_bChanged = true; }
174
	void SetDataCompression ( int c )       { m_SHeader2.iDataCompression = c; }
175
	void SetFileCompression ( int c )       { m_SHeader2.iFileCompression = c; }
176
	void SetValueCompression( int c )       { m_SHeader.iValueCompression = c; }
177
	void SetIcon ( C_File *file, CyString ext ) { if ( m_pIconFile ) delete m_pIconFile; m_sIconExt = ext; m_pIconFile = file; m_bChanged = true; }
178
	void SetFtpAddr			( CyString str ) { m_sFtpAddr = str; }
179
 
180
	void AddFileScript(int filetype, bool shared, CyString rest);
181
	void SetFilename ( CyString str ) { m_sFilename = str; }
182
	CyString GetFilename() { return m_sFilename; }
183
	CyString GetExportFilename() { return m_sExportFilename; }
184
 
185
	bool IsMod();
13 cycrow 186
	bool IsFakePatch() const;
6 cycrow 187
 
188
	// error handling
189
	void ClearError () { m_sLastError = ""; m_iLastError = SPKERR_NONE; }
190
	int GetLastError () { return m_iLastError; }
191
	CyString GetLastErrorString() { return m_sLastError; }
192
 
193
	// file handling
194
	void AddFile ( C_File *file );
195
	C_File *AddFile ( CyString, CyString, int type, int game = 0 );
196
	C_File *AppendFile ( CyString file, int type, int game, CyString dir = NullString, CProgressInfo *progress = NULL );
197
	C_File *FindFile ( CyString, int, CyString = NullString, int game = 0 );
198
	bool AddFileNow ( CyString, CyString, int type, CProgressInfo *progress = NULL );
199
	int CountFiles ( int filetype );
200
	C_File *FindFileAt ( int filetype, int pos );
201
	virtual bool RemoveFile ( int pos );
202
	virtual bool RemoveFile ( C_File *files );
203
	virtual bool RemoveFile ( CyString file, int type, CyString dir = NullString, int game = 0 );
204
	void RemoveAllFiles ( int type, int game );
205
	CyString CreateFilesLine ( bool updateheader, CProgressInfo * = NULL );
206
 
207
	virtual bool WriteHeader ( FILE *id, int, int );
208
	virtual bool WriteData ( FILE *id, CProgressInfo * = NULL );
209
	virtual bool WriteFile ( CyString filename, CProgressInfo * = NULL );
210
	virtual bool ReadFile ( CyString filename, int readType = SPKREAD_ALL, CProgressInfo *progress = NULL );
211
	virtual bool ReadFile ( FILE *id, int readtype, CProgressInfo *progress );
212
 
213
	virtual bool ExtractFile ( C_File *file, CyString dir, bool includedir = true, CProgressInfo *progress = NULL );
214
	virtual bool ExtractFile ( int file, CyString dir, bool includedir = true, CProgressInfo *progress = NULL );
215
	virtual bool ExtractAll ( CyString dir, int game, bool includedir = true, CProgressInfo *progress = NULL );
216
 
217
	virtual bool SaveToArchive(CyString filename, int game, CProgressInfo *progress = NULL);
218
	void ClearFileData();
219
 
220
	CLinkList<SNames> *GetNamesList() { return &m_lNames; }
221
 
222
	// reading files
223
	void ReadAllFilesToMemory ();
224
	void ReadIconFileToMemory ();
225
	bool ReadFileToMemory(C_File *f);
226
 
227
	// compression
228
	void RecompressAllFiles ( int compresstype, CProgressInfo *progress );
47 cycrow 229
	void CompressAllFiles ( int compresstype, CProgressInfo *progress = NULL, CProgressInfo *overallProgress = NULL, int level = DEFAULT_COMPRESSION_LEVEL );
6 cycrow 230
	bool UncompressAllFiles ( CProgressInfo * = NULL );
231
 
232
	// static functions
233
	static CyString GetEndOfLine ( FILE *id, int *line = NULL, bool upper = true );
234
	static int CheckFile ( CyString filename, float *version = NULL );
235
 
236
	bool IsFileAdded(C_File *f) { return m_lFiles.FindData(f); }
237
 
238
	// installing
239
	void SwitchFilePointer(C_File *oldFile, C_File *newFile);
240
	bool InstallFiles ( CyString destdir, CProgressInfo *progress, CLinkList<C_File> *spklist, CyStringList *errorStr, bool enabled = true, CPackages *packages = NULL );
241
	virtual bool IsPatch () { return false; }
242
 
243
	// installer functions
244
	bool IsProfileEnabled () { return m_bProfile; }
245
	bool IsEnabled () { return m_bEnable; }
246
	bool IsModifiedEnabled () { return m_bModifiedEnabled; }
247
	bool IsGlobalEnabled () { return m_bGlobal; }
248
 
249
	void SetProfileEnabled ( bool en ) { m_bProfile = en; }
250
	void SetEnabled ( bool en ) { m_bEnable = en; }
251
	void SetModifiedEnabled ( bool en ) { m_bModifiedEnabled = en; }
252
	void SetGlobalEnabled ( bool en ) { m_bGlobal = en; }
253
 
254
	int  GetLoadError() { return m_iLoadError; }
255
	void SetLoadError(int i) { m_iLoadError = i; }
256
	CyString CreateUpdateFile(CyString dir);
257
 
258
	// language functions
259
	void RemoveLanguageName ( int lang );
46 cycrow 260
	void AddLanguageName ( int lang, const Utils::String &name );
6 cycrow 261
	void ClearNames ();
262
 
14 cycrow 263
	virtual bool ParseValueLine(const Utils::String &line);
6 cycrow 264
 
265
	CLinkList<SGameCompat>  *GetGameCompatabilityList() { return &m_lGames; }
266
 
267
	CyString GetFullFileSizeString();
268
 
269
	CLinkList<SNeededLibrary> *GetNeededLibraries() { return &m_lNeededLibrarys; }
46 cycrow 270
	void AddNeededLibrary(const Utils::String &scriptName, const Utils::String &author, const Utils::String &minVersion);
271
	bool IsPackageNeeded(const Utils::String &scriptName, const Utils::String &author);
272
	SNeededLibrary *FindPackageNeeded(const Utils::String &scriptName, const Utils::String &author);
273
	void RemovePackageNeeded(const Utils::String &scriptName, const Utils::String &author);
6 cycrow 274
	void ClearNeededPackages();
275
	bool AnyDependacies() { return (m_lNeededLibrarys.size()) ? true: false; }
276
	bool AutoGenerateUpdateFile() { return m_bAutoGenerateUpdateFile; }
277
	void RemoveFakePatchOrder(bool after, CyString scriptName, CyString author);
278
	void RemoveFakePatchOrder(CyString scriptName, CyString author);
279
	void AddFakePatchOrder(bool after, CyString scriptName, CyString author);
280
	bool AnyFakePatchOrder() { if ( !m_lFakePatchBefore.Empty() || !m_lFakePatchAfter.Empty() ) return true; return false; }
281
	CyStringList &GetFakePatchBeforeOrder() { return m_lFakePatchBefore; }
282
	CyStringList &GetFakePatchAfterOrder() { return m_lFakePatchAfter; }
283
 
284
	bool IsChanged() { return m_bChanged; }
285
	void SetChanged(bool b) { m_bChanged = b; }
286
 
287
	int  FindFirstGameInPackage();
288
	bool IsAnyGameInPackage();
289
	bool IsMultipleGamesInPackage();
290
	bool IsGameInPackage(int game);
291
 
292
	virtual int GetType () { return TYPE_BASE; }
293
	bool AnyFileType ( int type );
294
	CBaseFile *GetParent () { return m_pParent; }
295
	void SetParent ( CBaseFile *file ) { m_pParent = file; }
48 cycrow 296
	int ParseLanguage(const Utils::String &lang) const;
6 cycrow 297
 
298
	virtual bool UpdateSigned (bool updateFiles);
299
	int GetNum() { return m_iNum; }
300
	void SetNum(int i) { m_iNum = i; }
301
 
302
	bool	IsFullyLoaded() { return m_bFullyLoaded; }
303
	virtual bool   IsSigned ()		{ return m_bSigned;}
304
	void SetOverrideFiles(bool b) { m_bOverrideFiles = b; }
305
	bool IsUpdateChecked () { return m_bUpdate; }
306
	void SetUpdateChecked ( bool en ) { m_bUpdate = en; }
307
 
308
	unsigned char *CreateData(size_t *size, CProgressInfo *progress = NULL);
309
 
310
protected:
311
	virtual void Delete ();
312
	virtual void SetDefaults ();
313
 
314
	// reading of files
14 cycrow 315
	virtual bool CheckHeader(const Utils::String header) const;
6 cycrow 316
	virtual bool ParseHeader ( CyString header );
317
	virtual bool ParseFileHeader ( CyString header );
318
	virtual bool ParseFilesLine ( CyString line );
319
	virtual void ReadValues ( CyString values );
320
	virtual void ReadFiles ( CyString values );
321
 
14 cycrow 322
	void _install_adjustFakePatches(CPackages *pPackages);
43 cycrow 323
	void _install_renameText(CPackages *pPackages);
14 cycrow 324
 
6 cycrow 325
	SSPKHeader m_SHeader;
326
	SSPKHeader2 m_SHeader2;
327
 
328
	CyString m_sName;
329
	CyString m_sVersion;
330
	CyString m_sAuthor;
331
	CyString m_sCreationDate;
332
 
333
	C_File *m_pIconFile;
334
	CyString m_sIconExt;
335
	CyString m_sLastError;
336
	int m_iLastError;
337
 
338
	CyString m_sFilename;
339
	CyString m_sExportFilename;
340
 
341
	CLinkList<C_File>  m_lFiles;
48 cycrow 342
	CLinkList<SNames> m_lNames;			//TODO: move to CorePackage
343
	CyStringList m_lMirrors;			//TODO: move to CorePackage
6 cycrow 344
	CyStringList m_lFakePatchBefore;
345
	CyStringList m_lFakePatchAfter;
346
 
48 cycrow 347
	//int m_iPluginType;
6 cycrow 348
	CLinkList<SGameCompat> m_lGames;
349
 
350
	bool m_bSigned;
351
	bool m_bFullyLoaded;
352
 
353
	//installer varibles
354
	bool m_bEnable;
355
	bool m_bModifiedEnabled;
356
	bool m_bGlobal;
357
	bool m_bProfile;
358
	int m_iLoadError;
359
 
360
	CBaseFile *m_pParent;
361
 
362
	int m_iNum;
363
	bool	m_bChanged;
364
 
365
	CLinkList<SNeededLibrary> m_lNeededLibrarys;
366
 
367
	bool	m_bOverrideFiles;
368
	CyString	m_sFtpAddr;
369
	bool	m_bAutoGenerateUpdateFile;
370
	bool m_bUpdate;
371
};
372
 
373
 
374
class SPKEXPORT CArchiveFile : public CBaseFile
375
{
376
public:
377
	CArchiveFile();
378
	virtual ~CArchiveFile();
379
	virtual CyString GetFullPackageName(CyString format, int lang) { return CyString("Archive(") + m_sName + ")"; }
380
	virtual CyString GetFullPackageName(int language, CyString byString) { return CyString("Archive(") + m_sName + ")"; }
381
	virtual CyString GetFullPackageName(int language, bool includeVersion = true, CyString byString = "by") { return CyString("Archive(") + m_sName + ")"; }
382
	virtual int GetType () { return TYPE_ARCHIVE; }
383
};
384
 
385
#endif //__BASEFILE_H__
386