Subversion Repositories spk

Rev

Rev 47 | Rev 49 | 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 GetWebSite ()		{ return m_sWebSite; }
109
	CyString GetWebAddress ()	{ return m_sWebAddress; }
110
	CyString GetEmail ()		{ return m_sEmail; }
111
	CyString GetCreationDate ()	{ return m_sCreationDate; }
112
	CyString GetForumLink ()	{ return m_sForumLink; }
113
	virtual CyString GetFullPackageName(int language, CyString byString) { return GetFullPackageName(language, true, byString); }
114
	virtual CyString GetFullPackageName(int language, bool includeVersion = true, CyString byString = "by") 
115
	{ 
116
		CyString p;
117
		if ( language == -1 )
118
			p = m_sName;
119
		else
120
			p = GetLanguageName(language);
121
		if ( includeVersion )
122
		{
123
			p += " V";
124
			p += m_sVersion;
125
		}
126
		p += " ";
127
		p += byString + " " + m_sAuthor;
128
		return p;
129
	}
130
	CLinkList<C_File> *GetFileList() { return &m_lFiles; }
131
	C_File *GetIcon () { return m_pIconFile; }
132
	CyString GetIconExt () { return m_sIconExt; }
133
	CyString GetNameValidFile ();
134
	int GetDataCompression () { return m_SHeader2.iDataCompression; }
135
	float GetFileVersion () { return m_SHeader.fVersion; }
136
	long GetFullFileSize ();
137
	CyString GetLanguageName ( int lang );
138
	virtual CyString GetFullPackageName(CyString format, int lang);
139
	CyString GetAutosaveName();
140
	void SetAutosaveName() { m_sFilename = GetAutosaveName(); }
141
	SGameCompat *GetGameCompatability(int game);
142
	bool RemoveGameCompatability(int game);
46 cycrow 143
	void AddGameCompatability(int game, const Utils::String &version);
6 cycrow 144
	bool CheckGameCompatability(int game);
145
	bool CheckGameVersionCompatability(int game, CyString sVersion, int iVersion);
146
	bool AnyGameCompatability() { return !m_lGames.empty(); }
147
 
148
	bool AnyWebMirrors() { return !m_lMirrors.Empty(); }
149
	CyStringList *GetWebMirrors() { return &m_lMirrors; }
150
	int GetMaxWebMirrors() { return m_lMirrors.Count(); }
151
	CyString GetWebMirror(int i) { if ( i >= 0 && i < m_lMirrors.Count() ) return m_lMirrors.StringAt(i); return NullString; }
152
	void ClearWebMirrors() { m_lMirrors.Clear(); }
153
 
154
	CLinkList<C_File> *GetFileList(int type);
13 cycrow 155
	C_File *GetFirstFile(int type) const;
156
	C_File *GetNextFile(C_File *prev) const;
157
	C_File *GetPrevFile(C_File *next) const;
6 cycrow 158
 
14 cycrow 159
	virtual Utils::String CreateValuesLine () const;
6 cycrow 160
 
14 cycrow 161
	virtual bool LoadPackageData(const Utils::String &sFfirst, const Utils::String &sRest);
6 cycrow 162
	virtual bool GeneratePackagerScript(bool wildcard, CyStringList *list, bool datafile = false);
163
	virtual bool GeneratePackagerScriptFile(bool wildcard, CyStringList *list);
164
 
165
	void ConvertNormalMod(C_File *f, CyString to);
166
	void ConvertFakePatch(C_File *f);
167
	void ConvertAutoText(C_File *f);
168
	C_File *FindMatchingMod(C_File *f);
169
	void RenameFile(C_File *f, CyString baseName);
170
 
171
	// set basic settings
172
	void SetName			( CyString str ) { m_sName = str.Remove ( '|' ); m_bChanged = true; }
173
	void SetVersion			( CyString str ) { m_sVersion = str; m_bChanged = true; }
174
	void SetAuthor			( CyString str ) { m_sAuthor = str.Remove ( '|' ); m_bChanged = true; }
175
	void SetWebAddress		( CyString str ) { m_sWebAddress = str; m_bChanged = true; }
176
	void SetWebSite			( CyString str ) { m_sWebSite = str; m_bChanged = true; }
