Subversion Repositories spk

Rev

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

Rev 212 Rev 213
Line 87... Line 87...
87
	m_gameExe.getDirectoryData(_pCurrentDir);
87
	m_gameExe.getDirectoryData(_pCurrentDir);
88
	_pCurrentDir->langid = this->getGameLanguage(_pCurrentDir->dir.toString());
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).toWString();
90
		_pCurrentDir->langname = this->ConvertLanguage(_pCurrentDir->langid).toWString();
91
 
91
 
92
	updateFoundPackages("");
92
	updateFoundPackages(L"");
93
}
93
}
94
 
94
 
95
 
95
 
96
void CPackages::SetVanilla(bool b)
96
void CPackages::SetVanilla(bool b)
97
{
97
{
Line 171... Line 171...
171
	m_bRemoveDir = false;
171
	m_bRemoveDir = false;
172
	m_bDisableVanilla = false;
172
	m_bDisableVanilla = false;
173
	m_bSurpressProtectedWarning = false;
173
	m_bSurpressProtectedWarning = false;
174
	m_iSaveGame = -1;
174
	m_iSaveGame = -1;
175
	m_iSaveGameManager = -1;
175
	m_iSaveGameManager = -1;
176
	m_sSetMod = "";
176
	m_sSetMod = L"";
177
 
177
 
178
	for ( int i = 0; i < WAREBUFFERS; i++ )
178
	for ( int i = 0; i < WAREBUFFERS; i++ )
179
	{
179
	{
180
		m_iWareBuffer[i] = 0;
180
		m_iWareBuffer[i] = 0;
181
		m_lGameWares[i].MemoryClear();
181
		m_lGameWares[i].MemoryClear();
Line 208... Line 208...
208
	{
208
	{
209
		C_File *f;
209
		C_File *f;
210
		for ( f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); f; f = m_pEnabledMod->GetNextFile(f) )
210
		for ( f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); f; f = m_pEnabledMod->GetNextFile(f) )
211
		{
211
		{
212
			if (f->IsFakePatch()) continue;
212
			if (f->IsFakePatch()) continue;
213
			if (f->checkFileExt("cat")) break;
213
			if (f->checkFileExt(L"cat")) break;
214
		}
214
		}
215
 
215
 
216
		if ( f )
216
		if ( f )
217
			m_pGameVFS.LoadFilesystem(m_sCurrentDir, f->filePointer(), 0);
217
			m_pGameVFS.LoadFilesystem(m_sCurrentDir, f->filePointer(), 0);
218
		else
218
		else
Line 253... Line 253...
253
}
253
}
254
 
254
 
255
bool CPackages::read(const Utils::WString& dir, CProgressInfo* progress)
255
bool CPackages::read(const Utils::WString& dir, CProgressInfo* progress)
256
{
256
{
257
	m_sCurrentDir = dir;
257
	m_sCurrentDir = dir;
258
	m_sCurrentDir = m_sCurrentDir.findReplace("\\", "/");
258
	m_sCurrentDir = m_sCurrentDir.findReplace(L"\\", L"/");
259
	this->setCurrentDir(dir);
259
	this->setCurrentDir(dir);
260
	m_bOldPlugin = false;
260
	m_bOldPlugin = false;
261
	_lCreatedFiles.clear();
261
	_lCreatedFiles.clear();
262
	m_bRemoveDir = false;
262
	m_bRemoveDir = false;
263
	m_bSurpressProtectedWarning = false;
263
	m_bSurpressProtectedWarning = false;
Line 818... Line 818...
818
			{
818
			{
819
				Utils::WString useAddonDir = addonDir;
819
				Utils::WString useAddonDir = addonDir;
820
				if ( !useAddonDir.empty() ) useAddonDir += L"\\";
820
				if ( !useAddonDir.empty() ) useAddonDir += L"\\";
821
				for (auto itr = files->cbegin(); itr != files->cend(); itr++)
821
				for (auto itr = files->cbegin(); itr != files->cend(); itr++)
822
				{
822
				{
823
					if ((*itr)->sFile.Compare("PlugMan\\TFake.pck") )
823
					if ((*itr)->sFile.Compare(L"PlugMan\\TFake.pck") )
824
						continue;
824
						continue;
825
					if ((*itr)->sFile.Compare(useAddonDir.toString() + "t\\44" + Utils::String::PadNumber(PMTEXTFILE, 4) + ".pck"))
825
					if ((*itr)->sFile.Compare(useAddonDir + L"t\\44" + Utils::WString::PadNumber(PMTEXTFILE, 4) + L".pck"))
826
						continue;
826
						continue;
827
					if ((*itr)->sFile.Compare(useAddonDir.toString() + "t\\" + Utils::String::PadNumber(PMTEXTFILE, 4) + "-L044.pck"))
827
					if ((*itr)->sFile.Compare(useAddonDir + L"t\\" + Utils::WString::PadNumber(PMTEXTFILE, 4) + L"-L044.pck"))
828
						continue;
828
						continue;
829
 
829
 
830
					found = true;
830
					found = true;
831
					break;
831
					break;
832
				}
832
				}
Line 843... Line 843...
843
						return true;
843
						return true;
844
				}
844
				}
845
			}
845
			}
846
			else
846
			else
847
			{
847
			{
848
				if ( catFile.Rename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat") )
848
				if ( catFile.Rename(m_sCurrentDir + L"/PluginManager/PlugMan_Fake.cat") )
849
				{
849
				{
850
					CFileIO datFile(m_sCurrentDir + L"/" + useFile + L".dat");
850
					CFileIO datFile(m_sCurrentDir + L"/" + useFile + L".dat");
851
 
851
 
852
					if ( datFile.Rename(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat") )
852
					if ( datFile.Rename(m_sCurrentDir + L"/PluginManager/PlugMan_Fake.dat") )
853
						return true;
853
						return true;
854
 
854
 
855
					// TODO: it failed, restore cat file and do error
855
					// TODO: it failed, restore cat file and do error
856
				}
856
				}
857
			}
857
			}
Line 860... Line 860...
860
		// if we're here, we tryed, and failed
860
		// if we're here, we tryed, and failed
861
		return false;
861
		return false;
862
	}
862
	}
863
	// no files found, but we have a fake patch ? restore from backup
863
	// no files found, but we have a fake patch ? restore from backup
864
	else if ( m_iFakePatch > 0 ) {
864
	else if ( m_iFakePatch > 0 ) {
865
		CLog::log(CLog::Log_Directory, 1, "PlugMan FakePatch seems to be missing (" + Utils::String::Number(m_iFakePatch) + "), Restoring from backup");
865
		CLog::log(CLog::Log_Directory, 1, L"PlugMan FakePatch seems to be missing (" + Utils::WString::Number(m_iFakePatch) + L"), Restoring from backup");
866
		CFileIO catFile(m_sCurrentDir + "/PluginManager/Backup/PlugMan_Fake.cat");
866
		CFileIO catFile(m_sCurrentDir + L"/PluginManager/Backup/PlugMan_Fake.cat");
867
		if ( catFile.exists() ) {
867
		if ( catFile.exists() ) {
868
			catFile.copy(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat");
868
			catFile.copy(m_sCurrentDir + L"/PluginManager/PlugMan_Fake.cat");
869
			CFileIO datFile(m_sCurrentDir + "/PluginManager/Backup/PlugMan_Fake.dat");
869
			CFileIO datFile(m_sCurrentDir + L"/PluginManager/Backup/PlugMan_Fake.dat");
870
			if ( datFile.exists() ) datFile.copy(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
870
			if ( datFile.exists() ) datFile.copy(m_sCurrentDir + L"/PluginManager/PlugMan_Fake.dat");
871
		}
871
		}
872
	}
872
	}
873
 
873
 
874
	// otherwise we didn't need to (hopefully)
874
	// otherwise we didn't need to (hopefully)
875
	return true;
875
	return true;
Line 919... Line 919...
919
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + L"/" + filename + L".dat"))
919
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + L"/" + filename + L".dat"))
920
	{
920
	{
921
		CCatFile openFile;
921
		CCatFile openFile;
922
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
922
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
923
		{
923
		{
924
			if ( openFile.findData("PlugMan\\TFake.pck") )
924
			if ( openFile.findData(L"PlugMan\\TFake.pck") )
925
				return true;
925
				return true;
926
			if ( openFile.findData("pluginmanagerfake.pck") )
926
			if ( openFile.findData(L"pluginmanagerfake.pck") )
927
				return true;
927
				return true;
928
		}
928
		}
929
	}
929
	}
930
 
930
 
931
	return false;
931
	return false;
Line 952... Line 952...
952
				gNode->Data()->iVersion = version;
952
				gNode->Data()->iVersion = version;
953
			}
953
			}
954
		}
954
		}
955
	}
955
	}
956
 
956
 
957
	if ( package->forumLink().empty() && package->webSite().isin("forum.egosoft")) {
957
	if ( package->forumLink().empty() && package->webSite().contains(L"forum.egosoft")) {
958
		package->setForumLink(package->webSite());
958
		package->setForumLink(package->webSite());
959
		package->setWebSite("");
959
		package->setWebSite(L"");
960
	}
960
	}
961
 
961
 
962
	// convert the version
962
	// convert the version
963
	if ( package->GetType() == TYPE_SPK )
963
	if ( package->GetType() == TYPE_SPK )
964
	{
964
	{
Line 1028... Line 1028...
1028
	// any extra files that are in director folder
1028
	// any extra files that are in director folder
1029
	if ( package->AnyFileType(FILETYPE_EXTRA) )
1029
	if ( package->AnyFileType(FILETYPE_EXTRA) )
1030
	{
1030
	{
1031
		for ( C_File *f = package->GetFirstFile(FILETYPE_EXTRA); f; f = package->GetNextFile(f) )
1031
		for ( C_File *f = package->GetFirstFile(FILETYPE_EXTRA); f; f = package->GetNextFile(f) )
1032
		{
1032
		{
1033
			if ( !f->dir().Compare("director") )
1033
			if ( !f->dir().Compare(L"director") )
1034
				continue;
1034
				continue;
1035
			if (f->checkFileExt("xml") || f->checkFileExt("pck"))
1035
			if (f->checkFileExt(L"xml") || f->checkFileExt(L"pck"))
1036
			{
1036
			{
1037
				f->setDir("");
1037
				f->setDir(L"");
1038
				f->setFileType(FILETYPE_MISSION);
1038
				f->setFileType(FILETYPE_MISSION);
1039
			}
1039
			}
1040
		}
1040
		}
1041
	}
1041
	}
1042
}
1042
}
Line 1386... Line 1386...
1386
			}
1386
			}
1387
			if ( CCatFile::IsAddonDir(f->Data()->getNameDirectory(pPackage)) ) {
1387
			if ( CCatFile::IsAddonDir(f->Data()->getNameDirectory(pPackage)) ) {
1388
				continue;
1388
				continue;
1389
			}
1389
			}
1390
			// check if its already in the fake patch
1390
			// check if its already in the fake patch
1391
			if ( f->Data()->fullDir().contains("::") ) {
1391
			if ( f->Data()->fullDir().contains(L"::") ) {
1392
				continue;
1392
				continue;
1393
			}
1393
			}
1394
			Utils::WString toFile;
1394
			Utils::WString toFile;
