Subversion Repositories spk

Rev

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

Rev 220 Rev 221
Line 83... Line 83...
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.toString());
88
	_pCurrentDir->langid = this->getGameLanguage(_pCurrentDir->dir);
89
	if (_pCurrentDir->langid > 0)
89
	if (_pCurrentDir->langid > 0)
90
		_pCurrentDir->langname = this->ConvertLanguage(_pCurrentDir->langid);
90
		_pCurrentDir->langname = this->ConvertLanguage(_pCurrentDir->langid);
91
 
91
 
92
	updateFoundPackages(L"");
92
	updateFoundPackages(L"");
93
}
93
}
Line 379... Line 379...
379
					else if ( cmd == L"modifieddisabled" )
379
					else if ( cmd == L"modifieddisabled" )
380
						packageFile->SetModifiedEnabled(false);
380
						packageFile->SetModifiedEnabled(false);
381
					else if ( cmd == L"icon" )
381
					else if ( cmd == L"icon" )
382
					{
382
					{
383
						C_File *icon = new C_File(rest.tokens(L" ", 2));
383
						C_File *icon = new C_File(rest.tokens(L" ", 2));
384
						packageFile->setIcon(icon, rest.token(L" ", 1).toString());
384
						packageFile->setIcon(icon, rest.token(L" ", 1));
385
					}
385
					}
386
					else
386
					else
387
						packageFile->parseValueLine(line);
387
						packageFile->parseValueLine(line);
388
				}
388
				}
389
				else if ( iStatus == READ_SCRIPTFILE )
389
				else if ( iStatus == READ_SCRIPTFILE )
Line 808... Line 808...
808
 
808
 
809
	if ( !useFile.empty() )
809
	if ( !useFile.empty() )
810
	{
810
	{
811
		// lets check whats in the file first
811
		// lets check whats in the file first
812
		CCatFile openCat;
812
		CCatFile openCat;
813
		if ( openCat.open((m_sCurrentDir + L"/" + useFile + L".cat").toString(), addonDir.toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
813
		if ( openCat.open((m_sCurrentDir + L"/" + useFile + L".cat"), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
814
		{
814
		{
815
			std::vector<SInCatFile *> *files = openCat.GetFiles();
815
			std::vector<SInCatFile *> *files = openCat.GetFiles();
816
			bool found = false;
816
			bool found = false;
817
			if ( files )
817
			if ( files )
818
			{
818
			{
Line 1198... Line 1198...
1198
	delete package;
1198
	delete package;
1199
 
1199
 
1200
	return ret;
1200
	return ret;
1201
}
1201
}
1202
 
1202
 
1203
int CPackages::prepareMultiPackage(const Utils::String &file, CLinkList<CBaseFile> *errorPackageList, int *error, CProgressInfo *progress)
1203
int CPackages::prepareMultiPackage(const Utils::WString &file, CLinkList<CBaseFile> *errorPackageList, int *error, CProgressInfo *progress)
1204
{
1204
{
1205
	int check = checkOpenPackage(file, error);
1205
	int check = checkOpenPackage(file, error);
1206
	if ( *error == -1 )
1206
	if ( *error == -1 )
1207
		return 0;
1207
		return 0;
1208
 
1208
 
Line 1377... Line 1377...
1377
}
1377
}
1378
 
1378
 
1379
void CPackages::_addToFakePatch(CBaseFile *pPackage)
1379
void CPackages::_addToFakePatch(CBaseFile *pPackage)
1380
{
1380
{
1381
	CCatFile cat;
1381
	CCatFile cat;
1382
	if ( CCatFile::Opened(cat.open((m_sCurrentDir + L"/PluginManager/PlugMan_Fake.cat").toString(), this->getAddonDir(), CATREAD_DAT))) {
1382
	if ( CCatFile::Opened(cat.open((m_sCurrentDir + L"/PluginManager/PlugMan_Fake.cat"), this->getAddonDir(), CATREAD_DAT))) {
1383
		for ( CListNode<C_File> *f = pPackage->GetFileList()->Front(); f; f = f->next() ) {
1383
		for ( CListNode<C_File> *f = pPackage->GetFileList()->Front(); f; f = f->next() ) {
1384
			if ( f->Data()->GetFileType() != FILETYPE_SHIPSCENE && f->Data()->GetFileType() != FILETYPE_COCKPITSCENE && f->Data()->GetFileType() != FILETYPE_SHIPMODEL && f->Data()->GetFileType() != FILETYPE_SHIPOTHER ) {
1384
			if ( f->Data()->GetFileType() != FILETYPE_SHIPSCENE && f->Data()->GetFileType() != FILETYPE_COCKPITSCENE && f->Data()->GetFileType() != FILETYPE_SHIPMODEL && f->Data()->GetFileType() != FILETYPE_SHIPOTHER ) {
1385
				continue;
1385
				continue;
1386
			}
1386
			}
1387
			if ( CCatFile::IsAddonDir(f->Data()->getNameDirectory(pPackage)) ) {
1387
			if ( CCatFile::IsAddonDir(f->Data()->getNameDirectory(pPackage)) ) {
Line 1492... Line 1492...
1492
 
1492
 
1493
	CLog::log(CLog::Log_Install, 3, L"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, L"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, progress, &m_lFiles, errors, !disabled, this))
1498
	{
1498
	{
1499
		CLog::log(CLog::Log_Install, 2, L"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;
Line 1602... Line 1602...
1602
				{
1602
				{
1603
					if ( f->Data()->baseName().left(5).Compare(L"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::WString next = Utils::WString::PadNumber(this->findNextFakePatch(), 2);
1608
						
1608
						
1609
						Utils::WString oldFilePointer = f->Data()->filePointer();
1609
						Utils::WString oldFilePointer = f->Data()->filePointer();
1610
						f->Data()->setDir(L"");
1610
						f->Data()->setDir(L"");
1611
						f->Data()->changeBaseName(next);
1611
						f->Data()->changeBaseName(next);
1612
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + L"/" + f->Data()->getNameDirectory(package)))
1612
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + L"/" + f->Data()->getNameDirectory(package)))
Line 2211... Line 2211...
2211
				if ( spk->IsAnotherMod() )
2211
				if ( spk->IsAnotherMod() )
2212
				{
2212
				{
2213
					for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
2213
					for ( CListNode<CBaseFile> *node = m_lInstallList.Front(); node; node = node->next() )
2214
					{
2214
					{
2215
						CBaseFile *p = node->Data();
2215
						CBaseFile *p = node->Data();
2216
						if ( spk->otherName().Compare(p->name().toString()) &&amp; spk->;otherAuthor().Compare(p->author().toString()) )
2216
						if ( spk->otherName().Compare(p->name()) &&amp; spk->;otherAuthor().Compare(p->author()) )
2217
						{
2217
						{
2218
							m_lInstallList.insert(m_lInstallList.FindPos(p) + 2, package);
2218
							m_lInstallList.insert(m_lInstallList.FindPos(p) + 2, package);
2219
							added = true;
2219
							added = true;
2220
							break;
2220
							break;
2221
						}
2221
						}
Line 2233... Line 2233...
2233
 
2233
 
2234
					CSpkFile *spk = (CSpkFile *)node->Data();
2234
					CSpkFile *spk = (CSpkFile *)node->Data();
2235
					if ( !spk->isAnotherMod() )
2235
					if ( !spk->isAnotherMod() )
2236
						continue;
2236
						continue;
2237
 
2237
 
2238
					if ( spk->otherName().Compare(package->name().toString()) &&amp; spk->;otherAuthor().Compare(package->author().toString()) )
2238
					if ( spk->otherName().Compare(package->name()) &&amp; spk->;otherAuthor().Compare(package->author()) )
2239
					{
2239
					{
2240
						added = true;
2240
						added = true;
2241
						m_lInstallList.insert(node->Data(), package);
2241
						m_lInstallList.insert(node->Data(), package);
2242
						break;
2242
						break;
2243
					}
2243
					}
Line 2707... Line 2707...
2707
	for(auto itr = _lNonRemovedFiles.begin(); itr != _lNonRemovedFiles.end(); itr++)
2707
	for(auto itr = _lNonRemovedFiles.begin(); itr != _lNonRemovedFiles.end(); itr++)
2708
		lines.pushBack(L"NonRemovedFile: " + (*itr)->str);
2708
		lines.pushBack(L"NonRemovedFile: " + (*itr)->str);
2709
 
2709
 
2710
	if ( m_lGameShips.size() )
2710
	if ( m_lGameShips.size() )
2711
	{
2711
	{
2712
		lines.pushBack(Utils::String(L"Ships: ") + (long)m_lGameShips.size());
2712
		lines.pushBack(Utils::WString(L"Ships: ") + (long)m_lGameShips.size());
2713
 
2713
 
2714
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
2714
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
2715
		{
2715
		{
2716
			SGameShip *gm = node->Data();
2716
			SGameShip *gm = node->Data();
2717
			lines.pushBack(Utils::WString((long)gm->iType) + L" $#C:" + gm->sShipClass + L" " + gm->sShipID);
2717
			lines.pushBack(Utils::WString((long)gm->iType) + L" $#C:" + gm->sShipClass + L" " + gm->sShipID);
Line 3059... Line 3059...
3059
		if ( !currentFile.exists() )
3059
		if ( !currentFile.exists() )
3060
		{
3060
		{
3061
			// missing file ??
3061
			// missing file ??
3062
			if ( !newFile.exists() )
3062
			if ( !newFile.exists() )
3063
			{
3063
			{
3064
				this->addLogEntry(SPKINSTALL_MISSINGFILE, newFilename.toString(), errors);
3064
				this->addLogEntry(SPKINSTALL_MISSINGFILE, newFilename, errors);
3065
				continue;
3065
				continue;
3066
			}
3066
			}
3067
		}
3067
		}
3068
		// remove existing file
3068
		// remove existing file
3069
		// file exists, so lets try to move it
3069
		// file exists, so lets try to move it
Line 3072... Line 3072...
3072
			if ( newFile.exists() )
3072
			if ( newFile.exists() )
3073
				newFile.remove();
3073
				newFile.remove();
3074
 
3074
 
3075
			if ( !currentFile.Rename(newFile.fullFilename()) )
3075
			if ( !currentFile.Rename(newFile.fullFilename()) )
3076
			{
3076
			{
3077
				this->addLogEntry(SPKINSTALL_ENABLEFILE_FAIL, newFilename.toString(), errors);
3077
				this->addLogEntry(SPKINSTALL_ENABLEFILE_FAIL, newFilename, errors);
3078
				continue;
3078
				continue;
3079
			}
3079
			}
3080
		}
3080
		}
3081
 
3081
 
3082
		this->addLogEntry(SPKINSTALL_ENABLEFILE, newFilename.toString(), errors);
3082
		this->addLogEntry(SPKINSTALL_ENABLEFILE, newFilename, errors);
3083
 
3083
 
3084
		// adjust the internal name to match the new filename
3084
		// adjust the internal name to match the new filename
3085
		f->setFilename((m_sCurrentDir + L"/" + newFilename).toString());
3085
		f->setFilename(m_sCurrentDir + L"/" + newFilename);
3086
		// no longer disabled, we need to remove the flag
3086
		// no longer disabled, we need to remove the flag
3087
		f->SetDisabled(false);
3087
		f->SetDisabled(false);
3088
	}
3088
	}
3089
 
3089
 
3090
	// recursive, auto enable all children
3090
	// recursive, auto enable all children
Line 3196... Line 3196...
3196
				continue;
3196
				continue;
3197
		}
3197
		}
3198
 
3198
 
3199
		if ( f->GetFileType() == FILETYPE_MOD && !f->IsFakePatch() && f->checkFileExt(L"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) )
3202
				m_sSetMod = Utils::WString::Null();
3202
				m_sSetMod = Utils::WString::Null();
3203
		}
3203
		}
3204
 
3204
 
3205
		// file is not being used by any enabled package
3205
		// file is not being used by any enabled package
3206
		// set disabled and move to disabled directory
3206
		// set disabled and move to disabled directory
Line 3280... Line 3280...
3280
			if(!removeDirs.contains(f->getDirectory(checkPackage)))
3280
			if(!removeDirs.contains(f->getDirectory(checkPackage)))
3281
				removeDirs.pushBack(f->getDirectory(checkPackage));
3281
				removeDirs.pushBack(f->getDirectory(checkPackage));
3282
		}
3282
		}
3283
 
3283
 
3284
		// change the filename
3284
		// change the filename
3285
		f->setFilename(newFilename.toString());
3285
		f->setFilename(newFilename);
3286
 
3286
 
3287
		// finally mark the file as disabled so we know not to try to move it again
3287
		// finally mark the file as disabled so we know not to try to move it again
3288
		f->SetDisabled(true);
3288
		f->SetDisabled(true);
3289
	}
3289
	}
3290
 
3290
 
Line 4179... Line 4179...
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);
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);
4188
		}
4188
		}
4189
	}
4189
	}
Line 4474... Line 4474...
4474
			Utils::WString newName2 = Utils::WString::PadNumber(to, 2) + L"." + f2->fileExt();
4474
			Utils::WString newName2 = Utils::WString::PadNumber(to, 2) + L"." + f2->fileExt();
4475
			CFileIO moveFile(f2->filePointer());
4475
			CFileIO moveFile(f2->filePointer());
4476
			if ( moveFile.Rename(m_sCurrentDir + L"/" + newName2) )
4476
			if ( moveFile.Rename(m_sCurrentDir + L"/" + newName2) )
4477
			{
4477
			{
4478
				this->addLogEntry(SPKINSTALL_FAKEPATCH, f2->name() + L"~" + newName2, errors);
4478
				this->addLogEntry(SPKINSTALL_FAKEPATCH, f2->name() + L"~" + newName2, errors);
4479
				f2->setName(newName2.toString());
4479
				f2->setName(newName2);
4480
			}
4480
			}
4481
			else
4481
			else
4482
				this->addLogEntry(SPKINSTALL_FAKEPATCH_FAIL, f2->name() + L"~" + newName2, errors);
4482
				this->addLogEntry(SPKINSTALL_FAKEPATCH_FAIL, f2->name() + L"~" + newName2, errors);
4483
		}
4483
		}
4484
 
4484
 
4485
		// finally make sure the internal name matches the new one
4485
		// finally make sure the internal name matches the new one
4486
		file->setName(newName.toString());
4486
		file->setName(newName);
4487
	}
4487
	}
4488
	else
4488
	else
4489
		this->addLogEntry(SPKINSTALL_FAKEPATCH_FAIL, file->name() + L"~" + newName, errors);
4489
		this->addLogEntry(SPKINSTALL_FAKEPATCH_FAIL, file->name() + L"~" + newName, errors);
4490
}
4490
}
4491
 
4491
 
Line 4517... Line 4517...
4517
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4517
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
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::WString::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)
Line 4566... Line 4566...
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
 */
4569
unsigned int CPackages::findNextTextFile(unsigned int start) const
4569
unsigned int CPackages::findNextTextFile(unsigned int start) const
4570
{
4570
{
4571
	return findNextTextFile(Utils::String::Null(), start);
4571
	return findNextTextFile(Utils::WString::Null(), start);
4572
}
4572
}
4573
unsigned int CPackages::findNextTextFile(const Utils::WString &dir, unsigned int start) const
4573
unsigned int CPackages::findNextTextFile(const Utils::WString &dir, unsigned int start) const
4574
{
4574
{
4575
	int check = start;
4575
	int check = start;
4576
	if ( check < 2 ) check = 2;
4576
	if ( check < 2 ) check = 2;
Line 4633... Line 4633...
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 )
4637
		{
4637
		{
4638
			Utils::String str(data);
4638
			Utils::WString str(data);
4639
			m_iLanguage = str.token("\n", 1).token(" ", 1).toInt();
4639
			m_iLanguage = str.token(L"\n", 1).token(L" ", 1).toInt();
4640
		}
4640
		}
4641
	}
4641
	}
4642
}
4642
}
4643
 