177
	void SetEmail			( CyString str ) { m_sEmail = str; m_bChanged = true; }
178
	void SetCreationDate	( CyString str ) { m_sCreationDate = str; m_bChanged = true; }
179
	void AddWebMirror		( CyString str ) { m_lMirrors.PushBack(str, "", true); m_bChanged = true; }
180
	void RemoveWebMirror	( CyString str ) { m_lMirrors.Remove(str, true); m_bChanged = true; }
181
	void SetDataCompression ( int c )       { m_SHeader2.iDataCompression = c; }
182
	void SetFileCompression ( int c )       { m_SHeader2.iFileCompression = c; }
183
	void SetValueCompression( int c )       { m_SHeader.iValueCompression = c; }
184
	void SetForumLink		( CyString str ) { m_sForumLink = str; m_bChanged = true; }
185
	void SetIcon ( C_File *file, CyString ext ) { if ( m_pIconFile ) delete m_pIconFile; m_sIconExt = ext; m_pIconFile = file; m_bChanged = true; }
186
	void SetFtpAddr			( CyString str ) { m_sFtpAddr = str; }
187
 
188
	void AddFileScript(int filetype, bool shared, CyString rest);
189
	void SetFilename ( CyString str ) { m_sFilename = str; }
190
	CyString GetFilename() { return m_sFilename; }
191
	CyString GetExportFilename() { return m_sExportFilename; }
192
 
193
	bool IsMod();
13 cycrow 194
	bool IsFakePatch() const;
6 cycrow 195
 
196
	// error handling
197
	void ClearError () { m_sLastError = ""; m_iLastError = SPKERR_NONE; }
198
	int GetLastError () { return m_iLastError; }
199
	CyString GetLastErrorString() { return m_sLastError; }
200
 
201
	// file handling
202
	void AddFile ( C_File *file );
203
	C_File *AddFile ( CyString, CyString, int type, int game = 0 );
204
	C_File *AppendFile ( CyString file, int type, int game, CyString dir = NullString, CProgressInfo *progress = NULL );
205
	C_File *FindFile ( CyString, int, CyString = NullString, int game = 0 );
206
	bool AddFileNow ( CyString, CyString, int type, CProgressInfo *progress = NULL );
207
	int CountFiles ( int filetype );
208
	C_File *FindFileAt ( int filetype, int pos );
209
	virtual bool RemoveFile ( int pos );
210
	virtual bool RemoveFile ( C_File *files );
211
	virtual bool RemoveFile ( CyString file, int type, CyString dir = NullString, int game = 0 );
212
	void RemoveAllFiles ( int type, int game );
213
	CyString CreateFilesLine ( bool updateheader, CProgressInfo * = NULL );
214
 
215
	virtual bool WriteHeader ( FILE *id, int, int );
216
	virtual bool WriteData ( FILE *id, CProgressInfo * = NULL );
217
	virtual bool WriteFile ( CyString filename, CProgressInfo * = NULL );
218
	virtual bool ReadFile ( CyString filename, int readType = SPKREAD_ALL, CProgressInfo *progress = NULL );
219
	virtual bool ReadFile ( FILE *id, int readtype, CProgressInfo *progress );
220
 
221
	virtual bool ExtractFile ( C_File *file, CyString dir, bool includedir = true, CProgressInfo *progress = NULL );
222
	virtual bool ExtractFile ( int file, CyString dir, bool includedir = true, CProgressInfo *progress = NULL );
223
	virtual bool ExtractAll ( CyString dir, int game, bool includedir = true, CProgressInfo *progress = NULL );
224
 
225
	virtual bool SaveToArchive(CyString filename, int game, CProgressInfo *progress = NULL);
226
	void ClearFileData();
227
 
228
	CLinkList<SNames> *GetNamesList() { return &m_lNames; }
229
 
230
	// reading files
231
	void ReadAllFilesToMemory ();
232
	void ReadIconFileToMemory ();
233
	bool ReadFileToMemory(C_File *f);
234
 
235
	// compression
236
	void RecompressAllFiles ( int compresstype, CProgressInfo *progress );
