Subversion Repositories spk

Rev

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

Rev Author Line No. Line
1 cycrow 1
#ifndef __PACKAGES_H__
2
#define __PACKAGES_H__
3
 
4
#include "SpkFile.h"
5
#include "GameExe.h"
6
#include "XspFile.h"
7
#include "archive/unzip.h"
8
 
9
#include "MultiSpkFile.h"
10
#include "VirtualFileSystem.h"
11
 
12
enum {INSTALLERR_NONE, INSTALLERR_VERSION, INSTALLERR_INVALID, INSTALLERR_NOMULTI, INSTALLERR_NOSHIP, INSTALLERR_UNKNOWN, INSTALLERR_NOEXIST, INSTALLERR_OLD};
13
enum {INSTALLCHECK_OK, INSTALLCHECK_OLDVERSION, INSTALLCHECK_NOOTHERMOD, INSTALLCHECK_ALREADYQUEUED, INSTALLCHECK_WRONGGAME, INSTALLCHECK_WRONGVERSION, INSTALLCHECK_MODIFIED, INSTALLCHECK_NOSHIP};
14
enum {PROGRESS_ENABLEFILE, PROGRESS_SHUFFLEFAKE, PROGRESS_DISABLEFILE};
15
enum {PKERR_NONE, PKERR_NOPARENT, PKERR_MODIFIED, PKERR_MISSINGDEP, PKERR_NOOUTPUT, PKERR_DONTEXIST, PKERR_UNABLETOOPEN};
16
enum {WARETYPE_NONE, WARETYPE_DELETED, WARETYPE_ADDED, WARETYPE_DISABLED};
17
enum {WARES_BIO, WARES_ENERGY, WARES_FOOD, WARES_MINERAL, WARES_TECH, WARES_NATURAL, WAREBUFFERS};
18
 
19
#define IC_WRONGGAME		1
20
#define IC_WRONGVERSION		2
21
#define IC_OLDVERSION		4
22
#define IC_MODIFIED			8
23
#define IC_ALL				15
24
 
25
#define PMTEXTFILE 901
26
 
27
#define SHIPSTARTTEXT		500000
28
#define WARETEXTSTART		400000
29
 
30
class CFileIO;
31
 
32
tstruct SGameWare {
33
	char cType;
34
	int iType;
35
	int iText;
36
	CyString sWareName;
37
	int iPos;
38
	SWares *pWare;
39
} SGameWare;
40
 
41
tstruct SGameShip {
42
	int		  iType;
43
	int		  iText;
44
	int		  iPos;
45
	CyString  sShipID;
46
	CyString  sShipClass;
47
	CXspFile *pPackage;
48
} SGameShip;
49
 
50
tstruct SBodies {
51
	CyString	 sNumbers;
52
	CyString	 sSection;
53
	CyStringList lEntries;
54
} SBodes;
55
 
56
tstruct SAvailablePackage {
57
	CLinkList<SGameCompat> lGames;
58
	int			iType;
59
	int			iPluginType;
60
	CyString	sName;
61
	CyString	sAuthor;
62
	CyString	sVersion;
63
	CyString	sDesc;
64
	CyString	sUpdated;
65
	int			iEase;
66
	int			iChanging;
67
	int			iRec;
68
	CyString	sFilename;
69
	int			iScriptType;
70
	bool		bSigned;
71
} SAvailablePackage;
72
 
