Subversion Repositories spk

Rev

Rev 196 | Rev 199 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 196 Rev 197
Line 28... Line 28...
28
typedef struct SComponantEntry {
28
typedef struct SComponantEntry {
29
	Utils::String		sSection;
29
	Utils::String		sSection;
30
	CLinkList<SComponantEntry2>	lEntries;
30
	CLinkList<SComponantEntry2>	lEntries;
31
} SComponantEntry;
31
} SComponantEntry;
32
 
32
 
33
Utils::String CPackages::m_sTempDir;
33
Utils::WString CPackages::m_sTempDir;
34
 
34
 
35
//////////////////////////////////////////////////////////////////////////////////////
35
//////////////////////////////////////////////////////////////////////////////////////
36
 
36
 
37
//////////////////////////////////////////////////////////////////////////////////////
37
//////////////////////////////////////////////////////////////////////////////////////
38
 
38
 
Line 74... Line 74...
74
	m_lDisableList.clear();
74
	m_lDisableList.clear();
75
	m_lEnableList.clear();
75
	m_lEnableList.clear();
76
	this->Reset();
76
	this->Reset();
77
}
77
}
78
 
78
 
79
void CPackages::setCurrentDir(const Utils::String &dir)
79
void CPackages::setCurrentDir(const Utils::WString &dir)
80
{ 
80
{ 
81
	m_sCurrentDir = dir;
81
	m_sCurrentDir = dir;
82
	if (_pCurrentDir) delete _pCurrentDir;
82
	if (_pCurrentDir) delete _pCurrentDir;
83
	_pCurrentDir = new GameDirectory();
83
	_pCurrentDir = new GameDirectory();
84
	_pCurrentDir->dir = dir;
84
	_pCurrentDir->dir = dir;
85
	_pCurrentDir->id = -1;
85
	_pCurrentDir->id = -1;
86
 
86
 
87
	m_gameExe.GetDirectoryData(_pCurrentDir);
87
	m_gameExe.getDirectoryData(_pCurrentDir);
88
	_pCurrentDir->langid = this->getGameLanguage(_pCurrentDir->dir);
88
	_pCurrentDir->langid = this->getGameLanguage(_pCurrentDir->dir.toString());
89
	if (_pCurrentDir->langid > 0)
89
	if (_pCurrentDir->langid > 0)
90
		_pCurrentDir->langname = this->ConvertLanguage(_pCurrentDir->langid);
90
		_pCurrentDir->langname = this->ConvertLanguage(_pCurrentDir->langid).toWString();
91
 
91
 
92
	updateFoundPackages("");
92
	updateFoundPackages("");
93
}
93
}
94
 
94
 
95
 
95
 
Line 101... Line 101...
101
		}
101
		}
102
	}
102
	}
103
	m_bVanilla = b;
103
	m_bVanilla = b;
104
}
104
}
105
 
105
 
106
void CPackages::setMod(const Utils::String &mod)
106
void CPackages::setMod(const Utils::WString &mod)
107
{
107
{
108
	if (mod != "PluginManager")
108
	if (mod != L"PluginManager")
109
		m_sSetMod = mod;
109
		m_sSetMod = mod;
110
}
110
}
111
 
111
 
112
void CPackages::setSaveGameManager(bool managed)
112
void CPackages::setSaveGameManager(bool managed)
113
{
113
{
Line 118... Line 118...
118
		// find new save directory
118
		// find new save directory
119
		CDirIO dir(this->saveDirectory());
119
		CDirIO dir(this->saveDirectory());
120
		if (dir.exists())
120
		if (dir.exists())
121
		{
121
		{
122
			int id = 1;
122
			int id = 1;
123
			while (dir.exists(Utils::String::PadNumber(id, 4)))
123
			while (dir.exists(Utils::WString::PadNumber(id, 4)))
124
				++id;
124
				++id;
125
			Utils::String d = Utils::String::PadNumber(id, 4);
125
			Utils::WString d = Utils::WString::PadNumber(id, 4);
126
			dir.create(d);
126
			dir.create(d);
127
			_sSaveDir = d;
127
			_sSaveDir = d;
128
 
128
 
129
			CDirIO destDir1(dir.dir(d));
129
			CDirIO destDir1(dir.dir(d));
130
			destDir1.create("Vanilla");
130
			destDir1.create(L"Vanilla");
131
			destDir1.cd("Vanilla");
131
			destDir1.cd(L"Vanilla");
132
			CDirIO destDir2(dir.dir(d));
132
			CDirIO destDir2(dir.dir(d));
133
			destDir2.create("Modified");
133
			destDir2.create(L"Modified");
134
			destDir2.cd("Modified");
134
			destDir2.cd(L"Modified");
135
 
135
 
136
			Utils::CStringList files;
136
			Utils::WStringList files;
137
			if (dir.dirList(files, Utils::String::Null(), "*.sav"))
137
			if (dir.dirList(files, Utils::WString::Null(), L"*.sav"))
138
			{
138
			{
139
				for (auto itr = files.begin(); itr != files.end(); ++itr)
139
				for (auto itr = files.begin(); itr != files.end(); ++itr)
140
				{
140
				{
141
					Utils::WString f = dir.file((*itr)->str);
141
					Utils::WString f = dir.file((*itr)->str);
142
					CFileIO(f).copy(destDir1.file((*itr)->str));
142
					CFileIO(f).copy(destDir1.file((*itr)->str));
Line 187... Line 187...
187
	m_lFoundPackages.MemoryClear();
187
	m_lFoundPackages.MemoryClear();
188
	m_lInstallList.MemoryClear();
188
	m_lInstallList.MemoryClear();
189
	m_lEnableList.MemoryClear();
189
	m_lEnableList.MemoryClear();
190
	m_lDisableList.MemoryClear();
190
	m_lDisableList.MemoryClear();
191
 
191
 
192
	m_lCreatedFiles.clear();
192
	_lCreatedFiles.clear();
193
	m_lNonRemovedFiles.clear();
193
	_lNonRemovedFiles.clear();
194
	m_lGlobals.clear();
194
	_lGlobals.clear();
195
	m_lFakePatchOrder.clear();
195
	_lFakePatchOrder.clear();
196
	if (_pCurrentDir)
196
	if (_pCurrentDir)
197
		delete _pCurrentDir;
197
		delete _pCurrentDir;
198
	_pCurrentDir = NULL;
198
	_pCurrentDir = NULL;
199
}
199
}
200
 
200
 
Line 252... Line 252...
252
	}
252
	}
253
 
253
 
254
	return oldPlugin;
254
	return oldPlugin;
255
}
255
}
256
 
256
 
257
bool CPackages::read(const Utils::String& dir, CProgressInfo* progress)
257
bool CPackages::read(const Utils::WString& dir, CProgressInfo* progress)
258
{
258
{
259
	m_sCurrentDir = dir;
259
	m_sCurrentDir = dir;
260
	m_sCurrentDir = m_sCurrentDir.findReplace("\\", "/");
260
	m_sCurrentDir = m_sCurrentDir.findReplace("\\", "/");
261
	this->setCurrentDir(dir);
261
	this->setCurrentDir(dir);
262
	m_bOldPlugin = false;
262
	m_bOldPlugin = false;
263
	m_lCreatedFiles.clear();
263
	_lCreatedFiles.clear();
264
	m_bRemoveDir = false;
264
	m_bRemoveDir = false;
265
	m_bSurpressProtectedWarning = false;
265
	m_bSurpressProtectedWarning = false;
266
	m_iSaveGame = -1;
266
	m_iSaveGame = -1;
267
	m_iSaveGameManager = -1;
267
	m_iSaveGameManager = -1;
268
	m_lNonRemovedFiles.clear();
268
	_lNonRemovedFiles.clear();
269
	m_lGlobals.clear();
269
	_lGlobals.clear();
270
	m_lFakePatchOrder.clear();
270
	_lFakePatchOrder.clear();
271
 
271
 
272
	if ( _pOriginalFiles ) delete _pOriginalFiles;
272
	if ( _pOriginalFiles ) delete _pOriginalFiles;
273
	_pOriginalFiles = new COriginalFiles(m_sCurrentDir);
273
	_pOriginalFiles = new COriginalFiles(m_sCurrentDir);
274
 
274
 
275
	m_bVanilla = true;
275
	m_bVanilla = true;
276
 
276
 
277
	// check the pluginmanager data file exists
277
	// check the pluginmanager data file exists
278
	CFileIO datFile(m_sCurrentDir + "/PluginManager/pluginmanager.dat");
278
	CFileIO datFile(m_sCurrentDir + L"/PluginManager/pluginmanager.dat");
279
	if ( datFile.exists() )
279
	if ( datFile.exists() )
280
	{
280
	{
281
		std::vector<Utils::String> *readFile = datFile.readLines();
281
		std::vector<Utils::WString> readFile;
282
		if ( readFile )
282
		if(datFile.readLines(readFile))
283
		{
283
		{
284
			float fVersion = 0;
284
			float fVersion = 0;
285
			bool spkinstaller = false;
285
			bool spkinstaller = false;
286
			float fBeta = 0;
286
			float fBeta = 0;
287
 
287
 
Line 289... Line 289...
289
			int iCount = 0;
289
			int iCount = 0;
290
			int iWare = -1;
290
			int iWare = -1;
291
			int iShip = -1;
291
			int iShip = -1;
292
 
292
 
293
			CBaseFile *packageFile = 0;
293
			CBaseFile *packageFile = 0;
294
 
294
 
295
			for ( int i = 0; i < (int)readFile->size(); i++ )
295
			for ( int i = 0; i < (int)readFile.size(); i++ )
296
			{
296
			{
297
				Utils::String line(readFile->at(i));
297
				Utils::WString line(readFile.at(i));
298
 
298
 
299
				Utils::String cmd = line.token(":", 1).lower();
299
				Utils::WString cmd = line.token(L":", 1).lower();
300
				Utils::String rest = line.tokens(":", 2).removeFirstSpace();
300
				Utils::WString rest = line.tokens(L":", 2).removeFirstSpace();
301
 
301
 
302
				if ( iStatus == READ_GLOBAL )
302
				if ( iStatus == READ_GLOBAL )
303
				{
303
				{
304
					if ( cmd == "<script>" )
304
					if ( cmd == L"<script>" )
305
					{
305
					{
306
						packageFile = new CSpkFile();
306
						packageFile = new CSpkFile();
307
						iStatus = READ_SCRIPT;
307
						iStatus = READ_SCRIPT;
308
					}
308
					}
309
					else if ( cmd == "<ship>" )
309
					else if ( cmd == L"<ship>" )
310
					{
310
					{
311
						packageFile = new CXspFile();
311
						packageFile = new CXspFile();
312
						iStatus = READ_SCRIPT;
312
						iStatus = READ_SCRIPT;
313
					}
313
					}
314
					else if ( cmd == "<base>" )
314
					else if ( cmd == L"<base>" )
315
					{
315
					{
316
						packageFile = new CBaseFile();
316
						packageFile = new CBaseFile();
317
						iStatus = READ_SCRIPT;
317
						iStatus = READ_SCRIPT;
318
					}
318
					}
319
					else if ( cmd == "<archive>" )
319
					else if ( cmd == L"<archive>" )
320
					{
320
					{
321
						packageFile = new CArchiveFile();
321
						packageFile = new CArchiveFile();
322
						iStatus = READ_SCRIPT;
322
						iStatus = READ_SCRIPT;
323
					}
323
					}
324
					else if ( cmd != "</scripts>" )
324
					else if ( cmd != L"</scripts>" )
325
					{
325
					{
326
						int game = 0;
326
						int game = 0;
327
						bool disabled = false;
327
						bool disabled = false;
328
						Utils::String fileName = line.tokens(":", 5);
328
						Utils::WString fileName = line.tokens(L":", 5);
329
						Utils::String origName;
329
						Utils::WString origName;
330
						if ( fileName.left(2) == "D#" )
330
						if ( fileName.left(2) == L"D#" )
331
						{
331
						{
332
							fileName.erase(0, 2);
332
							fileName.erase(0, 2);
333
							disabled = true;
333
							disabled = true;
334
						}
334
						}
335
						if ( fileName.left(2) == "G#" ) {
335
						if ( fileName.left(2) == L"G#" ) {
336
							fileName.erase(0, 2);
336
							fileName.erase(0, 2);
337
							game = fileName.token("#", 1).toLong();
337
							game = fileName.token(L"#", 1).toLong();
338
							fileName = fileName.tokens("#", 2);
338
							fileName = fileName.tokens(L"#", 2);
339
						}
339
						}
340
						if ( fileName.isin("O#") )
340
						if ( fileName.isin(L"O#") )
341
						{
341
						{
342
							origName = fileName.token("O#", 2);
342
							origName = fileName.token(L"O#", 2);
343
							fileName = fileName.token("O#", 1);
343
							fileName = fileName.token(L"O#", 1);
344
						}
344
						}
345
 
345
 
346
						C_File *newFile = new C_File(m_sCurrentDir + fileName);
346
						C_File *newFile = new C_File(m_sCurrentDir + fileName);
347
						newFile->setGame(game);
347
						newFile->setGame(game);
348
						newFile->SetOriginalName(origName);
348
						newFile->SetOriginalName(origName);
349
						newFile->SetDisabled(disabled);
349
						newFile->SetDisabled(disabled);
350
						newFile->setFileType((FileType)line.token(&quot;:", 1).toLong());
350
						newFile->setFileType(static_cast<FileType>(line.token(L&quot;:", 1).toLong()));
351
						newFile->SetCreationTime((time_t)line.token(&quot;:", 2).toLong());
351
						newFile->SetCreationTime(static_cast<time_t>(line.token(L&quot;:", 2).toLong()));
352
						newFile->setDir(line.token(":", 3));
352
						newFile->setDir(line.token(L":", 3));
353
						if ( line.token(":", 4).toLong() )
353
						if ( line.token(L":", 4).toLong() )
354
							newFile->SetShared(true);
354
							newFile->SetShared(true);
355
						newFile->UpdateSigned();
355
						newFile->UpdateSigned();
356
 
356
 
357
						m_lFiles.push_back(newFile);
357
						m_lFiles.push_back(newFile);
358
					}
358
					}
359
				}
359
				}
360
				else if ( iStatus == READ_SCRIPT )
360
				else if ( iStatus == READ_SCRIPT )
361
				{
361
				{
362
					if ( cmd == "installspk" )
362
					if ( cmd == L"installspk" )
363
						packageFile->setFilename(rest);
363
						packageFile->setFilename(rest);
364
					else if ( cmd == "files" )
364
					else if ( cmd == L"files" )
365
					{
365
					{
366
						iStatus = READ_SCRIPTFILE;
366
						iStatus = READ_SCRIPTFILE;
367
						if ( spkinstaller )
367
						if ( spkinstaller )
368
						{
368
						{
369
							int max;
369
							std::vector<Utils::WString> files;
370
							Utils::String *files = rest.tokenise("; ", &amp;max);
370
							rest.tokenise(L"; &quot;, files);
371
 
-
 
372
							for ( int i = 0; i < max; i++ )
371
							for (size_t i = 0; i < files.size(); i++ )
373
							{
372
							{
374
								int fileNum = files[i].toLong();
373
								int fileNum = files[i].toLong();
375
								if ( fileNum >= 0 && fileNum < m_lFiles.size() )
374
								if ( fileNum >= 0 && fileNum < m_lFiles.size() )
376
									packageFile->AddFile(m_lFiles[fileNum]);
375
									packageFile->AddFile(m_lFiles[fileNum]);
377
							}
376
							}
378
 
-
 
379
							CLEANSPLIT(files, max);
-
 
380
						}
377
						}
381
					}
378
					}
382
					else if ( cmd == "disabled" )
379
					else if ( cmd == L"disabled" )
383
						packageFile->SetEnabled(false);
380
						packageFile->SetEnabled(false);
384
					else if ( cmd == "modifieddisabled" )
381
					else if ( cmd == L"modifieddisabled" )
385
						packageFile->SetModifiedEnabled(false);
382
						packageFile->SetModifiedEnabled(false);
386
					else if ( cmd == "icon" )
383
					else if ( cmd == L"icon" )
387
					{
384
					{
388
						C_File *icon = new C_File(rest.tokens(" ", 2));
385
						C_File *icon = new C_File(rest.tokens(L" ", 2));
389
						packageFile->setIcon(icon, rest.token(" ", 1));
386
						packageFile->setIcon(icon, rest.token(L" ", 1).toString());
390
					}
387
					}
391
					else
388
					else
392
						packageFile->ParseValueLine(line);
389
						packageFile->ParseValueLine(line.toString());
393
				}
390
				}
394
				else if ( iStatus == READ_SCRIPTFILE )
391
				else if ( iStatus == READ_SCRIPTFILE )
395
				{
392
				{
396
					if ( cmd == "<script>" )
393
					if ( cmd == L"<script>" )
397
					{
394
					{
398
						if ( packageFile->IsMod() && packageFile->IsEnabled() )
395
						if ( packageFile->IsMod() && packageFile->IsEnabled() )
399
							m_pEnabledMod = packageFile;
396
							m_pEnabledMod = packageFile;
400
 
397
 
401
						m_lPackages.push_back(packageFile);
398
						m_lPackages.push_back(packageFile);
402
						this->ConvertOldPackage(packageFile);
399
						this->ConvertOldPackage(packageFile);
403
						packageFile = new CSpkFile();
400
						packageFile = new CSpkFile();
404
						iStatus = READ_SCRIPT;
401
						iStatus = READ_SCRIPT;
405
 
402
 
406
					}
403
					}
407
					else if ( cmd == "<ship>" )
404
					else if ( cmd == L"<ship>" )
-
 
405
					{
-
 
406
						m_lPackages.push_back(packageFile);
-
 
407
						this->ConvertOldPackage(packageFile);
-
 
408
						packageFile = new CXspFile();
-
 
409
						iStatus = READ_SCRIPT;
-
 
410
					}
-
 
411
					else if ( cmd == L"<base>" )
408
					{
412
					{
409
						m_lPackages.push_back(packageFile);
413
						m_lPackages.push_back(packageFile);
410
						this->ConvertOldPackage(packageFile);
414
						this->ConvertOldPackage(packageFile);
411
						packageFile = new CXspFile();
415
						packageFile = new CBaseFile();
412
						iStatus = READ_SCRIPT;
416
						iStatus = READ_SCRIPT;
413
					}
417
					}
414
					else if ( cmd == "<base>" )
-
 
415
					{
-
 
416
						m_lPackages.push_back(packageFile);
-
 
417
						this->ConvertOldPackage(packageFile);
-
 
418
						packageFile = new CBaseFile();
-
 
419
						iStatus = READ_SCRIPT;
-
 
420
					}
-
 
421
					else if ( cmd == "<archive>" )
418
					else if ( cmd == L"<archive>" )
422
					{
419
					{
423
						m_lPackages.push_back(packageFile);
420
						m_lPackages.push_back(packageFile);
424
						this->ConvertOldPackage(packageFile);
421
						this->ConvertOldPackage(packageFile);
425
						packageFile = new CArchiveFile();
422
						packageFile = new CArchiveFile();
426
						iStatus = READ_SCRIPT;
423
						iStatus = READ_SCRIPT;
427
					}
424
					}
428
					else if ( cmd == "</scripts>" )
425
					else if ( cmd == L"</scripts>" )
429
					{
426
					{
430
						if ( packageFile->IsMod() && packageFile->IsEnabled() )
427
						if ( packageFile->IsMod() && packageFile->IsEnabled() )
431
							m_pEnabledMod = packageFile;
428
							m_pEnabledMod = packageFile;
432
 
429
 
433
						m_lPackages.push_back(packageFile);
430
						m_lPackages.push_back(packageFile);
434
						this->ConvertOldPackage(packageFile);
431
						this->ConvertOldPackage(packageFile);
435
					}
432
					}
436
					else
433
					else
437
					{
434
					{
438
						int fileNum = line.token("::", 1).toLong();
435
						int fileNum = line.token(L"::", 1).toLong();
439
						if ( fileNum >= 0 && fileNum < m_lFiles.size() )
436
						if ( fileNum >= 0 && fileNum < m_lFiles.size() )
440
							packageFile->AddFile(m_lFiles[fileNum]);
437
							packageFile->AddFile(m_lFiles[fileNum]);
441
					}
438
					}
442
				}
439
				}
443
				else if ( iWare != -1 )
440
				else if ( iWare != -1 )
444
				{
441
				{
445
					--iCount;
442
					--iCount;
446
 
443
 
447
					SGameWare *gm = new SGameWare;
444
					SGameWare *gm = new SGameWare;
448
					gm->iPos = line.token(" ", 1).toLong();
445
					gm->iPos = line.token(L" ", 1).toLong();
449
					gm->iType = line.token(" ", 2).toLong();
446
					gm->iType = line.token(L" ", 2).toLong();
450
					gm->cType = line.token(" ", 3)[0];
447
					gm->cType = line.token(L" ", 3)[0];
451
					gm->pWare = NULL;
448
					gm->pWare = NULL;
452
					gm->sWareName = line.tokens(" ", 4);
449
					gm->sWareName = line.tokens(L" ", 4);
453
					m_lGameWares[iWare].push_back(gm);
450
					m_lGameWares[iWare].push_back(gm);
454
					if ( iCount <= 0 )
451
					if ( iCount <= 0 )
455
						iWare = -1;
452
						iWare = -1;
456
				}
453
				}
457
				else if ( iShip != -1 )
454
				else if ( iShip != -1 )
458
				{
455
				{
459
					--iCount;
456
					--iCount;
460
 
457
 
461
					SGameShip *gm = new SGameShip;
458
					SGameShip *gm = new SGameShip;
462
					gm->iType = line.token(" ", 1).toLong();
459
					gm->iType = line.token(L" ", 1).toLong();
463
					if ( line.token(" ", 2).left(4) == "$#C:" )
460
					if ( line.token(L" ", 2).left(4) == L"$#C:" )
464
					{
461
					{
465
						gm->sShipClass = line.token(" ", 2).right(-4);
462
						gm->sShipClass = line.token(L" ", 2).right(-4);
466
						gm->sShipID = line.tokens(" ", 3);
463
						gm->sShipID = line.tokens(L" ", 3);
467
					}
464
					}
468
					else
465
					else
469
					{
466
					{
470
						gm->sShipID = line.tokens(" ", 2);
467
						gm->sShipID = line.tokens(L" ", 2);
471
						gm->sShipClass = "OBJ_SHIP_M5";
468
						gm->sShipClass = L"OBJ_SHIP_M5";
472
					}
469
					}
473
					gm->pPackage = NULL;
470
					gm->pPackage = NULL;
474
					m_lGameShips.push_back(gm);
471
					m_lGameShips.push_back(gm);
475
					if ( iCount <= 0 )
472
					if ( iCount <= 0 )
476
						iShip = -1;
473
						iShip = -1;
477
				}
474
				}
478
				else if ( cmd.Compare("savegamemanager") )
475
				else if ( cmd.Compare(L"savegamemanager") )
479
					m_iSaveGameManager = rest.toLong();
476
					m_iSaveGameManager = rest.toLong();
480
				else if ( cmd.Compare("savegame") )
477
				else if ( cmd.Compare(L"savegame") )
481
					m_iSaveGame = rest.toLong();
478
					m_iSaveGame = rest.toLong();
482
				else if ( cmd == "fakepatch" )
479
				else if ( cmd == L"fakepatch" )
483
					m_iFakePatch = rest.toLong();
480
					m_iFakePatch = rest.toLong();
484
				else if ( cmd == "updatetime" )
481
				else if ( cmd == L"updatetime" )
485
					m_iLastUpdated = rest.toLong();
482
					m_iLastUpdated = rest.toLong();
486
				else if ( cmd == "surpressprotectedwarning" )
483
				else if ( cmd == L"surpressprotectedwarning" )
487
					m_bSurpressProtectedWarning = true;
484
					m_bSurpressProtectedWarning = true;
488
				else if ( cmd == "pluginmanager" )
485
				else if ( cmd == L"pluginmanager" )
489
				{
486
				{
490
					fVersion = rest.toFloat();
487
					fVersion = rest.toFloat();
491
					m_bOldPlugin = true;
488
					m_bOldPlugin = true;
492
				}
489
				}
493
				else if ( cmd == "setmod" )
490
				else if ( cmd == L"setmod" )
494
					m_sSetMod = rest;
491
					m_sSetMod = rest;
495
				else if ( cmd == "shipbuffer" )
492
				else if ( cmd == L"shipbuffer" )
496
					m_iShipBuffer = rest.toLong();
493
					m_iShipBuffer = rest.toLong();
497
				else if(cmd == "savedir")
494
				else if(cmd == L"savedir")
498
					_sSaveDir = rest;
495
					_sSaveDir = rest;
499
				else if ( cmd == "warebuffers" )
496
				else if ( cmd == L"warebuffers" )
500
				{
497
				{
501
					int max = rest.countToken(" ");
498
					int max = rest.countToken(L" ");
502
					for ( int i = 0; i < WAREBUFFERS; i++ )
499
					for ( int i = 0; i < WAREBUFFERS; i++ )
503
					{
500
					{
504
						if ( i > max )
501
						if ( i > max )
505
							m_iWareBuffer[i] = 0;
502
							m_iWareBuffer[i] = 0;
506
						else
503
						else
507
							m_iWareBuffer[i] = rest.token(" ", i + 1).toLong();
504
							m_iWareBuffer[i] = rest.token(L" ", i + 1).toLong();
508
					}
505
					}
509
				}
506
				}
510
				else if ( cmd == "createdfile" )
507
				else if ( cmd == L"createdfile" )
511
					m_lCreatedFiles.pushBack(rest);
508
					_lCreatedFiles.pushBack(rest);
512
				else if ( cmd == "wares" )
509
				else if ( cmd == L"wares" )
513
				{
510
				{
514
					iWare = rest.token(" ", 1).toLong();
511
					iWare = rest.token(L" ", 1).toLong();
515
					iCount = rest.token(" ", 2).toLong();
512
					iCount = rest.token(L" ", 2).toLong();
516
				}
513
				}
517
				else if ( cmd == "ships" )
514
				else if ( cmd == L"ships" )
518
				{
515
				{
519
					iShip = 1;
516
					iShip = 1;
520
					iCount = rest.token(" ", 1).toLong();
517
					iCount = rest.token(L" ", 1).toLong();
521
				}
518
				}
522
				else if ( cmd == "modified" )
519
				else if ( cmd == L"modified" )
523
					m_bVanilla = false;
520
					m_bVanilla = false;
524
				else if ( cmd == "spkinstaller" )
521
				else if ( cmd == L"spkinstaller" )
525
				{
522
				{
526
					fVersion = rest.toFloat();
523
					fVersion = rest.toFloat();
527
					spkinstaller = true;
524
					spkinstaller = true;
528
				}
525
				}
529
				else if ( cmd == "betaversion" )
526
				else if ( cmd == L"betaversion" )
530
					fBeta = rest.toFloat();
527
					fBeta = rest.toFloat();
531
				else if ( cmd == "uninstall" )
528
				else if ( cmd == L"uninstall" )
532
				{
529
				{
533
					C_File *uf = new C_File();
530
					C_File *uf = new C_File();
534
					uf->setFileType(FILETYPE_SCRIPT);
531
					uf->setFileType(FILETYPE_SCRIPT);
535
					uf->SetCreationTime(rest.token(" ", 1).toLong());
532
					uf->SetCreationTime(rest.token(L" ", 1).toLong());
536
					uf->setFilename(m_sCurrentDir + "/Scripts/" + rest.tokens(" ", 2));
533
					uf->setFilename(m_sCurrentDir + L"/Scripts/" + rest.tokens(L" ", 2));
537
					m_lUninstallFiles.push_back(uf);
534
					m_lUninstallFiles.push_back(uf);
538
				}
535
				}
539
				else if ( cmd == "nonremovedfile" )
536
				else if ( cmd == L"nonremovedfile" )
540
				{
537
				{
541
					if ( !CFileIO::Remove(rest) )
538
					if ( !CFileIO::Remove(rest) )
542
						m_lNonRemovedFiles.pushBack(rest);
539
						_lNonRemovedFiles.pushBack(rest);
543
				}
540
				}
544
				else if ( cmd == "original" )
541
				else if ( cmd == L"original" )
545
					_pOriginalFiles->parse(rest);
542
					_pOriginalFiles->parse(rest);
546
				else if ( cmd.Compare("GlobalSetting") )
543
				else if ( cmd.Compare(L"GlobalSetting") )
547
					m_lGlobals.pushBack(rest.token(":", 1), rest.tokens(":", 2));
544
					_lGlobals.pushBack(rest.token(L":", 1), rest.tokens(L":", 2));
548
				else if ( cmd.Compare("FakePatchOrder") )
545
				else if ( cmd.Compare(L"FakePatchOrder") )
549
					m_lFakePatchOrder.pushBack(rest.token(":", 1), rest.tokens(":", 2));
546
					_lFakePatchOrder.pushBack(rest.token(L":", 1), rest.tokens(L":", 2));
550
				else if ( cmd.Compare("EMPPriceOverride") )
547
				else if ( cmd.Compare(L"EMPPriceOverride") )
551
					this->addEMPPriceOverride(rest.token(" ", 1).toLong(), rest.token(" ", 2).toLong());
548
					this->addEMPPriceOverride(rest.token(L" ", 1).toLong(), rest.token(L" ", 2).toLong());
552
				else if ( cmd.Compare("EMPNotoOverride") )
549
				else if ( cmd.Compare(L"EMPNotoOverride") )
553
					this->addEMPNotoOverride(rest.token(" ", 1).toLong(), rest.token(" ", 2).toLong());
550
					this->addEMPNotoOverride(rest.token(L" ", 1).toLong(), rest.token(L" ", 2).toLong());
554
				else if ( cmd.Compare("BuiltInWarePriceOverride") )
551
				else if ( cmd.Compare(L"BuiltInWarePriceOverride") )
555
					this->addBuiltInWarePriceOverride(rest.token(" ", 1).toLong(), rest.token(" ", 2).toLong());
552
					this->addBuiltInWarePriceOverride(rest.token(L" ", 1).toLong(), rest.token(L" ", 2).toLong());
556
				else if ( cmd.Compare("BuiltInWareNotoOverride") )
553
				else if ( cmd.Compare(L"BuiltInWareNotoOverride") )
557
					this->addBuiltInWareNotoOverride(rest.token(" ", 1).toLong(), rest.token(" ", 2).toLong());
554
					this->addBuiltInWareNotoOverride(rest.token(L" ", 1).toLong(), rest.token(L" ", 2).toLong());
558
				else if ( cmd.Compare("CustomWarePriceOverride") )
555
				else if ( cmd.Compare(L"CustomWarePriceOverride") )
559
					this->addCustomWarePriceOverride(rest.token(";", 1), rest.token(";", 2).toLong());
556
					this->addCustomWarePriceOverride(rest.token(L";", 1), rest.token(L";", 2).toLong());
560
				else if ( cmd.Compare("CustomWareNotoOverride") )
557
				else if ( cmd.Compare(L"CustomWareNotoOverride") )
561
					this->addCustomWareNotoOverride(rest.token(";", 1), rest.token(";", 2).toLong());
558
					this->addCustomWareNotoOverride(rest.token(L";", 1), rest.token(L";", 2).toLong());
562
				else if ( cmd == "globalfiles" )
559
				else if ( cmd == L"globalfiles" )
563
					iStatus = READ_GLOBAL;
560
					iStatus = READ_GLOBAL;
564
 
561
 
565
				if ( progress )
562
				if ( progress )
566
				{
563
				{
567
					progress->UpdateProgress((long)i, (long)readFile->size());
564
					progress->UpdateProgress((long)i, static_cast<long>(readFile.size()));
568
				}
565
				}
569
			}
566
			}
570
			readFile->clear();
567
			readFile.clear();
571
 
568
 
572
			if ( !spkinstaller )
569
			if ( !spkinstaller )
573
				m_bRedo = true;
570
				m_bRedo = true;
574
 
-
 
575
			delete readFile;
-
 
576
		}
571
		}
577
	}
572
	}
578
 
573
 
579
	if ( m_pEnabledMod && !m_pEnabledMod->IsEnabled() )
574
	if ( m_pEnabledMod && !m_pEnabledMod->IsEnabled() )
580
		m_pEnabledMod = NULL;
575
		m_pEnabledMod = NULL;
581
 
576
 
582
	m_iGame = m_gameExe.GetGameType(m_sCurrentDir) + 1;
577
	m_iGame = m_gameExe.getGameType(m_sCurrentDir) + 1;
583
	m_pCurrentGameExe = m_gameExe.GetGame(m_gameExe.GetGameType(m_sCurrentDir));
578
	m_pCurrentGameExe = m_gameExe.game(m_gameExe.getGameType(m_sCurrentDir));
584
	Utils::String sGameVersion;
579
	Utils::WString sGameVersion;
585
	m_iGameVersion = m_gameExe.GetGameVersion(m_sCurrentDir, &sGameVersion) + 1;
580
	m_iGameVersion = m_gameExe.getGameVersion(m_sCurrentDir, &sGameVersion) + 1;
586
	m_sGameVersion = sGameVersion;
581
	_sGameVersion = sGameVersion;
587
	m_iGameFlags = m_gameExe.GetGameFlags(m_iGame - 1);
582
	m_iGameFlags = m_gameExe.gameFlags(m_iGame - 1);
588
	m_iMaxPatch = m_gameExe.GetMaxPatch(m_iGame - 1);
583
	m_iMaxPatch = m_gameExe.maxPatch(m_iGame - 1);
589
 
584
 
590
	// find the fake patch
585
	// find the fake patch
591
	if ( !ReadyFakePatch() )
586
	if ( !ReadyFakePatch() )
592
		return false;
587
		return false;
593
 
588
 
Line 616... Line 611...
616
		else if ( node->Data()->GetType() == TYPE_XSP )
611
		else if ( node->Data()->GetType() == TYPE_XSP )
617
		{
612
		{
618
			CXspFile *p = (CXspFile *)node->Data();
613
			CXspFile *p = (CXspFile *)node->Data();
619
			for ( CListNode<SGameShip> *gNode = m_lGameShips.Front(); gNode; gNode = gNode->next() )
614
			for ( CListNode<SGameShip> *gNode = m_lGameShips.Front(); gNode; gNode = gNode->next() )
620
			{
615
			{
621
				if ( p->GetShipID().Compare(gNode->Data()->sShipID) )
616
				if ( p->GetShipID().Compare(gNode->Data()->sShipID.toString()) )
622
				{
617
				{
623
					gNode->Data()->pPackage = p;
618
					gNode->Data()->pPackage = p;
624
					break;
619
					break;
625
				}
620
				}
626
			}
621
			}
Line 637... Line 632...
637
	return true;
632
	return true;
638
}
633
}
639
 
634
 
640
void CPackages::RemoveCreatedFiles()
635
void CPackages::RemoveCreatedFiles()
641
{
636
{
642
	for(auto itr = m_lCreatedFiles.begin(); itr != m_lCreatedFiles.end(); itr++)
637
	for(auto itr = _lCreatedFiles.begin(); itr != _lCreatedFiles.end(); itr++)
643
	{
638
	{
644
		if ( CFileIO::Exists((*itr)->str) )
639
		if ( CFileIO::Exists((*itr)->str) )
645
			CFileIO::Remove((*itr)->str);
640
			CFileIO::Remove((*itr)->str);
646
		else if ( CFileIO::Exists(m_sCurrentDir + "/" + (*itr)->str) )
641
		else if ( CFileIO::Exists(m_sCurrentDir + L"/" + (*itr)->str) )
647
			CFileIO::Remove(m_sCurrentDir + "/" + (*itr)->str);
642
			CFileIO::Remove(m_sCurrentDir + L"/" + (*itr)->str);
648
	}
643
	}
649
 
644
 
650
	m_lCreatedFiles.clear();
645
	_lCreatedFiles.clear();
651
}
646
}
652
 
647
 
653
void CPackages::PurgeGameObjects()
648
void CPackages::PurgeGameObjects()
654
{
649
{
655
	// check for the log file
650
	// check for the log file
656
	Utils::String logDir = logDirectory();
651
	Utils::WString logDir = logDirectory();
657
	CFileIO LogFile(logDir + "/log0" + Utils::String::PadNumber(PMTEXTFILE, 4) + ".txt");
652
	CFileIO LogFile(logDir + L"/log0" + Utils::WString::PadNumber(PMTEXTFILE, 4) + L".txt");
658
	if ( LogFile.exists() )
653
	if ( LogFile.exists() )
659
	{
654
	{
660
		// read the log file to memory
655
		// read the log file to memory
661
		std::vector<Utils::String> *lines = LogFile.readLines();
656
		std::vector<Utils::String> *lines = LogFile.readLines();
662
		if ( lines )
657
		if ( lines )
Line 711... Line 706...
711
			node->Data()->iType = WARETYPE_NONE;
706
			node->Data()->iType = WARETYPE_NONE;
712
	}
707
	}
713
	m_lGameShips.RemoveEmpty();
708
	m_lGameShips.RemoveEmpty();
714
}
709
}
715
 
710
 
716
Utils::String CPackages::logDirectory()
711
Utils::WString CPackages::logDirectory()
717
{
712
{
718
	Utils::String logDir = m_sCurrentDir;
713
	Utils::WString logDir = m_sCurrentDir;
719
	if ( m_iGameFlags & EXEFLAG_MYDOCLOG ) {
714
	if ( m_iGameFlags & EXEFLAG_MYDOCLOG ) {
720
		SGameExe *exe = m_gameExe.GetGame(m_iGame - 1);
715
		SGameExe *exe = m_gameExe.game(m_iGame - 1);
721
		if ( exe ) {
716
		if ( exe ) {
722
			if ( !exe->sMyDoc.empty() )
717
			if ( !exe->sMyDoc.empty() )
723
				logDir = m_sMyDoc + "/" + exe->sMyDoc;
718
				logDir = m_sMyDoc + L"/" + exe->sMyDoc;
724
		}
719
		}
725
	}
720
	}
726
 
721
 
727
	return logDir;
722
	return logDir;
728
}
723
}
729
 
724
 
730
Utils::String CPackages::logDirectory(const Utils::String &gameExe)
725
Utils::WString CPackages::logDirectory(const Utils::WString &gameExe)
731
{
726
{
732
	Utils::String logDir = m_sCurrentDir;
727
	Utils::WString logDir = m_sCurrentDir;
733
	if ( m_iGameFlags & EXEFLAG_MYDOCLOG )
728
	if ( m_iGameFlags & EXEFLAG_MYDOCLOG )
734
	{
729
	{
735
		SGameExe *exe = m_gameExe.gameExe(CFileIO(gameExe).filenameStr());
730
		SGameExe *exe = m_gameExe.gameExe(CFileIO(gameExe).filename());
736
		if ( exe )
731
		if ( exe )
737
		{
732
		{
738
			if ( !exe->sMyDoc.empty() )
733
			if ( !exe->sMyDoc.empty() )
739
				logDir = m_sMyDoc + "/" + exe->sMyDoc;
734
				logDir = m_sMyDoc + L"/" + exe->sMyDoc;
740
		}
735
		}
741
	}
736
	}
742
 
737
 
743
	return CFileIO(logDir).fullFilenameStr();
738
	return CFileIO(logDir).fullFilename();
744
}
739
}
745
 
740
 
746
Utils::String CPackages::saveDirectory()
741
Utils::WString CPackages::saveDirectory()
747
{
742
{
748
	Utils::String logDir = this->logDirectory();
743
	Utils::WString logDir = this->logDirectory();
749
	if ( m_iGameFlags & EXEFLAG_NOSAVESUBDIR )
744
	if ( m_iGameFlags & EXEFLAG_NOSAVESUBDIR )
750
		return logDir;
745
		return logDir;
751
 
746
 
752
	return logDir + "/save";
747
	return logDir + L"/save";
753
}
748
}
754
 
749
 
755
bool CPackages::ReadyFakePatch()
750
bool CPackages::ReadyFakePatch()
756
{
751
{
757
	// already exists, lets skip it
752
	// already exists, lets skip it
Line 765... Line 760...
765
		CFileIO::Remove(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
760
		CFileIO::Remove(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
766
 
761
 
767
	// fake patch is not being used
762
	// fake patch is not being used
768
	if ( m_iFakePatch < 0 ) return true;
763
	if ( m_iFakePatch < 0 ) return true;
769
	// now lets find the fake patch
764
	// now lets find the fake patch
770
	Utils::String useFile;
765
	Utils::WString useFile;
771
	if ( m_iFakePatch > 0 )
766
	if ( m_iFakePatch > 0 )
772
	{
767
	{
773
		Utils::String file = Utils::String::PadNumber(m_iFakePatch, 2);
768
		Utils::WString file = Utils::WString::PadNumber(m_iFakePatch, 2);
774
		if (checkValidPluginManagerFile(file))
769
		if (checkValidPluginManagerFile(file))
775
			useFile = file;
770
			useFile = file;
776
		else if (checkIfPluginManagerFile(file))
771
		else if (checkIfPluginManagerFile(file))
777
			useFile = file;
772
			useFile = file;
778
	}
773
	}
Line 783... Line 778...
783
		--nextfree; // gets the end fake patch
778
		--nextfree; // gets the end fake patch
784
 
779
 
785
		// work backwards till we find a valid one
780
		// work backwards till we find a valid one
786
		while ( nextfree > m_iMaxPatch )
781
		while ( nextfree > m_iMaxPatch )
787
		{
782
		{
788
			Utils::String file = Utils::String::PadNumber(nextfree, 2);
783
			Utils::WString file = Utils::WString::PadNumber(nextfree, 2);
789
			if (checkValidPluginManagerFile(file))
784
			if (checkValidPluginManagerFile(file))
790
			{
785
			{
791
				useFile = file;
786
				useFile = file;
792
				break;
787
				break;
793
			}
788
			}
794
			--nextfree;
789
			--nextfree;
795
		}
790
		}
796
	}
791
	}
797
 
792
 
798
	Utils::String addonDir = this->getAddonDir();
793
	Utils::WString addonDir = this->getAddonDir();
799
 
794
 
800
	// couldn't find the correct file, lets search for it
795
	// couldn't find the correct file, lets search for it
801
	if ( useFile.empty() ) {
796
	if ( useFile.empty() ) {
802
		int nextfree = this->findNextFakePatch();
797
		int nextfree = this->findNextFakePatch();
803
		--nextfree; // gets the end fake patch
798
		--nextfree; // gets the end fake patch
804
 
799
 
805
		// work backwards till we find a valid one
800
		// work backwards till we find a valid one
806
		while ( nextfree > m_iMaxPatch )
801
		while ( nextfree > m_iMaxPatch )
807
		{
802
		{
808
			Utils::String file = Utils::String::PadNumber(nextfree, 2);
803
			Utils::WString file = Utils::WString::PadNumber(nextfree, 2);
809
			if (checkIfPluginManagerFile(file))
804
			if (checkIfPluginManagerFile(file))
810
			{
805
			{
811
				useFile = file;
806
				useFile = file;
812
				break;
807
				break;
813
			}
808
			}
Line 817... Line 812...
817
 
812
 
818
	if ( !useFile.empty() )
813
	if ( !useFile.empty() )
819
	{
814
	{
820
		// lets check whats in the file first
815
		// lets check whats in the file first
821
		CCatFile openCat;
816
		CCatFile openCat;
822
		if ( openCat.open(m_sCurrentDir + "/" + useFile + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
817
		if ( openCat.open((m_sCurrentDir + L"/" + useFile + L".cat").toString(), addonDir.toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
823
		{
818
		{
824
			std::vector<SInCatFile *> *files = openCat.GetFiles();
819
			std::vector<SInCatFile *> *files = openCat.GetFiles();
825
			bool found = false;
820
			bool found = false;
826
			if ( files )
821
			if ( files )
827
			{
822
			{
828
				Utils::String useAddonDir = addonDir;
823
				Utils::WString useAddonDir = addonDir;
829
				if ( !useAddonDir.empty() ) useAddonDir += "\\";
824
				if ( !useAddonDir.empty() ) useAddonDir += L"\\";
830
				for (auto itr = files->cbegin(); itr != files->cend(); itr++)
825
				for (auto itr = files->cbegin(); itr != files->cend(); itr++)
831
				{
826
				{
832
					if ((*itr)->sFile.Compare("PlugMan\\TFake.pck") )
827
					if ((*itr)->sFile.Compare("PlugMan\\TFake.pck") )
833
						continue;
828
						continue;
834
					if ((*itr)->sFile.Compare(useAddonDir + "t\\44" + Utils::String::PadNumber(PMTEXTFILE, 4) + &quot;.pck") )
829
					if ((*itr)->sFile.Compare(useAddonDir.toString() + "t\\44" + Utils::String::PadNumber(PMTEXTFILE, 4) + &quot;.pck"))
835
						continue;
830
						continue;
836
					if ((*itr)->sFile.Compare(useAddonDir + "t\\" + Utils::String::PadNumber(PMTEXTFILE, 4) + ";-L044.pck") )
831
					if ((*itr)->sFile.Compare(useAddonDir.toString() + "t\\" + Utils::String::PadNumber(PMTEXTFILE, 4) + ";-L044.pck"))
837
						continue;
832
						continue;
838
 
833
 
839
					found = true;
834
					found = true;
840
					break;
835
					break;
841
				}
836
				}
842
			}
837
			}
843
 
838
 
844
			// no files, jsut delete them
839
			// no files, jsut delete them
845
			CFileIO catFile(m_sCurrentDir + "/" + useFile + ".cat");
840
			CFileIO catFile(m_sCurrentDir + L"/" + useFile + L".cat");
846
			if ( !files || !found )
841
			if ( !files || !found )
847
			{
842
			{
848
				if ( catFile.remove() )
843
				if ( catFile.remove() )
849
				{
844
				{
850
					CFileIO datFile(m_sCurrentDir + "/" + useFile + ".dat");
845
					CFileIO datFile(m_sCurrentDir + L"/" + useFile + L".dat");
851
					if ( datFile.remove() )
846
					if ( datFile.remove() )
852
						return true;
847
						return true;
853
				}
848
				}
854
			}
849
			}
855
			else
850
			else
856
			{
851
			{
857
				if ( catFile.Rename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat") )
852
				if ( catFile.Rename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat") )
858
				{
853
				{
859
					CFileIO datFile(m_sCurrentDir + "/" + useFile + ".dat");
854
					CFileIO datFile(m_sCurrentDir + L"/" + useFile + L".dat");
860
 
855
 
861
					if ( datFile.Rename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat") )
856
					if ( datFile.Rename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat") )
862
						return true;
857
						return true;
863
 
858
 
864
					// TODO: it failed, restore cat file and do error
859
					// TODO: it failed, restore cat file and do error
Line 883... Line 878...
883
	// otherwise we didn't need to (hopefully)
878
	// otherwise we didn't need to (hopefully)
884
	return true;
879
	return true;
885
}
880
}
886
 
881
 
887
 
882
 
888
bool CPackages::checkIfPluginManagerFile(const Utils::String &filename) const
883
bool CPackages::checkIfPluginManagerFile(const Utils::WString &filename) const
889
{
884
{
890
	bool found = false;
885
	bool found = false;
891
 
886
 
892
	CFileIO catFile(m_sCurrentDir + "/" + filename + ".cat");
887
	CFileIO catFile(m_sCurrentDir + L"/" + filename + L".cat");
893
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + "/" + filename + ".dat"))
888
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + L"/" + filename + L".dat"))
894
	{
889
	{
895
		CCatFile openFile;
890
		CCatFile openFile;
896
		if ( openFile.open(catFile.fullFilenameStr(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
891
		if ( openFile.open(catFile.fullFilenameStr(), this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
897
		{
892
		{
898
//			if ( openFile.internaldatFilename().Compare("PlugMan_Fake.dat") ) return true;
893
//			if ( openFile.internaldatFilename().Compare("PlugMan_Fake.dat") ) return true;
899
			int count = 0;
894
			int count = 0;
900
			int noncount = 0;
895
			int noncount = 0;
901
 
896
 
902
			// check for some of the files
897
			// check for some of the files
903
			for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
898
			for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() ) {
904
				if ( node->Data()->fullDir().contains("::") ) {
899
				if ( node->Data()->fullDir().contains(L"::") ) {
905
					if (CFileIO(node->Data()->fullDir().token("::", 1)).filename().Compare(L"PlugMan_Fake.cat") ) {
900
					if (CFileIO(node->Data()->fullDir().token(L"::", 1)).filename().Compare(L"PlugMan_Fake.cat") ) {
906
						Utils::String filename = node->Data()->filePointer().token("::", 2);
901
						Utils::WString filename = node->Data()->filePointer().token(L"::", 2);
907
						filename = filename.findReplace("/", "\\");
902
						filename = filename.findReplace(L"/", L"\\");
908
						if ( openFile.findData(filename) )
903
						if ( openFile.findData(filename) )
909
							++count;
904
							++count;
910
						else
905
						else
911
							++noncount;
906
							++noncount;
912
					}
907
					}
Line 919... Line 914...
919
	}
914
	}
920
 
915
 
921
	return found;
916
	return found;
922
}
917
}
923
 
918
 
924
bool CPackages::checkValidPluginManagerFile(const Utils::String &filename) const
919
bool CPackages::checkValidPluginManagerFile(const Utils::WString &filename) const
925
{
920
{
926
	// both the cat file and dat file exists, lets open it
921
	// both the cat file and dat file exists, lets open it
927
	CFileIO catFile(m_sCurrentDir + "/" + filename + ".cat");
922
	CFileIO catFile(m_sCurrentDir + L"/" + filename + L".cat");
928
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + "/" + filename + ".dat"))
923
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + L"/" + filename + L".dat"))
929
	{
924
	{
930
		CCatFile openFile;
925
		CCatFile openFile;
931
		if ( openFile.open(catFile.fullFilenameStr(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
926
		if ( openFile.open(catFile.fullFilenameStr(), this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
932
		{
927
		{
933
			if ( openFile.findData("PlugMan\\TFake.pck") )
928
			if ( openFile.findData("PlugMan\\TFake.pck") )
934
				return true;
929
				return true;
935
			if ( openFile.findData("pluginmanagerfake.pck") )
930
			if ( openFile.findData("pluginmanagerfake.pck") )
936
				return true;
931
				return true;
Line 955... Line 950...
955
			if ( gNode->Data()->iVersion == 0 )
950
			if ( gNode->Data()->iVersion == 0 )
956
				gNode->Data()->iGame = 0;
951
				gNode->Data()->iGame = 0;
957
			else
952
			else
958
			{
953
			{
959
				int version = 0;
954
				int version = 0;
960
				gNode->Data()->iGame = m_gameExe.ConvertGameType(gNode->Data()->iVersion, &version);
955
				gNode->Data()->iGame = m_gameExe.convertGameType(gNode->Data()->iVersion, &version);
961
				gNode->Data()->iVersion = version;
956
				gNode->Data()->iVersion = version;
962
			}
957
			}
963
		}
958
		}
964
	}
959
	}
965
 
960
 
Line 1115... Line 1110...
1115
 
1110
 
1116
	m_bRedo = false;
1111
	m_bRedo = false;
1117
	return true;
1112
	return true;
1118
}
1113
}
1119
 
1114
 
1120
int CPackages::checkOpenPackage(const Utils::String &file, int *error)
1115
int CPackages::checkOpenPackage(const Utils::WString &file, int *error)
1121
{
1116
{
1122
	// first check if it exists
1117
	// first check if it exists
1123
	if (!CFileIO::Exists(file))
1118
	if (!CFileIO::Exists(file))
1124
	{
1119
	{
1125
		*error = INSTALLERR_NOEXIST;
1120
		*error = INSTALLERR_NOEXIST;
Line 1138... Line 1133...
1138
	}
1133
	}
1139
 
1134
 
1140
	return check;
1135
	return check;
1141
}
1136
}
1142
 
1137
 
1143
CMultiSpkFile *CPackages::openMultiPackage(const Utils::String &file, int *error, CProgressInfo *progress)
1138
CMultiSpkFile *CPackages::openMultiPackage(const Utils::WString &file, int *error, CProgressInfo *progress)
1144
{
1139
{
1145
	int check = checkOpenPackage(file, error);
1140
	int check = checkOpenPackage(file, error);
1146
	if ( *error == -1 )
1141
	if ( *error == -1 )
1147
		return false;
1142
		return false;
1148
 
1143
 
Line 1173... Line 1168...
1173
 
1168
 
1174
	delete package;
1169
	delete package;
1175
	return NULL;
1170
	return NULL;
1176
}
1171
}
1177
 
1172
 
1178
bool CPackages::openMultiPackage(const Utils::String &file, CLinkList<CBaseFile> *packageList, int *error, CProgressInfo *progress )
1173
bool CPackages::openMultiPackage(const Utils::WString &file, CLinkList<CBaseFile> *packageList, int *error, CProgressInfo *progress )
1179
{
1174
{
1180
	int check = checkOpenPackage(file, error);
1175
	int check = checkOpenPackage(file, error);
1181
	if ( *error == -1 )
1176
	if ( *error == -1 )
1182
		return false;
1177
		return false;
1183
 
1178
 
Line 1253... Line 1248...
1253
	delete package;
1248
	delete package;
1254
 
1249
 
1255
	return count;
1250
	return count;
1256
}
1251
}
1257
 
1252
 
1258
CBaseFile *CPackages::openPackage(const Utils::String &file, int *error, CProgressInfo *progress, int readtype, int flags)
1253
CBaseFile *CPackages::openPackage(const Utils::WString &file, int *error, CProgressInfo *progress, int readtype, int flags)
1259
{
1254
{
1260
	int check = checkOpenPackage(file, error);
1255
	int check = checkOpenPackage(file, error);
1261
	if ( *error == -1 )
1256
	if ( *error == -1 )
1262
		return NULL;
1257
		return NULL;
1263
 
1258
 
Line 1274... Line 1269...
1274
		case SPKFILE_INVALID:
1269
		case SPKFILE_INVALID:
1275
			// convert xsp
1270
			// convert xsp
1276
			if ( CFileIO(file).isFileExtension(L"xsp") )
1271
			if ( CFileIO(file).isFileExtension(L"xsp") )
1277
			{
1272
			{
1278
				installFile = new CXspFile();
1273
				installFile = new CXspFile();
1279
				if ( !((CXspFile *)installFile)->ConvertOld(file) )
1274
				if ( !((CXspFile *)installFile)->ConvertOld(file.toString()) )
1280
				{
1275
				{
1281
					delete installFile;
1276
					delete installFile;
1282
					return NULL;
1277
					return NULL;
1283
				}
1278
				}
1284
				break;
1279
				break;
1285
			}
1280
			}
1286
			*error = INSTALLERR_INVALID;
1281
			*error = INSTALLERR_INVALID;
1287
			return NULL;
1282
			return NULL;
1288
		case SPKFILE_BASE:
1283
		case SPKFILE_BASE:
1289
			installFile = new CBaseFile();
1284
			installFile = new CBaseFile();
1290
			if ( !installFile->readFile(file, readtype, progress) )
1285
			if ( !installFile->readFile(file.toString(), readtype, progress))
1291
			{
1286
			{
1292
				delete installFile;
1287
				delete installFile;
1293
				return NULL;
1288
				return NULL;
1294
			}
1289
			}
1295
			break;
1290
			break;
1296
		case SPKFILE_SINGLE:
1291
		case SPKFILE_SINGLE:
1297
			installFile = new CSpkFile();
1292
			installFile = new CSpkFile();
1298
			if ( !((CSpkFile *)installFile)->readFile(file, readtype, progress) )
1293
			if ( !((CSpkFile *)installFile)->readFile(file.toString(), readtype, progress))
1299
			{
1294
			{
1300
				delete installFile;
1295
				delete installFile;
1301
				return NULL;
1296
				return NULL;
1302
			}
1297
			}
1303
			break;
1298
			break;
1304
		case SPKFILE_MULTI:
1299
		case SPKFILE_MULTI:
1305
			*error = INSTALLERR_NOMULTI;
1300
			*error = INSTALLERR_NOMULTI;
1306
			return NULL;
1301
			return NULL;
1307
		case SPKFILE_SINGLESHIP:
1302
		case SPKFILE_SINGLESHIP:
1308
			installFile = new CXspFile();
1303
			installFile = new CXspFile();
1309
			if ( !((CXspFile *)installFile)->readFile(file, readtype, progress))
1304
			if ( !((CXspFile *)installFile)->readFile(file.toString(), readtype, progress))
1310
			{
1305
			{
1311
				delete installFile;
1306
				delete installFile;
1312
				return NULL;
1307
				return NULL;
1313
			}
1308
			}
1314
			break;
1309
			break;
Line 1328... Line 1323...
1328
	this->ConvertOldPackage (installFile);
1323
	this->ConvertOldPackage (installFile);
1329
 
1324
 
1330
	return installFile;
1325
	return installFile;
1331
}
1326
}
1332
 
1327
 
1333
void CPackages::purgeUninstallScripts(CBaseFile *package, Utils::CStringList *errors)
1328
void CPackages::purgeUninstallScripts(CBaseFile *package, Utils::WStringList *errors)
1334
{
1329
{
1335
	for ( CListNode<C_File> *fNode = m_lUninstallFiles.Front(); fNode; fNode = fNode->next() )
1330
	for ( CListNode<C_File> *fNode = m_lUninstallFiles.Front(); fNode; fNode = fNode->next() )
1336
	{
1331
	{
1337
		C_File *uf = fNode->Data();
1332
		C_File *uf = fNode->Data();
1338
		// check against any script files
1333
		// check against any script files
Line 1356... Line 1351...
1356
	m_lUninstallFiles.RemoveEmpty();
1351
	m_lUninstallFiles.RemoveEmpty();
1357
 
1352
 
1358
	this->WriteData();
1353
	this->WriteData();
1359
}
1354
}
1360
 
1355
 
1361
int CPackages::installPreparedPackages(Utils::CStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *errored, CLinkList<CBaseFile> *installedList)
1356
int CPackages::installPreparedPackages(Utils::WStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *errored, CLinkList<CBaseFile> *installedList)
1362
{
1357
{
1363
	if ( m_lInstallList.empty() ) return false;
1358
	if ( m_lInstallList.empty() ) return false;
1364
	int installed = 0;
1359
	int installed = 0;
1365
	for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
1360
	for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
1366
	{
1361
	{
Line 1386... Line 1381...
1386
}
1381
}
1387
 
1382
 
1388
void CPackages::_addToFakePatch(CBaseFile *pPackage)
1383
void CPackages::_addToFakePatch(CBaseFile *pPackage)
1389
{
1384
{
1390
	CCatFile cat;
1385
	CCatFile cat;
1391
	if ( CCatFile::Opened(cat.open(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat";, this->getAddonDir(), CATREAD_DAT)) ) {
1386
	if ( CCatFile::Opened(cat.open((m_sCurrentDir + L"/PluginManager/PlugMan_Fake.cat";).toString(), this->getAddonDir(), CATREAD_DAT))) {
1392
		for ( CListNode<C_File> *f = pPackage->GetFileList()->Front(); f; f = f->next() ) {
1387
		for ( CListNode<C_File> *f = pPackage->GetFileList()->Front(); f; f = f->next() ) {
1393
			if ( f->Data()->GetFileType() != FILETYPE_SHIPSCENE && f->Data()->GetFileType() != FILETYPE_COCKPITSCENE && f->Data()->GetFileType() != FILETYPE_SHIPMODEL && f->Data()->GetFileType() != FILETYPE_SHIPOTHER ) {
1388
			if ( f->Data()->GetFileType() != FILETYPE_SHIPSCENE && f->Data()->GetFileType() != FILETYPE_COCKPITSCENE && f->Data()->GetFileType() != FILETYPE_SHIPMODEL && f->Data()->GetFileType() != FILETYPE_SHIPOTHER ) {
1394
				continue;
1389
				continue;
1395
			}
1390
			}
1396
			if ( CCatFile::IsAddonDir(f->Data()->getNameDirectory(pPackage)) ) {
1391
			if ( CCatFile::IsAddonDir(f->Data()->getNameDirectory(pPackage)) ) {
Line 1398... Line 1393...
1398
			}
1393
			}
1399
			// check if its already in the fake patch
1394
			// check if its already in the fake patch
1400
			if ( f->Data()->fullDir().contains("::") ) {
1395
			if ( f->Data()->fullDir().contains("::") ) {
1401
				continue;
1396
				continue;
1402
			}
1397
			}
1403
			Utils::String toFile;
1398
			Utils::WString toFile;
1404
			if ( cat.appendFile(f->Data()->filePointer(), f->Data()->getNameDirectory(pPackage), true, (m_iGameFlags & EXEFLAG_NOXOR) ? false : true, &toFile) ) {
1399
			if ( cat.appendFile(f->Data()->filePointer(), f->Data()->getNameDirectory(pPackage), true, (m_iGameFlags & EXEFLAG_NOXOR) ? false : true, &toFile) ) {
1405
				CLog::logf(CLog::Log_Install, 2, "Adding file: %s into the fake patch", f->Data()->getNameDirectory(pPackage).c_str());
1400
				CLog::logf(CLog::Log_Install, 2, "Adding file: %s into the fake patch", f->Data()->getNameDirectory(pPackage).c_str());
1406
				CFileIO::Remove(f->Data()->filePointer());
1401
				CFileIO::Remove(f->Data()->filePointer());
1407
				f->Data()->setFilename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat::" + toFile);
1402
				f->Data()->setFilename(m_sCurrentDir + L"/PluginManager/PlugMan_Fake.cat::" + toFile);
1408
			}
1403
			}
1409
		}
1404
		}
1410
	}
1405
	}
1411
}
1406
}
1412
 
1407
 
Line 1436... Line 1431...
1436
		disabled = prevDisabled;
1431
		disabled = prevDisabled;
1437
 
1432
 
1438
	return disabled;
1433
	return disabled;
1439
}
1434
}
1440
 
1435
 
1441
Utils::String CPackages::getCurrentDirectory() const
1436
Utils::WString CPackages::getCurrentDirectory() const
1442
{ 
1437
{ 
1443
	return (_pCurrentDir) ? _pCurrentDir->dir : Utils::String::Null(); 
1438
	return (_pCurrentDir) ? _pCurrentDir->dir : Utils::WString::Null();
1444
}
1439
}
1445
 
1440
 
1446
 
1441
 
1447
bool CPackages::installPackage(CBaseFile *package, Utils::CStringList *errors, CProgressInfo *progress, bool disabled)
1442
bool CPackages::installPackage(CBaseFile *package, Utils::WStringList *errors, CProgressInfo *progress, bool disabled)
1448
{
1443
{
1449
	CLog::logf(CLog::Log_Install, 1, "Starting to install new package, %s by %s (Version: %s)", package->name().c_str(), package->author().c_str(), package->version().c_str());
1444
	CLog::logf(CLog::Log_Install, 1, "Starting to install new package, %s by %s (Version: %s)", package->name().c_str(), package->author().c_str(), package->version().c_str());
1450
	
1445
	
1451
	CBaseFile *oldPackage = findPackage(package);
1446
	CBaseFile *oldPackage = findPackage(package);
1452
	disabled = _checkForDisable(package, disabled, oldPackage);
1447
	disabled = _checkForDisable(package, disabled, oldPackage);
Line 1501... Line 1496...
1501
 
1496
 
1502
	CLog::log(CLog::Log_Install, 3, "Reading all files into memory");
1497
	CLog::log(CLog::Log_Install, 3, "Reading all files into memory");
1503
	package->ReadAllFilesToMemory();
1498
	package->ReadAllFilesToMemory();
1504
 
1499
 
1505
	CLog::log(CLog::Log_Install, 3, "Starting to install files");
1500
	CLog::log(CLog::Log_Install, 3, "Starting to install files");
1506
	if ( !package->installFiles (m_sCurrentDir, progress, &m_lFiles, errors, !disabled, this) )
1501
	if ( !package->installFiles (m_sCurrentDir.toString(), progress, &m_lFiles, errors, !disabled, this))
1507
	{
1502
	{
1508
		CLog::log(CLog::Log_Install, 2, "There was an error installing files!!");
1503
		CLog::log(CLog::Log_Install, 2, "There was an error installing files!!");
1509
 
1504
 
1510
		// TODO: clear up installed files
1505
		// TODO: clear up installed files
1511
		return false;
1506
		return false;
Line 1578... Line 1573...
1578
 
1573
 
1579
				if ( findMatching )
1574
				if ( findMatching )
1580
				{
1575
				{
1581
					// copy accross all mods
1576
					// copy accross all mods
1582
					CCatFile catTo, catFrom;
1577
					CCatFile catTo, catFrom;
1583
					if ( catFrom.open(f->Data()->filePointer(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
1578
					if ( catFrom.open(f->Data()->filePointer(), this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
1584
					{
1579
					{
1585
						if ( catTo.open(findMatching->filePointer(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
1580
						if ( catTo.open(findMatching->filePointer(), this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
1586
						{
1581
						{
1587
							for (unsigned int i = 0; i < catFrom.GetNumFiles(); i++ )
1582
							for (unsigned int i = 0; i < catFrom.GetNumFiles(); i++ )
1588
							{
1583
							{
1589
								SInCatFile *c = catFrom.GetFile(i);								 
1584
								SInCatFile *c = catFrom.GetFile(i);								 
1590
								catTo.appendFile(f->Data()->filePointer() + "::" + c->sFile, c->sFile);
1585
								catTo.appendFile(f->Data()->filePointer() + "::" + c->sFile, c->sFile);
Line 1613... Line 1608...
1613
					{
1608
					{
1614
						shuffle = true;
1609
						shuffle = true;
1615
						C_File *match = package->findMatchingMod(f->Data());
1610
						C_File *match = package->findMatchingMod(f->Data());
1616
						Utils::String next = Utils::String::PadNumber(this->findNextFakePatch(), 2);
1611
						Utils::String next = Utils::String::PadNumber(this->findNextFakePatch(), 2);
1617
						
1612
						
1618
						Utils::String oldFilePointer = f->Data()->filePointer();
1613
						Utils::WString oldFilePointer = f->Data()->filePointer();
1619
						f->Data()->setDir("");
1614
						f->Data()->setDir(L"");
1620
						f->Data()->changeBaseName(next);
1615
						f->Data()->changeBaseName(next);
1621
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
1616
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + L"/" + f->Data()->getNameDirectory(package)))
1622
							f->Data()->setFilename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package));
1617
							f->Data()->setFilename(m_sCurrentDir + L"/" + f->Data()->getNameDirectory(package));
1623
 
1618
 
1624
						if ( match )
1619
						if ( match )
1625
						{
1620
						{
1626
							Utils::String oldFilePointer = match->filePointer();
1621
							Utils::WString oldFilePointer = match->filePointer();
1627
							match->setDir("");
1622
							match->setDir(L"");
1628
							match->changeBaseName(next);
1623
							match->changeBaseName(next);
1629
							if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + match->getNameDirectory(package)) )
1624
							if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + L"/" + match->getNameDirectory(package)))
1630
								match->setFilename(m_sCurrentDir + "/" + match->getNameDirectory(package));
1625
								match->setFilename(m_sCurrentDir + L"/" + match->getNameDirectory(package));
1631
						}
1626
						}
1632
					}
1627
					}
1633
					else
1628
					else
1634
					{
1629
					{
1635
						C_File *match = package->findMatchingMod(f->Data());
1630
						C_File *match = package->findMatchingMod(f->Data());
1636
 
1631
 
1637
						f->Data()->setDir("");
1632
						f->Data()->setDir(L"");
1638
						if ( CFileIO(f->Data()->filePointer()).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
1633
						if ( CFileIO(f->Data()->filePointer()).Rename(m_sCurrentDir + L"/" + f->Data()->getNameDirectory(package)))
1639
							f->Data()->setFilename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package));
1634
							f->Data()->setFilename(m_sCurrentDir + L"/" + f->Data()->getNameDirectory(package));
1640
						if ( match )
1635
						if ( match )
1641
						{
1636
						{
1642
							match->setDir("");
1637
							match->setDir(L"");
1643
							if ( CFileIO(match->filePointer()).Rename(m_sCurrentDir + "/" + match->getNameDirectory(package)) )
1638
							if ( CFileIO(match->filePointer()).Rename(m_sCurrentDir + L"/" + match->getNameDirectory(package)))
1644
								match->setFilename(m_sCurrentDir + "/" + match->getNameDirectory(package));
1639
								match->setFilename(m_sCurrentDir + L"/" + match->getNameDirectory(package));
1645
						}
1640
						}
1646
					}
1641
					}
1647
				}
1642
				}
1648
			}
1643
			}
1649
 
1644
 
Line 1652... Line 1647...
1652
			delete package;
1647
			delete package;
1653
			package = oldPackage;
1648
			package = oldPackage;
1654
			oldPackage = false;
1649
			oldPackage = false;
1655
			dontAdd = true;
1650
			dontAdd = true;
1656
 
1651
 
1657
			CDirIO(m_sCurrentDir).removeDir("temp");
1652
			CDirIO(m_sCurrentDir).removeDir(L"temp");
1658
			CDirIO(m_sCurrentDir).removeDir("Mods/temp");
1653
			CDirIO(m_sCurrentDir).removeDir(L"Mods/temp");
1659
		}
1654
		}
1660
	}
1655
	}
1661
 
1656
 
1662
	// if theres an icon, write it
1657
	// if theres an icon, write it
1663
	if (package->icon())
1658
	if (package->icon())
Line 1687... Line 1682...
1687
			{
1682
			{
1688
				if ( !icon->UncompressData() )
1683
				if ( !icon->UncompressData() )
1689
					package->setIcon(NULL, "");
1684
					package->setIcon(NULL, "");
1690
				else
1685
				else
1691
				{
1686
				{
1692
					CFileIO iconFile(m_sCurrentDir + "/PluginManager/Icons/" + package->author() + ";_" + package->name() + "." + package->iconExt());
1687
					CFileIO iconFile(m_sCurrentDir + L"/PluginManager/Icons/" + package->author().toWString() + L";_" + package->name().toWString() + L"." + package->iconExt());
1693
					if ( iconFile.WriteData((const char *)icon->GetData(), icon->GetDataSize()) )
1688
					if ( iconFile.WriteData((const char *)icon->GetData(), icon->GetDataSize()) )
1694
					{
1689
					{
1695
						icon->setFilename(package->author() + ";_" + package->name() + "." + package->iconExt());
1690
						icon->setFilename(package->author().toWString() + L";_" + package->name().toWString() + L"." + package->iconExt());
1696
						icon->setFullDir(m_sCurrentDir + "/PluginManager/Icons");
1691
						icon->setFullDir(m_sCurrentDir + L"/PluginManager/Icons");
1697
					}
1692
					}
1698
					else
1693
					else
1699
						package->setIcon(NULL, "");
1694
						package->setIcon(NULL, "");
1700
				}
1695
				}
1701
			}
1696
			}
Line 1808... Line 1803...
1808
 
1803
 
1809
	CLog::log(CLog::Log_Install, 1, "Installation Finished");
1804
	CLog::log(CLog::Log_Install, 1, "Installation Finished");
1810
	return true;
1805
	return true;
1811
}
1806
}
1812
 
1807
 
1813
bool CPackages::uninstallPreparedPackages(Utils::CStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *uninstalledPackages, CLinkList<CBaseFile> *disabledPackages)
1808
bool CPackages::uninstallPreparedPackages(Utils::WStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *uninstalledPackages, CLinkList<CBaseFile> *disabledPackages)
1814
{
1809
{
1815
	if ( m_lInstallList.empty() ) return false;
1810
	if ( m_lInstallList.empty() ) return false;
1816
 
1811
 
1817
	// update the used status, excluding all packages we are about to remove
1812
	// update the used status, excluding all packages we are about to remove
1818
	UpdateUsedFiles(&m_lInstallList);
1813
	UpdateUsedFiles(&m_lInstallList);
1819
 
1814
 
1820
	Utils::CStringList removeDirs;
1815
	Utils::WStringList removeDirs;
1821
	CLinkList<C_File> uninstallFiles;
1816
	CLinkList<C_File> uninstallFiles;
1822
	CLinkList<C_File> fileList;
1817
	CLinkList<C_File> fileList;
1823
	bool readme = false, original = false, shuffle = false;
1818
	bool readme = false, original = false, shuffle = false;
1824
 
1819
 
1825
	// find all files that need to be removed
1820
	// find all files that need to be removed
Line 1874... Line 1869...
1874
 
1869
 
1875
		if ( f->GetFileType() == FILETYPE_README )
1870
		if ( f->GetFileType() == FILETYPE_README )
1876
			readme = true;
1871
			readme = true;
1877
		else if ( f->GetFileType() == FILETYPE_UNINSTALL || f->GetFileType() == FILETYPE_MAP || f->GetFileType() == FILETYPE_SOUND || f->GetFileType() == FILETYPE_EXTRA || f->GetFileType() == FILETYPE_SHIPSCENE || f->GetFileType() == FILETYPE_COCKPITSCENE || f->GetFileType() == FILETYPE_SHIPOTHER || f->GetFileType() == FILETYPE_SHIPMODEL || f->GetFileType() == FILETYPE_ADVERT )
1872
		else if ( f->GetFileType() == FILETYPE_UNINSTALL || f->GetFileType() == FILETYPE_MAP || f->GetFileType() == FILETYPE_SOUND || f->GetFileType() == FILETYPE_EXTRA || f->GetFileType() == FILETYPE_SHIPSCENE || f->GetFileType() == FILETYPE_COCKPITSCENE || f->GetFileType() == FILETYPE_SHIPOTHER || f->GetFileType() == FILETYPE_SHIPMODEL || f->GetFileType() == FILETYPE_ADVERT )
1878
		{
1873
		{
1879
			Utils::String dir = f->getDirectory(NULL);
1874
			Utils::WString dir = f->getDirectory(NULL);
1880
			if(!removeDirs.contains(dir))
1875
			if(!removeDirs.contains(dir))
1881
				removeDirs.pushBack(dir);
1876
				removeDirs.pushBack(dir);
1882
			dir = dir.findReplace("\\", "/");
1877
			dir = dir.findReplace(L"\\", L"/");
1883
			if ( dir.contains("/") )
1878
			if ( dir.contains(L"/") )
1884
			{
1879
			{
1885
				for ( int i = dir.countToken("/"); i; i-- )
1880
				for ( int i = dir.countToken(L"/"); i; i-- )
1886
				{
1881
				{
1887
					Utils::String remDir = dir.tokens("/", 1, i);
1882
					Utils::WString remDir = dir.tokens(L"/", 1, i);
1888
					if(!removeDirs.contains(remDir))
1883
					if(!removeDirs.contains(remDir))
1889
						removeDirs.pushBack(remDir);
1884
						removeDirs.pushBack(remDir);
1890
				}
1885
				}
1891
			}
1886
			}
1892
		}
1887
		}
1893
 
1888
 
1894
		if (f->GetFileType() == FILETYPE_EXTRA && f->dir().left(6).lower() == "extras")
1889
		if (f->GetFileType() == FILETYPE_EXTRA && f->dir().left(6).lower() == L"extras")
1895
		{
1890
		{
1896
			if (!removeDirs.contains("Extras"))
1891
			if (!removeDirs.contains(L"Extras"))
1897
				removeDirs.pushBack("Extras");
1892
				removeDirs.pushBack(L"Extras");
1898
		}
1893
		}
1899
 
1894
 
1900
		if (removeFile(f, errors))
1895
		if (removeFile(f, errors))
1901
			original = _pOriginalFiles->restoreFile(f, errors);
1896
			original = _pOriginalFiles->restoreFile(f, errors);
1902
		else // problem removeing (try when the program closes)
1897
		else // problem removeing (try when the program closes)
1903
			m_lNonRemovedFiles.pushBack(f->filePointer());
1898
			_lNonRemovedFiles.pushBack(f->filePointer());
1904
 
1899
 
1905
		// check for fake patchs
1900
		// check for fake patchs
1906
		if ( f->IsFakePatch() )
1901
		if ( f->IsFakePatch() )
1907
			shuffle = true;
1902
			shuffle = true;
1908
		else if ( f->isAutoTextFile() )
1903
		else if ( f->isAutoTextFile() )
Line 1932... Line 1927...
1932
	m_lInstallList.clear();
1927
	m_lInstallList.clear();
1933
 
1928
 
1934
	// check unistall files
1929
	// check unistall files
1935
	if ( !uninstallFiles.empty() )
1930
	if ( !uninstallFiles.empty() )
1936
	{
1931
	{
1937
		removeDirs.pushBack("PluginManager/Uninstall");
1932
		removeDirs.pushBack(L"PluginManager/Uninstall");
1938
 
1933
 
1939
		// make sure the scripts directory is created, even thou it should always be there anyways
1934
		// make sure the scripts directory is created, even thou it should always be there anyways
1940
		CDirIO scriptDir(m_sCurrentDir);
1935
		CDirIO scriptDir(m_sCurrentDir);
1941
		if ( !scriptDir.exists("scripts") )
1936
		if ( !scriptDir.exists(L"scripts") )
1942
		{
1937
		{
1943
			if ( scriptDir.create("Scripts") )
1938
			if ( scriptDir.create(L"Scripts") )
1944
				this->addLogEntry(SPKINSTALL_CREATEDIRECTORY, "Scripts", errors);
1939
				this->addLogEntry(SPKINSTALL_CREATEDIRECTORY, L"Scripts", errors);
1945
			else
1940
			else
1946
				this->addLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, "Scripts", errors);
1941
				this->addLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, L"Scripts", errors);
1947
		}
1942
		}
1948
 
1943
 
1949
		for ( C_File *uf = uninstallFiles.First(); uf; uf = uninstallFiles.Next() )
1944
		for ( C_File *uf = uninstallFiles.First(); uf; uf = uninstallFiles.Next() )
1950
		{
1945
		{
1951
			C_File *newFile = new C_File();
1946
			C_File *newFile = new C_File();
1952
			newFile->setFileType(FILETYPE_SCRIPT);
1947
			newFile->setFileType(FILETYPE_SCRIPT);
1953
			newFile->setFilename(uf->filename());
1948
			newFile->setFilename(uf->filename());
1954
			newFile->SetCreationTime(uf->GetCreationTime());
1949
			newFile->SetCreationTime(uf->GetCreationTime());
1955
 
1950
 
1956
			// other installed packages use this file as well, copy it
1951
			// other installed packages use this file as well, copy it
1957
			Utils::String newFilename = m_sCurrentDir + "/" + newFile->getNameDirectory(NULL);
1952
			Utils::WString newFilename = m_sCurrentDir + L"/" + newFile->getNameDirectory(NULL);
1958
			CFileIO file(uf->filePointer());
1953
			CFileIO file(uf->filePointer());
1959
 
1954
 
1960
			if ( uf->getUsed() )
1955
			if ( uf->getUsed() )
1961
			{
1956
			{
1962
				if ( file.copy(newFilename) )
1957
				if ( file.copy(newFilename) )
Line 2011... Line 2006...
2011
	uninstallFiles.clear();
2006
	uninstallFiles.clear();
2012
 
2007
 
2013
	// remove all directies that we're not using
2008
	// remove all directies that we're not using
2014
	if ( readme )
2009
	if ( readme )
2015
	{
2010
	{
2016
		removeDirs.pushBack("PluginManager/Readme");
2011
		removeDirs.pushBack(L"PluginManager/Readme");
2017
		removeDirs.pushBack("Readme");
2012
		removeDirs.pushBack(L"Readme");
2018
	}
2013
	}
2019
	if ( original ) {
2014
	if ( original ) {
2020
		removeDirs.pushBack("PluginManager/Original/Replacements");
2015
		removeDirs.pushBack(L"PluginManager/Original/Replacements");
2021
		removeDirs.pushBack("PluginManager/Original");
2016
		removeDirs.pushBack(L"PluginManager/Original");
2022
	}
2017
	}
2023
	removeDirs.pushBack("PluginManager/Disabled");
2018
	removeDirs.pushBack(L"PluginManager/Disabled");
2024
	removeUnusedDirectories(removeDirs, errors);
2019
	removeUnusedDirectories(removeDirs, errors);
2025
 
2020
 
2026
	// finally lets shuffle any fake patchs to fill in gaps
2021
	// finally lets shuffle any fake patchs to fill in gaps
2027
	if ( shuffle )
2022
	if ( shuffle )
2028
	{
2023
	{
Line 2279... Line 2274...
2279
			m_lInstallList.remove(package, true);
2274
			m_lInstallList.remove(package, true);
2280
		}
2275
		}
2281
	}
2276
	}
2282
}
2277
}
2283
 
2278
 
2284
char CPackages::ConvertWareTypeBack(int w)
2279
wchar_t CPackages::ConvertWareTypeBack(int w)
2285
{
2280
{
2286
	switch ( w )
2281
	switch ( w )
2287
	{
2282
	{
2288
		case WARES_BIO:
2283
		case WARES_BIO:
2289
			return 'b';
2284
			return L'b';
2290
		case WARES_ENERGY:
2285
		case WARES_ENERGY:
2291
			return 'e';
2286
			return L'e';
2292
		case WARES_FOOD:
2287
		case WARES_FOOD:
2293
			return 'f';
2288
			return L'f';
2294
		case WARES_MINERAL:
2289
		case WARES_MINERAL:
2295
			return 'm';
2290
			return L'm';
2296
		case WARES_TECH:
2291
		case WARES_TECH:
2297
			return 't';
2292
			return L't';
2298
		case WARES_NATURAL:
2293
		case WARES_NATURAL:
2299
			return 'n';
2294
			return L'n';
2300
	}
2295
	}
2301
	return 't';
2296
	return L't';
2302
}
2297
}
2303
int CPackages::ConvertWareType(char w)
2298
int CPackages::ConvertWareType(wchar_t w)
2304
{
2299
{
2305
	switch ( LOWER(w) )
2300
	switch ( LOWER(w) )
2306
	{
2301
	{
2307
		case 'b':
2302
		case L'b':
2308
			return WARES_BIO;
2303
			return WARES_BIO;
2309
		case 'e':
2304
		case L'e':
2310
			return WARES_ENERGY;
2305
			return WARES_ENERGY;
2311
		case 'f':
2306
		case L'f':
2312
			return WARES_FOOD;
2307
			return WARES_FOOD;
2313
		case 'm':
2308
		case L'm':
2314
			return WARES_MINERAL;
2309
			return WARES_MINERAL;
2315
		case 't':
2310
		case L't':
2316
			return WARES_TECH;
2311
			return WARES_TECH;
2317
		case 'n':
2312
		case L'n':
2318
			return WARES_NATURAL;
2313
			return WARES_NATURAL;
2319
	}
2314
	}
2320
	return WARES_TECH;
2315
	return WARES_TECH;
2321
}
2316
}
2322
 
2317
 
Line 2344... Line 2339...
2344
					wNode->Data()->iType = WARETYPE_DISABLED;
2339
					wNode->Data()->iType = WARETYPE_DISABLED;
2345
				else
2340
				else
2346
					wNode->Data()->iType = WARETYPE_ADDED;
2341
					wNode->Data()->iType = WARETYPE_ADDED;
2347
				found = true;
2342
				found = true;
2348
				wNode->Data()->pPackage = p;
2343
				wNode->Data()->pPackage = p;
2349
				wNode->Data()->sShipClass = p->GetShipClass();
2344
				wNode->Data()->sShipClass = p->GetShipClass().toWString();
2350
				break;
2345
				break;
2351
			}
2346
			}
2352
		}
2347
		}
2353
 
2348
 
2354
		if ( found || !p->IsEnabled() )
2349
		if ( found || !p->IsEnabled() )
Line 2370... Line 2365...
2370
 
2365
 
2371
		// none found, create one
2366
		// none found, create one
2372
		if ( !gw )
2367
		if ( !gw )
2373
		{
2368
		{
2374
			gw = new SGameShip;
2369
			gw = new SGameShip;
2375
			gw->sShipID = p->GetShipID();
2370
			gw->sShipID = p->GetShipID().toWString();
2376
			gw->sShipClass = p->GetShipClass();
2371
			gw->sShipClass = p->GetShipClass().toWString();
2377
			gw->pPackage = p;
2372
			gw->pPackage = p;
2378
			m_lGameShips.push_back(gw);
2373
			m_lGameShips.push_back(gw);
2379
		}
2374
		}
2380
		gw->iType = WARETYPE_ADDED;
2375
		gw->iType = WARETYPE_ADDED;
2381
	}
2376
	}
Line 2455... Line 2450...
2455
/**
2450
/**
2456
 * Closing the current directory
2451
 * Closing the current directory
2457
 *
2452
 *
2458
 * When existing, program needs to close the directory
2453
 * When existing, program needs to close the directory
2459
 */
2454
 */
2460
bool CPackages::closeDir(Utils::CStringList *errors, CProgressInfo *progress, bool removedir)
2455
bool CPackages::closeDir(Utils::WStringList *errors, CProgressInfo *progress, bool removedir)
2461
{
2456
{
2462
	if ( m_sCurrentDir.empty() )
2457
	if ( m_sCurrentDir.empty() )
2463
		return true;
2458
		return true;
2464
	if ( !m_bLoaded )
2459
	if ( !m_bLoaded )
2465
		return true;
2460
		return true;
2466
 
2461
 
2467
	CLog::log(CLog::Log_Directory, 1, "closing directory: " + m_sCurrentDir);
2462
	CLog::log(CLog::Log_Directory, 1, L"closing directory: " + m_sCurrentDir);
2468
 
2463
 
2469
	if ( m_bRenameText ) {
2464
	if ( m_bRenameText ) {
2470
		CLog::log(CLog::Log_Directory, 2, "Creating other language files for game");
2465
		CLog::log(CLog::Log_Directory, 2, L"Creating other language files for game");
2471
		CreateLanguageTextFiles(errors);
2466
		CreateLanguageTextFiles(errors);
2472
	}
2467
	}
2473
 
2468
 
2474
	CLog::log(CLog::Log_Directory, 2, "Backing up save game files");
2469
	CLog::log(CLog::Log_Directory, 2, L"Backing up save game files");
2475
 
2470
 
2476
	if ( CFileIO::Exists(m_sCurrentDir + "/mods/PluginManager.dat") ) {
2471
	if ( CFileIO::Exists(m_sCurrentDir + L"/mods/PluginManager.dat") ) {
2477
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.dat file");
2472
		CLog::log(CLog::Log_IO, 3, L"Removing old PluginManager.dat file");
2478
		CFileIO::Remove(m_sCurrentDir + "/mods/PluginManager.dat");
2473
		CFileIO::Remove(m_sCurrentDir + L"/mods/PluginManager.dat");
2479
	}
2474
	}
2480
	if ( CFileIO::Exists(m_sCurrentDir + "/mods/PluginManager.cat") ) {
2475
	if ( CFileIO::Exists(m_sCurrentDir + L"/mods/PluginManager.cat") ) {
2481
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.cat file");
2476
		CLog::log(CLog::Log_IO, 3, L"Removing old PluginManager.cat file");
2482
		CFileIO::Remove(m_sCurrentDir + "/mods/PluginManager.cat");
2477
		CFileIO::Remove(m_sCurrentDir + L"/mods/PluginManager.cat");
2483
	}
2478
	}
2484
 
2479
 
2485
	if ( !m_bVanilla )
2480
	if ( !m_bVanilla )
2486
	{
2481
	{
2487
		// base mode for Reunion
2482
		// base mode for Reunion
Line 2492... Line 2487...
2492
				fDat = m_pEnabledMod->GetNextFile(fDat);
2487
				fDat = m_pEnabledMod->GetNextFile(fDat);
2493
 
2488
 
2494
			if ( fDat )
2489
			if ( fDat )
2495
			{
2490
			{
2496
				C_File *fCat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2491
				C_File *fCat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2497
				while ( fCat && !fCat->IsFakePatch() && !fCat->checkFileExt("cat") && !fCat->baseName().Compare(fDat->baseName()) )
2492
				while ( fCat && !fCat->IsFakePatch() && !fCat->checkFileExt(L"cat") && !fCat->baseName().Compare(fDat->baseName()) )
2498
					fCat = m_pEnabledMod->GetNextFile(fCat);
2493
					fCat = m_pEnabledMod->GetNextFile(fCat);
2499
 
2494
 
2500
				if ( fCat )
2495
				if ( fCat )
2501
				{
2496
				{
2502
					CFileIO(fDat->filePointer()).copy(m_sCurrentDir + "/mods/PluginManager.dat");
2497
					CFileIO(fDat->filePointer()).copy(m_sCurrentDir + L"/mods/PluginManager.dat");
2503
					CFileIO(fCat->filePointer()).copy(m_sCurrentDir + "/mods/PluginManager.cat");
2498
					CFileIO(fCat->filePointer()).copy(m_sCurrentDir + L"/mods/PluginManager.cat");
2504
				}
2499
				}
2505
			}
2500
			}
2506
		}
2501
		}
2507
		else if ( m_iGame == GAME_X3 && !m_sSetMod.empty() && CFileIO::Exists(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat") && CFileIO::Exists(m_sCurrentDir + "/mods/" + m_sSetMod + ".dat"))
2502
		else if ( m_iGame == GAME_X3 && !m_sSetMod.empty() && CFileIO::Exists(m_sCurrentDir + L"/mods/" + m_sSetMod + L".cat") && CFileIO::Exists(m_sCurrentDir + L"/mods/" + m_sSetMod + L".dat"))
2508
		{
2503
		{
2509
			CLog::log(CLog::Log_Directory, 2, "Copying mod file: " + m_sSetMod + ", to PluginManager.cat");
2504
			CLog::log(CLog::Log_Directory, 2, L"Copying mod file: " + m_sSetMod + L", to PluginManager.cat");
2510
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".dat").copy(m_sCurrentDir + "/mods/PluginManager.dat");
2505
			CFileIO(m_sCurrentDir + L"/mods/" + m_sSetMod + L".dat").copy(m_sCurrentDir + L"/mods/PluginManager.dat");
2511
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat").copy(m_sCurrentDir + "/mods/PluginManager.cat");
2506
			CFileIO(m_sCurrentDir + L"/mods/" + m_sSetMod + L".cat").copy(m_sCurrentDir + L"/mods/PluginManager.cat");
2512
		}
2507
		}
2513
 
2508
 
2514
		if ( !CDirIO(m_sCurrentDir).exists("mods") )
2509
		if ( !CDirIO(m_sCurrentDir).exists(L"mods") )
2515
			CDirIO(m_sCurrentDir).create("mods");
2510
			CDirIO(m_sCurrentDir).create(L"mods");
2516
 
2511
 
2517
		SetupWares();
2512
		SetupWares();
2518
		SetupShips();
2513
		SetupShips();
2519
		createEMPFile();
2514
		createEMPFile();
2520
		CreateWareFiles();
2515
		CreateWareFiles();
Line 2534... Line 2529...
2534
 
2529
 
2535
	WriteData();
2530
	WriteData();
2536
	if ( removedir && m_bRemoveDir )
2531
	if ( removedir && m_bRemoveDir )
2537
	{
2532
	{
2538
		m_bRemoveDir = false;
2533
		m_bRemoveDir = false;
2539
		Utils::CStringList removeDirs;
2534
		Utils::WStringList removeDirs;
2540
		removeDirs.pushBack(".");
2535
		removeDirs.pushBack(L".");
2541
		removeUnusedDirectories(removeDirs, errors);
2536
		removeUnusedDirectories(removeDirs, errors);
2542
	}
2537
	}
2543
 
2538
 
2544
	this->setCurrentDir("");
2539
	this->setCurrentDir(L"");
2545
		 
2540
		 
2546
	m_bLoaded = false;
2541
	m_bLoaded = false;
2547
	return true;
2542
	return true;
2548
}
2543
}
2549
 
2544
 
2550
Utils::String CPackages::getModKey() const
2545
Utils::WString CPackages::getModKey() const
2551
{
2546
{
2552
	return m_gameExe.getModKey(m_iGame - 1);
2547
	return m_gameExe.getModKey(m_iGame - 1);
2553
}
2548
}
2554
Utils::String CPackages::selectedModName() const
2549
Utils::WString CPackages::selectedModName() const
2555
{
2550
{
2556
	if ( !m_pEnabledMod )
2551
	if ( !m_pEnabledMod )
2557
	{
2552
	{
2558
		if ( m_sSetMod.empty() && m_iGame == GAME_X3 )
2553
		if ( m_sSetMod.empty() && m_iGame == GAME_X3 )
2559
			return "PluginManager";
2554
			return L"PluginManager";
2560
		return m_sSetMod;
2555
		return m_sSetMod;
2561
	}
2556
	}
2562
 
2557
 
2563
	if ( !m_pEnabledMod->IsEnabled() )
2558
	if ( !m_pEnabledMod->IsEnabled() )
2564
		return m_sSetMod;
2559
		return m_sSetMod;
2565
 
2560
 
2566
	C_File *f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2561
	C_File *f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2567
	if ( !f )
2562
	if ( !f )
2568
		return m_sSetMod;
2563
		return m_sSetMod;
2569
 
2564
 
2570
	Utils::String name = f->filename();
2565
	Utils::WString name = f->filename();
2571
	name = name.left(-4);
2566
	name = name.left(-4);
2572
	return name;
2567
	return name;
2573
 
2568
 
2574
}
2569
}
2575
 
2570
 
Line 2578... Line 2573...
2578
	CLog::log(CLog::Log_Directory, 1, "Restoring PluginManager fake patch into game");
2573
	CLog::log(CLog::Log_Directory, 1, "Restoring PluginManager fake patch into game");
2579
 	m_iFakePatch = -1;
2574
 	m_iFakePatch = -1;
2580
 
2575
 
2581
	CFileIO catFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat");
2576
	CFileIO catFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat");
2582
	CFileIO datFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
2577
	CFileIO datFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
2583
 
2578
 
2584
	// if only 1 exists, remove it
2579
	// if only 1 exists, remove it
2585
	if ( catFile.exists() && !datFile.exists() ) {
2580
	if ( catFile.exists() && !datFile.exists() ) {
2586
		CLog::log(CLog::Log_Directory, 1, "WARNING: cat/dat file mismatch, dat file seems to be missing, removing cat file");
2581
		CLog::log(CLog::Log_Directory, 1, "WARNING: cat/dat file mismatch, dat file seems to be missing, removing cat file");
2587
		if ( !catFile.remove() ) return false;
2582
		if ( !catFile.remove() ) return false;
2588
	}
2583
	}
Line 2594... Line 2589...
2594
	// if both exists, lets rename them
2589
	// if both exists, lets rename them
2595
	if ( catFile.exists() && datFile.exists() )
2590
	if ( catFile.exists() && datFile.exists() )
2596
	{
2591
	{
2597
		CLog::log(CLog::Log_Directory, 3, "Creating pluginmanagerfake.txt file to add to Fake Patch");
2592
		CLog::log(CLog::Log_Directory, 3, "Creating pluginmanagerfake.txt file to add to Fake Patch");
2598
		// we need to add the plugin manager file in
2593
		// we need to add the plugin manager file in
2599
		Utils::String file = m_sTempDir;
2594
		Utils::WString file = m_sTempDir;
2600
		if ( !file.empty() )
2595
		if ( !file.empty() )
2601
			file += "/";
2596
			file += L"/";
2602
		file += "pluginmanagerfake.txt";
2597
		file += L"pluginmanagerfake.txt";
2603
		file = file.findReplace("\\", "/");
2598
		file = file.findReplace(L"\\", L"/");
2604
		CFileIO fakeFile(file);
2599
		CFileIO fakeFile(file);
2605
		std::vector<Utils::String> lines;
2600
		std::vector<Utils::String> lines;
2606
		lines.push_back("//pluginmanager fake patch");
2601
		lines.push_back("//pluginmanager fake patch");
2607
		CLog::log(CLog::Log_Directory, 3, "Writing pluginmanagerfake.txt file to add to Fake Patch");
2602
		CLog::log(CLog::Log_Directory, 3, "Writing pluginmanagerfake.txt file to add to Fake Patch");
2608
		if ( !fakeFile.writeFile(&lines) ) {
2603
		if ( !fakeFile.writeFile(&lines) ) {
Line 2619... Line 2614...
2619
			}	*/		
2614
			}	*/		
2620
		}
2615
		}
2621
 
2616
 
2622
		// backup existing mod files incase something happens to them
2617
		// backup existing mod files incase something happens to them
2623
		if ( !datFile.exists() || !catFile.exists() ) {
2618
		if ( !datFile.exists() || !catFile.exists() ) {
2624
			CLog::log(CLog::Log_Directory, 2, Utils::String("ERROR: ") + (!catFile.exists() ? "cat" : "dat") + " file appears to be missing");
2619
			CLog::log(CLog::Log_Directory, 2, Utils::WString("ERROR: ") + (!catFile.exists() ? L"cat" : L"dat") + L" file appears to be missing");
2625
		}
2620
		}
2626
		else {
2621
		else {
2627
			catFile.GetDirIO().create("Backup");
2622
			catFile.GetDirIO().create(L"Backup");
2628
			catFile.copy(catFile.dir() + "/Backup/" + catFile.filename());
2623
			catFile.copy(catFile.dir() + L"/Backup/" + catFile.filename());
2629
			datFile.copy(datFile.dir() + "/Backup/" + datFile.filename());
2624
			datFile.copy(datFile.dir() + L"/Backup/" + datFile.filename());
2630
		}
2625
		}
2631
 
2626
 
2632
 
2627
 
2633
		// find next available fake patch
2628
		// find next available fake patch
2634
		m_iFakePatch = this->findNextFakePatch();
2629
		m_iFakePatch = this->findNextFakePatch();
2635
		CLog::log(CLog::Log_Directory, 2, "Finding next available fake patch number: " + (long)m_iFakePatch);
2630
		CLog::log(CLog::Log_Directory, 2, "Finding next available fake patch number: " + (long)m_iFakePatch);
2636
 
2631
 
2637
		Utils::String filename = Utils::String::PadNumber(m_iFakePatch, 2);
2632
		Utils::WString filename = Utils::WString::PadNumber(m_iFakePatch, 2);
2638
		CLog::log(CLog::Log_Directory, 2, "Renaming cat file to: " + filename + ".cat");
2633
		CLog::log(CLog::Log_Directory, 2, L"Renaming cat file to: " + filename + L".cat");
2639
		if ( catFile.Rename(m_sCurrentDir + "/" + filename + ".cat") )
2634
		if ( catFile.Rename(m_sCurrentDir + L"/" + filename + L".cat") )
2640
		{
2635
		{
2641
			CLog::log(CLog::Log_Directory, 2, "Renaming dat file to: " + filename + ".dat");
2636
			CLog::log(CLog::Log_Directory, 2, L"Renaming dat file to: " + filename + L".dat");
2642
			if ( datFile.Rename(m_sCurrentDir + "/" + filename + ".dat") ){
2637
			if ( datFile.Rename(m_sCurrentDir + L"/" + filename + L".dat") ){
2643
				CLog::log(CLog::Log_Directory, 3, "Deleting pluginmanagerfake.txt temporary file");
2638
				CLog::log(CLog::Log_Directory, 3, L"Deleting pluginmanagerfake.txt temporary file");
2644
				fakeFile.remove();
2639
				fakeFile.remove();
2645
				return true;
2640
				return true;
2646
			}
2641
			}
2647
			else {
2642
			else {
2648
				CLog::log(CLog::Log_Directory, 2, "ERROR: failed to rename dat file");
2643
				CLog::log(CLog::Log_Directory, 2, L"ERROR: failed to rename dat file");
2649
			}
2644
			}
2650
 
2645
 
2651
			// TODO: restore cat file
2646
			// TODO: restore cat file
2652
		}
2647
		}
2653
		else {
2648
		else {
2654
			CLog::log(CLog::Log_Directory, 2, "ERROR: failed to rename cat file");
2649
			CLog::log(CLog::Log_Directory, 2, L"ERROR: failed to rename cat file");
2655
		}
2650
		}
2656
 
2651
 
2657
		CLog::log(CLog::Log_Directory, 3, "Deleting pluginmanagerfake.txt temporary file");
2652
		CLog::log(CLog::Log_Directory, 3, L"Deleting pluginmanagerfake.txt temporary file");
2658
		fakeFile.remove();
2653
		fakeFile.remove();
2659
		return false;
2654
		return false;
2660
	}
2655
	}
2661
 
2656
 
2662
	return true;
2657
	return true;
Line 2671... Line 2666...
2671
void CPackages::WriteData()
2666
void CPackages::WriteData()
2672
{
2667
{
2673
	if ( m_sCurrentDir.empty() )
2668
	if ( m_sCurrentDir.empty() )
2674
		return;
2669
		return;
2675
 
2670
 
2676
	CLog::log(CLog::Log_Directory, 1, "Writing data file for current directory: " + m_sCurrentDir);
2671
	CLog::log(CLog::Log_Directory, 1, L"Writing data file for current directory: " + m_sCurrentDir);
2677
 
2672
 
2678
	Utils::CStringList lines;
2673
	Utils::WStringList lines;
2679
	Utils::String version = "SpkInstaller: " + Utils::String::FromFloat(GetLibraryVersion(), 2);
2674
	Utils::WString version = L"SpkInstaller: " + Utils::WString::FromFloat(GetLibraryVersion(), 2);
2680
	lines.pushBack(version);
2675
	lines.pushBack(version);
2681
 
2676
 
2682
	lines.pushBack(Utils::String("UpdateTime: ") + (long)m_iLastUpdated);
2677
	lines.pushBack(Utils::WString(L"UpdateTime: ") + (long)m_iLastUpdated);
2683
	if ( m_iFakePatch != -1 )
2678
	if ( m_iFakePatch != -1 )
2684
		lines.pushBack(Utils::String("FakePatch: ") + (long)m_iFakePatch);
2679
		lines.pushBack(Utils::WString(L"FakePatch: ") + (long)m_iFakePatch);
2685
	if ( m_iSaveGame != -1 )
2680
	if ( m_iSaveGame != -1 )
2686
		lines.pushBack(Utils::String("SaveGame: ") + (long)m_iSaveGame);
2681
		lines.pushBack(Utils::WString(L"SaveGame: ") + (long)m_iSaveGame);
2687
	lines.pushBack(Utils::String("SaveGameManager: ") + (long)m_iSaveGameManager);
2682
	lines.pushBack(Utils::WString(L"SaveGameManager: ") + (long)m_iSaveGameManager);
2688
	if ( !m_bVanilla )
2683
	if ( !m_bVanilla )
2689
		lines.pushBack("Modified");
2684
		lines.pushBack(L"Modified");
2690
	if ( m_bUsedWare )
2685
	if ( m_bUsedWare )
2691
		lines.pushBack("UsedWare");
2686
		lines.pushBack(L"UsedWare");
2692
	if ( m_bSurpressProtectedWarning )
2687
	if ( m_bSurpressProtectedWarning )
2693
		lines.pushBack("SurpressProtectedWarning");
2688
		lines.pushBack(L"SurpressProtectedWarning");
2694
	if ( !m_sSetMod.empty() )
2689
	if ( !m_sSetMod.empty() )
2695
		lines.pushBack("SetMod: " + m_sSetMod);
2690
		lines.pushBack(L"SetMod: " + m_sSetMod);
2696
	if (!_sSaveDir.empty())
2691
	if (!_sSaveDir.empty())
2697
		lines.pushBack("SaveDir: " + _sSaveDir);
2692
		lines.pushBack(L"SaveDir: " + _sSaveDir);
2698
	lines.pushBack(Utils::String("ShipBuffer: ") + (long)m_iShipBuffer);
2693
	lines.pushBack(L"ShipBuffer: " + (long)m_iShipBuffer);
2699
	Utils::String wareBuffer = "WareBuffers:";
2694
	Utils::WString wareBuffer = L"WareBuffers:";
2700
	for ( int i = 0; i < WAREBUFFERS; i++ )
2695
	for ( int i = 0; i < WAREBUFFERS; i++ )
2701
		wareBuffer += Utils::String(" ") + (long)m_iWareBuffer[i];
2696
		wareBuffer += Utils::WString(L" ") + (long)m_iWareBuffer[i];
2702
	lines.pushBack(wareBuffer);
2697
	lines.pushBack(wareBuffer);
2703
	for ( int i = 0; i < WAREBUFFERS; i++ )
2698
	for ( int i = 0; i < WAREBUFFERS; i++ )
2704
	{
2699
	{
2705
		if ( !m_lGameWares[i].size() )
2700
		if ( !m_lGameWares[i].size() )
2706
			continue;
2701
			continue;
2707
		lines.pushBack(Utils::String("Wares: ") + (long)i + " " + (long)m_lGameWares[i].size());
2702
		lines.pushBack(Utils::WString(L"Wares: ") + (long)i + " " + (long)m_lGameWares[i].size());
2708
 
2703
 
2709
		for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
2704
		for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
2710
		{
2705
		{
2711
			SGameWare *gm = node->Data();
2706
			SGameWare *gm = node->Data();
2712
			lines.pushBack(Utils::String((long)gm->iPos) + " " + (long)gm->iType + " " + Utils::String((char)gm->cType) + " " + gm->sWareName);
2707
			lines.pushBack(Utils::WString((long)gm->iPos) + L" " + (long)gm->iType + L" " + Utils::WString((char)gm->cType) + L" " + gm->sWareName);
2713
		}
2708
		}
2714
	}
2709
	}
2715
 
2710
 
2716
	for(auto itr = m_lNonRemovedFiles.begin(); itr != m_lNonRemovedFiles.end(); itr++)
2711
	for(auto itr = _lNonRemovedFiles.begin(); itr != _lNonRemovedFiles.end(); itr++)
2717
		lines.pushBack("NonRemovedFile: " + (*itr)->str);
2712
		lines.pushBack(L"NonRemovedFile: " + (*itr)->str);
2718
 
2713
 
2719
	if ( m_lGameShips.size() )
2714
	if ( m_lGameShips.size() )
2720
	{
2715
	{
2721
		lines.pushBack(Utils::String("Ships: ") + (long)m_lGameShips.size());
2716
		lines.pushBack(Utils::String(L"Ships: ") + (long)m_lGameShips.size());
2722
 
2717
 
2723
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
2718
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
2724
		{
2719
		{
2725
			SGameShip *gm = node->Data();
2720
			SGameShip *gm = node->Data();
2726
			lines.pushBack(Utils::String((long)gm->iType) + " $#C:" + gm->sShipClass + " " + gm->sShipID);
2721
			lines.pushBack(Utils::WString((long)gm->iType) + L" $#C:" + gm->sShipClass + L" " + gm->sShipID);
2727
		}
2722
		}
2728
	}
2723
	}
2729
 
2724
 
2730
	// write created Files
2725
	// write created Files
2731
	if ( !m_lCreatedFiles.empty() )
2726
	if ( !_lCreatedFiles.empty() )
2732
	{
2727
	{
2733
		for(auto itr = m_lCreatedFiles.begin(); itr != m_lCreatedFiles.end(); itr++)
2728
		for(auto itr = _lCreatedFiles.begin(); itr != _lCreatedFiles.end(); itr++)
2734
			lines.pushBack("CreatedFile: " + (*itr)->str.findRemove(m_sCurrentDir));
2729
			lines.pushBack(L"CreatedFile: " + (*itr)->str.findRemove(m_sCurrentDir));
2735
	}
2730
	}
2736
 
2731
 
2737
	// write uninstall files
2732
	// write uninstall files
2738
	if ( !m_lUninstallFiles.empty() )
2733
	if ( !m_lUninstallFiles.empty() )
2739
	{
2734
	{
2740
		for ( CListNode<C_File> *node = m_lUninstallFiles.Front(); node; node = node->next() )
2735
		for ( CListNode<C_File> *node = m_lUninstallFiles.Front(); node; node = node->next() )
2741
		{
2736
		{
2742
			C_File *uf = node->Data();
2737
			C_File *uf = node->Data();
2743
			Utils::String uString = "Uninstall: ";
2738
			Utils::WString uString = L"Uninstall: ";
2744
			uString += Utils::String::Number((long)uf->GetCreationTime()) + " ";
2739
			uString += Utils::WString::Number((long)uf->GetCreationTime()) + L" ";
2745
			uString += uf->filename();
2740
			uString += uf->filename();
2746
			lines.pushBack(uString);
2741
			lines.pushBack(uString);
2747
		}
2742
		}
2748
	}
2743
	}
2749
 
2744
 
2750
	// write the original file data
2745
	// write the original file data
2751
	_pOriginalFiles->writeData(lines);
2746
	_pOriginalFiles->writeData(lines);
2752
 
2747
 
2753
	// write the global changes
2748
	// write the global changes
2754
	if ( !m_lGlobals.empty() )
2749
	if ( !_lGlobals.empty() )
2755
	{
2750
	{
2756
		for(auto itr = m_lGlobals.begin(); itr != m_lGlobals.end(); itr++)
2751
		for(auto itr = _lGlobals.begin(); itr != _lGlobals.end(); itr++)
2757
			lines.pushBack("GlobalSetting: " + (*itr)->str + ":" + (*itr)->data.findRemove(";"));
2752
			lines.pushBack(L"GlobalSetting: " + (*itr)->str + L":" + (*itr)->data.findRemove(L";"));
2758
	}
2753
	}
2759
 
2754
 
2760
	// write the fake patch ordering
2755
	// write the fake patch ordering
2761
	if ( !m_lFakePatchOrder.empty() )
2756
	if ( !_lFakePatchOrder.empty() )
2762
	{
2757
	{
2763
		for(auto itr = m_lFakePatchOrder.begin(); itr != m_lFakePatchOrder.end(); itr++)
2758
		for(auto itr = _lFakePatchOrder.begin(); itr != _lFakePatchOrder.end(); itr++)
2764
			lines.pushBack("FakePatchOrder: " + (*itr)->str + ":" + (*itr)->data);
2759
			lines.pushBack(L"FakePatchOrder: " + (*itr)->str + L":" + (*itr)->data);
2765
	}
2760
	}
2766
 
2761
 
2767
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
2762
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
2768
		SWarePriceOverride *ware = node->Data();
2763
		SWarePriceOverride *ware = node->Data();
2769
		switch(ware->type) {
2764
		switch(ware->type) {
2770
			case Ware_EMP:
2765
			case Ware_EMP:
2771
				lines.pushBack(Utils::String("EMPPriceOverride:") + (long)ware->pos + " " + (long)ware->relval);
2766
				lines.pushBack(Utils::WString(L"EMPPriceOverride:") + (long)ware->pos + L" " + (long)ware->relval);
2772
				if ( ware->bNotority )
2767
				if ( ware->bNotority )
2773
					lines.pushBack(Utils::String("EMPNotoOverride:") + (long)ware->pos + " " + (long)ware->notority);
2768
					lines.pushBack(Utils::WString(L"EMPNotoOverride:") + (long)ware->pos + L" " + (long)ware->notority);
2774
				break;
2769
				break;
2775
			case Ware_Custom:
2770
			case Ware_Custom:
2776
				lines.pushBack(Utils::String("CustomWarePriceOverride:") + ware->id + ";" + (long)ware->relval);
2771
				lines.pushBack(Utils::WString(L"CustomWarePriceOverride:") + ware->id + L";" + (long)ware->relval);
2777
				if ( ware->bNotority )
2772
				if ( ware->bNotority )
2778
					lines.pushBack(Utils::String("CustomWareNotoOverride:") + ware->id + ";" + (long)ware->notority);
2773
					lines.pushBack(Utils::WString(L"CustomWareNotoOverride:") + ware->id + L";" + (long)ware->notority);
2779
				break;
2774
				break;
2780
			case Ware_BuiltIn:
2775
			case Ware_BuiltIn:
2781
				lines.pushBack(Utils::String("BuiltInWarePriceOverride:") + (long)ware->pos + " " + (long)ware->relval);
2776
				lines.pushBack(Utils::WString(L"BuiltInWarePriceOverride:") + (long)ware->pos + L" " + (long)ware->relval);
2782
				if ( ware->bNotority )
2777
				if ( ware->bNotority )
2783
					lines.pushBack(Utils::String("BuiltInWareNotoOverride:") + (long)ware->pos + " " + (long)ware->notority);
2778
					lines.pushBack(Utils::WString(L"BuiltInWareNotoOverride:") + (long)ware->pos + L" " + (long)ware->notority);
2784
				break;
2779
				break;
2785
		}
2780
		}
2786
	}
2781
	}
2787
 
2782
 
2788
	// write the global file list
2783
	// write the global file list
2789
	lines.pushBack("GlobalFiles:");
2784
	lines.pushBack(L"GlobalFiles:");
2790
	int num = 0;
2785
	int num = 0;
2791
	for ( CListNode<C_File> *fn = m_lFiles.Front(); fn; fn = fn->next() )
2786
	for ( CListNode<C_File> *fn = m_lFiles.Front(); fn; fn = fn->next() )
2792
	{
2787
	{
2793
		C_File *f = fn->Data();
2788
		C_File *f = fn->Data();
2794
		f->SetPos(num++);
2789
		f->SetPos(num++);
2795
 
2790
 
2796
		Utils::String line = Utils::String::Number(f->GetFileType()) + ":" + Utils::String::Number((long)f->GetCreationTime()) + ":" + f->dir() + ":";
2791
		Utils::WString line = Utils::WString::Number(f->GetFileType()) + L":" + Utils::WString::Number((long)f->GetCreationTime()) + L":" + f->dir() + L":";
2797
		if ( f->IsShared() && !f->IsFakePatch() )
2792
		if ( f->IsShared() && !f->IsFakePatch() )
2798
			line += "1:";
2793
			line += L"1:";
2799
		else
2794
		else
2800
			line += "0:";
2795
			line += L"0:";
2801
 
2796
 
2802
		Utils::String filename = f->filePointer().findRemove(m_sCurrentDir);
2797
		Utils::WString filename = f->filePointer().findRemove(m_sCurrentDir);
2803
 
2798
 
2804
		if ( f->IsDisabled() )
2799
		if ( f->IsDisabled() )
2805
			line += "D#";
2800
			line += L"D#";
2806
 
2801
 
2807
		line += "G#";
2802
		line += L"G#";
2808
		line += (long)f->GetGame();
2803
		line += (long)f->GetGame();
2809
		line += "#";
2804
		line += L"#";
2810
 
2805
 
2811
		line += filename;
2806
		line += filename;
2812
 
2807
 
2813
		if ( !f->originalName().empty() )
2808
		if ( !f->originalName().empty() )
2814
		{
2809
		{
2815
			line += "O#";
2810
			line += L"O#";
2816
			line += f->originalName();
2811
			line += f->originalName();
2817
		}
2812
		}
2818
 
2813
 
2819
		lines.pushBack(line);
2814
		lines.pushBack(line);
2820
	}
2815
	}
Line 2823... Line 2818...
2823
	for ( CListNode<CBaseFile> *pn = m_lPackages.Front(); pn; pn = pn->next() )
2818
	for ( CListNode<CBaseFile> *pn = m_lPackages.Front(); pn; pn = pn->next() )
2824
	{
2819
	{
2825
		CBaseFile *package = pn->Data();
2820
		CBaseFile *package = pn->Data();
2826
 
2821
 
2827
		if ( package->GetType() == TYPE_SPK )
2822
		if ( package->GetType() == TYPE_SPK )
2828
			lines.pushBack("<script>");
2823
			lines.pushBack(L"<script>");
2829
		else if ( package->GetType() == TYPE_XSP )
2824
		else if ( package->GetType() == TYPE_XSP )
2830
			lines.pushBack("<ship>");
2825
			lines.pushBack(L"<ship>");
2831
		else if ( package->GetType() == TYPE_ARCHIVE )
2826
		else if ( package->GetType() == TYPE_ARCHIVE )
2832
			lines.pushBack("<archive>");
2827
			lines.pushBack(L"<archive>");
2833
		else if ( package->GetType() == TYPE_BASE )
2828
		else if ( package->GetType() == TYPE_BASE )
2834
			lines.pushBack("<base>");
2829
			lines.pushBack(L"<base>");
2835
		else
2830
		else
2836
			continue;
2831
			continue;
2837
 
2832
 
2838
		if ( !package->filename().empty() )
2833
		if ( !package->filename().empty() )
2839
			lines.pushBack("Installspk: " + package->filename());
2834
			lines.pushBack(L"Installspk: " + package->filename());
2840
 
2835
 
2841
		Utils::String valuesline = package->createValuesLine();
2836
		Utils::WString valuesline = package->createValuesLine();
2842
		if ( valuesline.back() == '\n')
2837
		if ( valuesline.back() == '\n')
2843
			valuesline.truncate((int)valuesline.length() - 1);
2838
			valuesline.truncate((int)valuesline.length() - 1);
2844
		lines.pushBack(valuesline);
2839
		lines.pushBack(valuesline);
2845
 
2840
 
2846
		if ( !package->IsEnabled() )
2841
		if ( !package->IsEnabled() )
2847
			lines.pushBack("Disabled");
2842
			lines.pushBack(L"Disabled");
2848
		if ( !package->IsModifiedEnabled() )
2843
		if ( !package->IsModifiedEnabled() )
2849
			lines.pushBack("ModifiedDisabled");
2844
			lines.pushBack(L"ModifiedDisabled");
2850
 
2845
 
2851
		if (package->icon())
2846
		if (package->icon())
2852
			lines.pushBack("Icon: " + package->iconExt() + " " + package->icon()->filePointer() );
2847
			lines.pushBack(L"Icon: " + package->iconExt() + L" " + package->icon()->filePointer() );
2853
 
2848
 
2854
		Utils::String fileline("Files:");
2849
		Utils::WString fileline(L"Files:");
2855
		for ( CListNode<C_File> *fn = package->GetFileList()->Front(); fn; fn = fn->next() )
2850
		for ( CListNode<C_File> *fn = package->GetFileList()->Front(); fn; fn = fn->next() )
2856
		{
2851
		{
2857
			C_File *f = fn->Data();
2852
			C_File *f = fn->Data();
2858
			fileline += " ";
2853
			fileline += L" ";
2859
			fileline += Utils::String::Number(f->GetPos());
2854
			fileline += Utils::WString::Number(f->GetPos());
2860
		}
2855
		}
2861
		lines.pushBack(fileline);
2856
		lines.pushBack(fileline);
2862
	}
2857
	}
2863
 
2858
 
2864
	lines.pushBack("</scripts>");
2859
	lines.pushBack(L"</scripts>");
2865
 
2860
 
2866
	CFileIO datFile(m_sCurrentDir + "/PluginManager/PluginManager.new");
2861
	CFileIO datFile(m_sCurrentDir + L"/PluginManager/PluginManager.new");
2867
 
2862
 
2868
	CDirIO Dir(m_sCurrentDir);
2863
	CDirIO Dir(m_sCurrentDir);
2869
	if ( !Dir.exists("PluginManager") ) {
2864
	if ( !Dir.exists(L"PluginManager") ) {
2870
		CLog::log(CLog::Log_IO, 2, "Creating PluginManager directory");
2865
		CLog::log(CLog::Log_IO, 2, L"Creating PluginManager directory");
2871
 		Dir.create("PluginManager");
2866
 		Dir.create(L"PluginManager");
2872
	}
2867
	}
2873
 
2868
 
2874
	CLog::log(CLog::Log_IO, 2, "Writing data file: " + m_sCurrentDir + "/PluginManager/PluginManager.new");
2869
	CLog::log(CLog::Log_IO, 2, L"Writing data file: " + m_sCurrentDir + L"/PluginManager/PluginManager.new");
2875
	if ( !datFile.writeFile(&lines) )
2870
	if ( !datFile.writeFile(&lines) )
2876
	{
-
 
2877
		CLog::log(CLog::Log_IO, 1, "ERROR: Failed to write data file");
2871
		CLog::log(CLog::Log_IO, 1, L"ERROR: Failed to write data file");
2878
	}
-
 
2879
	else {
2872
	else {
2880
		CLog::log(CLog::Log_IO, 2, "Removing old data file: " + m_sCurrentDir + "/PluginManager/PluginManager.dat");
2873
		CLog::log(CLog::Log_IO, 2, L"Removing old data file: " + m_sCurrentDir + L"/PluginManager/PluginManager.dat");
2881
		if ( !CFileIO::Exists(m_sCurrentDir + "/PluginManager/PluginManager.dat") || CFileIO::Remove(m_sCurrentDir + "/PluginManager/PluginManager.dat") ) {
2874
		if ( !CFileIO::Exists(m_sCurrentDir + L"/PluginManager/PluginManager.dat") || CFileIO::Remove(m_sCurrentDir + L"/PluginManager/PluginManager.dat") ) {
2882
			CLog::log(CLog::Log_IO, 2, "Renaming data file: PluginManager.new => PluginManager.dat");
2875
			CLog::log(CLog::Log_IO, 2, L"Renaming data file: PluginManager.new => PluginManager.dat");
2883
			datFile.Rename(m_sCurrentDir + "/PluginManager/PluginManager.dat");
2876
			datFile.Rename(m_sCurrentDir + L"/PluginManager/PluginManager.dat");
2884
		}
2877
		}
2885
	}
2878
	}
2886
}
2879
}
2887
 
2880
 
2888
 
2881
 
2889
/**
2882
/**
2890
 * Get All Files
2883
 * Get All Files
2891
 *
2884
 *
2892
 * Gets a list of all files, includes any child package files
2885
 * Gets a list of all files, includes any child package files
2893
 */
2886
 */
2894
int CPackages::GetAllPackageFiles(CBaseFile *package, CLinkList<C_File> *fileList, bool includeChild)
2887
int CPackages::GetAllPackageFiles(CBaseFile *package, CLinkList<C_File> *fileList, bool includeChild)
2895
{
2888
{
2896
	for ( CListNode<C_File> *node = package->GetFileList()->Front(); node; node = node->next() )
2889
	for ( CListNode<C_File> *node = package->GetFileList()->Front(); node; node = node->next() )
2897
	{
2890
	{
2898
		C_File *f = node->Data();
2891
		C_File *f = node->Data();
2899
		if ( !fileList->FindData(f) )
2892
		if ( !fileList->FindData(f) )
2900
			fileList->push_back(f);
2893
			fileList->push_back(f);
2901
	}
2894
	}
2902
 
2895
 
2903
	if ( includeChild )
2896
	if ( includeChild )
2904
	{
2897
	{
2905
		CLinkList<CBaseFile> childList;
2898
		CLinkList<CBaseFile> childList;
2906
		if ( this->GetChildPackages(package, &childList) )
2899
		if ( this->GetChildPackages(package, &childList) )
2907
		{
2900
		{
2908
			for ( CBaseFile *child = childList.First(); child; child = childList.Next() )
2901
			for ( CBaseFile *child = childList.First(); child; child = childList.Next() )
2909
				this->GetAllPackageFiles(child, fileList, includeChild);
2902
				this->GetAllPackageFiles(child, fileList, includeChild);
2910
		}
2903
		}
2911
	}
2904
	}
2912
 
2905
 
2913
	// disablign for vanilla, make sure we add all files
2906
	// disablign for vanilla, make sure we add all files
2914
	if ( m_bDisableVanilla )
2907
	if ( m_bDisableVanilla )
2915
	{
2908
	{
2916
		for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
2909
		for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
2917
		{
2910
		{
2918
			C_File *f = node->Data();
2911
			C_File *f = node->Data();
2919
			if ( !fileList->FindData(f) )
2912
			if ( !fileList->FindData(f) )
2920
				fileList->push_back(f);
2913
				fileList->push_back(f);
2921
		}
2914
		}
2922
	}
2915
	}
2923
 
2916
 
2924
	return fileList->size();
2917
	return fileList->size();
2925
}
2918
}
2926
 
2919
 
2927
int CPackages::GetAllPackageFiles(CLinkList<CBaseFile> *list, CLinkList<C_File> *fileList, bool includeChild)
2920
int CPackages::GetAllPackageFiles(CLinkList<CBaseFile> *list, CLinkList<C_File> *fileList, bool includeChild)
2928
{
2921
{
2929
	for ( CListNode<CBaseFile> *node = list->Front(); node; node = node->next() )
2922
	for ( CListNode<CBaseFile> *node = list->Front(); node; node = node->next() )
2930
		this->GetAllPackageFiles(node->Data(), fileList, includeChild);
2923
		this->GetAllPackageFiles(node->Data(), fileList, includeChild);
Line 2935... Line 2928...
2935
 * Add Log
2928
 * Add Log
2936
 *
2929
 *
2937
 * Adds a log entry to displayed at end
2930
 * Adds a log entry to displayed at end
2938
 */
2931
 */
2939
 
2932
 
2940
void CPackages::addLogEntry(int type, const Utils::String &args, Utils::CStringList *errors)
2933
void CPackages::addLogEntry(int type, const Utils::WString &args, Utils::WStringList *errors)
2941
{
2934
{
2942
	if (!errors)
2935
	if (!errors)
2943
		return;
2936
		return;
2944
 
2937
 
2945
	errors->pushBack(args, ERRORLOG(type));
2938
	errors->pushBack(args, ERRORLOG(type));
Line 2959... Line 2952...
2959
 * param: errors		- The string list for all the status for debugging, ie has an entry for whats happened to every file
2952
 * param: errors		- The string list for all the status for debugging, ie has an entry for whats happened to every file
2960
 * param: progress		- The progress class, updates a progress screen of the derived class
2953
 * param: progress		- The progress class, updates a progress screen of the derived class
2961
 *
2954
 *
2962
 * return: boolen - Returns true if the package enabling was successful
2955
 * return: boolen - Returns true if the package enabling was successful
2963
 */
2956
 */
2964
bool CPackages::enablePackage(CBaseFile *package, Utils::CStringList *errors, CProgressInfo *progress )
2957
bool CPackages::enablePackage(CBaseFile *package, Utils::WStringList *errors, CProgressInfo *progress )
2965
{
2958
{
2966
	ClearError();
2959
	ClearError();
2967
 
2960
 
2968
	// if already enabled, just skip
2961
	// if already enabled, just skip
2969
	if ( package->IsEnabled() )
2962
	if ( package->IsEnabled() )
Line 2986... Line 2979...
2986
	if ( this->PrepareEnablePackage(package) )
2979
	if ( this->PrepareEnablePackage(package) )
2987
		return this->enablePreparedPackages(errors, progress);
2980
		return this->enablePreparedPackages(errors, progress);
2988
 
2981
 
2989
	return false;
2982
	return false;
2990
}
2983
}
2991
bool CPackages::enablePreparedPackages(Utils::CStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *enabledPackages )
2984
bool CPackages::enablePreparedPackages(Utils::WStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *enabledPackages )
2992
{
2985
{
2993
	ClearError();
2986
	ClearError();
2994
 
2987
 
2995
	// get all files, including children
2988
	// get all files, including children
2996
	CLinkList<C_File> fileList;
2989
	CLinkList<C_File> fileList;
2997
	int maxFiles = this->GetAllPackageFiles(&m_lEnableList, &fileList, false);
2990
	int maxFiles = this->GetAllPackageFiles(&m_lEnableList, &fileList, false);
2998
 
2991
 
2999
	int fileCount = 0;
2992
	int fileCount = 0;
3000
	// we use this list to match cat and dat files
2993
	// we use this list to match cat and dat files
3001
	Utils::CStringList fakePatches;
2994
	Utils::WStringList fakePatches;
3002
	for ( CListNode<C_File> *node = fileList.Front(); node; node = node->next() )
2995
	for ( CListNode<C_File> *node = fileList.Front(); node; node = node->next() )
3003
	{
2996
	{
3004
		C_File *f = node->Data();
2997
		C_File *f = node->Data();
3005
		if (!f->isForGame(m_iGame))
2998
		if (!f->isForGame(m_iGame))
3006
			continue;
2999
			continue;
3007
		CBaseFile *package = NULL;
3000
		CBaseFile *package = NULL;
3008
		for ( CListNode<CBaseFile> *node = m_lEnableList.Front(); node; node = node->next() )
3001
		for ( CListNode<CBaseFile> *node = m_lEnableList.Front(); node; node = node->next() )
3009
		{
3002
		{
3010
			CBaseFile *p = node->Data();
3003
			CBaseFile *p = node->Data();
3011
			if ( p->IsFileAdded(f) )
3004
			if ( p->IsFileAdded(f) )
3012
			{
3005
			{
3013
				package = p;
3006
				package = p;
3014
				break;
3007
				break;
Line 3043... Line 3036...
3043
		}
3036
		}
3044
 
3037
 
3045
		// check if theres an original file to backup
3038
		// check if theres an original file to backup
3046
		_pOriginalFiles->doBackup(f, errors);
3039
		_pOriginalFiles->doBackup(f, errors);
3047
 
3040
 
3048
		Utils::String newFilename = f->getNameDirectory(package);
3041
		Utils::WString newFilename = f->getNameDirectory(package);
3049
 
3042
 
3050
		// fake patches need to be renamed
3043
		// fake patches need to be renamed
3051
		if ( f->IsFakePatch() )
3044
		if ( f->IsFakePatch() )
3052
		{
3045
		{
3053
			// first check if the matching file has been done already
3046
			// first check if the matching file has been done already
3054
			if (fakePatches.contains(f->baseName()))
3047
			if (fakePatches.contains(f->baseName()))
3055
				newFilename = fakePatches.findString(f->baseName()) + "." + f->fileExt();
3048
				newFilename = fakePatches.findString(f->baseName()) + L"." + f->fileExt();
3056
			// we need to find the next available number instead
3049
			// we need to find the next available number instead
3057
			else
3050
			else
3058
			{
3051
			{
3059
				Utils::String newPos = Utils::String::PadNumber(findNextFakePatch(), 2);
3052
				Utils::WString newPos = Utils::WString::PadNumber(findNextFakePatch(), 2);
3060
				newFilename = newPos + "." + f->fileExt();
3053
				newFilename = newPos + L"." + f->fileExt();
3061
				// and wee need to push this onto the string list so we can adjust the matchign pair
3054
				// and wee need to push this onto the string list so we can adjust the matchign pair
3062
				fakePatches.pushBack(f->baseName(), newPos);
3055
				fakePatches.pushBack(f->baseName(), newPos);
3063
			}
3056
			}
3064
		}
3057
		}
3065
 
3058
 
3066
		// lets actually move the file back now
3059
		// lets actually move the file back now
3067
		// !!error checking!!
3060
		// !!error checking!!
3068
		CFileIO currentFile(f->filePointer());
3061
		CFileIO currentFile(f->filePointer());
3069
		CFileIO newFile(m_sCurrentDir + "/" + newFilename);
3062
		CFileIO newFile(m_sCurrentDir + L"/" + newFilename);
3070
		if ( !currentFile.exists() )
3063
		if ( !currentFile.exists() )
3071
		{
3064
		{
3072
			// missing file ??
3065
			// missing file ??
3073
			if ( !newFile.exists() )
3066
			if ( !newFile.exists() )
3074
			{
3067
			{
3075
				this->addLogEntry(SPKINSTALL_MISSINGFILE, newFilename, errors);
3068
				this->addLogEntry(SPKINSTALL_MISSINGFILE, newFilename.toString(), errors);
3076
				continue;
3069
				continue;
3077
			}
3070
			}
3078
		}
3071
		}
3079
		// remove existing file
3072
		// remove existing file
3080
		// file exists, so lets try to move it
3073
		// file exists, so lets try to move it
3081
		else
3074
		else
3082
		{
3075
		{
3083
			if ( newFile.exists() )
3076
			if ( newFile.exists() )
3084
				newFile.remove();
3077
				newFile.remove();
3085
 
3078
 
3086
			if ( !currentFile.Rename(newFile.fullFilename()) )
3079
			if ( !currentFile.Rename(newFile.fullFilename()) )
3087
			{
3080
			{
3088
				this->addLogEntry(SPKINSTALL_ENABLEFILE_FAIL, newFilename, errors);
3081
				this->addLogEntry(SPKINSTALL_ENABLEFILE_FAIL, newFilename.toString(), errors);
3089
				continue;
3082
				continue;
3090
			}
3083
			}
3091
		}
3084
		}
3092
 
3085
 
3093
		this->addLogEntry(SPKINSTALL_ENABLEFILE, newFilename, errors);
3086
		this->addLogEntry(SPKINSTALL_ENABLEFILE, newFilename.toString(), errors);
3094
 
3087
 
3095
		// adjust the internal name to match the new filename
3088
		// adjust the internal name to match the new filename
3096
		f->setFilename(m_sCurrentDir + "/" + newFilename);
3089
		f->setFilename((m_sCurrentDir + L"/" + newFilename).toString());
3097
		// no longer disabled, we need to remove the flag
3090
		// no longer disabled, we need to remove the flag
3098
		f->SetDisabled(false);
3091
		f->SetDisabled(false);
3099
	}
3092
	}
3100
 
3093
 
3101
	// recursive, auto enable all children
3094
	// recursive, auto enable all children
Line 3122... Line 3115...
3122
	// disabled the mod
3115
	// disabled the mod
3123
	if ( oldMod && oldMod != m_pEnabledMod && !m_bForceModInstall )
3116
	if ( oldMod && oldMod != m_pEnabledMod && !m_bForceModInstall )
3124
		this->disablePackage(oldMod, errors, progress);
3117
		this->disablePackage(oldMod, errors, progress);
3125
 
3118
 
3126
	// lets remove all the directories we might have left empty
3119
	// lets remove all the directories we might have left empty
3127
	Utils::CStringList removeDirs;
3120
	Utils::WStringList removeDirs;
3128
	removeDirs.pushBack("PluginManager/Disabled");
3121
	removeDirs.pushBack(L"PluginManager/Disabled");
3129
	removeUnusedDirectories(removeDirs, errors);
3122
	removeUnusedDirectories(removeDirs, errors);
3130
 
3123
 
3131
	m_lEnableList.clear();
3124
	m_lEnableList.clear();
3132
 
3125
 
3133
	this->WriteData();
3126
	this->WriteData();
3134
 
3127
 
3135
	return true;
3128
	return true;
3136
}
3129
}
3137
 
3130
 
3138
 
3131
 
3139
bool CPackages::disablePreparedPackages(Utils::CStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *disabledPackages )
3132
bool CPackages::disablePreparedPackages(Utils::WStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *disabledPackages )
3140
{
3133
{
3141
	if ( progress )
3134
	if ( progress )
3142
		progress->UpdateStatus(PROGRESS_DISABLEFILE);
3135
		progress->UpdateStatus(PROGRESS_DISABLEFILE);
3143
 
3136
 
3144
	UpdateUsedFiles(&m_lDisableList, false);
3137
	UpdateUsedFiles(&m_lDisableList, false);
3145
 
3138
 
3146
	// checks if there are any original files to restore and if any fake patches were disabled to reshuffle
3139
	// checks if there are any original files to restore and if any fake patches were disabled to reshuffle
3147
	bool original = false, shuffle = false;
3140
	bool original = false, shuffle = false;
3148
 
3141
 
3149
	// holds our list of directories that we might need to remove, only empty ones from this list will actually be removed
3142
	// holds our list of directories that we might need to remove, only empty ones from this list will actually be removed
3150
	Utils::CStringList removeDirs;
3143
	Utils::WStringList removeDirs;
3151
 
3144
 
3152
	// get all files, including children
3145
	// get all files, including children
3153
	CLinkList<C_File> fileList;
3146
	CLinkList<C_File> fileList;
3154
	int maxFiles = this->GetAllPackageFiles(&m_lDisableList, &fileList, true);
3147
	int maxFiles = this->GetAllPackageFiles(&m_lDisableList, &fileList, true);
3155
 
3148
 
Line 3176... Line 3169...
3176
			progress->UpdateFile(f);
3169
			progress->UpdateFile(f);
3177
		}
3170
		}
3178
 
3171
 
3179
		// only delete files that are not used by any other enabled packages, counter from UpdateUsedFiles()
3172
		// only delete files that are not used by any other enabled packages, counter from UpdateUsedFiles()
3180
		if ( f->getUsed() || (f->IsShared() && !m_bDisableVanilla) )
3173
		if ( f->getUsed() || (f->IsShared() && !m_bDisableVanilla) )
3181
			continue;
3174
			continue;
3182
 
3175
 
3183
		// file is already disabled, no need to disable again
3176
		// file is already disabled, no need to disable again
3184
		if ( f->IsDisabled() )
3177
		if ( f->IsDisabled() )
3185
			continue;
3178
			continue;
3186
 
3179
 
3187
		// readmes, uninstall and extra files dont need to be disabled
3180
		// readmes, uninstall and extra files dont need to be disabled
3188
		// Extra files not in the "Extras" directory could be anywhere, so these should be disabled incase they are game changing files, ie in "types"
3181
		// Extra files not in the "Extras" directory could be anywhere, so these should be disabled incase they are game changing files, ie in "types"
3189
		if ( f->GetFileType() == FILETYPE_README || f->GetFileType() == FILETYPE_UNINSTALL || (f->GetFileType() == FILETYPE_EXTRA && f->dir().left(5).lower() == "Extra") )
3182
		if ( f->GetFileType() == FILETYPE_README || f->GetFileType() == FILETYPE_UNINSTALL || (f->GetFileType() == FILETYPE_EXTRA && f->dir().left(5).lower() == "Extra") )
3190
			continue;
3183
			continue;
Line 3192... Line 3185...
3192
		// check if there is a matching uninstall file, ie there the script file is also an uninstall script file for a previously uninstalled package that has yet to be removed
3185
		// check if there is a matching uninstall file, ie there the script file is also an uninstall script file for a previously uninstalled package that has yet to be removed
3193
		if ( f->GetFileType() == FILETYPE_SCRIPT )
3186
		if ( f->GetFileType() == FILETYPE_SCRIPT )
3194
		{
3187
		{
3195
			bool found = false;
3188
			bool found = false;
3196
			for ( CListNode<C_File> *uNode = m_lUninstallFiles.Front(); uNode; uNode = uNode->next() )
3189
			for ( CListNode<C_File> *uNode = m_lUninstallFiles.Front(); uNode; uNode = uNode->next() )
3197
			{
3190
			{
3198
				C_File *uFile = uNode->Data();
3191
				C_File *uFile = uNode->Data();
3199
				if ( uFile->filename().Compare(f->filename()) )
3192
				if ( uFile->filename().Compare(f->filename()) )
3200
				{
3193
				{
3201
					found = true;
3194
					found = true;
3202
					break;
3195
					break;
Line 3206... Line 3199...
3206
			if ( found )
3199
			if ( found )
3207
				continue;
3200
				continue;
3208
		}
3201
		}
3209
 
3202
 
3210
		if ( f->GetFileType() == FILETYPE_MOD && !f->IsFakePatch() && f->checkFileExt("cat") )
3203
		if ( f->GetFileType() == FILETYPE_MOD && !f->IsFakePatch() && f->checkFileExt("cat") )
3211
		{
3204
		{
3212
			if ( f->baseName().Compare(m_sSetMod) )
3205
			if ( f->baseName().Compare(m_sSetMod.toString()) )
3213
				m_sSetMod = Utils::String::Null();
3206
				m_sSetMod = Utils::WString::Null();
3214
		}
3207
		}
3215
 
3208
 
3216
		// file is not being used by any enabled package
3209
		// file is not being used by any enabled package
3217
		// set disabled and move to disabled directory
3210
		// set disabled and move to disabled directory
3218
		CDirIO Dir(m_sCurrentDir);
3211
		CDirIO Dir(m_sCurrentDir);
3219
		Utils::String newFilename = "PluginManager/Disabled/";
3212
		Utils::WString newFilename = L"PluginManager/Disabled/";
3220
 
3213
 
3221
		// fake patches have thier own special directory
3214
		// fake patches have thier own special directory
3222
		if ( f->IsFakePatch() )
3215
		if ( f->IsFakePatch() )
3223
			newFilename += "FakePatches";
3216
			newFilename += L"FakePatches";
3224
		// otherwise we put them in thier usual directory structure inside the disabled dir
3217
		// otherwise we put them in thier usual directory structure inside the disabled dir
3225
		else
3218
		else
3226
			newFilename += f->getDirectory(NULL);
3219
			newFilename += f->getDirectory(NULL);
3227
 
3220
 
3228
		// make sure the directory exists so we can move the file
3221
		// make sure the directory exists so we can move the file
Line 3241... Line 3234...
3241
		// if a package with a fake patch is installed while another one is disabled, it will fill the gap left by the disabled one
3234
		// if a package with a fake patch is installed while another one is disabled, it will fill the gap left by the disabled one
3242
		// they will then end up with the same filename, if it gets disabled they would overright each other, so we change the filename to prevent that from happening
3235
		// they will then end up with the same filename, if it gets disabled they would overright each other, so we change the filename to prevent that from happening
3243
		if ( f->IsFakePatch() )
3236
		if ( f->IsFakePatch() )
3244
		{
3237
		{
3245
			// find package the fake patch belongs to
3238
			// find package the fake patch belongs to
3246
			if ( checkPackage )
3239
			if ( checkPackage )
3247
			{
3240
			{
3248
				newFilename = Utils::String(m_sCurrentDir) + &quot;/PluginManager/Disabled/FakePatches/FakePatch_&quot; + checkPackage-&gt;getNameValidFile() + "_" + checkPackage->author() + "_" + f->name();
3241
				newFilename = m_sCurrentDir + L&quot;/PluginManager/Disabled/FakePatches/FakePatch_&quot; + checkPackage-&gt;getNameValidFile() + L"_" + checkPackage->author().toWString() + L"_" + f->name();
3249
				shuffle = true;
3242
				shuffle = true;
3250
			}
3243
			}
3251
		}
3244
		}
3252
		else if ( f->isAutoTextFile() )
3245
		else if ( f->isAutoTextFile() )
3253
		{
3246
		{
3254
			if ( checkPackage )
3247
			if ( checkPackage )
3255
			{
3248
			{
3256
				newFilename = Utils::String(m_sCurrentDir) + &quot;/PluginManager/Disabled/TextFiles/Text_&quot; + checkPackage-&gt;getNameValidFile() + "_" + checkPackage->author() + "_" + f->name();
3249
				newFilename = m_sCurrentDir + L&quot;/PluginManager/Disabled/TextFiles/Text_&quot; + checkPackage-&gt;getNameValidFile() + L"_" + checkPackage->author().toWString() + L"_" + f->name();
3257
				shuffle = true;
3250
				shuffle = true;
3258
			}
3251
			}
3259
		}
3252
		}
3260
		// otherwise we can just use the standard filename
3253
		// otherwise we can just use the standard filename
3261
		else
3254
		else
3262
			newFilename = Utils::String(m_sCurrentDir) + "/PluginManager/Disabled/" + f->getNameDirectory(checkPackage);
3255
			newFilename = m_sCurrentDir + L"/PluginManager/Disabled/" + f->getNameDirectory(checkPackage);
3263
 
3256
 
3264
		// now to move the file by renameing it to its new location
3257
		// now to move the file by renameing it to its new location
3265
		// !!error checking!!
3258
		// !!error checking!!
3266
		// check the file, if it doesn't exist, and exists as disabled, we should just adjust the setting instead of an error
3259
		// check the file, if it doesn't exist, and exists as disabled, we should just adjust the setting instead of an error
3267
		CFileIO currentFile(f->filePointer());
3260
		CFileIO currentFile(f->filePointer());
Line 3291... Line 3284...
3291
			if(!removeDirs.contains(f->getDirectory(checkPackage)))
3284
			if(!removeDirs.contains(f->getDirectory(checkPackage)))
3292
				removeDirs.pushBack(f->getDirectory(checkPackage));
3285
				removeDirs.pushBack(f->getDirectory(checkPackage));
3293
		}
3286
		}
3294
 
3287
 
3295
		// change the filename
3288
		// change the filename
3296
		f->setFilename(newFilename);
3289
		f->setFilename(newFilename.toString());
3297
 
3290
 
3298
		// finally mark the file as disabled so we know not to try to move it again
3291
		// finally mark the file as disabled so we know not to try to move it again
3299
		f->SetDisabled(true);
3292
		f->SetDisabled(true);
3300
	}
3293
	}
3301
 
3294
 
3302
	// a fake patch has been disabled, we need to reshuffle the rest to fill in any gaps
3295
	// a fake patch has been disabled, we need to reshuffle the rest to fill in any gaps
3303
	if ( shuffle )
3296
	if ( shuffle )
3304
	{
3297
	{
3305
		if ( progress )
3298
		if ( progress )
Line 3308... Line 3301...
3308
		shuffleTextFiles(errors);
3301
		shuffleTextFiles(errors);
3309
	}
3302
	}
3310
 
3303
 
3311
	// original files were restored, check to remove the original file directory if its now empty
3304
	// original files were restored, check to remove the original file directory if its now empty
3312
	if ( original )
3305
	if ( original )
3313
		removeDirs.pushBack("PluginManager/Original");
3306
		removeDirs.pushBack(L"PluginManager/Original");
3314
 
3307
 
3315
	// remove any empty directories that we might have left
3308
	// remove any empty directories that we might have left
3316
	if ( !removeDirs.empty() )
3309
	if ( !removeDirs.empty() )
3317
		removeUnusedDirectories(removeDirs, errors);
3310
		removeUnusedDirectories(removeDirs, errors);
3318
 
3311
 
Line 3328... Line 3321...
3328
			disabledPackages->push_back(child);
3321
			disabledPackages->push_back(child);
3329
	}
3322
	}
3330
 
3323
 
3331
	// disabling has completed successfully, we hope
3324
	// disabling has completed successfully, we hope
3332
	m_bDisableVanilla = false;
3325
	m_bDisableVanilla = false;
3333
	m_lDisableList.clear();
3326
	m_lDisableList.clear();
3334
 
3327
 
3335
	this->WriteData();
3328
	this->WriteData();
3336
 
3329
 
3337
	return true;
3330
	return true;
3338
}
3331
}
3339
 
3332
 
Line 3355... Line 3348...
3355
 * param: errors	- A string list used to add the status as it progresses, used in debugging output
3348
 * param: errors	- A string list used to add the status as it progresses, used in debugging output
3356
 * param: progress	- The progress class, updates the progress of the current disabling.  Needs a divered class to report the progress somewhere
3349
 * param: progress	- The progress class, updates the progress of the current disabling.  Needs a divered class to report the progress somewhere
3357
 *
3350
 *
3358
 * return: boolean, true if there was no errors, otherwise false
3351
 * return: boolean, true if there was no errors, otherwise false
3359
 */
3352
 */
3360
bool CPackages::disablePackage(CBaseFile *package, Utils::CStringList *errors, CProgressInfo *progress )
3353
bool CPackages::disablePackage(CBaseFile *package, Utils::WStringList *errors, CProgressInfo *progress )
3361
{
3354
{
3362
	// if already disabled, just skip
3355
	// if already disabled, just skip
3363
	if ( !package->IsEnabled() )
3356
	if ( !package->IsEnabled() )
3364
		return true;
3357
		return true;
3365
 
3358
 
Line 3423... Line 3416...
3423
 * Find a File
3416
 * Find a File
3424
 *
3417
 *
3425
 * Searches for a file matching the filetype and filename
3418
 * Searches for a file matching the filetype and filename
3426
 * Optional dir is used for extras files
3419
 * Optional dir is used for extras files
3427
 */
3420
 */
3428
C_File *CPackages::findFile(FileType filetype, const Utils::String &filename, const Utils::String &dir) const
3421
C_File *CPackages::findFile(FileType filetype, const Utils::WString &filename, const Utils::WString &dir) const
3429
{
3422
{
3430
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
3423
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
3431
	{
3424
	{
3432
		C_File *f = node->Data();
3425
		C_File *f = node->Data();
3433
		if ( f->GetFileType() != filetype )
3426
		if ( f->GetFileType() != filetype )
Line 3457... Line 3450...
3457
			continue;
3450
			continue;
3458
 
3451
 
3459
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3452
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3460
		if ( file->name().Compare(name) )
3453
		if ( file->name().Compare(name) )
3461
			return (CArchiveFile *)file;
3454
			return (CArchiveFile *)file;
3462
	}
3455
	}
3463
 
3456
 
3464
	// nothing found
3457
	// nothing found
3465
	return 0;
3458
	return 0;
3466
}
3459
}
3467
 
3460
 
3468
/**
3461
/**
Line 3488... Line 3481...
3488
 
3481
 
3489
	// nothing found
3482
	// nothing found
3490
	return 0;
3483
	return 0;
3491
}
3484
}
3492
 
3485
 
3493
CBaseFile* CPackages::findPackage(const Utils::String &name, const Utils::String &author) const
3486
CBaseFile* CPackages::findPackage(const Utils::WString &name, const Utils::WString &author) const
3494
{
3487
{
3495
	// interate through all packages
3488
	// interate through all packages
3496
	for (CListNode<CBaseFile>* node = m_lPackages.Front(); node; node = node->next())
3489
	for (CListNode<CBaseFile>* node = m_lPackages.Front(); node; node = node->next())
3497
	{
3490
	{
3498
		CBaseFile* file = node->Data();
3491
		CBaseFile* file = node->Data();
3499
 
3492
 
3500
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3493
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3501
		if (file->name().Compare(name) &;& file->author().Compare(author))
3494
		if (file->name().toWString().Compare(name) &;& file->author().toWString().Compare(author))
3502
			return file;
3495
			return file;
3503
	}
3496
	}
3504
 
3497
 
3505
	// nothing found
3498
	// nothing found
3506
	return 0;
3499
	return 0;
Line 3565... Line 3558...
3565
}
3558
}
3566
 
3559
 
3567
/**
3560
/**
3568
 * Removes all empty directories that might have been created
3561
 * Removes all empty directories that might have been created
3569
 */
3562
 */
3570
void CPackages::removeUnusedDirectories(const Utils::CStringList& dirs, Utils::CStringList* errors)
3563
void CPackages::removeUnusedDirectories(const Utils::WStringList& dirs, Utils::WStringList* errors)
3571
{
3564
{
3572
	CDirIO Dir(m_sCurrentDir);
3565
	CDirIO Dir(m_sCurrentDir);
3573
	for(auto itr = dirs.begin(); itr != dirs.end(); itr++)
3566
	for(auto itr = dirs.begin(); itr != dirs.end(); itr++)
3574
	{
3567
	{
3575
		Utils::String dir = (*itr)->str;
3568
		Utils::WString dir = (*itr)->str;
3576
 
3569
 
3577
		Utils::CStringList removedDir;
3570
		Utils::WStringList removedDir;
3578
		if (Dir.removeDir(dir, false, true, &removedDir) || !removedDir.empty())
3571
		if (Dir.removeDir(dir, false, true, &removedDir) || !removedDir.empty())
3579
		{
3572
		{
3580
			for(auto rItr = removedDir.begin(); rItr != removedDir.end(); rItr++)
3573
			for(auto rItr = removedDir.begin(); rItr != removedDir.end(); rItr++)
3581
			{
3574
			{
3582
				Utils::String displayName = (*rItr)->str;
3575
				Utils::WString displayName = (*rItr)->str;
3583
				displayName = displayName.findRemove(m_sCurrentDir);
3576
				displayName = displayName.findRemove(m_sCurrentDir);
3584
				this->addLogEntry(SPKINSTALL_REMOVEDIR, displayName, errors);
3577
				this->addLogEntry(SPKINSTALL_REMOVEDIR, displayName, errors);
3585
			}
3578
			}
3586
		}
3579
		}
3587
	}
3580
	}
Line 3630... Line 3623...
3630
	{
3623
	{
3631
		if ( package->AnyGameCompatability() )
3624
		if ( package->AnyGameCompatability() )
3632
		{
3625
		{
3633
			if ( (check & IC_WRONGGAME) && (!package->CheckGameCompatability(m_iGame)) )
3626
			if ( (check & IC_WRONGGAME) && (!package->CheckGameCompatability(m_iGame)) )
3634
				return INSTALLCHECK_WRONGGAME;
3627
				return INSTALLCHECK_WRONGGAME;
3635
			else if ( (check & IC_WRONGVERSION) && (!package->checkGameVersionCompatability(m_iGame, m_sGameVersion, m_iGameVersion)) )
3628
			else if ( (check & IC_WRONGVERSION) && (!package->checkGameVersionCompatability(m_iGame, _sGameVersion, m_iGameVersion)) )
3636
				return INSTALLCHECK_WRONGVERSION;
3629
				return INSTALLCHECK_WRONGVERSION;
3637
		}
3630
		}
3638
	}
3631
	}
3639
 
3632
 
3640
	// check for modified
3633
	// check for modified
Line 3721... Line 3714...
3721
		// now check version
3714
		// now check version
3722
		if (version.compareVersion(p->version()) == COMPARE_OLDER)
3715
		if (version.compareVersion(p->version()) == COMPARE_OLDER)
3723
			return false;
3716
			return false;
3724
 
3717
 
3725
		if ( onlyEnabled && !p->IsEnabled() )
3718
		if ( onlyEnabled && !p->IsEnabled() )
3726
			return false;
3719
			return false;
3727
 
3720
 
3728
		return true;
3721
		return true;
3729
	}
3722
	}
3730
 
3723
 
3731
	// now check the prepared list
3724
	// now check the prepared list
3732
	if ( includePrepared )
3725
	if ( includePrepared )
3733
	{
3726
	{
3734
		for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
3727
		for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
Line 3736... Line 3729...
3736
			p = node->Data();
3729
			p = node->Data();
3737
			if ( !p )
3730
			if ( !p )
3738
				continue;
3731
				continue;
3739
 
3732
 
3740
			if ( p->name().Compare(name) && p->author().Compare(author) )
3733
			if ( p->name().Compare(name) && p->author().Compare(author) )
3741
			{
3734
			{
3742
				if (version.compareVersion(p->version()) == COMPARE_OLDER)
3735
				if (version.compareVersion(p->version()) == COMPARE_OLDER)
3743
					continue;
3736
					continue;
3744
 
3737
 
3745
				if ( onlyEnabled && !p->IsEnabled() )
3738
				if ( onlyEnabled && !p->IsEnabled() )
3746
					continue;
3739
					continue;
Line 3765... Line 3758...
3765
			{
3758
			{
3766
				bool found = false;
3759
				bool found = false;
3767
				for (auto itr = packages.Front(); itr; itr = itr->next())
3760
				for (auto itr = packages.Front(); itr; itr = itr->next())
3768
				{
3761
				{
3769
					if (itr->Data()->name().Compare(nl->sName) && itr->Data()->author().Compare(nl->sAuthor) && nl->sMinVersion.compareVersion(itr->Data()->version()) >= 0)
3762
					if (itr->Data()->name().Compare(nl->sName) && itr->Data()->author().Compare(nl->sAuthor) && nl->sMinVersion.compareVersion(itr->Data()->version()) >= 0)
3770
					{
3763
					{
3771
						if (!findAllNeededDependacies(itr->Data(), packages, foundPackages, onlyEnabled, includePrepared))
3764
						if (!findAllNeededDependacies(itr->Data(), packages, foundPackages, onlyEnabled, includePrepared))
3772
							return false;
3765
							return false;
3773
						if (foundPackages)
3766
						if (foundPackages)
3774
						{
3767
						{
3775
							bool added = false;
3768
							bool added = false;
3776
							for (auto itr2 = foundPackages->Front(); itr2; itr2 = itr2->next())
3769
							for (auto itr2 = foundPackages->Front(); itr2; itr2 = itr2->next())
3777
							{
3770
							{
Line 3780... Line 3773...
3780
									added = true;
3773
									added = true;
3781
									break;
3774
									break;
3782
								}
3775
								}
3783
							}
3776
							}
3784
							if(!added)
3777
							if(!added)
3785
								foundPackages->push_front(itr->Data());
3778
								foundPackages->push_front(itr->Data());
3786
						}
3779
						}
3787
						found = true;
3780
						found = true;
3788
						break;
3781
						break;
3789
					}
3782
					}
3790
				}
3783
				}
3791
				if (!found)
3784
				if (!found)
3792
					return false;
3785
					return false;
3793
			}
3786
			}
Line 3799... Line 3792...
3799
		CSpkFile *spk = (CSpkFile *)p;
3792
		CSpkFile *spk = (CSpkFile *)p;
3800
		if (spk->isAnotherMod())
3793
		if (spk->isAnotherMod())
3801
		{
3794
		{
3802
			bool found = true;
3795
			bool found = true;
3803
			if (!this->findSpkPackage(spk->otherName(), spk->otherAuthor()))
3796
			if (!this->findSpkPackage(spk->otherName(), spk->otherAuthor()))
3804
			{
3797
			{
3805
				if (includePrepared)
3798
				if (includePrepared)
3806
				{
3799
				{
3807
					found = false;
3800
					found = false;
3808
					for (CListNode<CBaseFile> *pNode = m_lInstallList.Front(); pNode; pNode = pNode->next())
3801
					for (CListNode<CBaseFile> *pNode = m_lInstallList.Front(); pNode; pNode = pNode->next())
3809
					{
3802
					{
Line 3814... Line 3807...
3814
							break;
3807
							break;
3815
						}
3808
						}
3816
					}
3809
					}
3817
				}
3810
				}
3818
				else
3811
				else
3819
					found = false;
3812
					found = false;
3820
			}
3813
			}
3821
 
3814
 
3822
			if (!found)
3815
			if (!found)
3823
			{
3816
			{
3824
				for (auto itr = packages.Front(); itr; itr = itr->next())
3817
				for (auto itr = packages.Front(); itr; itr = itr->next())
Line 3846... Line 3839...
3846
					}
3839
					}
3847
				}
3840
				}
3848
 
3841
 
3849
				if(!found)
3842
				if(!found)
3850
					return false;
3843
					return false;
3851
			}
3844
			}
3852
		}
3845
		}
3853
	}
3846
	}
3854
 
3847
 
3855
	return true;
3848
	return true;
3856
 
3849
 
3857
}
3850
}
3858
 
3851
 
3859
size_t CPackages::getDownloadableDependacies(CBaseFile* p, std::vector<const SAvailablePackage*>& list, bool onlyEnabled, bool includePrepared) const
3852
size_t CPackages::getDownloadableDependacies(CBaseFile* p, std::vector<const SAvailablePackage*>& list, bool onlyEnabled, bool includePrepared) const
3860
{
3853
{
3861
	size_t count = 0;
3854
	size_t count = 0;
3862
	CLinkList<SNeededLibrary>* neededList = p->GetNeededLibraries();
3855
	CLinkList<SNeededLibrary>* neededList = p->GetNeededLibraries();
Line 3866... Line 3859...
3866
		{
3859
		{
3867
			SNeededLibrary* nl = node->Data();
3860
			SNeededLibrary* nl = node->Data();
3868
			if (!checkInstalledDependacy((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare("<package>")) ? false : onlyEnabled, (nl->sName.Compare("<package>")) ? false : includePrepared))
3861
			if (!checkInstalledDependacy((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare("<package>")) ? false : onlyEnabled, (nl->sName.Compare("<package>")) ? false : includePrepared))
3869
			{
3862
			{
3870
				const SAvailablePackage *available = findAvailablePackage((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor);
3863
				const SAvailablePackage *available = findAvailablePackage((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor);
3871
				if (available)
3864
				if (available)
3872
					list.push_back(available);
3865
					list.push_back(available);
3873
				++count;
3866
				++count;
3874
			}
3867
			}
3875
		}
3868
		}
3876
	}
3869
	}
3877
 
3870
 
3878
	if (p->GetType() == TYPE_SPK)
3871
	if (p->GetType() == TYPE_SPK)
Line 3916... Line 3909...
3916
int CPackages::GetMissingDependacies(CBaseFile *p, Utils::CStringList *list, bool onlyEnabled, bool includePrepared)
3909
int CPackages::GetMissingDependacies(CBaseFile *p, Utils::CStringList *list, bool onlyEnabled, bool includePrepared)
3917
{
3910
{
3918
	int count = 0;
3911
	int count = 0;
3919
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3912
	CLinkList<SNeededLibrary> *neededList = p->GetNeededLibraries();
3920
	if ( neededList )
3913
	if ( neededList )
3921
	{
3914
	{
3922
		for ( CListNode<SNeededLibrary> *node = neededList->Front(); node; node = node->next() )
3915
		for ( CListNode<SNeededLibrary> *node = neededList->Front(); node; node = node->next() )
3923
		{
3916
		{
3924
			SNeededLibrary *nl = node->Data();
3917
			SNeededLibrary *nl = node->Data();
3925
			if ( !checkInstalledDependacy((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare("<package>")) ? false : onlyEnabled, (nl->sName.Compare("<package>")) ? false : includePrepared) )
3918
			if ( !checkInstalledDependacy((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare("<package>")) ? false : onlyEnabled, (nl->sName.Compare("<package>")) ? false : includePrepared) )
3926
			{
3919
			{
Line 3980... Line 3973...
3980
		bool missingDep = false;
3973
		bool missingDep = false;
3981
		if ( !this->CheckOtherPackage(p) )
3974
		if ( !this->CheckOtherPackage(p) )
3982
			missingDep = true;
3975
			missingDep = true;
3983
		else if ( this->GetMissingDependacies(p, NULL, false, true) )
3976
		else if ( this->GetMissingDependacies(p, NULL, false, true) )
3984
			missingDep = true;
3977
			missingDep = true;
3985
 
3978
 
3986
		if ( missingDep )
3979
		if ( missingDep )
3987
		{
3980
		{
3988
			if ( list )
3981
			if ( list )
3989
			{
3982
			{
3990
				node->ChangeData(NULL);
3983
				node->ChangeData(NULL);
Line 4005... Line 3998...
4005
/**
3998
/**
4006
 * Remove uninstall file
3999
 * Remove uninstall file
4007
 *
4000
 *
4008
 * Removes a single uninstall file
4001
 * Removes a single uninstall file
4009
 */
4002
 */
4010
bool CPackages::removeUninstallFile(C_File *file, Utils::CStringList *errors)
4003
bool CPackages::removeUninstallFile(C_File *file, Utils::WStringList *errors)
4011
{
4004
{
4012
	CFileIO fio(file->filePointer());
4005
	CFileIO fio(file->filePointer());
4013
	if ( fio.exists() )
4006
	if ( fio.exists() )
4014
	{
4007
	{
4015
		if ( fio.remove() ) {
4008
		if ( fio.remove() ) {
Line 4027... Line 4020...
4027
 * Remove uninstall scripts
4020
 * Remove uninstall scripts
4028
 *
4021
 *
4029
 * Removes any unused unisntall scripts
4022
 * Removes any unused unisntall scripts
4030
 * Finds if any scripts are in the current package
4023
 * Finds if any scripts are in the current package
4031
 */
4024
 */
4032
int CPackages::removeUninstallScripts(Utils::CStringList *errors, CProgressInfo *progress)
4025
int CPackages::removeUninstallScripts(Utils::WStringList *errors, CProgressInfo *progress)
4033
{
4026
{
4034
	if ( m_lUninstallFiles.empty() )
4027
	if ( m_lUninstallFiles.empty() )
4035
		return 0;
4028
		return 0;
4036
 
4029
 
4037
	UpdateUsedFiles();
4030
	UpdateUsedFiles();
Line 4077... Line 4070...
4077
/**
4070
/**
4078
 * Remove unused shared file
4071
 * Remove unused shared file
4079
 *
4072
 *
4080
 * Removes a single file
4073
 * Removes a single file
4081
 */
4074
 */
4082
bool CPackages::removeSharedFile(C_File *file, Utils::CStringList *errors)
4075
bool CPackages::removeSharedFile(C_File *file, Utils::WStringList *errors)
4083
{
4076
{
4084
	CFileIO fio(file->filePointer());
4077
	CFileIO fio(file->filePointer());
4085
	if ( fio.exists() )
4078
	if ( fio.exists() )
4086
	{
4079
	{
4087
		if ( fio.remove() ) {
4080
		if ( fio.remove() ) {
Line 4102... Line 4095...
4102
 * Files that have been marked as shared will not be removed or disabled when the last package is removed
4095
 * Files that have been marked as shared will not be removed or disabled when the last package is removed
4103
 * This function will remove any that are no longer connected with packages
4096
 * This function will remove any that are no longer connected with packages
4104
 *
4097
 *
4105
 * Marked shared fiels are mainly used for library scripts that arn't always added to packages
4098
 * Marked shared fiels are mainly used for library scripts that arn't always added to packages
4106
 */
4099
 */
4107
int CPackages::removeUnusedSharedFiles(Utils::CStringList *errors, CProgressInfo *progress)
4100
int CPackages::removeUnusedSharedFiles(Utils::WStringList *errors, CProgressInfo *progress)
4108
{
4101
{
4109
	UpdateUsedFiles();
4102
	UpdateUsedFiles();
4110
	int files = 0;
4103
	int files = 0;
4111
	int done = 0;
4104
	int done = 0;
4112
 
4105
 
Line 4164... Line 4157...
4164
 
4157
 
4165
	return false;
4158
	return false;
4166
 
4159
 
4167
}
4160
}
4168
 
4161
 
4169
void CPackages::shuffleTextFiles(Utils::CStringList *errors)
4162
void CPackages::shuffleTextFiles(Utils::WStringList *errors)
4170
{
4163
{
4171
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4164
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4172
	{
4165
	{
4173
		C_File *f = node->Data();
4166
		C_File *f = node->Data();
4174
		// only do files that are enabled
4167
		// only do files that are enabled
Line 4186... Line 4179...
4186
		int current = findNextTextFile();
4179
		int current = findNextTextFile();
4187
		if ( current < f->textFileID() )
4180
		if ( current < f->textFileID() )
4188
		{
4181
		{
4189
			CFileIO moveFile(f->filePointer());
4182
			CFileIO moveFile(f->filePointer());
4190
	
4183
	
4191
			Utils::String newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + "." + moveFile.extension().toString();
4184
			Utils::WString newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + L"." + moveFile.extension();
4192
			if ( moveFile.Rename(m_sCurrentDir + "/t/" + newName) )
4185
			if ( moveFile.Rename(m_sCurrentDir + L"/t/" + newName) )
4193
			{
4186
			{
4194
				this->addLogEntry(SPKINSTALL_AUTOTEXT, f->name() + "~" + newName, errors);
4187
				this->addLogEntry(SPKINSTALL_AUTOTEXT, f->name() + L"~" + newName, errors);
4195
				f->setName(newName);
4188
				f->setName(newName.toString());
4196
			}
4189
			}
4197
			else
4190
			else
4198
				this->addLogEntry(SPKINSTALL_AUTOTEXT_FAIL, f->name() + "~" + newName, errors);
4191
				this->addLogEntry(SPKINSTALL_AUTOTEXT_FAIL, f->name() + L"~" + newName, errors);
4199
		}
4192
		}
4200
	}
4193
	}
4201
}
4194
}
4202
 
4195
 
4203
/**
4196
/**
Line 4205... Line 4198...
4205
 *
4198
 *
4206
 * Rename the fake patches so they are always in sequence to be loaded into the game
4199
 * Rename the fake patches so they are always in sequence to be loaded into the game
4207
 *
4200
 *
4208
 * IE, when one is removed, the rest need to be shuffled down so theres no gaps
4201
 * IE, when one is removed, the rest need to be shuffled down so theres no gaps
4209
 */
4202
 */
4210
void CPackages::shuffleFakePatches(Utils::CStringList *errors)
4203
void CPackages::shuffleFakePatches(Utils::WStringList *errors)
4211
{
4204
{
4212
	int check = findNextFakePatch();
4205
	int check = findNextFakePatch();
4213
 
4206
 
4214
	// lets make sure our order is correct
4207
	// lets make sure our order is correct
4215
	// find Lowest Fake Patch Installed
4208
	// find Lowest Fake Patch Installed
Line 4243... Line 4236...
4243
		if (spk)
4236
		if (spk)
4244
		{
4237
		{
4245
			if (spk->IsAnotherMod())
4238
			if (spk->IsAnotherMod())
4246
			{
4239
			{
4247
				auto package = findPackage(spk->otherName(), spk->otherAuthor());
4240
				auto package = findPackage(spk->otherName(), spk->otherAuthor());
4248
				if (package)
4241
				if (package)
4249
				{
4242
				{
4250
					packagesBefore.insert(package);
4243
					packagesBefore.insert(package);
4251
					packagesAfter[p].insert(package);
4244
					packagesAfter[p].insert(package);
4252
				}
4245
				}
4253
			}
4246
			}
4254
		}
4247
		}
4255
 
4248
 
4256
		if (!p->getFakePatchBeforeOrder().empty())
4249
		if (!p->getFakePatchBeforeOrder().empty())
Line 4277... Line 4270...
4277
				}
4270
				}
4278
			}
4271
			}
4279
		}
4272
		}
4280
	}
4273
	}
4281
 
4274
 
4282
	auto addOrderedList = [](const std::vector<CBaseFile*>& addList, const Utils::CStringList& orderList, std::vector<CBaseFile*>& addTo, const CPackages *packages)
4275
	auto addOrderedList = [](const std::vector<CBaseFile*>& addList, const Utils::WStringList& orderList, std::vector<CBaseFile*>& addTo, const CPackages *packages)
4283
	{
4276
	{
4284
		// add all the items in the ordered list first
4277
		// add all the items in the ordered list first
4285
		for (auto itr = orderList.begin(); itr != orderList.end(); itr++)
4278
		for (auto itr = orderList.begin(); itr != orderList.end(); itr++)
4286
		{
4279
		{
4287
			auto p = packages->findPackage((*itr)->str, (*itr)->data);
4280
			auto p = packages->findPackage((*itr)->str, (*itr)->data);
Line 4353... Line 4346...
4353
		{
4346
		{
4354
			for (auto itr = packagesBefore.begin(); itr != packagesBefore.end(); itr++)
4347
			for (auto itr = packagesBefore.begin(); itr != packagesBefore.end(); itr++)
4355
				packagesOrder.push_back(*itr);
4348
				packagesOrder.push_back(*itr);
4356
		}
4349
		}
4357
 
4350
 
4358
		addOrderedList(packagesOrder, m_lFakePatchOrder, order, this);
4351
		addOrderedList(packagesOrder, _lFakePatchOrder, order, this);
4359
		removeList(packagesOrder, packagesBefore);
4352
		removeList(packagesOrder, packagesBefore);
4360
	}
4353
	}
4361
 
4354
 
4362
	// now add the remaining list ordered list
4355
	// now add the remaining list ordered list
4363
	for (auto itr = m_lFakePatchOrder.begin(); itr != m_lFakePatchOrder.end(); itr++)
4356
	for (auto itr = _lFakePatchOrder.begin(); itr != _lFakePatchOrder.end(); itr++)
4364
	{
4357
	{
4365
		auto p = findPackage((*itr)->str, (*itr)->data);
4358
		auto p = findPackage((*itr)->str, (*itr)->data);
4366
		if (p)
4359
		if (p)
4367
		{
4360
		{
4368
			auto findItr = std::find(order.begin(), order.end(), p);
4361
			auto findItr = std::find(order.begin(), order.end(), p);
Line 4381... Line 4374...
4381
			{
4374
			{
4382
				C_File *lowestFile = NULL;
4375
				C_File *lowestFile = NULL;
4383
				for ( C_File *file = package->GetFirstFile(FILETYPE_MOD); file; file = package->GetNextFile(file) )
4376
				for ( C_File *file = package->GetFirstFile(FILETYPE_MOD); file; file = package->GetNextFile(file) )
4384
				{
4377
				{
4385
					if (!file->IsFakePatch()) continue;
4378
					if (!file->IsFakePatch()) continue;
4386
					if (!file->checkFileExt("cat")) continue; // only do the cat file, we can shuffle the dat file to match later
4379
					if (!file->checkFileExt(L"cat")) continue; // only do the cat file, we can shuffle the dat file to match later
4387
					if (doneList.FindData(file)) continue; // already done?
4380
					if (doneList.FindData(file)) continue; // already done?
4388
 
4381
 
4389
					if ( !lowestFile )
4382
					if ( !lowestFile )
4390
						lowestFile = file;
4383
						lowestFile = file;
4391
					else
4384
					else
Line 4400... Line 4393...
4400
 
4393
 
4401
				// check its filename, it might already be in the correct place
4394
				// check its filename, it might already be in the correct place
4402
				if ( lowestFile->baseName().toInt() != lowest )
4395
				if ( lowestFile->baseName().toInt() != lowest )
4403
				{
4396
				{
4404
					// if the file already exists, we need to move it elsewhere
4397
					// if the file already exists, we need to move it elsewhere
4405
					Utils::String nextName = Utils::String::PadNumber(lowest, 2);
4398
					Utils::WString nextName = Utils::WString::PadNumber(lowest, 2);
4406
					if ( CFileIO::Exists(m_sCurrentDir + "/" + nextName + ".cat") )
4399
					if ( CFileIO::Exists(m_sCurrentDir + L"/" + nextName + L".cat") )
4407
					{
4400
					{
4408
						// find the file in our internal file list
4401
						// find the file in our internal file list
4409
						C_File *moveFile = findFile(FILETYPE_MOD, nextName + ".cat");
4402
						C_File *moveFile = findFile(FILETYPE_MOD, nextName + L".cat");
4410
						if ( !moveFile ) // must not have it in our list ? lets move to the next
4403
						if ( !moveFile ) // must not have it in our list ? lets move to the next
4411
						{
4404
						{
4412
							lowest++;
4405
							lowest++;
4413
							continue;
4406
							continue;
4414
						}
4407
						}
Line 4448... Line 4441...
4448
		if (!f->checkFileExt("cat"))
4441
		if (!f->checkFileExt("cat"))
4449
			continue;
4442
			continue;
4450
 
4443
 
4451
		// now lets check if its greater than our gap
4444
		// now lets check if its greater than our gap
4452
		int check = findNextFakePatch();
4445
		int check = findNextFakePatch();
4453
		int patchNum = f->filename().token(".", 1).toInt();
4446
		int patchNum = f->filename().token(L".", 1).toInt();
4454
		if ( patchNum <= check )
4447
		if ( patchNum <= check )
4455
			continue;
4448
			continue;
4456
 
4449
 
4457
		shufflePatchTo(f, check, errors);
4450
		shufflePatchTo(f, check, errors);
4458
	}
4451
	}
4459
}
4452
}
4460
 
4453
 
4461
void CPackages::shufflePatchTo(C_File *file, int to, Utils::CStringList *errors)
4454
void CPackages::shufflePatchTo(C_File *file, int to, Utils::WStringList *errors)
4462
{
4455
{
4463
	// it is, we need to shift this to fill the gap
4456
	// it is, we need to shift this to fill the gap
4464
	Utils::String newName = Utils::String::PadNumber(to, 2) + "." + file->fileExt();
4457
	Utils::WString newName = Utils::WString::PadNumber(to, 2) + L"." + file->fileExt();
4465
 
4458
 
4466
	// now rename the file
4459
	// now rename the file
4467
	CFileIO moveFile(file->filePointer());
4460
	CFileIO moveFile(file->filePointer());
4468
	if ( moveFile.Rename(m_sCurrentDir + "/" + newName) )
4461
	if ( moveFile.Rename(m_sCurrentDir + L"/" + newName) )
4469
	{
4462
	{
4470
		// display moveing
4463
		// display moveing
4471
		this->addLogEntry(SPKINSTALL_FAKEPATCH, file->name() + "~" + newName, errors);
4464
		this->addLogEntry(SPKINSTALL_FAKEPATCH, file->name() + L"~" + newName, errors);
4472
 
4465
 
4473
		// now find the matching pairing if it exists
4466
		// now find the matching pairing if it exists
4474
		for ( CListNode<C_File> *node2 = m_lFiles.Front(); node2; node2 = node2->next() )
4467
		for ( CListNode<C_File> *node2 = m_lFiles.Front(); node2; node2 = node2->next() )
4475
		{
4468
		{
4476
			C_File *f2 = node2->Data();
4469
			C_File *f2 = node2->Data();
Line 4480... Line 4473...
4480
 
4473
 
4481
			// needs to be the same file
4474
			// needs to be the same file
4482
			if ( f2->baseName() != file->baseName() )
4475
			if ( f2->baseName() != file->baseName() )
4483
				continue;
4476
				continue;
4484
 
4477
 
4485
			Utils::String newName2 = Utils::String::PadNumber(to, 2) + "." + f2->fileExt();
4478
			Utils::WString newName2 = Utils::WString::PadNumber(to, 2) + L"." + f2->fileExt();
4486
			CFileIO moveFile(f2->filePointer());
4479
			CFileIO moveFile(f2->filePointer());
4487
			if ( moveFile.Rename(m_sCurrentDir + "/" + newName2) )
4480
			if ( moveFile.Rename(m_sCurrentDir + L"/" + newName2) )
4488
			{
4481
			{
4489
				this->addLogEntry(SPKINSTALL_FAKEPATCH, f2->name() + "~" + newName2, errors);
4482
				this->addLogEntry(SPKINSTALL_FAKEPATCH, f2->name() + L"~" + newName2, errors);
4490
				f2->setName(newName2);
4483
				f2->setName(newName2.toString());
4491
			}
4484
			}
4492
			else
4485
			else
4493
				this->addLogEntry(SPKINSTALL_FAKEPATCH_FAIL, f2->name() + "~" + newName2, errors);
4486
				this->addLogEntry(SPKINSTALL_FAKEPATCH_FAIL, f2->name() + L"~" + newName2, errors);
4494
		}
4487
		}
4495
 
4488
 
4496
		// finally make sure the internal name matches the new one
4489
		// finally make sure the internal name matches the new one
4497
		file->setName(newName);
4490
		file->setName(newName.toString());
4498
	}
4491
	}
4499
	else
4492
	else
4500
		this->addLogEntry(SPKINSTALL_FAKEPATCH_FAIL, file->name() + "~" + newName, errors);
4493
		this->addLogEntry(SPKINSTALL_FAKEPATCH_FAIL, file->name() + L"~" + newName, errors);
4501
}
4494
}
4502
 
4495
 
4503
int CPackages::FindLowestFakePatchInstalled()
4496
int CPackages::FindLowestFakePatchInstalled()
4504
{
4497
{
4505
	int lowest = 99;
4498
	int lowest = 99;
Line 4511... Line 4504...
4511
 
4504
 
4512
		// now get all fake patches
4505
		// now get all fake patches
4513
		for ( C_File *file = p->GetFirstFile(FILETYPE_MOD); file; file = p->GetNextFile(file) )
4506
		for ( C_File *file = p->GetFirstFile(FILETYPE_MOD); file; file = p->GetNextFile(file) )
4514
		{
4507
		{
4515
			if (!file->IsFakePatch()) continue;
4508
			if (!file->IsFakePatch()) continue;
4516
			if (file->checkFileExt("dat")) continue;
4509
			if (file->checkFileExt(L"dat")) continue;
4517
			int check = file->baseName().toInt();
4510
			int check = file->baseName().toInt();
4518
			if ( check < lowest )
4511
			if ( check < lowest )
4519
				lowest = check;
4512
				lowest = check;
4520
		}
4513
		}
4521
	}
4514
	}
4522
 
4515
 
4523
	return lowest;
4516
	return lowest;
4524
}
4517
}
4525
 
4518
 
4526
int CPackages::findLastFakePatch(int start, const Utils::String &dir) const
4519
int CPackages::findLastFakePatch(int start, const Utils::WString &dir) const
4527
{
4520
{
4528
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4521
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4529
 
4522
 
4530
	int check = start;
4523
	int check = start;
4531
	while ( check > 0 )
4524
	while ( check > 0 )
4532
	{
4525
	{
4533
		Utils::String checkStr = Utils::String::PadNumber(check, 2);
4526
		Utils::WString checkStr = Utils::String::PadNumber(check, 2);
4534
 
4527
 
4535
		// check if a cat file exists
4528
		// check if a cat file exists
4536
		if ( !Dir.exists(checkStr + ".cat") )
4529
		if ( !Dir.exists(checkStr + L".cat") )
4537
		{
4530
		{
4538
			// it doen't, check if theres a dat file (incase of package error)
4531
			// it doen't, check if theres a dat file (incase of package error)
4539
			if ( !Dir.exists(checkStr + ".dat") )
4532
			if ( !Dir.exists(checkStr + L".dat") )
4540
				break;
4533
				break;
4541
		}
4534
		}
4542
		--check;
4535
		--check;
4543
	}
4536
	}
4544
 
4537
 
4545
	return check;
4538
	return check;
4546
}
4539
}
4547
 
4540
 
4548
/**
4541
/**
4549
 * Find next fake patch
4542
 * Find next fake patch
4550
 *
4543
 *
4551
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4544
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4552
 */
4545
 */
4553
int CPackages::findNextFakePatch(int start, const Utils::String &dir) const
4546
int CPackages::findNextFakePatch(int start, const Utils::WString &dir) const
4554
{
4547
{
4555
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4548
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4556
 
4549
 
4557
	int check = start;
4550
	int check = start;
4558
	while ( check < 99 )
4551
	while ( check < 99 )
4559
	{
4552
	{
4560
		++check;
4553
		++check;
4561
		Utils::String checkStr = Utils::String::PadNumber(check, 2);
4554
		Utils::WString checkStr = Utils::WString::PadNumber(check, 2);
4562
 
4555
 
4563
		// check if a cat file exists
4556
		// check if a cat file exists
4564
		if ( !Dir.exists(checkStr + ".cat") )
4557
		if ( !Dir.exists(checkStr + L".cat") )
4565
		{
4558
		{
4566
			// it doen't, check if theres a dat file (incase of package error)
4559
			// it doen't, check if theres a dat file (incase of package error)
4567
			if ( !Dir.exists(checkStr + ".dat") )
4560
			if ( !Dir.exists(checkStr + L".dat") )
4568
				break;
4561
				break;
4569
		}
4562
		}
4570
	}
4563
	}
4571
 
4564
 
4572
	return check;
4565
	return check;
Line 4578... Line 4571...
4578
 * Searching for the next gap in automatic text files, start with 0004-LXXX or XX0004
4571
 * Searching for the next gap in automatic text files, start with 0004-LXXX or XX0004
4579
 */
4572
 */
4580
unsigned int CPackages::findNextTextFile(unsigned int start) const
4573
unsigned int CPackages::findNextTextFile(unsigned int start) const
4581
{
4574
{
4582
	return findNextTextFile(Utils::String::Null(), start);
4575
	return findNextTextFile(Utils::String::Null(), start);
4583
}
4576
}
4584
unsigned int CPackages::findNextTextFile(const Utils::String &dir, unsigned int start) const
4577
unsigned int CPackages::findNextTextFile(const Utils::WString &dir, unsigned int start) const
4585
{
4578
{
4586
	int check = start;
4579
	int check = start;
4587
	if ( check < 2 ) check = 2;
4580
	if ( check < 2 ) check = 2;
4588
	while ( check < 9999 )
4581
	while ( check < 9999 )
4589
	{
4582
	{
4590
		++check;
4583
		++check;
4591
		Utils::String newFilename = SPK::FormatTextName(check, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4584
		Utils::WString newFilename = SPK::FormatTextName(check, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4592
 
4585
 
4593
		// check the vfs
4586
		// check the vfs
4594
		if ( m_pGameVFS.isFileAvailable("t/" + newFilename + ".pck") ) continue;
4587
		if ( m_pGameVFS.isFileAvailable(L"t/" + newFilename + L".pck") ) continue;
4595
		if ( m_pGameVFS.isFileAvailable("t/" + newFilename + ".xml") ) continue;
4588
		if ( m_pGameVFS.isFileAvailable(L"t/" + newFilename + L".xml") ) continue;
4596
 
4589
 
4597
		break;
4590
		break;
4598
	}
4591
	}
4599
 
4592
 
4600
	return check;
4593
	return check;
4601
}
4594
}
4602
 
4595
 
4603
int CPackages::findLastTextFile(int start, const Utils::String& dir) const
4596
int CPackages::findLastTextFile(int start, const Utils::WString& dir) const
4604
{
4597
{
4605
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4598
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4606
	Dir.cd("t");
4599
	Dir.cd(L"t");
4607
 
4600
 
4608
	int check = start;
4601
	int check = start;
4609
	while ( check < 9999 )
4602
	while ( check < 9999 )
4610
	{
4603
	{
4611
		++check;
4604
		++check;
4612
		Utils::String newFilename = SPK::FormatTextName(check, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4605
		Utils::WString newFilename = SPK::FormatTextName(check, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4613
 
4606
 
4614
		// check if a packed file exists
4607
		// check if a packed file exists
4615
		if ( !Dir.exists(newFilename + ".pck") )
4608
		if ( !Dir.exists(newFilename + L".pck") )
4616
		{
4609
		{
4617
			// it doen't, check if theres an unpacked file
4610
			// it doen't, check if theres an unpacked file
4618
			if ( !Dir.exists(newFilename + ".xml") )
4611
			if ( !Dir.exists(newFilename + L".xml") )
4619
				break;
4612
				break;
4620
		}
4613
		}
4621
	}
4614
	}
4622
 
4615
 
4623
	return check;
4616
	return check;
4624
}
4617
}
4625
 
4618
 
4626
/**
4619
/**
4627
 * Read game language
4620
 * Read game language
4628
 *
4621
 *
4629
 * Reads the lang.dat file from the game directory for the language id
4622
 * Reads the lang.dat file from the game directory for the language id
Line 4655... Line 4648...
4655
/**
4648
/**
4656
 * Create Language Text File
4649
 * Create Language Text File
4657
 *
4650
 *
4658
 * Creates text files for all packages into the correct language
4651
 * Creates text files for all packages into the correct language
4659
 */
4652
 */
4660
void CPackages::CreateLanguageTextFiles(Utils::CStringList *errors)
4653
void CPackages::CreateLanguageTextFiles(Utils::WStringList *errors)
4661
{
4654
{
4662
	// no need to create them if theres no language to use
4655
	// no need to create them if theres no language to use
4663
	if ( !m_iLanguage )
4656
	if ( !m_iLanguage )
4664
		return;
4657
		return;
4665
 
4658
 
4666
	// find all text files
4659
	// find all text files
4667
	Utils::CStringList ids;
4660
	Utils::WStringList ids;
4668
 
4661
 
4669
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4662
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4670
	{
4663
	{
4671
		C_File *f = node->Data();
4664
		C_File *f = node->Data();
4672
		// only do text fiels
4665
		// only do text fiels
4673
		if ( f->GetFileType() != FILETYPE_TEXT )
4666
		if ( f->GetFileType() != FILETYPE_TEXT )
4674
			continue;
4667
			continue;
4675
 
4668
 
4676
		Utils::String id, lang;
4669
		Utils::WString id, lang;
4677
		if ( m_iGameFlags & EXEFLAG_TCTEXT )
4670
		if ( m_iGameFlags & EXEFLAG_TCTEXT )
4678
		{
4671
		{
4679
			id = f->baseName().token("-", 1);
4672
			id = f->baseName().token(L"-", 1);
4680
			lang = f->baseName().token("-", 2);
4673
			lang = f->baseName().token(L"-", 2);
4681
			if ( lang.empty() )
4674
			if ( lang.empty() )
4682
				lang = "NULL";
4675
				lang = L"NULL";
4683
			else
4676
			else
4684
				lang = lang.erase(0, 1);  // remove the "L"
4677
				lang = lang.erase(0, 1);  // remove the "L"
4685
		}
4678
		}
4686
		else
4679
		else
4687
		{
4680
		{
4688
			lang = Utils::String::PadNumber(f->baseName().left((int)f->baseName().length() - 4), 3);
4681
			lang = Utils::WString::PadNumber(f->baseName().left((int)f->baseName().length() - 4), 3);
4689
			id = f->baseName().mid(((int)f->baseName().length() - 4) + 1, 4);
4682
			id = f->baseName().mid(((int)f->baseName().length() - 4) + 1, 4);
4690
		}
4683
		}
4691
 
4684
 
4692
 
4685
 
4693
		// not added, add a new one
4686
		// not added, add a new one
4694
		if (!ids.contains(id))
4687
		if (!ids.contains(id))
4695
			ids.pushBack(id, lang);
4688
			ids.pushBack(id, lang);
4696
		else
4689
		else
4697
		{
4690
		{
4698
			Utils::String data = ids.findString(id);
4691
			Utils::WString data = ids.findString(id);
4699
			if (data.empty())
4692
			if (data.empty())
4700
				data = lang;
4693
				data = lang;
4701
			else
4694
			else
4702
			{
4695
			{
4703
				data += ":";
4696
				data += L":";
4704
				data += lang;
4697
				data += lang;
4705
			}
4698
			}
4706
			ids.changeData(id, data);
4699
			ids.changeData(id, data);
4707
		}
4700
		}
4708
	}
4701
	}
4709
 
4702
 
4710
	// we should now have a list of all text files, we need to remove those that have a matching language
4703
	// we should now have a list of all text files, we need to remove those that have a matching language
4711
	for(auto itr = ids.begin(); itr != ids.end(); itr++)
4704
	for(auto itr = ids.begin(); itr != ids.end(); itr++)
4712
	{
4705
	{
4713
		int size = 0;
4706
		int size = 0;
-
 
4707
		std::vector<Utils::WString> data;
4714
		Utils::String *data = (*itr)-&gt;data.tokenise(":", &size);
4708
		if(!(*itr)-&gt;data.tokenise(L":", data))			
4715
 
-
 
4716
		// huh ? we shouldn't have this
4709
			continue; // huh ? we shouldn't have this
4717
		if ( !size )
-
 
4718
			continue;
-
 
4719
 
4710
 
4720
		// lets search for a matching id
4711
		// lets search for a matching id
4721
		int useId = 0;
4712
		int useId = 0;
4722
		bool found = false;
4713
		bool found = false;
4723
		for ( int i = 0; i < size; i++ )
4714
		for ( int i = 0; i < size; i++ )
4724
		{
4715
		{
4725
			if ( data[i] == "NULL" )
4716
			if ( data[i] == L"NULL" )
4726
				useId = -1;
4717
				useId = -1;
4727
			else
4718
			else
4728
			{
4719
			{
4729
				int num = data[i].toInt();
4720
				int num = data[i].toInt();
4730
				if ( num == m_iLanguage )
4721
				if ( num == m_iLanguage )
Line 4744... Line 4735...
4744
					useId = num;
4735
					useId = num;
4745
			}
4736
			}
4746
		}
4737
		}
4747
 
4738
 
4748
		if (found)
4739
		if (found)
4749
		{
-
 
4750
			CLEANSPLIT(data, size);
-
 
4751
			continue;
4740
			continue;
4752
		}
-
 
4753
 
4741
 
4754
		if ( !useId )
4742
		if ( !useId )
4755
			useId = data[0].toInt();
4743
			useId = data[0].toInt();
4756
		if ( !useId )
4744
		if ( !useId )
4757
			useId = -1;
4745
			useId = -1;
4758
 
4746
 
4759
		CLEANSPLIT(data, size);
-
 
4760
		RenameTextFile((*itr)->str, useId, errors);
4747
		renameTextFile((*itr)->str, useId, errors);
4761
	}
4748
	}
4762
}
4749
}
4763
 
4750
 
4764
/**
4751
/**
4765
 * Rename a text file
4752
 * Rename a text file
4766
 *
4753
 *
4767
 * Creates a new text file for the selected langage by copying an existing one
4754
 * Creates a new text file for the selected langage by copying an existing one
4768
 */
4755
 */
4769
bool CPackages::RenameTextFile(const Utils::String &textid, int languageid, Utils::CStringList *errors)
4756
bool CPackages::renameTextFile(const Utils::WString &textid, int languageid, Utils::WStringList *errors)
4770
{
4757
{
4771
	// lets check if the file already exists
4758
	// lets check if the file already exists
4772
	Utils::String newFilename = SPK::FormatTextName(textid.toInt(), m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4759
	Utils::WString newFilename = SPK::FormatTextName(textid.toInt(), m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4773
	C_File *addFile = findFile(FILETYPE_TEXT, newFilename + ".xml");
4760
	C_File *addFile = findFile(FILETYPE_TEXT, newFilename + L".xml");
4774
	if ( !addFile )
4761
	if ( !addFile )
4775
		addFile = findFile(FILETYPE_TEXT, newFilename + ".pck");
4762
		addFile = findFile(FILETYPE_TEXT, newFilename + L".pck");
4776
 
4763
 
4777
	// we have found the file, lets just add it to our scripts
4764
	// we have found the file, lets just add it to our scripts
4778
	if ( addFile )
4765
	if ( addFile )
4779
	{
4766
	{
4780
		addTextFileToScripts(addFile, textid);
4767
		addTextFileToScripts(addFile, textid);
4781
		return true;
4768
		return true;
4782
	}
4769
	}
4783
 
4770
 
4784
	// first we need to find our text file
4771
	// first we need to find our text file
4785
	Utils::String filename;
4772
	Utils::WString filename;
4786
	if ( languageid != -1 )
4773
	if ( languageid != -1 )
4787
		filename = SPK::FormatTextName(textid.toInt(), languageid, (m_iGameFlags & EXEFLAG_TCTEXT));
4774
		filename = SPK::FormatTextName(textid.toInt(), languageid, (m_iGameFlags & EXEFLAG_TCTEXT));
4788
	else
4775
	else
4789
		filename = textid;
4776
		filename = textid;
4790
 
4777
 
4791
	C_File *textFile = findFile(FILETYPE_TEXT, filename + ".xml");
4778
	C_File *textFile = findFile(FILETYPE_TEXT, filename + L".xml");
4792
	if ( !textFile )
4779
	if ( !textFile )
4793
	{
4780
	{
4794
		textFile = findFile(FILETYPE_TEXT, filename + ".pck");
4781
		textFile = findFile(FILETYPE_TEXT, filename + L".pck");
4795
		if ( !textFile )
4782
		if ( !textFile )
4796
			return false;
4783
			return false;
4797
	}
4784
	}
4798
 
4785
 
4799
	// now lets create out new text file
4786
	// now lets create out new text file
4800
	CFileIO readFile(textFile->filePointer());
4787
	CFileIO readFile(textFile->filePointer());
-
 
4788
 
4801
	std::vector<Utils::String> *lines = readFile.readLines();
4789
	std::vector<Utils::WString> lines;
-
 
4790
	readFile.readLines(lines);
4802
 
4791
 
4803
	// find the language id in the lines
4792
	// find the language id in the lines
4804
	std::vector<Utils::String> frontLines;
4793
	std::vector<Utils::WString> frontLines;
4805
	for(std::vector<Utils::String>::iterator it = lines->begin(); it != lines->end(); ++it)
4794
	for(std::vector<Utils::WString>::iterator it = lines.begin(); it != lines.end(); ++it)
4806
	{
4795
	{
4807
		Utils::String line = *it;
4796
		Utils::WString line = *it;
4808
		int pos = line.findPos("<language id");
4797
		int pos = line.findPos(L"<language id");
4809
		if ( pos != -1)
4798
		if ( pos != -1)
4810
		{
4799
		{
4811
			Utils::String newLine = "<language id=\"";
4800
			Utils::WString newLine = L"<language id=\"";
4812
			newLine += Utils::String::Number(m_iLanguage);
4801
			newLine += Utils::WString::Number(m_iLanguage);
4813
			newLine += "\">";
4802
			newLine += L"\">";
4814
			newLine += line.tokens(">", 2);
4803
			newLine += line.tokens(L">", 2);
4815
 
4804
 
4816
			frontLines.insert(frontLines.begin(), newLine);
4805
			frontLines.insert(frontLines.begin(), newLine);
4817
 
4806
 
4818
			lines->erase(lines->begin(), ++it);
4807
			lines.erase(lines.begin(), ++it);
4819
			break;
4808
			break;
4820
		}
4809
		}
4821
		frontLines.insert(frontLines.begin(), line);
4810
		frontLines.insert(frontLines.begin(), line);
4822
	}
4811
	}
4823
 
4812
 
4824
	for(std::vector<Utils::String>::iterator it = frontLines.begin(); it != frontLines.end(); ++it)
4813
	for(std::vector<Utils::WString>::iterator it = frontLines.begin(); it != frontLines.end(); ++it)
4825
		lines->insert(lines->begin(), *it);
4814
		lines.insert(lines.begin(), *it);
4826
 
4815
 
4827
	addFile = new C_File(newFilename + ".xml");
4816
	addFile = new C_File(newFilename + ".xml");
4828
	addFile->setFileType(FILETYPE_TEXT);
4817
	addFile->setFileType(FILETYPE_TEXT);
4829
 
4818
 
4830
	CFileIO writeFile(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
4819
	CFileIO writeFile(m_sCurrentDir + L"/" + addFile->getNameDirectory(NULL));
4831
	if ( writeFile.writeFile(lines) )
4820
	if ( writeFile.writeFile(lines) )
4832
	{
4821
	{
4833
		this->addLogEntry(SPKINSTALL_WRITEFILE, addFile->getNameDirectory(NULL), errors);
4822
		this->addLogEntry(SPKINSTALL_WRITEFILE, addFile->getNameDirectory(NULL), errors);
4834
 
4823
 
4835
		addFile->setFilename(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
4824
		addFile->setFilename(m_sCurrentDir + L"/" + addFile->getNameDirectory(NULL));
4836
		// now we have the file wrriten, we need to add it to all scripts that need it
4825
		// now we have the file wrriten, we need to add it to all scripts that need it
4837
		// first we add it to the global list
4826
		// first we add it to the global list
4838
		m_lFiles.push_back(addFile);
4827
		m_lFiles.push_back(addFile);
4839
 
4828
 
4840
		// now add it to the scripts
4829
		// now add it to the scripts
4841
		addTextFileToScripts(addFile, textid);
4830
		addTextFileToScripts(addFile, textid);
4842
	}
4831
	}
4843
	else
4832
	else
4844
	{
4833
	{
4845
		this->addLogEntry(SPKINSTALL_WRITEFILE_FAIL, addFile->getNameDirectory(NULL), errors);
4834
		this->addLogEntry(SPKINSTALL_WRITEFILE_FAIL, addFile->getNameDirectory(NULL), errors);
4846
		if ( lines )
-
 
4847
			delete lines;
-
 
4848
		return false;
4835
		return false;
4849
	}
4836
	}
4850
 
-
 
4851
	if ( lines )
-
 
4852
		delete lines;
-
 
4853
 
-
 
4854
 
4837
 
4855
	return true;
4838
	return true;
4856
}
4839
}
4857
 
4840
 
4858
/**
4841
/**
4859
 * Add file to scripts
4842
 * Add file to scripts
4860
 *
4843
 *
4861
 * Adds a file to all scripts that need it
4844
 * Adds a file to all scripts that need it
4862
 */
4845
 */
4863
void CPackages::addTextFileToScripts(C_File *file, const Utils::String &textid)
4846
void CPackages::addTextFileToScripts(C_File *file, const Utils::WString &textid)
4864
{
4847
{
4865
	// now we need to find all scripts that have a matching file and add this to the list
4848
	// now we need to find all scripts that have a matching file and add this to the list
4866
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4849
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4867
	{
4850
	{
4868
		CBaseFile *package = node->Data();
4851
		CBaseFile *package = node->Data();
Line 4876... Line 4859...
4876
		{
4859
		{
4877
			C_File *tFile = fNode->Data();
4860
			C_File *tFile = fNode->Data();
4878
			if ( tFile->GetFileType() != FILETYPE_TEXT )
4861
			if ( tFile->GetFileType() != FILETYPE_TEXT )
4879
				continue;
4862
				continue;
4880
 
4863
 
4881
			Utils::String id = tFile->baseName().token("-", 1);
4864
			Utils::WString id = tFile->baseName().token(L"-", 1);
4882
			if ( id == textid )
4865
			if ( id == textid )
4883
			{
4866
			{
4884
				found = true;
4867
				found = true;
4885
				break;
4868
				break;
4886
			}
4869
			}
Line 4889... Line 4872...
4889
		if ( found )
4872
		if ( found )
4890
			package->GetFileList()->push_back(file);
4873
			package->GetFileList()->push_back(file);
4891
	}
4874
	}
4892
}
4875
}
4893
 
4876
 
4894
bool CPackages::removeFile(C_File *file, Utils::CStringList *errors)
4877
bool CPackages::removeFile(C_File *file, Utils::WStringList *errors)
4895
{
4878
{
4896
	if ( !file )
4879
	if ( !file )
4897
		return true;
4880
		return true;
4898
 
4881
 
4899
	Utils::String remFileStr = file->filePointer();
4882
	Utils::WString remFileStr = file->filePointer().findReplace(m_sCurrentDir, L"");
4900
	remFileStr.findReplace(m_sCurrentDir, "");
-
 
4901
 
4883
 
4902
	if ( file->filePointer().contains("::")) {
4884
	if ( file->filePointer().contains(L"::")) {
4903
		CFileIO CatFile(file->filePointer().token("::", 1));
4885
		CFileIO CatFile(file->filePointer().token(L"::", 1));
4904
		if ( CatFile.exists() ) {
4886
		if ( CatFile.exists() ) {
4905
			CCatFile cat;
4887
			CCatFile cat;
4906
			if ( cat.open(CatFile.fullFilenameStr(), this->getAddonDir(), CATREAD_DAT, false) == CATERR_NONE ) {
4888
			if ( cat.open(CatFile.fullFilenameStr(), this->getAddonDir(), CATREAD_DAT, false) == CATERR_NONE) {
4907
				Utils::String fileName = file->filePointer().token("::", 2);
4889
				Utils::WString fileName = file->filePointer().token(L"::", 2);
4908
				if ( cat.findData(fileName) ) {
4890
				if ( cat.findData(fileName) ) {
4909
					if ( cat.removeFile(fileName) ) {
4891
					if ( cat.removeFile(fileName) ) {
4910
						this->addLogEntry(SPKINSTALL_DELETEFILE, remFileStr, errors);
4892
						this->addLogEntry(SPKINSTALL_DELETEFILE, remFileStr, errors);
4911
					}
4893
					}
4912
					else {
4894
					else {
Line 4933... Line 4915...
4933
	}
4915
	}
4934
 
4916
 
4935
	return true;
4917
	return true;
4936
}
4918
}
4937
 
4919
 
4938
int CPackages::removeAllPackages(Utils::CStringList *errors, CProgressInfo *progress)
4920
int CPackages::removeAllPackages(Utils::WStringList *errors, CProgressInfo *progress)
4939
{
4921
{
4940
	int files = 0;
4922
	int files = 0;
4941
 
4923
 
4942
	// remove all files
4924
	// remove all files
4943
	int max = m_lFiles.size() + _pOriginalFiles->count() + m_lUninstallFiles.size();
4925
	int max = m_lFiles.size() + _pOriginalFiles->count() + m_lUninstallFiles.size();
Line 5044... Line 5026...
5044
		return Dir.file(L"../Data/" + file);
5026
		return Dir.file(L"../Data/" + file);
5045
 
5027
 
5046
	return Utils::WString::Null();
5028
	return Utils::WString::Null();
5047
}
5029
}
5048
 
5030
 
5049
void CPackages::startup(const Utils::String &dir, const Utils::String &tempDir, const Utils::String &myDoc)
5031
void CPackages::startup(const Utils::WString &dir, const Utils::WString &tempDir, const Utils::WString &myDoc)
5050
{
5032
{
5051
	this->setTempDirectory(tempDir);
5033
	this->setTempDirectory(tempDir);
5052
	this->setMyDocuments(myDoc);
5034
	this->setMyDocuments(myDoc);
5053
 
5035
 
5054
	// need to read the game exe versions
5036
	// need to read the game exe versions
Line 5056... Line 5038...
5056
 
5038
 
5057
	Utils::WString exeFile = this->findDataDir(dir, L"exe");
5039
	Utils::WString exeFile = this->findDataDir(dir, L"exe");
5058
 
5040
 
5059
	// if file exists, read it, otherwise, just add
5041
	// if file exists, read it, otherwise, just add
5060
	if (!exeFile.empty() && CFileIO::Exists(exeFile))
5042
	if (!exeFile.empty() && CFileIO::Exists(exeFile))
5061
		m_gameExe.ReadFile(exeFile.toString());
5043
		m_gameExe.readFile(exeFile);
5062
	else
5044
	else
5063
	{
5045
	{
5064
		m_gameExe.ParseExe("x2.exe|0:5:NOSAVESUBDIR:HKCU/Software/EgoSoftware/X2/ModName:X2 The Threat:!GAMEDIR!:2:1604608!2150400:1.4 Artifical Life:1974272:1.5 Uplink");
5046
		m_gameExe.parseExe(L"x2.exe|0:5:NOSAVESUBDIR:HKCU/Software/EgoSoftware/X2/ModName:X2 The Threat:!GAMEDIR!:2:1604608!2150400:1.4 Artifical Life:1974272:1.5 Uplink");
5065
		m_gameExe.ParseExe("x3.exe|30:5:0:HKCU/Software/Egosoft/X3/ModName:X3 Reunion:Egosoft/X3:2:2347008:2.0 Bala Gi:2367488!2375680:2.5 Uplink");
5047
		m_gameExe.parseExe(L"x3.exe|30:5:0:HKCU/Software/Egosoft/X3/ModName:X3 Reunion:Egosoft/X3:2:2347008:2.0 Bala Gi:2367488!2375680:2.5 Uplink");
5066
		m_gameExe.ParseExe("x3tc.exe|35:5:NO_XOR|TC_TEXT|MYDOCLOG:HKCU/Software/Egosoft/X3TC/ModName:X3 Terran Conflict:Egosoft/X3TC:3:1933464!1933520:2.0 Aldrin Expansion:-1:2.5 A New Home (Superbox):-1:3.0 Balance of Power");
5048
		m_gameExe.parseExe(L"x3tc.exe|35:5:NO_XOR|TC_TEXT|MYDOCLOG:HKCU/Software/Egosoft/X3TC/ModName:X3 Terran Conflict:Egosoft/X3TC:3:1933464!1933520:2.0 Aldrin Expansion:-1:2.5 A New Home (Superbox):-1:3.0 Balance of Power");
5067
		m_gameExe.ParseExe("x3ap.exe|38:2:NO_XOR|TC_TEXT|MYDOCLOG|ADDON:HKCU/Software/Egosoft/X3AP/ModName:X3 Albion Prelude:Egosoft/X3AP:addon!x3tc.exe:3:-1:2.0 The War Continues:-1:2.5 Operation Loose Ends:-1:3.0 Shady Business");
5049
		m_gameExe.parseExe(L"x3ap.exe|38:2:NO_XOR|TC_TEXT|MYDOCLOG|ADDON:HKCU/Software/Egosoft/X3AP/ModName:X3 Albion Prelude:Egosoft/X3AP:addon!x3tc.exe:3:-1:2.0 The War Continues:-1:2.5 Operation Loose Ends:-1:3.0 Shady Business");
5068
		m_gameExe.ParseExe("x3fl.exe|39:3:NO_XOR|TC_TEXT|MYDOCLOG|ADDON:HKCU/Software/Egosoft/X3FL/ModName:X3 Farnham's Legacy:Egosoft/X3FL:addon2!x3tc.exe:0");
5050
		m_gameExe.parseExe(L"x3fl.exe|39:3:NO_XOR|TC_TEXT|MYDOCLOG|ADDON:HKCU/Software/Egosoft/X3FL/ModName:X3 Farnham's Legacy:Egosoft/X3FL:addon2!x3tc.exe:0");
5069
	}
5051
	}
5070
}
5052
}
5071
void CPackages::startup(const Utils::String &dir, const Utils::String &tempDir, const Utils::String &myDoc, const Utils::String &mod)
5053
void CPackages::startup(const Utils::WString &dir, const Utils::WString &tempDir, const Utils::WString &myDoc, const Utils::WString &mod)
5072
{
5054
{
5073
	startup(dir, tempDir, myDoc);
5055
	startup(dir, tempDir, myDoc);
5074
	m_sSetMod = mod;
5056
	m_sSetMod = mod;
5075
}
5057
}
5076
 
5058
 
5077
int CPackages::getGameLanguage() const
5059
int CPackages::getGameLanguage() const
5078
{
5060
{
5079
	return this->getGameLanguage(m_sCurrentDir);
5061
	return this->getGameLanguage(m_sCurrentDir);
5080
}
5062
}
5081
int CPackages::getGameLanguage(const Utils::String &sDir) const
5063
int CPackages::getGameLanguage(const Utils::WString &sDir) const
5082
{
5064
{
5083
	Utils::String dir = sDir;
5065
	Utils::WString dir = sDir;
5084
	if (dir.empty())
5066
	if (dir.empty())
5085
		dir = m_sCurrentDir;
5067
		dir = m_sCurrentDir;
5086
	else
5068
	else
5087
		dir = this->getProperDir(dir);
5069
		dir = this->getProperDir(dir);
5088
 
5070
 
5089
	CDirIO Dir(dir);
5071
	CDirIO Dir(dir);
5090
 
5072
 
5091
	// check for lang.dat file
5073
	// check for lang.dat file
5092
	if ( Dir.exists("lang.dat") )
5074
	if ( Dir.exists(L"lang.dat") )
5093
	{
5075
	{
5094
		CFileIO File(Dir.file("lang.dat"));
5076
		CFileIO File(Dir.file(L"lang.dat"));
5095
 
5077
 
5096
		size_t size;
5078
		size_t size;
5097
		char *data = File.ReadToData(&size);
5079
		char *data = File.ReadToData(&size);
5098
 
5080
 
5099
		if ( data )
5081
		if ( data )
Line 5103... Line 5085...
5103
		}
5085
		}
5104
	}
5086
	}
5105
 
5087
 
5106
	return 0;
5088
	return 0;
5107
}
5089
}
5108
Utils::String CPackages::getGameRunExe(const Utils::String &dir) const
5090
Utils::WString CPackages::getGameRunExe(const Utils::WString &dir) const
5109
{
5091
{
5110
	return m_gameExe.GetGameRunExe(dir);
5092
	return m_gameExe.gameRunExe(dir);
5111
}
5093
}
5112
Utils::String CPackages::getGameRunExe() const
5094
Utils::WString CPackages::getGameRunExe() const
5113
{
5095
{
5114
	return m_gameExe.GetGameRunExe(m_sCurrentDir);
5096
	return m_gameExe.gameRunExe(m_sCurrentDir);
5115
}
5097
}
5116
 
5098
 
5117
Utils::String CPackages::getGameNameFromType(int game) const
5099
Utils::WString CPackages::getGameNameFromType(int game) const
5118
{
5100
{
5119
	return m_gameExe.GetGameNameFromType(game - 1);
5101
	return m_gameExe.gameNameFromType(game - 1);
5120
}
5102
}
5121
Utils::String CPackages::getGameName() const
5103
Utils::WString CPackages::getGameName() const
5122
{
5104
{
5123
	return getGameName(m_sCurrentDir);
5105
	return getGameName(m_sCurrentDir);
5124
}
5106
}
5125
 
5107
 
5126
Utils::String CPackages::getGameName(const Utils::String &dir) const
5108
Utils::WString CPackages::getGameName(const Utils::WString &dir) const
5127
{
5109
{
5128
	return m_gameExe.GetGameName(dir.empty() ? m_sCurrentDir : dir);
5110
	return m_gameExe.gameName(dir.empty() ? m_sCurrentDir : dir);
5129
}
5111
}
5130
 
5112
 
5131
Utils::String CPackages::getProperDir() const
5113
Utils::WString CPackages::getProperDir() const
5132
{
5114
{
5133
	return getProperDir(m_sCurrentDir);
5115
	return getProperDir(m_sCurrentDir);
5134
}
5116
}
5135
Utils::String CPackages::getProperDir(const Utils::String &dir) const
5117
Utils::WString CPackages::getProperDir(const Utils::WString &dir) const
5136
{
5118
{
5137
	return m_gameExe.GetProperDir((dir.empty()) ? m_sCurrentDir : dir);
5119
	return m_gameExe.properDir((dir.empty()) ? m_sCurrentDir : dir);
5138
}
5120
}
5139
Utils::String CPackages::getAddonDir() const
5121
Utils::WString CPackages::getAddonDir() const
5140
{
5122
{
5141
	return getAddonDir(m_sCurrentDir);
5123
	return getAddonDir(m_sCurrentDir);
5142
}
5124
}
5143
Utils::String CPackages::getAddonDir(const Utils::String &dir) const
5125
Utils::WString CPackages::getAddonDir(const Utils::WString &dir) const
5144
{
5126
{
5145
	return m_gameExe.GetAddonDir((dir.empty()) ? m_sCurrentDir : dir);
5127
	return m_gameExe.addonDir((dir.empty()) ? m_sCurrentDir : dir);
5146
}
5128
}
5147
int CPackages::getGameAddons(Utils::CStringList &exes, const Utils::String &dir) const
5129
int CPackages::getGameAddons(Utils::WStringList &exes, const Utils::WString &dir) const
5148
{
5130
{
5149
	return m_gameExe.getGameAddons((dir.empty()) ? m_sCurrentDir : dir, exes);
5131
	return m_gameExe.getGameAddons((dir.empty()) ? m_sCurrentDir : dir, exes);
5150
}
5132
}
5151
int CPackages::getGameAddons(Utils::CStringList &exes) const
5133
int CPackages::getGameAddons(Utils::WStringList &exes) const
5152
{
5134
{
5153
	return m_gameExe.getGameAddons(m_sCurrentDir, exes);
5135
	return m_gameExe.getGameAddons(m_sCurrentDir, exes);
5154
}
5136
}
5155
 
5137
 
5156
Utils::String CPackages::getGameTypesString(CBaseFile *package, bool includeVersion) const
5138
Utils::WString CPackages::getGameTypesString(CBaseFile *package, bool includeVersion) const
5157
{
5139
{
5158
	if ( !package->AnyGameCompatability() )
5140
	if ( !package->AnyGameCompatability() )
5159
		return "";
5141
		return L"";
5160
 
5142
 
5161
	Utils::String sGames;
5143
	Utils::WString sGames;
5162
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5144
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5163
		if ( !sGames.empty() )
5145
		if ( !sGames.empty() )
5164
			sGames += ", ";
5146
			sGames += L", ";
5165
		sGames += m_gameExe.GetGameNameFromType(gNode->Data()->iGame - 1);
5147
		sGames += m_gameExe.gameNameFromType(gNode->Data()->iGame - 1);
5166
		if ( includeVersion ) {
5148
		if ( includeVersion ) {
5167
			Utils::String version = m_gameExe.GetGameVersionFromType(gNode->Data()->iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
5149
			Utils::WString version = m_gameExe.gameVersionFromType(gNode->Data()->iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
5168
			if ( !version.empty() ) {
5150
			if ( !version.empty() ) {
5169
				sGames += " (";
5151
				sGames += L" (";
5170
				sGames += version;
5152
				sGames += version;
5171
				sGames += ")";
5153
				sGames += L")";
5172
			}
5154
			}
5173
		}
5155
		}
5174
	}
5156
	}
5175
	return sGames;
5157
	return sGames;
5176
}
5158
}
5177
 
5159
 
5178
Utils::String CPackages::getGameVersionString(CBaseFile *package) const
5160
Utils::WString CPackages::getGameVersionString(CBaseFile *package) const
5179
{
5161
{
5180
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5162
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5181
		if ( gNode->Data()->iGame == m_iGame ) {
5163
		if ( gNode->Data()->iGame == m_iGame ) {
5182
			return m_gameExe.GetGameVersionFromType(m_iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
5164
			return m_gameExe.gameVersionFromType(m_iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
5183
		}
5165
		}
5184
	}
5166
	}
5185
 
5167
 
5186
	return Utils::String::Null();
5168
	return Utils::WString::Null();
5187
}
5169
}
5188
 
5170
 
5189
Utils::String CPackages::getGameVersionFromType(int game, int version, const Utils::String &sVersion) const
5171
Utils::WString CPackages::getGameVersionFromType(int game, int version, const Utils::WString &sVersion) const
5190
{
5172
{
5191
	return m_gameExe.GetGameVersionFromType(game - 1, version - 1, sVersion);
5173
	return m_gameExe.gameVersionFromType(game - 1, version - 1, sVersion);
5192
}
5174
}
5193
 
5175
 
5194
int CPackages::CountBuiltInPackages(bool onlyEnabled)
5176
int CPackages::CountBuiltInPackages(bool onlyEnabled)
5195
{
5177
{
5196
	int count = 0;
5178
	int count = 0;
Line 5224... Line 5206...
5224
	}
5206
	}
5225
 
5207
 
5226
	return count;
5208
	return count;
5227
}
5209
}
5228
 
5210
 
5229
int CPackages::extractGameFile(const Utils::String &aFilename, const Utils::String &aTo, const Utils::String &aDir, const Utils::String &addon) const
5211
int CPackages::extractGameFile(const Utils::WString &aFilename, const Utils::WString &aTo, const Utils::WString &aDir, const Utils::WString &addon) const
5230
{
5212
{
5231
	// first check the enabled mod
5213
	// first check the enabled mod
5232
	Utils::String dir = aDir;
5214
	Utils::WString dir = aDir;
5233
	if (dir.empty())
5215
	if (dir.empty())
5234
		dir = m_sCurrentDir;
5216
		dir = m_sCurrentDir;
5235
 
5217
 
5236
	Utils::String addonDir = addon;
5218
	Utils::WString addonDir = addon;
5237
	if (addonDir.empty()) addonDir = this->getAddonDir(dir);
5219
	if (addonDir.empty()) addonDir = this->getAddonDir(dir);
5238
 
5220
 
5239
	if (m_pEnabledMod && m_pEnabledMod->AnyFileType(FILETYPE_MOD))
5221
	if (m_pEnabledMod && m_pEnabledMod->AnyFileType(FILETYPE_MOD))
5240
	{
5222
	{
5241
		for (C_File* file = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); file; file = m_pEnabledMod->GetNextFile(file))
5223
		for (C_File* file = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); file; file = m_pEnabledMod->GetNextFile(file))
5242
		{
5224
		{
5243
			if (!file->checkFileExt("cat"))
5225
			if (!file->checkFileExt(L"cat"))
5244
				continue;
5226
				continue;
5245
 
5227
 
5246
			CCatFile catFile;
5228
			CCatFile catFile;
5247
			if (catFile.open(file->filePointer(), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5229
			if (catFile.open(file->filePointer(), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5248
			{
5230
			{
Line 5257... Line 5239...
5257
			}
5239
			}
5258
		}
5240
		}
5259
	}
5241
	}
5260
	else if (!m_sSetMod.empty())
5242
	else if (!m_sSetMod.empty())
5261
	{
5243
	{
5262
		if (CFileIO::Exists(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat"))
5244
		if (CFileIO::Exists(m_sCurrentDir + L"/mods/" + m_sSetMod + L".cat"))
5263
		{
5245
		{
5264
			CCatFile catFile;
5246
			CCatFile catFile;
5265
			if (catFile.open(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5247
			if (catFile.open(m_sCurrentDir + L"/mods/" + m_sSetMod + L".cat", addonDir.toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
5266
			{
5248
			{
5267
				if (catFile.extractFile(aFilename, aTo))
5249
				if (catFile.extractFile(aFilename, aTo))
5268
					return 1;
5250
					return 1;
5269
				if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
5251
				if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
5270
				{
5252
				{
Line 5275... Line 5257...
5275
		}
5257
		}
5276
	}
5258
	}
5277
 
5259
 
5278
	// find the highest cat number
5260
	// find the highest cat number
5279
	int catNumber = 1;
5261
	int catNumber = 1;
5280
	while (CFileIO::Exists(dir + "/" + Utils::String::PadNumber(catNumber, 2) + ".cat") && catNumber < 99)
5262
	while (CFileIO::Exists(dir + L"/" + Utils::WString::PadNumber(catNumber, 2) + L".cat") && catNumber < 99)
5281
		++catNumber;
5263
		++catNumber;
5282
 
5264
 
5283
	// get the last one, not the next free one
5265
	// get the last one, not the next free one
5284
	--catNumber;
5266
	--catNumber;
5285
 
5267
 
5286
	// work backwards until we find the file
5268
	// work backwards until we find the file
5287
	for (; catNumber; catNumber--)
5269
	for (; catNumber; catNumber--)
5288
	{
5270
	{
5289
		CCatFile catFile;
5271
		CCatFile catFile;
5290
		if (catFile.open((dir + "/" + Utils::String::PadNumber(catNumber, 2) + ".cat"), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5272
		if (catFile.open((dir + L"/" + Utils::WString::PadNumber(catNumber, 2) + L".cat"), addonDir.toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
5291
		{
5273
		{
5292
			// check for the file
5274
			// check for the file
5293
			if (catFile.extractFile(aFilename, aTo))
5275
			if (catFile.extractFile(aFilename, aTo))
5294
				return 1;
5276
				return 1;
5295
			if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
5277
			if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
Line 5312... Line 5294...
5312
		// its empty, no need to create ware files
5294
		// its empty, no need to create ware files
5313
		if ( !m_lGameWares[i].size() )
5295
		if ( !m_lGameWares[i].size() )
5314
			continue;
5296
			continue;
5315
 
5297
 
5316
		// lets extract the ware file
5298
		// lets extract the ware file
5317
		char wareType = CPackages::ConvertWareTypeBack(i);
5299
		wchar_t wareType = CPackages::ConvertWareTypeBack(i);
5318
		Utils::String wareFile = "TWare";
5300
		Utils::WString wareFile = L"TWare";
5319
		wareFile += (char)UPPER(wareType);
5301
		wareFile += (wchar_t)UPPER(wareType);
5320
 
5302
 
5321
		Utils::String openFile;
5303
		Utils::WString openFile;
5322
 
5304
 
5323
		int e;
5305
		int e;
5324
		if ( i == WARES_TECH && CFileIO::Exists(m_sTempDir + "/TWareT.txt") )
5306
		if ( i == WARES_TECH && CFileIO::Exists(m_sTempDir + L"/TWareT.txt") )
5325
			openFile = m_sTempDir + "/TWareT.txt";
5307
			openFile = m_sTempDir + L"/TWareT.txt";
5326
		else {
5308
		else {
5327
			e = extractGameFile("types/" + wareFile + ".pck", m_sTempDir + "/" + wareFile + ".txt");
5309
			e = extractGameFile(L"types/" + wareFile + L".pck", m_sTempDir + L"/" + wareFile + L".txt");
5328
			if ( e == 1 )
5310
			if ( e == 1 )
5329
				openFile = m_sTempDir + "/" + wareFile + ".txt";
5311
				openFile = m_sTempDir + L"/" + wareFile + L".txt";
5330
			else if ( e == -2 )
5312
			else if ( e == -2 )
5331
				openFile = wareFile + ".txt";
5313
				openFile = wareFile + L".txt";
5332
		}
5314
		}
5333
 
5315
 
5334
		if ( !openFile.empty() )
5316
		if ( !openFile.empty() )
5335
		{
5317
		{
5336
			// read the file into memory
5318
			// read the file into memory
5337
			Utils::CStringList wareLines;
5319
			Utils::WStringList wareLines;
5338
			size_t oldSize = -1;
5320
			size_t oldSize = -1;
5339
			int version = -1;
5321
			int version = -1;
5340
 
5322
 
5341
			// read first number
5323
			// read first number
5342
			CFileIO readFile(m_sTempDir + "/" + wareFile + ".txt");
5324
			CFileIO readFile(m_sTempDir + L"/" + wareFile + L".txt");
5343
			Utils::CStringList *lines = readFile.readLinesStr();
5325
			std::vector<Utils::WString> lines;
5344
			if ( lines )
5326
			if(readFile.readLines(lines))
5345
			{
5327
			{
5346
				for(auto itr = lines->begin(); itr != lines->end(); itr++)
5328
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
5347
				{
5329
				{
5348
					Utils::String line((*itr)->str);
5330
					Utils::WString line = *itr;
5349
					line.removeFirstSpace();
5331
					line.removeFirstSpace();
5350
					line.removeChar(9);
5332
					line.removeChar(9);
5351
					line.removeChar('\r');
5333
					line.removeChar('\r');
5352
					if ( line.empty() )
5334
					if ( line.empty() )
5353
						continue;
5335
						continue;
5354
					if ( line[0] == '/' )
5336
					if ( line[0] == '/' )
5355
						continue;
5337
						continue;
5356
 
5338
 
5357
					if ( oldSize == -1 )
5339
					if ( oldSize == -1 )
5358
					{
5340
					{
5359
						version = line.token(";", 1).toInt();
5341
						version = line.token(L";", 1).toInt();
5360
						oldSize = line.token(";", 2).toInt();
5342
						oldSize = line.token(L";", 2).toInt();
5361
					}
5343
					}
5362
					else
5344
					else
5363
					{
5345
					{
5364
						line.removeEndSpace();
5346
						line.removeEndSpace();
5365
						if ( line.back() != ';')
5347
						if ( line.back() != L';')
5366
							line += ";";
5348
							line += L";";
5367
						wareLines.pushBack(line);
5349
						wareLines.pushBack(line);
5368
						if ( wareLines.size() >= oldSize )
5350
						if ( wareLines.size() >= oldSize )
5369
							break;
5351
							break;
5370
					}
5352
					}
5371
				}
5353
				}
5372
 
-
 
5373
				delete lines;
-
 
5374
 
5354
 
5375
				// apply the buffer
5355
				// apply the buffer
5376
				if ( m_iWareBuffer[i] <= 0 )
5356
				if ( m_iWareBuffer[i] <= 0 )
5377
					m_iWareBuffer[i] = wareLines.size() + 10;
5357
					m_iWareBuffer[i] = wareLines.size() + 10;
5378
				// last resort, readjust the buffer
5358
				// last resort, readjust the buffer
5379
				else if ( wareLines.size() > static_cast<size_t>(m_iWareBuffer[i]) )
5359
				else if ( wareLines.size() > static_cast<size_t>(m_iWareBuffer[i]) )
5380
					m_iWareBuffer[i] = wareLines.size();
5360
					m_iWareBuffer[i] = wareLines.size();
5381
 
5361
 
5382
				// add the buffers
5362
				// add the buffers
5383
				while ( wareLines.size() < static_cast<size_t>(m_iWareBuffer[i]) )
5363
				while ( wareLines.size() < static_cast<size_t>(m_iWareBuffer[i]) )
5384
					wareLines.pushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_FILLER;");
5364
					wareLines.pushBack(L"27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_FILLER;");
5385
 
5365
 
5386
				// add the ware lines
5366
				// add the ware lines
5387
				bool create = false;
5367
				bool create = false;
5388
				for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
5368
				for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
5389
				{
5369
				{
5390
					SGameWare *w = node->Data();
5370
					SGameWare *w = node->Data();
5391
 
5371
 
5392
					if ( w->iType == WARETYPE_NONE )
5372
					if ( w->iType == WARETYPE_NONE )
5393
						continue;
5373
						continue;
5394
					else if ( w->iType == WARETYPE_DISABLED )
5374
					else if ( w->iType == WARETYPE_DISABLED )
5395
					{
5375
					{
5396
						create = true;
5376
						create = true;
5397
						wareLines.pushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;" + w->sWareName + "_DISABLED;");
5377
						wareLines.pushBack(L"27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;" + w->sWareName + L"_DISABLED;");
5398
					}
5378
					}
5399
					else if ( w->iType == WARETYPE_DELETED || !w->pWare )
5379
					else if ( w->iType == WARETYPE_DELETED || !w->pWare )
5400
					{
5380
					{
5401
						create = true;
5381
						create = true;
5402
						wareLines.pushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_DELETED;");
5382
						wareLines.pushBack(L"27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_DELETED;");
5403
					}
5383
					}
5404
					else if ( w->iType == WARETYPE_ADDED )
5384
					else if ( w->iType == WARETYPE_ADDED )
5405
					{
5385
					{
5406
						create = true;
5386
						create = true;
5407
						w->pWare->iDescID = wareTextID;
5387
						w->pWare->iDescID = wareTextID;
Line 5411... Line 5391...
5411
						long price = this->customWareOveridePrice(w->pWare->sID);
5391
						long price = this->customWareOveridePrice(w->pWare->sID);
5412
						int notority = w->pWare->iNotority;
5392
						int notority = w->pWare->iNotority;
5413
						if ( !this->customWareOverideNoto(w->pWare->sID, &notority) ) notority = w->pWare->iNotority;
5393
						if ( !this->customWareOverideNoto(w->pWare->sID, &notority) ) notority = w->pWare->iNotority;
5414
						if ( !price ) price = w->pWare->iPrice;
5394
						if ( !price ) price = w->pWare->iPrice;
5415
 
5395
 
5416
						wareLines.pushBack(Utils::String("28;0;0;0;0;") + (long)wareLines.size() + ";" + (long)(w->iText + 3) + ";" + (long)w->pWare->iVolumn + ";" + price + ";1;1;" + (long)w->pWare->iSize + ";" + price + ";" + (long)notority + ";0;0;" + w->sWareName.upper() + ";");
5396
						wareLines.pushBack(Utils::WString("28;0;0;0;0;") + (long)wareLines.size() + L";" + (long)(w->iText + 3) + L";" + (long)w->pWare->iVolumn + L";" + price + L";1;1;" + (long)w->pWare->iSize + L";" + price + L";" + (long)notority + L";0;0;" + w->sWareName.upper() + L";");
5417
					}
5397
					}
5418
				}
5398
				}
5419
 
5399
 
5420
				if ( create )
5400
				if ( create )
5421
				{
5401
				{
5422
					wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5402
					wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5423
					Utils::String strV;
-
 
5424
					strV.FromFloat(GetLibraryVersion(), 2);
5403
					Utils::WString strV = Utils::WString::FromFloat(GetLibraryVersion(), 2);
5425
					wareLines.pushFront("// Created by SPKInstaller Libraries V" + strV, Utils::String::Null());
5404
					wareLines.pushFront("// Created by SPKInstaller Libraries V" + strV, Utils::WString::Null());
5426
					if ( readFile.writeFile(&wareLines) )
5405
					if ( readFile.writeFile(&wareLines) )
5427
						this->packFile(&readFile, "types\\" + wareFile + ".pck");
5406
						this->packFile(&readFile, L"types\\" + wareFile + L".pck");
5428
				}
5407
				}
5429
			}
5408
			}
5430
			readFile.remove();
5409
			readFile.remove();
5431
		}
5410
		}
5432
	}
5411
	}
5433
}
5412
}
5434
 
5413
 
5435
Utils::String CPackages::empWaresForGame(size_t *maxsize)
5414
Utils::WString CPackages::empWaresForGame(size_t *maxsize)
5436
{
5415
{
5437
	if ( maxsize ) (*maxsize) = 0;
5416
	if ( maxsize ) (*maxsize) = 0;
5438
 
5417
 
5439
	if ( m_iGame == GAME_X3TC )
5418
	if ( m_iGame == GAME_X3TC )
5440
	{
5419
	{
5441
		if ( maxsize ) (*maxsize) = EMP_X3TC;
5420
		if ( maxsize ) (*maxsize) = EMP_X3TC;
5442
		return GetX3TCEmp();
5421
		return GetX3TCEmp();
5443
	}
5422
	}
5444
	else if (m_iGame == GAME_X3AP)
5423
	else if (m_iGame == GAME_X3AP)
5445
	{
5424
	{
5446
		if (maxsize) (*maxsize) = EMP_X3AP;
5425
		if (maxsize) (*maxsize) = EMP_X3AP;
5447
		return GetX3TCEmp();
5426
		return GetX3TCEmp();
5448
	}
5427
	}
5449
	else if (m_iGame == GAME_X3FL)
5428
	else if (m_iGame == GAME_X3FL)
5450
	{
5429
	{
5451
		if (maxsize) (*maxsize) = EMP_X3FL;
5430
		if (maxsize) (*maxsize) = EMP_X3FL;
5452
		return GetX3TCEmp();
5431
		return GetX3TCEmp();
5453
	}
5432
	}
5454
	else if ( m_iGame == GAME_X3 )
5433
	else if ( m_iGame == GAME_X3 )
5455
	{
5434
	{
5456
		if ( maxsize ) (*maxsize) = EMP_X3;
5435
		if ( maxsize ) (*maxsize) = EMP_X3;
5457
		return GetX3Emp();
5436
		return GetX3Emp();
5458
	}
5437
	}
5459
 
5438
 
5460
	return Utils::String::Null();
5439
	return Utils::String::Null();
5461
}
5440
}
5462
 
5441
 
5463
void CPackages::_addWareOverride(enum WareTypes type, int pos, const Utils::String &id, int value, bool noto)
5442
void CPackages::_addWareOverride(enum WareTypes type, int pos, const Utils::WString &id, int value, bool noto)
5464
{
5443
{
5465
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
5444
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
5466
		SWarePriceOverride *wp = node->Data();
5445
		SWarePriceOverride *wp = node->Data();
5467
		if ( wp->type == type ) {
5446
		if ( wp->type == type ) {
5468
			if ( wp->type == Ware_Custom && !wp->id.Compare(id) ) continue;
5447
			if ( wp->type == Ware_Custom && !wp->id.Compare(id) ) continue;
Line 5486... Line 5465...
5486
 
5465
 
5487
	m_lWarePrices.push_back(ware);
5466
	m_lWarePrices.push_back(ware);
5488
}
5467
}
5489
 
5468
 
5490
void CPackages::addEMPPriceOverride(int empId, int price)
5469
void CPackages::addEMPPriceOverride(int empId, int price)
5491
{
5470
{
5492
	_addWareOverride(Ware_EMP, empId, Utils::String::Null(), price, false);
5471
	_addWareOverride(Ware_EMP, empId, Utils::WString::Null(), price, false);
5493
}
5472
}
5494
 
5473
 
5495
void CPackages::addEMPNotoOverride(int empId, int noto)
5474
void CPackages::addEMPNotoOverride(int empId, int noto)
5496
{
5475
{
5497
	_addWareOverride(Ware_EMP, empId, Utils::String::Null(), noto, true);
5476
	_addWareOverride(Ware_EMP, empId, Utils::WString::Null(), noto, true);
5498
}
5477
}
5499
 
5478
 
5500
void CPackages::addBuiltInWarePriceOverride(int empId, int price)
5479
void CPackages::addBuiltInWarePriceOverride(int empId, int price)
5501
{
5480
{
5502
	_addWareOverride(Ware_BuiltIn, empId, Utils::String::Null(), price, false);
5481
	_addWareOverride(Ware_BuiltIn, empId, Utils::WString::Null(), price, false);
5503
}
5482
}
5504
 
5483
 
5505
void CPackages::addBuiltInWareNotoOverride(int empId, int noto)
5484
void CPackages::addBuiltInWareNotoOverride(int empId, int noto)
5506
{
5485
{
5507
	_addWareOverride(Ware_BuiltIn, empId, Utils::String::Null(), noto, false);
5486
	_addWareOverride(Ware_BuiltIn, empId, Utils::WString::Null(), noto, false);
5508
}
5487
}
5509
 
5488
 
5510
void CPackages::addCustomWarePriceOverride(const Utils::String &id, int price)
5489
void CPackages::addCustomWarePriceOverride(const Utils::WString &id, int price)
5511
{
5490
{
5512
	_addWareOverride(Ware_Custom, 0, id, price, false);
5491
	_addWareOverride(Ware_Custom, 0, id, price, false);
5513
}
5492
}
5514
 
5493
 
5515
void CPackages::addCustomWareNotoOverride(const Utils::String &id, int noto)
5494
void CPackages::addCustomWareNotoOverride(const Utils::WString &id, int noto)
5516
{
5495
{
5517
	_addWareOverride(Ware_Custom, 0, id, noto, true);
5496
	_addWareOverride(Ware_Custom, 0, id, noto, true);
5518
}
5497
}
5519
 
5498
 
5520
 
5499
 
5521
void CPackages::createEMPFile(const Utils::String &progDir)
5500
void CPackages::createEMPFile(const Utils::String &progDir)
5522
{
5501
{
5523
	// do emp wares
5502
	// do emp wares
5524
	size_t maxsize = 0;
5503
	size_t maxsize = 0;
5525
	Utils::String empWares = empWaresForGame(&maxsize);
5504
	Utils::WString empWares = empWaresForGame(&maxsize);
5526
 
5505
 
5527
	if ( maxsize )
5506
	if ( maxsize )
5528
	{
5507
	{
5529
		int e = extractGameFile("types/TWareT.pck", m_sTempDir + "/TWareT.txt");
5508
		int e = extractGameFile(L"types/TWareT.pck", m_sTempDir + L"/TWareT.txt");
5530
		if (e)
5509
		if (e)
5531
		{
5510
		{
5532
			// read the file into memory
5511
			// read the file into memory
5533
			Utils::CStringList wareLines;
5512
			Utils::WStringList wareLines;
5534
			size_t oldSize = -1;
5513
			size_t oldSize = -1;
5535
			int version = -1;
5514
			int version = -1;
5536
 
5515
 
5537
			// read first number
5516
			// read first number
5538
			CFileIO readFile((e == -1) ? "TWareT.txt" : m_sTempDir + "/TWareT.txt");
5517
			CFileIO readFile((e == -1) ? L"TWareT.txt" : m_sTempDir + L"/TWareT.txt");
5539
			std::vector<Utils::String> lines;
5518
			std::vector<Utils::WString> lines;
5540
			if(readFile.readLines(lines))
5519
			if(readFile.readLines(lines))
5541
			{
5520
			{
5542
				for ( int i = 0; i < (int)lines.size(); i++ )
5521
				for ( int i = 0; i < (int)lines.size(); i++ )
5543
				{
5522
				{
5544
					Utils::String line(lines.at(i));
5523
					Utils::WString line(lines.at(i));
5545
					line.removeFirstSpace();
5524
					line.removeFirstSpace();
5546
					line.removeChar('\r');
5525
					line.removeChar('\r');
5547
					line.removeChar(9);
5526
					line.removeChar(9);
5548
					if ( line[0] == '/' )
5527
					if ( line[0] == '/' )
5549
						continue;
5528
						continue;
5550
 
5529
 
5551
					if ( oldSize == -1 )
5530
					if ( oldSize == -1 )
5552
					{
5531
					{
5553
						version = line.token(";", 1).toLong();
5532
						version = line.token(L";", 1).toLong();
5554
						oldSize = line.token(";", 2).toLong();
5533
						oldSize = line.token(L";", 2).toLong();
5555
					}
5534
					}
5556
					else
5535
					else
5557
					{
5536
					{
5558
						line.removeEndSpace();
5537
						line.removeEndSpace();
5559
						if ( line.right(1) != ";" )
5538
						if ( line.right(1) != L";" )
5560
							line += ";";
5539
							line += L";";
5561
 
5540
 
5562
						// check for any override values for built in wares
5541
						// check for any override values for built in wares
5563
						if ( (i >= 62 && i <= 81) || (i >= 88 && i <= 93) ) {
5542
						if ( (i >= 62 && i <= 81) || (i >= 88 && i <= 93) ) {
5564
							int pos = i - ((i >= 88) ? 88 : 62);
5543
							int pos = i - ((i >= 88) ? 88 : 62);
5565
							int price = this->builtInWareOveridePrice(pos);
5544
							int price = this->builtInWareOveridePrice(pos);
5566
							if ( price ) {
5545
							if ( price ) {
5567
								line = line.replaceToken(";", 9, Utils::String::Number(price));
5546
								line = line.replaceToken(L";", 9, Utils::WString::Number(price));
5568
								line = line.replaceToken(";", 13, Utils::String::Number(price));
5547
								line = line.replaceToken(L";", 13, Utils::WString::Number(price));
5569
							}
5548
							}
5570
 
5549
 
5571
							int noto = 0;
5550
							int noto = 0;
5572
							if ( this->builtInWareOverideNoto(pos, &noto) ) {
5551
							if ( this->builtInWareOverideNoto(pos, &noto) ) {
5573
								line = line.replaceToken(";", 14, Utils::String::Number(noto));
5552
								line = line.replaceToken(L";", 14, Utils::WString::Number(noto));
5574
							}
5553
							}
5575
						}
5554
						}
5576
 
5555
 
5577
						// check for any override values for EMP
5556
						// check for any override values for EMP
5578
						if ( i >= 116 ) {
5557
						if ( i >= 116 ) {
5579
							int price = this->empOveridePrice(i - 116);
5558
							int price = this->empOveridePrice(i - 116);
5580
							if ( price ) {
5559
							if ( price ) {
5581
								line = line.replaceToken(";", 9, Utils::String::Number(price));
5560
								line = line.replaceToken(L";", 9, Utils::WString::Number(price));
5582
								line = line.replaceToken(";", 13, Utils::String::Number(price));
5561
								line = line.replaceToken(L";", 13, Utils::WString::Number(price));
5583
							}
5562
							}
5584
 
5563
 
5585
							int noto = 0;
5564
							int noto = 0;
5586
							if ( this->empOverideNoto(i - 116, &noto) ) {
5565
							if ( this->empOverideNoto(i - 116, &noto) ) {
5587
								line = line.replaceToken(";", 14, Utils::String::Number(noto));
5566
								line = line.replaceToken(L";", 14, Utils::WString::Number(noto));
5588
							}
5567
							}
5589
						}
5568
						}
5590
 
5569
 
5591
						wareLines.pushBack(line);
5570
						wareLines.pushBack(line);
5592
						if ( wareLines.size() >= oldSize )
5571
						if ( wareLines.size() >= oldSize )
5593
							break;
5572
							break;
5594
					}
5573
					}
5595
				}
5574
				}
5596
			}
5575
			}
5597
 
5576
 
5598
			// now we too add/remove entries to match
5577
			// now we too add/remove entries to match
5599
			// need filler entries
5578
			// need filler entries
5600
			while ( wareLines.size() < maxsize )
5579
			while ( wareLines.size() < maxsize )
5601
				wareLines.pushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_FILLER;");
5580
				wareLines.pushBack(L"27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_FILLER;");
5602
 
5581
 
5603
			int empEntries = 0;
-
 
5604
			Utils::String *empStr = empWares.tokenise("\n", &amp;empEntries);
5582
			std::vector<Utils::WString&gt; empStr;
5605
 
-
 
5606
			if ( empEntries &&amp; empStr )
5583
			if(empWares.tokenise(L&quot;\n", empStr))
5607
			{
5584
			{
5608
				// apply any price overrides
5585
				// apply any price overrides
-
 
5586
				size_t empEntries = empStr.size();
5609
				for(int i = 0; i < empEntries; i++) {
5587
				for(size_t i = 0; i < empEntries; i++) {
5610
					int price = this->empOveridePrice(i);
5588
					int price = this->empOveridePrice(i);
5611
					if ( price ) {
5589
					if ( price ) {
5612
						empStr[i] = empStr[i].replaceToken(";", 9, Utils::String::Number(price));
5590
						empStr[i] = empStr[i].replaceToken(L";", 9, Utils::WString::Number(price));
5613
						empStr[i] = empStr[i].replaceToken(";", 13, Utils::String::Number(price));
5591
						empStr[i] = empStr[i].replaceToken(L";", 13, Utils::WString::Number(price));
5614
					}
5592
					}
5615
 
5593
 
5616
					int noto = 0;
5594
					int noto = 0;
5617
					if ( this->empOverideNoto(i, &noto) ) {
5595
					if ( this->empOverideNoto(i, &noto) ) {
5618
						empStr[i] = empStr[i].replaceToken(";", 14, Utils::String::Number(noto));
5596
						empStr[i] = empStr[i].replaceToken(L";", 14, Utils::WString::Number(noto));
5619
					}
5597
					}
5620
				}
5598
				}
5621
				// remove any empty end entries
5599
				// remove any empty end entries
5622
				while ( empStr[empEntries - 1].empty() )
5600
				while ( empStr[empEntries - 1].empty() )
5623
					--empEntries;
5601
					--empEntries;
5624
 
5602
 
5625
				Utils::CStringList addAfter;
5603
				Utils::WStringList addAfter;
5626
				if ( wareLines.size() > maxsize )
5604
				if ( wareLines.size() > maxsize )
5627
				{
5605
				{
5628
					// force emp, remove entries to allow them to be added
5606
					// force emp, remove entries to allow them to be added
5629
					if ( m_bForceEMP )
5607
					if ( m_bForceEMP )
5630
					{
5608
					{
5631
						// more after emp
5609
						// more after emp
5632
						if ( wareLines.size() > (maxsize + empEntries) )
5610
						if ( wareLines.size() > (maxsize + empEntries) )
5633
						{
5611
						{
5634
							for (size_t i = (maxsize + empEntries); i < wareLines.size(); i++)
5612
							for (size_t i = (maxsize + empEntries); i < wareLines.size(); i++)
5635
							{
5613
							{
5636
								auto node = wareLines.get(i);
5614
								auto node = wareLines.get(i);
5637
								addAfter.pushBack(node->str);
5615
								addAfter.pushBack(node->str);
5638
							}
5616
							}
5639
						}
5617
						}
5640
 
5618
 
Line 5644... Line 5622...
5644
					}
5622
					}
5645
					else if ( m_iGame == GAME_X3TC || m_iGame == GAME_X3AP || m_iGame == GAME_X3FL) // check if old emp is included, and convert it
5623
					else if ( m_iGame == GAME_X3TC || m_iGame == GAME_X3AP || m_iGame == GAME_X3FL) // check if old emp is included, and convert it
5646
					{
5624
					{
5647
						if ( wareLines.size() > 128 )
5625
						if ( wareLines.size() > 128 )
5648
						{
5626
						{
5649
							Utils::String test = wareLines.get(128)->str;
5627
							Utils::WString test = wareLines.get(128)->str;
5650
							if ( test.tokens(";", -2).Compare("SS_WARE_SW_CUSTOM16_1;") )
5628
							if ( test.tokens(L";", -2).Compare(L"SS_WARE_SW_CUSTOM16_1;") )
5651
							{
5629
							{
5652
								// if theres any at the end, remove the last emp entry
5630
								// if theres any at the end, remove the last emp entry
5653
								if ( wareLines.size() > (maxsize + empEntries - 1) )
5631
								if ( wareLines.size() > (maxsize + empEntries - 1) )
5654
								{
5632
								{
5655
									wareLines.removeAt(maxsize + empEntries - 2);
5633
									wareLines.removeAt(maxsize + empEntries - 2);
5656
								}
5634
								}
5657
								wareLines.insertAt(128, "0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;128;");
5635
								wareLines.insertAt(128, L"0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;128;");
5658
							}
5636
							}
5659
						}
5637
						}
5660
					}
5638
					}
5661
				}
5639
				}
5662
 
5640
 
5663
				// too many entries, need to remove the first set of EMP wares
5641
				// too many entries, need to remove the first set of EMP wares
5664
				int i = 0;
5642
				size_t i = 0;
5665
				if ( wareLines.size() > maxsize )
5643
				if ( wareLines.size() > maxsize )
5666
					i = wareLines.size() - maxsize;
5644
					i = wareLines.size() - maxsize;
5667
 
5645
 
5668
				for ( ; i < empEntries; i++ )
5646
				for ( ; i < empEntries; i++ )
5669
				{
5647
				{
5670
					Utils::String str = empStr[i];
5648
					Utils::WString str = empStr[i];
5671
					str.removeEndSpace();
5649
					str.removeEndSpace();
5672
					str.removeChar(9);
5650
					str.removeChar(9);
5673
					str.removeChar('\r');
5651
					str.removeChar('\r');
5674
					if ( str.empty() )
5652
					if ( str.empty() )
5675
						continue;
5653
						continue;
5676
					if ( str.right(1) != ";")
5654
					if ( str.right(1) != L";")
5677
						str += ";";
5655
						str += L";";
5678
					wareLines.pushBack(str);
5656
					wareLines.pushBack(str);
5679
				}
5657
				}
5680
 
5658
 
5681
				for(auto afterItr = addAfter.begin(); afterItr != addAfter.end(); afterItr++)
5659
				for(auto afterItr = addAfter.begin(); afterItr != addAfter.end(); afterItr++)
5682
					wareLines.pushBack((*afterItr)->str);
5660
					wareLines.pushBack((*afterItr)->str);
5683
 
5661
 
5684
				// finally we write the whole file
5662
				// finally we write the whole file
5685
				wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5663
				wareLines.pushFront(Utils::WString::Number(version) + ";" + Utils::WString::Number(wareLines.size()) + L";", Utils::WString::Null());
5686
				wareLines.pushFront("// Created by SPKInstaller Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2), Utils::String::Null());
5664
				wareLines.pushFront(L"// Created by SPKInstaller Libraries V" + Utils::WString::FromFloat(GetLibraryVersion(), 2), Utils::WString::Null());
5687
				if ( readFile.writeFile(&wareLines) )
5665
				if ( readFile.writeFile(&wareLines) )
5688
					this->packFile(&readFile, "types\\TWareT.pck");
5666
					this->packFile(&readFile, L"types\\TWareT.pck");
5689
			}
5667
			}
5690
			CLEANSPLIT(empStr, empEntries);
-
 
5691
		}
5668
		}
5692
	}
5669
	}
5693
}
5670
}
5694
 
5671
 
5695
Utils::String parseXmlText(const Utils::String &str)
5672
Utils::WString parseXmlText(const Utils::WString &str)
5696
{
5673
{
5697
	Utils::String newStr(str);
5674
	Utils::WString newStr(str);
5698
	Utils::CStringList changes;
5675
	Utils::WStringList changes;
5699
 
5676
 
5700
	// find all XML commands, &<command>;
5677
	// find all XML commands, &<command>;
5701
	Utils::String sStr = str;
5678
	Utils::WString sStr = str;
5702
	Utils::String::size_type pos = sStr.find_first_of("&", 0);
5679
	Utils::WString::size_type pos = sStr.find_first_of(L"&", 0);
5703
	while ( pos != Utils::String::npos ) {
5680
	while ( pos != Utils::WString::npos ) {
5704
		// find the next space and next ;.  If ; comes first, assume its acommand
5681
		// find the next space and next ;.  If ; comes first, assume its acommand
5705
		Utils::String::size_type spacePos = sStr.find_first_of(" ", pos);
5682
		Utils::WString::size_type spacePos = sStr.find_first_of(L" ", pos);
5706
		Utils::String::size_type colonPos = sStr.find_first_of(";", pos);
5683
		Utils::WString::size_type colonPos = sStr.find_first_of(L";", pos);
5707
		if ( colonPos != Utils::String::npos && colonPos < spacePos ) {
5684
		if ( colonPos != Utils::WString::npos && colonPos < spacePos ) {
5708
			// replace with <::command::> so they the & doesn't get replaced
5685
			// replace with <::command::> so they the & doesn't get replaced
5709
			Utils::String repStr = sStr.substr(pos, (colonPos + 1) - pos);
5686
			Utils::WString repStr = sStr.substr(pos, (colonPos + 1) - pos);
5710
			Utils::String repWithStr = "<::" + sStr.substr(pos + 1, colonPos - pos - 1) + "::>";
5687
			Utils::WString repWithStr = L"<::" + sStr.substr(pos + 1, colonPos - pos - 1) + L"::>";
5711
			newStr = newStr.findReplace(repStr, repWithStr);
5688
			newStr = newStr.findReplace(repStr, repWithStr);
5712
			changes.pushBack(repStr, repWithStr);
5689
			changes.pushBack(repStr, repWithStr);
5713
		}
5690
		}
5714
 
5691
 
5715
		// find the next command
5692
		// find the next command
5716
		pos = sStr.find_first_of("&", pos + 1);
5693
		pos = sStr.find_first_of(L"&", pos + 1);
5717
	}
5694
	}
5718
 
5695
 
5719
	// replace the & now
5696
	// replace the & now
5720
	newStr = newStr.findReplace("&", "&amp;");
5697
	newStr = newStr.findReplace(L"&", L"&amp;");
5721
 
5698
 
5722
	// restore the commands
5699
	// restore the commands
5723
	for(auto itr = changes.begin(); itr != changes.end(); itr++)
5700
	for(auto itr = changes.begin(); itr != changes.end(); itr++)
5724
		newStr = newStr.findReplace((*itr)->data, (*itr)->str);
5701
		newStr = newStr.findReplace((*itr)->data, (*itr)->str);
5725
 
5702
 
5726
	return newStr;
5703
	return newStr;
5727
}
5704
}
5728
 
5705
 
5729
Utils::String CPackages::ConvertTextString(const Utils::String &sText)
5706
Utils::WString CPackages::convertTextString(const Utils::WString &sText)
5730
{
5707
{
5731
	//process any &
5708
	//process any &
5732
	Utils::String text = parseXmlText(sText);
5709
	Utils::WString text = parseXmlText(sText);
5733
 
5710
 
5734
	// change special cases
5711
	// change special cases
5735
	text = text.findReplace("(", "\\(");
5712
	text = text.findReplace(L"(", L"\\(");
5736
	text = text.findReplace(")", "\\)");
5713
	text = text.findReplace(L")", L"\\)");
5737
	text = text.findReplace("[", "{");
5714
	text = text.findReplace(L"[", L"{");
5738
	text = text.findReplace("]", "}");
5715
	text = text.findReplace(L"]", L"}");
5739
	text = text.findReplace(">", "&gt;");
5716
	text = text.findReplace(L">", L"&gt;");
5740
	text = text.findReplace("<", "&lt;");
5717
	text = text.findReplace(L"<", L"&lt;");
5741
	return text;
5718
	return text;
5742
}
5719
}
5743
 
5720
 
5744
int CPackages::_gameTextNumber() const
5721
int CPackages::_gameTextNumber() const
5745
{
5722
{
5746
	int gameNumber = (m_pCurrentGameExe) ? m_pCurrentGameExe->iTextNum : -1;
5723
	int gameNumber = (m_pCurrentGameExe) ? m_pCurrentGameExe->iTextNum : -1;
5747
	if ( gameNumber != -1 ) return gameNumber;
5724
	if ( gameNumber != -1 ) return gameNumber;
5748
 
5725
 
5749
	switch(m_iGame) {
5726
	switch(m_iGame) {
5750
		case GAME_X3: return 30;
5727
		case GAME_X3: return 30;
Line 5753... Line 5730...
5753
		case GAME_X3FL: return 39;
5730
		case GAME_X3FL: return 39;
5754
		default: return 0;
5731
		default: return 0;
5755
	}
5732
	}
5756
}
5733
}
5757
 
5734
 
5758
void CPackages::createPluginManagerOpenText()
5735
void CPackages::createPluginManagerOpenText()
5759
{
-
 
5760
	int gameNumber = _gameTextNumber();
-
 
5761
 
-
 
5762
	int lang = m_iLanguage;
-
 
5763
	if ( !lang || lang < 0 )
-
 
5764
		lang = 44;
-
 
5765
 
-
 
5766
	CDirIO Dir(m_sCurrentDir);
-
 
5767
	if ( !Dir.exists("t") )
-
 
5768
		Dir.create("t");
-
 
5769
 
-
 
5770
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
-
 
5771
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
-
 
5772
 
-
 
5773
	std::vector<Utils::String> writeData;
-
 
5774
 
-
 
5775
	writeData.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
-
 
5776
	writeData.push_back("<language id=\"" + Utils::String::Number(lang) + "\">");
-
 
5777
 
-
 
5778
	if ( !gameNumber )
-
 
5779
		writeData.push_back("	<page id=\"" + Utils::String::Number(PMTEXTFILE) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
-
 
5780
	else
-
 
5781
		writeData.push_back("	<page id=\"" + (long)gameNumber + Utils::String::PadNumber(PMTEXTFILE, 4) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
-
 
5782
 
-
 
5783
	writeData.push_back("		<t id=\"99998\">[author]Plugin Manager[/author]It appears the plugin manager hasn't been closed properly.  Make sure its closed before running the game otherwise things may not work correctly</t>");
-
 
5784
	writeData.push_back("		<t id=\"99999\">2</t>");	
-
 
5785
	writeData.push_back("	</page>");
-
 
5786
 
-
 
5787
	writeData.push_back("</language>");
-
 
5788
	textFile.writeFileUTF(&writeData);
-
 
5789
 
-
 
5790
	size_t fileSize;
-
 
5791
	char *fileData = CFileIO(textFile.fullFilename()).ReadToData(&fileSize);
-
 
5792
 
-
 
5793
	if ( fileData && fileSize)
-
 
5794
	{
-
 
5795
		size_t newFileSize;
-
 
5796
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
-
 
5797
		if ( pckData )
-
 
5798
		{
-
 
5799
			CFileIO pckFile(m_sCurrentDir + "/t/" + filename + ".pck");
-
 
5800
			pckFile.WriteData((char *)pckData, newFileSize);
-
 
5801
			this->addCreatedFile(pckFile.fullFilenameStr());
-
 
5802
		}
-
 
5803
	}
-
 
5804
	textFile.remove();
-
 
5805
}
-
 
5806
 
-
 
5807
void CPackages::CreatePluginManagerText()
-
 
5808
{
5736
{
5809
	int gameNumber = _gameTextNumber();
5737
	int gameNumber = _gameTextNumber();
5810
 
5738
 
5811
	int lang = m_iLanguage;
5739
	int lang = m_iLanguage;
5812
	if ( !lang || lang < 0 )
5740
	if ( !lang || lang < 0 )
5813
		lang = 44;
5741
		lang = 44;
5814
 
5742
 
5815
	CDirIO Dir(m_sCurrentDir);
5743
	CDirIO Dir(m_sCurrentDir);
5816
	if ( !Dir.exists("t") )
5744
	if ( !Dir.exists("t") )
5817
		Dir.create("t");
5745
		Dir.create("t");
-
 
5746
 
-
 
5747
	Utils::WString filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
-
 
5748
	CFileIO textFile(m_sCurrentDir + L"/t/" + filename + L".xml");
-
 
5749
 
-
 
5750
	std::vector<Utils::WString> writeData;
-
 
5751
 
-
 
5752
	writeData.push_back(L"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
-
 
5753
	writeData.push_back(L"<language id=\"" + Utils::WString::Number(lang) + L"\">");
-
 
5754
 
-
 
5755
	if ( !gameNumber )
-
 
5756
		writeData.push_back(L"	<page id=\"" + Utils::WString::Number(PMTEXTFILE) + L"\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
-
 
5757
	else
-
 
5758
		writeData.push_back(L"	<page id=\"" + (long)gameNumber + Utils::WString::PadNumber(PMTEXTFILE, 4) + L"\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
-
 
5759
 
-
 
5760
	writeData.push_back(L"		<t id=\"99998\">[author]Plugin Manager[/author]It appears the plugin manager hasn't been closed properly.  Make sure its closed before running the game otherwise things may not work correctly</t>");
-
 
5761
	writeData.push_back(L"		<t id=\"99999\">2</t>");	
-
 
5762
	writeData.push_back(L"	</page>");
-
 
5763
 
-
 
5764
	writeData.push_back(L"</language>");
-
 
5765
	textFile.writeFileUTF(&writeData);
-
 
5766
 
-
 
5767
	size_t fileSize;
-
 
5768
	char *fileData = CFileIO(textFile.fullFilename()).ReadToData(&fileSize);
-
 
5769
 
-
 
5770
	if ( fileData && fileSize)
-
 
5771
	{
-
 
5772
		size_t newFileSize;
-
 
5773
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
-
 
5774
		if ( pckData )
-
 
5775
		{
-
 
5776
			CFileIO pckFile(m_sCurrentDir + L"/t/" + filename + L".pck");
-
 
5777
			pckFile.WriteData((char *)pckData, newFileSize);
-
 
5778
			this->addCreatedFile(pckFile.fullFilenameStr());
-
 
5779
		}
-
 
5780
	}
-
 
5781
	textFile.remove();
-
 
5782
}
-
 
5783
 
-
 
5784
void CPackages::CreatePluginManagerText()
-
 
5785
{
-
 
5786
	int gameNumber = _gameTextNumber();
-
 
5787
 
-
 
5788
	int lang = m_iLanguage;
-
 
5789
	if ( !lang || lang < 0 )
-
 
5790
		lang = 44;
-
 
5791
 
-
 
5792
	CDirIO Dir(m_sCurrentDir);
-
 
5793
	if ( !Dir.exists(L"t") )
-
 
5794
		Dir.create(L"t");
5818
 
5795
 
5819
	m_iLastUpdated = (int)time(NULL);
5796
	m_iLastUpdated = (int)time(NULL);
5820
 
5797
 
5821
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5798
	Utils::WString filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5822
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5799
	CFileIO textFile(m_sCurrentDir + L"/t/" + filename + L".xml");
5823
 
5800
 
5824
	std::vector<Utils::String> writeData;
5801
	std::vector<Utils::WString> writeData;
5825
 
5802
 
5826
	CLinkList<SGameWare> lWares;
5803
	CLinkList<SGameWare> lWares;
5827
	CLinkList<SGameShip> lShips;
5804
	CLinkList<SGameShip> lShips;
5828
	for ( int i = 0; i < WAREBUFFERS; i++ )
5805
	for ( int i = 0; i < WAREBUFFERS; i++ )
5829
	{
5806
	{
Line 5840... Line 5817...
5840
		if ( node->Data()->iType == WARETYPE_NONE )
5817
		if ( node->Data()->iType == WARETYPE_NONE )
5841
			continue;
5818
			continue;
5842
		lShips.push_back(node->Data());
5819
		lShips.push_back(node->Data());
5843
	}
5820
	}
5844
 
5821
 
5845
	writeData.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
5822
	writeData.push_back(L"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
5846
	writeData.push_back("<language id=\"" + Utils::String::Number(lang) + "\">");
5823
	writeData.push_back(L"<language id=\"" + Utils::WString::Number(lang) + "\">");
5847
 
5824
 
5848
	if ( !gameNumber )
5825
	if ( !gameNumber )
5849
		writeData.push_back("	<page id=\"" + Utils::String::Number(PMTEXTFILE) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5826
		writeData.push_back(L"	<page id=\"" + Utils::WString::Number(PMTEXTFILE) + L"\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5850
	else
5827
	else
5851
		writeData.push_back("	<page id=\"" + Utils::String::Number(gameNumber) + Utils::String::PadNumber(PMTEXTFILE, 4) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5828
		writeData.push_back(L"	<page id=\"" + Utils::WString::Number(gameNumber) + Utils::WString::PadNumber(PMTEXTFILE, 4) + L"\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5852
 
5829
 
5853
	// write the heading
5830
	// write the heading
5854
	int start = 10000;
5831
	int start = 10000;
5855
	writeData.push_back("		<t id=\"1\">" + Utils::String::Number(m_iLastUpdated) + "</t>");
5832
	writeData.push_back(L"		<t id=\"1\">" + Utils::WString::Number(m_iLastUpdated) + L"</t>");
5856
	writeData.push_back("		<t id=\"2\">" + Utils::String::Number(this->countPackages(TYPE_SPK, true)) + "</t>");
5833
	writeData.push_back(L"		<t id=\"2\">" + Utils::WString::Number(this->countPackages(TYPE_SPK, true)) + L"</t>");
5857
	writeData.push_back("		<t id=\"3\">" + Utils::String::Number(start) + "</t>");
5834
	writeData.push_back(L"		<t id=\"3\">" + Utils::WString::Number(start) + L"</t>");
5858
	writeData.push_back("		<t id=\"4\">" + Utils::String::Number(lWares.size()) + "</t>");
5835
	writeData.push_back(L"		<t id=\"4\">" + Utils::WString::Number(lWares.size()) + L"</t>");
5859
	writeData.push_back("		<t id=\"6\">" + Utils::String::Number(lShips.size()) + "</t>");
5836
	writeData.push_back(L"		<t id=\"6\">" + Utils::WString::Number(lShips.size()) + L"</t>");
5860
 
5837
 
5861
	// write some generic texts
5838
	// write some generic texts
5862
	writeData.push_back("		<t id=\"110\">" + Utils::String::Number((long)m_iLanguage) + "</t>");
5839
	writeData.push_back(L"		<t id=\"110\">" + Utils::WString::Number((long)m_iLanguage) + L"</t>");
5863
	writeData.push_back("		<t id=\"109\">Plugin Manager: \\033GPoll Gui Data\\033X</t>");
5840
	writeData.push_back(L"		<t id=\"109\">Plugin Manager: \\033GPoll Gui Data\\033X</t>");
5864
	writeData.push_back("		<t id=\"107\">Plugin Manager: \\033GExport Game Data\\033X </t>");
5841
	writeData.push_back(L"		<t id=\"107\">Plugin Manager: \\033GExport Game Data\\033X </t>");
5865
	writeData.push_back("		<t id=\"100\">\\n</t>");
5842
	writeData.push_back(L"		<t id=\"100\">\\n</t>");
5866
	writeData.push_back("		<t id=\"101\">\\033B</t>");
5843
	writeData.push_back(L"		<t id=\"101\">\\033B</t>");
5867
	writeData.push_back("		<t id=\"102\">\\033G</t>");
5844
	writeData.push_back(L"		<t id=\"102\">\\033G</t>");
5868
	writeData.push_back("		<t id = \"103\">\\033B</t>");
5845
	writeData.push_back(L"		<t id = \"103\">\\033B</t>");
5869
	writeData.push_back("		<t id=\"104\">\\033X</t>");
5846
	writeData.push_back(L"		<t id=\"104\">\\033X</t>");
5870
	writeData.push_back("		<t id=\"105\">\\033Y</t>");
5847
	writeData.push_back(L"		<t id=\"105\">\\033Y</t>");
5871
	writeData.push_back("		<t id=\"106\">\\033C</t>");
5848
	writeData.push_back(L"		<t id=\"106\">\\033C</t>");
5872
	writeData.push_back("		<t id=\"108\">\\033</t>");
5849
	writeData.push_back(L"		<t id=\"108\">\\033</t>");
5873
 
5850
 
5874
	writeData.push_back("		<t id=\"99998\">[author]Plugin Manager[/author]It appears the plugin manager hasn't been closed properly.  Make sure its closed before running the game otherwise things may not work correctly</t>");
5851
	writeData.push_back(L"		<t id=\"99998\">[author]Plugin Manager[/author]It appears the plugin manager hasn't been closed properly.  Make sure its closed before running the game otherwise things may not work correctly</t>");
5875
	writeData.push_back("		<t id=\"99999\">1</t>");
5852
	writeData.push_back(L"		<t id=\"99999\">1</t>");
5876
	// now write each package
5853
	// now write each package
5877
	int settingStart = 100000;
5854
	int settingStart = 100000;
5878
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5855
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5879
	{
5856
	{
5880
		CBaseFile *p = node->Data();
5857
		CBaseFile *p = node->Data();
Line 5885... Line 5862...
5885
			continue;
5862
			continue;
5886
 
5863
 
5887
		CSpkFile *spk = (CSpkFile *)p;
5864
		CSpkFile *spk = (CSpkFile *)p;
5888
 
5865
 
5889
		// count text files
5866
		// count text files
5890
		Utils::String textEntries;
5867
		Utils::WString textEntries;
5891
		int textCount = 0;
5868
		int textCount = 0;
5892
		C_File *f = p->GetFirstFile(FILETYPE_TEXT);
5869
		C_File *f = p->GetFirstFile(FILETYPE_TEXT);
5893
		while ( f )
5870
		while ( f )
5894
		{
5871
		{
5895
			Utils::String sLang;
5872
			Utils::WString sLang;
5896
			Utils::String id;
5873
			Utils::WString id;
5897
			if ( m_iGameFlags & EXEFLAG_TCTEXT )
5874
			if ( m_iGameFlags & EXEFLAG_TCTEXT )
5898
			{
5875
			{
5899
				id = f->baseName().token("-", 1);
5876
				id = f->baseName().token(L"-", 1);
5900
				sLang = f->baseName().token("-", 2);
5877
				sLang = f->baseName().token(L"-", 2);
5901
				if ( sLang.empty() )
5878
				if ( sLang.empty() )
5902
					sLang = "NULL";
5879
					sLang = L"NULL";
5903
				else
5880
				else
5904
					sLang = sLang.erase(0, 1);  // remove the "L"
5881
					sLang = sLang.erase(0, 1);  // remove the "L"
5905
			}
5882
			}
5906
			else
5883
			else
5907
			{
5884
			{
5908
				sLang = f->baseName().left((int)f->baseName().length() - 4).padNumber(3);
5885
				sLang = f->baseName().left((int)f->baseName().length() - 4).padNumber(3);
5909
				id = f->baseName().mid(((int)f->baseName().length() - 4) + 1, 4);
5886
				id = f->baseName().mid(((int)f->baseName().length() - 4) + 1, 4);
5910
			}
5887
			}
5911
 
5888
 
5912
			if ( sLang != "NULL" )
5889
			if ( sLang != L"NULL" )
5913
			{
5890
			{
5914
				if ( sLang.toInt() == lang )
5891
				if ( sLang.toInt() == lang )
5915
				{
5892
				{
5916
					++textCount;
5893
					++textCount;
5917
					if ( !textEntries.empty() )
5894
					if ( !textEntries.empty() )
5918
						textEntries += " ";
5895
						textEntries += L" ";
5919
					textEntries += id;
5896
					textEntries += id;
5920
				}
5897
				}
5921
			}
5898
			}
5922
			f = p->GetNextFile(f);
5899
			f = p->GetNextFile(f);
5923
		}
5900
		}
5924
 
5901
 
5925
		Utils::String sTextCount((long)textCount);
5902
		Utils::WString sTextCount((long)textCount);
5926
		writeData.push_back("		<t id=\"" + Utils::String::Number((long)start) + "\">" + this->ConvertTextString(p->name()) + "</t>");
5903
		writeData.push_back(L"		<t id=\"" + Utils::WString::Number((long)start) + L"\">" + this->convertTextString(p->name()) + L"</t>");
5927
		writeData.push_back("		<t id=\"" + Utils::String::Number((long)(start + 1)) + "\">" + this->ConvertTextString(p->author()) + "</t>");
5904
		writeData.push_back(L"		<t id=\"" + Utils::WString::Number((long)(start + 1)) + L"\">" + this->convertTextString(p->author()) + L"</t>");
5928
		writeData.push_back("		<t id=\"" + Utils::String::Number((long)(start + 2)) + "\">" + this->ConvertTextString(p->version()) + "</t>");
5905
		writeData.push_back(L"		<t id=\"" + Utils::WString::Number((long)(start + 2)) + L"\">" + this->convertTextString(p->version()) + L"</t>");
5929
		writeData.push_back("		<t id=\"" + Utils::String::Number((long)(start + 3)) + "\">" + this->ConvertTextString(p->name(lang)) + "</t>");
5906
		writeData.push_back(L"		<t id=\"" + Utils::WString::Number((long)(start + 3)) + L"\">" + this->convertTextString(p->name(lang)) + L"</t>");
5930
 
5907
 
5931
		CLinkList<SSettingType> *settings = spk->GetSettingsList();
5908
		CLinkList<SSettingType> *settings = spk->GetSettingsList();
5932
		if ( settings && settings->size() )
5909
		if ( settings && settings->size() )
5933
		{
5910
		{
5934
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 4) + "\">" + (long)settings->size() + "</t>");
5911
			writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(start + 4) + L"\">" + (long)settings->size() + L"</t>");
5935
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 5) + "\">" + (long)settingStart + "</t>");
5912
			writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(start + 5) + L"\">" + (long)settingStart + L"</t>");
5936
 
5913
 
5937
			for ( CListNode<SSettingType> *sNode = settings->Front(); sNode; sNode = sNode->next() )
5914
			for ( CListNode<SSettingType> *sNode = settings->Front(); sNode; sNode = sNode->next() )
5938
			{
5915
			{
5939
				SSettingType *st = sNode->Data();
5916
				SSettingType *st = sNode->Data();
5940
				writeData.push_back(Utils::String("		<t id=\"") + (long)(settingStart++) + "\">" + st->sKey + "</t>");
5917
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(settingStart++) + L"\">" + st->sKey.toWString() + L"</t>");
5941
				writeData.push_back(Utils::String("		<t id=\"") + (long)(settingStart++) + "\">" + spk->GetSetting(st) + "</t>");
5918
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(settingStart++) + L"\">" + spk->GetSetting(st).toWString() + L"</t>");
5942
			}
5919
			}
5943
		}
5920
		}
5944
		else
5921
		else
5945
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 4) + "\">0</t>");
5922
			writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(start + 4) + L"\">0</t>");
5946
 
5923
 
5947
		writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 6) + "\">" + sTextCount + "</t>");
5924
		writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(start + 6) + L"\">" + sTextCount + L"</t>");
5948
		if ( textCount )
5925
		if ( textCount )
5949
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 7) + "\">" + textEntries + "</t>");
5926
			writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(start + 7) + L"\">" + textEntries + L"</t>");
5950
 
5927
 
5951
		start += 10;
5928
		start += 10;
5952
	}
5929
	}
5953
 
5930
 
5954
	// write ware names
5931
	// write ware names
5955
	if ( lWares.size() )
5932
	if ( lWares.size() )
5956
	{
5933
	{
5957
		writeData.push_back("		<t id=\"5\">" + Utils::String::Number(start) + "</t>");
5934
		writeData.push_back(L"		<t id=\"5\">" + Utils::WString::Number(start) + L"</t>");
5958
		for ( CListNode<SGameWare> *node = lWares.Front(); node; node = node->next() )
5935
		for ( CListNode<SGameWare> *node = lWares.Front(); node; node = node->next() )
5959
		{
5936
		{
5960
			SGameWare *w = node->Data();
5937
			SGameWare *w = node->Data();
5961
			if ( w->pWare && w->iType == WARETYPE_ADDED )
5938
			if ( w->pWare && w->iType == WARETYPE_ADDED )
5962
				writeData.push_back(Utils::String("		<t id=\"") + (long)start + "\">" + this->ConvertTextString(w->sWareName) + "</t>");
5939
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)start + L"\">" + this->convertTextString(w->sWareName) + L"</t>");
5963
			else
5940
			else
5964
				writeData.push_back(Utils::String("		<t id=\"") + (long)start + "\">-1</t>");
5941
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)start + L"\">-1</t>");
5965
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 1) + "\">" + Utils::String((char)w->cType) + "</t>");
5942
			writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(start + 1) + L"\">" + Utils::WString(w->cType) + L"</t>");
5966
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 2) + "\">" + (long)w->iPos + "</t>");
5943
			writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(start + 2) + L"\">" + (long)w->iPos + L"</t>");
5967
			start += 10;
5944
			start += 10;
5968
		}
5945
		}
5969
	}
5946
	}
5970
 
5947
 
5971
	if ( lShips.size() )
5948
	if ( lShips.size() )
5972
	{
5949
	{
5973
		writeData.push_back("		<t id=\"7\">" + Utils::String::Number(start) + "</t>");
5950
		writeData.push_back(L"		<t id=\"7\">" + Utils::WString::Number(start) + L"</t>");
5974
		for ( CListNode<SGameShip> *node = lShips.Front(); node; node = node->next() )
5951
		for ( CListNode<SGameShip> *node = lShips.Front(); node; node = node->next() )
5975
		{
5952
		{
5976
			SGameShip *gs = node->Data();
5953
			SGameShip *gs = node->Data();
5977
			if ( gs->iType == WARETYPE_NONE )
5954
			if ( gs->iType == WARETYPE_NONE )
5978
				continue;
5955
				continue;
5979
			if ( gs->pPackage && gs->iType == WARETYPE_ADDED )
5956
			if ( gs->pPackage && gs->iType == WARETYPE_ADDED )
5980
				writeData.push_back(Utils::String("		<t id=\"") + (long)start + "\">" + gs->sShipID + "</t>");
5957
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)start + L"\">" + gs->sShipID + L"</t>");
5981
			else
5958
			else
5982
				writeData.push_back(Utils::String("		<t id=\"") + (long)start + "\">-1</t>");
5959
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)start + L"\">-1</t>");
5983
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 1) + "\">" + (long)gs->iPos + "</t>");
5960
			writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(start + 1) + L"\">" + (long)gs->iPos + L"</t>");
5984
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 2) + "\">Ship</t>");
5961
			writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(start + 2) + L"\">Ship</t>");
5985
 
5962
 
5986
			// write shipyard info
5963
			// write shipyard info
5987
			if ( gs->pPackage )
5964
			if ( gs->pPackage )
5988
			{
5965
			{
5989
				int doStart = start + 5;
5966
				int doStart = start + 5;
5990
				for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
5967
				for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
5991
				{
5968
				{
5992
					writeData.push_back(Utils::String("		<t id=\"") + (long)(doStart) + "\">" + ((gs->pPackage->IsShipyard(i)) ? Utils::String::Number(1) : Utils::String::Number(0)) + "</t>");
5969
					writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(doStart) + L"\">" + ((gs->pPackage->IsShipyard(i)) ? Utils::WString::Number(1) : Utils::WString::Number(0)) + L"</t>");
5993
					++doStart;
5970
					++doStart;
5994
				}
5971
				}
5995
			}
5972
			}
5996
 
5973
 
5997
			start += 20;
5974
			start += 20;
5998
		}
5975
		}
5999
	}
5976
	}
6000
 
5977
 
6001
	writeData.push_back("	</page>");
5978
	writeData.push_back(L"	</page>");
6002
 
5979
 
6003
	// do emp
5980
	// do emp
6004
	if (m_iGame == GAME_X3TC || m_iGame == GAME_X3 || m_iGame == GAME_X3AP || m_iGame == GAME_X3FL)
5981
	if (m_iGame == GAME_X3TC || m_iGame == GAME_X3 || m_iGame == GAME_X3AP || m_iGame == GAME_X3FL)
6005
	{
5982
	{
6006
		writeData.push_back("  <page id=\"17\" title=\"Plugin Manager Objects\">");
5983
		writeData.push_back(L"  <page id=\"17\" title=\"Plugin Manager Objects\">");
6007
		writeData.push_back(GetEMPText());
5984
		writeData.push_back(GetEMPText());
6008
		writeData.push_back("  </page>");
5985
		writeData.push_back(L"  </page>");
6009
	}
5986
	}
6010
 
5987
 
6011
	// wares
5988
	// wares
6012
	if ( m_iGame == GAME_X3AP || m_iGame == GAME_X3TC || m_iGame == GAME_X3FL || m_iGame == GAME_X3 || lWares.size() || lShips.size() )
5989
	if ( m_iGame == GAME_X3AP || m_iGame == GAME_X3TC || m_iGame == GAME_X3FL || m_iGame == GAME_X3 || lWares.size() || lShips.size() )
6013
	{
5990
	{
6014
 
5991
 
6015
		if ( !gameNumber )
5992
		if ( !gameNumber )
6016
			writeData.push_back("  <page id=\"17\" title=\"Plugin Manager Objects\">");
5993
			writeData.push_back(L"  <page id=\"17\" title=\"Plugin Manager Objects\">");
6017
		else
5994
		else
6018
			writeData.push_back(Utils::String("  <page id=\"") + (long)gameNumber + "0017\" title=\"Plugin Manager Objects\">");
5995
			writeData.push_back(Utils::WString(L"  <page id=\"") + (long)gameNumber + L"0017\" title=\"Plugin Manager Objects\">");
6019
 
5996
 
6020
		writeData.push_back(Utils::String("		<t id=\"") + (long)(SHIPSTARTTEXT - 1) + "\">ZZ_BLANKSHIP</t>");
5997
		writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(SHIPSTARTTEXT - 1) + L"\">ZZ_BLANKSHIP</t>");
6021
 
5998
 
6022
		// object names
5999
		// object names
6023
		for ( CListNode<SGameWare> *node = lWares.Front(); node; node = node->next() )
6000
		for ( CListNode<SGameWare> *node = lWares.Front(); node; node = node->next() )
6024
		{
6001
		{
6025
			SGameWare *w = node->Data();
6002
			SGameWare *w = node->Data();
6026
			if ( !w->pWare || w->iType != WARETYPE_ADDED )
6003
			if ( !w->pWare || w->iType != WARETYPE_ADDED )
6027
				continue;
6004
				continue;
6028
 
6005
 
6029
			// find the correct text for the language
6006
			// find the correct text for the language
6030
			Utils::String name = CSpkFile::GetWareText(w->pWare, m_iLanguage);
6007
			Utils::WString name = CSpkFile::GetWareText(w->pWare, m_iLanguage);
6031
			Utils::String desc = CSpkFile::GetWareDesc(w->pWare, m_iLanguage);
6008
			Utils::WString desc = CSpkFile::GetWareDesc(w->pWare, m_iLanguage);
6032
			if ( !name.empty() )
6009
			if ( !name.empty() )
6033
				writeData.push_back(Utils::String("		<t id=\"") + (long)(w->iText + 3) + "\">" + this->ConvertTextString(name) + "</t>");
6010
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(w->iText + 3) + L"\">" + this->convertTextString(name) + L"</t>");
6034
			if ( !desc.empty() )
6011
			if ( !desc.empty() )
6035
				writeData.push_back(Utils::String("		<t id=\"") + (long)(w->iText + 4) + "\">" + this->ConvertTextString(desc) + "</t>");
6012
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(w->iText + 4) + L"\">" + this->convertTextString(desc) + L"</t>");
6036
		}
6013
		}
6037
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6014
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6038
		{
6015
		{
6039
			SGameShip *s = node->Data();
6016
			SGameShip *s = node->Data();
6040
			if ( !s->pPackage || s->iType != WARETYPE_ADDED )
6017
			if ( !s->pPackage || s->iType != WARETYPE_ADDED )
6041
				continue;
6018
				continue;
6042
			if ( s->pPackage->GetOriginalDescription() )
6019
			if ( s->pPackage->GetOriginalDescription() )
6043
				continue;
6020
				continue;
6044
 
6021
 
6045
			Utils::String name = s->pPackage->GetTextName(m_iLanguage);
6022
			Utils::WString name = s->pPackage->GetTextName(m_iLanguage);
6046
			Utils::String desc = s->pPackage->GetTextDescription(m_iLanguage);
6023
			Utils::WString desc = s->pPackage->GetTextDescription(m_iLanguage);
6047
			if ( !name.empty() )
6024
			if ( !name.empty() )
6048
				writeData.push_back(Utils::String("		<t id=\"") + (long)s->iText + "\">" + this->ConvertTextString(name) + "</t>");
6025
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)s->iText + L"\">" + this->convertTextString(name) + L"</t>");
6049
			if ( !desc.empty() )
6026
			if ( !desc.empty() )
6050
				writeData.push_back(Utils::String("		<t id=\"") + (long)(s->iText + 1) + "\">" + this->ConvertTextString(desc) + "</t>");
6027
				writeData.push_back(Utils::WString(L"		<t id=\"") + (long)(s->iText + 1) + L"\">" + this->convertTextString(desc) + L"</t>");
6051
		}
6028
		}
6052
		writeData.push_back("  </page>");
6029
		writeData.push_back(L"  </page>");
6053
	}
6030
	}
6054
	writeData.push_back("</language>");
6031
	writeData.push_back(L"</language>");
6055
	textFile.writeFileUTF(&writeData);
6032
	textFile.writeFileUTF(&writeData);
6056
 
6033
 
6057
	size_t fileSize;
6034
	size_t fileSize;
6058
	char *fileData = CFileIO(textFile.fullFilename()).ReadToData(&fileSize);
6035
	char *fileData = CFileIO(textFile.fullFilename()).ReadToData(&fileSize);
6059
 
6036
 
Line 6061... Line 6038...
6061
	{
6038
	{
6062
		size_t newFileSize;
6039
		size_t newFileSize;
6063
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
6040
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
6064
		if ( pckData )
6041
		if ( pckData )
6065
		{
6042
		{
6066
			CFileIO pckFile(m_sCurrentDir + "/t/" + filename + ".pck");
6043
			CFileIO pckFile(m_sCurrentDir + L"/t/" + filename + L".pck");
6067
			pckFile.WriteData((char *)pckData, newFileSize);
6044
			pckFile.WriteData((char *)pckData, newFileSize);
6068
			this->addCreatedFile(pckFile.fullFilenameStr());
6045
			this->addCreatedFile(pckFile.fullFilenameStr());
6069
		}
6046
		}
6070
	}
6047
	}
6071
	textFile.remove();
6048
	textFile.remove();
6072
}
6049
}
6073
 
6050
 
6074
bool CPackages::isCurrentDir(const Utils::String &dir) const
6051
bool CPackages::isCurrentDir(const Utils::WString &dir) const
6075
{
6052
{
6076
	Utils::String cur = m_sCurrentDir;
6053
	Utils::WString cur = m_sCurrentDir;
6077
 
6054
 
6078
	if ( dir.Compare(cur) )
6055
	if ( dir.Compare(cur) )
6079
		return true;
6056
		return true;
6080
 
6057
 
6081
	Utils::String checkDir = cur;
6058
	Utils::WString checkDir = cur;
6082
	checkDir = checkDir.findReplace("/", "\\");
6059
	checkDir = checkDir.findReplace(L"/", L"\\");
6083
	if ( checkDir.Compare(dir) )
6060
	if ( checkDir.Compare(dir) )
6084
		return true;
6061
		return true;
6085
 
6062
 
6086
	checkDir = checkDir.findReplace("\\", "/");
6063
	checkDir = checkDir.findReplace(L"\\", L"/");
6087
	if ( checkDir.Compare(dir) )
6064
	if ( checkDir.Compare(dir) )
6088
		return true;
6065
		return true;
6089
 
6066
 
6090
	return false;
6067
	return false;
6091
}
6068
}
Line 6106... Line 6083...
6106
		if (!gameSaveDir.exists(dir))
6083
		if (!gameSaveDir.exists(dir))
6107
			gameSaveDir.create(dir);
6084
			gameSaveDir.create(dir);
6108
		gameSaveDir.cd(dir);
6085
		gameSaveDir.cd(dir);
6109
 
6086
 
6110
		// backup the saves
6087
		// backup the saves
6111
		Utils::CStringList files;
6088
		Utils::WStringList files;
6112
		if(saveDir.dirList(files, Utils::String::Null(), L"*.sav"))
6089
		if(saveDir.dirList(files, Utils::WString::Null(), L"*.sav"))
6113
		{
6090
		{
6114
			for(auto itr = files.begin(); itr != files.end(); ++itr)
6091
			for(auto itr = files.begin(); itr != files.end(); ++itr)
6115
			{
6092
			{
6116
				CFileIO File(saveDir.file((*itr)->str));
6093
				CFileIO File(saveDir.file((*itr)->str));
6117
				if (!File.isFileExtension(L"sav"))
6094
				if (!File.isFileExtension(L"sav"))
Line 6155... Line 6132...
6155
				}
6132
				}
6156
			}
6133
			}
6157
			*/
6134
			*/
6158
 
6135
 
6159
			// now we copy of the backed up save games
6136
			// now we copy of the backed up save games
6160
			Utils::CStringList files;
6137
			Utils::WStringList files;
6161
			if(restoreDir.dirList(files, Utils::String::Null(), "*.sav"))
6138
			if(restoreDir.dirList(files, Utils::WString::Null(), L"*.sav"))
6162
			{
6139
			{
6163
				for(auto itr = files.begin(); itr != files.end(); itr++)
6140
				for(auto itr = files.begin(); itr != files.end(); itr++)
6164
				{
6141
				{
6165
					CFileIO File(restoreDir.file((*itr)->str));
6142
					CFileIO File(restoreDir.file((*itr)->str));
6166
					// remove the file if already exists
6143
					// remove the file if already exists
Line 6795... Line 6772...
6795
		Utils::String name = p->GetCustomStartName();
6772
		Utils::String name = p->GetCustomStartName();
6796
		if ( name.empty() )
6773
		if ( name.empty() )
6797
			continue;
6774
			continue;
6798
 
6775
 
6799
		// find if maps file exists
6776
		// find if maps file exists
6800
		Utils::CStringList createFiles;
6777
		Utils::WStringList createFiles;
6801
		createFiles.pushBack(name, "maps/x3_universe");
6778
		createFiles.pushBack(name, L"maps/x3_universe");
6802
		createFiles.pushBack(name, "types/Jobs");
6779
		createFiles.pushBack(name, L"types/Jobs");
6803
		createFiles.pushBack(name, "types/JobWings");
6780
		createFiles.pushBack(name, L"types/JobWings");
6804
 
6781
 
6805
		for(auto itr = createFiles.begin(); itr != createFiles.end(); itr++)
6782
		for(auto itr = createFiles.begin(); itr != createFiles.end(); itr++)
6806
		{
6783
		{
6807
			Utils::WString dir = CFileIO((*itr)->data).dir();
6784
			Utils::WString dir = CFileIO((*itr)->data).dir();
6808
			FileType type = FileType::FILETYPE_EXTRA;
6785
			FileType type = FileType::FILETYPE_EXTRA;
6809
			if ( dir.Compare(L"maps") )
6786
			if ( dir.Compare(L"maps") )
6810
				type = FileType::FILETYPE_MAP;
6787
				type = FileType::FILETYPE_MAP;
6811
 
6788
 
6812
			if ( !p->findFile((*itr)->str + ".xml", type) && !p->findFile((*itr)->str + ".pck", type))
6789
			if ( !p->findFile((*itr)->str + L".xml", type) && !p->findFile((*itr)->str + L".pck", type))
6813
			{
6790
			{
6814
				// create a maps files
6791
				// create a maps files
6815
				int e = this->extractGameFile((*itr)->data + ".pck", m_sTempDir + "/" + (*itr)->data + ".pck");
6792
				int e = this->extractGameFile((*itr)->data + L".pck", m_sTempDir + L"/" + (*itr)->data + L".pck");
6816
				if ( e )
6793
				if ( e )
6817
				{
6794
				{
6818
					CFileIO File((e == -1) ? ((*itr)->data + ".pck") : (m_sTempDir + "/" + (*itr)->data + ".pck"));
6795
					CFileIO File((e == -1) ? ((*itr)->data + L".pck") : (m_sTempDir + L"/" + (*itr)->data + L".pck"));
6819
					if ( File.exists() )
6796
					if ( File.exists() )
6820
					{
6797
					{
6821
						File.Rename(m_sCurrentDir.toWString() + L"/" + dir + L";/&quot; + (*itr)->str.toWString() + L".pck");
6798
						File.Rename(m_sCurrentDir + L";/&quot; + dir + L"/"; + (*itr)->str + L".pck");
6822
						this->addCreatedFile(dir.toString() + "/" + (*itr)->str + ".pck");
6799
						this->addCreatedFile(dir + L"/" + (*itr)->str + L".pck");
6823
					}
6800
					}
6824
				}
6801
				}
6825
			}
6802
			}
6826
		}
6803
		}
6827
	}
6804
	}
6828
}
6805
}
6829
 
6806
 
6830
void CPackages::addCreatedFile(const Utils::String &sFile)
6807
void CPackages::addCreatedFile(const Utils::WString &sFile)
6831
{
6808
{
6832
	Utils::String file = sFile.findRemove(m_sCurrentDir);
6809
	Utils::WString file = sFile.findRemove(m_sCurrentDir);
6833
	while ( file[0] == '/' )
6810
	while ( file[0] == '/' )
6834
		file.erase(0, 1);
6811
		file.erase(0, 1);
6835
	while ( file[0] == '\\' )
6812
	while ( file[0] == '\\' )
6836
		file.erase(0, 1);
6813
		file.erase(0, 1);
6837
 
6814
 
6838
	if(!m_lCreatedFiles.contains(file, true))
6815
	if(!_lCreatedFiles.contains(file, true))
6839
		m_lCreatedFiles.pushBack(file);
6816
		_lCreatedFiles.pushBack(file);
6840
}
6817
}
6841
 
6818
 
6842
void CPackages::CreateComponants()
6819
void CPackages::CreateComponants()
6843
{
6820
{
6844
	// first check we have any ships
6821
	// first check we have any ships
Line 7046... Line 7023...
7046
 
7023
 
7047
bool CPackages::readWares(int iLang, CLinkList<SWareEntry> &list)
7024
bool CPackages::readWares(int iLang, CLinkList<SWareEntry> &list)
7048
{
7025
{
7049
	if ( iLang == 0 ) iLang = m_iLanguage;
7026
	if ( iLang == 0 ) iLang = m_iLanguage;
7050
 
7027
 
7051
	Utils::String empWares = this->empWaresForGame();
7028
	Utils::WString empWares = this->empWaresForGame();
7052
 
7029
 
7053
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
7030
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
7054
		if ( !node->Data()->IsEnabled() ) continue;
7031
		if ( !node->Data()->IsEnabled() ) continue;
7055
		node->Data()->readWares(iLang, list, empWares);
7032
		node->Data()->readWares(iLang, list, empWares);
7056
	}
7033
	}
Line 7080... Line 7057...
7080
	}
7057
	}
7081
 
7058
 
7082
	return true;
7059
	return true;
7083
}
7060
}
7084
 
7061
 
7085
int CPackages::_warePriceOverride(enum WareTypes type, int pos, const Utils::String &id)
7062
int CPackages::_warePriceOverride(enum WareTypes type, int pos, const Utils::WString &id)
7086
{
7063
{
7087
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7064
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7088
		if ( node->Data()->type == type ) {
7065
		if ( node->Data()->type == type ) {
7089
			if ( node->Data()->type == Ware_Custom && id.Compare(node->Data()->id) ) return node->Data()->relval;
7066
			if ( node->Data()->type == Ware_Custom && id.Compare(node->Data()->id) ) return node->Data()->relval;
7090
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos == pos ) return node->Data()->relval;
7067
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos == pos ) return node->Data()->relval;
7091
		}
7068
		}
7092
	}
7069
	}
7093
	return 0;
7070
	return 0;
7094
}
7071
}
7095
 
7072
 
7096
bool CPackages::_wareNotoOverride(enum WareTypes type, int pos, const Utils::String &id, int *noto)
7073
bool CPackages::_wareNotoOverride(enum WareTypes type, int pos, const Utils::WString &id, int *noto)
7097
{
7074
{
7098
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7075
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7099
		if ( node->Data()->type == type && node->Data()->bNotority ) {
7076
		if ( node->Data()->type == type && node->Data()->bNotority ) {
7100
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7077
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7101
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
7078
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
Line 7105... Line 7082...
7105
		}
7082
		}
7106
	}
7083
	}
7107
	return false;
7084
	return false;
7108
}
7085
}
7109
 
7086
 
7110
void CPackages::_removeWareOverride(enum WareTypes type, int pos, const Utils::String &id)
7087
void CPackages::_removeWareOverride(enum WareTypes type, int pos, const Utils::WString &id)
7111
{
7088
{
7112
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7089
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7113
		if ( node->Data()->type == type ) {
7090
		if ( node->Data()->type == type ) {
7114
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7091
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7115
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
7092
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
Line 7119... Line 7096...
7119
	}
7096
	}
7120
}
7097
}
7121
 
7098
 
7122
int CPackages::empOveridePrice(int id)
7099
int CPackages::empOveridePrice(int id)
7123
{
7100
{
7124
	return _warePriceOverride(Ware_EMP, id, Utils::String::Null()); 
7101
	return _warePriceOverride(Ware_EMP, id, Utils::WString::Null()); 
7125
}
7102
}
7126
 
7103
 
7127
bool CPackages::empOverideNoto(int id, int *noto)
7104
bool CPackages::empOverideNoto(int id, int *noto)
7128
{
7105
{
7129
	return _wareNotoOverride(Ware_EMP, id, Utils::String::Null(), noto);
7106
	return _wareNotoOverride(Ware_EMP, id, Utils::WString::Null(), noto);
7130
}
7107
}
7131
 
7108
 
7132
int CPackages::builtInWareOveridePrice(int id)
7109
int CPackages::builtInWareOveridePrice(int id)
7133
{
7110
{
7134
	return _warePriceOverride(Ware_BuiltIn, id, Utils::String::Null()); 
7111
	return _warePriceOverride(Ware_BuiltIn, id, Utils::WString::Null()); 
7135
}
7112
}
7136
 
7113
 
7137
bool CPackages::builtInWareOverideNoto(int id, int *noto)
7114
bool CPackages::builtInWareOverideNoto(int id, int *noto)
7138
{
7115
{
7139
	return _wareNotoOverride(Ware_BuiltIn, id, Utils::String::Null(), noto);
7116
	return _wareNotoOverride(Ware_BuiltIn, id, Utils::WString::Null(), noto);
7140
}
7117
}
7141
 
7118
 
7142
int CPackages::customWareOveridePrice(const Utils::String &id)
7119
int CPackages::customWareOveridePrice(const Utils::WString &id)
7143
{
7120
{
7144
	return _warePriceOverride(Ware_Custom, 0, id); 
7121
	return _warePriceOverride(Ware_Custom, 0, id); 
7145
}
7122
}
7146
 
7123
 
7147
bool CPackages::customWareOverideNoto(const Utils::String &id, int *noto)
7124
bool CPackages::customWareOverideNoto(const Utils::WString &id, int *noto)
7148
{
7125
{
7149
	return _wareNotoOverride(Ware_Custom, 0, id, noto);
7126
	return _wareNotoOverride(Ware_Custom, 0, id, noto);
7150
}
7127
}
7151
 
7128
 
7152
void CPackages::removeEmpOverride(int pos)
7129
void CPackages::removeEmpOverride(int pos)
7153
{
7130
{
7154
	_removeWareOverride(Ware_EMP, pos, Utils::String::Null());
7131
	_removeWareOverride(Ware_EMP, pos, Utils::WString::Null());
7155
}
7132
}
7156
 
7133
 
7157
void CPackages::removeBuiltinWareOverride(int pos)
7134
void CPackages::removeBuiltinWareOverride(int pos)
7158
{
7135
{
7159
	_removeWareOverride(Ware_BuiltIn, pos, Utils::String::Null());
7136
	_removeWareOverride(Ware_BuiltIn, pos, Utils::WString::Null());
7160
}
7137
}
7161
 
7138
 
7162
void CPackages::removeCustomWareOverride(const Utils::String &id)
7139
void CPackages::removeCustomWareOverride(const Utils::WString &id)
7163
{
7140
{
7164
	_removeWareOverride(Ware_Custom, 0, id);
7141
	_removeWareOverride(Ware_Custom, 0, id);
7165
}
7142
}
7166
 
7143
 
7167
 
7144
 
7168
bool CPackages::readGlobals(Utils::CStringList &globals) const
7145
bool CPackages::readGlobals(Utils::WStringList &globals) const
7169
{
7146
{
7170
	int e = extractGameFile("types/Globals.pck", m_sTempDir);
7147
	int e = extractGameFile(L"types/Globals.pck", m_sTempDir);
7171
	if ( e )
7148
	if ( e )
7172
	{
7149
	{
7173
		CFileIO File((e == -1) ? "Globals.txt" : m_sTempDir + "/Globals.txt");
7150
		CFileIO File((e == -1) ? L"Globals.txt" : m_sTempDir + L"/Globals.txt");
7174
		if ( File.exists() )
7151
		if ( File.exists() )
7175
		{
7152
		{
7176
			std::vector<Utils::String> lines;
7153
			std::vector<Utils::WString> lines;
7177
			if(File.readLines(lines))
7154
			if(File.readLines(lines))
7178
			{
7155
			{
7179
				int entries = -1;
7156
				int entries = -1;
7180
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
7157
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
7181
				{
7158
				{
7182
					Utils::String str = itr->remove('\r').remove(9);
7159
					Utils::WString str = itr->remove('\r').remove(9);
7183
					str.removeFirstSpace();
7160
					str.removeFirstSpace();
7184
 
7161
 
7185
					if ( str.empty() )
7162
					if ( str.empty() )
7186
						continue;
7163
						continue;
7187
					if ( str[0] == '/' )
7164
					if ( str[0] == L'/' )
7188
						continue;
7165
						continue;
7189
 
7166
 
7190
					// remove comments
7167
					// remove comments
7191
					if (str.contains("/") ) 
7168
					if (str.contains(L"/") ) 
7192
						str = str.token("/", 1);
7169
						str = str.token(L"/", 1);
7193
 
7170
 
7194
					if ( entries == -1 )
7171
					if ( entries == -1 )
7195
						entries = str.token(";", 1).toInt();
7172
						entries = str.token(L";", 1).toInt();
7196
					else
7173
					else
7197
						globals.pushBack(str.token(";", 1), str.token(";", 2));
7174
						globals.pushBack(str.token(L";", 1), str.token(L";", 2));
7198
				}
7175
				}
7199
 
7176
 
7200
				return true;
7177
				return true;
7201
			}
7178
			}
7202
		}
7179
		}
Line 7205... Line 7182...
7205
	return false;
7182
	return false;
7206
}
7183
}
7207
 
7184
 
7208
void CPackages::CreateGlobals()
7185
void CPackages::CreateGlobals()
7209
{
7186
{
7210
	if ( m_lGlobals.empty() )
7187
	if ( _lGlobals.empty() )
7211
		return; // no global settings
7188
		return; // no global settings
7212
 
7189
 
7213
	Utils::CStringList globals;
7190
	Utils::WStringList globals;
7214
	if (readGlobals(globals))
7191
	if (readGlobals(globals))
7215
	{
7192
	{
7216
		// apply out settings
7193
		// apply out settings
7217
		for(auto itr = m_lGlobals.begin(); itr != m_lGlobals.end(); itr++)
7194
		for(auto itr = _lGlobals.begin(); itr != _lGlobals.end(); itr++)
7218
			globals.changeData((*itr)->str, (*itr)->data);
7195
			globals.changeData((*itr)->str, (*itr)->data);
7219
 
7196
 
7220
		// now write it
7197
		// now write it
7221
		Utils::CStringList writeList;
7198
		Utils::WStringList writeList;
7222
		for(auto itr = globals.begin(); itr != globals.end(); itr++)
7199
		for(auto itr = globals.begin(); itr != globals.end(); itr++)
7223
			writeList.pushBack((*itr)->str + ";" + (*itr)->data + ";");
7200
			writeList.pushBack((*itr)->str + L";" + (*itr)->data + L";");
7224
		
7201
		
7225
		// finally, write the file
7202
		// finally, write the file
7226
		writeList.pushFront(Utils::String::Number(writeList.size()) + "; /globals amount", "");
7203
		writeList.pushFront(Utils::WString::Number(writeList.size()) + L"; /globals amount", "");
7227
		writeList.pushFront("// Globals file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2), "");
7204
		writeList.pushFront(L"// Globals file, created by SPK Libraries V" + Utils::WString::FromFloat(GetLibraryVersion(), 2), L"");
7228
 
7205
 
7229
		CFileIO WriteFile(m_sTempDir + "/Globals.txt");
7206
		CFileIO WriteFile(m_sTempDir + L"/Globals.txt");
7230
		if ( WriteFile.writeFile(&writeList) )
7207
		if ( WriteFile.writeFile(&writeList) )
7231
		{
7208
		{
7232
			this->packFile(&WriteFile, "types/Globals.pck");
7209
			this->packFile(&WriteFile, L"types/Globals.pck");
7233
			WriteFile.remove();
7210
			WriteFile.remove();
7234
		}
7211
		}
7235
	}
7212
	}
7236
}
7213
}
7237
 
7214
 
Line 7310... Line 7287...
7310
							if ( shipData.readShipData(line) )
7287
							if ( shipData.readShipData(line) )
7311
							{
7288
							{
7312
								for ( CListNode<SGameShip> *node = shipOverrides.Front(); node; node = node->next() )
7289
								for ( CListNode<SGameShip> *node = shipOverrides.Front(); node; node = node->next() )
7313
								{
7290
								{
7314
									SGameShip *s = node->Data();
7291
									SGameShip *s = node->Data();
7315
									if ( !s->pPackage->GetShipID().Compare(shipData.sID) )
7292
									if ( !s->pPackage->GetShipID().toWString().Compare(shipData.sID))
7316
										continue;
7293
										continue;
7317
									s->iText = shiptext;
7294
									s->iText = shiptext;
7318
									if ( !s->pPackage->GetOriginalDescription() )
7295
									if ( !s->pPackage->GetOriginalDescription() )
7319
										shiptext += 2;
7296
										shiptext += 2;
7320
									s->iPos = tshipsList.size();
7297
									s->iPos = tshipsList.size();
Line 7392... Line 7369...
7392
		}
7369
		}
7393
	}
7370
	}
7394
 
7371
 
7395
}
7372
}
7396
 
7373
 
7397
bool CPackages::packFile(const Utils::String &filename) const
7374
bool CPackages::packFile(const Utils::WString &filename) const
7398
{
7375
{
7399
	// compress the file
7376
	// compress the file
7400
	CFileIO File(filename);
7377
	CFileIO File(filename);
7401
	size_t fileSize;
7378
	size_t fileSize;
7402
	char *fileData = File.ReadToData(&fileSize);
7379
	char *fileData = File.ReadToData(&fileSize);
Line 7421... Line 7398...
7421
	}
7398
	}
7422
 
7399
 
7423
	return false;
7400
	return false;
7424
}
7401
}
7425
 
7402
 
7426
bool CPackages::unPackFile(const Utils::String &filename, bool checkxml) const
7403
bool CPackages::unPackFile(const Utils::WString &filename, bool checkxml) const
7427
{
7404
{
7428
	// compress the file
7405
	// compress the file
7429
	CFileIO File(filename);
7406
	CFileIO File(filename);
7430
	size_t fileSize;
7407
	size_t fileSize;
7431
	char *fileData = File.ReadToData(&fileSize);
7408
	char *fileData = File.ReadToData(&fileSize);
Line 7436... Line 7413...
7436
		unsigned char *pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, false);
7413
		unsigned char *pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, false);
7437
		if ( !pckData )
7414
		if ( !pckData )
7438
			pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7415
			pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7439
 
7416
 
7440
		if ( pckData )
7417
		if ( pckData )
7441
		{
7418
		{
7442
			Utils::WString ext = L"txt";
7419
			Utils::WString ext = L"txt";
7443
			if ( File.isFileExtension(L"pbb") )
7420
			if ( File.isFileExtension(L"pbb") )
7444
				ext = L"bob";
7421
				ext = L"bob";
7445
			else if ( File.isFileExtension(L"pbd") )
7422
			else if ( File.isFileExtension(L"pbd") )
7446
				ext = L"bod";
7423
				ext = L"bod";
Line 7453... Line 7430...
7453
			if ( checkxml )
7430
			if ( checkxml )
7454
			{
7431
			{
7455
				int readmaxlines = 20;
7432
				int readmaxlines = 20;
7456
				bool isxml = false;
7433
				bool isxml = false;
7457
				do {
7434
				do {
7458
					Utils::String line = pckFile.readEndOfLine();
7435
					Utils::String line = pckFile.readEndOfLineStr();
7459
					if ( line.contains("<language id=") )
7436
					if ( line.contains("<language id=") )
7460
					{
7437
					{
7461
						isxml = true;
7438
						isxml = true;
7462
						break;
7439
						break;
7463
					}
7440
					}
Line 7488... Line 7465...
7488
	}
7465
	}
7489
 
7466
 
7490
	return false;
7467
	return false;
7491
}
7468
}
7492
 
7469
 
7493
bool CPackages::packFile(CFileIO* File, const Utils::String &sFilename) const
7470
bool CPackages::packFile(CFileIO* File, const Utils::WString &sFilename) const
7494
{
7471
{
7495
	Utils::String filename = sFilename.findReplace("\\", "/");
7472
	Utils::WString filename = sFilename.findReplace(L"\\", L"/");
7496
	if ( m_iGame == GAME_X3 )
7473
	if ( m_iGame == GAME_X3 )
7497
	{
7474
	{
7498
		CCatFile catFile;
7475
		CCatFile catFile;
7499
		int error = catFile.open(m_sCurrentDir + "/mods/PluginManager.cat", this->getAddonDir(), CATREAD_CATDECRYPT, true);
7476
		int error = catFile.open(m_sCurrentDir + L"/mods/PluginManager.cat", this->getAddonDir(), CATREAD_CATDECRYPT, true);
7500
		if ( error == CATERR_NONE || error == CATERR_CREATED )
7477
		if ( error == CATERR_NONE || error == CATERR_CREATED )
7501
		{
7478
		{
7502
			// it it wrote ok, remove the old ones
7479
			// it it wrote ok, remove the old ones
7503
			if ( !catFile.appendFile(File->fullFilenameStr(), filename, true, true) )
7480
			if ( !catFile.appendFile(File->fullFilename(), filename, true, true) )
7504
				return false;
7481
				return false;
7505
			return true;
7482
			return true;
7506
		}
7483
		}
7507
	}
7484
	}
7508
	else
7485
	else
Line 7517... Line 7494...
7517
			unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7494
			unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7518
			if ( pckData )
7495
			if ( pckData )
7519
			{
7496
			{
7520
//				if ( !this->GetAddonDir().Empty() && CCatFile::IsAddonDir(filename) )
7497
//				if ( !this->GetAddonDir().Empty() && CCatFile::IsAddonDir(filename) )
7521
//					filename = this->GetAddonDir() + "/" + filename;
7498
//					filename = this->GetAddonDir() + "/" + filename;
7522
				CFileIO pckFile(m_sCurrentDir + "/" + filename);
7499
				CFileIO pckFile(m_sCurrentDir + L"/" + filename);
7523
				if ( !CDirIO(pckFile.dir()).exists() )
7500
				if ( !CDirIO(pckFile.dir()).exists() )
7524
					CDirIO(pckFile.dir()).create();
7501
					CDirIO(pckFile.dir()).create();
7525
				pckFile.WriteData((char *)pckData, newFileSize);
7502
				pckFile.WriteData((char *)pckData, newFileSize);
7526
				const_cast<CPackages *>(this)->addCreatedFile(pckFile.fullFilenameStr());
7503
				const_cast<CPackages *>(this)->addCreatedFile(pckFile.fullFilename());
7527
				return true;
7504
				return true;
7528
			}
7505
			}
7529
		}
7506
		}
7530
	}
7507
	}
7531
 
7508
 
Line 7674... Line 7651...
7674
		return false;
7651
		return false;
7675
 
7652
 
7676
	Utils::CStringList gameAddons;
7653
	Utils::CStringList gameAddons;
7677
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7654
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7678
	{
7655
	{
7679
		SGameExe *exe = m_gameExe.GetGame(i);
7656
		SGameExe *exe = m_gameExe.game(i);
7680
		if (!exe->sAddon.empty())
7657
		if (!exe->sAddon.empty())
7681
			gameAddons.pushBack(Utils::String::Number(i + 1), exe->sAddon);
7658
			gameAddons.pushBack(Utils::String::Number(i + 1), exe->sAddon.toString());
7682
	}
7659
	}
7683
 
7660
 
7684
	return baseFile->extractAll(dir, game, gameAddons, includedir, progress);
7661
	return baseFile->extractAll(dir, game, gameAddons, includedir, progress);
7685
}
7662
}
7686
 
7663
 
Line 7690... Line 7667...
7690
		return false;
7667
		return false;
7691
 
7668
 
7692
	Utils::CStringList gameAddons;
7669
	Utils::CStringList gameAddons;
7693
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7670
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7694
	{
7671
	{
7695
		SGameExe *exe = m_gameExe.GetGame(i);
7672
		SGameExe *exe = m_gameExe.game(i);
7696
		if (!exe->sAddon.empty())
7673
		if (!exe->sAddon.empty())
7697
			gameAddons.pushBack(Utils::String::Number(i + 1), exe->sAddon);
7674
			gameAddons.pushBack(Utils::String::Number(i + 1), exe->sAddon.toString());
7698
	}
7675
	}
7699
 
7676
 
7700
	return baseFile->GeneratePackagerScript(wildcard, list, game, gameAddons, datafile);
7677
	return baseFile->GeneratePackagerScript(wildcard, list, game, gameAddons, datafile);
7701
}
7678
}
7702
 
7679
 
7703
CBaseFile *CPackages::LoadPackagerScript(const Utils::String &filename, int compression, Utils::String (*askFunc)(const Utils::String &), Utils::CStringList *malformedLines, Utils::CStringList *unknownCommands, Utils::CStringList *variables, CProgressInfo *progress)
7680
CBaseFile *CPackages::loadPackagerScript(const Utils::WString &filename, int compression, Utils::WString (*askFunc)(const Utils::WString &), Utils::WStringList *malformedLines, Utils::WStringList *unknownCommands, Utils::WStringList *variables, CProgressInfo *progress)
7704
{
7681
{
7705
	// check the file exists
7682
	// check the file exists
7706
	if ( !CFileIO::Exists(filename) )
7683
	if ( !CFileIO::Exists(filename) )
7707
		return NULL;
7684
		return NULL;
7708
 
7685
 
7709
	// read all the lines
7686
	// read all the lines
7710
	CFileIO File(filename);
7687
	CFileIO File(filename);
7711
	if ( !File.startRead() ) 
7688
	if ( !File.startRead() ) 
7712
		return NULL;
7689
		return NULL;
7713
 
7690
 
7714
	Utils::CStringList fileData;
7691
	Utils::WStringList fileData;
7715
 
7692
 
7716
	int iLine = 0;
7693
	int iLine = 0;
7717
 
7694
 
7718
	CBaseFile *package = NULL;
7695
	CBaseFile *package = NULL;
7719
 
7696
 
7720
	while(!File.atEnd()) {
7697
	while(!File.atEnd()) {
7721
		// read the next line in the file
7698
		// read the next line in the file
7722
		Utils::String line = File.readEndOfLine();
7699
		Utils::WString line = File.readEndOfLineStr();
7723
 
7700
 
7724
		// filter out any characters we dont really want
7701
		// filter out any characters we dont really want
7725
		line.removeChar("\t\r");
7702
		line.removeChar(L"\t\r");
7726
		line.removeFirstSpace();
7703
		line.removeFirstSpace();
7727
 
7704
 
7728
		if ( line.empty() ) continue;
7705
		if ( line.empty() ) continue;
7729
 
7706
 
7730
		// check for any comments (so we can ignore them)
7707
		// check for any comments (so we can ignore them)
7731
		if ( line.left(2).Compare("//") || line[0] == '#' ) continue;
7708
		if ( line.left(2).Compare(L"//") || line[0] == L'#' ) continue;
7732
 
7709
 
7733
		++iLine;
7710
		++iLine;
7734
 
7711
 
7735
		// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
7712
		// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
7736
		if ( !line.contains(':') )
7713
		if ( !line.contains(L':') )
7737
		{
7714
		{
7738
			// there are some exeptions, and these are one word entrys only
7715
			// there are some exeptions, and these are one word entrys only
7739
			line.removeEndSpace();
7716
			line.removeEndSpace();
7740
			if ( line.contains(" ") )
7717
			if ( line.contains(L" ") )
7741
			{
7718
			{
7742
				if ( malformedLines )
7719
				if ( malformedLines )
7743
					malformedLines->pushBack(line, Utils::String::Number(iLine));
7720
					malformedLines->pushBack(line, Utils::WString::Number(iLine));
7744
				continue;
7721
				continue;
7745
			}
7722
			}
7746
		}
7723
		}
7747
 
7724
 
7748
		// check for the type line
7725
		// check for the type line
7749
		if ( !package && line.token(":", 1).Compare("FileType") )
7726
		if ( !package && line.token(L":", 1).Compare(L"FileType") )
7750
		{
7727
		{
7751
			Utils::String sFileType = line.tokens(":", 2).removeFirstSpace();
7728
			Utils::WString sFileType = line.tokens(L":", 2).removeFirstSpace();
7752
			if ( sFileType.Compare("Ship") )
7729
			if ( sFileType.Compare(L"Ship") )
7753
				package = new CXspFile();
7730
				package = new CXspFile();
7754
			else if ( sFileType.Compare("Script") )
7731
			else if ( sFileType.Compare(L"Script") )
7755
				package = new CSpkFile();
7732
				package = new CSpkFile();
7756
			else if ( sFileType.Compare("Base") )
7733
			else if ( sFileType.Compare(L"Base") )
7757
				package = new CBaseFile();
7734
				package = new CBaseFile();
7758
			continue;
7735
			continue;
7759
		}
7736
		}
7760
 
7737
 
7761
		fileData.pushBack(line, Utils::String::Number(iLine));
7738
		fileData.pushBack(line, Utils::WString::Number(iLine));
7762
	}
7739
	}
7763
 
7740
 
7764
	// assume its a script if no type is set (all old versions are scripts)
7741
	// assume its a script if no type is set (all old versions are scripts)
7765
	if ( !package )
7742
	if ( !package )
7766
		package = new CSpkFile();
7743
		package = new CSpkFile();
7767
 
7744
 
7768
	if ( compression != -1 )
7745
	if ( compression != -1 )
7769
		package->SetDataCompression(compression);
7746
		package->SetDataCompression(compression);
7770
 
7747
 
7771
	Utils::String ftpaddr;
7748
	Utils::WString ftpaddr;
7772
	Utils::String ftpuser;
7749
	Utils::WString ftpuser;
7773
	Utils::String ftppass;
7750
	Utils::WString ftppass;
7774
	Utils::String ftpdir;
7751
	Utils::WString ftpdir;
7775
	Utils::String sMainGame;
7752
	Utils::WString sMainGame;
7776
	Utils::CStringList otherGames;
7753
	Utils::WStringList otherGames;
7777
	Utils::CStringList gameAddons;
7754
	Utils::WStringList gameAddons;
7778
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7755
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7779
	{
7756
	{
7780
		SGameExe *exe = m_gameExe.GetGame(i);
7757
		SGameExe *exe = m_gameExe.game(i);
7781
		if (!exe->sAddon.empty())
7758
		if (!exe->sAddon.empty())
7782
			gameAddons.pushBack(Utils::String::Number(i + 1), exe->sAddon);
7759
			gameAddons.pushBack(Utils::WString::Number(i + 1), exe->sAddon);
7783
	}
7760
	}
7784
 
7761
 
7785
	// now lets read the rest of the day
7762
	// now lets read the rest of the day
7786
	Utils::CStringList listVaribles;
7763
	Utils::WStringList listVaribles;
7787
	for (Utils::SStringList *line = fileData.first(); line; line = fileData.next())
7764
	for (Utils::WStringNode *line = fileData.first(); line; line = fileData.next())
7788
	{
7765
	{
7789
		Utils::String cmd = line->str.token(":", 1);
7766
		Utils::WString cmd = line->str.token(L":", 1);
7790
		Utils::String rest = line->str.tokens(":", 2).removeFirstSpace();
7767
		Utils::WString rest = line->str.tokens(L":", 2).removeFirstSpace();
7791
 
7768
 
7792
		if (cmd.Compare("Varible") || cmd.Compare("Variable"))
7769
		if (cmd.Compare(L"Varible") || cmd.Compare(L"Variable"))
7793
		{
7770
		{
7794
			Utils::String s1 = rest.token(" ", 1);
7771
			Utils::WString s1 = rest.token(L" ", 1);
7795
			Utils::String s2 = rest.tokens(" ", 2);
7772
			Utils::WString s2 = rest.tokens(L" ", 2);
7796
			if(!listVaribles.changeData(s1, s2))
7773
			if(!listVaribles.changeData(s1, s2))
7797
				listVaribles.pushBack(s1, s2);
7774
				listVaribles.pushBack(s1, s2);
7798
		}
7775
		}
7799
		else
7776
		else
7800
		{
7777
		{
7801
			// replace variables
7778
			// replace variables
7802
			if ( rest.isin("$") )
7779
			if ( rest.contains(L"$") )
7803
			{
7780
			{
7804
				for (Utils::SStringList *strVar = listVaribles.first(); strVar; strVar = listVaribles.next())
7781
				for (Utils::WStringNode *strVar = listVaribles.first(); strVar; strVar = listVaribles.next())
7805
				{
7782
				{
7806
					if ( rest.contains(strVar->str) )
7783
					if ( rest.contains(strVar->str) )
7807
						rest = rest.findReplace(strVar->str, strVar->data);
7784
						rest = rest.findReplace(strVar->str, strVar->data);
7808
				}
7785
				}
7809
 
7786
 
7810
				if ( variables )
7787
				if ( variables )
7811
				{
7788
				{
7812
					for (Utils::SStringList *strVar = variables->first(); strVar; strVar = variables->next())
7789
					for (Utils::WStringNode *strVar = variables->first(); strVar; strVar = variables->next())
7813
					{
7790
					{
7814
						if ( rest.contains(strVar->str) )
7791
						if ( rest.contains(strVar->str) )
7815
							rest = rest.findReplace(strVar->str, strVar->data);
7792
							rest = rest.findReplace(strVar->str, strVar->data);
7816
					}
7793
					}
7817
				}
7794
				}
7818
			}
7795
			}
7819
 
7796
 
7820
			//check for the built in varibles
7797
			//check for the built in varibles
7821
			if ( rest.contains("$ASK") )
7798
			if ( rest.contains(L"$ASK") )
7822
			{
7799
			{
7823
				Utils::String replace = "$ASK";
7800
				Utils::WString replace = L"$ASK";
7824
				Utils::String result;
7801
				Utils::WString result;
7825
 
7802
 
7826
				if ( askFunc )
7803
				if ( askFunc )
7827
					result = askFunc(cmd);
7804
					result = askFunc(cmd);
7828
 
7805
 
7829
				if ( rest.contains("$ASK(") )
7806
				if ( rest.contains(L"$ASK(") )
7830
				{
7807
				{
7831
					replace = rest.tokens("$ASK(", 2).token(")", 1);
7808
					replace = rest.tokens(L"$ASK(", 2).token(L")", 1);
7832
					if ( result.empty() )
7809
					if ( result.empty() )
7833
						result = replace;
7810
						result = replace;
7834
					replace = "$ASK(" + replace + ")";
7811
					replace = L"$ASK(" + replace + L")";
7835
				}
7812
				}
7836
 
7813
 
7837
				if ( !result.empty() )
7814
				if ( !result.empty() )
7838
					rest = rest.findReplace(replace, result);
7815
					rest = rest.findReplace(replace, result);
7839
			}
7816
			}
7840
			// todays date
7817
			// todays date
7841
			if ( rest.isin("$DATE") )
7818
			if ( rest.contains(L"$DATE") )
7842
			{
7819
			{
7843
				time_t now;
7820
				time_t now;
7844
				time(&now);
7821
				time(&now);
7845
				struct tm *timeinfo = localtime(&now);
7822
				struct tm *timeinfo = localtime(&now);
7846
				Utils::String result = Utils::String::Number(timeinfo->tm_mday) + "." + Utils::String::Number(timeinfo->tm_mon + 1) + "." + Utils::String::Number(timeinfo->tm_year + 1900);
7823
				Utils::WString result = Utils::WString::Number(timeinfo->tm_mday) + L"." + Utils::WString::Number(timeinfo->tm_mon + 1) + L"." + Utils::WString::Number(timeinfo->tm_year + 1900);
7847
				if ( !result.empty() )
7824
				if ( !result.empty() )
7848
					rest = rest.findReplace("$DATE", result);
7825
					rest = rest.findReplace(L"$DATE", result);
7849
			}
7826
			}
7850
			// mydocuments
7827
			// mydocuments
7851
			if ( rest.isin("$MYDOCUMENTS") )
7828
			if ( rest.contains(L"$MYDOCUMENTS") )
7852
			{
7829
			{
7853
				if ( !m_sMyDoc.empty() )
7830
				if ( !m_sMyDoc.empty() )
7854
					rest = rest.findReplace("$MYDOCUMENTS", m_sMyDoc);
7831
					rest = rest.findReplace(L"$MYDOCUMENTS", m_sMyDoc);
7855
			}
7832
			}
7856
 
7833
 
7857
			// current path
7834
			// current path
7858
			if ( rest.isin("$PATH") )
7835
			if ( rest.contains(L"$PATH") )
7859
			{
7836
			{
7860
				Utils::WString currentDir = CFileIO(filename).dir();
7837
				Utils::WString currentDir = CFileIO(filename).dir();
7861
				if ( !currentDir.empty() )
7838
				if ( !currentDir.empty() )
7862
					rest = rest.findReplace("$PATH", currentDir.toString());
7839
					rest = rest.findReplace(L"$PATH", currentDir);
7863
			}
7840
			}
7864
 
7841
 
7865
			// now parse the rest of the values
7842
			// now parse the rest of the values
7866
			if ( cmd.Compare("FtpUpload") )
7843
			if ( cmd.Compare(L"FtpUpload") )
7867
				ftpaddr = rest.token(" ", 1) + ":" + rest.token(" ", 2);
7844
				ftpaddr = rest.token(L" ", 1) + L":" + rest.token(L" ", 2);
7868
			else if ( cmd.Compare("FtpUser") )
7845
			else if ( cmd.Compare(L"FtpUser") )
7869
				ftpuser = rest;
7846
				ftpuser = rest;
7870
			else if ( cmd.Compare("FtpPass") )
7847
			else if ( cmd.Compare(L"FtpPass") )
7871
				ftppass = rest;
7848
				ftppass = rest;
7872
			else if ( cmd.Compare("FtpDir") )
7849
			else if ( cmd.Compare(L"FtpDir") )
7873
				ftpdir = rest;
7850
				ftpdir = rest;
7874
			else if ( cmd.Compare("MultiGames") ) {
7851
			else if ( cmd.Compare(L"MultiGames") ) {
7875
				sMainGame = rest.token(" ", 1);
7852
				sMainGame = rest.token(L" ", 1);
7876
				otherGames.tokenise(rest.tokens(" ", 2), " ");
7853
				otherGames.tokenise(rest.tokens(L" ", 2), L" ");
7877
			}
7854
			}
7878
			else if ( !package->LoadPackageData(cmd, rest, sMainGame, otherGames, gameAddons, progress) )
7855
			else if ( !package->loadPackageData(cmd, rest, sMainGame, otherGames, gameAddons, progress))
7879
			{
7856
			{
7880
				if ( unknownCommands )
7857
				if ( unknownCommands )
7881
					unknownCommands->pushBack(cmd, rest);
7858
					unknownCommands->pushBack(cmd, rest);
7882
			}
7859
			}
7883
		}
7860
		}
7884
	}
7861
	}
7885
 
7862
 
7886
	if ( package->filename().empty() )
7863
	if ( package->filename().empty() )
7887
		package->LoadPackageData("AutoSave", "$AUTOSAVE", sMainGame, otherGames, gameAddons, progress);
7864
		package->loadPackageData(L"AutoSave", L"$AUTOSAVE", sMainGame, otherGames, gameAddons, progress);
7888
 
7865
 
7889
	if (package->autoExtraction())
7866
	if (package->autoExtraction())
7890
	{
7867
	{
7891
		for (auto itr = package->autoExtraction()->begin(); itr != package->autoExtraction()->end(); itr++)
7868
		for (auto itr = package->autoExtraction()->begin(); itr != package->autoExtraction()->end(); itr++)
7892
		{
7869
		{
Line 7918... Line 7895...
7918
		}
7895
		}
7919
 
7896
 
7920
		if ( !ftpdir.empty() )
7897
		if ( !ftpdir.empty() )
7921
			ftpaddr += ftpdir;
7898
			ftpaddr += ftpdir;
7922
 
7899
 
7923
		package->setFtpAddr(ftpaddr);
7900
		package->setFtpAddr(ftpaddr.toString());
7924
	}
7901
	}
7925
 
7902
 
7926
	return package;
7903
	return package;
7927
}
7904
}
7928
 
7905
 
7929
Utils::String CPackages::getLanguageName() const
7906
Utils::String CPackages::getLanguageName() const
7930
{
7907
{
7931
	return CPackages::ConvertLanguage(m_iLanguage);
7908
	return CPackages::ConvertLanguage(m_iLanguage);
7932
}
7909
}
7933
 
7910
 
7934
size_t CPackages::updateFoundPackages(const Utils::String& dir)
7911
size_t CPackages::updateFoundPackages(const Utils::WString& dir)
7935
{
7912
{
7936
	m_lFoundPackages.MemoryClear();
7913
	m_lFoundPackages.MemoryClear();
7937
	if (!m_sCurrentDir.empty())
7914
	if (!m_sCurrentDir.empty())
7938
		return findAllPackages(m_lFoundPackages, dir);
7915
		return findAllPackages(m_lFoundPackages, dir);
7939
 
7916
 
7940
	return 0;
7917
	return 0;
7941
}
7918
}
7942
 
7919
 
7943
size_t CPackages::addFoundPackages(const Utils::String& dir)
7920
size_t CPackages::addFoundPackages(const Utils::WString& dir)
7944
{
7921
{
7945
	return findPackageDirectories(m_lFoundPackages, dir);
7922
	return findPackageDirectories(m_lFoundPackages, dir);
7946
}
7923
}
7947
 
7924
 
7948
int CPackages::findAllPackages(CLinkList<CBaseFile> &packages, const Utils::String &dir)
7925
int CPackages::findAllPackages(CLinkList<CBaseFile> &packages, const Utils::WString &dir)
7949
{
7926
{
7950
	int count = 0;
7927
	int count = 0;
7951
	if (!dir.empty())
7928
	if (!dir.empty())
7952
	{
7929
	{
7953
		count += findPackageDirectories(packages, dir + "/Addons");
7930
		count += findPackageDirectories(packages, dir + L"/Addons");
7954
		count += findPackageDirectories(packages, dir + "/Downloads");
7931
		count += findPackageDirectories(packages, dir + L"/Downloads");
7955
	}
7932
	}
7956
 
7933
 
7957
	count += findPackageDirectories(packages, "./Addons");
7934
	count += findPackageDirectories(packages, L"./Addons");
7958
	count += findPackageDirectories(packages, "./Downloads");
7935
	count += findPackageDirectories(packages, L"./Downloads");
7959
	count += findPackageDirectories(packages, m_sMyDoc + "/Egosoft/PluginManager/Addons");
7936
	count += findPackageDirectories(packages, m_sMyDoc + L"/Egosoft/PluginManager/Addons");
7960
	count += findPackageDirectories(packages, m_sMyDoc + "/Egosoft/PluginManager/Downloads");
7937
	count += findPackageDirectories(packages, m_sMyDoc + L"/Egosoft/PluginManager/Downloads");
7961
 
7938
 
7962
	if (_pCurrentDir)
7939
	if (_pCurrentDir)
7963
	{
7940
	{
7964
		count += findPackageDirectories(packages, _pCurrentDir->dir + "/Addons");
7941
		count += findPackageDirectories(packages, _pCurrentDir->dir + L"/Addons");
7965
		count += findPackageDirectories(packages, _pCurrentDir->dir + "/Downloads");
7942
		count += findPackageDirectories(packages, _pCurrentDir->dir + L"/Downloads");
7966
		count += findPackageDirectories(packages, _pCurrentDir->dir + "/ExtraContent");
7943
		count += findPackageDirectories(packages, _pCurrentDir->dir + L"/ExtraContent");
7967
	}
7944
	}
7968
 
7945
 
7969
	return count;
7946
	return count;
7970
}
7947
}
7971
int CPackages::findPackageDirectories(CLinkList<CBaseFile> &packages, const Utils::String &dir)
7948
int CPackages::findPackageDirectories(CLinkList<CBaseFile> &packages, const Utils::WString &dir)
7972
{
7949
{
7973
	CDirIO Dir(dir);
7950
	CDirIO Dir(dir);
7974
	int count = 0;
7951
	int count = 0;
7975
	Utils::WStringList files;
7952
	Utils::WStringList files;
7976
	if (Dir.dirList(files))
7953
	if (Dir.dirList(files))
Line 7984... Line 7961...
7984
	}
7961
	}
7985
 
7962
 
7986
	count += findPackageFiles(packages, dir);
7963
	count += findPackageFiles(packages, dir);
7987
	return count;
7964
	return count;
7988
}
7965
}
7989
int CPackages::findPackageFiles(CLinkList<CBaseFile> &packages, const Utils::String &dir)
7966
int CPackages::findPackageFiles(CLinkList<CBaseFile> &packages, const Utils::WString &dir)
7990
{
7967
{
7991
	CDirIO Dir(dir);
7968
	CDirIO Dir(dir);
7992
	int count = 0;
7969
	int count = 0;
7993
	for (int type = 0; type < 2; type++)
7970
	for (int type = 0; type < 2; type++)
7994
	{
7971
	{
Line 8000... Line 7977...
8000
		else
7977
		else
8001
			break;
7978
			break;
8002
			
7979
			
8003
		for(auto itr = files.begin(); itr != files.end(); itr++)
7980
		for(auto itr = files.begin(); itr != files.end(); itr++)
8004
		{
7981
		{
8005
			Utils::String f = Dir.file((*itr)->str).toString();
7982
			Utils::WString f = Dir.file((*itr)->str);
8006
			int error = 0;
7983
			int error = 0;
8007
			CBaseFile *p = this->openPackage(f, &error, 0, SPKREAD_NODATA, READFLAG_NOUNCOMPRESS);
7984
			CBaseFile *p = this->openPackage(f, &error, 0, SPKREAD_NODATA, READFLAG_NOUNCOMPRESS);
8008
			if (!p)
7985
			if (!p)
8009
				continue;
7986
				continue;
8010
			if (p->IsMod() || this->findSpkPackage(p->name(), p->author()))
7987
			if (p->IsMod() || this->findSpkPackage(p->name(), p->author()))
Line 8039... Line 8016...
8039
			
8016
			
8040
			if (p->icon())
8017
			if (p->icon())
8041
			{
8018
			{
8042
				bool addedIcon = false;
8019
				bool addedIcon = false;
8043
				p->ReadIconFileToMemory();
8020
				p->ReadIconFileToMemory();
8044
				p->icon()->setFilename(this->tempDirectory().findReplace("\\", "/") + "/" + p->author() + ";_" + p->name() + "." + p->iconExt());
8021
				p->icon()->setFilename(this->tempDirectory().findReplace(L"\\", L"/") + L"/" + p->author().toWString() + L";_" + p->name().toWString() + L"." + p->iconExt());
8045
				p->icon()->setFullDir(this->tempDirectory());
8022
				p->icon()->setFullDir(this->tempDirectory());
8046
				if (p->icon()->UncompressData())
8023
				if (p->icon()->UncompressData())
8047
				{
8024
				{
8048
					if (p->icon()->writeFilePointer())
8025
					if (p->icon()->writeFilePointer())
8049
						addedIcon = true;
8026
						addedIcon = true;
Line 8123... Line 8100...
8123
	}
8100
	}
8124
 
8101
 
8125
	return Utils::String::Number(lang);
8102
	return Utils::String::Number(lang);
8126
}
8103
}
8127
 
8104
 
8128
bool CPackages::checkAccessRights(const Utils::String &aDir) const
8105
bool CPackages::checkAccessRights(const Utils::WString &aDir) const
8129
{
8106
{
8130
	Utils::String dir = aDir;
8107
	Utils::WString dir = aDir;
8131
	if (dir.empty())
8108
	if (dir.empty())
8132
		dir = m_sCurrentDir;
8109
		dir = m_sCurrentDir;
8133
 
8110
 
8134
	// write a file, then read the contents
8111
	// write a file, then read the contents
8135
	CFileIO File(dir + "/accessrightscheck.dat");
8112
	CFileIO File(dir + L"/accessrightscheck.dat");
8136
 
8113
 
8137
	// check if file exists and remove it
8114
	// check if file exists and remove it
8138
	if ( File.exists() )
8115
	if ( File.exists() )
8139
	{
8116
	{
8140
		// if we cant remove it, we dont have enough rights
8117
		// if we cant remove it, we dont have enough rights
Line 8153... Line 8130...
8153
	// now check it exists
8130
	// now check it exists
8154
	if ( !File.exists() )
8131
	if ( !File.exists() )
8155
		return false;
8132
		return false;
8156
 
8133
 
8157
	// now read the file for the correct contents
8134
	// now read the file for the correct contents
8158
	std::vector<Utils::String> lines;
8135
	std::vector<Utils::WString> lines;
8159
	if (!File.readLines(lines))
8136
	if (!File.readLines(lines))
8160
		return false;
8137
		return false;
8161
 
8138
 
8162
	// check that one of the lines is correct
8139
	// check that one of the lines is correct
8163
	for(auto itr = lines.begin(); itr != lines.end(); itr++)
8140
	for(auto itr = lines.begin(); itr != lines.end(); itr++)
8164
	{
8141
	{
8165
		if ( *itr == "testing access rights" )
8142
		if ( *itr == L"testing access rights" )
8166
			return true;
8143
			return true;
8167
	}
8144
	}
8168
 
8145
 
8169
	return false;
8146
	return false;
8170
}
8147
}
8171
 
8148
 
8172
size_t CPackages::loadShipData(const Utils::String &file, Utils::CStringList &list) const
8149
size_t CPackages::loadShipData(const Utils::String &file, Utils::CStringList &list) const
8173
{
8150
{
8174
	CFileIO File;
8151
	CFileIO File;
8175
	bool deleteFile = false;
8152
	bool deleteFile = false;
8176
 
8153
 
8177
	// load from cat file
8154
	// load from cat file
8178
	if (CFileIO(file).isFileExtension(L"cat"))
8155
	if (CFileIO(file).isFileExtension(L"cat"))
8179
	{
8156
	{
8180
		CCatFile cat;
8157
		CCatFile cat;
8181
		if (cat.open(file, this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE)
8158
		if (cat.open(file, this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) != CATERR_NONE)
8182
			return false;
8159
			return false;
8183
 
8160
 
8184
		if (!cat.extractFile("types\\TShips.pck", m_sTempDir + "/tships.txt"))
8161
		if (!cat.extractFile("types\\TShips.pck", m_sTempDir + "/tships.txt"))
8185
			return false;
8162
			return false;
8186
 
8163
 
8187
		File.open(m_sTempDir + "/tships.txt");
8164
		File.open(m_sTempDir + "/tships.txt");
8188
		deleteFile = true;
8165
		deleteFile = true;
8189
	}
8166
	}
8190
	// otherwise its a normal file
8167
	// otherwise its a normal file
Line 8195... Line 8172...
8195
			return false;
8172
			return false;
8196
		f.UnPCKFile();
8173
		f.UnPCKFile();
8197
 
8174
 
8198
		f.setFilename(m_sTempDir + "/tships.txt");
8175
		f.setFilename(m_sTempDir + "/tships.txt");
8199
		if (!f.writeFilePointer())
8176
		if (!f.writeFilePointer())
8200
			return false;
8177
			return false;
8201
 
8178
 
8202
		File.open(m_sTempDir + "/tships.txt");
8179
		File.open(m_sTempDir + "/tships.txt");
8203
		deleteFile = true;
8180
		deleteFile = true;
8204
	}
8181
	}
8205
	else
8182
	else
8206
		File.open(file);
8183
		File.open(file);
8207
 
8184
 
8208
	if (!File.exists())
8185
	if (!File.exists())
8209
		return false;
8186
		return false;
8210
 
8187
 
8211
	bool ret = false;
8188
	bool ret = false;
8212
	std::vector<Utils::String> lines;
8189
	std::vector<Utils::String> lines;
8213
	if (File.readLines(lines))
8190
	if (File.readLines(lines))
8214
	{
8191
	{
8215
		bool readFirst = false;
8192
		bool readFirst = false;
8216
		for (auto itr = lines.begin(); itr != lines.end(); itr++)
8193
		for (auto itr = lines.begin(); itr != lines.end(); itr++)
8217
		{
8194
		{
8218
			if (itr->empty())
8195
			if (itr->empty())
8219
				continue;
8196
				continue;
8220
			Utils::String str = itr->remove('\r').remove(9);
8197
			Utils::String str = itr->remove('\r').remove(9);
8221
			str = str.removeFirstSpace();
8198
			str = str.removeFirstSpace();
8222
			if (str.empty())
8199
			if (str.empty())
Line 8258... Line 8235...
8258
	}
8235
	}
8259
 
8236
 
8260
	return Utils::String::Null();
8237
	return Utils::String::Null();
8261
}
8238
}
8262
 
8239
 
8263
bool CPackages::readTextPage(const Utils::String &file, Utils::CStringList &list, bool search, int page) const
8240
bool CPackages::readTextPage(const Utils::WString &file, Utils::WStringList &list, bool search, int page) const
8264
{
8241
{
8265
	CFileIO File;
8242
	CFileIO File;
8266
	bool deleteFile = false;
8243
	bool deleteFile = false;
8267
 
8244
 
8268
	// read all text files from mod
8245
	// read all text files from mod
8269
	if ( CFileIO(file).isFileExtension(L"cat") )
8246
	if ( CFileIO(file).isFileExtension(L"cat") )
8270
	{
8247
	{
8271
		bool done = false;
8248
		bool done = false;
8272
 
8249
 
8273
		CCatFile cat;
8250
		CCatFile cat;
8274
		if ( cat.open(file, this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
8251
		if ( cat.open(file, this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) != CATERR_NONE)
8275
			return false;
8252
			return false;
8276
 
8253
 
8277
		// extract 1 at a time
8254
		// extract 1 at a time
8278
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8255
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8279
		{
8256
		{
8280
			SInCatFile *f = cat.GetFile(i);
8257
			SInCatFile *f = cat.GetFile(i);
8281
			Utils::String sF = f->sFile;
8258
			Utils::WString sF = f->sFile;
8282
			// is a text file
8259
			// is a text file
8283
			sF = sF.findReplace("\\", "/");
8260
			sF = sF.findReplace(L"\\", L"/");
8284
			if ( !sF.token("/", 1).Compare("t") )
8261
			if ( !sF.token(L"/", 1).Compare(L"t") )
8285
				continue;
8262
				continue;
8286
 
8263
 
8287
			Utils::WString baseFile = CFileIO(sF).baseName();
8264
			Utils::WString baseFile = CFileIO(sF).baseName();
8288
			// check language
8265
			// check language
8289
			int lang = 0;
8266
			int lang = 0;
8290
			if ( baseFile.findPos("-L") != -1 ) // new language file
8267
			if ( baseFile.findPos(L"-L") != -1 ) // new language file
8291
				lang = baseFile.right(3).toInt();
8268
				lang = baseFile.right(3).toInt();
8292
			else
8269
			else
8293
			{
8270
			{
8294
				baseFile.truncate((int)baseFile.length() - 4);
8271
				baseFile.truncate((int)baseFile.length() - 4);
8295
				lang = baseFile.toInt();
8272
				lang = baseFile.toInt();
8296
			}
8273
			}
8297
 
8274
 
8298
			if ( lang != m_iLanguage )
8275
			if ( lang != m_iLanguage )
8299
				continue;
8276
				continue;
8300
 
8277
 
8301
			// now extract and parse
8278
			// now extract and parse
8302
			if ( cat.extractFile(f->sFile, m_sTempDir + "/" + CFileIO(f->sFile).baseName().toString() + ".xml"))
8279
			if ( cat.extractFile(f->sFile, m_sTempDir + L"/" + CFileIO(f->sFile).baseName() + L".xml"))
8303
			{
8280
			{
8304
				if ( this->readTextPage(m_sTempDir + "/" + CFileIO(f->sFile).baseName().toString() + ".xml", list, search, page))
8281
				if ( this->readTextPage(m_sTempDir + L"/" + CFileIO(f->sFile).baseName() + L".xml", list, search, page))
8305
					done = true;
8282
					done = true;
8306
			}
8283
			}
8307
		}
8284
		}
8308
 
8285
 
8309
		return done;
8286
		return done;
8310
	}
8287
	}
8311
	// otherwise its a normal file
8288
	// otherwise its a normal file
8312
	else if ( CFileIO(file).isFileExtension(L"pck") )
8289
	else if ( CFileIO(file).isFileExtension(L"pck") )
8313
	{
8290
	{
8314
		C_File f(file);
8291
		C_File f(file);
8315
		if ( !f.ReadFromFile() )
8292
		if ( !f.ReadFromFile() )
8316
			return false;
8293
			return false;
8317
		f.UnPCKFile();
8294
		f.UnPCKFile();
8318
 
8295
 
8319
		f.setFilename(m_sTempDir + "/textfile.xml");
8296
		f.setFilename(m_sTempDir + L"/textfile.xml");
8320
		if ( !f.writeFilePointer() )
8297
		if ( !f.writeFilePointer() )
8321
			return false;
8298
			return false;
8322
 
8299
 
8323
		File.open(m_sTempDir + "/textfile.xml");
8300
		File.open(m_sTempDir + L"/textfile.xml");
8324
		deleteFile = true;
8301
		deleteFile = true;
8325
	}
8302
	}
8326
	else
8303
	else
8327
		File.open(file);
8304
		File.open(file);
8328
 
8305
 
8329
	if ( !File.exists() )
8306
	if ( !File.exists() )
8330
		return false;
8307
		return false;
8331
 
8308
 
8332
	// open and read file
8309
	// open and read file
8333
	std::vector<Utils::String> lines;
8310
	std::vector<Utils::WString> lines;
8334
	if(!File.readLines(lines))
8311
	if(!File.readLines(lines))
8335
		return false;
8312
		return false;
8336
 
8313
 
8337
	bool inPage = false;
8314
	bool inPage = false;
8338
	for(auto itr = lines.begin(); itr != lines.end(); itr++)
8315
	for(auto itr = lines.begin(); itr != lines.end(); itr++)
8339
	{
8316
	{
8340
		// search for page
8317
		// search for page
8341
		if ( !inPage )
8318
		if ( !inPage )
8342
		{
8319
		{
8343
			if (itr->findPos("<page") > -1 )
8320
			if (itr->findPos(L"<page") > -1 )
8344
			{
8321
			{
8345
				// find the page id
8322
				// find the page id
8346
				int pos = itr->findPos("\"");
8323
				int pos = itr->findPos(L"\"");
8347
				if ( pos > -1 )
8324
				if ( pos > -1 )
8348
				{
8325
				{
8349
					int endpos = itr->findPos("\"", pos + 1);
8326
					int endpos = itr->findPos(L"\"", pos + 1);
8350
					if ( endpos > -1 )
8327
					if ( endpos > -1 )
8351
					{
8328
					{
8352
						Utils::String p = itr->mid(pos + 2, endpos - pos - 1);
8329
						Utils::WString p = itr->mid(pos + 2, endpos - pos - 1);
8353
						if ( p.length() > 4 )
8330
						if ( p.length() > 4 )
8354
							p = p.right(4);
8331
							p = p.right(4);
8355
						int checkPage = p.toInt();
8332
						int checkPage = p.toInt();
8356
						if ( checkPage == page )
8333
						if ( checkPage == page )
8357
							inPage = true;
8334
							inPage = true;
Line 8361... Line 8338...
8361
 
8338
 
8362
		}
8339
		}
8363
		// add each id
8340
		// add each id
8364
		else
8341
		else
8365
		{
8342
		{
8366
			if (itr->findPos("</page") > -1 )
8343
			if (itr->findPos(L"</page") > -1 )
8367
				break;
8344
				break;
8368
 
8345
 
8369
			if (itr->findPos("<t id") > -1 )
8346
			if (itr->findPos(L"<t id") > -1 )
8370
			{
8347
			{
8371
				int pos = itr->findPos("\"");
8348
				int pos = itr->findPos(L"\"");
8372
				if ( pos > -1 )
8349
				if ( pos > -1 )
8373
				{
8350
				{
8374
					int endpos = itr->findPos("\"", pos + 1);
8351
					int endpos = itr->findPos(L"\"", pos + 1);
8375
					if ( endpos > -1 )
8352
					if ( endpos > -1 )
8376
					{
8353
					{
8377
						int id = itr->mid(pos + 2, endpos - pos - 1).toInt();
8354
						int id = itr->mid(pos + 2, endpos - pos - 1).toInt();
8378
						pos = itr->findPos(">", endpos);
8355
						pos = itr->findPos(">", endpos);
8379
						if ( pos > -1 )
8356
						if ( pos > -1 )
8380
						{
8357
						{
8381
							++pos;
8358
							++pos;
8382
							endpos = itr->findPos("</", pos);
8359
							endpos = itr->findPos(L"</", pos);
8383
							if ( endpos > -1 )
8360
							if ( endpos > -1 )
8384
							{
8361
							{
8385
								Utils::String text = itr->mid(pos + 1, endpos - pos);
8362
								Utils::WString text = itr->mid(pos + 1, endpos - pos);
8386
								while ( text.findPos('(') != -1 && text.findPos(')') != -1 )
8363
								while ( text.findPos(L'(') != -1 && text.findPos(L')') != -1 )
8387
								{
8364
								{
8388
									int s = text.findPos('(');
8365
									int s = text.findPos(L'(');
8389
									text = text.erase(s, text.findPos(')') - s + 1);
8366
									text = text.erase(s, text.findPos(L')') - s + 1);
8390
								}
8367
								}
8391
								if(!search || !list.contains(Utils::String::Number(id)))
8368
								if(!search || !list.contains(Utils::WString::Number(id)))
8392
									list.pushBack(Utils::String::Number(id), text);
8369
									list.pushBack(Utils::WString::Number(id), text);
8393
							}
8370
							}
8394
						}
8371
						}
8395
					}
8372
					}
8396
				}
8373
				}
8397
			}
8374
			}
Line 8400... Line 8377...
8400
 
8377
 
8401
	return true;
8378
	return true;
8402
}
8379
}
8403
 
8380
 
8404
 
8381
 
8405
FileType CPackages::adjustFileType(const Utils::String &file, FileType filetype) const
8382
FileType CPackages::adjustFileType(const Utils::WString &file, FileType filetype) const
8406
{
8383
{
8407
	CFileIO File(file);
8384
	CFileIO File(file);
8408
	Utils::WString dir = File.GetDirIO().topDir();
8385
	Utils::WString dir = File.GetDirIO().topDir();
8409
	Utils::WString basename = File.baseName();
8386
	Utils::WString basename = File.baseName();
8410
 
8387
 
Line 8430... Line 8407...
8430
	return filetype;
8407
	return filetype;
8431
}
8408
}
8432
 
8409
 
8433
void CPackages::RemoveFailedFiles()
8410
void CPackages::RemoveFailedFiles()
8434
{
8411
{
8435
	Utils::CStringList removed;
8412
	Utils::WStringList removed;
8436
	for (auto itr = m_lNonRemovedFiles.begin(); itr != m_lNonRemovedFiles.end(); itr++)
8413
	for (auto itr = _lNonRemovedFiles.begin(); itr != _lNonRemovedFiles.end(); itr++)
8437
	{
8414
	{
8438
		if (CFileIO::Remove((*itr)->str))
8415
		if (CFileIO::Remove((*itr)->str))
8439
			removed.pushBack((*itr)->str);
8416
			removed.pushBack((*itr)->str);
8440
	}
8417
	}
8441
	for (auto itr = removed.begin(); itr != removed.end(); itr++)
8418
	for (auto itr = removed.begin(); itr != removed.end(); itr++)
8442
		m_lNonRemovedFiles.remove((*itr)->str);
8419
		_lNonRemovedFiles.remove((*itr)->str);
8443
}
8420
}
8444
 
8421
 
8445
CXspFile *CPackages::extractShip(const Utils::String &sCatFile, const Utils::String &sId, CProgressInfo *progress)
8422
CXspFile *CPackages::extractShip(const Utils::String &sCatFile, const Utils::String &sId, CProgressInfo *progress)
8446
{
8423
{
8447
	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
8424
	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
Line 8459... Line 8436...
8459
	delete pVfs;
8436
	delete pVfs;
8460
 
8437
 
8461
	return newShip;
8438
	return newShip;
8462
}
8439
}
8463
 
8440
 
8464
void CPackages::getMergedFiles(Utils::CStringList &list, CCatFile *cat1, CCatFile *cat2) const
8441
void CPackages::getMergedFiles(Utils::WStringList &list, CCatFile *cat1, CCatFile *cat2) const
8465
{
8442
{
8466
	// first add all files from the "primary" mod
8443
	// first add all files from the "primary" mod
8467
	for (auto itr = cat1->GetFiles()->cbegin(); itr != cat1->GetFiles()->cend(); itr++)
8444
	for (auto itr = cat1->GetFiles()->cbegin(); itr != cat1->GetFiles()->cend(); itr++)
8468
		list.pushBack((*itr)->sFile.findReplace("\\", "/"), "1");
8445
		list.pushBack((*itr)->sFile.findReplace(L"\\", L"/"), L"1");
8469
 
8446
 
8470
	// now add the ones from the secondary
8447
	// now add the ones from the secondary
8471
	for (auto itr = cat2->GetFiles()->cbegin(); itr != cat2->GetFiles()->cend(); itr++)
8448
	for (auto itr = cat2->GetFiles()->cbegin(); itr != cat2->GetFiles()->cend(); itr++)
8472
	{
8449
	{
8473
		Utils::String sFile = (*itr)->sFile.findReplace("\\", "/");
8450
		Utils::WString sFile = (*itr)->sFile.findReplace(L"\\", L"/");
8474
		// if its found on the 2nd list, dont add, just adjust the type
8451
		// if its found on the 2nd list, dont add, just adjust the type
8475
		if(!list.changeData(sFile, "-1"))
8452
		if(!list.changeData(sFile, L"-1"))
8476
			list.pushBack(sFile, "2");
8453
			list.pushBack(sFile, L"2");
8477
	}
8454
	}
8478
}
8455
}
8479
 
8456
 
8480
bool CPackages::canWeMerge(const Utils::String &file) const
8457
bool CPackages::canWeMerge(const Utils::WString &file) const
8481
{
8458
{
8482
	return CModDiff::CanBeDiffed(file);
8459
	return CModDiff::CanBeDiffed(file);
8483
}
8460
}
8484
 
8461
 
8485
bool CPackages::needToMerge(const Utils::String &file) const
8462
bool CPackages::needToMerge(const Utils::WString &file) const
8486
{
8463
{
8487
	Utils::String firstDir = file.token("/", 1);
8464
	Utils::WString firstDir = file.token(L"/", 1);
8488
	if ( firstDir.Compare("t") )
8465
	if ( firstDir.Compare(L"t") )
8489
		return true;
8466
		return true;
8490
	if ( firstDir.Compare("types") )
8467
	if ( firstDir.Compare(L"types") )
8491
		return true;
8468
		return true;
8492
	if ( firstDir.Compare("maps") )
8469
	if ( firstDir.Compare(L"maps") )
8493
		return true;
8470
		return true;
8494
 
8471
 
8495
	return false;
8472
	return false;
8496
}
8473
}
8497
 
8474
 
8498
bool CPackages::mergeMods(CCatFile *mod1, CCatFile *mod2, const Utils::String &outFile, Utils::CStringList *cantMerge) const
8475
bool CPackages::mergeMods(CCatFile *mod1, CCatFile *mod2, const Utils::WString &outFile, Utils::WStringList *cantMerge) const
8499
{
8476
{
8500
	CCatFile newCat;
8477
	CCatFile newCat;
8501
	if ( newCat.open(outFile, this->getAddonDir()) != CATERR_CREATED )
8478
	if ( newCat.open(outFile, this->getAddonDir()) != CATERR_CREATED )
8502
		return false;
8479
		return false;
8503
 
8480
 
8504
	Utils::CStringList list;
8481
	Utils::WStringList list;
8505
	this->getMergedFiles(list, mod1, mod2);
8482
	this->getMergedFiles(list, mod1, mod2);
8506
	if (list.empty())
8483
	if (list.empty())
8507
		return false;
8484
		return false;
8508
 
8485
 
8509
	// add all the files to the new mod first
8486
	// add all the files to the new mod first
8510
	Utils::CStringList conflicts;
8487
	Utils::WStringList conflicts;
8511
	for(auto itr = list.begin(); itr != list.end(); itr++)
8488
	for(auto itr = list.begin(); itr != list.end(); itr++)
8512
	{		
8489
	{		
8513
		int status = (*itr)->data.toInt();
8490
		int status = (*itr)->data.toInt();
8514
		if ( status == 1 )
8491
		if ( status == 1 )
8515
		{
8492
		{
8516
			if ( !newCat.writeFromCat(mod1, (*itr)->str) )
8493
			if ( !newCat.writeFromCat(mod1, (*itr)->str) )
8517
			{
8494
			{
8518
				if ( cantMerge )
8495
				if ( cantMerge )
8519
					cantMerge->pushBack((*itr)->str, "1");
8496
					cantMerge->pushBack((*itr)->str, L"1");
8520
			}
8497
			}
8521
		}
8498
		}
8522
		else if ( status == 2 )
8499
		else if ( status == 2 )
8523
		{
8500
		{
8524
			if ( !newCat.writeFromCat(mod2, (*itr)->str) )
8501
			if ( !newCat.writeFromCat(mod2, (*itr)->str) )
8525
			{
8502
			{
8526
				if ( cantMerge )
8503
				if ( cantMerge )
8527
					cantMerge->pushBack((*itr)->str, "2");
8504
					cantMerge->pushBack((*itr)->str, L"2");
8528
			}
8505
			}
8529
		}
8506
		}
8530
		else if ( status == -1 )
8507
		else if ( status == -1 )
8531
		{
8508
		{
8532
			if ( this->needToMerge((*itr)->str) )
8509
			if ( this->needToMerge((*itr)->str) )
8533
			{
8510
			{
8534
				if ( this->canWeMerge((*itr)->str) )
8511
				if ( this->canWeMerge((*itr)->str) )
8535
					conflicts.pushBack((*itr)->str);
8512
					conflicts.pushBack((*itr)->str);
8536
				else if ( cantMerge )
8513
				else if ( cantMerge )
8537
					cantMerge->pushBack((*itr)->str, "-1");
8514
					cantMerge->pushBack((*itr)->str, L"-1");
8538
			}
8515
			}
8539
			else
8516
			else
8540
			{
8517
			{
8541
				if ( !newCat.writeFromCat(mod1, (*itr)->str) )
8518
				if ( !newCat.writeFromCat(mod1, (*itr)->str) )
8542
				{
8519
				{
8543
					if ( cantMerge )
8520
					if ( cantMerge )
8544
						cantMerge->pushBack((*itr)->str, "1");
8521
						cantMerge->pushBack((*itr)->str, L"1");
8545
				}
8522
				}
8546
			}
8523
			}
8547
		}
8524
		}
8548
	}
8525
	}
8549
 
8526
 
8550
	/* 
8527
	/* 
8551
		Merging Files
8528
		Merging Files
8552
 
8529
 
8553
		* Text Files: Join all text entries into a single file (excluding page 17)
8530
		* Text Files: Join all text entries into a single file (excluding page 17)
8554
		* Weapons: TBullets and TLaser (grab matching entrys from text files and adjust ids)
8531
		* Weapons: TBullets and TLaser (grab matching entrys from text files and adjust ids)
8555
	*/
8532
	*/
8556
	// new merge the conflicting files
8533
	// new merge the conflicting files
8557
	// first the text files
8534
	// first the text files
Line 8570... Line 8547...
8570
 *
8547
 *
8571
 * This includes all types and text files
8548
 * This includes all types and text files
8572
 *
8549
 *
8573
 * Returns true if it finds any files
8550
 * Returns true if it finds any files
8574
 */
8551
 */
8575
bool CPackages::getModCompatabilityList(C_File *file, Utils::CStringList *list) const
8552
bool CPackages::getModCompatabilityList(C_File *file, Utils::WStringList *list) const
8576
{
8553
{
8577
	// not a valid file
8554
	// not a valid file
8578
	if ( !file ) return false;
8555
	if ( !file ) return false;
8579
	if ( file->GetFileType() != FILETYPE_MOD ) return false;
8556
	if ( file->GetFileType() != FILETYPE_MOD ) return false;
8580
	if ( !file->fileExt().Compare("cat") ) return false;
8557
	if ( !file->fileExt().Compare(L"cat") ) return false;
8581
 
8558
 
8582
	// we need to read the file list for the mod
8559
	// we need to read the file list for the mod
8583
	CCatFile cat;
8560
	CCatFile cat;
8584
	if ( cat.open(file->filePointer(), this->getAddonDir(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
8561
	if ( cat.open(file->filePointer(), this->getAddonDir().toString(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE)
8585
	{
8562
	{
8586
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8563
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8587
		{
8564
		{
8588
			SInCatFile *f = cat.GetFile(i);
8565
			SInCatFile *f = cat.GetFile(i);
8589
			Utils::String filename = f->sFile;
8566
			Utils::WString filename = f->sFile;
8590
			filename = filename.findReplace("\\", "/");
8567
			filename = filename.findReplace(L"\\", L"/");
8591
			bool found = false;
8568
			bool found = false;
8592
			//TODO: rework this
8569
			//TODO: rework this
8593
			if ( filename.left(2).Compare("t/") || filename.left(6).Compare("types/") )
8570
			if ( filename.left(2).Compare(L"t/") || filename.left(6).Compare(L"types/") )
8594
				found = true;
8571
				found = true;
8595
			else if (filename.left(8).Compare("addon/t/") || filename.left(12).Compare("addon/types/"))
8572
			else if (filename.left(8).Compare(L"addon/t/") || filename.left(12).Compare(L"addon/types/"))
8596
				found = true;
8573
				found = true;
8597
			else if (filename.left(9).Compare("addon2/t/") || filename.left(13).Compare("addon2/types/"))
8574
			else if (filename.left(9).Compare(L"addon2/t/") || filename.left(13).Compare(L"addon2/types/"))
8598
				found = true;
8575
				found = true;
8599
 
8576
 
8600
			if ( found ) {
8577
			if ( found ) {
8601
				if ( list )
8578
				if ( list )
8602
					list->pushBack(filename, Utils::String::Number(f->lSize));
8579
					list->pushBack(filename, Utils::WString::Number(f->lSize));
8603
				else
8580
				else
8604
					return true;
8581
					return true;
8605
			}
8582
			}
8606
		}
8583
		}
8607
	}
8584
	}
8608
 
8585
 
8609
	if ( list && !list->empty() )
8586
	if ( list && !list->empty() )
8610
		return true;
8587
		return true;
8611
 
8588
 
8612
	return false;
8589
	return false;
8613
}
8590
}
8614
 
8591
 
Line 8617... Line 8594...
8617
 *
8594
 *
8618
 * Returns true if theres any files that are not compatable
8595
 * Returns true if theres any files that are not compatable
8619
 *
8596
 *
8620
 * If list is specified, fills up with all files that were found
8597
 * If list is specified, fills up with all files that were found
8621
 */
8598
 */
8622
bool CPackages::checkCompatabilityBetweenModFiles(C_File *from, C_File *to, Utils::CStringList *list) const
8599
bool CPackages::checkCompatabilityBetweenModFiles(C_File *from, C_File *to, Utils::WStringList *list) const
8623
{
8600
{
8624
	// not a valid file
8601
	// not a valid file
8625
	if ( !from || !to ) return false;
8602
	if ( !from || !to ) return false;
8626
	if ( from->GetFileType() != FILETYPE_MOD ) return false;
8603
	if ( from->GetFileType() != FILETYPE_MOD ) return false;
8627
	if ( to->GetFileType() != FILETYPE_MOD ) return false;
8604
	if ( to->GetFileType() != FILETYPE_MOD ) return false;
8628
	if (!from->fileExt().Compare("cat")) return false;
8605
	if (!from->fileExt().Compare(L"cat")) return false;
8629
	if (!to->fileExt().Compare("cat")) return false;
8606
	if (!to->fileExt().Compare(L"cat")) return false;
8630
 
8607
 
8631
	// get file lists from each file
8608
	// get file lists from each file
8632
	Utils::CStringList fromList;
8609
	Utils::WStringList fromList;
8633
	if (getModCompatabilityList(from, &fromList))
8610
	if (getModCompatabilityList(from, &fromList))
8634
	{
8611
	{
8635
		Utils::CStringList toList;
8612
		Utils::WStringList toList;
8636
		if (getModCompatabilityList(to, &toList))
8613
		if (getModCompatabilityList(to, &toList))
8637
		{
8614
		{
8638
			// both have files we need to check, compare them
8615
			// both have files we need to check, compare them
8639
			for(auto itr = fromList.begin(); itr != fromList.end(); itr++)
8616
			for(auto itr = fromList.begin(); itr != fromList.end(); itr++)
8640
			{
8617
			{
8641
				Utils::String fromFile = (*itr)->str;
8618
				Utils::WString fromFile = (*itr)->str;
8642
				fromFile = fromFile.findReplace("\\", "/");
8619
				fromFile = fromFile.findReplace(L"\\", L"/");
8643
				fromFile = fromFile.findReplace("//", "/");
8620
				fromFile = fromFile.findReplace(L"//", L"/");
8644
				for (auto toItr = toList.begin(); toItr != toList.end(); toItr++)
8621
				for (auto toItr = toList.begin(); toItr != toList.end(); toItr++)
8645
				{
8622
				{
8646
					Utils::String toFile = (*toItr)->str;
8623
					Utils::WString toFile = (*toItr)->str;
8647
					toFile = toFile.findReplace("\\", "/");
8624
					toFile = toFile.findReplace(L"\\", L"/");
8648
					toFile = toFile.findReplace("//", "/");
8625
					toFile = toFile.findReplace(L"//", L"/");
8649
					if ( fromFile.Compare(toFile) )
8626
					if ( fromFile.Compare(toFile) )
8650
					{
8627
					{
8651
						if ( list )
8628
						if ( list )
8652
							list->pushBack(from->filename() + "::" + fromFile, to->filename() + "::" + toFile);
8629
							list->pushBack(from->filename() + L"::" + fromFile, to->filename() + L"::" + toFile);
8653
						else
8630
						else
8654
							return true;
8631
							return true;
8655
					}
8632
					}
8656
				}
8633
				}
8657
			}
8634
			}
Line 8662... Line 8639...
8662
		return true;
8639
		return true;
8663
 
8640
 
8664
	return false;
8641
	return false;
8665
}
8642
}
8666
 
8643
 
8667
bool CPackages::checkCompatabilityBetweenMods(CBaseFile *from, CBaseFile *to, Utils::CStringList *list) const
8644
bool CPackages::checkCompatabilityBetweenMods(CBaseFile *from, CBaseFile *to, Utils::WStringList *list) const
8668
{
8645
{
8669
	if ( !from || !to ) return false;
8646
	if ( !from || !to ) return false;
8670
	if ( !from->IsEnabled() || !to->IsEnabled() ) return false;
8647
	if ( !from->IsEnabled() || !to->IsEnabled() ) return false;
8671
	if ( !from->AnyFileType(FILETYPE_MOD) ) return false;
8648
	if ( !from->AnyFileType(FILETYPE_MOD) ) return false;
8672
	if ( !to->AnyFileType(FILETYPE_MOD) ) return false;
8649
	if ( !to->AnyFileType(FILETYPE_MOD) ) return false;
Line 8698... Line 8675...
8698
 
8675
 
8699
	int count = 0;
8676
	int count = 0;
8700
	for ( C_File *f = from->GetFirstFile(FILETYPE_MOD); f; f = from->GetNextFile(f) )
8677
	for ( C_File *f = from->GetFirstFile(FILETYPE_MOD); f; f = from->GetNextFile(f) )
8701
	{
8678
	{
8702
		if ( !f->IsFakePatch() ) continue;
8679
		if ( !f->IsFakePatch() ) continue;
8703
		if ( f->fileExt().Compare("dat") ) continue;
8680
		if ( f->fileExt().Compare(L"dat") ) continue;
8704
 
8681
 
8705
		for ( C_File *compareFile = to->GetFirstFile(FILETYPE_MOD); compareFile; compareFile = to->GetNextFile(compareFile) )
8682
		for ( C_File *compareFile = to->GetFirstFile(FILETYPE_MOD); compareFile; compareFile = to->GetNextFile(compareFile) )
8706
		{
8683
		{
8707
			if ( compareFile == f ) continue; // same file we're checking against
8684
			if ( compareFile == f ) continue; // same file we're checking against
8708
			if ( !compareFile->IsFakePatch() ) continue;
8685
			if ( !compareFile->IsFakePatch() ) continue;
8709
			if ( compareFile->fileExt().Compare("dat") ) continue;
8686
			if ( compareFile->fileExt().Compare(L"dat") ) continue;
8710
 
8687
 
8711
			// now we have to files to compare
8688
			// now we have to files to compare
8712
			if (checkCompatabilityBetweenModFiles(f, compareFile, list))
8689
			if (checkCompatabilityBetweenModFiles(f, compareFile, list))
8713
				++count;
8690
				++count;
8714
		}
8691
		}
Line 8718... Line 8695...
8718
		return true;
8695
		return true;
8719
 
8696
 
8720
	return false;
8697
	return false;
8721
}
8698
}
8722
 
8699
 
8723
int CPackages::checkCompatabilityAgainstPackages(CBaseFile *newFile, Utils::CStringList *list, CLinkList<CBaseFile> *packages) const
8700
int CPackages::checkCompatabilityAgainstPackages(CBaseFile *newFile, Utils::WStringList *list, CLinkList<CBaseFile> *packages) const
8724
{
8701
{
8725
	if ( !newFile->IsEnabled() ) return 0;
8702
	if ( !newFile->IsEnabled() ) return 0;
8726
	if ( !newFile->AnyFileType(FILETYPE_MOD) ) return 0;
8703
	if ( !newFile->AnyFileType(FILETYPE_MOD) ) return 0;
8727
 
8704
 
8728
	// we need to extract all mod files
8705
	// we need to extract all mod files
8729
	for ( CListNode<C_File> *fNode = newFile->GetFileList()->Front(); fNode; fNode = fNode->next() )
8706
	for ( CListNode<C_File> *fNode = newFile->GetFileList()->Front(); fNode; fNode = fNode->next() )
8730
	{
8707
	{
8731
		C_File *f = fNode->Data();
8708
		C_File *f = fNode->Data();
8732
		if ( f->GetFileType() != FILETYPE_MOD ) continue;
8709
		if ( f->GetFileType() != FILETYPE_MOD ) continue;
8733
		if ( !f->IsFakePatch() ) continue;
8710
		if ( !f->IsFakePatch() ) continue;
8734
		if (!f->checkFileExt("cat")) continue;
8711
		if (!f->checkFileExt(L"cat")) continue;
8735
 
8712
 
8736
		if (newFile->extractFile(f, m_sTempDir) )
8713
		if (newFile->extractFile(f, m_sTempDir.toString()) )
8737
			f->setFullDir(m_sTempDir);
8714
			f->setFullDir(m_sTempDir);
8738
	}
8715
	}
8739
 
8716
 
8740
	// compare mod files against all installed packages
8717
	// compare mod files against all installed packages
8741
	int count = 0;
8718
	int count = 0;
Line 8758... Line 8735...
8758
	
8735
	
8759
	for ( CListNode<C_File> *fNode = newFile->GetFileList()->Front(); fNode; fNode = fNode->next() )
8736
	for ( CListNode<C_File> *fNode = newFile->GetFileList()->Front(); fNode; fNode = fNode->next() )
8760
	{
8737
	{
8761
		C_File *f = fNode->Data();
8738
		C_File *f = fNode->Data();
8762
		CFileIO::Remove(f->filePointer());
8739
		CFileIO::Remove(f->filePointer());
8763
		f->setFullDir("");
8740
		f->setFullDir(L"");
8764
	}
8741
	}
8765
 
8742
 
8766
	return count;
8743
	return count;
8767
}
8744
}
8768
 
8745
 
Line 8777... Line 8754...
8777
}
8754
}
8778
 
8755
 
8779
void CPackages::ApplyFakePatchOrder(Utils::CStringList *list)
8756
void CPackages::ApplyFakePatchOrder(Utils::CStringList *list)
8780
{
8757
{
8781
	if ( !list ) return;
8758
	if ( !list ) return;
8782
	m_lFakePatchOrder.clear();
8759
	_lFakePatchOrder.clear();
8783
	for(auto itr = list->begin(); itr != list->end(); itr++)
8760
	for(auto itr = list->begin(); itr != list->end(); itr++)
8784
		m_lFakePatchOrder.pushBack((*itr)->str, (*itr)->data);
8761
		_lFakePatchOrder.pushBack((*itr)->str, (*itr)->data);
8785
}
8762
}
8786
 
8763
 
8787
SAvailablePackage *CPackages::CreateAvailablePackageData(CBaseFile *package)
8764
SAvailablePackage *CPackages::CreateAvailablePackageData(CBaseFile *package)
8788
{
8765
{
8789
	if ( !package ) return NULL;
8766
	if ( !package ) return NULL;
Line 8810... Line 8787...
8810
	else 
8787
	else 
8811
	{
8788
	{
8812
		p->iType = ((CSpkFile *)package)->GetPackageType();
8789
		p->iType = ((CSpkFile *)package)->GetPackageType();
8813
		p->iScriptType = ((CSpkFile *)package)->GetScriptType();
8790
		p->iScriptType = ((CSpkFile *)package)->GetScriptType();
8814
	}
8791
	}
8815
	p->sAuthor = package->author();
8792
	p->sAuthor = package->author().toWString();
8816
	p->sDesc = package->description().findReplace("\n", "::newline::");
8793
	p->sDesc = package->description().toWString().findReplace(L"\n", L"::newline::");
8817
	p->sName = package->name();
8794
	p->sName = package->name().toWString();
8818
	p->sUpdated = package->creationDate();
8795
	p->sUpdated = package->creationDate().toWString();
8819
	p->sVersion = package->version();
8796
	p->sVersion = package->version().toWString();
8820
	p->sFilename = CFileIO(package->filename()).filenameStr();
8797
	p->sFilename = CFileIO(package->filename()).filename();
8821
 
8798
 
8822
	return p;
8799
	return p;
8823
}
8800
}
8824
 
8801
 
8825
Utils::String CPackages::FormatAvailablePackageData(CBaseFile *package)
8802
Utils::WString CPackages::FormatAvailablePackageData(CBaseFile *package)
8826
{
8803
{
8827
	SAvailablePackage *p = CPackages::CreateAvailablePackageData(package);
8804
	SAvailablePackage *p = CPackages::CreateAvailablePackageData(package);
8828
	Utils::String ret = CPackages::FormatAvailablePackageData(p);
8805
	Utils::WString ret = CPackages::FormatAvailablePackageData(p);
8829
	delete p;
8806
	delete p;
8830
	return ret;
8807
	return ret;
8831
}
8808
}
8832
 
8809
 
8833
Utils::String CPackages::FormatAvailablePackageData(SAvailablePackage *package)
8810
Utils::WString CPackages::FormatAvailablePackageData(SAvailablePackage *package)
8834
{
8811
{
8835
	Utils::String ret = (long)package->iType;
8812
	Utils::WString ret = (long)package->iType;
8836
 
8813
 
8837
	Utils::String gameCompat;
8814
	Utils::WString gameCompat;
8838
	for ( CListNode<SGameCompat> *node = package->lGames.Front(); node; node = node->next() ) {
8815
	for ( CListNode<SGameCompat> *node = package->lGames.Front(); node; node = node->next() ) {
8839
		if ( !gameCompat.empty() )
8816
		if ( !gameCompat.empty() )
8840
			gameCompat += "!";
8817
			gameCompat += L"!";
8841
		gameCompat += Utils::String::Number(node->Data()->iGame);
8818
		gameCompat += Utils::WString::Number(node->Data()->iGame);
8842
	}
8819
	}
8843
 
8820
 
8844
	if ( gameCompat.empty() )
8821
	if ( gameCompat.empty() )
8845
		gameCompat = "0";
8822
		gameCompat = L"0";
8846
 
8823
 
8847
	ret = ret.addToken("::", gameCompat);
8824
	ret = ret.addToken(L"::", gameCompat);
8848
	ret = ret.addToken("::", package->sName);
8825
	ret = ret.addToken(L"::", package->sName);
8849
	ret = ret.addToken("::", package->sAuthor);
8826
	ret = ret.addToken(L"::", package->sAuthor);
8850
	ret = ret.addToken("::", package->sVersion);
8827
	ret = ret.addToken(L"::", package->sVersion);
8851
	ret = ret.addToken("::", package->sUpdated);
8828
	ret = ret.addToken(L"::", package->sUpdated);
8852
	ret = ret.addToken("::", package->sFilename);
8829
	ret = ret.addToken(L"::", package->sFilename);
8853
	ret = ret.addToken("::", Utils::String::Number(package->iEase));
8830
	ret = ret.addToken(L"::", Utils::WString::Number(package->iEase));
8854
	ret = ret.addToken("::", Utils::String::Number(package->iChanging));
8831
	ret = ret.addToken(L"::", Utils::WString::Number(package->iChanging));
8855
	ret = ret.addToken("::", Utils::String::Number(package->iRec));
8832
	ret = ret.addToken(L"::", Utils::WString::Number(package->iRec));
8856
	ret = ret.addToken("::", Utils::String::Number(package->iPluginType));
8833
	ret = ret.addToken(L"::", Utils::WString::Number(package->iPluginType));
8857
	ret = ret.addToken("::", Utils::String::Number(package->iScriptType));
8834
	ret = ret.addToken(L"::", Utils::WString::Number(package->iScriptType));
8858
	ret = ret.addToken("::", (package->bSigned) ? "1" : "0");
8835
	ret = ret.addToken(L"::", (package->bSigned) ? L"1" : L"0");
8859
	ret = ret.addToken("::", package->sDesc);
8836
	ret = ret.addToken(L"::", package->sDesc);
8860
 
8837
 
8861
	return ret;
8838
	return ret;
8862
}
8839
}
8863
 
8840
 
8864
void CPackages::parseAvailablePackage(const Utils::String &str, const Utils::String &webaddress)
8841
void CPackages::parseAvailablePackage(const Utils::WString &str, const Utils::WString &webaddress)
8865
{
8842
{
8866
	// first check game
8843
	// first check game
8867
	int num = 0;
8844
	int num = 0;
-
 
8845
	std::vector<Utils::WString> tok;
8868
	Utils::String *tok = str.tokenise("::", &num);
8846
	if (!str.tokenise(L"::", tok))
8869
	if ( !num || !tok ) return;
8847
		return;
8870
	// invalid number of entries?
8848
	// invalid number of entries?
8871
	if ( num < 7 ) { CLEANSPLIT(tok, num); return; }
8849
	if ( num < 7 ) return;
8872
 
8850
 
8873
	SAvailablePackage *p = new SAvailablePackage;
8851
	SAvailablePackage *p = new SAvailablePackage;
8874
	p->iType = tok[0].toLong();
8852
	p->iType = tok[0].toLong();
8875
	p->bSigned = false;
8853
	p->bSigned = false;
8876
 
8854
 
8877
	// theres multiple games, so we need to split it
8855
	// theres multiple games, so we need to split it
8878
	if ( m_iGame ) {
8856
	if ( m_iGame ) {
8879
		Utils::String sGame = tok[1];
8857
		Utils::WString sGame = tok[1];
8880
		if ( sGame.isin("!") ) {
8858
		if ( sGame.contains(L"!") ) {
8881
			for(int i = 1; i <= sGame.countToken("!"); i++) {
8859
			for(int i = 1; i <= sGame.countToken(L"!"); i++) {
8882
				SGameCompat *gc = new SGameCompat;
8860
				SGameCompat *gc = new SGameCompat;
8883
				gc->iVersion = 0;
8861
				gc->iVersion = 0;
8884
				gc->iGame = sGame.token("!", i).toLong();
8862
				gc->iGame = sGame.token(L"!", i).toLong();
8885
				p->lGames.push_back(gc);
8863
				p->lGames.push_back(gc);
8886
			}
8864
			}
8887
		}
8865
		}
8888
		else {
8866
		else {
8889
			SGameCompat *gc = new SGameCompat;
8867
			SGameCompat *gc = new SGameCompat;
Line 8896... Line 8874...
8896
	p->sName = tok[2];
8874
	p->sName = tok[2];
8897
	p->sAuthor = tok[3];
8875
	p->sAuthor = tok[3];
8898
	p->sVersion = tok[4];
8876
	p->sVersion = tok[4];
8899
	p->sUpdated = tok[5];
8877
	p->sUpdated = tok[5];
8900
	p->sFilename = tok[6];
8878
	p->sFilename = tok[6];
8901
 
8879
 
8902
	if ( !webaddress.empty() )
8880
	if ( !webaddress.empty() )
8903
		p->sFilename = webaddress + "/" + p->sFilename;
8881
		p->sFilename = webaddress + L"/" + p->sFilename;
8904
 
8882
 
8905
	p->iChanging = p->iEase = p->iPluginType = p->iRec = p->iScriptType = -1;
8883
	p->iChanging = p->iEase = p->iPluginType = p->iRec = p->iScriptType = -1;
8906
 
8884
 
8907
	// check if we have the extra values
8885
	// check if we have the extra values
8908
	if ( num >= 12 )
8886
	if ( num >= 12 )
Line 8914... Line 8892...
8914
		p->iScriptType = tok[11].toLong();
8892
		p->iScriptType = tok[11].toLong();
8915
		if ( num > 12 ) {
8893
		if ( num > 12 ) {
8916
			if ( num > 13 ) {
8894
			if ( num > 13 ) {
8917
				p->sDesc = tok[13];
8895
				p->sDesc = tok[13];
8918
				p->bSigned = tok[12].toBool();
8896
				p->bSigned = tok[12].toBool();
8919
			}
8897
			}
8920
			else
8898
			else
8921
				p->sDesc = tok[12];
8899
				p->sDesc = tok[12];
8922
		}
8900
		}
8923
	}
8901
	}
8924
	else if ( num > 7 )
8902
	else if ( num > 7 )
8925
		p->sDesc = tok[8];
8903
		p->sDesc = tok[8];
8926
 
8904
 
8927
	if ( !p->sDesc.empty() )
8905
	if ( !p->sDesc.empty() )
8928
		p->sDesc = p->sDesc.findReplace("::newline::", "\\n");
8906
		p->sDesc = p->sDesc.findReplace(L"::newline::", L"\\n");
8929
 
8907
 
8930
	addAvailablePackage(p);
8908
	addAvailablePackage(p);
8931
 
-
 
8932
	CLEANSPLIT(tok, num);
-
 
8933
}
8909
}
8934
 
8910
 
8935
const SAvailablePackage* CPackages::findAvailablePackage(const Utils::String& filename) const
8911
const SAvailablePackage* CPackages::findAvailablePackage(const Utils::WString& filename) const
8936
{
8912
{
8937
	for (CListNode<SAvailablePackage>* node = m_lAvailablePackages.Front(); node; node = node->next())
8913
	for (CListNode<SAvailablePackage>* node = m_lAvailablePackages.Front(); node; node = node->next())
8938
	{
8914
	{
8939
		if (node->Data()->sFilename.Compare(filename))
8915
		if (node->Data()->sFilename.Compare(filename))
8940
			return node->Data();
8916
			return node->Data();
8941
	}
8917
	}
8942
	return NULL;
8918
	return NULL;
8943
}
8919
}
8944
const SAvailablePackage* CPackages::findAvailablePackage(const Utils::String& name, const Utils::String& author) const
8920
const SAvailablePackage* CPackages::findAvailablePackage(const Utils::WString& name, const Utils::WString& author) const
8945
{
8921
{
8946
	for (CListNode<SAvailablePackage>* node = m_lAvailablePackages.Front(); node; node = node->next())
8922
	for (CListNode<SAvailablePackage>* node = m_lAvailablePackages.Front(); node; node = node->next())
8947
	{
8923
	{
8948
		if (node->Data()->sName.Compare(name) && node->Data()->sAuthor.Compare(author))
8924
		if (node->Data()->sName.Compare(name) && node->Data()->sAuthor.Compare(author))
8949
			return node->Data();
8925
			return node->Data();
8950
	}
8926
	}
8951
	return NULL;
8927
	return NULL;
8952
}
8928
}
8953
 
8929
 
8954
CBaseFile* CPackages::findFoundPackage(const Utils::String& name, const Utils::String& author) const
8930
CBaseFile* CPackages::findFoundPackage(const Utils::WString& name, const Utils::WString& author) const
8955
{
8931
{
8956
	for (CListNode<CBaseFile>* node = m_lFoundPackages.Front(); node; node = node->next())
8932
	for (CListNode<CBaseFile>* node = m_lFoundPackages.Front(); node; node = node->next())
8957
	{
8933
	{
8958
		if (node->Data()->name().Compare(name) &&; node->;Data()->author().Compare(author))
8934
		if (node->Data()->name().toWString().Compare(name) &&; node->;Data()->author().toWString().Compare(author))
8959
			return node->Data();
8935
			return node->Data();
8960
	}
8936
	}
8961
	return NULL;
8937
	return NULL;
8962
}
8938
}
8963
 
8939
 
Line 8978... Line 8954...
8978
	}
8954
	}
8979
 
8955
 
8980
	// check if a matching package is already found
8956
	// check if a matching package is already found
8981
	const CBaseFile* bf = findFoundPackage(package->sName, package->sAuthor);
8957
	const CBaseFile* bf = findFoundPackage(package->sName, package->sAuthor);
8982
	if (bf)
8958
	if (bf)
8983
	{
8959
	{
8984
		if (bf->version().compareVersion(package->sVersion) <= 0)
8960
		if (bf->version().toWString().compareVersion(package->sVersion) <= 0)
8985
			return true;		
8961
			return true;		
8986
	}
8962
	}
8987
 
8963
 
8988
	const SAvailablePackage *p = findAvailablePackage(package->sFilename);
8964
	const SAvailablePackage *p = findAvailablePackage(package->sFilename);
8989
	if(p)
8965
	if(p)
8990
	{
8966
	{
8991
		if (p->sVersion.compareVersion(package->sVersion) <= 0)
8967
		if (p->sVersion.compareVersion(package->sVersion) <= 0)
8992
			return true;
8968
			return true;
8993
		m_lAvailablePackages.remove(p);
8969
		m_lAvailablePackages.remove(p);
8994
	}
8970
	}
8995
 
8971
 
8996
	p = findAvailablePackage(package->sName, package->sAuthor);
8972
	p = findAvailablePackage(package->sName, package->sAuthor);
8997
	if (p)
8973
	if (p)
8998
	{
8974
	{
8999
		if (p->sVersion.compareVersion(package->sVersion) <= 0)
8975
		if (p->sVersion.compareVersion(package->sVersion) <= 0)
9000
			return true;
8976
			return true;
9001
		m_lAvailablePackages.remove(p);
8977
		m_lAvailablePackages.remove(p);
9002
	}
8978
	}
9003
 
8979
 
9004
	m_lAvailablePackages.push_back(package); 
8980
	m_lAvailablePackages.push_back(package); 
9005
	saveAvailablePackages();
8981
	saveAvailablePackages();
9006
	return true;
8982
	return true;
9007
}
8983
}
9008
 
8984
 
9009
void CPackages::saveAvailablePackages()
8985
void CPackages::saveAvailablePackages()
9010
{
8986
{
9011
	std::vector<Utils::String> lines;
8987
	std::vector<Utils::WString> lines;
9012
 
8988
 
9013
	lines.push_back("Version;1;" + Utils::String::Number(m_lAvailablePackages.size()));
8989
	lines.push_back(L"Version;1;" + Utils::WString::Number(m_lAvailablePackages.size()));
9014
 
8990
 
9015
	for (auto itr = m_lAvailablePackages.First(); itr; itr = m_lAvailablePackages.Next())
8991
	for (auto itr = m_lAvailablePackages.First(); itr; itr = m_lAvailablePackages.Next())
9016
	{
8992
	{
9017
		Utils::String l = "Package";
8993
		Utils::WString l = L"Package";
9018
		l += ";" + itr->sName.findReplace(";", ":&COL&:");
8994
		l += L";" + itr->sName.findReplace(L";", L":&COL&:");
9019
		l += ";" + itr->sAuthor.findReplace(";", ":&COL&:");
8995
		l += L";" + itr->sAuthor.findReplace(L";", L":&COL&:");
9020
		l += ";" + itr->sVersion.findReplace(";", ":&COL&:");
8996
		l += L";" + itr->sVersion.findReplace(L";", L":&COL&:");
9021
		l += ";" + itr->sFilename;
8997
		l += L";" + itr->sFilename;
9022
		l += ";" + itr->sDesc.findReplace(";", ":&COL&:");
8998
		l += L";" + itr->sDesc.findReplace(L";", L":&COL&:");
9023
		l += ";" + itr->sUpdated;
8999
		l += L";" + itr->sUpdated;
-
 
9000
 
-
 
9001
		l += L";" + Utils::WString::Number(itr->lGames.size());
-
 
9002
 
-
 
9003
		for (auto g = itr->lGames.First(); g; g = itr->lGames.Next())
-
 
9004
			l += L";" + Utils::WString::Number(g->iGame) + L";" + Utils::WString::Number(g->iVersion) + L";" + g->sVersion;
9024
 
9005
 
9025
		l += ";" + Utils::String::Number(itr->lGames.size());
-
 
9026
 
-
 
9027
		for (auto g = itr->lGames.First(); g; g = itr->lGames.Next())
-
 
9028
			l += ";" + Utils::String::Number(g->iGame) + ";" + Utils::String::Number(g->iVersion) + ";" + g->sVersion;
-
 
9029
 
-
 
9030
		l += ";" + Utils::String::Number(itr->iType);
9006
		l += L";" + Utils::WString::Number(itr->iType);
9031
		l += ";" + Utils::String::Number(itr->iPluginType);
9007
		l += L";" + Utils::WString::Number(itr->iPluginType);
9032
		l += ";" + Utils::String::Number(itr->iScriptType);
9008
		l += L";" + Utils::WString::Number(itr->iScriptType);
9033
		l += ";" + Utils::String::Number(itr->iChanging);
9009
		l += L";" + Utils::WString::Number(itr->iChanging);
9034
		l += ";" + Utils::String::Number(itr->iEase);
9010
		l += L";" + Utils::WString::Number(itr->iEase);
9035
		l += ";" + Utils::String::Number(itr->iRec);
9011
		l += L";" + Utils::WString::Number(itr->iRec);
9036
		l += itr->bSigned ? ";1" : ";0";
9012
		l += itr->bSigned ? L";1" : L";0";
9037
 
9013
 
9038
		lines.push_back(l);
9014
		lines.push_back(l);
9039
	}
9015
	}
9040
 
9016
 
9041
	// write out the file
9017
	// write out the file
9042
	CDirIO dir(m_sCurrentDir + "/PluginManager");
9018
	CDirIO dir(m_sCurrentDir + L"/PluginManager");
9043
	if (!dir.exists())
9019
	if (!dir.exists())
9044
		dir.create();
9020
		dir.create();
9045
	CFileIO file(dir.file("packagecache.new"));
9021
	CFileIO file(dir.file(L"packagecache.new"));
9046
	if (file.writeFile(&lines))
9022
	if (file.writeFile(lines))
9047
	{
9023
	{
9048
		if (CFileIO::Exists(dir.file("packagecache.new")))
9024
		if (CFileIO::Exists(dir.file(L"packagecache.new")))
9049
		{
9025
		{
9050
			if (CFileIO::Exists(dir.file("packagecache.dat")))
9026
			if (CFileIO::Exists(dir.file(L"packagecache.dat")))
9051
				CFileIO::Remove(dir.file("packagecache.dat"));
9027
				CFileIO::Remove(dir.file(L"packagecache.dat"));
9052
			file.Rename(dir.file("packagecache.dat"));
9028
			file.Rename(dir.file(L"packagecache.dat"));
9053
		}
9029
		}
9054
	}
9030
	}
9055
}
9031
}
9056
 
9032
 
9057
void CPackages::readAvailablePackages()
9033
void CPackages::readAvailablePackages()
9058
{
9034
{
9059
	m_lAvailablePackages.MemoryClear();
9035
	m_lAvailablePackages.MemoryClear();
9060
 
9036
 
9061
	CDirIO dir(m_sCurrentDir + "/PluginManager");
9037
	CDirIO dir(m_sCurrentDir + L"/PluginManager");
9062
	CFileIO file(dir.file("packagecache.dat"));
9038
	CFileIO file(dir.file(L"packagecache.dat"));
9063
 
9039
 
9064
	if (file.exists())
9040
	if (file.exists())
9065
	{
9041
	{
9066
 
-
 
9067
		size_t version = 0;
9042
		size_t version = 0;
9068
		size_t count = 0;
9043
		size_t count = 0;
9069
		std::vector<Utils::String> lines;
9044
		std::vector<Utils::WString> lines;
9070
		if (file.readLines(lines))
9045
		if (file.readLines(lines))
9071
		{
9046
		{
9072
			for (auto itr = lines.begin(); itr != lines.end(); itr++)
9047
			for (auto itr = lines.begin(); itr != lines.end(); itr++)
9073
			{
9048
			{
9074
				Utils::String cmd = itr->token(";", 1);
9049
				Utils::WString cmd = itr->token(L";", 1);
9075
				if (cmd == "Version")
9050
				if (cmd == L"Version")
9076
				{
9051
				{
9077
					version = itr->token(";", 2).toInt();
9052
					version = itr->token(L";", 2).toInt();
9078
					count = itr->token(";", 3).toInt();
9053
					count = itr->token(L";", 3).toInt();
9079
				}
9054
				}
9080
				else if (cmd == "Package")
9055
				else if (cmd == L"Package")
9081
				{
9056
				{
9082
					int max = 0;
9057
					int max = 0;
-
 
9058
					std::vector<Utils::WString> str;
9083
					Utils::String *str = itr-&gt;tokenise(";", &max);
9059
					itr-&gt;tokenise(L";", str);
9084
 
9060
 
9085
					SAvailablePackage* package = new SAvailablePackage;
9061
					SAvailablePackage* package = new SAvailablePackage;
9086
					int pos = 1;
9062
					int pos = 1;
9087
					package->sName = str[pos++].findReplace(":&COL&:", ";");
9063
					package->sName = str[pos++].findReplace(L":&COL&:", L";");
9088
					package->sAuthor = str[pos++].findReplace(":&COL&:", ";");
9064
					package->sAuthor = str[pos++].findReplace(L":&COL&:", L";");
9089
					package->sVersion = str[pos++].findReplace(":&COL&:", ";");
9065
					package->sVersion = str[pos++].findReplace(L":&COL&:", L";");
9090
					package->sFilename = str[pos++].findReplace(":&COL&:", ";");
9066
					package->sFilename = str[pos++].findReplace(L":&COL&:", L";");
9091
					package->sDesc = str[pos++].findReplace(":&COL&:", ";");
9067
					package->sDesc = str[pos++].findReplace(L":&COL&:", L";");
9092
					package->sUpdated = str[pos++].findReplace(":&COL&:", ";");
9068
					package->sUpdated = str[pos++].findReplace(L":&COL&:", L";");
9093
 
9069
 
9094
					size_t games = str[pos++].toInt();
9070
					size_t games = str[pos++].toInt();
9095
					for (size_t i = 0; i < games; i++)
9071
					for (size_t i = 0; i < games; i++)
9096
					{
9072
					{
9097
						SGameCompat* g = new SGameCompat;
9073
						SGameCompat* g = new SGameCompat;
Line 9105... Line 9081...
9105
					package->iPluginType = str[pos++].toInt();
9081
					package->iPluginType = str[pos++].toInt();
9106
					package->iScriptType = str[pos++].toInt();
9082
					package->iScriptType = str[pos++].toInt();
9107
					package->iChanging = str[pos++].toInt();
9083
					package->iChanging = str[pos++].toInt();
9108
					package->iEase = str[pos++].toInt();
9084
					package->iEase = str[pos++].toInt();
9109
					package->iRec = str[pos++].toInt();
9085
					package->iRec = str[pos++].toInt();
9110
					package->bSigned = (str[pos] == "1");
9086
					package->bSigned = (str[pos] == L"1");
9111
 
-
 
9112
					CLEANSPLIT(str, max);
-
 
9113
 
9087
 
9114
					addAvailablePackage(package);
9088
					addAvailablePackage(package);
9115
				}
9089
				}
9116
			}
9090
			}
9117
		}
9091
		}
Line 9149... Line 9123...
9149
					list->pushBack((*itr)->str);
9123
					list->pushBack((*itr)->str);
9150
			}
9124
			}
9151
		}
9125
		}
9152
	}
9126
	}
9153
 
9127
 
9154
	CFileIO File("data\\web");
9128
	CFileIO File(L"data\\web");
9155
 
9129
 
9156
	if ( File.startRead() ) {
9130
	if ( File.startRead() ) {
9157
		while(!File.atEnd()) {
9131
		while(!File.atEnd()) {
9158
			Utils::String line = File.readEndOfLine();
9132
			Utils::String line = File.readEndOfLineStr();
9159
			line.removeChar("\n\r\t ");
9133
			line.removeChar("\n\r\t ");
9160
			if (!line.empty())
9134
			if (!line.empty())
9161
			{
9135
			{
9162
				if(!list->contains(line))
9136
				if(!list->contains(line))
9163
					list->pushBack(line);
9137
					list->pushBack(line);
Line 9181... Line 9155...
9181
	size_t size;
9155
	size_t size;
9182
	char *data = CFileIO(filename).ReadToData(&size);
9156
	char *data = CFileIO(filename).ReadToData(&size);
9183
	if ( size && data )
9157
	if ( size && data )
9184
		readArchiveData(data, size, archive);
9158
		readArchiveData(data, size, archive);
9185
}
9159
}
9186
 
9160
 
9187
void CPackages::readArchiveData(const char *buf, size_t len, CBaseFile *archive) const
9161
void CPackages::readArchiveData(const char *buf, size_t len, CBaseFile *archive) const
9188
{
9162
{
9189
	Utils::CStringList otherGames;
9163
	Utils::WStringList otherGames;
9190
	Utils::CStringList gameAddons;
9164
	Utils::WStringList gameAddons;
9191
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
9165
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
9192
	{
9166
	{
9193
		SGameExe *exe = m_gameExe.GetGame(i);
9167
		SGameExe *exe = m_gameExe.game(i);
9194
		if (!exe->sAddon.empty())
9168
		if (!exe->sAddon.empty())
9195
			gameAddons.pushBack(Utils::String::Number(i + 1), exe->sAddon);
9169
			gameAddons.pushBack(Utils::WString::Number(i + 1), exe->sAddon);
9196
	}
9170
	}
9197
 
9171
 
9198
	Utils::String data(buf);
9172
	Utils::WString data(buf);
9199
	int max;
-
 
9200
	Utils::String *str = data.tokenise("\n", &amp;max);
9173
	std::vector<Utils::WString&gt; str;
9201
	if ( str &&amp; max )
9174
	if(data.tokenise(L&quot;\n", str))
9202
	{
9175
	{
9203
		for ( int i = 0; i < max; i++ )
9176
		for(size_t i = 0; i < str.size(); i++ )
9204
		{
9177
		{
9205
			Utils::String line = str[i];
9178
			Utils::WString line = str[i];
9206
			if ( line.empty() )
9179
			if ( line.empty() )
9207
				continue;
9180
				continue;
9208
 
9181
 
9209
			// filter out any spaces, tabs in front
9182
			// filter out any spaces, tabs in front
9210
			line.removeChar('\t');
9183
			line.removeChar('\t');
9211
			line.removeChar('\r');
9184
			line.removeChar('\r');
9212
			Utils::String linenospace = line;
9185
			Utils::WString linenospace = line;
9213
			linenospace.removeFirstSpace();
9186
			linenospace.removeFirstSpace();
9214
			if ( linenospace.empty() )
9187
			if ( linenospace.empty() )
9215
				continue;
9188
				continue;
9216
 
9189
 
9217
			// check for any comments
9190
			// check for any comments
9218
			if ( linenospace.left(2) == "//" )
9191
			if ( linenospace.left(2) == L"//" )
9219
				continue;
9192
				continue;
9220
			if ( linenospace[0] == '#' )
9193
			if ( linenospace[0] == L'#' )
9221
				continue;
9194
				continue;
9222
 
9195
 
9223
			// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
9196
			// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
9224
			if ( !line.contains(':'))
9197
			if ( !line.contains(':'))
9225
				continue;
9198
				continue;
9226
 
9199
 
9227
			Utils::String first = line.token(":", 1);
9200
			Utils::WString first = line.token(L":", 1);
9228
			Utils::String rest = line.tokens(":", 2).removeFirstSpace();
9201
			Utils::WString rest = line.tokens(L":", 2).removeFirstSpace();
9229
 
9202
 
9230
			Utils::String checkType = first;
9203
			Utils::WString checkType = first;
9231
			bool shared = false;
9204
			bool shared = false;
9232
			if ( checkType.left(6).Compare("Shared") )
9205
			if ( checkType.left(6).Compare(L"Shared") )
9233
			{
9206
			{
9234
				checkType = first.right(-6);
9207
				checkType = first.right(-6);
9235
				shared = true;
9208
				shared = true;
9236
			}
9209
			}
9237
			bool packed = false;
9210
			bool packed = false;
9238
			if (checkType.right(3).compare("PCK"))
9211
			if (checkType.right(3).compare(L"PCK"))
9239
			{
9212
			{
9240
				checkType = checkType.left(-3);
9213
				checkType = checkType.left(-3);
9241
				packed = true;
9214
				packed = true;
9242
			}
9215
			}
9243
 
9216
 
9244
			// now check type name
9217
			// now check type name
9245
			int filetype = GetFileTypeFromString(checkType);
9218
			int filetype = GetFileTypeFromString(checkType);
9246
			if (filetype == -1)
9219
			if (filetype == -1)
9247
			{
9220
			{
9248
				archive->LoadPackageData(first, rest, Utils::String::Null(), otherGames, gameAddons, NULL);
9221
				archive->loadPackageData(first, rest, Utils::WString::Null(), otherGames, gameAddons, NULL);
9249
			}
9222
			}
9250
		}
9223
		}
9251
	}
9224
	}
9252
 
-
 
9253
	CLEANSPLIT(str, max)
-
 
9254
}
9225
}
9255
 
9226
 
9256
CBaseFile *CPackages::_archive_fromRar(const Utils::String &filename, bool toInstall) const
9227
CBaseFile *CPackages::_archive_fromRar(const Utils::String &filename, bool toInstall) const
9257
{
9228
{
9258
	// make sure we can open the zip file
9229
	// make sure we can open the zip file
Line 9307... Line 9278...
9307
 
9278
 
9308
	bool error = false;
9279
	bool error = false;
9309
	Utils::WString extractedFile = CDirIO(m_sTempDir).file("extracted.tst").findReplace(L"/", L"\\").findReplace(L"\\\\", L"\\");
9280
	Utils::WString extractedFile = CDirIO(m_sTempDir).file("extracted.tst").findReplace(L"/", L"\\").findReplace(L"\\\\", L"\\");
9310
	while ((RHCode=RARReadHeaderEx(hArcData,&HeaderData))==0)
9281
	while ((RHCode=RARReadHeaderEx(hArcData,&HeaderData))==0)
9311
	{
9282
	{
9312
		Utils::String fileName = HeaderData.FileName;
9283
		Utils::WString fileName = HeaderData.FileName;
9313
 
9284
 
9314
		if ( HeaderData.FileAttr == 16 )
9285
		if ( HeaderData.FileAttr == 16 )
9315
			continue;
9286
			continue;
9316
		PFCode=RARProcessFileW(hArcData, RAR_EXTRACT, NULL, NULL);
9287
		PFCode=RARProcessFileW(hArcData, RAR_EXTRACT, NULL, NULL);
9317
		if (PFCode!=0)
9288
		if (PFCode!=0)
Line 9321... Line 9292...
9321
		}
9292
		}
9322
 
9293
 
9323
		CFileIO File(fileName);
9294
		CFileIO File(fileName);
9324
		if ( File.exists() )
9295
		if ( File.exists() )
9325
		{
9296
		{
9326
			if ( fileName.Compare("pluginmanager.txt") )
9297
			if ( fileName.Compare(L"pluginmanager.txt") )
9327
				this->readArchiveData(File.fullFilenameStr(), archive);
9298
				this->readArchiveData(File.fullFilenameStr(), archive);
9328
			else
9299
			else
9329
			{
9300
			{
9330
				Utils::String extradir;
9301
				Utils::WString extradir;
9331
				int type = SPK::GetAutomaticFiletype(fileName, &extradir, true);
9302
				int type = SPK::GetAutomaticFiletype(fileName, &extradir, true);
9332
				// check for special file types
9303
				// check for special file types
9333
				C_File *f = NULL;
9304
				C_File *f = NULL;
9334
 
9305
 
9335
				if ( type == FILETYPE_SCRIPT_UNINSTALL ) {
9306
				if ( type == FILETYPE_SCRIPT_UNINSTALL ) {
9336
					f = archive->addFile(CFileIO(fileName).filenameStr(), "", FILETYPE_SCRIPT);
9307
					f = archive->addFile(CFileIO(fileName).filename(), L"", FILETYPE_SCRIPT);
9337
					if ( f ) {
9308
					if ( f ) {
9338
						f->readFromFile(File.fullFilenameStr());
9309
						f->readFromFile(File.fullFilename());
9339
					}
9310
					}
9340
					type = FILETYPE_UNINSTALL;
9311
					type = FILETYPE_UNINSTALL;
9341
				}
9312
				}
9342
 
9313
 
9343
				if ( type == -1 )
9314
				if ( type == -1 )
9344
					f = archive->addFile(CFileIO(fileName).filenameStr(), CFileIO(fileName).dirStr(), FILETYPE_EXTRA);
9315
					f = archive->addFile(CFileIO(fileName).filename(), CFileIO(fileName).dir(), FILETYPE_EXTRA);
9345
				else
9316
				else
9346
					f = archive->addFile(CFileIO(fileName).filenameStr(), extradir, static_cast<FileType>(type));
9317
					f = archive->addFile(CFileIO(fileName).filename(), extradir, static_cast<FileType>(type));
9347
				f->readFromFile(File.fullFilenameStr());
9318
				f->readFromFile(File.fullFilenameStr());
9348
			}
9319
			}
9349
 
9320
 
9350
			File.remove();
9321
			File.remove();
9351
		}
9322
		}
9352
	}
9323
	}
9353
 
9324
 
9354
	RARCloseArchive(hArcData);
9325
	RARCloseArchive(hArcData);
9355
 
9326
 
9356
	if ( error )
9327
	if ( error )
9357
	{
9328
	{
9358
		delete archive;
9329
		delete archive;
9359
		archive = NULL;
9330
		archive = NULL;
Line 9381... Line 9352...
9381
	CloseZip(hz);
9352
	CloseZip(hz);
9382
 
9353
 
9383
	hz = OpenZip(buf, 0);
9354
	hz = OpenZip(buf, 0);
9384
	if ( !hz ) 
9355
	if ( !hz ) 
9385
		return NULL;
9356
		return NULL;
9386
 
9357
 
9387
	// create the correct package
9358
	// create the correct package
9388
	if ( toInstall )
9359
	if ( toInstall )
9389
		archive = new CArchiveFile(); // just installing an archive file
9360
		archive = new CArchiveFile(); // just installing an archive file
9390
	else
9361
	else
9391
		archive = new CSpkFile(); // converting to a spk file
9362
		archive = new CSpkFile(); // converting to a spk file
9392
 
9363
 
9393
	GetZipItem(hz, -1, &ze);
9364
	GetZipItem(hz, -1, &ze);
9394
	int numitems = ze.index;
9365
	int numitems = ze.index;
9395
 
9366
 
9396
	bool error = false;
9367
	bool error = false;
9397
	for ( int zi = 0; zi < numitems; zi++ )
9368
	for ( int zi = 0; zi < numitems; zi++ )
9398
	{
9369
	{
9399
		ZIPENTRY ze;
9370
		ZIPENTRY ze;
9400
		if ( GetZipItem(hz, zi, &ze) != Z_OK )
9371
		if ( GetZipItem(hz, zi, &ze) != Z_OK )
9401
		{
9372
		{
9402
			error = true;
9373
			error = true;
9403
			break;
9374
			break;
9404
		}
9375
		}
9405
 
9376
 
9406
		if ( ze.attr & FILE_ATTRIBUTE_DIRECTORY )
9377
		if ( ze.attr & FILE_ATTRIBUTE_DIRECTORY )
9407
			continue; // dont do directories
9378
			continue; // dont do directories
9408
 
9379
 
9409
 
9380
 
9410
		char *iBuf = new char[ze.unc_size];
9381
		char *iBuf = new char[ze.unc_size];
9411
		UnzipItem(hz, zi, iBuf, ze.unc_size);
9382
		UnzipItem(hz, zi, iBuf, ze.unc_size);
9412
 
9383
 
9413
		Utils::String Name(ze.name);
9384
		Utils::String Name(ze.name);
9414
 
9385
 
9415
		// if its the data file, dont add it, but extract to get settings from
9386
		// if its the data file, dont add it, but extract to get settings from
9416
		if ( Name.Compare("pluginmanager.txt") )
9387
		if ( Name.Compare("pluginmanager.txt") )
9417
		{
9388
		{
9418
			this->readArchiveData(iBuf, ze.unc_size, archive);
9389
			this->readArchiveData(iBuf, ze.unc_size, archive);
9419
			delete[] iBuf;
9390
			delete[] iBuf;
9420
		}
9391
		}
9421
		else
9392
		else
9422
		{
9393
		{
9423
			Utils::String extradir;
9394
			Utils::WString extradir;
9424
			int type = SPK::GetAutomaticFiletype(Name, &extradir, true);
9395
			int type = SPK::GetAutomaticFiletype(Name, &extradir, true);
9425
 
9396
 
9426
			C_File *f = NULL;
9397
			C_File *f = NULL;
9427
 
9398
 
9428
			Utils::String filename = CFileIO(Name).filenameStr();
9399
			Utils::WString filename = CFileIO(Name).filename();
9429
			Utils::String dir = CFileIO(Name).dirStr();
9400
			Utils::WString dir = CFileIO(Name).dir();
9430
 
9401
 
9431
			// check for special file types
9402
			// check for special file types
9432
			if ( type == FILETYPE_SCRIPT_UNINSTALL ) {
9403
			if ( type == FILETYPE_SCRIPT_UNINSTALL ) {
9433
				f = archive->addFile(filename, dir, FILETYPE_SCRIPT);
9404
				f = archive->addFile(filename, dir, FILETYPE_SCRIPT);
9434
				if ( f ) {
9405
				if ( f ) {
Line 9439... Line 9410...
9439
 
9410
 
9440
			int game = 0;
9411
			int game = 0;
9441
			// check for addons
9412
			// check for addons
9442
			if (dir.contains('/', true)) 
9413
			if (dir.contains('/', true)) 
9443
			{
9414
			{
9444
				Utils::String first = dir.token("/", 1);
9415
				Utils::WString first = dir.token(L"/", 1);
9445
				int g = m_gameExe.findAddonType(first);
9416
				int g = m_gameExe.findAddonType(first);
9446
				if (g != -1)
9417
				if (g != -1)
9447
					game = g + 1;
9418
					game = g + 1;
9448
			}
9419
			}
9449
 
9420
 
Line 9463... Line 9434...
9463
 
9434
 
9464
	if ( error )
9435
	if ( error )
9465
	{
9436
	{
9466
		delete archive;
9437
		delete archive;
9467
		archive = NULL;
9438
		archive = NULL;
9468
	}
9439
	}
9469
	return archive;
9440
	return archive;
9470
}
9441
}
9471
 
9442
 
9472
CBaseFile *CPackages::createFromArchive(const Utils::String &filename, bool toInstall) const
9443
CBaseFile *CPackages::createFromArchive(const Utils::String &filename, bool toInstall) const
9473
{
9444
{
9474
	// make sure we can open the zip file
9445
	// make sure we can open the zip file
Line 9487... Line 9458...
9487
	}
9458
	}
9488
 
9459
 
9489
	return archive;
9460
	return archive;
9490
}
9461
}
9491
 
9462
 
9492
Utils::String CPackages::CreateFromPackagerScript(CPackages *packages, const Utils::String &filename)
9463
Utils::WString CPackages::CreateFromPackagerScript(CPackages *packages, const Utils::WString &filename)
9493
{
9464
{
9494
	Utils::String curDir = CFileIO(filename).dirStr();
9465
	Utils::WString curDir = CFileIO(filename).dir();
9495
	Utils::CStringList variables;
9466
	Utils::WStringList variables;
9496
	variables.pushBack("$PATH", curDir);
9467
	variables.pushBack(L"$PATH", curDir);
9497
	CBaseFile *package = packages->LoadPackagerScript(filename, NULL, NULL, NULL, &variables);
9468
	CBaseFile *package = packages->loadPackagerScript(filename, NULL, NULL, NULL, &variables);
9498
 
9469
 
9499
	if ( !package )
9470
	if ( !package )
9500
		return Utils::String::Null();
9471
		return Utils::String::Null();
9501
 
9472
 
9502
	Utils::String saveto = package->filename();
9473
	Utils::WString saveto = package->filename();
9503
	saveto = saveto.findReplace("$DEFAULTDIR", curDir + "/");
9474
	saveto = saveto.findReplace(L"$DEFAULTDIR", curDir + L"/");
9504
	saveto = saveto.findReplace("$PATH", curDir);
9475
	saveto = saveto.findReplace(L"$PATH", curDir);
9505
	saveto = saveto.findReplace("\\", "/");
9476
	saveto = saveto.findReplace(L"\\", L"/");
9506
	saveto = saveto.findReplace("//", "/");
9477
	saveto = saveto.findReplace(L"//", L"/");
9507
	if ( !saveto.right(4).Compare(".spk") && package->GetType() != TYPE_XSP )
9478
	if ( !saveto.right(4).Compare(L".spk") && package->GetType() != TYPE_XSP )
9508
		saveto += ".spk";
9479
		saveto += L".spk";
9509
	else if ( !saveto.right(4).Compare(".xsp") && package->GetType() == TYPE_XSP )
9480
	else if ( !saveto.right(4).Compare(L".xsp") && package->GetType() == TYPE_XSP )
9510
		saveto += ".xsp";
9481
		saveto += L".xsp";
9511
 
9482
 
9512
	// write script
9483
	// write script
9513
	if ( package->writeFile(saveto) )
9484
	if ( package->writeFile(saveto.toString()) )
9514
	{
9485
	{
9515
		if ( package->AutoGenerateUpdateFile() )
9486
		if ( package->AutoGenerateUpdateFile() )
9516
			package->createUpdateFile(CFileIO(saveto).dir());
9487
			package->createUpdateFile(CFileIO(saveto).dir());
9517
		return saveto;
9488
		return saveto;
9518
	}
9489
	}
9519
 
9490
 
9520
	return Utils::String::Null();
9491
	return Utils::String::Null();
9521
}
9492
}
9522
 
9493
 
9523
int CPackages::GeneratePackageUpdateData(const Utils::String &dir, bool includeSingle)
9494
int CPackages::GeneratePackageUpdateData(const Utils::WString &dir, bool includeSingle)
9524
{
9495
{
9525
	Utils::CStringList filedata;
9496
	Utils::WStringList filedata;
9526
 
9497
 
9527
	CPackages packages;
9498
	CPackages packages;
9528
 
9499
 
9529
	CDirIO Dir(dir);
9500
	CDirIO Dir(dir);
9530
	for ( int i = 0; i < 2; i++ )
9501
	for ( int i = 0; i < 2; i++ )
9531
	{
9502
	{
9532
		Utils::String pattern;
9503
		Utils::WString pattern;
9533
		if ( i == 0 ) pattern = "*.spk";
9504
		if ( i == 0 ) pattern = L"*.spk";
9534
		else if ( i == 1 ) pattern = ".xsp";
9505
		else if ( i == 1 ) pattern = L".xsp";
9535
		else break;
9506
		else break;
9536
 
9507
 
9537
		Utils::CStringList files;
9508
		Utils::WStringList files;
9538
		if(Dir.dirList(files, "", pattern))
9509
		if(Dir.dirList(files, L"", pattern))
9539
		{
9510
		{
9540
			for(auto itr = files.begin(); itr != files.end(); itr++)
9511
			for(auto itr = files.begin(); itr != files.end(); itr++)
9541
			{
9512
			{
9542
				int error = 0;
9513
				int error = 0;
9543
				CBaseFile *p = packages.openPackage(Dir.file((*itr)->str).toString(), &error, 0, SPKREAD_NODATA);
9514
				CBaseFile *p = packages.openPackage(Dir.file((*itr)->str), &error, 0, SPKREAD_NODATA);
9544
				if ( !p )
9515
				if ( !p )
9545
					continue;
9516
					continue;
9546
 
9517
 
9547
				if ( includeSingle )
9518
				if ( includeSingle )
9548
					p->createUpdateFile(dir);
9519
					p->createUpdateFile(dir);
Line 9552... Line 9523...
9552
		}
9523
		}
9553
	}
9524
	}
9554
 
9525
 
9555
	if ( !filedata.empty() )
9526
	if ( !filedata.empty() )
9556
	{
9527
	{
9557
		CFileIO File(dir + "/xpackagedata.dat");
9528
		CFileIO File(dir + L"/xpackagedata.dat");
9558
		if ( File.writeFile(&filedata) )
9529
		if ( File.writeFile(&filedata) )
9559
			return filedata.size();
9530
			return filedata.size();
9560
	}
9531
	}
9561
 
9532
 
9562
	return 0;
9533
	return 0;
9563
}
9534
}
9564
 
9535
 
9565
size_t CPackages::verifyInstalledFiles(Utils::CStringList *missingFiles, bool getPackages) const
9536
size_t CPackages::verifyInstalledFiles(Utils::WStringList *missingFiles, bool getPackages) const
9566
{
9537
{
9567
	int count = 0;
9538
	int count = 0;
9568
	for ( CListNode<C_File> *fn = m_lFiles.Front(); fn; fn = fn->next() )
9539
	for ( CListNode<C_File> *fn = m_lFiles.Front(); fn; fn = fn->next() )
9569
	{
9540
	{
9570
		C_File *f = fn->Data();
9541
		C_File *f = fn->Data();
9571
		bool exists = false;
9542
		bool exists = false;
9572
		if ( f->filePointer().contains("::") ) {
9543
		if ( f->filePointer().contains(L"::") ) {
9573
			Utils::String modFile = f->filePointer().token("::", 1);
9544
			Utils::WString modFile = f->filePointer().token(L"::", 1);
9574
			Utils::String file = f->filePointer().token("::", 2);
9545
			Utils::WString file = f->filePointer().token(L"::", 2);
9575
 
9546
 
9576
			if ( CFileIO::Exists(modFile)) {
9547
			if ( CFileIO::Exists(modFile)) {
9577
				CCatFile catFile;
9548
				CCatFile catFile;
9578
				if ( catFile.open(modFile, "", CATREAD_CATDECRYPT, false) == CATERR_NONE ) {
9549
				if ( catFile.open(modFile, L"", CATREAD_CATDECRYPT, false) == CATERR_NONE ) {
9579
					if ( catFile.findData(file) )
9550
					if ( catFile.findData(file) )
9580
						exists = true;
9551
						exists = true;
9581
				}
9552
				}
9582
			}
9553
			}
9583
		}
9554
		}
Line 9588... Line 9559...
9588
		if ( !exists )
9559
		if ( !exists )
9589
		{
9560
		{
9590
			++count;
9561
			++count;
9591
			if ( missingFiles )
9562
			if ( missingFiles )
9592
			{
9563
			{
9593
				Utils::String packages;
9564
				Utils::WString packages;
9594
				if ( getPackages )
9565
				if ( getPackages )
9595
				{
9566
				{
9596
					for ( CListNode<CBaseFile> *p = m_lPackages.Front(); p; p = p->next() )
9567
					for ( CListNode<CBaseFile> *p = m_lPackages.Front(); p; p = p->next() )
9597
					{
9568
					{
9598
						CBaseFile *package = p->Data();
9569
						CBaseFile *package = p->Data();
9599
						if ( package->IsFileAdded(f) )
9570
						if ( package->IsFileAdded(f) )
9600
						{
9571
						{
9601
							if ( !packages.empty() )
9572
							if ( !packages.empty() )
9602
								packages += "\n";
9573
								packages += L"\n";
9603
							packages += package->getFullPackageName(m_iLanguage);
9574
							packages += package->getFullPackageName(m_iLanguage).toWString();
9604
						}
9575
						}
9605
					}
9576
					}
9606
				}
9577
				}
9607
				Utils::String filename = f->filePointer();
9578
				Utils::WString filename = f->filePointer();
9608
				filename = filename.findRemove(m_sCurrentDir);
9579
				filename = filename.findRemove(m_sCurrentDir);
9609
				missingFiles->pushBack(filename, packages);
9580
				missingFiles->pushBack(filename, packages);
9610
			}
9581
			}
9611
		}
9582
		}
9612
	}
9583
	}