47 cycrow 237
	void CompressAllFiles ( int compresstype, CProgressInfo *progress = NULL, CProgressInfo *overallProgress = NULL, int level = DEFAULT_COMPRESSION_LEVEL );
6 cycrow 238
	bool UncompressAllFiles ( CProgressInfo * = NULL );
239
 
240
	// static functions
241
	static CyString GetEndOfLine ( FILE *id, int *line = NULL, bool upper = true );
242
	static int CheckFile ( CyString filename, float *version = NULL );
243
 
244
	bool IsFileAdded(C_File *f) { return m_lFiles.FindData(f); }
245
 
246
	// installing
247
	void SwitchFilePointer(C_File *oldFile, C_File *newFile);
248
	bool InstallFiles ( CyString destdir, CProgressInfo *progress, CLinkList<C_File> *spklist, CyStringList *errorStr, bool enabled = true, CPackages *packages = NULL );
249
	virtual bool IsPatch () { return false; }
250
 
251
	// installer functions
252
	bool IsProfileEnabled () { return m_bProfile; }
253
	bool IsEnabled () { return m_bEnable; }
254
	bool IsModifiedEnabled () { return m_bModifiedEnabled; }
255
	bool IsGlobalEnabled () { return m_bGlobal; }
256
 
257
	void SetProfileEnabled ( bool en ) { m_bProfile = en; }
258
	void SetEnabled ( bool en ) { m_bEnable = en; }
259
	void SetModifiedEnabled ( bool en ) { m_bModifiedEnabled = en; }
260
	void SetGlobalEnabled ( bool en ) { m_bGlobal = en; }
261
 
262
	int  GetLoadError() { return m_iLoadError; }
263
	void SetLoadError(int i) { m_iLoadError = i; }
264
	CyString CreateUpdateFile(CyString dir);
265
 
266
	// language functions
267
	void RemoveLanguageName ( int lang );
46 cycrow 268
	void AddLanguageName ( int lang, const Utils::String &name );
6 cycrow 269
	void ClearNames ();
270
 
14 cycrow 271
	virtual bool ParseValueLine(const Utils::String &line);
6 cycrow 272
 
273
	CLinkList<SGameCompat>  *GetGameCompatabilityList() { return &m_lGames; }
274
 
275
	CyString GetFullFileSizeString();
276
 
277
	CLinkList<SNeededLibrary> *GetNeededLibraries() { return &m_lNeededLibrarys; }
46 cycrow 278
	void AddNeededLibrary(const Utils::String &scriptName, const Utils::String &author, const Utils::String &minVersion);
279
	bool IsPackageNeeded(const Utils::String &scriptName, const Utils::String &author);
280
	SNeededLibrary *FindPackageNeeded(const Utils::String &scriptName, const Utils::String &author);
281
	void RemovePackageNeeded(const Utils::String &scriptName, const Utils::String &author);
6 cycrow 282
	void ClearNeededPackages();
283
	bool AnyDependacies() { return (m_lNeededLibrarys.size()) ? true: false; }
284
	bool AutoGenerateUpdateFile() { return m_bAutoGenerateUpdateFile; }
285
	void RemoveFakePatchOrder(bool after, CyString scriptName, CyString author);
286
	void RemoveFakePatchOrder(CyString scriptName, CyString author);
287
	void AddFakePatchOrder(bool after, CyString scriptName, CyString author);
288
	bool AnyFakePatchOrder() { if ( !m_lFakePatchBefore.Empty() || !m_lFakePatchAfter.Empty() ) return true; return false; }
289
	CyStringList &GetFakePatchBeforeOrder() { return m_lFakePatchBefore; }
290
	CyStringList &GetFakePatchAfterOrder() { return m_lFakePatchAfter; }
291
 
292
	bool IsChanged() { return m_bChanged; }
293
	void SetChanged(bool b) { m_bChanged = b; }
294
 
295
	int  FindFirstGameInPackage();
296
	bool IsAnyGameInPackage();
297
	bool IsMultipleGamesInPackage();
298
	bool IsGameInPackage(int game);
299
 
300
	virtual int GetType () { return TYPE_BASE; }
301
	bool AnyFileType ( int type );
302
	CBaseFile *GetParent () { return m_pParent; }
