Subversion Repositories spk

Rev

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