Subversion Repositories spk

Rev

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