4643
 
4644
/**
4644
/**
Line 4979... Line 4979...
4979
	return package->uninstallText(m_iLanguage, true);
4979
	return package->uninstallText(m_iLanguage, true);
4980
}
4980
}
4981
Utils::WString CPackages::getUninstallAfterText(CBaseFile *package) const
4981
Utils::WString CPackages::getUninstallAfterText(CBaseFile *package) const
4982
{
4982
{
4983
	return package->uninstallText(m_iLanguage, false);
4983
	return package->uninstallText(m_iLanguage, false);
4984
}
4984
}
4985
 
4985
 
4986
int CPackages::GetChildPackages(CBaseFile *package, CLinkList<CBaseFile> *children, bool recursive)
4986
int CPackages::GetChildPackages(CBaseFile *package, CLinkList<CBaseFile> *children, bool recursive)
4987
{
4987
{
4988
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4988
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4989
	{
4989
	{
4990
		CBaseFile *p = node->Data();
4990
		CBaseFile *p = node->Data();
4991
		if ( p->GetParent() == package )
4991
		if ( p->GetParent() == package )
4992
		{
4992
		{
4993
			children->push_back(p);
4993
			children->push_back(p);
4994
 
4994
 
4995
			if ( recursive )
4995
			if ( recursive )
4996
				this->GetChildPackages(p, children, recursive);
4996
				this->GetChildPackages(p, children, recursive);
4997
		}
4997
		}
4998
	}
4998
	}
4999
 
4999
 
Line 5008... Line 5008...
5008
}
5008
}
5009
 
5009
 
5010
Utils::WString CPackages::findDataDir(const Utils::WString &dir, const Utils::WString &file)
5010
Utils::WString CPackages::findDataDir(const Utils::WString &dir, const Utils::WString &file)
5011
{
5011
{
5012
	CDirIO Dir(dir);
5012
	CDirIO Dir(dir);
5013
 
5013
 
5014
	// data files could be in 4 places depending on what program is used, check for all of these
5014
	// data files could be in 4 places depending on what program is used, check for all of these
5015
	if (Dir.exists(file))
5015
	if (Dir.exists(file))
5016
		return Dir.file(file);
5016
		return Dir.file(file);
5017
	else if (Dir.exists(L"Data/" + file))
5017
	else if (Dir.exists(L"Data/" + file))
5018
		return Dir.file(L"Data/" + file);
5018
		return Dir.file(L"Data/" + file);
Line 5055... Line 5055...
5055
int CPackages::getGameLanguage() const
5055
int CPackages::getGameLanguage() const
5056
{
5056
{
5057
	return this->getGameLanguage(m_sCurrentDir);
5057
	return this->getGameLanguage(m_sCurrentDir);
5058
}
5058
}
5059
int CPackages::getGameLanguage(const Utils::WString &sDir) const
5059
int CPackages::getGameLanguage(const Utils::WString &sDir) const
5060
{
5060
{
5061
	Utils::WString dir = sDir;
5061
	Utils::WString dir = sDir;
5062
	if (dir.empty())
5062
	if (dir.empty())
5063
		dir = m_sCurrentDir;
5063
		dir = m_sCurrentDir;
5064
	else
5064
	else
5065
		dir = this->getProperDir(dir);
5065
		dir = this->getProperDir(dir);
Line 5074... Line 5074...
5074
		size_t size;
5074
		size_t size;
5075
		char *data = File.ReadToData(&size);
5075
		char *data = File.ReadToData(&size);
5076
 
5076
 
5077
		if ( data )
5077
		if ( data )
5078
		{
5078
		{
5079
			Utils::String str(data);
5079
			Utils::WString str(data);
5080
			return str.token("\n", 1).token(" ", 1).toLong();
5080
			return str.token(L"\n", 1).token(L" ", 1).toLong();
5081
		}
5081
		}
5082
	}
5082
	}
5083
 
5083
 
5084
	return 0;
5084
	return 0;
5085
}
5085
}
5086
Utils::WString CPackages::getGameRunExe(const Utils::WString &dir) const
5086
Utils::WString CPackages::getGameRunExe(const Utils::WString &dir) const
5087
{
5087
{
5088
	return m_gameExe.gameRunExe(dir);
5088
	return m_gameExe.gameRunExe(dir);
5089
}
5089
}
5090
Utils::WString CPackages::getGameRunExe() const
5090
Utils::WString CPackages::getGameRunExe() const
5091
{
5091
{
5092
	return m_gameExe.gameRunExe(m_sCurrentDir);
5092
	return m_gameExe.gameRunExe(m_sCurrentDir);
5093
}
5093
}
5094
 
5094
 
5095
Utils::WString CPackages::getGameNameFromType(int game) const
5095
Utils::WString CPackages::getGameNameFromType(int game) const
5096
{
5096
{
5097
	return m_gameExe.gameNameFromType(game - 1);
5097
	return m_gameExe.gameNameFromType(game - 1);
5098
}
5098
}
5099
Utils::WString CPackages::getGameName() const
5099
Utils::WString CPackages::getGameName() const
5100
{
5100
{
5101
	return getGameName(m_sCurrentDir);
5101
	return getGameName(m_sCurrentDir);
5102
}
5102
}
5103
 
5103
 
5104
Utils::WString CPackages::getGameName(const Utils::WString &dir) const
5104
Utils::WString CPackages::getGameName(const Utils::WString &dir) const
5105
{
5105
{
5106
	return m_gameExe.gameName(dir.empty() ? m_sCurrentDir : dir);
5106
	return m_gameExe.gameName(dir.empty() ? m_sCurrentDir : dir);
5107
}
5107
}
5108
 
5108
 
5109
Utils::WString CPackages::getProperDir() const
5109
Utils::WString CPackages::getProperDir() const
5110
{
5110
{
5111
	return getProperDir(m_sCurrentDir);
5111
	return getProperDir(m_sCurrentDir);
5112
}
5112
}
5113
Utils::WString CPackages::getProperDir(const Utils::WString &dir) const
5113
Utils::WString CPackages::getProperDir(const Utils::WString &dir) const
5114
{
5114
{
5115
	return m_gameExe.properDir((dir.empty()) ? m_sCurrentDir : dir);
5115
	return m_gameExe.properDir((dir.empty()) ? m_sCurrentDir : dir);
Line 5133... Line 5133...
5133
 
5133
 
5134
Utils::WString CPackages::getGameTypesString(CBaseFile *package, bool includeVersion) const
5134
Utils::WString CPackages::getGameTypesString(CBaseFile *package, bool includeVersion) const
5135
{
5135
{
5136
	if ( !package->AnyGameCompatability() )
5136
	if ( !package->AnyGameCompatability() )
5137
		return L"";
5137
		return L"";
5138
 
5138
 
5139
	Utils::WString sGames;
5139
	Utils::WString sGames;
5140
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5140
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5141
		if ( !sGames.empty() )
5141
		if ( !sGames.empty() )
5142
			sGames += L", ";
5142
			sGames += L", ";
5143
		sGames += m_gameExe.gameNameFromType(gNode->Data()->iGame - 1);
5143
		sGames += m_gameExe.gameNameFromType(gNode->Data()->iGame - 1);
Line 5146... Line 5146...
5146
			if ( !version.empty() ) {
5146
			if ( !version.empty() ) {
5147
				sGames += L" (";
5147
				sGames += L" (";
5148
				sGames += version;
5148
				sGames += version;
5149
				sGames += L")";
5149
				sGames += L")";
5150
			}
5150
			}
5151
		}
5151
		}
5152
	}
5152
	}
5153
	return sGames;
5153
	return sGames;
5154
}
5154
}
5155
 
5155
 
5156
Utils::WString CPackages::getGameVersionString(CBaseFile *package) const
5156
Utils::WString CPackages::getGameVersionString(CBaseFile *package) const
5157
{
5157
{
5158
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5158
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5159
		if ( gNode->Data()->iGame == m_iGame ) {
5159
		if ( gNode->Data()->iGame == m_iGame ) {
5160
			return m_gameExe.gameVersionFromType(m_iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
5160
			return m_gameExe.gameVersionFromType(m_iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
Line 5163... Line 5163...
5163
 
5163
 
5164
	return Utils::WString::Null();
5164
	return Utils::WString::Null();
5165
}
5165
}
5166
 
5166
 
5167
Utils::WString CPackages::getGameVersionFromType(int game, int version, const Utils::WString &sVersion) const
5167
Utils::WString CPackages::getGameVersionFromType(int game, int version, const Utils::WString &sVersion) const
5168
{
5168
{
5169
	return m_gameExe.gameVersionFromType(game - 1, version - 1, sVersion);
5169
	return m_gameExe.gameVersionFromType(game - 1, version - 1, sVersion);
5170
}
5170
}
5171
 
5171
 
5172
int CPackages::CountBuiltInPackages(bool onlyEnabled)
5172
int CPackages::CountBuiltInPackages(bool onlyEnabled)
5173
{
5173
{
5174
	int count = 0;
5174
	int count = 0;
5175
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5175
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
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;
Line 5238... Line 5238...
5238
	else if (!m_sSetMod.empty())
5238
	else if (!m_sSetMod.empty())
5239
	{
5239
	{
5240
		if (CFileIO::Exists(m_sCurrentDir + L"/mods/" + m_sSetMod + L".cat"))
5240
		if (CFileIO::Exists(m_sCurrentDir + L"/mods/" + m_sSetMod + L".cat"))
5241
		{
5241
		{
5242
			CCatFile catFile;
5242
			CCatFile catFile;
5243
			if (catFile.open(m_sCurrentDir + L"/mods/" + m_sSetMod + L".cat", addonDir.toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
5243
			if (catFile.open(m_sCurrentDir + L"/mods/" + m_sSetMod + L".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5244
			{
5244
			{
5245
				if (catFile.extractFile(aFilename, aTo))
5245
				if (catFile.extractFile(aFilename, aTo))
5246
					return 1;
5246
					return 1;
5247
				if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
5247
				if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
5248
				{
5248
				{
Line 5263... Line 5263...
5263
 
5263
 
5264
	// work backwards until we find the file
5264
	// work backwards until we find the file
5265
	for (; catNumber; catNumber--)
5265
	for (; catNumber; catNumber--)
5266
	{
5266
	{
5267
		CCatFile catFile;
5267
		CCatFile catFile;
5268
		if (catFile.open((dir + L"/" + Utils::WString::PadNumber(catNumber, 2) + L".cat"), addonDir.toString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
5268
		if (catFile.open((dir + L"/" + Utils::WString::PadNumber(catNumber, 2) + L".cat"), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5269
		{
5269
		{
5270
			// check for the file
5270
			// check for the file
5271
			if (catFile.extractFile(aFilename, aTo))
5271
			if (catFile.extractFile(aFilename, aTo))
5272
				return 1;
5272
				return 1;
5273
			if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
5273
			if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
Line 5393... Line 5393...
5393
					}
5393
					}
5394
				}
5394
				}
5395
 
5395
 
5396
				if ( create )
5396
				if ( create )
5397
				{
5397
				{
5398
					wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5398
					wareLines.pushFront(Utils::WString::Number(version) + L";" + Utils::WString::Number(wareLines.size()) + L";", Utils::WString::Null());
5399
					Utils::WString strV = Utils::WString::FromFloat(GetLibraryVersion(), 2);
5399
					Utils::WString strV = Utils::WString::FromFloat(GetLibraryVersion(), 2);
5400
					wareLines.pushFront("// Created by SPKInstaller Libraries V" + strV, Utils::WString::Null());
5400
					wareLines.pushFront("// Created by SPKInstaller Libraries V" + strV, Utils::WString::Null());
5401
					if ( readFile.writeFile(&wareLines) )
5401
					if ( readFile.writeFile(&wareLines) )
5402
						this->packFile(&readFile, L"types\\" + wareFile + L".pck");
5402
						this->packFile(&readFile, L"types\\" + wareFile + L".pck");
5403
				}
5403
				}
Line 5430... Line 5430...
5430
	{
5430
	{
5431
		if ( maxsize ) (*maxsize) = EMP_X3;
5431
		if ( maxsize ) (*maxsize) = EMP_X3;
5432
		return GetX3Emp();
5432
		return GetX3Emp();
5433
	}
5433
	}
5434
 
5434
 
5435
	return Utils::String::Null();
5435
	return Utils::WString::Null();
5436
}
5436
}
5437
 
5437
 
5438
void CPackages::_addWareOverride(enum WareTypes type, int pos, const Utils::WString &id, int value, bool noto)
5438
void CPackages::_addWareOverride(enum WareTypes type, int pos, const Utils::WString &id, int value, bool noto)
5439
{
5439
{
5440
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
5440
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
Line 5491... Line 5491...
5491
{
5491
{
5492
	_addWareOverride(Ware_Custom, 0, id, noto, true);
5492
	_addWareOverride(Ware_Custom, 0, id, noto, true);
5493
}
5493
}
5494
 
5494
 
5495
 
5495
 
5496
void CPackages::createEMPFile(const Utils::String &progDir)
5496
void CPackages::createEMPFile(const Utils::WString &progDir)
5497
{
5497
{
5498
	// do emp wares
5498
	// do emp wares
5499
	size_t maxsize = 0;
5499
	size_t maxsize = 0;
5500
	Utils::WString empWares = empWaresForGame(&maxsize);
5500
	Utils::WString empWares = empWaresForGame(&maxsize);
5501
 
5501
 
Line 6066... Line 6066...
6066
void CPackages::backupSaves(bool vanilla)
6066
void CPackages::backupSaves(bool vanilla)
6067
{
6067
{
6068
	if (!_sSaveDir.empty())
6068
	if (!_sSaveDir.empty())
6069
	{
6069
	{
6070
		// copy any saves into the vanilla directory
6070
		// copy any saves into the vanilla directory
6071
		Utils::String dir = (vanilla) ? "Vanilla" : "Modified";
6071
		Utils::WString dir = (vanilla) ? L"Vanilla" : L"Modified";
6072
 
6072
 
6073
		// make sure the directory exists
6073
		// make sure the directory exists
6074
		CDirIO saveDir(this->saveDirectory());
6074
		CDirIO saveDir(this->saveDirectory());
6075
		CDirIO gameSaveDir(saveDir.dir(_sSaveDir));
6075
		CDirIO gameSaveDir(saveDir.dir(_sSaveDir));
6076
 
6076
 
Line 6103... Line 6103...
6103
void CPackages::restoreSaves(bool vanilla)
6103
void CPackages::restoreSaves(bool vanilla)
6104
{
6104
{
6105
	// get dir to restore from
6105
	// get dir to restore from
6106
	if (!_sSaveDir.empty())
6106
	if (!_sSaveDir.empty())
6107
	{
6107
	{
6108
		Utils::String dir = (vanilla) ? "Vanilla" : "Modified";
6108
		Utils::WString dir = (vanilla) ? L"Vanilla" : L"Modified";
6109
		CDirIO toDir(this->saveDirectory());
6109
		CDirIO toDir(this->saveDirectory());
6110
		CDirIO restoreDir(toDir.dir(_sSaveDir));
6110
		CDirIO restoreDir(toDir.dir(_sSaveDir));
6111
		restoreDir.cd(dir);
6111
		restoreDir.cd(dir);
6112
 
6112
 
6113
		if (restoreDir.exists())
6113
		if (restoreDir.exists())
Line 6353... Line 6353...
6353
		}
6353
		}
6354
	}
6354
	}
6355
}
6355
}
6356
 
6356
 
6357
void CPackages::CreateCutData()
6357
void CPackages::CreateCutData()
6358
{
6358
{
6359
	// first check we have any ships
6359
	// first check we have any ships
6360
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6360
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6361
		return;
6361
		return;
6362
 
6362
 
6363
	bool found = false;
6363
	bool found = false;
6364
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6364
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6365
	{
6365
	{
6366
		SGameShip *s = node->Data();
6366
		SGameShip *s = node->Data();
6367
		if ( s->iType != WARETYPE_ADDED || !s->pPackage )
6367
		if ( s->iType != WARETYPE_ADDED || !s->pPackage )
6368
			continue;
6368
			continue;
6369
 
6369
 
6370
		// no dummies to add?
6370
		// no dummies to add?
6371
		if ( !s->pPackage->anyCutData() )
6371
		if ( !s->pPackage->anyCutData() )
6372
			continue;
6372
			continue;
Line 6483... Line 6483...
6483
			if(File.readLines(lines))
6483
			if(File.readLines(lines))
6484
			{
6484
			{
6485
				for ( int j = 0; j < (int)lines.size(); j++ )
6485
				for ( int j = 0; j < (int)lines.size(); j++ )
6486
				{
6486
				{
6487
					Utils::WString line(lines.at(j));
6487
					Utils::WString line(lines.at(j));
6488
					aniList.pushBack(line.toString());
6488
					aniList.pushBack(line);
6489
				}
6489
				}
6490
			}
6490
			}
6491
 
6491
 
6492
			File.remove();
6492
			File.remove();
6493
		}
6493
		}
Line 6506... Line 6506...
6506
		if ( !s->pPackage->anyAnimations() )
6506
		if ( !s->pPackage->anyAnimations() )
6507
			continue;
6507
			continue;
6508
 
6508
 
6509
		// add each dummy to list
6509
		// add each dummy to list
6510
		for(auto itr = s->pPackage->getAnimations().begin(); itr != s->pPackage->getAnimations().end(); itr++)
6510
		for(auto itr = s->pPackage->getAnimations().begin(); itr != s->pPackage->getAnimations().end(); itr++)
6511
			parsedAniList.pushBack((*itr)->str.toString());
6511
			parsedAniList.pushBack((*itr)->str);
6512
	}
6512
	}
6513
 
6513
 
6514
	// format the list with added spaces
6514
	// format the list with added spaces
6515
	Utils::WStringList formatedAniList;
6515
	Utils::WStringList formatedAniList;
6516
	int lineCount = -1;
6516
	int lineCount = -1;
Line 6590... Line 6590...
6590
	// write the file to disk
6590
	// write the file to disk
6591
	CFileIO WriteFile(m_sTempDir + L"/Animations.txt");
6591
	CFileIO WriteFile(m_sTempDir + L"/Animations.txt");
6592
	if ( WriteFile.writeFile(&formatedAniList) )
6592
	if ( WriteFile.writeFile(&formatedAniList) )
6593
	{
6593
	{
6594
		this->packFile(&WriteFile, L"types\\Animations.pck");
6594
		this->packFile(&WriteFile, L"types\\Animations.pck");
6595
		WriteFile.remove();
6595
		WriteFile.remove();
6596
	}
6596
	}
6597
}
6597
}
6598
 
6598
 
6599
void CPackages::CreateBodies()
6599
void CPackages::CreateBodies()
6600
{
6600
{
6601
	// first check we have any ships
6601
	// first check we have any ships
6602
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6602
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6603
		return;
6603
		return;
Line 6626... Line 6626...
6626
	if ( e )
6626
	if ( e )
6627
	{
6627
	{
6628
		CFileIO File;
6628
		CFileIO File;
6629
		if ( File.open((e == -1) ? L"Bodies.txt" : m_sTempDir + L"/Bodies.txt") )
6629
		if ( File.open((e == -1) ? L"Bodies.txt" : m_sTempDir + L"/Bodies.txt") )
6630
		{
6630
		{
6631
			std::vector<Utils::String> *lines = File.readLines();
6631
			std::vector<Utils::WString> lines;
6632
			if ( lines )
6632
			if(File.readLines(lines))
6633
			{
6633
			{
6634
				int entries = 0;
6634
				int entries = 0;
6635
				for ( int j = 0; j < (int)lines->size(); j++ )
6635
				for (size_t j = 0; j < lines.size(); j++ )
6636
				{
6636
				{
6637
					Utils::String line(lines->at(j));
6637
					Utils::WString line(lines.at(j));
6638
					line.removeChar(' ');
6638
					line.removeChar(' ');
6639
					line.removeChar(9);
6639
					line.removeChar(9);
6640
					if ( line.empty() || line[0] == '/' )
6640
					if ( line.empty() || line[0] == '/' )
6641
						continue;
6641
						continue;
6642
					if ( entries <= 0 )
6642
					if ( entries <= 0 )
6643
					{
6643
					{
6644
						entries = line.token(";", 2).toInt();
6644
						entries = line.token(L";", 2).toInt();
6645
						currentSection = new SBodies;
6645
						currentSection = new SBodies;
6646
						currentSection->sSection = line.token(";", 1).toWString();
6646
						currentSection->sSection = line.token(L";", 1);
6647
						bodiesList.push_back(currentSection);
6647
						bodiesList.push_back(currentSection);
6648
					}
6648
					}
6649
					else if ( currentSection )
6649
					else if ( currentSection )
6650
					{
6650
					{
6651
						int num;
-
 
6652
						Utils::String *strs = line.tokenise(";", &amp;num);
6651
						std::vector<Utils::WString&gt; strs;
6653
						if ( num &;&amp; strs )
6652
						if(line.tokenise(L";&quot;, strs))
6654
						{
6653
						{
6655
							for ( int i = 0; i <; num; i++ )
6654
							for (size_t i = 0; i <; strs.size(); i++)
6656
							{
6655
							{
6657
								if ( strs[i].empty() )
6656
								if ( strs[i].empty() )
6658
									continue;
6657
									continue;
6659
								if(!currentSection->lEntries.contains(strs[i].toWString() + L";"))
6658
								if(!currentSection->lEntries.contains(strs[i] + L";"))
6660
									currentSection->lEntries.pushBack(strs[i].toWString() + L";");
6659
									currentSection->lEntries.pushBack(strs[i] + L";");
6661
								--entries;
6660
								--entries;
6662
							}
6661
							}
6663
						}
6662
						}
6664
						CLEANSPLIT(strs, num);
-
 
6665
					}
6663
					}
6666
				}
6664
				}
6667
 
-
 
6668
				delete lines;
-
 
6669
			}
6665
			}
6670
			File.remove();
6666
			File.remove();
6671
		}
6667
		}
6672
	}
6668
	}
6673
 
6669
 
Line 6711... Line 6707...
6711
				foundSection->lEntries.pushBack(body);
6707
				foundSection->lEntries.pushBack(body);
6712
		}
6708
		}
6713
	}
6709
	}
6714
 
6710
 
6715
	// now write the file
6711
	// now write the file
6716
	std::vector<Utils::String> writeList;
6712
	std::vector<Utils::WString> writeList;
6717
	// the header first
6713
	// the header first
6718
	writeList.push_back("// Bodies file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6714
	writeList.push_back(L"// Bodies file, created by SPK Libraries V" + Utils::WString::FromFloat(GetLibraryVersion(), 2));
6719
	writeList.push_back("//body type;num bodies;");
6715
	writeList.push_back(L"//body type;num bodies;");
6720
	writeList.push_back("//[body id/name]");
6716
	writeList.push_back(L"//[body id/name]");
6721
 
6717
 
6722
	// now our sections
6718
	// now our sections
6723
	for ( SBodies *bSection = bodiesList.First(); bSection; bSection = bodiesList.Next() )
6719
	for ( SBodies *bSection = bodiesList.First(); bSection; bSection = bodiesList.Next() )
6724
	{
6720
	{
6725
		writeList.push_back("");
6721
		writeList.push_back(L"");
6726
		writeList.push_back("// Section: " + bSection->sSection.toString());
6722
		writeList.push_back(L"// Section: " + bSection->sSection);
6727
		writeList.push_back(bSection->sSection.toString() + ";" + Utils::String::Number(bSection->lEntries.size()) + ";");
6723
		writeList.push_back(bSection->sSection + L";" + Utils::WString::Number(bSection->lEntries.size()) + L";");
6728
		for(auto itr = bSection->lEntries.begin(); itr != bSection->lEntries.end(); itr++)
6724
		for(auto itr = bSection->lEntries.begin(); itr != bSection->lEntries.end(); itr++)
6729
		{
6725
		{
6730
			Utils::WString str = (*itr)->str;
6726
			Utils::WString str = (*itr)->str;
6731
			str.removeChar(9);
6727
			str.removeChar(9);
6732
			str.removeChar(' ');
6728
			str.removeChar(' ');
6733
			if ( str.right(1) != L";" )
6729
			if ( str.right(1) != L";" )
6734
				str += L";";
6730
				str += L";";
6735
			writeList.push_back(str.toString());
6731
			writeList.push_back(str);
6736
		}
6732
		}
6737
	}
6733
	}
6738
 
6734
 
6739
	// write the file to disk
6735
	// write the file to disk
6740
	CFileIO WriteFile(m_sTempDir + L"/Bodies.txt");
6736
	CFileIO WriteFile(m_sTempDir + L"/Bodies.txt");
6741
	if ( WriteFile.writeFile(&writeList) )
6737
	if ( WriteFile.writeFile(writeList) )
6742
	{
6738
	{
6743
		this->packFile(&WriteFile, L"types\\Bodies.pck");
6739
		this->packFile(&WriteFile, L"types\\Bodies.pck");
6744
		WriteFile.remove();
6740
		WriteFile.remove();
6745
	}
6741
	}
6746
}
6742
}
Line 6769... Line 6765...
6769
		createFiles.pushBack(name, L"maps/x3_universe");
6765
		createFiles.pushBack(name, L"maps/x3_universe");
6770
		createFiles.pushBack(name, L"types/Jobs");
6766
		createFiles.pushBack(name, L"types/Jobs");
6771
		createFiles.pushBack(name, L"types/JobWings");
6767
		createFiles.pushBack(name, L"types/JobWings");
6772
 
6768
 
6773
		for(auto itr = createFiles.begin(); itr != createFiles.end(); itr++)
6769
		for(auto itr = createFiles.begin(); itr != createFiles.end(); itr++)
6774
		{
6770
		{
6775
			Utils::WString dir = CFileIO((*itr)->data).dir();
6771
			Utils::WString dir = CFileIO((*itr)->data).dir();
6776
			FileType type = FileType::FILETYPE_EXTRA;
6772
			FileType type = FileType::FILETYPE_EXTRA;
6777
			if ( dir.Compare(L"maps") )
6773
			if ( dir.Compare(L"maps") )
6778
				type = FileType::FILETYPE_MAP;
6774
				type = FileType::FILETYPE_MAP;
6779
 
6775
 
Line 6845... Line 6841...
6845
					// read the section, first entry is section, second is size
6841
					// read the section, first entry is section, second is size
6846
					while ( !line.empty() )
6842
					while ( !line.empty() )
6847
					{
6843
					{
6848
						line = line.removeFirstSpace();
6844
						line = line.removeFirstSpace();
6849
						if ( line.empty() )
6845
						if ( line.empty() )
6850
							break;
6846
							break;
6851
 
6847
 
6852
						if ( !insection && !insubsection )
6848
						if ( !insection && !insubsection )
6853
						{
6849
						{
6854
							Utils::WString section = line.token(L";", 1);
6850
							Utils::WString section = line.token(L";", 1);
6855
							insection = line.token(L";", 2).toInt();
6851
							insection = line.token(L";", 2).toInt();
6856
 
6852
 
6857
							// search for the sections
6853
							// search for the sections
6858
							currentSection = NULL;
6854
							currentSection = NULL;
6859
							for ( CListNode<SComponantEntry> *node = dummyList.Front(); node; node = node->next() )
6855
							for ( CListNode<SComponantEntry> *node = dummyList.Front(); node; node = node->next() )
6860
							{
6856
							{
6861
								SComponantEntry *d = node->Data();
6857
								SComponantEntry *d = node->Data();
6862
								if ( d->sSection.Compare(section) )
6858
								if ( d->sSection.Compare(section) )
6863
								{
6859
								{
6864
									currentSection = node->Data();
6860
									currentSection = node->Data();
6865
									break;
6861
									break;
Line 6883... Line 6879...
6883
							insubsection = line.token(L";", 2).toInt();
6879
							insubsection = line.token(L";", 2).toInt();
6884
 
6880
 
6885
							currentSubSection = new SComponantEntry2;
6881
							currentSubSection = new SComponantEntry2;
6886
							currentSubSection->sSection = section;
6882
							currentSubSection->sSection = section;
6887
							currentSection->lEntries.push_back(currentSubSection);
6883
							currentSection->lEntries.push_back(currentSubSection);
6888
 
6884
 
6889
							line = line.remTokens(L";", 1, 2);
6885
							line = line.remTokens(L";", 1, 2);
6890
						}
6886
						}
6891
						else
6887
						else
6892
						{
6888
						{
6893
							--insubsection;
6889
							--insubsection;
Line 6921... Line 6917...
6921
				SComponantEntry *found = NULL;
6917
				SComponantEntry *found = NULL;
6922
				SComponantEntry2 *found2 = NULL;
6918
				SComponantEntry2 *found2 = NULL;
6923
				for ( CListNode<SComponantEntry> *eNode = dummyList.Front(); eNode; eNode = eNode->next() )
6919
				for ( CListNode<SComponantEntry> *eNode = dummyList.Front(); eNode; eNode = eNode->next() )
6924
				{
6920
				{
6925
					if ( eNode->Data()->sSection.Compare(dummy->sSection) )
6921
					if ( eNode->Data()->sSection.Compare(dummy->sSection) )
6926
					{
6922
					{
6927
						found = eNode->Data();
6923
						found = eNode->Data();
6928
						break;
6924
						break;
6929
					}
6925
					}
6930
				}
6926
				}
6931
				if ( !found )
6927
				if ( !found )
Line 6939... Line 6935...
6939
				}
6935
				}
6940
				// else check for the 2nd section
6936
				// else check for the 2nd section
6941
				else
6937
				else
6942
				{
6938
				{
6943
					for ( CListNode<SComponantEntry2> *cNode = found->lEntries.Front(); cNode; cNode = cNode->next() )
6939
					for ( CListNode<SComponantEntry2> *cNode = found->lEntries.Front(); cNode; cNode = cNode->next() )
6944
					{
6940
					{
6945
						if ( cNode->Data()->sSection.Compare(dummy->sSection2) )
6941
						if ( cNode->Data()->sSection.Compare(dummy->sSection2) )
6946
						{
6942
						{
6947
							found2 = cNode->Data();
6943
							found2 = cNode->Data();
6948
							break;
6944
							break;
6949
						}
6945
						}
6950
					}
6946
					}
6951
 
6947
 
6952
					if ( !found2 )
6948
					if ( !found2 )
6953
					{
6949
					{
6954
						found2 = new SComponantEntry2;
6950
						found2 = new SComponantEntry2;
6955
						found2->sSection = dummy->sSection2;
6951
						found2->sSection = dummy->sSection2;
6956
						found->lEntries.push_back(found2);
6952
						found->lEntries.push_back(found2);
6957
					}
6953
					}
6958
					else
6954
					else
Line 6994... Line 6990...
6994
					cStr.removeChar(9);
6990
					cStr.removeChar(9);
6995
					cStr.removeChar('\r');
6991
					cStr.removeChar('\r');
6996
					if ( cStr.right(1) != L";" )
6992
					if ( cStr.right(1) != L";" )
6997
						cStr += L";";
6993
						cStr += L";";
6998
					lines.push_back(cStr);
6994
					lines.push_back(cStr);
6999
				}
6995
				}
7000
			}
6996
			}
7001
		}
6997
		}
7002
 
6998
 
7003
		// write the file to disk
6999
		// write the file to disk
7004
		CFileIO WriteFile(m_sTempDir + L"/Components.txt");
7000
		CFileIO WriteFile(m_sTempDir + L"/Components.txt");
7005
		if ( WriteFile.writeFile(lines) )
7001
		if ( WriteFile.writeFile(lines) )
7006
		{
7002
		{
7007
			this->packFile(&WriteFile, L"types\\Components.pck");
7003
			this->packFile(&WriteFile, L"types\\Components.pck");
7008
			WriteFile.remove();
7004
			WriteFile.remove();
7009
		}
7005
		}
7010
	}
7006
	}
7011
}
7007
}
7012
 
7008
 
7013
bool CPackages::readWares(int iLang, CLinkList<SWareEntry> &list)
7009
bool CPackages::readWares(int iLang, CLinkList<SWareEntry> &list)
7014
{
7010
{
7015
	if ( iLang == 0 ) iLang = m_iLanguage;
7011
	if ( iLang == 0 ) iLang = m_iLanguage;
7016
 
7012
 
7017
	Utils::WString empWares = this->empWaresForGame();
7013
	Utils::WString empWares = this->empWaresForGame();
7018
 
7014
 
7019
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
7015
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
7020
		if ( !node->Data()->IsEnabled() ) continue;
7016
		if ( !node->Data()->IsEnabled() ) continue;
7021
		node->Data()->readWares(iLang, list, empWares);
7017
		node->Data()->readWares(iLang, list, empWares);
7022
	}
7018
	}
7023
 
7019
 
7024
	return true;
7020
	return true;
7025
}
7021
}
7026
 
7022
 
7027
bool CPackages::readCommands(int iLang, CLinkList<SCommandSlot> &list)
7023
bool CPackages::readCommands(int iLang, CLinkList<SCommandSlot> &list)
7028
{
7024
{
7029
	if ( iLang == 0 ) iLang = m_iLanguage;
7025
	if ( iLang == 0 ) iLang = m_iLanguage;
7030
 
7026
 
7031
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
7027
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
7032
		if ( !node->Data()->IsEnabled() ) continue;
7028
		if ( !node->Data()->IsEnabled() ) continue;
7033
		node->Data()->readCommands(iLang, list);
7029
		node->Data()->readCommands(iLang, list);
7034
	}
7030
	}
7035
 
7031
 
7036
	return true;
7032
	return true;
7037
}
7033
}
7038
 
7034
 
7039
bool CPackages::readWingCommands(int iLang, CLinkList<SCommandSlot> &list)
7035
bool CPackages::readWingCommands(int iLang, CLinkList<SCommandSlot> &list)
7040
{
7036
{
7041
	if ( iLang == 0 ) iLang = m_iLanguage;
7037
	if ( iLang == 0 ) iLang = m_iLanguage;
Line 7047... Line 7043...
7047
 
7043
 
7048
	return true;
7044
	return true;
7049
}
7045
}
7050
 
7046
 
7051
int CPackages::_warePriceOverride(enum WareTypes type, int pos, const Utils::WString &id)
7047
int CPackages::_warePriceOverride(enum WareTypes type, int pos, const Utils::WString &id)
7052
{
7048
{
7053
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7049
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7054
		if ( node->Data()->type == type ) {
7050
		if ( node->Data()->type == type ) {
7055
			if ( node->Data()->type == Ware_Custom && id.Compare(node->Data()->id) ) return node->Data()->relval;
7051
			if ( node->Data()->type == Ware_Custom && id.Compare(node->Data()->id) ) return node->Data()->relval;
7056
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos == pos ) return node->Data()->relval;
7052
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos == pos ) return node->Data()->relval;
7057
		}
7053
		}
7058
	}
7054
	}
7059
	return 0;
7055
	return 0;
7060
}
7056
}
7061
 
7057
 
7062
bool CPackages::_wareNotoOverride(enum WareTypes type, int pos, const Utils::WString &id, int *noto)
7058
bool CPackages::_wareNotoOverride(enum WareTypes type, int pos, const Utils::WString &id, int *noto)
7063
{
7059
{
7064
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7060
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7065
		if ( node->Data()->type == type && node->Data()->bNotority ) {
7061
		if ( node->Data()->type == type && node->Data()->bNotority ) {
7066
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7062
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7067
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
7063
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
7068
		
7064
		
7069
			(*noto) = node->Data()->notority;
7065
			(*noto) = node->Data()->notority;
7070
			return true;
7066
			return true;
7071
		}
7067
		}
7072
	}
7068
	}
7073
	return false;
7069
	return false;
7074
}
7070
}
7075
 
7071
 
7076
void CPackages::_removeWareOverride(enum WareTypes type, int pos, const Utils::WString &id)
7072
void CPackages::_removeWareOverride(enum WareTypes type, int pos, const Utils::WString &id)
7077
{
7073
{
7078
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7074
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7079
		if ( node->Data()->type == type ) {
7075
		if ( node->Data()->type == type ) {
7080
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7076
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
Line 7295... Line 7291...
7295
						if ( !added )
7291
						if ( !added )
7296
							tshipsList.push_back(line);
7292
							tshipsList.push_back(line);
7297
						--count;
7293
						--count;
7298
						if ( count < 0 )
7294
						if ( count < 0 )
7299
							break;
7295
							break;
7300
					}
7296
					}
7301
				}
7297
				}
7302
			}
7298
			}
7303
 
7299
 
7304
			File.remove();
7300
			File.remove();
7305
 
7301
 
7306
			// assign the ship buffer
7302
			// assign the ship buffer
7307
			if ( !m_iShipBuffer )
7303
			if ( !m_iShipBuffer )
7308
				m_iShipBuffer = tshipsList.size() + 15;
7304
				m_iShipBuffer = tshipsList.size() + 15;
Line 7343... Line 7339...
7343
			}
7339
			}
7344
 
7340
 
7345
			// finally, write the file
7341
			// finally, write the file
7346
			tshipsList.insert(tshipsList.begin(), Utils::WString::Number(fileType) + L";" + Utils::WString::Number(tshipsList.size()) + L";");
7342
			tshipsList.insert(tshipsList.begin(), Utils::WString::Number(fileType) + L";" + Utils::WString::Number(tshipsList.size()) + L";");
7347
			tshipsList.insert(tshipsList.begin(), L"// TShips file, created by SPK Libraries V" + Utils::WString::FromFloat(GetLibraryVersion(), 2));
7343
			tshipsList.insert(tshipsList.begin(), L"// TShips file, created by SPK Libraries V" + Utils::WString::FromFloat(GetLibraryVersion(), 2));
7348
 
7344
 
7349
			CFileIO WriteFile(m_sTempDir + L"/TShips.txt");
7345
			CFileIO WriteFile(m_sTempDir + L"/TShips.txt");
7350
			if ( WriteFile.writeFile(tshipsList) )
7346
			if ( WriteFile.writeFile(tshipsList) )
7351
			{
7347
			{
7352
				this->packFile(&WriteFile, L"types/TShips.pck");
7348
				this->packFile(&WriteFile, L"types/TShips.pck");
7353
				WriteFile.remove();
7349
				WriteFile.remove();
Line 7372... Line 7368...
7372
			Utils::WString ext = L"pck";
7368
			Utils::WString ext = L"pck";
7373
			if ( File.isFileExtension(L"bob") )
7369
			if ( File.isFileExtension(L"bob") )
7374
				ext = L"pbb";
7370
				ext = L"pbb";
7375
			else if ( File.isFileExtension(L"bod") )
7371
			else if ( File.isFileExtension(L"bod") )
7376
				ext = L"pbd";
7372
				ext = L"pbd";
7377
			CFileIO pckFile(File.changeFileExtension(ext));
7373
			CFileIO pckFile(File.changeFileExtension(ext));
7378
			if ( !CDirIO(pckFile.dir()).exists() )
7374
			if ( !CDirIO(pckFile.dir()).exists() )
7379
				CDirIO(pckFile.dir()).create();
7375
				CDirIO(pckFile.dir()).create();
7380
			pckFile.WriteData((char *)pckData, newFileSize);
7376
			pckFile.WriteData((char *)pckData, newFileSize);
7381
			return true;
7377
			return true;
7382
		}
7378
		}
7383
	}
7379
	}
7384
 
7380
 
7385
	return false;
7381
	return false;
Line 7415... Line 7411...
7415
			if ( checkxml )
7411
			if ( checkxml )
7416
			{
7412
			{
7417
				int readmaxlines = 20;
7413
				int readmaxlines = 20;
7418
				bool isxml = false;
7414
				bool isxml = false;
7419
				do {
7415
				do {
7420
					Utils::String line = pckFile.readEndOfLineStr();
7416
					Utils::WString line = pckFile.readEndOfLine();
7421
					if ( line.contains("<language id=") )
7417
					if ( line.contains(L"<language id=") )
7422
					{
7418
					{
7423
						isxml = true;
7419
						isxml = true;
7424
						break;
7420
						break;
7425
					}
7421
					}
7426
					else if ( line.contains("<page id=") )
7422
					else if ( line.contains(L"<page id=") )
7427
					{
7423
					{
7428
						isxml = true;
7424
						isxml = true;
7429
						break;
7425
						break;
7430
					}
7426
					}
7431
					else if ( line.contains("<?xml") || line.contains("<script>") )
7427
					else if ( line.contains(L"<?xml") || line.contains(L"<script>") )
7432
					{
7428
					{
7433
						isxml = true;
7429
						isxml = true;
7434
						break;
7430
						break;
7435
					}
7431
					}
7436
					--readmaxlines;
7432
					--readmaxlines;
Line 7608... Line 7604...
7608
		list.popFront();
7604
		list.popFront();
7609
		list.popFront();
7605
		list.popFront();
7610
	}
7606
	}
7611
 
7607
 
7612
	return list.size();
7608
	return list.size();
7613
}
7609
}
7614
 
7610
 
7615
CBaseFile *CPackages::findScriptByAuthor(const Utils::String &author, CBaseFile *prev)
7611
CBaseFile *CPackages::findScriptByAuthor(const Utils::WString &author, CBaseFile *prev)
7616
{
7612
{
7617
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
7613
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
7618
	{
7614
	{
7619
		CBaseFile *p = node->Data();
7615
		CBaseFile *p = node->Data();
7620
		if ( prev )
7616
		if ( prev )
7621
		{
7617
		{
7622
			if ( p == prev )
7618
			if ( p == prev )
7623
				prev = NULL;
7619
				prev = NULL;
7624
			continue;
7620
			continue;
7625
		}
7621
		}
7626
		if ( p->author().Compare(author) )
7622
		if ( p->author().Compare(author) )
7627
			return p;
7623
			return p;
7628
	}
7624
	}
7629
 
7625
 
7630
	return NULL;
7626
	return NULL;
7631
}
7627
}
7632
 
7628
 
7633
bool CPackages::extractAll(CBaseFile *baseFile, const Utils::String &dir, int game, bool includedir, CProgressInfo *progress) const
7629
bool CPackages::extractAll(CBaseFile *baseFile, const Utils::WString &dir, int game, bool includedir, CProgressInfo *progress) const
7634
{
7630
{
7635
	if (!baseFile)
7631
	if (!baseFile)
7636
		return false;
7632
		return false;
7637
 
7633
 
7638
	Utils::WStringList gameAddons;
7634
	Utils::WStringList gameAddons;
7639
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7635
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
7640
	{
7636
	{
7641
		SGameExe *exe = m_gameExe.game(i);
7637
		SGameExe *exe = m_gameExe.game(i);
7642
		if (!exe->sAddon.empty())
7638
		if (!exe->sAddon.empty())
7643
			gameAddons.pushBack(Utils::WString::Number(i + 1), exe->sAddon);
7639
			gameAddons.pushBack(Utils::WString::Number(i + 1), exe->sAddon);
7644
	}
7640
	}
7645
 
7641
 
7646
	return baseFile->extractAll(dir, game, gameAddons, includedir, progress);
7642
	return baseFile->extractAll(dir, game, gameAddons, includedir, progress);
7647
}
7643
}
7648
 
7644
 
7649
bool CPackages::generatePackagerScript(CBaseFile *baseFile, bool wildcard, Utils::WStringList *list, int game, bool datafile) const
7645
bool CPackages::generatePackagerScript(CBaseFile *baseFile, bool wildcard, Utils::WStringList *list, int game, bool datafile) const
7650
{	
7646
{	
7651
	if (!baseFile)
7647
	if (!baseFile)
7652
		return false;
7648
		return false;
7653
 
7649
 
Line 7672... Line 7668...
7672
	CFileIO File(filename);
7668
	CFileIO File(filename);
7673
	if ( !File.startRead() ) 
7669
	if ( !File.startRead() ) 
7674
		return NULL;
7670
		return NULL;
7675
 
7671
 
7676
	Utils::WStringList fileData;
7672
	Utils::WStringList fileData;
7677
 
7673
 
7678
	int iLine = 0;
7674
	int iLine = 0;
7679
 
7675
 
7680
	CBaseFile *package = NULL;
7676
	CBaseFile *package = NULL;
7681
 
7677
 
7682
	while(!File.atEnd()) {
7678
	while(!File.atEnd()) {
Line 7691... Line 7687...
7691
 
7687
 
7692
		// check for any comments (so we can ignore them)
7688
		// check for any comments (so we can ignore them)
7693
		if ( line.left(2).Compare(L"//") || line[0] == L'#' ) continue;
7689
		if ( line.left(2).Compare(L"//") || line[0] == L'#' ) continue;
7694
 
7690
 
7695
		++iLine;
7691
		++iLine;
7696
 
7692
 
7697
		// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
7693
		// all commands start with a keyword followed by a colon, if one doesn't exist, it cant be a valid line
7698
		if ( !line.contains(L':') )
7694
		if ( !line.contains(L':') )
7699
		{
7695
		{
7700
			// there are some exeptions, and these are one word entrys only
7696
			// there are some exeptions, and these are one word entrys only
7701
			line.removeEndSpace();
7697
			line.removeEndSpace();
Line 7844... Line 7840...
7844
			}
7840
			}
7845
		}
7841
		}
7846
	}
7842
	}
7847
 
7843
 
7848
	if ( package->filename().empty() )
7844
	if ( package->filename().empty() )
7849
		package->loadPackageData(L"AutoSave", L"$AUTOSAVE", sMainGame, otherGames, gameAddons, progress);
7845
		package->loadPackageData(L"AutoSave", L"$AUTOSAVE", sMainGame, otherGames, gameAddons, progress);
7850
 
7846
 
7851
	if (package->autoExtraction())
7847
	if (package->autoExtraction())
7852
	{
7848
	{
7853
		for (auto itr = package->autoExtraction()->begin(); itr != package->autoExtraction()->end(); itr++)
7849
		for (auto itr = package->autoExtraction()->begin(); itr != package->autoExtraction()->end(); itr++)
7854
		{
7850
		{
Line 7856... Line 7852...
7856
			for (auto node = package->fileList().Front(); node; node = node->next())
7852
			for (auto node = package->fileList().Front(); node; node = node->next())
7857
			{
7853
			{
7858
				C_File *f = node->Data();
7854
				C_File *f = node->Data();
7859
				if (f->game() && f->game() != GAME_ALLNEW && !(f->game() & (1 << game)))
7855
				if (f->game() && f->game() != GAME_ALLNEW && !(f->game() & (1 << game)))
7860
					continue;
7856
					continue;
7861
				package->extractFile(f, itr->second.toString(), game, gameAddons);
7857
				package->extractFile(f, itr->second, game, gameAddons);
7862
			}
7858
			}
7863
		}
7859
		}
7864
	}
7860
	}
7865
 
7861
 
7866
	if (package->autoExporter())
7862
	if (package->autoExporter())
7867
	{
7863
	{
7868
		for (auto itr = package->autoExporter()->begin(); itr != package->autoExporter()->end(); itr++)
7864
		for (auto itr = package->autoExporter()->begin(); itr != package->autoExporter()->end(); itr++)
7869
			package->saveToArchive(itr->second.toString(), itr->first, &m_gameExe);
7865
			package->saveToArchive(itr->second, itr->first, &m_gameExe);
7870
	}
7866
	}
7871
 
7867
 
7872
	if ( !ftpaddr.empty() )
7868
	if ( !ftpaddr.empty() )
7873
	{
7869
	{
7874
		if ( !ftpuser.empty() )
7870
		if ( !ftpuser.empty() )
7875
		{
7871
		{
7876
			if ( !ftppass.empty() )
7872
			if ( !ftppass.empty() )
7877
				ftpaddr = ftpuser + ":" + ftppass + "@" + ftpaddr;
7873
				ftpaddr = ftpuser + L":" + ftppass + L"@" + ftpaddr;
7878
			else
7874
			else
7879
				ftpaddr = ftpuser + "@" + ftpaddr;
7875
				ftpaddr = ftpuser + L"@" + ftpaddr;
7880
		}
7876
		}
7881
 
7877
 
7882
		if ( !ftpdir.empty() )
7878
		if ( !ftpdir.empty() )
7883
			ftpaddr += ftpdir;
7879
			ftpaddr += ftpdir;
7884
 
7880
 
7885
		package->setFtpAddr(ftpaddr.toString());
7881
		package->setFtpAddr(ftpaddr);
7886
	}
7882
	}
7887
 
7883
 
7888
	return package;
7884
	return package;
7889
}
7885
}
7890
 
7886
 
Line 7924... Line 7920...
7924
	if (_pCurrentDir)
7920
	if (_pCurrentDir)
7925
	{
7921
	{
7926
		count += findPackageDirectories(packages, _pCurrentDir->dir + L"/Addons");
7922
		count += findPackageDirectories(packages, _pCurrentDir->dir + L"/Addons");
7927
		count += findPackageDirectories(packages, _pCurrentDir->dir + L"/Downloads");
7923
		count += findPackageDirectories(packages, _pCurrentDir->dir + L"/Downloads");
7928
		count += findPackageDirectories(packages, _pCurrentDir->dir + L"/ExtraContent");
7924
		count += findPackageDirectories(packages, _pCurrentDir->dir + L"/ExtraContent");
7929
	}
7925
	}
7930
 
7926
 
7931
	return count;
7927
	return count;
7932
}
7928
}
7933
int CPackages::findPackageDirectories(CLinkList<CBaseFile> &packages, const Utils::WString &dir)
7929
int CPackages::findPackageDirectories(CLinkList<CBaseFile> &packages, const Utils::WString &dir)
7934
{
7930
{
7935
	CDirIO Dir(dir);
7931
	CDirIO Dir(dir);
Line 7939... Line 7935...
7939
	{
7935
	{
7940
		for (auto itr = files.begin(); itr != files.end(); itr++)
7936
		for (auto itr = files.begin(); itr != files.end(); itr++)
7941
		{
7937
		{
7942
			Utils::WString d = Dir.file((*itr)->str);
7938
			Utils::WString d = Dir.file((*itr)->str);
7943
			if (CDirIO(d).isDir())
7939
			if (CDirIO(d).isDir())
7944
				count += findPackageDirectories(packages, d.toString());
7940
				count += findPackageDirectories(packages, d);
7945
		}
7941
		}
7946
	}
7942
	}
7947
 
7943
 
7948
	count += findPackageFiles(packages, dir);
7944
	count += findPackageFiles(packages, dir);
7949
	return count;
7945
	return count;
Line 8231... Line 8227...
8231
	if ( CFileIO(file).isFileExtension(L"cat") )
8227
	if ( CFileIO(file).isFileExtension(L"cat") )
8232
	{
8228
	{
8233
		bool done = false;
8229
		bool done = false;
8234
 
8230
 
8235
		CCatFile cat;
8231
		CCatFile cat;
8236
		if ( cat.open(file, this->getAddonDir().toString(), CATREAD_CATDECRYPT, false) != CATERR_NONE)
8232
		if ( cat.open(file, this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE)
8237
			return false;
8233
			return false;
8238
 
8234
 
8239
		// extract 1 at a time
8235
		// extract 1 at a time
8240
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8236
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8241
		{
8237
		{
8242
			SInCatFile *f = cat.GetFile(i);
8238
			SInCatFile *f = cat.GetFile(i);
Line 8402... Line 8398...
8402
	}
8398
	}
8403
	for (auto itr = removed.begin(); itr != removed.end(); itr++)
8399
	for (auto itr = removed.begin(); itr != removed.end(); itr++)
8404
		_lNonRemovedFiles.remove((*itr)->str);
8400
		_lNonRemovedFiles.remove((*itr)->str);
8405
}
8401
}
8406
 
8402
 
8407
CXspFile *CPackages::extractShip(const Utils::String &sCatFile, const Utils::String &sId, CProgressInfo *progress)
8403
CXspFile *CPackages::extractShip(const Utils::WString &sCatFile, const Utils::WString &sId, CProgressInfo *progress)
8408
{
8404
{
8409
	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
8405
	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
8410
	if ( !pVfs->addMod(sCatFile) ) {
8406
	if ( !pVfs->addMod(sCatFile) ) {
8411
		delete pVfs;
8407
		delete pVfs;
8412
		return NULL;
8408
		return NULL;
Line 8541... Line 8537...
8541
	if ( file->GetFileType() != FILETYPE_MOD ) return false;
8537
	if ( file->GetFileType() != FILETYPE_MOD ) return false;
8542
	if ( !file->fileExt().Compare(L"cat") ) return false;
8538
	if ( !file->fileExt().Compare(L"cat") ) return false;
8543
 
8539
 
8544
	// we need to read the file list for the mod
8540
	// we need to read the file list for the mod
8545
	CCatFile cat;
8541
	CCatFile cat;
8546
	if ( cat.open(file->filePointer(), this->getAddonDir().toString(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE)
8542
	if ( cat.open(file->filePointer(), this->getAddonDir(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE)
8547
	{
8543
	{
8548
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8544
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8549
		{
8545
		{
8550
			SInCatFile *f = cat.GetFile(i);
8546
			SInCatFile *f = cat.GetFile(i);
8551
			Utils::WString filename = f->sFile;
8547
			Utils::WString filename = f->sFile;
Line 8693... Line 8689...
8693
		C_File *f = fNode->Data();
8689
		C_File *f = fNode->Data();
8694
		if ( f->GetFileType() != FILETYPE_MOD ) continue;
8690
		if ( f->GetFileType() != FILETYPE_MOD ) continue;
8695
		if ( !f->IsFakePatch() ) continue;
8691
		if ( !f->IsFakePatch() ) continue;
8696
		if (!f->checkFileExt(L"cat")) continue;
8692
		if (!f->checkFileExt(L"cat")) continue;
8697
 
8693
 
8698
		if (newFile->extractFile(f, m_sTempDir.toString()) )
8694
		if (newFile->extractFile(f, m_sTempDir) )
8699
			f->setFullDir(m_sTempDir);
8695
			f->setFullDir(m_sTempDir);
8700
	}
8696
	}
8701
 
8697
 
8702
	// compare mod files against all installed packages
8698
	// compare mod files against all installed packages
8703
	int count = 0;
8699
	int count = 0;
Line 9129... Line 9125...
9129
		list->pushBack(L"http://xpluginmanager.co.uk/flscripts");
9125
		list->pushBack(L"http://xpluginmanager.co.uk/flscripts");
9130
 
9126
 
9131
	return list->size();
9127
	return list->size();
9132
}
9128
}
9133
 
9129
 
9134
void CPackages::readArchiveData(const Utils::String &filename, CBaseFile *archive) const
9130
void CPackages::readArchiveData(const Utils::WString &filename, CBaseFile *archive) const
9135
{
9131
{
9136
	size_t size;
9132
	size_t size;
9137
	char *data = CFileIO(filename).ReadToData(&size);
9133
	char *data = CFileIO(filename).ReadToData(&size);
9138
	if ( size && data )
9134
	if ( size && data )
9139
		readArchiveData(data, size, archive);
9135
		readArchiveData(data, size, archive);
Line 9203... Line 9199...
9203
			}
9199
			}
9204
		}
9200
		}
9205
	}
9201
	}
9206
}
9202
}
9207
 
9203
 
9208
CBaseFile *CPackages::_archive_fromRar(const Utils::String &filename, bool toInstall) const
9204
CBaseFile *CPackages::_archive_fromRar(const Utils::WString &filename, bool toInstall) const
9209
{
9205
{
9210
	// make sure we can open the zip file
9206
	// make sure we can open the zip file
9211
	CBaseFile *archive = NULL;
9207
	CBaseFile *archive = NULL;
9212
#ifdef _RAR
9208
#ifdef _RAR
9213
	HANDLE hArcData;
9209
	HANDLE hArcData;
Line 9229... Line 9225...
9229
 
9225
 
9230
		HeaderData.CmtBuf=NULL;
9226
		HeaderData.CmtBuf=NULL;
9231
		memset(&OpenArchiveData.Reserved,0,sizeof(OpenArchiveData.Reserved));
9227
		memset(&OpenArchiveData.Reserved,0,sizeof(OpenArchiveData.Reserved));
9232
 
9228
 
9233
		while ((RHCode=RARReadHeaderEx(hArcData,&HeaderData))==0) {
9229
		while ((RHCode=RARReadHeaderEx(hArcData,&HeaderData))==0) {
9234
			if ( Utils::String(HeaderData.FileName).Compare("pluginmanager.txt") ) {
9230
			if ( Utils::WString(HeaderData.FileName).Compare(L"pluginmanager.txt") ) {
9235
				toInstall = false;
9231
				toInstall = false;
9236
				break;
9232
				break;
9237
			}
9233
			}
9238
		}
9234
		}
9239
		RARCloseArchive(hArcData);
9235
		RARCloseArchive(hArcData);
Line 9313... Line 9309...
9313
#endif
9309
#endif
9314
 
9310
 
9315
	return archive;
9311
	return archive;
9316
}
9312
}
9317
 
9313
 
9318
CBaseFile *CPackages::_archive_fromZip(const Utils::String &filename, bool toInstall) const
9314
CBaseFile *CPackages::_archive_fromZip(const Utils::WString &filename, bool toInstall) const
9319
{
9315
{
9320
	CBaseFile *archive = NULL;
9316
	CBaseFile *archive = NULL;
9321
 
9317
 
9322
	TCHAR buf[5000];
9318
	TCHAR buf[5000];
9323
	wsprintf(buf, L"%hs", filename.c_str());
9319
	wsprintf(buf, L"%hs", filename.c_str());
Line 9360... Line 9356...
9360
 
9356
 
9361
 
9357
 
9362
		char *iBuf = new char[ze.unc_size];
9358
		char *iBuf = new char[ze.unc_size];
9363
		UnzipItem(hz, zi, iBuf, ze.unc_size);
9359
		UnzipItem(hz, zi, iBuf, ze.unc_size);
9364
 
9360
 
9365
		Utils::String Name(ze.name);
9361
		Utils::WString Name(ze.name);
9366
 
9362
 
9367
		// if its the data file, dont add it, but extract to get settings from
9363
		// if its the data file, dont add it, but extract to get settings from
9368
		if ( Name.Compare("pluginmanager.txt") )
9364
		if ( Name.Compare("pluginmanager.txt") )
9369
		{
9365
		{
9370
			this->readArchiveData(iBuf, ze.unc_size, archive);
9366
			this->readArchiveData(iBuf, ze.unc_size, archive);
Line 9419... Line 9415...
9419
		archive = NULL;
9415
		archive = NULL;
9420
	}
9416
	}
9421
	return archive;
9417
	return archive;
9422
}
9418
}
9423
 
9419
 
9424
CBaseFile *CPackages::createFromArchive(const Utils::String &filename, bool toInstall) const
9420
CBaseFile *CPackages::createFromArchive(const Utils::WString &filename, bool toInstall) const
9425
{
9421
{
9426
	// make sure we can open the zip file
9422
	// make sure we can open the zip file
9427
	CBaseFile *archive = NULL;
9423
	CBaseFile *archive = NULL;
9428
	if ( CFileIO(filename).isFileExtension(L"rar") )
9424
	if ( CFileIO(filename).isFileExtension(L"rar") )
9429
		archive = this->_archive_fromRar(filename, toInstall);
9425
		archive = this->_archive_fromRar(filename, toInstall);
9430
	else if ( CFileIO(filename).isFileExtension(L"zip") )
9426
	else if ( CFileIO(filename).isFileExtension(L"zip") )
9431
		archive = this->_archive_fromZip(filename, toInstall);
9427
		archive = this->_archive_fromZip(filename, toInstall);
9432
 
9428
 
9433
	if ( archive ) {
9429
	if ( archive ) {
9434
		archive->setFilename(CFileIO(filename).changeFileExtension(L"spk").toString());
9430
		archive->setFilename(CFileIO(filename).changeFileExtension(L"spk"));
9435
		if ( toInstall )
9431
		if ( toInstall )
9436
			archive->setName(CFileIO(filename).filenameStr());
9432
			archive->setName(CFileIO(filename).filenameStr());
9437
		else
9433
		else
9438
			archive->setName(CFileIO(filename).baseName().toString());
9434
			archive->setName(CFileIO(filename).baseName());
9439
	}
9435
	}
9440
 
9436
 
9441
	return archive;
9437
	return archive;
9442
}
9438
}
9443
 
9439
 
Line 9447... Line 9443...
9447
	Utils::WStringList variables;
9443
	Utils::WStringList variables;
9448
	variables.pushBack(L"$PATH", curDir);
9444
	variables.pushBack(L"$PATH", curDir);
9449
	CBaseFile *package = packages->loadPackagerScript(filename, NULL, NULL, NULL, &variables);
9445
	CBaseFile *package = packages->loadPackagerScript(filename, NULL, NULL, NULL, &variables);
9450
 
9446
 
9451
	if ( !package )
9447
	if ( !package )
9452
		return Utils::String::Null();
9448
		return Utils::WString::Null();
9453
 
9449
 
9454
	Utils::WString saveto = package->filename();
9450
	Utils::WString saveto = package->filename();
9455
	saveto = saveto.findReplace(L"$DEFAULTDIR", curDir + L"/");
9451
	saveto = saveto.findReplace(L"$DEFAULTDIR", curDir + L"/");
9456
	saveto = saveto.findReplace(L"$PATH", curDir);
9452
	saveto = saveto.findReplace(L"$PATH", curDir);
9457
	saveto = saveto.findReplace(L"\\", L"/");
9453
	saveto = saveto.findReplace(L"\\", L"/");
Line 9460... Line 9456...
9460
		saveto += L".spk";
9456
		saveto += L".spk";
9461
	else if ( !saveto.right(4).Compare(L".xsp") && package->GetType() == TYPE_XSP )
9457
	else if ( !saveto.right(4).Compare(L".xsp") && package->GetType() == TYPE_XSP )
9462
		saveto += L".xsp";
9458
		saveto += L".xsp";
9463
 
9459
 
9464
	// write script
9460
	// write script
9465
	if ( package->writeFile(saveto.toString()) )
9461
	if ( package->writeFile(saveto) )
9466
	{
9462
	{
9467
		if ( package->AutoGenerateUpdateFile() )
9463
		if ( package->AutoGenerateUpdateFile() )
9468
			package->createUpdateFile(CFileIO(saveto).dir());
9464
			package->createUpdateFile(CFileIO(saveto).dir());
9469
		return saveto;
9465
		return saveto;
9470
	}
9466
	}
9471
 
9467
 
9472
	return Utils::String::Null();
9468
	return Utils::WString::Null();
9473
}
9469
}
9474
 
9470
 
9475
int CPackages::GeneratePackageUpdateData(const Utils::WString &dir, bool includeSingle)
9471
int CPackages::GeneratePackageUpdateData(const Utils::WString &dir, bool includeSingle)
9476
{
9472
{
9477
	Utils::WStringList filedata;
9473
	Utils::WStringList filedata;