73
class SPKEXPORT CPackages
74
{
75
public:
76
	static CyString ConvertLanguage(int lang);
77
	static SAvailablePackage *CreateAvailablePackageData(CBaseFile *package);
78
	static CyString FormatAvailablePackageData(CBaseFile *package);
79
	static CyString FormatAvailablePackageData(SAvailablePackage *package);
80
	static CyString CreateFromPackagerScript(CyString filename);
81
	static int GeneratePackageUpdateData(CyString dir, bool includeSingle = true);
82
 
83
	CPackages ();
84
	~CPackages ();
85
 
83 cycrow 86
	bool isOldDir(const Utils::String &dir);
1 cycrow 87
	bool Read ( CyString dir, CProgressInfo *progress = NULL );
88
	void Startup(CyString dir, CyString tempDir, CyString myDoc, CyString mod = NullString);
89
 
90
	CBaseFile *LoadPackagerScript(CyString filename, int compression, CyString (*askFunc)(CyString), CyStringList *malformedLines = NULL, CyStringList *unknownCommands = NULL, CyStringList *variables = NULL);
91
	CyStringList *GetGlobals() { return &m_lGlobals; }
92
	CyStringList *GetFakePatchOrder() { return &m_lFakePatchOrder; }
93
	CyString GetCurrentDirectory() { return m_sCurrentDir; }
79 cycrow 94
	static CyString GetTempDirectory() { return m_sTempDir; }
95
	static Utils::String tempDirectory() { return m_sTempDir.ToString(); }
1 cycrow 96
	CyString GetMyDocuments() { return m_sMyDoc; }
97
	CGameExe *GetGameExe() { return &m_gameExe; }
98
	CLinkList<CBaseFile> *GetInstallPackageList() { return &m_lInstallList; }
99
 
100
	// installing/uninstalling
101
	bool		InstallPackage ( CBaseFile *package, CyStringList *errors, CProgressInfo *progress = NULL, bool disabled = false );
102
	CBaseFile		*OpenPackage ( CyString file, int *error, CProgressInfo *progress = NULL, int readtype = SPKREAD_ALL, int flags = READFLAG_NONE );
103
	CMultiSpkFile	*OpenMultiPackage(CyString file, int *error, CProgressInfo *progress = NULL);
104
	bool		OpenMultiPackage ( CyString file, CLinkList<CBaseFile> *packageList, int *error, CProgressInfo *progress = NULL );
105
	int			CheckInstallPackage(CBaseFile *package, int check = IC_ALL);
106
	bool		RemoveFile(C_File *file, CyStringList *errors = NULL);
107
	void		PrepareUninstallPackage(CBaseFile *package);
108
	bool		UninstallPreparedPackages(CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *uninstalledPackages = NULL, CLinkList<CBaseFile> *disabledPackages = NULL);
109
	void		ConvertOldPackage(CBaseFile *p);
110
	void		PurgeUninstallScripts(CBaseFile *package, CyStringList *errors);
111
	int 		PrepareInstallPackage(CBaseFile *package, bool disabled = false, bool force = false, int check = IC_ALL);
112
	int			InstallPreparedPackages(CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *errored, CLinkList<CBaseFile> *installedList = NULL);
113
	void		RemovePreparedInstall(CBaseFile *package);
114
	int			GetNumPackagesInQueue() { return m_lInstallList.size(); }
115
	int			CheckOpenPackage(CyString file, int *error);
116
	int			GetMissingDependacies(CBaseFile *p, CyStringList *list, bool onlyEnabled = false, bool includePrepared = false);
117
	bool		CheckInstalledDependacy(CyString name, CyString author, CyString version, bool onlyEnabled = false, bool includePerpered = false);
118
	bool		CheckEnabledDependacy(CBaseFile *p);
119
	int			GetDependacyList(CBaseFile *package, CLinkList<CBaseFile> *list);
120
	int			PrepareMultiPackage ( CyString file, CLinkList<CBaseFile> *errorPackageList, int *error, CProgressInfo *progress = 0);
121
 
122
	bool		IsOldPluginManager() { return m_bOldPlugin; }
123
 
124
	// enable/disable
125
	bool EnablePackage ( CBaseFile *package, CyStringList *errors, CProgressInfo *progress = NULL );
126
	bool DisablePackage ( CBaseFile *package, CyStringList *errors, CProgressInfo *progress = NULL );
127
	bool DisablePreparedPackages ( CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *disabledPackages = NULL );
128
	bool PrepareEnablePackage(CBaseFile *package);
129
	bool PrepareDisablePackage(CBaseFile *package);
130
	bool EnablePreparedPackages ( CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *enabledPackages = NULL );
131
	int  GetNumPackagesInEnabledQueue() { return m_lEnableList.size(); }
132
	int  GetNumPackagesInDisabledQueue() { return m_lDisableList.size(); }
133
	bool PrepareDisableForVanilla();
134
	bool PrepareEnableLibrarys();
135
	bool PrepareEnableFromVanilla();
136
 
137
	void WriteData();
138
	bool CloseDir ( CyStringList *errors = 0, CProgressInfo *progress = NULL, bool removedir = false );
139
	bool RestoreFakePatch();
140
	bool ReadyFakePatch();
141
	bool CheckValidPluginManagerFile(CyString filename);
142
	bool CheckIfPluginManagerFile(CyString filename);
143
 
144
	// package control
145
	void UpdateUsedFiles(CLinkList<CBaseFile> *ignoreList = NULL, bool = true);
146
	void UpdateSigned();
147
	bool UpdatePackages(int doStatus = -1, bool individual = false);
148
	CBaseFile *FindXspPackage(CyString id);
149
	CBaseFile *FindSpkPackage(CyString name, CyString author);
150
	CArchiveFile *FindArchivePackage(CyString name);
151
	CBaseFile *FindPackage(CyString name, CyString author);
152
	CBaseFile *FindFirstPackageWithFile(C_File *f);
153
	CBaseFile *FindNextPackageWithFile(CBaseFile *p, C_File *f);
154
	CBaseFile *FindPackage(CBaseFile *package);
155
	C_File *FindFile(int filetype, CyString filename, CyString dir = NullString);
156
	CBaseFile *FirstPackage() { return m_lPackages.First(); }
157
	CBaseFile *NextPackage() { return m_lPackages.Next(); }
158
	CBaseFile *GetFirstPackage() { if ( m_lPackages.Front() ) return m_lPackages.Front()->Data(); return NULL; }
159
	CBaseFile *GetNextPackage(CBaseFile *from) 
160
	{ 
161
		bool found = false;
162
		for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
163
		{
164
			if ( !node->Data() ) continue;
165
			if ( node->Data() == from )
166
				found = true;
167
			else if ( found )
168
				return node->Data();
169
		}
170
		return NULL; 
171
	}
172
	void Reset();
173
	CBaseFile *GetPackageAt(int i) { return m_lPackages[i]; }
174
	CyString GetSelectedModName();
175
	CyString GetModKey();
176
	void SetupWares();
177
	void SetupShips();
178
	void PurgeGameObjects();
179
	void PurgeWares();
180
	void PurgeShips();
181
	void StartPackage() { m_pPackageNode = m_lPackages.Front(); }
182
	void UpdatePackage(CBaseFile *p);
183
	CBaseFile *GetCurrentPackage() { return (m_pPackageNode) ? m_pPackageNode->Data() : NULL; }
184
	bool RemoveCurrentDirectory();
185
	void RemoveCreatedFiles();
186
	bool AnyUnusedShared();
187
 
188
	// util functions
189
	void RemoveUnusedDirectories(CyStringList &dirs, CyStringList *errors = NULL);
190
	int  RemoveUninstallScripts(CyStringList *errors = 0, CProgressInfo *progress = NULL);
191
	bool RemoveUninstallFile(C_File *file, CyStringList *errors = 0);
192
	int  RemoveUnusedSharedFiles(CyStringList *errors = 0, CProgressInfo *progress = NULL);
193
	bool RemoveSharedFile(C_File *file, CyStringList *errors = NULL);
194
	void ShufflePatchTo(C_File *file, int to, CyStringList *errors);
195
	void ShuffleFakePatches(CyStringList *errors);
196
	void ShuffleTextFiles(CyStringList *errors);
197
	int  FindNextFakePatch(int start = 0, CyString dir = NullString);
198
	int  FindNextTextFile(int start = 2, CyString dir = NullString);
199
	int  FindLastFakePatch(int start = 99, CyString dir = NullString);
200
	int  FindLastTextFile(int start = 9999, CyString dir = NullString);
201
	int  FindLowestFakePatchInstalled();
202
	void ReadGameLanguage(bool force = true);
203
	int	 RemoveAllPackages(CyStringList *errors = NULL, CProgressInfo *progress = NULL);
204
	void AssignPackageNumbers();
205
	int  GetChildPackages(CBaseFile *package, CLinkList<CBaseFile> *children, bool recursive = false);
206
	int  GetAllPackageFiles(CBaseFile *package, CLinkList<C_File> *fileList, bool includeChild);
207
	int	 GetAllPackageFiles(CLinkList<CBaseFile> *list, CLinkList<C_File> *fileList, bool includeChild);
208
	void AddLogEntry(int type, CyString args, CyStringList *errors);
209
	CyString FindDataDir(CyString dir, CyString file);
210
	int  CountPackages(int type, bool onlyEnabled);
211
	int  CountBuiltInPackages(bool onlyEnabled);
212
	bool IsCurrentDir(CyString dir);
213
	bool CheckOtherPackage(CBaseFile *package);
214
	int CheckPreparedInstallRequired(CLinkList<CBaseFile> *list);
215
	static int ConvertWareType(char w);
216
	static char ConvertWareTypeBack(int w);
217
	CyString GetLogDirectory();
218
	CyString GetLogDirectory(CyString gameExe);
219
	CyString GetSaveDirectory();
220
	void BackupSaves() { BackupSaves(m_bVanilla); }
221
	void BackupSaves(bool vanilla);
222
	void RestoreSaves() { RestoreSaves(m_bVanilla); }
223
	void RestoreSaves(bool vanilla);
224
	bool UnPackFile(CyString filename, bool checkxml = true);
225
	bool PackFile(CyString filename);
226
	bool PackFile(CFileIO *File, CyString filename);
84 cycrow 227
	Utils::String ConvertTextString(const Utils::String &text);
1 cycrow 228
	void LoadVirtualFileSystem();
229
	bool CheckAccessRights(CyString dir);
230
	bool LoadShipData(CyString file, CyStringList *list);
35 cycrow 231
	bool LoadShipData(CVirtualFileSystem *pVfs, CyStringList *list);
1 cycrow 232
	bool ReadTextPage(CyString file, CyStringList *list, bool search, int page);
233
	CyStringList *LoadShipData(CyString file);
234
	CyStringList *ReadTextPage(CyString file, bool search, int page);
235
	int AdjustFileType(CyString name, int filetype);
35 cycrow 236
	CXspFile *extractShip(const Utils::String &sCatFile, const Utils::String &sId, CProgressInfo *progress = NULL);
1 cycrow 237
	CyString ReadShipData(CyString file, CyString entry);
238
	bool IsSamePackage(CBaseFile *p1, CBaseFile *p2);
239
	void ApplyFakePatchOrder(CyStringList *list);
240
	CBaseFile *CreateFromArchive(CyString filename, bool toInstall = false );
241
	void ReadArchiveData(const char *buf, size_t len, CBaseFile *archive);
242
	void ReadArchiveData(CyString filename, CBaseFile *archive);
243
	int VerifyInstalledFiles(CyStringList *missingFiles = NULL, bool getPackages = true);
244
 
245
	int GetCurrentGameFlags() { return m_iGameFlags; }
246
 
247
	void SetCurrentDir(CyString dir) { m_sCurrentDir = dir; }
248
 
249
	// merge mods
250
	CyStringList *GetMergedFiles(CCatFile *cat1, CCatFile *cat2);
58 cycrow 251
	bool CanWeMerge(const Utils::String &file) const;
1 cycrow 252
	bool MergeMods(CCatFile *mod1, CCatFile *mod2, CyString outFile, CyStringList *cantMerge);
253
	bool NeedToMerge(CyString file);
254
	CyStringList MergeTextFiles(CyStringList *files, CCatFile *mod1, CCatFile *mod2);
255
	bool GetModCompatabilityList(C_File *file, CyStringList *list = NULL);
256
	bool CheckCompatabilityBetweenModFiles(C_File *from, C_File *to, CyStringList *list = NULL);
257
	bool CheckCompatabilityBetweenMods(CBaseFile *from, CBaseFile *to, CyStringList *list = NULL);
258
	int CheckCompatabilityAgainstPackages(CBaseFile *newFile, CyStringList *list = NULL, CLinkList<CBaseFile> *packages = NULL);
259
 
260
	CyString GetLanguageName();
261
 
262
	int	GetGameLanguage(CyString dir = NullString);
263
	int      GetGameAddons(CyStringList &exes, CyString dir = NullString);
264
	CyString GetGameName(CyString dir = NullString);
265
	CyString GetGameVersionFromType(int game, int version, CyString sVersion);
266
	CyString GetGameNameFromType(int game);
267
	CyString GetGameTypesString(CBaseFile *package, bool includeVersion);
268
	CyString GetGameVersionString(CBaseFile *package);
269
	CyString GetGameRunExe(CyString dir = NullString);
270
	CyString GetProperDir(CyString dir = NullString);
271
	CyString GetAddonDir(CyString dir = NullString);
272
 
273
	// text files
274
	void CreateLanguageTextFiles(CyStringList *errors = 0);
275
	bool RenameTextFile(CyString textid, int languageid, CyStringList *errors);
276
	void AddTextFileToScripts(C_File *file, CyString textid);
277
	void CreatePluginManagerText();
87 cycrow 278
	void createPluginManagerOpenText();
1 cycrow 279
 
280
	// game control
65 cycrow 281
	void CreateEMPFile(CyString progDir = NullString);
1 cycrow 282
	void CreateWareFiles();
283
	int ExtractGameFile(CyString aFilename, CyString aTo, CyString dir = NullString, CyString addon = NullString);
284
	void CreateDummies();
285
	void CreateComponants();
286
	void CreateCutData();
287
	void CreateBodies();
288
	void CreateGlobals();
289
	void CreateAnimations();
290
	void CreateTShips();
291
	CyStringList *CreateCockpits();
292
	void CreateCustomStarts();
293
	void AddCreatedFile(CyString file);
294
	bool ReadGlobals(CyStringList &globals);
295
 
296
	// install text
297
	CyString GetInstallBeforeText(CBaseFile *package);
298
	CyString GetInstallAfterText(CBaseFile *package);
299
	CyString GetUninstallBeforeText(CBaseFile *package);
300
	CyString GetUninstallAfterText(CBaseFile *package);
301
 
302
	// original files
303
	void StoreOriginalFiles(int filetype, CyString searchPath);
304
	void AddOriginalFile(int filetype, CyString filename, CyString searchPath);
305
	C_File *GetOriginalFile(C_File *file);
306
	bool IsOriginalFile(C_File *file);
307
	bool BackupOriginalFile(C_File *f, CyStringList *errors);
308
 
309
	//setting functions
310
	void SetRenameText(bool b) { m_bRenameText = b; }
311
	void SetLanguage(int i) { m_iLanguage = i; }
312
	void SetAutoEnable(bool b) { m_bAutoEnableChild = b; }
313
	void SetForceModInstall(bool b) { m_bForceModInstall = b; }
314
	void SetTempDirectory(CyString s) { m_sTempDir = s; }
315
	void SetMyDocuments(CyString s) { m_sMyDoc = s; }
316
	void SetForceEMP(bool b) { m_bForceEMP = b; }
317
	void SetSurpressProtectedWarning(bool b) { m_bSurpressProtectedWarning = b; }
318
	void SurpressProtectedWarning() { m_bSurpressProtectedWarning = true; }
319
	bool IsSupressProtectedWarning() { return m_bSurpressProtectedWarning; }
320
 
321
	int GetLanguage() { return m_iLanguage; }
322
	int GetGame() { return m_iGame; }
323
	bool IsLoaded() { return m_bLoaded; }
324
	bool IsVanilla() { return m_bVanilla; }
325
	void SetVanilla(bool b);
326
 
327
	CyString GetSetMod() { return m_sSetMod; }
328
	void SetMod(CyString mod) { 
329
		if ( mod != "PluginManager" )
330
			m_sSetMod = mod; 
331
	}
332
 
333
	CBaseFile *GetEnabledMod() { return m_pEnabledMod; }
334
 
335
	//errors
336
	void ClearError() { m_iError = PKERR_NONE; }
337
	int  GetError() { return m_iError; }
338
 
339
	CLinkList<CBaseFile> *PackageList() { return &m_lPackages; }
340
	CLinkList<SAvailablePackage> *GetAvailablePackageList() { return &m_lAvailablePackages; }
341
	bool AnyAvailablePackages(int type = -1);
342
	bool AddAvailablePackage(SAvailablePackage *package);
343
	void ParseAvailablePackage(CyString str, CyString webaddress = NullString);
344
	SAvailablePackage *FindAvailablePackage(CyString &filename);
345
	int FindAllServers(CyStringList *list);
346
 
347
	CBaseFile *FindScriptByAuthor(CyString author, CBaseFile *prev = NULL);
348
	void RemoveFailedFiles();
349
 
350
private:
85 cycrow 351
	bool _checkForDisable(CBaseFile *package, bool disabled, CBaseFile *oldPackage);
43 cycrow 352
	CBaseFile *_archive_fromRar(CyString filename, bool toInstall);
353
	CBaseFile *_archive_fromZip(CyString filename, bool toInstall);
50 cycrow 354
	void _addToFakePatch(CBaseFile *pPackage);
56 cycrow 355
	int _gameTextNumber() const;
43 cycrow 356
 
357
private:
1 cycrow 358
	CyString	m_sCurrentDir;
79 cycrow 359
	static CyString	m_sTempDir;
1 cycrow 360
	CyString	m_sMyDoc;
361
	CyString	m_sSetMod;
362
	CyString	m_sActiveDir;
363
 
364
	// global files list
365
	CLinkList<C_File>		m_lFiles;
366
	CLinkList<CBaseFile>	m_lPackages;
367
	CLinkList<C_File>		m_lUninstallFiles;
368
	CLinkList<C_File>		m_lOriginalFiles;
369
	CLinkList<SGameWare>	m_lGameWares[WAREBUFFERS];
370
	CLinkList<SGameShip>	m_lGameShips;
371
 
372
	// prepared lists
373
	CLinkList<CBaseFile>	m_lInstallList; // install/uninstalling packages
374
	CLinkList<CBaseFile>	m_lEnableList;  // enable packages
375
	CLinkList<CBaseFile>	m_lDisableList; // disable packages
376
 
377
	CyStringList			m_lCreatedFiles; // list of files we've created
378
	CyStringList			m_lNonRemovedFiles; // list of fiels that couldn't be removed for some reason
379
	CyStringList			m_lGlobals; // global settigns that we want changed
380
	CyStringList			m_lFakePatchOrder; // ordered fake patches
381
	CLinkList<SAvailablePackage> m_lAvailablePackages; // list of available packages online
382
 
383
	CVirtualFileSystem		m_pGameVFS; // Games Virtual File System
384
 
385
	CGameExe				m_gameExe;
56 cycrow 386
	SGameExe				*m_pCurrentGameExe;
1 cycrow 387
	CBaseFile			   *m_pEnabledMod;
388
 
389
	// settings
390
	bool		m_bRenameText;  // rename text files
391
	bool		m_bAutoEnableChild;	// auto enable all children
392
	bool		m_bForceModInstall; // allowsm ultiple mods to be installed
393
	bool		m_bOldPlugin;		// if its loading data from the old plugin manager
394
	bool		m_bLoadVFS;			// if we should load the virtual filesystem
395
	int			m_iLanguage;	// Language id to use
396
	int			m_iSaveGameManager; // Save game manager
397
	bool		m_bSurpressProtectedWarning; // prevent checking for protected directory
398
 
399
	int			m_iGame;		// the game the directory is
400
	int			m_iGameVersion; // the version of the game (version position)
401
	CyString	m_sGameVersion; // the version of the game (full version)
402
	int			m_iGameFlags;	// the flags for the game from SGameExe
403
	int			m_iMaxPatch;	// the maximum patch for the game
404
 
405
	int			m_iSaveGame;
406
	int			m_iError;
407
	int			m_iLastUpdated;
408
	int			m_iFakePatch;		// The current fake patch
409
 
410
	bool		m_bVanilla;		// currently in vanilla mode, dont allow unsigned packages to be installed
411
 
412
	bool		m_bLoaded;
413
	bool		m_bRedo;
414
	bool		m_bUsedWare;	// if we have used the ware files in the directory, not in a patch
415
	bool		m_bRemoveDir;	// shall we remove direcotires;
416
 
417
	int			m_iWareBuffer[WAREBUFFERS];	//Ware Buffers
418
	int			m_iShipBuffer; //Ship Buffers
419
 
420
	bool		m_bDisableVanilla;
421
	bool		m_bForceEMP;
422
 
423
	CListNode<CBaseFile>	*m_pPackageNode;
424
};
425
 
426
#endif // __PACKAGES_H__