1395
			if ( cat.appendFile(f->Data()->filePointer(), f->Data()->getNameDirectory(pPackage), true, (m_iGameFlags & EXEFLAG_NOXOR) ? false : true, &toFile) ) {
1395
			if ( cat.appendFile(f->Data()->filePointer(), f->Data()->getNameDirectory(pPackage), true, (m_iGameFlags & EXEFLAG_NOXOR) ? false : true, &toFile) ) {
1396
				CLog::logf(CLog::Log_Install, 2, "Adding file: %s into the fake patch", f->Data()->getNameDirectory(pPackage).c_str());
1396
				CLog::logf(CLog::Log_Install, 2, "Adding file: %s into the fake patch", f->Data()->getNameDirectory(pPackage).c_str());
Line 1406... Line 1406...
1406
	bool prevDisabled = disabled;
1406
	bool prevDisabled = disabled;
1407
 
1407
 
1408
	// first check if we are installed a mod
1408
	// first check if we are installed a mod
1409
	if ( package->IsMod() && m_pEnabledMod && !m_bForceModInstall ) {
1409
	if ( package->IsMod() && m_pEnabledMod && !m_bForceModInstall ) {
1410
		disabled = true;
1410
		disabled = true;
1411
		CLog::log(CLog::Log_Install, 2, "Package is a mod and another mod is already enabled, setting to disabled");
1411
		CLog::log(CLog::Log_Install, 2, L"Package is a mod and another mod is already enabled, setting to disabled");
1412
	}
1412
	}
1413
	// if vanilla nad package aint signed
1413
	// if vanilla nad package aint signed
1414
	if ( m_bVanilla && !package->IsSigned() ) {
1414
	if ( m_bVanilla && !package->IsSigned() ) {
1415
		disabled = true;
1415
		disabled = true;
1416
		CLog::log(CLog::Log_Install, 2, "Package is a not signed and are we in vanilla mode, setting to disabled");
1416
		CLog::log(CLog::Log_Install, 2, L"Package is a not signed and are we in vanilla mode, setting to disabled");
1417
	}
1417
	}
1418
 
1418
 
1419
	// check any depancies
1419
	// check any depancies
1420
	if ( !disabled && !this->CheckEnabledDependacy(package) ) {
1420
	if ( !disabled && !this->CheckEnabledDependacy(package) ) {
1421
		disabled = true;
1421
		disabled = true;
1422
		CLog::log(CLog::Log_Install, 2, "Dependacies missing for package, setting to disabled");
1422
		CLog::log(CLog::Log_Install, 2, L"Dependacies missing for package, setting to disabled");
1423
	}
1423
	}
1424
 
1424
 
1425
	// search for an old version
1425
	// search for an old version
1426
	if ( oldPackage && oldPackage == m_pEnabledMod && disabled )
1426
	if ( oldPackage && oldPackage == m_pEnabledMod && disabled )
1427
		disabled = prevDisabled;
1427
		disabled = prevDisabled;
Line 1445... Line 1445...
1445
	// update packages must have an old package installed already (should have been checked for already)
1445
	// update packages must have an old package installed already (should have been checked for already)
1446
	if ( package->GetType() == TYPE_SPK )
1446
	if ( package->GetType() == TYPE_SPK )
1447
	{
1447
	{
1448
		if ( ((CSpkFile *)package)->IsPackageUpdate() )
1448
		if ( ((CSpkFile *)package)->IsPackageUpdate() )
1449
		{
1449
		{
1450
			CLog::log(CLog::Log_Install, 3, "Package is an Update, checking for existing package installed");
1450
			CLog::log(CLog::Log_Install, 3, L"Package is an Update, checking for existing package installed");
1451
			if ( !oldPackage ) {
1451
			if ( !oldPackage ) {
1452
				CLog::log(CLog::Log_Install, 2, "Package is an Update but no existing package found, cancelling install");
1452
				CLog::log(CLog::Log_Install, 2, L"Package is an Update but no existing package found, cancelling install");
1453
				return false;
1453
				return false;
1454
			}
1454
			}
1455
			// change any mods to temp ones
1455
			// change any mods to temp ones
1456
			for ( CListNode<C_File> *f = package->GetFileList()->Front(); f; f = f->next() )
1456
			for ( CListNode<C_File> *f = package->GetFileList()->Front(); f; f = f->next() )
1457
			{
1457
			{
1458
				if ( f->Data()->GetFileType() != FILETYPE_MOD )
1458
				if ( f->Data()->GetFileType() != FILETYPE_MOD )
1459
					continue;
1459
					continue;
1460
 
1460
 
1461
				f->Data()->setDir("temp");
1461
				f->Data()->setDir(L"temp");
1462
				if ( f->Data()->IsFakePatch() ) {
1462
				if ( f->Data()->IsFakePatch() ) {
1463
					CLog::logf(CLog::Log_Install, 2, "Moving fake package to temporary location to preper for update, %s", f->Data()->filePointer().c_str());
1463
					CLog::logf(CLog::Log_Install, 2, "Moving fake package to temporary location to preper for update, %s", f->Data()->filePointer().c_str());
1464
					f->Data()->setName("Fake_" + f->Data()->name());
1464
					f->Data()->setName(L"Fake_" + f->Data()->name());
1465
				}
1465
				}
1466
			}
1466
			}
1467
		}
1467
		}
1468
	}
1468
	}
1469
 
1469
 
1470
	// no need to backup if we're disabling them
1470
	// no need to backup if we're disabling them
1471
	if ( !disabled )
1471
	if ( !disabled )
1472
	{
1472
	{
1473
		// find any uninstall files and remove them
1473
		// find any uninstall files and remove them
1474
		CLog::log(CLog::Log_Install, 3, "Purging uninstall scripts");
1474
		CLog::log(CLog::Log_Install, 3, L"Purging uninstall scripts");
1475
		this->purgeUninstallScripts(package, errors);
1475
		this->purgeUninstallScripts(package, errors);
1476
 
1476
 
1477
		// backup any original files before installing
1477
		// backup any original files before installing
1478
		_pOriginalFiles->backup(package, errors);
1478
		_pOriginalFiles->backup(package, errors);
1479
	}
1479
	}
1480
 
1480
 
1481
	// install all the files
1481
	// install all the files
1482
	CLog::log(CLog::Log_Install, 3, "Checking for any existing files");
1482
	CLog::log(CLog::Log_Install, 3, L"Checking for any existing files");
1483
	if ( oldPackage )
1483
	if ( oldPackage )
1484
	{
1484
	{
1485
		CLog::logf(CLog::Log_Install, 3, "Excluding existing package (%s) from file check list", oldPackage->version().c_str());
1485
		CLog::logf(CLog::Log_Install, 3, "Excluding existing package (%s) from file check list", oldPackage->version().c_str());
1486
		CLinkList<CBaseFile> excludeList;
1486
		CLinkList<CBaseFile> excludeList;
1487
		excludeList.push_back(oldPackage);
1487
		excludeList.push_back(oldPackage);
1488
		this->UpdateUsedFiles(&excludeList, true);
1488
		this->UpdateUsedFiles(&excludeList, true);
1489
	}
1489
	}
1490
	else
1490
	else
1491
		this->UpdateUsedFiles(0, true);
1491
		this->UpdateUsedFiles(0, true);
1492
 
1492
 
1493
	CLog::log(CLog::Log_Install, 3, "Reading all files into memory");
1493
	CLog::log(CLog::Log_Install, 3, L"Reading all files into memory");
1494
	package->ReadAllFilesToMemory();
1494
	package->ReadAllFilesToMemory();
1495
 
1495
 
1496
	CLog::log(CLog::Log_Install, 3, "Starting to install files");
1496
	CLog::log(CLog::Log_Install, 3, L"Starting to install files");
1497
	if ( !package->installFiles (m_sCurrentDir.toString(), progress, &m_lFiles, errors, !disabled, this))
1497
	if ( !package->installFiles (m_sCurrentDir.toString(), progress, &m_lFiles, errors, !disabled, this))
1498
	{
1498
	{
1499
		CLog::log(CLog::Log_Install, 2, "There was an error installing files!!");
1499
		CLog::log(CLog::Log_Install, 2, L"There was an error installing files!!");
1500
 
1500
 
1501
		// TODO: clear up installed files
1501
		// TODO: clear up installed files
1502
		return false;
1502
		return false;
1503
	}
1503
	}
1504
 
1504
 
Line 1521... Line 1521...
1521
				if ( !f->Data() )
1521
				if ( !f->Data() )
1522
					continue;
1522
					continue;
1523
				if ( f->Data()->GetFileType() != FILETYPE_MOD )
1523
				if ( f->Data()->GetFileType() != FILETYPE_MOD )
1524
					continue;
1524
					continue;
1525
				// we only need the cat file
1525
				// we only need the cat file
1526
				if (!f->Data()->checkFileExt("cat"))
1526
				if (!f->Data()->checkFileExt(L"cat"))
1527
					continue;
1527
					continue;
1528
 
1528
 
1529
				// if fake patch, find first fake patch in package
1529
				// if fake patch, find first fake patch in package
1530
				C_File *findMatching = NULL;
1530
				C_File *findMatching = NULL;
1531
				if ( f->Data()->baseName().left(5).Compare("fake_") )
1531
				if ( f->Data()->baseName().left(5).Compare(L"fake_") )
1532
				{
1532
				{
1533
					for ( CListNode<C_File> *node = oldPackage->GetFileList()->Front(); node; node = node->next() )
1533
					for ( CListNode<C_File> *node = oldPackage->GetFileList()->Front(); node; node = node->next() )
1534
					{
1534
					{
1535
						if ( !node->Data() )
1535
						if ( !node->Data() )
1536
							continue;
1536
							continue;
1537
						if ( node->Data()->GetFileType() != FILETYPE_MOD )
1537
						if ( node->Data()->GetFileType() != FILETYPE_MOD )
1538
							continue;
1538
							continue;
1539
						// we only need the cat file
1539
						// we only need the cat file
1540
						if ( !node->Data()->checkFileExt("cat") )
1540
						if ( !node->Data()->checkFileExt(L"cat") )
1541
							continue;
1541
							continue;
1542
						if ( !node->Data()->IsFakePatch() )
1542
						if ( !node->Data()->IsFakePatch() )
1543
							continue;
1543
							continue;
1544
 
1544
 
1545
						findMatching = node->Data();
1545
						findMatching = node->Data();
Line 1554... Line 1554...
1554
						if ( !node->Data() )
1554
						if ( !node->Data() )
1555
							continue;
1555
							continue;
1556
						if ( node->Data()->GetFileType() != FILETYPE_MOD )
1556
						if ( node->Data()->GetFileType() != FILETYPE_MOD )
1557
							continue;
1557
							continue;
1558
						// we only need the cat file
1558
						// we only need the cat file
1559
						if (!node->Data()->checkFileExt("cat"))
1559
						if (!node->Data()->checkFileExt(L"cat"))
1560
							continue;
1560
							continue;
1561
 
1561
 
1562
						if ( node->Data()->name().Compare(f->Data()->name()) )
1562
						if ( node->Data()->name().Compare(f->Data()->name()) )
1563
						{
1563
						{
1564
							findMatching = node->Data();
1564
							findMatching = node->Data();
Line 1569... Line 1569...
1569
 
1569
 
1570
				if ( findMatching )
1570
				if ( findMatching )
1571
				{
1571
				{
1572
					// copy accross all mods
1572
					// copy accross all mods
1573
					CCatFile catTo, catFrom;
1573
					CCatFile catTo, catFrom;
1574
					if ( catFrom.open(f->Data()->filePointer(), this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
1574
					if ( catFrom.open(f->Data()->filePointer(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
1575
					{
1575
					{
1576
						if ( catTo.open(findMatching->filePointer(), this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
1576
						if ( catTo.open(findMatching->filePointer(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
1577
						{
1577
						{
1578
							for (unsigned int i = 0; i < catFrom.GetNumFiles(); i++ )
1578
							for (unsigned int i = 0; i < catFrom.GetNumFiles(); i++ )
1579
							{
1579
							{
1580
								SInCatFile *c = catFrom.GetFile(i);								 
1580
								SInCatFile *c = catFrom.GetFile(i);								 
1581
								catTo.appendFile(f->Data()->filePointer() + "::" + c->sFile, c->sFile);
1581
								catTo.appendFile(f->Data()->filePointer() + L"::" + c->sFile, c->sFile);
1582
							}
1582
							}
1583
						}
1583
						}
1584
					}
1584
					}
1585
 
1585
 
1586
					// now remove the files
1586
					// now remove the files
Line 1598... Line 1598...
1598
					}
1598
					}
1599
				}
1599
				}
1600
				// no matching file, then we shall just renaming back
1600
				// no matching file, then we shall just renaming back
1601
				else
1601
				else
1602
				{
1602
				{
1603
					if ( f->Data()->baseName().left(5).Compare("fake_") )
1603
					if ( f->Data()->baseName().left(5).Compare(L"fake_") )
1604
					{
1604
					{
1605
						shuffle = true;
1605
						shuffle = true;
1606
						C_File *match = package->findMatchingMod(f->Data());
1606
						C_File *match = package->findMatchingMod(f->Data());
1607
						Utils::String next = Utils::String::PadNumber(this->findNextFakePatch(), 2);
1607
						Utils::String next = Utils::String::PadNumber(this->findNextFakePatch(), 2);
1608
						
1608
						
Line 1651... Line 1651...
1651
	}
1651
	}
1652
 
1652
 
1653
	// if theres an icon, write it
1653
	// if theres an icon, write it
1654
	if (package->icon())
1654
	if (package->icon())
1655
	{
1655
	{
1656
		CLog::log(CLog::Log_Install, 3, "Checking to install icon display file");
1656
		CLog::log(CLog::Log_Install, 3, L"Checking to install icon display file");
1657
		C_File *icon = package->icon();
1657
		C_File *icon = package->icon();
1658
		if ( !icon->GetData() || !icon->GetDataSize() ) {
1658
		if ( !icon->GetData() || !icon->GetDataSize() ) {
1659
			package->setIcon(NULL, "");
1659
			package->setIcon(NULL, L"");
1660
			CLog::log(CLog::Log_Install, 2, "Unable to extract icon, clearing");
1660
			CLog::log(CLog::Log_Install, 2, L"Unable to extract icon, clearing");
1661
		}
1661
		}
1662
		else
1662
		else
1663
		{
1663
		{
1664
			CDirIO Dir(m_sCurrentDir);
1664
			CDirIO Dir(m_sCurrentDir);
1665
			bool ready = true;
1665
			bool ready = true;
1666
			if ( !Dir.exists("PluginManager") )
1666
			if ( !Dir.exists(L"PluginManager") )
1667
			{
1667
			{
1668
				if ( !Dir.create("PluginManager") )
1668
				if ( !Dir.create(L"PluginManager") )
1669
					ready = false;
1669
					ready = false;
1670
			}
1670
			}
1671
			if ( ready && !Dir.exists("PluginManager/Icons") )
1671
			if ( ready && !Dir.exists(L"PluginManager/Icons") )
1672
			{
1672
			{
1673
				if ( !Dir.create("PluginManager/Icons") )
1673
				if ( !Dir.create(L"PluginManager/Icons") )
1674
					ready = false;
1674
					ready = false;
1675
			}
1675
			}
1676
 
1676
 
1677
			if ( ready )
1677
			if ( ready )
1678
			{
1678
			{
1679
				if ( !icon->UncompressData() )
1679
				if ( !icon->UncompressData() )
1680
					package->setIcon(NULL, "");
1680
					package->setIcon(NULL, L"");
1681
				else
1681
				else
1682
				{
1682
				{
1683
					CFileIO iconFile(m_sCurrentDir + L"/PluginManager/Icons/" + package->author() + L"_" + package->name() + L"." + package->iconExt());
1683
					CFileIO iconFile(m_sCurrentDir + L"/PluginManager/Icons/" + package->author() + L"_" + package->name() + L"." + package->iconExt());
1684
					if ( iconFile.WriteData((const char *)icon->GetData(), icon->GetDataSize()) )
1684
					if ( iconFile.WriteData((const char *)icon->GetData(), icon->GetDataSize()) )
1685
					{
1685
					{
1686
						icon->setFilename(package->author() + L"_" + package->name() + L"." + package->iconExt());
1686
						icon->setFilename(package->author() + L"_" + package->name() + L"." + package->iconExt());
1687
						icon->setFullDir(m_sCurrentDir + L"/PluginManager/Icons");
1687
						icon->setFullDir(m_sCurrentDir + L"/PluginManager/Icons");
1688
					}
1688
					}
1689
					else
1689
					else
1690
						package->setIcon(NULL, "");
1690
						package->setIcon(NULL, L"");
1691
				}
1691
				}
1692
			}
1692
			}
1693
 
1693
 
1694
			if (package->icon())
1694
			if (package->icon())
1695
				package->icon()->DeleteData();
1695
				package->icon()->DeleteData();
1696
		}
1696
		}
1697
	}
1697
	}
1698
 
1698
 
1699
	// remove all data
1699
	// remove all data
1700
	CLog::log(CLog::Log_Install, 3, "Clearing all unneeded file data");
1700
	CLog::log(CLog::Log_Install, 3, L"Clearing all unneeded file data");
1701
	package->ClearFileData();
1701
	package->ClearFileData();
1702
 
1702
 
1703
	// add to list
1703
	// add to list
1704
	if ( !dontAdd )
1704
	if ( !dontAdd )
1705
	{
1705
	{
1706
		CLog::log(CLog::Log_Install, 1, "Adding package into main list");
1706
		CLog::log(CLog::Log_Install, 1, L"Adding package into main list");
1707
		if ( oldPackage )
1707
		if ( oldPackage )
1708
		{
1708
		{
1709
			// find all other packages that has the old package as parent and switch to new
1709
			// find all other packages that has the old package as parent and switch to new
1710
			for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
1710
			for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
1711
				if ( node->Data()->GetParent() == oldPackage ) {
1711
				if ( node->Data()->GetParent() == oldPackage ) {
Line 1719... Line 1719...
1719
		}
1719
		}
1720
		else
1720
		else
1721
			m_lPackages.push_back (package);
1721
			m_lPackages.push_back (package);
1722
	}
1722
	}
1723
 
1723
 
1724
	CLog::log(CLog::Log_Install, 2, "Updating file used count");
1724
	CLog::log(CLog::Log_Install, 2, L"Updating file used count");
1725
	UpdateUsedFiles();
1725
	UpdateUsedFiles();
1726
 
1726
 
1727
	if ( disabled ) package->SetEnabled(false);
1727
	if ( disabled ) package->SetEnabled(false);
1728
 
1728
 
1729
	// remove any files no longer used by old package
1729
	// remove any files no longer used by old package
1730
	if ( oldPackage )
1730
	if ( oldPackage )
1731
	{
1731
	{
1732
		CLog::log(CLog::Log_Install, 3, "Removing any unused files from previous package");
1732
		CLog::log(CLog::Log_Install, 3, L"Removing any unused files from previous package");
1733
 
1733
 
1734
		CListNode<C_File> *fnode = oldPackage->GetFileList()->Front();
1734
		CListNode<C_File> *fnode = oldPackage->GetFileList()->Front();
1735
		while ( fnode )
1735
		while ( fnode )
1736
		{
1736
		{
1737
			C_File *f = fnode->Data();
1737
			C_File *f = fnode->Data();
Line 1766... Line 1766...
1766
 
1766
 
1767
	}
1767
	}
1768
 
1768
 
1769
	if ( shuffle )
1769
	if ( shuffle )
1770
	{
1770
	{
1771
		CLog::log(CLog::Log_Install, 2, "Shuffling Fake patches");
1771
		CLog::log(CLog::Log_Install, 2, L"Shuffling Fake patches");
1772
		shuffleFakePatches(errors);
1772
		shuffleFakePatches(errors);
1773
		CLog::log(CLog::Log_Install, 2, "Shuffling Text Files");
1773
		CLog::log(CLog::Log_Install, 2, L"Shuffling Text Files");
1774
		shuffleTextFiles(errors);
1774
		shuffleTextFiles(errors);
1775
	}
1775
	}
1776
 
1776
 
1777
	// now we need to link any child/parent packages
1777
	// now we need to link any child/parent packages
1778
	if ( package->GetType() == TYPE_SPK )
1778
	if ( package->GetType() == TYPE_SPK )
Line 1785... Line 1785...
1785
	}
1785
	}
1786
 
1786
 
1787
	// store enabled mod
1787
	// store enabled mod
1788
	if ( package->IsMod() && !disabled ) {
1788
	if ( package->IsMod() && !disabled ) {
1789
		m_pEnabledMod = package;
1789
		m_pEnabledMod = package;
1790
		CLog::log(CLog::Log_Install, 1, "Setting package as primary mod");
1790
		CLog::log(CLog::Log_Install, 1, L"Setting package as primary mod");
1791
	}
1791
	}
1792
 
1792
 
1793
	package->updateTextDB();
1793
	package->updateTextDB();
1794
 
1794
 
1795
	m_bRemoveDir = true;
1795
	m_bRemoveDir = true;
1796
 
1796
 
1797
	CLog::log(CLog::Log_Install, 1, "Saving data to file");
1797
	CLog::log(CLog::Log_Install, 1, L"Saving data to file");
1798
	this->WriteData();
1798
	this->WriteData();
1799
 
1799
 
1800
	CLog::log(CLog::Log_Install, 1, "Installation Finished");
1800
	CLog::log(CLog::Log_Install, 1, L"Installation Finished");
1801
	return true;
1801
	return true;
1802
}
1802
}
1803
 
1803
 
1804
bool CPackages::uninstallPreparedPackages(Utils::WStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *uninstalledPackages, CLinkList<CBaseFile> *disabledPackages)
1804
bool CPackages::uninstallPreparedPackages(Utils::WStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *uninstalledPackages, CLinkList<CBaseFile> *disabledPackages)
1805
{
1805
{
Line 2327... Line 2327...
2327
		CXspFile *p = (CXspFile *)pNode->Data();
2327
		CXspFile *p = (CXspFile *)pNode->Data();
2328
 
2328
 
2329
		bool found = false;
2329
		bool found = false;
2330
		for ( CListNode<SGameShip> *wNode = m_lGameShips.Front(); wNode; wNode = wNode->next() )
2330
		for ( CListNode<SGameShip> *wNode = m_lGameShips.Front(); wNode; wNode = wNode->next() )
2331
		{
2331
		{
2332
			if ( wNode->Data()->sShipID.Compare(p->GetShipID().c_str()) )
2332
			if ( wNode->Data()->sShipID.Compare(p->GetShipID()) )
2333
			{
2333
			{
2334
				if ( !p->IsEnabled() )
2334
				if ( !p->IsEnabled() )
2335
					wNode->Data()->iType = WARETYPE_DISABLED;
2335
					wNode->Data()->iType = WARETYPE_DISABLED;
2336
				else
2336
				else
2337
					wNode->Data()->iType = WARETYPE_ADDED;
2337
					wNode->Data()->iType = WARETYPE_ADDED;
Line 2350... Line 2350...
2350
		for ( CListNode<SGameShip> *wNode = m_lGameShips.Front(); wNode; wNode = wNode->next() )
2350
		for ( CListNode<SGameShip> *wNode = m_lGameShips.Front(); wNode; wNode = wNode->next() )
2351
		{
2351
		{
2352
			if ( (!gw) && (wNode->Data()->iType == WARETYPE_NONE) )
2352
			if ( (!gw) && (wNode->Data()->iType == WARETYPE_NONE) )
2353
				gw = wNode->Data();
2353
				gw = wNode->Data();
2354
			// find an old entry for the ware and add it to the same place
2354
			// find an old entry for the ware and add it to the same place
2355
			if ( wNode->Data()->sShipID.Compare(p->GetShipID().c_str()) )
2355
			if ( wNode->Data()->sShipID.Compare(p->GetShipID()) )
2356
			{
2356
			{
2357
				gw = wNode->Data();
2357
				gw = wNode->Data();
2358
				break;
2358
				break;
2359
			}
2359
			}
2360
		}
2360
		}
Line 2477... Line 2477...
2477
	{
2477
	{
2478
		// base mode for Reunion
2478
		// base mode for Reunion
2479
		if ( m_iGame == GAME_X3 && m_pEnabledMod )
2479
		if ( m_iGame == GAME_X3 && m_pEnabledMod )
2480
		{
2480
		{
2481
			C_File *fDat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2481
			C_File *fDat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2482
			while (fDat && !fDat->IsFakePatch() && !fDat->checkFileExt("dat"))
2482
			while (fDat && !fDat->IsFakePatch() && !fDat->checkFileExt(L"dat"))
2483
				fDat = m_pEnabledMod->GetNextFile(fDat);
2483
				fDat = m_pEnabledMod->GetNextFile(fDat);
2484
 
2484
 
2485
			if ( fDat )
2485
			if ( fDat )
2486
			{
2486
			{
2487
				C_File *fCat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2487
				C_File *fCat = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
Line 2564... Line 2564...
2564
 
2564
 
2565
}
2565
}
2566
 
2566
 
2567
bool CPackages::RestoreFakePatch()
2567
bool CPackages::RestoreFakePatch()
2568
{
2568
{
2569
	CLog::log(CLog::Log_Directory, 1, "Restoring PluginManager fake patch into game");
2569
	CLog::log(CLog::Log_Directory, 1, L"Restoring PluginManager fake patch into game");
2570
 	m_iFakePatch = -1;
2570
 	m_iFakePatch = -1;
2571
 
2571
 
2572
	CFileIO catFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat");
2572
	CFileIO catFile(m_sCurrentDir + L"/PluginManager/PlugMan_Fake.cat");
2573
	CFileIO datFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
2573
	CFileIO datFile(m_sCurrentDir + L"/PluginManager/PlugMan_Fake.dat");
2574
 
2574
 
2575
	// if only 1 exists, remove it
2575
	// if only 1 exists, remove it
2576
	if ( catFile.exists() && !datFile.exists() ) {
2576
	if ( catFile.exists() && !datFile.exists() ) {
2577
		CLog::log(CLog::Log_Directory, 1, "WARNING: cat/dat file mismatch, dat file seems to be missing, removing cat file");
2577
		CLog::log(CLog::Log_Directory, 1, L"WARNING: cat/dat file mismatch, dat file seems to be missing, removing cat file");
2578
		if ( !catFile.remove() ) return false;
2578
		if ( !catFile.remove() ) return false;
2579
	}
2579
	}
2580
	else if ( !catFile.exists() && datFile.exists() ) {
2580
	else if ( !catFile.exists() && datFile.exists() ) {
2581
		CLog::log(CLog::Log_Directory, 1, "WARNING: cat/dat file mismatch, cat file seems to be missing, removing dat file");
2581
		CLog::log(CLog::Log_Directory, 1, L"WARNING: cat/dat file mismatch, cat file seems to be missing, removing dat file");
2582
		if ( !datFile.remove() ) return false;
2582
		if ( !datFile.remove() ) return false;
2583
	}
2583
	}
2584
 
2584
 
2585
	// if both exists, lets rename them
2585
	// if both exists, lets rename them
2586
	if ( catFile.exists() && datFile.exists() )
2586
	if ( catFile.exists() && datFile.exists() )
2587
	{
2587
	{
2588
		CLog::log(CLog::Log_Directory, 3, "Creating pluginmanagerfake.txt file to add to Fake Patch");
2588
		CLog::log(CLog::Log_Directory, 3, L"Creating pluginmanagerfake.txt file to add to Fake Patch");
2589
		// we need to add the plugin manager file in
2589
		// we need to add the plugin manager file in
2590
		Utils::WString file = m_sTempDir;
2590
		Utils::WString file = m_sTempDir;
2591
		if ( !file.empty() )
2591
		if ( !file.empty() )
2592
			file += L"/";
2592
			file += L"/";
2593
		file += L"pluginmanagerfake.txt";
2593
		file += L"pluginmanagerfake.txt";
Line 2621... Line 2621...
2621
		}
2621
		}
2622
 
2622
 
2623
 
2623
 
2624
		// find next available fake patch
2624
		// find next available fake patch
2625
		m_iFakePatch = this->findNextFakePatch();
2625
		m_iFakePatch = this->findNextFakePatch();
2626
		CLog::log(CLog::Log_Directory, 2, "Finding next available fake patch number: " + (long)m_iFakePatch);
2626
		CLog::log(CLog::Log_Directory, 2, L"Finding next available fake patch number: " + (long)m_iFakePatch);
2627
 
2627
 
2628
		Utils::WString filename = Utils::WString::PadNumber(m_iFakePatch, 2);
2628
		Utils::WString filename = Utils::WString::PadNumber(m_iFakePatch, 2);
2629
		CLog::log(CLog::Log_Directory, 2, L"Renaming cat file to: " + filename + L".cat");
2629
		CLog::log(CLog::Log_Directory, 2, L"Renaming cat file to: " + filename + L".cat");
2630
		if ( catFile.Rename(m_sCurrentDir + L"/" + filename + L".cat") )
2630
		if ( catFile.Rename(m_sCurrentDir + L"/" + filename + L".cat") )
2631
		{
2631
		{
Line 3173... Line 3173...
3173
		if ( f->IsDisabled() )
3173
		if ( f->IsDisabled() )
3174
			continue;
3174
			continue;
3175
 
3175
 
3176
		// readmes, uninstall and extra files dont need to be disabled
3176
		// readmes, uninstall and extra files dont need to be disabled
3177
		// Extra files not in the "Extras" directory could be anywhere, so these should be disabled incase they are game changing files, ie in "types"
3177
		// Extra files not in the "Extras" directory could be anywhere, so these should be disabled incase they are game changing files, ie in "types"
3178
		if ( f->GetFileType() == FILETYPE_README || f->GetFileType() == FILETYPE_UNINSTALL || (f->GetFileType() == FILETYPE_EXTRA && f->dir().left(5).lower() == "Extra") )
3178
		if ( f->GetFileType() == FILETYPE_README || f->GetFileType() == FILETYPE_UNINSTALL || (f->GetFileType() == FILETYPE_EXTRA && f->dir().left(5).lower() == L"Extra") )
3179
			continue;
3179
			continue;
3180
 
3180
 
3181
		// 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
3181
		// 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
3182
		if ( f->GetFileType() == FILETYPE_SCRIPT )
3182
		if ( f->GetFileType() == FILETYPE_SCRIPT )
3183
		{
3183
		{
Line 3194... Line 3194...
3194
 
3194
 
3195
			if ( found )
3195
			if ( found )
3196
				continue;
3196
				continue;
3197
		}
3197
		}
3198
 
3198
 
3199
		if ( f->GetFileType() == FILETYPE_MOD && !f->IsFakePatch() && f->checkFileExt("cat") )
3199
		if ( f->GetFileType() == FILETYPE_MOD && !f->IsFakePatch() && f->checkFileExt(L"cat") )
3200
		{
3200
		{
3201
			if ( f->baseName().Compare(m_sSetMod.toString()) )
3201
			if ( f->baseName().Compare(m_sSetMod.toString()) )
3202
				m_sSetMod = Utils::WString::Null();
3202
				m_sSetMod = Utils::WString::Null();
3203
		}
3203
		}
3204
 
3204
 
Line 3852... Line 3852...
3852
	if (neededList)
3852
	if (neededList)
3853
	{
3853
	{
3854
		for (CListNode<SNeededLibrary>* node = neededList->Front(); node; node = node->next())
3854
		for (CListNode<SNeededLibrary>* node = neededList->Front(); node; node = node->next())
3855
		{
3855
		{
3856
			SNeededLibrary* nl = node->Data();
3856
			SNeededLibrary* nl = node->Data();
3857
			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))
3857
			if (!checkInstalledDependacy((nl->sName.Compare(L"<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare(L"<author>")) ? p->author() : nl->sAuthor, nl->sMinVersion, (nl->sName.Compare(L"<package>")) ? false : onlyEnabled, (nl->sName.Compare(L"<package>")) ? false : includePrepared))
3858
			{
3858
			{
3859
				const SAvailablePackage *available = findAvailablePackage((nl->sName.Compare("<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare("<author>")) ? p->author() : nl->sAuthor);
3859
				const SAvailablePackage *available = findAvailablePackage((nl->sName.Compare(L"<package>")) ? p->name() : nl->sName, (nl->sAuthor.Compare(L"<author>")) ? p->author() : nl->sAuthor);
3860
				if (available)
3860
				if (available)
3861
					list.push_back(available);
3861
					list.push_back(available);
3862
				++count;
3862
				++count;
3863
			}
3863
			}
3864
		}
3864
		}
Line 3877... Line 3877...
3877
					found = false;
3877
					found = false;
3878
					for (CListNode<CBaseFile>* pNode = m_lInstallList.Front(); pNode; pNode = pNode->next())
3878
					for (CListNode<CBaseFile>* pNode = m_lInstallList.Front(); pNode; pNode = pNode->next())
3879
					{
3879
					{
3880
						CBaseFile* checkP = pNode->Data();
3880
						CBaseFile* checkP = pNode->Data();
3881
						if (p->author().Compare(checkP->author()) && p->name().Compare(checkP->name()))
3881
						if (p->author().Compare(checkP->author()) && p->name().Compare(checkP->name()))
3882
						{
3882
						{
3883
							found = true;
3883
							found = true;
3884
							break;
3884
							break;
3885
						}
3885
						}
3886
					}
3886
					}
3887
				}
3887
				}
3888
				else
3888
				else
3889
					found = false;
3889
					found = false;
3890
			}
3890
			}
3891
 
3891
 
3892
			if (!found)
3892
			if (!found)
3893
			{
3893
			{
Line 3941... Line 3941...
3941
						}
3941
						}
3942
					}
3942
					}
3943
				}
3943
				}
3944
				else
3944
				else
3945
					found = false;
3945
					found = false;
3946
			}
3946
			}
3947
 
3947
 
3948
			if ( !found )
3948
			if ( !found )
3949
			{
3949
			{
3950
				if ( list )
3950
				if ( list )
3951
					list->pushBack(spk->GetOtherName(), spk->GetOtherAuthor());
3951
					list->pushBack(spk->GetOtherName(), spk->GetOtherAuthor());
3952
				++count;
3952
				++count;
Line 3971... Line 3971...
3971
			missingDep = true;
3971
			missingDep = true;
3972
		else if ( this->getMissingDependacies(p, NULL, false, true) )
3972
		else if ( this->getMissingDependacies(p, NULL, false, true) )
3973
			missingDep = true;
3973
			missingDep = true;
3974
 
3974
 
3975
		if ( missingDep )
3975
		if ( missingDep )
3976
		{
3976
		{
3977
			if ( list )
3977
			if ( list )
3978
			{
3978
			{
3979
				node->ChangeData(NULL);
3979
				node->ChangeData(NULL);
3980
				list->push_back(p);
3980
				list->push_back(p);
3981
			}
3981
			}
Line 4058... Line 4058...
4058
	}
4058
	}
4059
 
4059
 
4060
	m_lUninstallFiles.RemoveEmpty();
4060
	m_lUninstallFiles.RemoveEmpty();
4061
 
4061
 
4062
	return files;
4062
	return files;
4063
}
4063
}
4064
 
4064
 
4065
 
4065
 
4066
/**
4066
/**
4067
 * Remove unused shared file
4067
 * Remove unused shared file
4068
 *
4068
 *
4069
 * Removes a single file
4069
 * Removes a single file
4070
 */
4070
 */
4071
bool CPackages::removeSharedFile(C_File *file, Utils::WStringList *errors)
4071
bool CPackages::removeSharedFile(C_File *file, Utils::WStringList *errors)
4072
{
4072
{
4073
	CFileIO fio(file->filePointer());
4073
	CFileIO fio(file->filePointer());
Line 4088... Line 4088...
4088
/**
4088
/**
4089
 * Remove Unused Shared Files
4089
 * Remove Unused Shared Files
4090
 *
4090
 *
4091
 * Files that have been marked as shared will not be removed or disabled when the last package is removed
4091
 * Files that have been marked as shared will not be removed or disabled when the last package is removed
4092
 * This function will remove any that are no longer connected with packages
4092
 * This function will remove any that are no longer connected with packages
4093
 *
4093
 *
4094
 * Marked shared fiels are mainly used for library scripts that arn't always added to packages
4094
 * Marked shared fiels are mainly used for library scripts that arn't always added to packages
4095
 */
4095
 */
4096
int CPackages::removeUnusedSharedFiles(Utils::WStringList *errors, CProgressInfo *progress)
4096
int CPackages::removeUnusedSharedFiles(Utils::WStringList *errors, CProgressInfo *progress)
4097
{
4097
{
4098
	UpdateUsedFiles();
4098
	UpdateUsedFiles();
Line 4107... Line 4107...
4107
 
4107
 
4108
		C_File *file = node->Data();
4108
		C_File *file = node->Data();
4109
 
4109
 
4110
		// only do marked shared files
4110
		// only do marked shared files
4111
		if ( !file->IsShared() )
4111
		if ( !file->IsShared() )
4112
			continue;
4112
			continue;
4113
 
4113
 
4114
		// only do ones that are no longer needed
4114
		// only do ones that are no longer needed
4115
		if ( file->getUsed() )
4115
		if ( file->getUsed() )
4116
			continue;
4116
			continue;
4117
 
4117
 
4118
		if (removeSharedFile(file, errors) )
4118
		if (removeSharedFile(file, errors) )
4119
			++done;
4119
			++done;
4120
		node->ChangeData(NULL);
4120
		node->ChangeData(NULL);
4121
	}
4121
	}
4122
 
4122
 
4123
	m_lFiles.RemoveEmpty();
4123
	m_lFiles.RemoveEmpty();
4124
 
4124
 
4125
	return done;
4125
	return done;
4126
}
4126
}
4127
 
4127
 
4128
/**
4128
/**
4129
 * Any Unused Shared
4129
 * Any Unused Shared
4130
 *
4130
 *
4131
 * Checks if theres any unused shared files available
4131
 * Checks if theres any unused shared files available
4132
 *
4132
 *
4133
 * Any file thats marked as shared, and is no longer connected to any installed package
4133
 * Any file thats marked as shared, and is no longer connected to any installed package
4134
 */
4134
 */
4135
bool CPackages::AnyUnusedShared()
4135
bool CPackages::AnyUnusedShared()
4136
{
4136
{
4137
	UpdateUsedFiles();
4137
	UpdateUsedFiles();
4138
 
4138
 
4139
	for ( CListNode<C_File> *node = m_lFiles.Back(); node; node = node->prev() )
4139
	for ( CListNode<C_File> *node = m_lFiles.Back(); node; node = node->prev() )
4140
	{
4140
	{
4141
		C_File *file = node->Data();
4141
		C_File *file = node->Data();
4142
 
4142
 
4143
		// only do marked shared files
4143
		// only do marked shared files
4144
		if ( !file->IsShared() )
4144
		if ( !file->IsShared() )
4145
			continue;
4145
			continue;
4146
 
4146
 
4147
		// only do ones that are no longer needed
4147
		// only do ones that are no longer needed
4148
		if ( file->getUsed() )
4148
		if ( file->getUsed() )
4149
			continue;
4149
			continue;
4150
 
4150
 
4151
		return true;
4151
		return true;
4152
	}
4152
	}
4153
 
4153
 
4154
	return false;
4154
	return false;
4155
 
4155
 
4156
}
4156
}
4157
 
4157
 
Line 4177... Line 4177...
4177
		{
4177
		{
4178
			CFileIO moveFile(f->filePointer());
4178
			CFileIO moveFile(f->filePointer());
4179
	
4179
	
4180
			Utils::WString newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + L"." + moveFile.extension();
4180
			Utils::WString newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + L"." + moveFile.extension();
4181
			if ( moveFile.Rename(m_sCurrentDir + L"/t/" + newName) )
4181
			if ( moveFile.Rename(m_sCurrentDir + L"/t/" + newName) )
4182
			{
4182
			{
4183
				this->addLogEntry(SPKINSTALL_AUTOTEXT, f->name() + L"~" + newName, errors);
4183
				this->addLogEntry(SPKINSTALL_AUTOTEXT, f->name() + L"~" + newName, errors);
4184
				f->setName(newName.toString());
4184
				f->setName(newName.toString());
4185
			}
4185
			}
4186
			else
4186
			else
4187
				this->addLogEntry(SPKINSTALL_AUTOTEXT_FAIL, f->name() + L"~" + newName, errors);
4187
				this->addLogEntry(SPKINSTALL_AUTOTEXT_FAIL, f->name() + L"~" + newName, errors);
Line 4232... Line 4232...
4232
		if (spk)
4232
		if (spk)
4233
		{
4233
		{
4234
			if (spk->IsAnotherMod())
4234
			if (spk->IsAnotherMod())
4235
			{
4235
			{
4236
				auto package = findPackage(spk->otherName(), spk->otherAuthor());
4236
				auto package = findPackage(spk->otherName(), spk->otherAuthor());
4237
				if (package)
4237
				if (package)
4238
				{
4238
				{
4239
					packagesBefore.insert(package);
4239
					packagesBefore.insert(package);
4240
					packagesAfter[p].insert(package);
4240
					packagesAfter[p].insert(package);
4241
				}
4241
				}
4242
			}
4242
			}
4243
		}
4243
		}
4244
 
4244
 
4245
		if (!p->getFakePatchBeforeOrder().empty())
4245
		if (!p->getFakePatchBeforeOrder().empty())
Line 4249... Line 4249...
4249
			for (auto itr = list.begin(); itr != list.end(); itr++)
4249
			for (auto itr = list.begin(); itr != list.end(); itr++)
4250
			{
4250
			{
4251
				auto package = findPackage((*itr)->str, (*itr)->data);
4251
				auto package = findPackage((*itr)->str, (*itr)->data);
4252
				if (package)				
4252
				if (package)				
4253
					packagesAfter[package].insert(p);
4253
					packagesAfter[package].insert(p);
4254
			}
4254
			}
4255
		}
4255
		}
4256
		if (!p->getFakePatchAfterOrder().empty())
4256
		if (!p->getFakePatchAfterOrder().empty())
4257
		{
4257
		{
4258
			auto& list = p->getFakePatchAfterOrder();
4258
			auto& list = p->getFakePatchAfterOrder();
4259
			for (auto itr = list.begin(); itr != list.end(); itr++)
4259
			for (auto itr = list.begin(); itr != list.end(); itr++)
4260
			{
4260
			{
Line 4265... Line 4265...
4265
					packagesAfter[p].insert(package);
4265
					packagesAfter[p].insert(package);
4266
				}
4266
				}
4267
			}
4267
			}
4268
		}
4268
		}
4269
	}
4269
	}
4270
 
4270
 
4271
	auto addOrderedList = [](const std::vector<CBaseFile*>& addList, const Utils::WStringList& orderList, std::vector<CBaseFile*>& addTo, const CPackages *packages)
4271
	auto addOrderedList = [](const std::vector<CBaseFile*>& addList, const Utils::WStringList& orderList, std::vector<CBaseFile*>& addTo, const CPackages *packages)
4272
	{
4272
	{
4273
		// add all the items in the ordered list first
4273
		// add all the items in the ordered list first
4274
		for (auto itr = orderList.begin(); itr != orderList.end(); itr++)
4274
		for (auto itr = orderList.begin(); itr != orderList.end(); itr++)
4275
		{
4275
		{
Line 4294... Line 4294...
4294
				addTo.push_back(*itr);
4294
				addTo.push_back(*itr);
4295
		}
4295
		}
4296
	};
4296
	};
4297
 
4297
 
4298
	auto removeList = [](const std::vector<CBaseFile*>& removeList, std::set<CBaseFile*>& list)
4298
	auto removeList = [](const std::vector<CBaseFile*>& removeList, std::set<CBaseFile*>& list)
4299
	{
4299
	{
4300
		for (auto itr = removeList.begin(); itr != removeList.end(); itr++)
4300
		for (auto itr = removeList.begin(); itr != removeList.end(); itr++)
4301
		{
4301
		{
4302
			auto findItr = std::find(list.begin(), list.end(), *itr);
4302
			auto findItr = std::find(list.begin(), list.end(), *itr);
4303
			if (findItr != list.end())
4303
			if (findItr != list.end())
4304
				list.erase(findItr);
4304
				list.erase(findItr);
4305
		}
4305
		}
4306
	};
4306
	};
4307
 
4307
 
4308
	std::vector<CBaseFile*> order;
4308
	std::vector<CBaseFile*> order;
4309
	while (!packagesBefore.empty())
4309
	while (!packagesBefore.empty())
4310
	{
4310
	{
4311
		std::vector<CBaseFile*> packagesOrder;
4311
		std::vector<CBaseFile*> packagesOrder;
4312
 
4312
 
Line 4323... Line 4323...
4323
				bool notAdded = false;
4323
				bool notAdded = false;
4324
				for (auto checkItr = findItr->second.begin(); checkItr != findItr->second.end(); checkItr++)
4324
				for (auto checkItr = findItr->second.begin(); checkItr != findItr->second.end(); checkItr++)
4325
				{
4325
				{
4326
					auto findItr2 = std::find(order.begin(), order.end(), *checkItr);
4326
					auto findItr2 = std::find(order.begin(), order.end(), *checkItr);
4327
					if (findItr2 == order.end())
4327
					if (findItr2 == order.end())
4328
					{
4328
					{
4329
						notAdded = true;
4329
						notAdded = true;
4330
						break;
4330
						break;
4331
					}
4331
					}
4332
				}
4332
				}
4333
 
4333
 
4334
				if (!notAdded)
4334
				if (!notAdded)
4335
					packagesOrder.push_back(p);
4335
					packagesOrder.push_back(p);
4336
			}
4336
			}
4337
		}
4337
		}
4338
 
4338
 
4339
 
4339
 
4340
		// no valid packages left ? lets just add the rest
4340
		// no valid packages left ? lets just add the rest
4341
		if (packagesOrder.empty())
4341
		if (packagesOrder.empty())
4342
		{
4342
		{
4343
			for (auto itr = packagesBefore.begin(); itr != packagesBefore.end(); itr++)
4343
			for (auto itr = packagesBefore.begin(); itr != packagesBefore.end(); itr++)
4344
				packagesOrder.push_back(*itr);
4344
				packagesOrder.push_back(*itr);
4345
		}
4345
		}
4346
 
4346
 
4347
		addOrderedList(packagesOrder, _lFakePatchOrder, order, this);
4347
		addOrderedList(packagesOrder, _lFakePatchOrder, order, this);
Line 4351... Line 4351...
4351
	// now add the remaining list ordered list
4351
	// now add the remaining list ordered list
4352
	for (auto itr = _lFakePatchOrder.begin(); itr != _lFakePatchOrder.end(); itr++)
4352
	for (auto itr = _lFakePatchOrder.begin(); itr != _lFakePatchOrder.end(); itr++)
4353
	{
4353
	{
4354
		auto p = findPackage((*itr)->str, (*itr)->data);
4354
		auto p = findPackage((*itr)->str, (*itr)->data);
4355
		if (p)
4355
		if (p)
4356
		{
4356
		{
4357
			auto findItr = std::find(order.begin(), order.end(), p);
4357
			auto findItr = std::find(order.begin(), order.end(), p);
4358
			if (findItr == order.end())
4358
			if (findItr == order.end())
4359
				order.push_back(p);
4359
				order.push_back(p);
4360
		}
4360
		}
4361
	}
4361
	}
4362
 
4362
 
4363
	for(auto itr = order.begin(); itr != order.end(); itr++)
4363
	for(auto itr = order.begin(); itr != order.end(); itr++)
4364
	{
4364
	{
4365
		CBaseFile *package = *itr;
4365
		CBaseFile *package = *itr;
4366
		if ( package )
4366
		if ( package )
4367
		{
4367
		{
Line 4379... Line 4379...
4379
						lowestFile = file;
4379
						lowestFile = file;
4380
					else
4380
					else
4381
					{
4381
					{
4382
						if ( file->baseName().toInt() < lowestFile->baseName().toInt() )
4382
						if ( file->baseName().toInt() < lowestFile->baseName().toInt() )
4383
							lowestFile = file;
4383
							lowestFile = file;
4384
					}
4384
					}
4385
				}
4385
				}
4386
 
4386
 
4387
				if ( !lowestFile ) // no more files ?
4387
				if ( !lowestFile ) // no more files ?
4388
					break;
4388
					break;
4389
 
4389
 
Line 4432... Line 4432...
4432
		// check if the file is a fake patch
4432
		// check if the file is a fake patch
4433
		if ( !f->IsFakePatch() )
4433
		if ( !f->IsFakePatch() )
4434
			continue;
4434
			continue;
4435
 
4435
 
4436
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4436
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4437
		if (!f->checkFileExt("cat"))
4437
		if (!f->checkFileExt(L"cat"))
4438
			continue;
4438
			continue;
4439
 
4439
 
4440
		// now lets check if its greater than our gap
4440
		// now lets check if its greater than our gap
4441
		int check = findNextFakePatch();
4441
		int check = findNextFakePatch();
4442
		int patchNum = f->filename().token(L".", 1).toInt();
4442
		int patchNum = f->filename().token(L".", 1).toInt();
Line 4518... Line 4518...
4518
 
4518
 
4519
	int check = start;
4519
	int check = start;
4520
	while ( check > 0 )
4520
	while ( check > 0 )
4521
	{
4521
	{
4522
		Utils::WString checkStr = Utils::String::PadNumber(check, 2);
4522
		Utils::WString checkStr = Utils::String::PadNumber(check, 2);
4523
 
4523
 
4524
		// check if a cat file exists
4524
		// check if a cat file exists
4525
		if ( !Dir.exists(checkStr + L".cat") )
4525
		if ( !Dir.exists(checkStr + L".cat") )
4526
		{
4526
		{
4527
			// it doen't, check if theres a dat file (incase of package error)
4527
			// it doen't, check if theres a dat file (incase of package error)
4528
			if ( !Dir.exists(checkStr + L".dat") )
4528
			if ( !Dir.exists(checkStr + L".dat") )
4529
				break;
4529
				break;
4530
		}
4530
		}
4531
		--check;
4531
		--check;
4532
	}
4532
	}
4533
 
4533
 
4534
	return check;
4534
	return check;
4535
}
4535
}
4536
 
4536
 
4537
/**
4537
/**
4538
 * Find next fake patch
4538
 * Find next fake patch
4539
 *
4539
 *
4540
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4540
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
Line 4552... Line 4552...
4552
		// check if a cat file exists
4552
		// check if a cat file exists
4553
		if ( !Dir.exists(checkStr + L".cat") )
4553
		if ( !Dir.exists(checkStr + L".cat") )
4554
		{
4554
		{
4555
			// it doen't, check if theres a dat file (incase of package error)
4555
			// it doen't, check if theres a dat file (incase of package error)
4556
			if ( !Dir.exists(checkStr + L".dat") )
4556
			if ( !Dir.exists(checkStr + L".dat") )
4557
				break;
4557
				break;
4558
		}
4558
		}
4559
	}
4559
	}
4560
 
4560
 
4561
	return check;
4561
	return check;
4562
}
4562
}
4563
 
4563
 
4564
/**
4564
/**
4565
 * Find next text file
4565
 * Find next text file
4566
 *
4566
 *
4567
 * Searching for the next gap in automatic text files, start with 0004-LXXX or XX0004
4567
 * Searching for the next gap in automatic text files, start with 0004-LXXX or XX0004
4568
 */
4568
 */
Line 4588... Line 4588...
4588
 
4588
 
4589
	return check;
4589
	return check;
4590
}
4590
}
4591
 
4591
 
4592
int CPackages::findLastTextFile(int start, const Utils::WString& dir) const
4592
int CPackages::findLastTextFile(int start, const Utils::WString& dir) const
4593
{
4593
{
4594
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4594
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4595
	Dir.cd(L"t");
4595
	Dir.cd(L"t");
4596
 
4596
 
4597
	int check = start;
4597
	int check = start;
4598
	while ( check < 9999 )
4598
	while ( check < 9999 )
Line 4624... Line 4624...
4624
		return;
4624
		return;
4625
 
4625
 
4626
	CDirIO Dir(m_sCurrentDir);
4626
	CDirIO Dir(m_sCurrentDir);
4627
 
4627
 
4628
	// check for lang.dat file
4628
	// check for lang.dat file
4629
	if ( Dir.exists("lang.dat") )
4629
	if ( Dir.exists(L"lang.dat") )
4630
	{
4630
	{
4631
		CFileIO File(Dir.file("lang.dat"));
4631
		CFileIO File(Dir.file(L"lang.dat"));
4632
 
4632
 
4633
		size_t size;
4633
		size_t size;
4634
		char *data = File.ReadToData(&size);
4634
		char *data = File.ReadToData(&size);
4635
 
4635
 
4636
		if ( data )
4636
		if ( data )
Line 4649... Line 4649...
4649
void CPackages::CreateLanguageTextFiles(Utils::WStringList *errors)
4649
void CPackages::CreateLanguageTextFiles(Utils::WStringList *errors)
4650
{
4650
{
4651
	// no need to create them if theres no language to use
4651
	// no need to create them if theres no language to use
4652
	if ( !m_iLanguage )
4652
	if ( !m_iLanguage )
4653
		return;
4653
		return;
4654
 
4654
 
4655
	// find all text files
4655
	// find all text files
4656
	Utils::WStringList ids;
4656
	Utils::WStringList ids;
4657
 
4657
 
4658
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4658
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4659
	{
4659
	{
Line 4737... Line 4737...
4737
 
4737
 
4738
		if ( !useId )
4738
		if ( !useId )
4739
			useId = data[0].toInt();
4739
			useId = data[0].toInt();
4740
		if ( !useId )
4740
		if ( !useId )
4741
			useId = -1;
4741
			useId = -1;
4742
 
4742
 
4743
		renameTextFile((*itr)->str, useId, errors);
4743
		renameTextFile((*itr)->str, useId, errors);
4744
	}
4744
	}
4745
}
4745
}
4746
 
4746
 
4747
/**
4747
/**
Line 4795... Line 4795...
4795
		{
4795
		{
4796
			Utils::WString newLine = L"<language id=\"";
4796
			Utils::WString newLine = L"<language id=\"";
4797
			newLine += Utils::WString::Number(m_iLanguage);
4797
			newLine += Utils::WString::Number(m_iLanguage);
4798
			newLine += L"\">";
4798
			newLine += L"\">";
4799
			newLine += line.tokens(L">", 2);
4799
			newLine += line.tokens(L">", 2);
4800
 
4800
 
4801
			frontLines.insert(frontLines.begin(), newLine);
4801
			frontLines.insert(frontLines.begin(), newLine);
4802
 
4802
 
4803
			lines.erase(lines.begin(), ++it);
4803
			lines.erase(lines.begin(), ++it);
4804
			break;
4804
			break;
4805
		}
4805
		}
Line 5176... Line 5176...
5176
	{
5176
	{
5177
		if ( !node->Data()->CheckGameCompatability(m_iGame) )
5177
		if ( !node->Data()->CheckGameCompatability(m_iGame) )
5178
			continue;
5178
			continue;
5179
		if ( onlyEnabled && !node->Data()->IsEnabled() )
5179
		if ( onlyEnabled && !node->Data()->IsEnabled() )
5180
			continue;
5180
			continue;
5181
		if ( node->Data()->author().Compare("PluginManager") )
5181
		if ( node->Data()->author().Compare(L"PluginManager") )
5182
			++count;
5182
			++count;
5183
	}
5183
	}
5184
 
5184
 
5185
	return count;
5185
	return count;
5186
}
5186
}
Line 5735... Line 5735...
5735
	int lang = m_iLanguage;
5735
	int lang = m_iLanguage;
5736
	if ( !lang || lang < 0 )
5736
	if ( !lang || lang < 0 )
5737
		lang = 44;
5737
		lang = 44;
5738
 
5738
 
5739
	CDirIO Dir(m_sCurrentDir);
5739
	CDirIO Dir(m_sCurrentDir);
5740
	if ( !Dir.exists("t") )
5740
	if ( !Dir.exists(L"t") )
5741
		Dir.create("t");
5741
		Dir.create(L"t");
5742
 
5742
 
5743
	Utils::WString filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5743
	Utils::WString filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5744
	CFileIO textFile(m_sCurrentDir + L"/t/" + filename + L".xml");
5744
	CFileIO textFile(m_sCurrentDir + L"/t/" + filename + L".xml");
5745
 
5745
 
5746
	std::vector<Utils::WString> writeData;
5746
	std::vector<Utils::WString> writeData;
Line 6161... Line 6161...
6161
	this->Reset();
6161
	this->Reset();
6162
	m_bLoaded = false;
6162
	m_bLoaded = false;
6163
 
6163
 
6164
	// clear the plugin manager directory
6164
	// clear the plugin manager directory
6165
	CDirIO Dir(m_sCurrentDir);
6165
	CDirIO Dir(m_sCurrentDir);
6166
	Dir.removeDir("PluginManager", true, true, 0);
6166
	Dir.removeDir(L"PluginManager", true, true, 0);
6167
	Dir.removeDir("dds", false, true, 0);
6167
	Dir.removeDir(L"dds", false, true, 0);
6168
	Dir.removeDir("objects", false, true, 0);
6168
	Dir.removeDir(L"objects", false, true, 0);
6169
	Dir.removeDir("types", false, true, 0);
6169
	Dir.removeDir(L"types", false, true, 0);
6170
	Dir.removeDir("textures", false, true, 0);
6170
	Dir.removeDir(L"textures", false, true, 0);
6171
 
6171
 
6172
	// remove the plugin manager mod files
6172
	// remove the plugin manager mod files
6173
	if ( Dir.exists("mods/PluginManager.cat") )	CFileIO::Remove(Dir.file("mods/PluginManager.cat"));
6173
	if ( Dir.exists(L"mods/PluginManager.cat") )	CFileIO::Remove(Dir.file(L"mods/PluginManager.cat"));
6174
	if ( Dir.exists("mods/PluginManager.dat") )	CFileIO::Remove(Dir.file("mods/PluginManager.dat"));
6174
	if ( Dir.exists(L"mods/PluginManager.dat") )	CFileIO::Remove(Dir.file(L"mods/PluginManager.dat"));
6175
 
6175
 
6176
	return true;
6176
	return true;
6177
}
6177
}
6178
 
6178
 
6179
void CPackages::CreateDummies()
6179
void CPackages::CreateDummies()
Line 6183... Line 6183...
6183
		return;
6183
		return;
6184
 
6184
 
6185
	CLinkList<SDummyEntry> dummyList;
6185
	CLinkList<SDummyEntry> dummyList;
6186
 
6186
 
6187
	// now extract the existing dummies
6187
	// now extract the existing dummies
6188
	int e = extractGameFile("types/Dummies.pck", m_sTempDir + "/Dummies.txt");
6188
	int e = extractGameFile(L"types/Dummies.pck", m_sTempDir + L"/Dummies.txt");
6189
	if ( e )
6189
	if ( e )
6190
	{
6190
	{
6191
		// read the dummies
6191
		// read the dummies
6192
		CFileIO File;
6192
		CFileIO File;
6193
		if ( File.open((e == -1) ? "Dummies.txt" : m_sTempDir + "/Dummies.txt") )
6193
		if ( File.open((e == -1) ? L"Dummies.txt" : m_sTempDir + L"/Dummies.txt") )
6194
		{
6194
		{
6195
			std::vector<Utils::String> lines;
6195
			std::vector<Utils::String> lines;
6196
			if(File.readLines(lines))
6196
			if(File.readLines(lines))
6197
			{
6197
			{
6198
				int insection = 0;
6198
				int insection = 0;
Line 6343... Line 6343...
6343
			}
6343
			}
6344
		}
6344
		}
6345
		lines.push_back("");
6345
		lines.push_back("");
6346
 
6346
 
6347
		// write the file to disk
6347
		// write the file to disk
6348
		CFileIO WriteFile(m_sTempDir + "/dummies.txt");
6348
		CFileIO WriteFile(m_sTempDir + L"/dummies.txt");
6349
		if ( WriteFile.writeFile(&lines) )
6349
		if ( WriteFile.writeFile(&lines) )
6350
		{
6350
		{
6351
			this->packFile(&WriteFile, "types\\dummies.pck");
6351
			this->packFile(&WriteFile, L"types\\dummies.pck");
6352
			WriteFile.remove();
6352
			WriteFile.remove();
6353
		}
6353
		}
6354
	}
6354
	}
6355
}
6355
}
6356
 
6356
 
Line 6376... Line 6376...
6376
 
6376
 
6377
	if ( !found )
6377
	if ( !found )
6378
		return;
6378
		return;
6379
 
6379
 
6380
	std::vector<Utils::String> cutList;
6380
	std::vector<Utils::String> cutList;
6381
	int e = extractGameFile("types/CutData.pck", m_sTempDir + "/CutData.txt");
6381
	int e = extractGameFile(L"types/CutData.pck", m_sTempDir + L"/CutData.txt");
6382
	if ( e )
6382
	if ( e )
6383
	{
6383
	{
6384
		CFileIO File;
6384
		CFileIO File;
6385
		if ( File.open((e == -1) ? "CutData.txt" : m_sTempDir + "/CutData.txt") )
6385
		if ( File.open((e == -1) ? L"CutData.txt" : m_sTempDir + L"/CutData.txt") )
6386
		{
6386
		{
6387
 
6387
 
6388
			std::vector<Utils::String> lines;
6388
			std::vector<Utils::String> lines;
6389
			if(File.readLines(lines))
6389
			if(File.readLines(lines))
6390
			{
6390
			{
Line 6440... Line 6440...
6440
	cutList.insert(cutList.begin(), Utils::String::Number(cutList.size()) + ";");
6440
	cutList.insert(cutList.begin(), Utils::String::Number(cutList.size()) + ";");
6441
	cutList.insert(cutList.begin(), "/cut id;filename (leave blank to use id)");
6441
	cutList.insert(cutList.begin(), "/cut id;filename (leave blank to use id)");
6442
	cutList.insert(cutList.begin(), "// Cut Data file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6442
	cutList.insert(cutList.begin(), "// Cut Data file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6443
 
6443
 
6444
	// write the file to disk
6444
	// write the file to disk
6445
	CFileIO WriteFile(m_sTempDir + "/CutData.txt");
6445
	CFileIO WriteFile(m_sTempDir + L"/CutData.txt");
6446
	if ( WriteFile.writeFile(&cutList) )
6446
	if ( WriteFile.writeFile(&cutList) )
6447
	{
6447
	{
6448
		this->packFile(&WriteFile, "types\\CutData.pck");
6448
		this->packFile(&WriteFile, L"types\\CutData.pck");
6449
		WriteFile.remove();
6449
		WriteFile.remove();
6450
	}
6450
	}
6451
}
6451
}
6452
 
6452
 
6453
void CPackages::CreateAnimations()
6453
void CPackages::CreateAnimations()
Line 6589... Line 6589...
6589
 
6589
 
6590
	formatedAniList.pushFront(Utils::String::Number(parsedAniList.size()) + ";");
6590
	formatedAniList.pushFront(Utils::String::Number(parsedAniList.size()) + ";");
6591
	formatedAniList.pushFront("// Animations, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6591
	formatedAniList.pushFront("// Animations, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6592
 
6592
 
6593
	// write the file to disk
6593
	// write the file to disk
6594
	CFileIO WriteFile(m_sTempDir + "/Animations.txt");
6594
	CFileIO WriteFile(m_sTempDir + L"/Animations.txt");
6595
	if ( WriteFile.writeFile(&formatedAniList) )
6595
	if ( WriteFile.writeFile(&formatedAniList) )
6596
	{
6596
	{
6597
		this->packFile(&WriteFile, "types\\Animations.pck");
6597
		this->packFile(&WriteFile, L"types\\Animations.pck");
6598
		WriteFile.remove();
6598
		WriteFile.remove();
6599
	}
6599
	}
6600
}
6600
}
6601
 
6601
 
6602
void CPackages::CreateBodies()
6602
void CPackages::CreateBodies()
Line 6738... Line 6738...
6738
			writeList.push_back(str);
6738
			writeList.push_back(str);
6739
		}
6739
		}
6740
	}
6740
	}
6741
 
6741
 
6742
	// write the file to disk
6742
	// write the file to disk
6743
	CFileIO WriteFile(m_sTempDir + "/Bodies.txt");
6743
	CFileIO WriteFile(m_sTempDir + L"/Bodies.txt");
6744
	if ( WriteFile.writeFile(&writeList) )
6744
	if ( WriteFile.writeFile(&writeList) )
6745
	{
6745
	{
6746
		this->packFile(&WriteFile, "types\\Bodies.pck");
6746
		this->packFile(&WriteFile, L"types\\Bodies.pck");
6747
		WriteFile.remove();
6747
		WriteFile.remove();
6748
	}
6748
	}
6749
}
6749
}
6750
 
6750
 
6751
void CPackages::CreateCustomStarts()
6751
void CPackages::CreateCustomStarts()
Line 6817... Line 6817...
6817
		return;
6817
		return;
6818
 
6818
 
6819
	CLinkList<SComponantEntry> dummyList;
6819
	CLinkList<SComponantEntry> dummyList;
6820
 
6820
 
6821
	// now extract the existing dummies
6821
	// now extract the existing dummies
6822
	int e = extractGameFile("types/Components.pck", m_sTempDir + "/Components.txt");
6822
	int e = extractGameFile(L"types/Components.pck", m_sTempDir + L"/Components.txt");
6823
	if ( e )
6823
	if ( e )
6824
	{
6824
	{
6825
		// read the dummies
6825
		// read the dummies
6826
		CFileIO File;
6826
		CFileIO File;
6827
		if ( File.open((e == -1) ? "Components.txt" : m_sTempDir + "/Components.txt") )
6827
		if ( File.open((e == -1) ? L"Components.txt" : m_sTempDir + L"/Components.txt") )
6828
		{
6828
		{
6829
			std::vector<Utils::String> *lines = File.readLines();
6829
			std::vector<Utils::String> *lines = File.readLines();
6830
			if ( lines )
6830
			if ( lines )
6831
			{
6831
			{
6832
				int insection = 0;
6832
				int insection = 0;
Line 7004... Line 7004...
7004
				}
7004
				}
7005
			}
7005
			}
7006
		}
7006
		}
7007
 
7007
 
7008
		// write the file to disk
7008
		// write the file to disk
7009
		CFileIO WriteFile(m_sTempDir + "/Components.txt");
7009
		CFileIO WriteFile(m_sTempDir + L"/Components.txt");
7010
		if ( WriteFile.writeFile(&lines) )
7010
		if ( WriteFile.writeFile(&lines) )
7011
		{
7011
		{
7012
			this->packFile(&WriteFile, "types\\Components.pck");
7012
			this->packFile(&WriteFile, L"types\\Components.pck");
7013
			WriteFile.remove();
7013
			WriteFile.remove();
7014
		}
7014
		}
7015
	}
7015
	}
7016
}
7016
}
7017
 
7017
 
Line 7192... Line 7192...
7192
		Utils::WStringList writeList;
7192
		Utils::WStringList writeList;
7193
		for(auto itr = globals.begin(); itr != globals.end(); itr++)
7193
		for(auto itr = globals.begin(); itr != globals.end(); itr++)
7194
			writeList.pushBack((*itr)->str + L";" + (*itr)->data + L";");
7194
			writeList.pushBack((*itr)->str + L";" + (*itr)->data + L";");
7195
		
7195
		
7196
		// finally, write the file
7196
		// finally, write the file
7197
		writeList.pushFront(Utils::WString::Number(writeList.size()) + L"; /globals amount", "");
7197
		writeList.pushFront(Utils::WString::Number(writeList.size()) + L"; /globals amount", L"");
7198
		writeList.pushFront(L"// Globals file, created by SPK Libraries V" + Utils::WString::FromFloat(GetLibraryVersion(), 2), L"");
7198
		writeList.pushFront(L"// Globals file, created by SPK Libraries V" + Utils::WString::FromFloat(GetLibraryVersion(), 2), L"");
7199
 
7199
 
7200
		CFileIO WriteFile(m_sTempDir + L"/Globals.txt");
7200
		CFileIO WriteFile(m_sTempDir + L"/Globals.txt");
7201
		if ( WriteFile.writeFile(&writeList) )
7201
		if ( WriteFile.writeFile(&writeList) )
7202
		{
7202
		{
Line 7233... Line 7233...
7233
			continue;
7233
			continue;
7234
		shipOverrides.push_back(node->Data());
7234
		shipOverrides.push_back(node->Data());
7235
	}
7235
	}
7236
 
7236
 
7237
	// read the existing tships file
7237
	// read the existing tships file
7238
	int e = extractGameFile("types/TShips.pck", m_sTempDir + "/TShips.txt");
7238
	int e = extractGameFile(L"types/TShips.pck", m_sTempDir + L"/TShips.txt");
7239
	if ( e )
7239
	if ( e )
7240
	{
7240
	{
7241
		int fileType = 51;
7241
		int fileType = 51;
7242
		std::vector<Utils::String> tshipsList;
7242
		std::vector<Utils::String> tshipsList;
7243
 
7243
 
7244
		// if we have no buffer, lets create one
7244
		// if we have no buffer, lets create one
7245
		CFileIO File;
7245
		CFileIO File;
7246
		if ( File.open((e == -1) ? "TShips.txt" : m_sTempDir + "/TShips.txt") )
7246
		if ( File.open((e == -1) ? L"TShips.txt" : m_sTempDir + L"/TShips.txt") )
7247
		{
7247
		{
7248
			int shiptext = SHIPSTARTTEXT;
7248
			int shiptext = SHIPSTARTTEXT;
7249
 
7249
 
7250
			std::vector<Utils::String> *lines = File.readLines();
7250
			std::vector<Utils::String> *lines = File.readLines();
7251
			if ( lines )
7251
			if ( lines )
Line 7352... Line 7352...
7352
 
7352
 
7353
			// finally, write the file
7353
			// finally, write the file
7354
			tshipsList.insert(tshipsList.begin(), Utils::String::Number(fileType) + ";" + Utils::String::Number(tshipsList.size()) + ";");
7354
			tshipsList.insert(tshipsList.begin(), Utils::String::Number(fileType) + ";" + Utils::String::Number(tshipsList.size()) + ";");
7355
			tshipsList.insert(tshipsList.begin(), "// TShips file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
7355
			tshipsList.insert(tshipsList.begin(), "// TShips file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
7356
 
7356
 
7357
			CFileIO WriteFile(m_sTempDir + "/TShips.txt");
7357
			CFileIO WriteFile(m_sTempDir + L"/TShips.txt");
7358
			if ( WriteFile.writeFile(&tshipsList) )
7358
			if ( WriteFile.writeFile(&tshipsList) )
7359
			{
7359
			{
7360
				this->packFile(&WriteFile, "types/TShips.pck");
7360
				this->packFile(&WriteFile, L"types/TShips.pck");
7361
				WriteFile.remove();
7361
				WriteFile.remove();
7362
			}
7362
			}
7363
		}
7363
		}
7364
	}
7364
	}
7365
 
7365
 
Line 7509... Line 7509...
7509
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
7509
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
7510
		return NULL;
7510
		return NULL;
7511
 
7511
 
7512
	// now extract the existing cockpits
7512
	// now extract the existing cockpits
7513
	int fileType = 51;
7513
	int fileType = 51;
7514
	int e = extractGameFile("types/TCockpits.pck", m_sTempDir + "/TCockpits.txt");
7514
	int e = extractGameFile(L"types/TCockpits.pck", m_sTempDir + L"/TCockpits.txt");
7515
	if ( e )
7515
	if ( e )
7516
	{
7516
	{
7517
		// read the dummies
7517
		// read the dummies
7518
		CFileIO File;
7518
		CFileIO File;
7519
		if ( File.open((e == -1) ? "TCockpits.txt" : m_sTempDir + "/TCockpits.txt") )
7519
		if ( File.open((e == -1) ? L"TCockpits.txt" : m_sTempDir + L"/TCockpits.txt") )
7520
		{
7520
		{
7521
			std::vector<Utils::String> lines;
7521
			std::vector<Utils::String> lines;
7522
			if(File.readLines(lines))
7522
			if(File.readLines(lines))
7523
			{
7523
			{
7524
				int count = -1;
7524
				int count = -1;
Line 7604... Line 7604...
7604
 
7604
 
7605
		// finally, write the file
7605
		// finally, write the file
7606
		list.pushFront(Utils::String::Number(fileType) + ";" + Utils::String::Number(list.size()) + ";");
7606
		list.pushFront(Utils::String::Number(fileType) + ";" + Utils::String::Number(list.size()) + ";");
7607
		list.pushFront("// TCockpits file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
7607
		list.pushFront("// TCockpits file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
7608
 
7608
 
7609
		CFileIO WriteFile(m_sTempDir + "/TCockpits.txt");
7609
		CFileIO WriteFile(m_sTempDir + L"/TCockpits.txt");
7610
		if ( WriteFile.writeFile(&list) )
7610
		if ( WriteFile.writeFile(&list) )
7611
		{
7611
		{
7612
			this->packFile(&WriteFile, "types\\TCockpits.pck");
7612
			this->packFile(&WriteFile, L"types\\TCockpits.pck");
7613
			WriteFile.remove();
7613
			WriteFile.remove();
7614
		}
7614
		}
7615
 
7615
 
7616
		// remove those entrys
7616
		// remove those entrys
7617
		list.popFront();
7617
		list.popFront();
Line 8019... Line 8019...
8019
					if (p->icon()->writeFilePointer())
8019
					if (p->icon()->writeFilePointer())
8020
						addedIcon = true;
8020
						addedIcon = true;
8021
				}
8021
				}
8022
 
8022
 
8023
				if (!addedIcon)
8023
				if (!addedIcon)
8024
					p->setIcon(NULL, "");
8024
					p->setIcon(NULL, L"");
8025
			}
8025
			}
8026
 
8026
 
8027
			// get an advert to display
8027
			// get an advert to display
8028
			if (p->GetFirstFile(FILETYPE_ADVERT))
8028
			if (p->GetFirstFile(FILETYPE_ADVERT))
8029
			{
8029
			{
Line 8150... Line 8150...
8150
	{
8150
	{
8151
		CCatFile cat;
8151
		CCatFile cat;
8152
		if (cat.open(file, this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) != CATERR_NONE)
8152
		if (cat.open(file, this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) != CATERR_NONE)
8153
			return false;
8153
			return false;
8154
 
8154
 
8155
		if (!cat.extractFile("types\\TShips.pck", m_sTempDir + "/tships.txt"))
8155
		if (!cat.extractFile(L"types\\TShips.pck", m_sTempDir + L"/tships.txt"))
8156
			return false;
8156
			return false;
8157
 
8157
 
8158
		File.open(m_sTempDir + "/tships.txt");
8158
		File.open(m_sTempDir + L"/tships.txt");
8159
		deleteFile = true;
8159
		deleteFile = true;
8160
	}
8160
	}
8161
	// otherwise its a normal file
8161
	// otherwise its a normal file
8162
	else if (CFileIO(file).isFileExtension(L"pck"))
8162
	else if (CFileIO(file).isFileExtension(L"pck"))
8163
	{
8163
	{
8164
		C_File f(file);
8164
		C_File f(file);
8165
		if (!f.ReadFromFile())
8165
		if (!f.ReadFromFile())
8166
			return false;
8166
			return false;
8167
		f.UnPCKFile();
8167
		f.UnPCKFile();
8168
 
8168
 
8169
		f.setFilename(m_sTempDir + "/tships.txt");
8169
		f.setFilename(m_sTempDir + L"/tships.txt");
8170
		if (!f.writeFilePointer())
8170
		if (!f.writeFilePointer())
8171
			return false;
8171
			return false;
8172
 
8172
 
8173
		File.open(m_sTempDir + "/tships.txt");
8173
		File.open(m_sTempDir + L"/tships.txt");
8174
		deleteFile = true;
8174
		deleteFile = true;
8175
	}
8175
	}
8176
	else
8176
	else
8177
		File.open(file);
8177
		File.open(file);
8178
 
8178
 
Line 8344... Line 8344...
8344
				{
8344
				{
8345
					int endpos = itr->findPos(L"\"", pos + 1);
8345
					int endpos = itr->findPos(L"\"", pos + 1);
8346
					if ( endpos > -1 )
8346
					if ( endpos > -1 )
8347
					{
8347
					{
8348
						int id = itr->mid(pos + 2, endpos - pos - 1).toInt();
8348
						int id = itr->mid(pos + 2, endpos - pos - 1).toInt();
8349
						pos = itr->findPos(">", endpos);
8349
						pos = itr->findPos(L">", endpos);
8350
						if ( pos > -1 )
8350
						if ( pos > -1 )
8351
						{
8351
						{
8352
							++pos;
8352
							++pos;
8353
							endpos = itr->findPos(L"</", pos);
8353
							endpos = itr->findPos(L"</", pos);
8354
							if ( endpos > -1 )
8354
							if ( endpos > -1 )
Line 9265... Line 9265...
9265
 
9265
 
9266
	HeaderData.CmtBuf=NULL;
9266
	HeaderData.CmtBuf=NULL;
9267
	memset(&OpenArchiveData.Reserved,0,sizeof(OpenArchiveData.Reserved));
9267
	memset(&OpenArchiveData.Reserved,0,sizeof(OpenArchiveData.Reserved));
9268
 
9268
 
9269
	bool error = false;
9269
	bool error = false;
9270
	Utils::WString extractedFile = CDirIO(m_sTempDir).file("extracted.tst").findReplace(L"/", L"\\").findReplace(L"\\\\", L"\\");
9270
	Utils::WString extractedFile = CDirIO(m_sTempDir).file(L"extracted.tst").findReplace(L"/", L"\\").findReplace(L"\\\\", L"\\");
9271
	while ((RHCode=RARReadHeaderEx(hArcData,&HeaderData))==0)
9271
	while ((RHCode=RARReadHeaderEx(hArcData,&HeaderData))==0)
9272
	{
9272
	{
9273
		Utils::WString fileName = HeaderData.FileName;
9273
		Utils::WString fileName = HeaderData.FileName;
9274
 
9274
 
9275
		if ( HeaderData.FileAttr == 16 )
9275
		if ( HeaderData.FileAttr == 16 )