303
	void SetParent ( CBaseFile *file ) { m_pParent = file; }
48 cycrow 304
	int ParseLanguage(const Utils::String &lang) const;
6 cycrow 305
 
306
	virtual bool UpdateSigned (bool updateFiles);
307
	int GetNum() { return m_iNum; }
308
	void SetNum(int i) { m_iNum = i; }
309
 
310
	bool	IsFullyLoaded() { return m_bFullyLoaded; }
311
	virtual bool   IsSigned ()		{ return m_bSigned;}
312
	void SetOverrideFiles(bool b) { m_bOverrideFiles = b; }
313
	bool IsUpdateChecked () { return m_bUpdate; }
314
	void SetUpdateChecked ( bool en ) { m_bUpdate = en; }
315
 
316
	unsigned char *CreateData(size_t *size, CProgressInfo *progress = NULL);
317
 
318
protected:
319
	virtual void Delete ();
320
	virtual void SetDefaults ();
321
 
322
	// reading of files
14 cycrow 323
	virtual bool CheckHeader(const Utils::String header) const;
6 cycrow 324
	virtual bool ParseHeader ( CyString header );
325
	virtual bool ParseFileHeader ( CyString header );
326
	virtual bool ParseFilesLine ( CyString line );
327
	virtual void ReadValues ( CyString values );
328
	virtual void ReadFiles ( CyString values );
329
 
14 cycrow 330
	void _install_adjustFakePatches(CPackages *pPackages);
43 cycrow 331
	void _install_renameText(CPackages *pPackages);
14 cycrow 332
 
6 cycrow 333
	SSPKHeader m_SHeader;
334
	SSPKHeader2 m_SHeader2;
335
 
336
	CyString m_sName;
337
	CyString m_sVersion;
338
	CyString m_sAuthor;
339
	CyString m_sWebSite;
340
	CyString m_sWebAddress;
341
	CyString m_sEmail;
342
	CyString m_sCreationDate;
343
	CyString m_sForumLink;
344
 
345
	C_File *m_pIconFile;
346
	CyString m_sIconExt;
347
	CyString m_sLastError;
348
	int m_iLastError;
349
 
350
	CyString m_sFilename;
351
	CyString m_sExportFilename;
352
 
353
	CLinkList<C_File>  m_lFiles;
48 cycrow 354
	CLinkList<SNames> m_lNames;			//TODO: move to CorePackage
355
	CyStringList m_lMirrors;			//TODO: move to CorePackage
6 cycrow 356
	CyStringList m_lFakePatchBefore;
357
	CyStringList m_lFakePatchAfter;
358
 
48 cycrow 359
	//int m_iPluginType;
6 cycrow 360
	CLinkList<SGameCompat> m_lGames;
361
 
362
	bool m_bSigned;
363
	bool m_bFullyLoaded;
364
 
365
	//installer varibles
366
	bool m_bEnable;
367
	bool m_bModifiedEnabled;
368
	bool m_bGlobal;
369
	bool m_bProfile;
370
	int m_iLoadError;
371
 
372
	CBaseFile *m_pParent;
373
 
374
	int m_iNum;
375
	bool	m_bChanged;
376
 
377
	CLinkList<SNeededLibrary> m_lNeededLibrarys;
378
 
379
	bool	m_bOverrideFiles;
380
	CyString	m_sFtpAddr;
381
	bool	m_bAutoGenerateUpdateFile;
382
	bool m_bUpdate;
383
};
384
 
385
 
386
class SPKEXPORT CArchiveFile : public CBaseFile
387
{
388
public:
389
	CArchiveFile();
390
	virtual ~CArchiveFile();
391
	virtual CyString GetFullPackageName(CyString format, int lang) { return CyString("Archive(") + m_sName + ")"; }
392
	virtual CyString GetFullPackageName(int language, CyString byString) { return CyString("Archive(") + m_sName + ")"; }
393
	virtual CyString GetFullPackageName(int language, bool includeVersion = true, CyString byString = "by") { return CyString("Archive(") + m_sName + ")"; }
394
	virtual int GetType () { return TYPE_ARCHIVE; }
395
};
396
 
397
#endif //__BASEFILE_H__
398