Subversion Repositories spk

Rev

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