Subversion Repositories spk

Rev

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

Rev 158 Rev 160
Line 4... Line 4...
4
#include <time.h>
4
#include <time.h>
5
#include <vector>
5
#include <vector>
6
 
6
 
7
#include "OriginalFiles.h"
7
#include "OriginalFiles.h"
8
#include "spkdef.h"
8
#include "spkdef.h"
-
 
9
#include <set>
9
 
10
 
10
#ifdef _RAR
11
#ifdef _RAR
11
#include <unrar.h>
12
#include <unrar.h>
12
#endif
13
#endif
13
 
14
 
Line 95... Line 96...
95
		for ( CListNode<CBaseFile> *pNode = m_lPackages.Front(); pNode; pNode = pNode->next() ) {
96
		for ( CListNode<CBaseFile> *pNode = m_lPackages.Front(); pNode; pNode = pNode->next() ) {
96
			pNode->Data()->SetModifiedEnabled(pNode->Data()->IsEnabled());
97
			pNode->Data()->SetModifiedEnabled(pNode->Data()->IsEnabled());
97
		}
98
		}
98
	}
99
	}
99
	m_bVanilla = b;
100
	m_bVanilla = b;
-
 
101
}
-
 
102
 
-
 
103
void CPackages::setMod(const Utils::String &mod)
-
 
104
{
-
 
105
	if (mod != "PluginManager")
-
 
106
		m_sSetMod = mod;
100
}
107
}
101
 
108
 
102
void CPackages::setSaveGameManager(bool managed)
109
void CPackages::setSaveGameManager(bool managed)
103
{
110
{
104
	m_iSaveGameManager = managed ? 1 : 0;
111
	m_iSaveGameManager = managed ? 1 : 0;
Line 111... Line 118...
111
		{
118
		{
112
			int id = 1;
119
			int id = 1;
113
			while (dir.exists(Utils::String::PadNumber(id, 4)))
120
			while (dir.exists(Utils::String::PadNumber(id, 4)))
114
				++id;
121
				++id;
115
			Utils::String d = Utils::String::PadNumber(id, 4);
122
			Utils::String d = Utils::String::PadNumber(id, 4);
116
			dir.Create(d);
123
			dir.create(d);
117
			_sSaveDir = d;
124
			_sSaveDir = d;
118
 
125
 
119
			CDirIO destDir1(dir.dir(d));
126
			CDirIO destDir1(dir.dir(d));
120
			destDir1.Create("Vanilla");
127
			destDir1.create("Vanilla");
121
			destDir1.cd("Vanilla");
128
			destDir1.cd("Vanilla");
122
			CDirIO destDir2(dir.dir(d));
129
			CDirIO destDir2(dir.dir(d));
123
			destDir2.Create("Modified");
130
			destDir2.create("Modified");
124
			destDir2.cd("Modified");
131
			destDir2.cd("Modified");
125
 
132
 
126
			Utils::CStringList files;
133
			Utils::CStringList files;
127
			if (dir.dirList(files, Utils::String::Null(), "*.sav"))
134
			if (dir.dirList(files, Utils::String::Null(), "*.sav"))
128
			{
135
			{
Line 176... Line 183...
176
	m_lAvailablePackages.MemoryClear();
183
	m_lAvailablePackages.MemoryClear();
177
	m_lInstallList.MemoryClear();
184
	m_lInstallList.MemoryClear();
178
	m_lEnableList.MemoryClear();
185
	m_lEnableList.MemoryClear();
179
	m_lDisableList.MemoryClear();
186
	m_lDisableList.MemoryClear();
180
 
187
 
181
	m_lCreatedFiles.Clear();
188
	m_lCreatedFiles.clear();
182
	m_lNonRemovedFiles.Clear();
189
	m_lNonRemovedFiles.clear();
183
	m_lGlobals.Clear();
190
	m_lGlobals.clear();
184
	m_lFakePatchOrder.Clear();
191
	m_lFakePatchOrder.clear();
185
	if (_pCurrentDir)
192
	if (_pCurrentDir)
186
		delete _pCurrentDir;
193
		delete _pCurrentDir;
187
	_pCurrentDir = NULL;
194
	_pCurrentDir = NULL;
188
}
195
}
189
 
196
 
Line 208... Line 215...
208
			m_pGameVFS.LoadFilesystem(m_sCurrentDir, 0);
215
			m_pGameVFS.LoadFilesystem(m_sCurrentDir, 0);
209
	}
216
	}
210
	else
217
	else
211
		m_pGameVFS.LoadFilesystem(m_sCurrentDir, 0);
218
		m_pGameVFS.LoadFilesystem(m_sCurrentDir, 0);
212
}
219
}
213
 
220
 
214
bool CPackages::isOldDir(const Utils::String &dir)
221
bool CPackages::isOldDir(const Utils::String &dir)
215
{
222
{
216
	bool oldPlugin = false;
223
	bool oldPlugin = false;
217
 
224
 
218
	CFileIO datFile(dir + "/PluginManager/pluginmanager.dat");
225
	CFileIO datFile(dir + "/PluginManager/pluginmanager.dat");
Line 224... Line 231...
224
			for ( int i = 0; i < (int)readFile->size(); i++ )
231
			for ( int i = 0; i < (int)readFile->size(); i++ )
225
			{
232
			{
226
				Utils::String line(readFile->at(i));
233
				Utils::String line(readFile->at(i));
227
				Utils::String cmd = line.token(":", 1);
234
				Utils::String cmd = line.token(":", 1);
228
				if ( cmd.Compare("<script>") || cmd.Compare("</scripts>") )
235
				if ( cmd.Compare("<script>") || cmd.Compare("</scripts>") )
229
					break;
236
					break;
230
				else if ( cmd.Compare("spkinstaller") || cmd.Compare("globalfiles") )
237
				else if ( cmd.Compare("spkinstaller") || cmd.Compare("globalfiles") )
231
					break;
238
					break;
232
				else if ( cmd.Compare("pluginmanager") )
239
				else if ( cmd.Compare("pluginmanager") )
233
				{
240
				{
234
					oldPlugin = true;
241
					oldPlugin = true;
235
					break;
242
					break;
236
				}
243
				}
Line 252... Line 259...
252
{
259
{
253
	m_sCurrentDir = dir;
260
	m_sCurrentDir = dir;
254
	m_sCurrentDir = m_sCurrentDir.findReplace("\\", "/");
261
	m_sCurrentDir = m_sCurrentDir.findReplace("\\", "/");
255
	this->setCurrentDir(dir);
262
	this->setCurrentDir(dir);
256
	m_bOldPlugin = false;
263
	m_bOldPlugin = false;
257
	m_lCreatedFiles.Clear();
264
	m_lCreatedFiles.clear();
258
	m_bRemoveDir = false;
265
	m_bRemoveDir = false;
259
	m_bSurpressProtectedWarning = false;
266
	m_bSurpressProtectedWarning = false;
260
	m_iSaveGame = -1;
267
	m_iSaveGame = -1;
261
	m_iSaveGameManager = -1;
268
	m_iSaveGameManager = -1;
262
	m_lNonRemovedFiles.Clear();
269
	m_lNonRemovedFiles.clear();
263
	m_lGlobals.Clear();
270
	m_lGlobals.clear();
264
	m_lFakePatchOrder.Clear();
271
	m_lFakePatchOrder.clear();
265
 
272
 
266
	if ( _pOriginalFiles ) delete _pOriginalFiles;
273
	if ( _pOriginalFiles ) delete _pOriginalFiles;
267
	_pOriginalFiles = new COriginalFiles(m_sCurrentDir);
274
	_pOriginalFiles = new COriginalFiles(m_sCurrentDir);
268
 
275
 
269
	m_bVanilla = true;
276
	m_bVanilla = true;
Line 500... Line 507...
500
						else
507
						else
501
							m_iWareBuffer[i] = rest.token(" ", i + 1).toLong();
508
							m_iWareBuffer[i] = rest.token(" ", i + 1).toLong();
502
					}
509
					}
503
				}
510
				}
504
				else if ( cmd == "createdfile" )
511
				else if ( cmd == "createdfile" )
505
					m_lCreatedFiles.PushBack(CyString(rest));
512
					m_lCreatedFiles.pushBack(rest);
506
				else if ( cmd == "wares" )
513
				else if ( cmd == "wares" )
507
				{
514
				{
508
					iWare = rest.token(" ", 1).toLong();
515
					iWare = rest.token(" ", 1).toLong();
509
					iCount = rest.token(" ", 2).toLong();
516
					iCount = rest.token(" ", 2).toLong();
510
				}
517
				}
Line 523... Line 530...
523
				else if ( cmd == "betaversion" )
530
				else if ( cmd == "betaversion" )
524
					fBeta = rest.toFloat();
531
					fBeta = rest.toFloat();
525
				else if ( cmd == "uninstall" )
532
				else if ( cmd == "uninstall" )
526
				{
533
				{
527
					C_File *uf = new C_File();
534
					C_File *uf = new C_File();
528
					uf->SetFileType(FILETYPE_SCRIPT);
535
					uf->setFileType(FILETYPE_SCRIPT);
529
					uf->SetCreationTime(rest.token(" ", 1).toLong());
536
					uf->SetCreationTime(rest.token(" ", 1).toLong());
530
					uf->SetFilename(m_sCurrentDir + "/Scripts/" + rest.tokens(" ", 2));
537
					uf->SetFilename(m_sCurrentDir + "/Scripts/" + rest.tokens(" ", 2));
531
					m_lUninstallFiles.push_back(uf);
538
					m_lUninstallFiles.push_back(uf);
532
				}
539
				}
533
				else if ( cmd == "nonremovedfile" )
540
				else if ( cmd == "nonremovedfile" )
534
				{
541
				{
535
					if ( !CFileIO::Remove(rest) )
542
					if ( !CFileIO::Remove(rest) )
536
						m_lNonRemovedFiles.PushBack(CyString(rest));
543
						m_lNonRemovedFiles.pushBack(rest);
537
				}
544
				}
538
				else if ( cmd == "original" )
545
				else if ( cmd == "original" )
539
					_pOriginalFiles->parse(rest);
546
					_pOriginalFiles->parse(rest);
540
				else if ( cmd.Compare("GlobalSetting") )
547
				else if ( cmd.Compare("GlobalSetting") )
541
					m_lGlobals.PushBack(CyString(rest.token(":", 1)), CyString(rest.tokens(":", 2)));
548
					m_lGlobals.pushBack(rest.token(":", 1), rest.tokens(":", 2));
542
				else if ( cmd.Compare("FakePatchOrder") )
549
				else if ( cmd.Compare("FakePatchOrder") )
543
					m_lFakePatchOrder.PushBack(CyString(rest.token(":", 1)), CyString(rest.tokens(":", 2)));
550
					m_lFakePatchOrder.pushBack(rest.token(":", 1), rest.tokens(":", 2));
544
				else if ( cmd.Compare("EMPPriceOverride") )
551
				else if ( cmd.Compare("EMPPriceOverride") )
545
					this->addEMPPriceOverride(rest.token(" ", 1).toLong(), rest.token(" ", 2).toLong());
552
					this->addEMPPriceOverride(rest.token(" ", 1).toLong(), rest.token(" ", 2).toLong());
546
				else if ( cmd.Compare("EMPNotoOverride") )
553
				else if ( cmd.Compare("EMPNotoOverride") )
547
					this->addEMPNotoOverride(rest.token(" ", 1).toLong(), rest.token(" ", 2).toLong());
554
					this->addEMPNotoOverride(rest.token(" ", 1).toLong(), rest.token(" ", 2).toLong());
548
				else if ( cmd.Compare("BuiltInWarePriceOverride") )
555
				else if ( cmd.Compare("BuiltInWarePriceOverride") )
Line 597... Line 604...
597
			for ( CListNode<SWares> *wNode = p->GetWaresList()->Front(); wNode; wNode = wNode->next() )
604
			for ( CListNode<SWares> *wNode = p->GetWaresList()->Front(); wNode; wNode = wNode->next() )
598
			{
605
			{
599
				SWares *w = wNode->Data();
606
				SWares *w = wNode->Data();
600
				for ( CListNode<SGameWare> *gNode = m_lGameWares[CPackages::ConvertWareType(w->cType)].Front(); gNode; gNode = gNode->next() )
607
				for ( CListNode<SGameWare> *gNode = m_lGameWares[CPackages::ConvertWareType(w->cType)].Front(); gNode; gNode = gNode->next() )
601
				{
608
				{
602
					if ( w->sID == gNode->Data()->sWareName.ToString() )
609
					if ( w->sID == gNode->Data()->sWareName )
603
					{
610
					{
604
						gNode->Data()->pWare = w;
611
						gNode->Data()->pWare = w;
605
						break;
612
						break;
606
					}
613
					}
607
				}
614
				}
Line 610... Line 617...
610
		else if ( node->Data()->GetType() == TYPE_XSP )
617
		else if ( node->Data()->GetType() == TYPE_XSP )
611
		{
618
		{
612
			CXspFile *p = (CXspFile *)node->Data();
619
			CXspFile *p = (CXspFile *)node->Data();
613
			for ( CListNode<SGameShip> *gNode = m_lGameShips.Front(); gNode; gNode = gNode->next() )
620
			for ( CListNode<SGameShip> *gNode = m_lGameShips.Front(); gNode; gNode = gNode->next() )
614
			{
621
			{
615
				if ( p->GetShipID().Compare(gNode->Data()->sShipID.ToString()) )
622
				if ( p->GetShipID().Compare(gNode->Data()->sShipID) )
616
				{
623
				{
617
					gNode->Data()->pPackage = p;
624
					gNode->Data()->pPackage = p;
618
					break;
625
					break;
619
				}
626
				}
620
			}
627
			}
621
		}
628
		}
622
	}
629
	}
623
 
630
 
624
	// check the purged time
631
	// check the purged time
Line 629... Line 636...
629
	return true;
636
	return true;
630
}
637
}
631
 
638
 
632
void CPackages::RemoveCreatedFiles()
639
void CPackages::RemoveCreatedFiles()
633
{
640
{
634
	for ( SStringList *node = m_lCreatedFiles.Head(); node; node = node->;next )
641
	for(auto itr = m_lCreatedFiles.begin(); itr != m_lCreatedFiles.end(); itr++)
635
	{
642
	{
636
		if ( CFileIO(node->str).ExistsOld() )
643
		if ( CFileIO::Exists((*itr)->str) )
637
			CFileIO::Remove(node->str.ToString());
644
			CFileIO::Remove((*itr)->str);
638
		else if ( CFileIO(m_sCurrentDir + "/" + node->str.ToString()).ExistsOld() )
645
		else if ( CFileIO::Exists(m_sCurrentDir + "/" + (*itr)->str) )
639
			CFileIO::Remove(m_sCurrentDir + "/" + node->str.ToString());
646
			CFileIO::Remove(m_sCurrentDir + "/" + (*itr)->str);
640
	}
647
	}
641
 
648
 
642
	m_lCreatedFiles.Clear();
649
	m_lCreatedFiles.clear();
643
}
650
}
644
 
651
 
645
void CPackages::PurgeGameObjects()
652
void CPackages::PurgeGameObjects()
646
{
653
{
647
	// check for the log file
654
	// check for the log file
648
	Utils::String logDir = logDirectory();
655
	Utils::String logDir = logDirectory();
649
	CFileIO LogFile(logDir + "/log0" + Utils::String::PadNumber(PMTEXTFILE, 4) + ".txt");
656
	CFileIO LogFile(logDir + "/log0" + Utils::String::PadNumber(PMTEXTFILE, 4) + ".txt");
650
	if ( LogFile.exists() )
657
	if ( LogFile.exists() )
651
	{
658
	{
652
		// read the log file to memory
659
		// read the log file to memory
653
		std::vector<CyString> *lines = LogFile.ReadLines();
660
		std::vector<Utils::String> *lines = LogFile.readLines();
654
		if ( lines )
661
		if ( lines )
655
		{
662
		{
656
			for ( int i = 0; i < (int)lines->size(); i++ )
663
			for ( int i = 0; i < (int)lines->size(); i++ )
657
			{
664
			{
658
				CyString line(lines->at(i));
665
				Utils::String line(lines->at(i));
659
				CyString start = line.GetToken(":", 1, 1).ToLower();
666
				Utils::String start = line.token(":", 1).toLower();
660
				CyString rest = line.GetToken(":", 2, 2).RemoveFirstSpace();
667
				Utils::String rest = line.token(":", 2).removeFirstSpace();
661
				if ( start.Compare("purged") )
668
				if ( start.Compare("purged") )
662
				{
669
				{
663
					long time = rest.ToLong();
670
					long time = rest.toLong();
664
					if ( time == m_iLastUpdated )
671
					if ( time == m_iLastUpdated )
665
					{
672
					{
666
						this->PurgeWares();
673
						this->PurgeWares();
667
						this->PurgeShips();
674
						this->PurgeShips();
668
						this->RemoveUninstallScripts();
675
						this->RemoveUninstallScripts();
Line 1033... Line 1040...
1033
		{
1040
		{
1034
			if ( !f->GetDir().Compare("director") )
1041
			if ( !f->GetDir().Compare("director") )
1035
				continue;
1042
				continue;
1036
			if ( f->CheckFileExt("xml") || f->CheckFileExt("pck") )
1043
			if ( f->CheckFileExt("xml") || f->CheckFileExt("pck") )
1037
			{
1044
			{
1038
				f->SetDir("");
1045
				f->setDir("");
1039
				f->SetFileType(FILETYPE_MISSION);
1046
				f->setFileType(FILETYPE_MISSION);
1040
			}
1047
			}
1041
		}
1048
		}
1042
	}
1049
	}
1043
}
1050
}
1044
 
1051
 
Line 1131... Line 1138...
1131
 
1138
 
1132
	return check;
1139
	return check;
1133
}
1140
}
1134
 
1141
 
1135
CMultiSpkFile *CPackages::OpenMultiPackage(CyString file, int *error, CProgressInfo *progress)
1142
CMultiSpkFile *CPackages::OpenMultiPackage(CyString file, int *error, CProgressInfo *progress)
1136
{
1143
{
1137
	int check = CheckOpenPackage(file, error);
1144
	int check = CheckOpenPackage(file, error);
1138
	if ( *error == -1 )
1145
	if ( *error == -1 )
1139
		return false;
1146
		return false;
1140
 
1147
 
1141
	if ( check != SPKFILE_MULTI )
1148
	if ( check != SPKFILE_MULTI )
1142
	{
1149
	{
1143
		*error = INSTALLERR_NOMULTI;
1150
		*error = INSTALLERR_NOMULTI;
1144
		return false;
1151
		return false;
1145
	}
1152
	}
1146
 
1153
 
1147
	*error = INSTALLERR_NONE;
1154
	*error = INSTALLERR_NONE;
1148
 
1155
 
1149
	CMultiSpkFile *package = new CMultiSpkFile;
1156
	CMultiSpkFile *package = new CMultiSpkFile;
Line 1296... Line 1303...
1296
		case SPKFILE_MULTI:
1303
		case SPKFILE_MULTI:
1297
			*error = INSTALLERR_NOMULTI;
1304
			*error = INSTALLERR_NOMULTI;
1298
			return NULL;
1305
			return NULL;
1299
		case SPKFILE_SINGLESHIP:
1306
		case SPKFILE_SINGLESHIP:
1300
			installFile = new CXspFile();
1307
			installFile = new CXspFile();
1301
			if ( !((CXspFile *)installFile)->ReadFile(file, readtype, progress) )
1308
			if ( !((CXspFile *)installFile)->readFile(file.ToString(), readtype, progress))
1302
			{
1309
			{
1303
				delete installFile;
1310
				delete installFile;
1304
				return NULL;
1311
				return NULL;
1305
			}
1312
			}
1306
			break;
1313
			break;
Line 1507... Line 1514...
1507
	_pOriginalFiles->installed(package);
1514
	_pOriginalFiles->installed(package);
1508
 
1515
 
1509
	// if we're installing an addon, lets use the fake patch method for object files
1516
	// if we're installing an addon, lets use the fake patch method for object files
1510
	if ( m_iGameFlags & EXEFLAG_ADDON ) this->_addToFakePatch(package);
1517
	if ( m_iGameFlags & EXEFLAG_ADDON ) this->_addToFakePatch(package);
1511
 
1518
 
1512
	bool shuffle = false;
1519
	bool shuffle = package->anyFakePatchOrder();
1513
 
1520
 
1514
	// merge the update into the old package
1521
	// merge the update into the old package
1515
	bool dontAdd = false;
1522
	bool dontAdd = false;
1516
	if ( package->GetType() == TYPE_SPK )
1523
	if ( package->GetType() == TYPE_SPK )
1517
	{
1524
	{
Line 1645... Line 1652...
1645
			delete package;
1652
			delete package;
1646
			package = oldPackage;
1653
			package = oldPackage;
1647
			oldPackage = false;
1654
			oldPackage = false;
1648
			dontAdd = true;
1655
			dontAdd = true;
1649
 
1656
 
1650
			CDirIO(m_sCurrentDir).RemoveDir("temp");
1657
			CDirIO(m_sCurrentDir).removeDir("temp");
1651
			CDirIO(m_sCurrentDir).RemoveDir("Mods/temp");
1658
			CDirIO(m_sCurrentDir).removeDir("Mods/temp");
1652
		}
1659
		}
1653
	}
1660
	}
1654
 
1661
 
1655
	// if theres an icon, write it
1662
	// if theres an icon, write it
1656
	if ( package->GetIcon() )
1663
	if ( package->GetIcon() )
Line 1665... Line 1672...
1665
		{
1672
		{
1666
			CDirIO Dir(m_sCurrentDir);
1673
			CDirIO Dir(m_sCurrentDir);
1667
			bool ready = true;
1674
			bool ready = true;
1668
			if ( !Dir.exists("PluginManager") )
1675
			if ( !Dir.exists("PluginManager") )
1669
			{
1676
			{
1670
				if ( !Dir.Create("PluginManager") )
1677
				if ( !Dir.create("PluginManager") )
1671
					ready = false;
1678
					ready = false;
1672
			}
1679
			}
1673
			if ( ready && !Dir.exists("PluginManager/Icons") )
1680
			if ( ready && !Dir.exists("PluginManager/Icons") )
1674
			{
1681
			{
1675
				if ( !Dir.Create("PluginManager/Icons") )
1682
				if ( !Dir.create("PluginManager/Icons") )
1676
					ready = false;
1683
					ready = false;
1677
			}
1684
			}
1678
 
1685
 
1679
			if ( ready )
1686
			if ( ready )
1680
			{
1687
			{
Line 1737... Line 1744...
1737
		while ( fnode )
1744
		while ( fnode )
1738
		{
1745
		{
1739
			C_File *f = fnode->Data();
1746
			C_File *f = fnode->Data();
1740
 
1747
 
1741
			// no longer used
1748
			// no longer used
1742
			if ( !f->GetUsed() )
1749
			if ( !f->getUsed() )
1743
			{
1750
			{
1744
				// remove from file list
1751
				// remove from file list
1745
				m_lFiles.remove(f, false);
1752
				m_lFiles.remove(f, false);
1746
 
1753
 
1747
				// if its a readme file, then check if its in the new package
1754
				// if its a readme file, then check if its in the new package
Line 1860... Line 1867...
1860
			continue;
1867
			continue;
1861
		}
1868
		}
1862
 
1869
 
1863
		// only delete files that are not used
1870
		// only delete files that are not used
1864
		// if its a shared file, we skip it
1871
		// if its a shared file, we skip it
1865
		if ( f->GetUsed() || f->IsShared() )
1872
		if ( f->getUsed() || f->IsShared() )
1866
			continue;
1873
			continue;
1867
 
1874
 
1868
		if ( f->GetFileType() == FILETYPE_README )
1875
		if ( f->GetFileType() == FILETYPE_README )
1869
			readme = true;
1876
			readme = true;
1870
		else if ( f->GetFileType() == FILETYPE_UNINSTALL || f->GetFileType() == FILETYPE_MAP || f->GetFileType() == FILETYPE_SOUND || f->GetFileType() == FILETYPE_EXTRA || f->GetFileType() == FILETYPE_SHIPSCENE || f->GetFileType() == FILETYPE_COCKPITSCENE || f->GetFileType() == FILETYPE_SHIPOTHER || f->GetFileType() == FILETYPE_SHIPMODEL || f->GetFileType() == FILETYPE_ADVERT )
1877
		else if ( f->GetFileType() == FILETYPE_UNINSTALL || f->GetFileType() == FILETYPE_MAP || f->GetFileType() == FILETYPE_SOUND || f->GetFileType() == FILETYPE_EXTRA || f->GetFileType() == FILETYPE_SHIPSCENE || f->GetFileType() == FILETYPE_COCKPITSCENE || f->GetFileType() == FILETYPE_SHIPOTHER || f->GetFileType() == FILETYPE_SHIPMODEL || f->GetFileType() == FILETYPE_ADVERT )
Line 1888... Line 1895...
1888
		if ( RemoveFile(f, errors) )
1895
		if ( RemoveFile(f, errors) )
1889
		{
1896
		{
1890
			original = _pOriginalFiles->restoreFile(f, errors);
1897
			original = _pOriginalFiles->restoreFile(f, errors);
1891
		}
1898
		}
1892
		else // problem removeing (try when the program closes)
1899
		else // problem removeing (try when the program closes)
1893
			m_lNonRemovedFiles.PushBack(f->GetFilePointer());
1900
			m_lNonRemovedFiles.pushBack(f->filePointer());
1894
 
1901
 
1895
		// check for fake patchs
1902
		// check for fake patchs
1896
		if ( f->IsFakePatch() )
1903
		if ( f->IsFakePatch() )
1897
			shuffle = true;
1904
			shuffle = true;
1898
		else if ( f->isAutoTextFile() )
1905
		else if ( f->isAutoTextFile() )
Line 1928... Line 1935...
1928
 
1935
 
1929
		// make sure the scripts directory is created, even thou it should always be there anyways
1936
		// make sure the scripts directory is created, even thou it should always be there anyways
1930
		CDirIO scriptDir(m_sCurrentDir);
1937
		CDirIO scriptDir(m_sCurrentDir);
1931
		if ( !scriptDir.exists("scripts") )
1938
		if ( !scriptDir.exists("scripts") )
1932
		{
1939
		{
1933
			if ( scriptDir.Create("Scripts") )
1940
			if ( scriptDir.create("Scripts") )
1934
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, "Scripts", errors);
1941
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, "Scripts", errors);
1935
			else
1942
			else
1936
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, "Scripts", errors);
1943
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, "Scripts", errors);
1937
		}
1944
		}
1938
 
1945
 
1939
		for ( C_File *uf = uninstallFiles.First(); uf; uf = uninstallFiles.Next() )
1946
		for ( C_File *uf = uninstallFiles.First(); uf; uf = uninstallFiles.Next() )
1940
		{
1947
		{
1941
			C_File *newFile = new C_File();
1948
			C_File *newFile = new C_File();
1942
			newFile->SetFileType(FILETYPE_SCRIPT);
1949
			newFile->setFileType(FILETYPE_SCRIPT);
1943
			newFile->setFilename(uf->filename());
1950
			newFile->setFilename(uf->filename());
1944
			newFile->SetCreationTime(uf->GetCreationTime());
1951
			newFile->SetCreationTime(uf->GetCreationTime());
1945
 
1952
 
1946
			// other installed packages use this file as well, copy it
1953
			// other installed packages use this file as well, copy it
1947
			Utils::String newFilename = m_sCurrentDir + "/" + newFile->getNameDirectory(NULL);
1954
			Utils::String newFilename = m_sCurrentDir + "/" + newFile->getNameDirectory(NULL);
1948
			CFileIO file(uf->filePointer());
1955
			CFileIO file(uf->filePointer());
1949
 
1956
 
1950
			if ( uf->GetUsed() )
1957
			if ( uf->getUsed() )
1951
			{
1958
			{
1952
				if ( file.copy(newFilename) )
1959
				if ( file.copy(newFilename) )
1953
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY, newFile->getNameDirectory(NULL), errors);
1960
					this->AddLogEntry(SPKINSTALL_UNINSTALL_COPY, newFile->getNameDirectory(NULL), errors);
1954
				else
1961
				else
1955
				{
1962
				{
Line 2451... Line 2458...
2451
{
2458
{
2452
	if ( m_sCurrentDir.empty() )
2459
	if ( m_sCurrentDir.empty() )
2453
		return true;
2460
		return true;
2454
	if ( !m_bLoaded )
2461
	if ( !m_bLoaded )
2455
		return true;
2462
		return true;
-
 
2463
 
-
 
2464
	Utils::CStringList lErrors;
2456
 
2465
 
2457
	CLog::log(CLog::Log_Directory, 1, "closing directory: " + m_sCurrentDir);
2466
	CLog::log(CLog::Log_Directory, 1, "closing directory: " + m_sCurrentDir);
2458
 
2467
 
2459
	if ( m_bRenameText ) {
2468
	if ( m_bRenameText ) {
2460
		CLog::log(CLog::Log_Directory, 2, "Creating other language files for game");
2469
		CLog::log(CLog::Log_Directory, 2, "Creating other language files for game");
2461
		CreateLanguageTextFiles(errors);
2470
		CreateLanguageTextFiles(&lErrors);
2462
	}
2471
	}
2463
 
2472
 
2464
	CLog::log(CLog::Log_Directory, 2, "Backing up save game files");
2473
	CLog::log(CLog::Log_Directory, 2, "Backing up save game files");
2465
 
2474
 
2466
	if ( CFileIO(m_sCurrentDir + "/mods/PluginManager.dat").ExistsOld() ) {
2475
	if ( CFileIO::Exists(m_sCurrentDir + "/mods/PluginManager.dat") ) {
2467
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.dat file");
2476
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.dat file");
2468
		CFileIO::Remove(m_sCurrentDir + "/mods/PluginManager.dat");
2477
		CFileIO::Remove(m_sCurrentDir + "/mods/PluginManager.dat");
2469
	}
2478
	}
2470
	if ( CFileIO(m_sCurrentDir + "/mods/PluginManager.cat").ExistsOld() ) {
2479
	if ( CFileIO::Exists(m_sCurrentDir + "/mods/PluginManager.cat") ) {
2471
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.cat file");
2480
		CLog::log(CLog::Log_IO, 3, "Removing old PluginManager.cat file");
2472
		CFileIO::Remove(m_sCurrentDir + "/mods/PluginManager.cat");
2481
		CFileIO::Remove(m_sCurrentDir + "/mods/PluginManager.cat");
2473
	}
2482
	}
2474
 
2483
 
2475
	if ( !m_bVanilla )
2484
	if ( !m_bVanilla )
Line 2487... Line 2496...
2487
				while ( fCat && !fCat->IsFakePatch() && !fCat->CheckFileExt("cat") && !fCat->GetBaseName().Compare(fDat->GetBaseName()) )
2496
				while ( fCat && !fCat->IsFakePatch() && !fCat->CheckFileExt("cat") && !fCat->GetBaseName().Compare(fDat->GetBaseName()) )
2488
					fCat = m_pEnabledMod->GetNextFile(fCat);
2497
					fCat = m_pEnabledMod->GetNextFile(fCat);
2489
 
2498
 
2490
				if ( fCat )
2499
				if ( fCat )
2491
				{
2500
				{
2492
					CFileIO(fDat->GetFilePointer()).copy(m_sCurrentDir + "/mods/PluginManager.dat");
2501
					CFileIO(fDat->filePointer()).copy(m_sCurrentDir + "/mods/PluginManager.dat");
2493
					CFileIO(fCat->GetFilePointer()).copy(m_sCurrentDir + "/mods/PluginManager.cat");
2502
					CFileIO(fCat->filePointer()).copy(m_sCurrentDir + "/mods/PluginManager.cat");
2494
				}
2503
				}
2495
			}
2504
			}
2496
		}
2505
		}
2497
		else if ( m_iGame == GAME_X3 && !m_sSetMod.Empty() && CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ".cat").ExistsOld() && CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ".dat").ExistsOld())
2506
		else if ( m_iGame == GAME_X3 && !m_sSetMod.empty() && CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat").ExistsOld() && CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".dat").ExistsOld())
2498
		{
2507
		{
2499
			CLog::log(CLog::Log_Directory, 2, "Copying mod file: " + m_sSetMod.ToString() + ", to PluginManager.cat");
2508
			CLog::log(CLog::Log_Directory, 2, "Copying mod file: " + m_sSetMod + ", to PluginManager.cat");
2500
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ".dat").copy(m_sCurrentDir + "/mods/PluginManager.dat");
2509
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".dat").copy(m_sCurrentDir + "/mods/PluginManager.dat");
2501
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ".cat").copy(m_sCurrentDir + "/mods/PluginManager.cat");
2510
			CFileIO(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat").copy(m_sCurrentDir + "/mods/PluginManager.cat");
2502
		}
2511
		}
2503
 
2512
 
2504
		if ( !CDirIO(m_sCurrentDir).exists("mods") )
2513
		if ( !CDirIO(m_sCurrentDir).exists("mods") )
2505
			CDirIO(m_sCurrentDir).Create("mods");
2514
			CDirIO(m_sCurrentDir).create("mods");
2506
 
2515
 
2507
		SetupWares();
2516
		SetupWares();
2508
		SetupShips();
2517
		SetupShips();
2509
		CreateEMPFile();
2518
		CreateEMPFile();
2510
		CreateWareFiles();
2519
		CreateWareFiles();
Line 2524... Line 2533...
2524
 
2533
 
2525
	WriteData();
2534
	WriteData();
2526
	if ( removedir && m_bRemoveDir )
2535
	if ( removedir && m_bRemoveDir )
2527
	{
2536
	{
2528
		m_bRemoveDir = false;
2537
		m_bRemoveDir = false;
2529
		CyStringList removeDirs;
2538
		Utils::CStringList removeDirs;
2530
		removeDirs.PushBack(".");
2539
		removeDirs.pushBack(".");
2531
		RemoveUnusedDirectories(removeDirs, errors);
2540
		removeUnusedDirectories(removeDirs, &lErrors);
2532
	}
2541
	}
2533
 
2542
 
2534
	this->setCurrentDir("");
2543
	this->setCurrentDir("");
2535
		 
2544
		 
-
 
2545
	//TEMP: switch to errors
-
 
2546
	if (errors)
-
 
2547
	{
-
 
2548
		for (auto itr = lErrors.begin(); itr != lErrors.end(); itr++)
-
 
2549
			errors->PushBack(CyString((*itr)->str), CyString((*itr)->data));
-
 
2550
	}
-
 
2551
 
2536
	m_bLoaded = false;
2552
	m_bLoaded = false;
2537
	return true;
2553
	return true;
2538
}
2554
}
2539
 
2555
 
2540
CyString CPackages::GetModKey()
2556
CyString CPackages::GetModKey()
2541
{
2557
{
2542
	return m_gameExe.GetModKey(m_iGame - 1);
2558
	return m_gameExe.GetModKey(m_iGame - 1);
2543
}
2559
}
2544
CyString CPackages::GetSelectedModName()
2560
Utils::String CPackages::selectedModName() const
2545
{
2561
{
2546
	if ( !m_pEnabledMod )
2562
	if ( !m_pEnabledMod )
2547
	{
2563
	{
2548
		if ( m_sSetMod.Empty() && m_iGame == GAME_X3 )
2564
		if ( m_sSetMod.empty() && m_iGame == GAME_X3 )
2549
			return "PluginManager";
2565
			return "PluginManager";
2550
		return m_sSetMod;
2566
		return m_sSetMod;
2551
	}
2567
	}
2552
 
2568
 
2553
	if ( !m_pEnabledMod->IsEnabled() )
2569
	if ( !m_pEnabledMod->IsEnabled() )
2554
		return m_sSetMod;
2570
		return m_sSetMod;
2555
 
2571
 
2556
	C_File *f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2572
	C_File *f = m_pEnabledMod->GetFirstFile(FILETYPE_MOD);
2557
	if ( !f )
2573
	if ( !f )
2558
		return m_sSetMod;
2574
		return m_sSetMod;
2559
 
2575
 
2560
	CyString name = f->filename();
2576
	Utils::String name = f->filename();
2561
	name = name.Left(-4);
2577
	name = name.left(-4);
2562
	return name;
2578
	return name;
2563
 
2579
 
2564
}
2580
}
2565
 
2581
 
2566
bool CPackages::RestoreFakePatch()
2582
bool CPackages::RestoreFakePatch()
2567
{
2583
{
2568
	CLog::log(CLog::Log_Directory, 1, "Restoring PluginManager fake patch into game");
2584
	CLog::log(CLog::Log_Directory, 1, "Restoring PluginManager fake patch into game");
2569
 	m_iFakePatch = -1;
2585
 	m_iFakePatch = -1;
2570
 
2586
 
2571
	CFileIO catFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat");
2587
	CFileIO catFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat");
2572
	CFileIO datFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
2588
	CFileIO datFile(m_sCurrentDir + "/PluginManager/PlugMan_Fake.dat");
2573
 
2589
 
2574
	// if only 1 exists, remove it
2590
	// if only 1 exists, remove it
2575
	if ( catFile.exists() && !datFile.exists() ) {
2591
	if ( catFile.exists() && !datFile.exists() ) {
Line 2590... Line 2606...
2590
		if ( !file.Empty() )
2606
		if ( !file.Empty() )
2591
			file += "/";
2607
			file += "/";
2592
		file += "pluginmanagerfake.txt";
2608
		file += "pluginmanagerfake.txt";
2593
		file = file.FindReplace("\\", "/");
2609
		file = file.FindReplace("\\", "/");
2594
		CFileIO fakeFile(file);
2610
		CFileIO fakeFile(file);
2595
		std::vector<CyString> lines;
2611
		std::vector<Utils::String> lines;
2596
		lines.push_back("//pluginmanager fake patch");
2612
		lines.push_back("//pluginmanager fake patch");
2597
		CLog::log(CLog::Log_Directory, 3, "Writing pluginmanagerfake.txt file to add to Fake Patch");
2613
		CLog::log(CLog::Log_Directory, 3, "Writing pluginmanagerfake.txt file to add to Fake Patch");
2598
		if ( !fakeFile.WriteFile(&lines) ) {
2614
		if ( !fakeFile.writeFile(&lines) ) {
2599
			CLog::log(CLog::Log_Directory, 3, "Writing pluginmanagerfake.txt failed!!");
2615
			CLog::log(CLog::Log_Directory, 3, "Writing pluginmanagerfake.txt failed!!");
2600
		}
2616
		}
2601
		else {
2617
		else {
2602
/*
2618
/*
2603
			CLog::log(CLog::Log_Directory, 2, "Adding TFake.pck file into FakePatch");
2619
			CLog::log(CLog::Log_Directory, 2, "Adding TFake.pck file into FakePatch");
2604
			CCatFile fakePatch;
2620
			CCatFile fakePatch;
2605
			if ( fakePatch.Open(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat", this->GetAddonDir(), CATREAD_DAT, false) == CATERR_NONE )
2621
			if ( fakePatch.Open(m_sCurrentDir + "/PluginManager/PlugMan_Fake.cat", this->GetAddonDir(), CATREAD_DAT, false) == CATERR_NONE )
2606
			{
2622
			{
Line 2612... Line 2628...
2612
		// backup existing mod files incase something happens to them
2628
		// backup existing mod files incase something happens to them
2613
		if ( !datFile.exists() || !catFile.exists() ) {
2629
		if ( !datFile.exists() || !catFile.exists() ) {
2614
			CLog::log(CLog::Log_Directory, 2, Utils::String("ERROR: ") + (!catFile.exists() ? "cat" : "dat") + " file appears to be missing");
2630
			CLog::log(CLog::Log_Directory, 2, Utils::String("ERROR: ") + (!catFile.exists() ? "cat" : "dat") + " file appears to be missing");
2615
		}
2631
		}
2616
		else {
2632
		else {
2617
			catFile.GetDirIO().Create("Backup");
2633
			catFile.GetDirIO().create("Backup");
2618
			catFile.copy(catFile.dir() + "/Backup/" + catFile.filename());
2634
			catFile.copy(catFile.dir() + "/Backup/" + catFile.filename());
2619
			datFile.copy(datFile.dir() + "/Backup/" + datFile.filename());
2635
			datFile.copy(datFile.dir() + "/Backup/" + datFile.filename());
2620
		}
2636
		}
2621
 
2637
 
2622
 
2638
 
2623
		// find next available fake patch
2639
		// find next available fake patch
2624
		m_iFakePatch = this->FindNextFakePatch();
2640
		m_iFakePatch = this->FindNextFakePatch();
2625
		CLog::log(CLog::Log_Directory, 2, "Finding next available fake patch number: " + (long)m_iFakePatch);
2641
		CLog::log(CLog::Log_Directory, 2, "Finding next available fake patch number: " + (long)m_iFakePatch);
2626
 
2642
 
2627
		Utils::String filename = Utils::String::PadNumber(m_iFakePatch, 2);
2643
		Utils::String filename = Utils::String::PadNumber(m_iFakePatch, 2);
Line 2663... Line 2679...
2663
	if ( m_sCurrentDir.empty() )
2679
	if ( m_sCurrentDir.empty() )
2664
		return;
2680
		return;
2665
 
2681
 
2666
	CLog::log(CLog::Log_Directory, 1, "Writing data file for current directory: " + m_sCurrentDir);
2682
	CLog::log(CLog::Log_Directory, 1, "Writing data file for current directory: " + m_sCurrentDir);
2667
 
2683
 
2668
	CyStringList lines;
2684
	Utils::CStringList lines;
2669
	CyString version;
-
 
2670
	version.FromFloat(GetLibraryVersion(), 2);
2685
	Utils::String version = "SpkInstaller: " + Utils::String::FromFloat(GetLibraryVersion(), 2);
2671
	version.Prepend("SpkInstaller: ");
-
 
2672
	lines.PushBack(version);
2686
	lines.pushBack(version);
2673
 
2687
 
2674
	lines.PushBack(CyString("UpdateTime: ") + (long)m_iLastUpdated);
2688
	lines.pushBack(Utils::String("UpdateTime: ") + (long)m_iLastUpdated);
2675
	if ( m_iFakePatch != -1 )
2689
	if ( m_iFakePatch != -1 )
2676
		lines.PushBack(CyString("FakePatch: ") + (long)m_iFakePatch);
2690
		lines.pushBack(Utils::String("FakePatch: ") + (long)m_iFakePatch);
2677
	if ( m_iSaveGame != -1 )
2691
	if ( m_iSaveGame != -1 )
2678
		lines.PushBack(CyString("SaveGame: ") + (long)m_iSaveGame);
2692
		lines.pushBack(Utils::String("SaveGame: ") + (long)m_iSaveGame);
2679
	lines.PushBack(CyString("SaveGameManager: ") + (long)m_iSaveGameManager);
2693
	lines.pushBack(Utils::String("SaveGameManager: ") + (long)m_iSaveGameManager);
2680
	if ( !m_bVanilla )
2694
	if ( !m_bVanilla )
2681
		lines.PushBack("Modified");
2695
		lines.pushBack("Modified");
2682
	if ( m_bUsedWare )
2696
	if ( m_bUsedWare )
2683
		lines.PushBack("UsedWare");
2697
		lines.pushBack("UsedWare");
2684
	if ( m_bSurpressProtectedWarning )
2698
	if ( m_bSurpressProtectedWarning )
2685
		lines.PushBack("SurpressProtectedWarning");
2699
		lines.pushBack("SurpressProtectedWarning");
2686
	if ( !m_sSetMod.Empty() )
2700
	if ( !m_sSetMod.empty() )
2687
		lines.PushBack(CyString("SetMod: ") + m_sSetMod);
2701
		lines.pushBack("SetMod: " + m_sSetMod);
2688
	if (!_sSaveDir.empty())
2702
	if (!_sSaveDir.empty())
2689
		lines.PushBack(CyString("SaveDir: ") + _sSaveDir);
2703
		lines.pushBack("SaveDir: " + _sSaveDir);
2690
	lines.PushBack(CyString("ShipBuffer: ") + (long)m_iShipBuffer);
2704
	lines.pushBack(Utils::String("ShipBuffer: ") + (long)m_iShipBuffer);
2691
	CyString wareBuffer = "WareBuffers:";
2705
	Utils::String wareBuffer = "WareBuffers:";
2692
	for ( int i = 0; i < WAREBUFFERS; i++ )
2706
	for ( int i = 0; i < WAREBUFFERS; i++ )
2693
		wareBuffer += CyString(" ") + (long)m_iWareBuffer[i];
2707
		wareBuffer += Utils::String(" ") + (long)m_iWareBuffer[i];
2694
	lines.PushBack(wareBuffer);
2708
	lines.pushBack(wareBuffer);
2695
	for ( int i = 0; i < WAREBUFFERS; i++ )
2709
	for ( int i = 0; i < WAREBUFFERS; i++ )
2696
	{
2710
	{
2697
		if ( !m_lGameWares[i].size() )
2711
		if ( !m_lGameWares[i].size() )
2698
			continue;
2712
			continue;
2699
		lines.PushBack(CyString("Wares: ") + (long)i + " " + (long)m_lGameWares[i].size());
2713
		lines.pushBack(Utils::String("Wares: ") + (long)i + " " + (long)m_lGameWares[i].size());
2700
 
2714
 
2701
		for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
2715
		for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
2702
		{
2716
		{
2703
			SGameWare *gm = node->Data();
2717
			SGameWare *gm = node->Data();
2704
			lines.PushBack(CyString((long)gm->iPos) + " " + (long)gm->iType + " " + CyString((char)gm->cType) + " " + gm->sWareName);
2718
			lines.pushBack(Utils::String((long)gm->iPos) + " " + (long)gm->iType + " " + Utils::String((char)gm->cType) + " " + gm->sWareName);
2705
		}
2719
		}
2706
	}
2720
	}
2707
 
2721
 
2708
	for ( SStringList *str = m_lNonRemovedFiles.Head(); str; str = str->;next )
2722
	for(auto itr = m_lNonRemovedFiles.begin(); itr != m_lNonRemovedFiles.end(); itr++)
2709
		lines.PushBack(CyString("NonRemovedFile: ") + str->str);
2723
		lines.pushBack("NonRemovedFile: " + (*itr)->str);
2710
 
2724
 
2711
	if ( m_lGameShips.size() )
2725
	if ( m_lGameShips.size() )
2712
	{
2726
	{
2713
		lines.PushBack(CyString("Ships: ") + (long)m_lGameShips.size());
2727
		lines.pushBack(Utils::String("Ships: ") + (long)m_lGameShips.size());
2714
 
2728
 
2715
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
2729
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
2716
		{
2730
		{
2717
			SGameShip *gm = node->Data();
2731
			SGameShip *gm = node->Data();
2718
			lines.PushBack(CyString((long)gm->iType) + " $#C:" + gm->sShipClass + " " + gm->sShipID);
2732
			lines.pushBack(Utils::String((long)gm->iType) + " $#C:" + gm->sShipClass + " " + gm->sShipID);
2719
		}
2733
		}
2720
	}
2734
	}
2721
 
2735
 
2722
	// write created Files
2736
	// write created Files
2723
	if ( !m_lCreatedFiles.Empty() )
2737
	if ( !m_lCreatedFiles.empty() )
2724
	{
2738
	{
2725
		for ( SStringList *node = m_lCreatedFiles.Head(); node; node = node->;next )
2739
		for(auto itr = m_lCreatedFiles.begin(); itr != m_lCreatedFiles.end(); itr++)
2726
			lines.PushBack(CyString("CreatedFile: ") + node->str.Remove(m_sCurrentDir));
2740
			lines.pushBack("CreatedFile: " + (*itr)->str.findRemove(m_sCurrentDir));
2727
	}
2741
	}
2728
 
2742
 
2729
	// write uninstall files
2743
	// write uninstall files
2730
	if ( !m_lUninstallFiles.empty() )
2744
	if ( !m_lUninstallFiles.empty() )
2731
	{
2745
	{
2732
		for ( CListNode<C_File> *node = m_lUninstallFiles.Front(); node; node = node->next() )
2746
		for ( CListNode<C_File> *node = m_lUninstallFiles.Front(); node; node = node->next() )
2733
		{
2747
		{
2734
			C_File *uf = node->Data();
2748
			C_File *uf = node->Data();
2735
			CyString uString = "Uninstall: ";
2749
			Utils::String uString = "Uninstall: ";
2736
			uString += CyString::Number((long)uf->GetCreationTime()) + " ";
2750
			uString += Utils::String::Number((long)uf->GetCreationTime()) + " ";
2737
			uString += uf->filename();
2751
			uString += uf->filename();
2738
			lines.PushBack(uString);
2752
			lines.pushBack(uString);
2739
		}
2753
		}
2740
	}
2754
	}
2741
 
2755
 
2742
	// write the original file data
2756
	// write the original file data
2743
	_pOriginalFiles->writeData(&lines);
2757
	_pOriginalFiles->writeData(lines);
2744
 
2758
 
2745
	// write the global changes
2759
	// write the global changes
2746
	if ( !m_lGlobals.Empty() )
2760
	if ( !m_lGlobals.empty() )
2747
	{
2761
	{
2748
		for ( SStringList *str = m_lGlobals.Head(); str; str = str->;next )
2762
		for(auto itr = m_lGlobals.begin(); itr != m_lGlobals.end(); itr++)
2749
			lines.PushBack(CyString("GlobalSetting: ") + str->str + ":" + str->data.Remove(";"));
2763
			lines.pushBack("GlobalSetting: " + (*itr)->str + ":" + (*itr)->data.findRemove(";"));
2750
	}
2764
	}
2751
 
2765
 
2752
	// write the fake patch ordering
2766
	// write the fake patch ordering
2753
	if ( !m_lFakePatchOrder.Empty() )
2767
	if ( !m_lFakePatchOrder.empty() )
2754
	{
2768
	{
2755
		for ( SStringList *str = m_lFakePatchOrder.Head(); str; str = str->;next )
2769
		for(auto itr = m_lFakePatchOrder.begin(); itr != m_lFakePatchOrder.end(); itr++)
2756
			lines.PushBack(CyString("FakePatchOrder: ") + str->str + ":" + str->data);
2770
			lines.pushBack("FakePatchOrder: " + (*itr)->str + ":" + (*itr)->data);
2757
	}
2771
	}
2758
 
2772
 
2759
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
2773
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
2760
		SWarePriceOverride *ware = node->Data();
2774
		SWarePriceOverride *ware = node->Data();
2761
		switch(ware->type) {
2775
		switch(ware->type) {
2762
			case Ware_EMP:
2776
			case Ware_EMP:
2763
				lines.PushBack(CyString(Utils::String(";EMPPriceOverride:") + (long)ware->pos + "; " + (long)ware->relval));
2777
				lines.pushBack(Utils::String(";EMPPriceOverride:") + (long)ware->pos + "; " + (long)ware->relval);
2764
				if ( ware->bNotority )
2778
				if ( ware->bNotority )
2765
					lines.PushBack(CyString(Utils::String(";EMPNotoOverride:") + (long)ware->pos + "; " + (long)ware->notority));
2779
					lines.pushBack(Utils::String(";EMPNotoOverride:") + (long)ware->pos + "; " + (long)ware->notority);
2766
				break;
2780
				break;
2767
			case Ware_Custom:
2781
			case Ware_Custom:
2768
				lines.PushBack(CyString(Utils::String(";CustomWarePriceOverride:") + ware->id + &quot;;&quot; + (long)ware->relval));
2782
				lines.pushBack(Utils::String(";CustomWarePriceOverride:") + ware->id + &quot;;&quot; + (long)ware->relval);
2769
				if ( ware->bNotority )
2783
				if ( ware->bNotority )
2770
					lines.PushBack(CyString(Utils::String(";CustomWareNotoOverride:") + ware->id + &quot;;&quot; + (long)ware->notority));
2784
					lines.pushBack(Utils::String(";CustomWareNotoOverride:") + ware->id + &quot;;&quot; + (long)ware->notority);
2771
				break;
2785
				break;
2772
			case Ware_BuiltIn:
2786
			case Ware_BuiltIn:
2773
				lines.PushBack(CyString(Utils::String(";BuiltInWarePriceOverride:") + (long)ware->pos + "; " + (long)ware->relval));
2787
				lines.pushBack(Utils::String(";BuiltInWarePriceOverride:") + (long)ware->pos + "; " + (long)ware->relval);
2774
				if ( ware->bNotority )
2788
				if ( ware->bNotority )
2775
					lines.PushBack(CyString(Utils::String(";BuiltInWareNotoOverride:") + (long)ware->pos + "; " + (long)ware->notority));
2789
					lines.pushBack(Utils::String(";BuiltInWareNotoOverride:") + (long)ware->pos + "; " + (long)ware->notority);
2776
				break;
2790
				break;
2777
		}
2791
		}
2778
	}
2792
	}
2779
 
2793
 
2780
	// write the global file list
2794
	// write the global file list
2781
	lines.PushBack("GlobalFiles:");
2795
	lines.pushBack("GlobalFiles:");
2782
	int num = 0;
2796
	int num = 0;
2783
	for ( CListNode<C_File> *fn = m_lFiles.Front(); fn; fn = fn->next() )
2797
	for ( CListNode<C_File> *fn = m_lFiles.Front(); fn; fn = fn->next() )
2784
	{
2798
	{
2785
		C_File *f = fn->Data();
2799
		C_File *f = fn->Data();
2786
		f->SetPos(num++);
2800
		f->SetPos(num++);
2787
 
2801
 
2788
		CyString line = CyString::Number(f-&gt;GetFileType()) + ":" + CyString::Number((long)f->GetCreationTime()) + ":" + f->GetDir() + ":";
2802
		Utils::String line = Utils::String::Number(f-&gt;GetFileType()) + ":" + Utils::String::Number((long)f->GetCreationTime()) + ":" + f->dir() + ":";
2789
		if ( f->IsShared() && !f->IsFakePatch() )
2803
		if ( f->IsShared() && !f->IsFakePatch() )
2790
			line += "1:";
2804
			line += "1:";
2791
		else
2805
		else
2792
			line += "0:";
2806
			line += "0:";
2793
 
2807
 
2794
		CyString filename = f->GetFilePointer();
2808
		Utils::String filename = f->filePointer().findRemove(m_sCurrentDir);
2795
		filename.Remove(m_sCurrentDir);
-
 
2796
 
2809
 
2797
		if ( f->IsDisabled() )
2810
		if ( f->IsDisabled() )
2798
			line += "D#";
2811
			line += "D#";
2799
 
2812
 
2800
		line += "G#";
2813
		line += "G#";
2801
		line += (long)f->GetGame();
2814
		line += (long)f->GetGame();
2802
		line += "#";
2815
		line += "#";
2803
 
2816
 
2804
		line += filename;
2817
		line += filename;
2805
 
2818
 
2806
		if ( !f->GetOriginalName().Empty() )
2819
		if ( !f->originalName().empty() )
2807
		{
2820
		{
2808
			line += "O#";
2821
			line += "O#";
2809
			line += f->GetOriginalName();
2822
			line += f->originalName();
2810
		}
2823
		}
2811
 
2824
 
2812
		lines.PushBack(line);
2825
		lines.pushBack(line);
2813
	}
2826
	}
2814
 
2827
 
2815
	// write the package list
2828
	// write the package list
2816
	for ( CListNode<CBaseFile> *pn = m_lPackages.Front(); pn; pn = pn->next() )
2829
	for ( CListNode<CBaseFile> *pn = m_lPackages.Front(); pn; pn = pn->next() )
2817
	{
2830
	{
2818
		CBaseFile *package = pn->Data();
2831
		CBaseFile *package = pn->Data();
2819
 
2832
 
2820
		if ( package->GetType() == TYPE_SPK )
2833
		if ( package->GetType() == TYPE_SPK )
2821
			lines.PushBack("<script>");
2834
			lines.pushBack("<script>");
2822
		else if ( package->GetType() == TYPE_XSP )
2835
		else if ( package->GetType() == TYPE_XSP )
2823
			lines.PushBack("<ship>");
2836
			lines.pushBack("<ship>");
2824
		else if ( package->GetType() == TYPE_ARCHIVE )
2837
		else if ( package->GetType() == TYPE_ARCHIVE )
2825
			lines.PushBack("<archive>");
2838
			lines.pushBack("<archive>");
2826
		else if ( package->GetType() == TYPE_BASE )
2839
		else if ( package->GetType() == TYPE_BASE )
2827
			lines.PushBack("<base>");
2840
			lines.pushBack("<base>");
2828
		else
2841
		else
2829
			continue;
2842
			continue;
2830
 
2843
 
2831
		if ( !package->filename().empty() )
2844
		if ( !package->filename().empty() )
2832
			lines.PushBack(CyString("Installspk: ") + package->filename());
2845
			lines.pushBack("Installspk: " + package->filename());
2833
 
2846
 
2834
		CyString valuesline = package->CreateValuesLine();
2847
		Utils::String valuesline = package->CreateValuesLine();
2835
		if ( valuesline.Right(1) == '\n' )
2848
		if ( valuesline.back() == '\n')
2836
			valuesline.Truncate((int)valuesline.Length() - 1);
2849
			valuesline.truncate((int)valuesline.length() - 1);
2837
		lines.PushBack(valuesline);
2850
		lines.pushBack(valuesline);
2838
 
2851
 
2839
		if ( !package->IsEnabled() )
2852
		if ( !package->IsEnabled() )
2840
			lines.PushBack("Disabled");
2853
			lines.pushBack("Disabled");
2841
		if ( !package->IsModifiedEnabled() )
2854
		if ( !package->IsModifiedEnabled() )
2842
			lines.PushBack("ModifiedDisabled");
2855
			lines.pushBack("ModifiedDisabled");
2843
 
2856
 
2844
		if ( package->GetIcon() )
2857
		if ( package->GetIcon() )
2845
			lines.PushBack(CyString("Icon: ") + package->iconExt() + " " + package->GetIcon()->filePointer() );
2858
			lines.pushBack("Icon: " + package->iconExt() + " " + package->GetIcon()->filePointer() );
2846
 
2859
 
2847
		CyString fileline("Files:");
2860
		Utils::String fileline("Files:");
2848
		for ( CListNode<C_File> *fn = package->GetFileList()->Front(); fn; fn = fn->next() )
2861
		for ( CListNode<C_File> *fn = package->GetFileList()->Front(); fn; fn = fn->next() )
2849
		{
2862
		{
2850
			C_File *f = fn->Data();
2863
			C_File *f = fn->Data();
2851
			fileline += " ";
2864
			fileline += " ";
2852
			fileline += CyString::Number(f->GetPos());
2865
			fileline += Utils::String::Number(f->GetPos());
2853
		}
2866
		}
2854
		lines.PushBack(fileline);
2867
		lines.pushBack(fileline);
2855
	}
2868
	}
2856
 
2869
 
2857
	lines.PushBack("</scripts>");
2870
	lines.pushBack("</scripts>");
2858
 
2871
 
2859
	CFileIO datFile(m_sCurrentDir + "/PluginManager/PluginManager.new");
2872
	CFileIO datFile(m_sCurrentDir + "/PluginManager/PluginManager.new");
2860
 
2873
 
2861
	CDirIO Dir(m_sCurrentDir);
2874
	CDirIO Dir(m_sCurrentDir);
2862
	if ( !Dir.exists("PluginManager") ) {
2875
	if ( !Dir.exists("PluginManager") ) {
2863
		CLog::log(CLog::Log_IO, 2, "Creating PluginManager directory");
2876
		CLog::log(CLog::Log_IO, 2, "Creating PluginManager directory");
2864
 		Dir.Create("PluginManager");
2877
 		Dir.create("PluginManager");
2865
	}
2878
	}
2866
 
2879
 
2867
	CLog::log(CLog::Log_IO, 2, "Writing data file: " + m_sCurrentDir + "/PluginManager/PluginManager.new");
2880
	CLog::log(CLog::Log_IO, 2, "Writing data file: " + m_sCurrentDir + "/PluginManager/PluginManager.new");
2868
	if ( !datFile.WriteFile(&lines) )
2881
	if ( !datFile.writeFile(&lines) )
2869
	{
2882
	{
2870
		CLog::log(CLog::Log_IO, 1, "ERROR: Failed to write data file");
2883
		CLog::log(CLog::Log_IO, 1, "ERROR: Failed to write data file");
2871
	}
2884
	}
2872
	else {
2885
	else {
2873
		CLog::log(CLog::Log_IO, 2, "Removing old data file: " + m_sCurrentDir + "/PluginManager/PluginManager.dat");
2886
		CLog::log(CLog::Log_IO, 2, "Removing old data file: " + m_sCurrentDir + "/PluginManager/PluginManager.dat");
Line 2927... Line 2940...
2927
/**
2940
/**
2928
 * Add Log
2941
 * Add Log
2929
 *
2942
 *
2930
 * Adds a log entry to displayed at end
2943
 * Adds a log entry to displayed at end
2931
 */
2944
 */
2932
void CPackages::AddLogEntry(int type, CyString args, CyStringList *errors)
2945
void CPackages::AddLogEntry(int type, CyString args, CyStringList* errors)
2933
{
2946
{
2934
	if ( !errors )
2947
	if (!errors)
2935
		return;
2948
		return;
2936
 
2949
 
2937
	errors->PushBack(args, ERRORLOG_OLD(type));
2950
	errors->PushBack(args, ERRORLOG_OLD(type));
-
 
2951
}
-
 
2952
void CPackages::addLogEntry(int type, const Utils::String &args, Utils::CStringList *errors)
-
 
2953
{
-
 
2954
	if (!errors)
-
 
2955
		return;
-
 
2956
 
-
 
2957
	errors->pushBack(args, ERRORLOG(type));
2938
}
2958
}
2939
 
2959
 
2940
/**
2960
/**
2941
 * Enable a package
2961
 * Enable a package
2942
 *
2962
 *
Line 3023... Line 3043...
3023
		// fake patches are in the root, no need for directory
3043
		// fake patches are in the root, no need for directory
3024
		if ( !f->IsFakePatch() )
3044
		if ( !f->IsFakePatch() )
3025
		{
3045
		{
3026
			if ( !Dir.exists(f->getDirectory(package)) )
3046
			if ( !Dir.exists(f->getDirectory(package)) )
3027
			{
3047
			{
3028
				if ( !Dir.Create(f->getDirectory(package)) )
3048
				if ( !Dir.create(f->getDirectory(package)) )
3029
				{
3049
				{
3030
					this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, f->GetDirectory(package), errors);
3050
					this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, f->GetDirectory(package), errors);
3031
					continue;
3051
					continue;
3032
				}
3052
				}
3033
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, f->GetDirectory(package), errors);
3053
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, f->GetDirectory(package), errors);
Line 3167... Line 3187...
3167
			progress->UpdateProgress(++fileCount, maxFiles);
3187
			progress->UpdateProgress(++fileCount, maxFiles);
3168
			progress->UpdateFile(f);
3188
			progress->UpdateFile(f);
3169
		}
3189
		}
3170
 
3190
 
3171
		// only delete files that are not used by any other enabled packages, counter from UpdateUsedFiles()
3191
		// only delete files that are not used by any other enabled packages, counter from UpdateUsedFiles()
3172
		if ( f->GetUsed() || (f->IsShared() && !m_bDisableVanilla) )
3192
		if ( f->getUsed() || (f->IsShared() && !m_bDisableVanilla) )
3173
			continue;
3193
			continue;
3174
 
3194
 
3175
		// file is already disabled, no need to disable again
3195
		// file is already disabled, no need to disable again
3176
		if ( f->IsDisabled() )
3196
		if ( f->IsDisabled() )
3177
			continue;
3197
			continue;
Line 3199... Line 3219...
3199
				continue;
3219
				continue;
3200
		}
3220
		}
3201
 
3221
 
3202
		if ( f->GetFileType() == FILETYPE_MOD && !f->IsFakePatch() && f->CheckFileExt("cat") )
3222
		if ( f->GetFileType() == FILETYPE_MOD && !f->IsFakePatch() && f->CheckFileExt("cat") )
3203
		{
3223
		{
3204
			if ( f->GetBaseName().Compare(m_sSetMod) )
3224
			if ( f->baseName().Compare(m_sSetMod) )
3205
				m_sSetMod = NullString;
3225
				m_sSetMod = Utils::String::Null();
3206
		}
3226
		}
3207
 
3227
 
3208
		// file is not being used by any enabled package
3228
		// file is not being used by any enabled package
3209
		// set disabled and move to disabled directory
3229
		// set disabled and move to disabled directory
3210
		CDirIO Dir(m_sCurrentDir);
3230
		CDirIO Dir(m_sCurrentDir);
Line 3219... Line 3239...
3219
 
3239
 
3220
		// make sure the directory exists so we can move the file
3240
		// make sure the directory exists so we can move the file
3221
		if ( !Dir.exists(newFilename) )
3241
		if ( !Dir.exists(newFilename) )
3222
		{
3242
		{
3223
			// we couldn't create the directory for some reason, this is not good
3243
			// we couldn't create the directory for some reason, this is not good
3224
			if ( !Dir.Create(newFilename) )
3244
			if ( !Dir.create(newFilename) )
3225
			{
3245
			{
3226
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, newFilename, errors);
3246
				this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY_FAIL, newFilename, errors);
3227
				continue;
3247
				continue;
3228
			}
3248
			}
3229
			this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, newFilename, errors);
3249
			this->AddLogEntry(SPKINSTALL_CREATEDIRECTORY, newFilename, errors);
Line 3365... Line 3385...
3365
 *
3385
 *
3366
 * Finds a matching package so we can find if one is already installed
3386
 * Finds a matching package so we can find if one is already installed
3367
 *
3387
 *
3368
 * Uses seperate functions for each package type, ie for SPK and XSP packages
3388
 * Uses seperate functions for each package type, ie for SPK and XSP packages
3369
 */
3389
 */
3370
CBaseFile *CPackages::FindPackage(CBaseFile *package)
3390
CBaseFile* CPackages::FindPackage(CBaseFile* package)
3371
{
3391
{
3372
	// no point checking if we've been sent a null pointer
3392
	// no point checking if we've been sent a null pointer
3373
	if ( !package )
3393
	if ( !package )
3374
		return 0;
3394
		return 0;
3375
 
3395
 
Line 3481... Line 3501...
3481
 
3501
 
3482
	// nothing found
3502
	// nothing found
3483
	return 0;
3503
	return 0;
3484
}
3504
}
3485
 
3505
 
3486
CBaseFile *CPackages::FindPackage(CyString name, CyString author)
3506
CBaseFile* CPackages::findPackage(const Utils::String &name, const Utils::String &author) const
3487
{
3507
{
3488
	// interate through all packages
3508
	// interate through all packages
3489
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3509
	for (CListNode<CBaseFile>* node = m_lPackages.Front(); node; node = node->next())
3490
	{
3510
	{
3491
		CBaseFile *file = node->Data();
3511
		CBaseFile* file = node->Data();
3492
 
3512
 
3493
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3513
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3494
		if ( file->name().Compare(name.ToString()) &amp;&amp; file->author().Compare(author.ToString()) )
3514
		if (file->name().Compare(name) &amp;&amp; file->author().Compare(author))
3495
			return file;
3515
			return file;
3496
	}
3516
	}
3497
 
3517
 
3498
	// nothing found
3518
	// nothing found
3499
	return 0;
3519
	return 0;
-
 
3520
}
-
 
3521
CBaseFile* CPackages::FindPackage(CyString name, CyString author)
-
 
3522
{
-
 
3523
	return findPackage(name.ToString(), author.ToString());
3500
}
3524
}
3501
 
3525
 
3502
/**
3526
/**
3503
 * Find a XSP Package
3527
 * Find a XSP Package
3504
 *
3528
 *
3505
 * This searching all installed packages for a XSP Package matching the object id
3529
 * This searching all installed packages for a XSP Package matching the object id
3506
 */
3530
 */
3507
CBaseFile *CPackages::FindXspPackage(CyString id)
3531
CBaseFile *CPackages::FindXspPackage(CyString id)
Line 3520... Line 3544...
3520
			return file;
3544
			return file;
3521
	}
3545
	}
3522
 
3546
 
3523
	// nothing found
3547
	// nothing found
3524
	return 0;
3548
	return 0;
3525
}
3549
}
3526
 
3550
 
3527
/**
3551
/**
3528
 * Update the used files count
3552
 * Update the used files count
3529
 *
3553
 *
3530
 * counts how many packages are currently using the file
3554
 * counts how many packages are currently using the file
3531
 */
3555
 */
3532
void CPackages::UpdateUsedFiles(CLinkList<CBaseFile> *ignoreList, bool includedisabled)
3556
void CPackages::UpdateUsedFiles(CLinkList<CBaseFile> *ignoreList, bool includedisabled)
3533
{
3557
{
3534
	// clear amounts for all files
3558
	// clear amounts for all files
3535
	CListNode<C_File> *fnode = m_lFiles.Front();
3559
	CListNode<C_File> *fnode = m_lFiles.Front();
3536
	while ( fnode )
3560
	while ( fnode )
3537
	{
3561
	{
3538
		fnode->Data()->ClearUsed();
3562
		fnode->Data()->clearUsed();
3539
		fnode = fnode->next();
3563
		fnode = fnode->next();
3540
	}
3564
	}
3541
 
3565
 
3542
	// update for all packages
3566
	// update for all packages
3543
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node= node->next() )
3567
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node= node->next() )
3544
	{
3568
	{
3545
		CBaseFile *file = node->Data();
3569
		CBaseFile *file = node->Data();
3546
		if ( (ignoreList) && (ignoreList->FindData(file)) )
3570
		if ( (ignoreList) && (ignoreList->FindData(file)) )
Line 3549... Line 3573...
3549
			continue;
3573
			continue;
3550
		// now mark all files
3574
		// now mark all files
3551
		CListNode<C_File> *fnode = file->GetFileList()->Front();
3575
		CListNode<C_File> *fnode = file->GetFileList()->Front();
3552
		while ( fnode )
3576
		while ( fnode )
3553
		{
3577
		{
3554
			fnode->Data()->IncUsed();
3578
			fnode->Data()->incUsed();
3555
			fnode = fnode->next();
3579
			fnode = fnode->next();
3556
		}
3580
		}
3557
	}
3581
	}
3558
}
3582
}
3559
 
3583
 
3560
/**
3584
/**
3561
 * Removes all empty directories that might have been created
3585
 * Removes all empty directories that might have been created
3562
 */
3586
 */
3563
void CPackages::RemoveUnusedDirectories(CyStringList &dirs, CyStringList *errors)
3587
void CPackages::RemoveUnusedDirectories(CyStringList& dirs, CyStringList* errors)
3564
{
3588
{
3565
	CDirIO Dir(m_sCurrentDir);
3589
	CDirIO Dir(m_sCurrentDir);
3566
	for ( SStringList *str = dirs.Head(); str; str = str->next )
3590
	for (SStringList* str = dirs.Head(); str; str = str->next)
3567
	{
3591
	{
3568
		CyString dir = str->str;
3592
		CyString dir = str->str;
3569
 
3593
 
3570
		CyStringList removedDir;
3594
		CyStringList removedDir;
3571
		if ( Dir.RemoveDir(dir, false, true, &removedDir) || !removedDir.Empty() )
3595
		if (Dir.RemoveDir(dir, false, true, &removedDir) || !removedDir.Empty())
3572
		{
3596
		{
3573
			for ( SStringList *node = removedDir.Head(); node; node = node->next )
3597
			for (SStringList* node = removedDir.Head(); node; node = node->next)
3574
			{
3598
			{
3575
				CyString displayName = node->str;
3599
				CyString displayName = node->str;
3576
				displayName = displayName.Remove(m_sCurrentDir);
3600
				displayName = displayName.Remove(m_sCurrentDir);
3577
				this->AddLogEntry(SPKINSTALL_REMOVEDIR, displayName, errors);
3601
				this->AddLogEntry(SPKINSTALL_REMOVEDIR, displayName, errors);
-
 
3602
			}
-
 
3603
		}
-
 
3604
	}
-
 
3605
}
-
 
3606
void CPackages::removeUnusedDirectories(const Utils::CStringList& dirs, Utils::CStringList* errors)
-
 
3607
{
-
 
3608
	CDirIO Dir(m_sCurrentDir);
-
 
3609
	for(auto itr = dirs.begin(); itr != dirs.end(); itr++)
-
 
3610
	{
-
 
3611
		Utils::String dir = (*itr)->str;
-
 
3612
 
-
 
3613
		Utils::CStringList removedDir;
-
 
3614
		if (Dir.removeDir(dir, false, true, &removedDir) || !removedDir.empty())
-
 
3615
		{
-
 
3616
			for(auto rItr = removedDir.begin(); rItr != removedDir.end(); rItr++)
-
 
3617
			{
-
 
3618
				Utils::String displayName = (*rItr)->str;
-
 
3619
				displayName = displayName.findRemove(m_sCurrentDir);
-
 
3620
				this->addLogEntry(SPKINSTALL_REMOVEDIR, displayName, errors);
3578
			}
3621
			}
3579
		}
3622
		}
3580
	}
3623
	}
3581
}
3624
}
3582
 
3625
 
Line 3590... Line 3633...
3590
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3633
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3591
	{
3634
	{
3592
		CBaseFile *p = node->Data();
3635
		CBaseFile *p = node->Data();
3593
 
3636
 
3594
		if ( p->GetType() != TYPE_SPK )
3637
		if ( p->GetType() != TYPE_SPK )
3595
			continue;
3638
			continue;
3596
 
3639
 
3597
		((CSpkFile *)p)->UpdateSigned(false);
3640
		((CSpkFile *)p)->UpdateSigned(false);
3598
	}
3641
	}
3599
}
3642
}
3600
 
3643
 
3601
/**
3644
/**
Line 3663... Line 3706...
3663
						break;
3706
						break;
3664
					}
3707
					}
3665
				}
3708
				}
3666
 
3709
 
3667
				if ( !found )
3710
				if ( !found )
3668
					return false;
3711
					return false;
3669
			}
3712
			}
3670
		}
3713
		}
3671
	}
3714
	}
3672
 
3715
 
3673
	return true;
3716
	return true;
3674
}
3717
}
3675
 
3718
 
3676
bool CPackages::CheckEnabledDependacy(CBaseFile *p)
3719
bool CPackages::CheckEnabledDependacy(CBaseFile *p)
Line 3691... Line 3734...
3691
		}
3734
		}
3692
	}
3735
	}
3693
 
3736
 
3694
	// check any dependacies
3737
	// check any dependacies
3695
	if ( p->AnyDependacies() )
3738
	if ( p->AnyDependacies() )
3696
	{
3739
	{
3697
		for ( CListNode<SNeededLibrary> *dNode = p->GetNeededLibraries()->Front(); dNode; dNode = dNode->next() )
3740
		for ( CListNode<SNeededLibrary> *dNode = p->GetNeededLibraries()->Front(); dNode; dNode = dNode->next() )
3698
		{
3741
		{
3699
			if ( dNode->Data()->sName.Compare("<package>") )
3742
			if ( dNode->Data()->sName.Compare("<package>") )
3700
				continue;
3743
				continue;
3701
			if ( !this->CheckInstalledDependacy(dNode->Data()->sName, dNode->Data()->sAuthor, dNode->Data()->sMinVersion, true, true) )
3744
			if ( !this->CheckInstalledDependacy(dNode->Data()->sName, dNode->Data()->sAuthor, dNode->Data()->sMinVersion, true, true) )
Line 3887... Line 3930...
3887
					{
3930
					{
3888
						CBaseFile *checkP = pNode->Data();
3931
						CBaseFile *checkP = pNode->Data();
3889
						if ( p->author().Compare(checkP->author()) && p->name().Compare(checkP->name()) )
3932
						if ( p->author().Compare(checkP->author()) && p->name().Compare(checkP->name()) )
3890
						{
3933
						{
3891
							found = true;
3934
							found = true;
3892
							break;
3935
							break;
3893
						}
3936
						}
3894
					}
3937
					}
3895
				}
3938
				}
3896
				else
3939
				else
3897
					found = false;
3940
					found = false;
3898
			}
3941
			}
3899
 
3942
 
3900
			if ( !found )
3943
			if ( !found )
3901
			{
3944
			{
3902
				if ( list )
3945
				if ( list )
3903
					list->pushBack(spk->GetOtherName(), spk->GetOtherAuthor());
3946
					list->pushBack(spk->GetOtherName(), spk->GetOtherAuthor());
3904
				++count;
3947
				++count;
3905
			}
3948
			}
3906
		}
3949
		}
3907
	}
3950
	}
3908
 
3951
 
3909
	return count;
3952
	return count;
3910
}
3953
}
3911
 
3954
 
3912
int CPackages::CheckPreparedInstallRequired(CLinkList<CBaseFile> *list)
3955
int CPackages::CheckPreparedInstallRequired(CLinkList<CBaseFile> *list)
3913
{
3956
{
3914
	// loop through all packages
3957
	// loop through all packages
Line 3938... Line 3981...
3938
	}
3981
	}
3939
 
3982
 
3940
	m_lInstallList.RemoveEmpty();
3983
	m_lInstallList.RemoveEmpty();
3941
 
3984
 
3942
	return count;
3985
	return count;
3943
}
3986
}
3944
 
3987
 
3945
 
3988
 
3946
/**
3989
/**
3947
 * Remove uninstall file
3990
 * Remove uninstall file
3948
 *
3991
 *
3949
 * Removes a single uninstall file
3992
 * Removes a single uninstall file
3950
 */
3993
 */
3951
bool CPackages::RemoveUninstallFile(C_File *file, CyStringList *errors)
3994
bool CPackages::RemoveUninstallFile(C_File *file, CyStringList *errors)
Line 3991... Line 4034...
3991
		for ( CListNode<C_File> *fNode = m_lFiles.Front(); fNode; fNode = fNode->next() )
4034
		for ( CListNode<C_File> *fNode = m_lFiles.Front(); fNode; fNode = fNode->next() )
3992
		{
4035
		{
3993
			C_File *checkFile = fNode->Data();
4036
			C_File *checkFile = fNode->Data();
3994
			if ( checkFile->GetFileType() != FILETYPE_SCRIPT )
4037
			if ( checkFile->GetFileType() != FILETYPE_SCRIPT )
3995
				continue;
4038
				continue;
3996
 
4039
 
3997
			if ( checkFile->filename().Compare(file->filename()) )
4040
			if ( checkFile->filename().Compare(file->filename()) )
3998
			{
4041
			{
3999
				found = true;
4042
				found = true;
4000
				break;
4043
				break;
4001
			}
4044
			}
Line 4004... Line 4047...
4004
		// not found a matching file, we can safetly remove it
4047
		// not found a matching file, we can safetly remove it
4005
		if ( !found )
4048
		if ( !found )
4006
		{
4049
		{
4007
			if ( RemoveUninstallFile(file) )
4050
			if ( RemoveUninstallFile(file) )
4008
				node->DeleteData();
4051
				node->DeleteData();
4009
		}
4052
		}
4010
	}
4053
	}
4011
 
4054
 
4012
	m_lUninstallFiles.RemoveEmpty();
4055
	m_lUninstallFiles.RemoveEmpty();
4013
 
4056
 
4014
	return files;
4057
	return files;
Line 4054... Line 4097...
4054
	for ( CListNode<C_File> *node = m_lFiles.Back(); node; node = node->prev() )
4097
	for ( CListNode<C_File> *node = m_lFiles.Back(); node; node = node->prev() )
4055
	{
4098
	{
4056
		if ( progress )
4099
		if ( progress )
4057
			progress->UpdateProgress(files, m_lFiles.size());
4100
			progress->UpdateProgress(files, m_lFiles.size());
4058
		files++;
4101
		files++;
4059
 
4102
 
4060
		C_File *file = node->Data();
4103
		C_File *file = node->Data();
4061
 
4104
 
4062
		// only do marked shared files
4105
		// only do marked shared files
4063
		if ( !file->IsShared() )
4106
		if ( !file->IsShared() )
4064
			continue;
4107
			continue;
4065
 
4108
 
4066
		// only do ones that are no longer needed
4109
		// only do ones that are no longer needed
4067
		if ( file->GetUsed() )
4110
		if ( file->getUsed() )
4068
			continue;
4111
			continue;
4069
 
4112
 
4070
		if ( RemoveSharedFile(file, errors) )
4113
		if ( RemoveSharedFile(file, errors) )
4071
			++done;
4114
			++done;
4072
		node->ChangeData(NULL);
4115
		node->ChangeData(NULL);
Line 4092... Line 4135...
4092
	{
4135
	{
4093
		C_File *file = node->Data();
4136
		C_File *file = node->Data();
4094
 
4137
 
4095
		// only do marked shared files
4138
		// only do marked shared files
4096
		if ( !file->IsShared() )
4139
		if ( !file->IsShared() )
4097
			continue;
4140
			continue;
4098
 
4141
 
4099
		// only do ones that are no longer needed
4142
		// only do ones that are no longer needed
4100
		if ( file->GetUsed() )
4143
		if ( file->getUsed() )
4101
			continue;
4144
			continue;
4102
 
4145
 
4103
		return true;
4146
		return true;
4104
	}
4147
	}
4105
 
4148
 
4106
	return false;
4149
	return false;
4107
 
4150
 
4108
}
4151
}
4109
 
4152
 
4110
void CPackages::ShuffleTextFiles(CyStringList *errors)
4153
void CPackages::ShuffleTextFiles(CyStringList *errors)
4111
{
4154
{
4112
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4155
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4113
	{
4156
	{
4114
		C_File *f = node->Data();
4157
		C_File *f = node->Data();
Line 4124... Line 4167...
4124
			continue;
4167
			continue;
4125
 
4168
 
4126
		// we need to rename it
4169
		// we need to rename it
4127
		int current = findNextTextFile();
4170
		int current = findNextTextFile();
4128
		if ( current < f->GetTextFileID() )
4171
		if ( current < f->GetTextFileID() )
4129
		{
4172
		{
4130
			CFileIO moveFile(f->filePointer());
4173
			CFileIO moveFile(f->filePointer());
4131
	
4174
	
4132
			Utils::String newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + "." + moveFile.extension();
4175
			Utils::String newName = SPK::FormatTextName(current, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT)) + "." + moveFile.extension();
4133
			if ( moveFile.Rename(m_sCurrentDir + "/t/" + newName) )
4176
			if ( moveFile.Rename(m_sCurrentDir + "/t/" + newName) )
4134
			{
4177
			{
Line 4155... Line 4198...
4155
	// lets make sure our order is correct
4198
	// lets make sure our order is correct
4156
	// find Lowest Fake Patch Installed
4199
	// find Lowest Fake Patch Installed
4157
	CLinkList<C_File> doneList;
4200
	CLinkList<C_File> doneList;
4158
	int lowest = FindLowestFakePatchInstalled();
4201
	int lowest = FindLowestFakePatchInstalled();
4159
	if ( check < lowest ) lowest = check; // gap at the beginning, lets use that
4202
	if ( check < lowest ) lowest = check; // gap at the beginning, lets use that
-
 
4203
 
-
 
4204
	// find all packages that need to go before or after other packages
-
 
4205
	std::set<CBaseFile*> packagesBefore;
-
 
4206
	std::map<CBaseFile*, std::set<CBaseFile*>> packagesAfter;
-
 
4207
	for (CListNode<CBaseFile>* pNode = m_lPackages.Front(); pNode; pNode = pNode->next())
-
 
4208
	{
-
 
4209
		CBaseFile* p = pNode->Data();
-
 
4210
		// search for any fake patches in package
-
 
4211
		if (!p->IsEnabled()) continue;
-
 
4212
		if (!p->AnyFileType(FILETYPE_MOD)) continue;
-
 
4213
 
-
 
4214
		if (p->AnyDependacies())
-
 
4215
		{
-
 
4216
			for (SNeededLibrary* nl = p->GetNeededLibraries()->First(); nl; nl = p->GetNeededLibraries()->Next())
-
 
4217
			{
-
 
4218
				auto package = FindPackage(nl->sName, nl->sAuthor);
-
 
4219
				if (package)
-
 
4220
				{
-
 
4221
					packagesBefore.insert(package);
-
 
4222
					packagesAfter[p].insert(package);
-
 
4223
				}
-
 
4224
			}
-
 
4225
		}
-
 
4226
		CSpkFile* spk = dynamic_cast<CSpkFile*>(p);
-
 
4227
		if (spk)
-
 
4228
		{
-
 
4229
			if (spk->IsAnotherMod())
-
 
4230
			{
-
 
4231
				auto package = FindPackage(spk->otherName(), spk->otherAuthor());
-
 
4232
				if (package)
-
 
4233
				{
-
 
4234
					packagesBefore.insert(package);
-
 
4235
					packagesAfter[p].insert(package);
-
 
4236
				}
-
 
4237
			}
-
 
4238
		}
-
 
4239
 
-
 
4240
		if (!p->getFakePatchBeforeOrder().empty())
-
 
4241
		{
-
 
4242
			packagesBefore.insert(p);
-
 
4243
			auto& list = p->getFakePatchBeforeOrder();
-
 
4244
			for (auto itr = list.begin(); itr != list.end(); itr++)
-
 
4245
			{
-
 
4246
				auto package = FindPackage((*itr)->str, (*itr)->data);
-
 
4247
				if (package)				
-
 
4248
					packagesAfter[package].insert(p);
-
 
4249
			}
-
 
4250
		}
-
 
4251
		if (!p->getFakePatchAfterOrder().empty())
-
 
4252
		{
-
 
4253
			auto& list = p->getFakePatchAfterOrder();
-
 
4254
			for (auto itr = list.begin(); itr != list.end(); itr++)
-
 
4255
			{
-
 
4256
				auto package = FindPackage((*itr)->str, (*itr)->data);
-
 
4257
				if (package)
-
 
4258
				{
-
 
4259
					packagesBefore.insert(package);
-
 
4260
					packagesAfter[p].insert(package);
-
 
4261
				}
-
 
4262
			}
-
 
4263
		}
-
 
4264
	}
-
 
4265
 
-
 
4266
	auto addOrderedList = [](const std::vector<CBaseFile*>& addList, const Utils::CStringList& orderList, std::vector<CBaseFile*>& addTo, const CPackages *packages)
-
 
4267
	{
-
 
4268
		// add all the items in the ordered list first
-
 
4269
		for (auto itr = orderList.begin(); itr != orderList.end(); itr++)
-
 
4270
		{
-
 
4271
			auto p = packages->findPackage((*itr)->str, (*itr)->data);
-
 
4272
			if (p)
-
 
4273
			{
-
 
4274
				auto findItr = std::find(addList.begin(), addList.end(), p);
-
 
4275
				if (findItr != addList.end())
-
 
4276
				{
-
 
4277
					auto checkItr = std::find(addTo.begin(), addTo.end(), p);
-
 
4278
					if(checkItr == addTo.end())
-
 
4279
						addTo.push_back(p);
-
 
4280
				}
-
 
4281
			}
-
 
4282
		}
-
 
4283
 
-
 
4284
		// now add all the others
-
 
4285
		for (auto itr = addList.begin(); itr != addList.end(); itr++)
-
 
4286
		{
-
 
4287
			auto checkItr = std::find(addTo.begin(), addTo.end(), *itr);
-
 
4288
			if (checkItr == addTo.end())
-
 
4289
				addTo.push_back(*itr);
-
 
4290
		}
-
 
4291
	};
-
 
4292
 
-
 
4293
	auto removeList = [](const std::vector<CBaseFile*>& removeList, std::set<CBaseFile*>& list)
-
 
4294
	{
-
 
4295
		for (auto itr = removeList.begin(); itr != removeList.end(); itr++)
-
 
4296
		{
-
 
4297
			auto findItr = std::find(list.begin(), list.end(), *itr);
-
 
4298
			if (findItr != list.end())
-
 
4299
				list.erase(findItr);
-
 
4300
		}
-
 
4301
	};
-
 
4302
 
-
 
4303
	std::vector<CBaseFile*> order;
-
 
4304
	while (!packagesBefore.empty())
-
 
4305
	{
-
 
4306
		std::vector<CBaseFile*> packagesOrder;
-
 
4307
 
-
 
4308
		// all packages that go before, but not after should go first
-
 
4309
		for (auto itr = packagesBefore.begin(); itr != packagesBefore.end(); itr++)
-
 
4310
		{
-
 
4311
			CBaseFile* p = *itr;
-
 
4312
			auto findItr = packagesAfter.find(p);
-
 
4313
			if (findItr == packagesAfter.end())
-
 
4314
				packagesOrder.push_back(p);
-
 
4315
			else
-
 
4316
			{
-
 
4317
				// check if any packages that we go after have been added
-
 
4318
				bool notAdded = false;
-
 
4319
				for (auto checkItr = findItr->second.begin(); checkItr != findItr->second.end(); checkItr++)
-
 
4320
				{
-
 
4321
					auto findItr2 = std::find(order.begin(), order.end(), *checkItr);
-
 
4322
					if (findItr2 == order.end())
-
 
4323
					{
-
 
4324
						notAdded = true;
-
 
4325
						break;
-
 
4326
					}
-
 
4327
				}
-
 
4328
 
-
 
4329
				if (!notAdded)
-
 
4330
					packagesOrder.push_back(p);
-
 
4331
			}
-
 
4332
		}
-
 
4333
 
-
 
4334
 
-
 
4335
		// no valid packages left ? lets just add the rest
-
 
4336
		if (packagesOrder.empty())
-
 
4337
		{
-
 
4338
			for (auto itr = packagesBefore.begin(); itr != packagesBefore.end(); itr++)
-
 
4339
				packagesOrder.push_back(*itr);
-
 
4340
		}
-
 
4341
 
-
 
4342
		addOrderedList(packagesOrder, m_lFakePatchOrder, order, this);
-
 
4343
		removeList(packagesOrder, packagesBefore);
-
 
4344
	}
4160
 
4345
 
-
 
4346
	// now add the remaining list ordered list
-
 
4347
	for (auto itr = m_lFakePatchOrder.begin(); itr != m_lFakePatchOrder.end(); itr++)
-
 
4348
	{
-
 
4349
		auto p = findPackage((*itr)->str, (*itr)->data);
-
 
4350
		if (p)
-
 
4351
		{
-
 
4352
			auto findItr = std::find(order.begin(), order.end(), p);
-
 
4353
			if (findItr == order.end())
-
 
4354
				order.push_back(p);
-
 
4355
		}
-
 
4356
	}
-
 
4357
 
-
 
4358
	/*
4161
	// lets define the order
4359
	// lets define the order
4162
	CyStringList fakePatchOrder;
-
 
4163
	for ( SStringList *str = m_lFakePatchOrder.Head(); str; str = str->next )
-
 
4164
		fakePatchOrder.PushBack(str->str, str->data);
-
 
4165
 
4360
 
4166
	// add any other packages that need to be ordered
4361
	// add any other packages that need to be ordered
4167
	// we need to work out the correct order
4362
	// we need to work out the correct order
4168
	CLinkList<CBaseFile> packages;
4363
	CLinkList<CBaseFile> packages;
4169
	for ( CListNode<CBaseFile> *pNode = m_lPackages.Front(); pNode; pNode = pNode->next() )
4364
	for ( CListNode<CBaseFile> *pNode = m_lPackages.Front(); pNode; pNode = pNode->next() )
Line 4171... Line 4366...
4171
		CBaseFile *p = pNode->Data();
4366
		CBaseFile *p = pNode->Data();
4172
		// search for any fake patches in package
4367
		// search for any fake patches in package
4173
		if ( !p->IsEnabled() ) continue;
4368
		if ( !p->IsEnabled() ) continue;
4174
		if ( !p->AnyFileType(FILETYPE_MOD) ) continue;
4369
		if ( !p->AnyFileType(FILETYPE_MOD) ) continue;
4175
 
4370
 
-
 
4371
		int existingPos = fakePatchOrder.findStringAndData(p->name(), p->author());
-
 
4372
 
4176
		// must have an order define
4373
		if (p->AnyDependacies())
-
 
4374
		{
-
 
4375
			for (SNeededLibrary* nl = p->GetNeededLibraries()->First(); nl; nl = p->GetNeededLibraries()->Next())
-
 
4376
			{
-
 
4377
				int findPos = fakePatchOrder.findStringAndData(nl->sName, nl->sAuthor);
-
 
4378
				if (existingPos == -1)
-
 
4379
					fakePatchOrder.pushBack(nl->sName, nl->sAuthor);
-
 
4380
				else if (findPos == -1)
-
 
4381
					fakePatchOrder.insertAt(existingPos, nl->sName, nl->sAuthor);
-
 
4382
				else if (findPos > existingPos)
-
 
4383
				{
4177
		if ( !p->AnyFakePatchOrder() ) continue;
4384
					fakePatchOrder.removeAt(findPos);
-
 
4385
					fakePatchOrder.insertAt(existingPos, nl->sName, nl->sAuthor);
-
 
4386
				}
-
 
4387
			}
-
 
4388
		}
4178
 
4389
 
4179
		// check if theres any already ordered (manual)
4390
		CSpkFile* spk = dynamic_cast<CSpkFile*>(p);
4180
		bool added = false;
4391
		if (spk)
4181
		for ( SStringList *sCheck = fakePatchOrder.Head(); sCheck; sCheck = sCheck->next )
-
 
4182
		{
4392
		{
4183
			if ( sCheck->str.Compare(CyString(p->name())) && sCheck->data.Compare(CyString(p->author())) )
4393
			if (spk->IsAnotherMod())
4184
			{
4394
			{
-
 
4395
				int findPos = fakePatchOrder.findStringAndData(spk->otherName(), spk->otherAuthor());
-
 
4396
				if (existingPos == -1)
-
 
4397
					fakePatchOrder.pushBack(spk->otherName(), spk->otherAuthor());
4185
				added = true;
4398
				else if (findPos == -1)
-
 
4399
					fakePatchOrder.insertAt(existingPos, spk->otherName(), spk->otherAuthor());
-
 
4400
				else if (findPos > existingPos)
-
 
4401
				{
-
 
4402
					fakePatchOrder.removeAt(findPos);
-
 
4403
					fakePatchOrder.insertAt(existingPos, spk->otherName(), spk->otherAuthor());
4186
				break;
4404
				}				
4187
			}
4405
			}
4188
		}
4406
		}
4189
 
4407
 
-
 
4408
		// must have an order define
-
 
4409
		if (!p->anyFakePatchOrder())
-
 
4410
			continue;
-
 
4411
 
-
 
4412
		if (fakePatchOrder.findStringAndData(p->name(), p->author()) != -1)
4190
		if ( added ) continue;
4413
			continue;
4191
 
4414
 
4192
		bool anyFound = false;
4415
		bool anyFound = false;
4193
		for ( C_File *file = p->GetFirstFile(FILETYPE_MOD); file; file = p->GetNextFile(file) )
4416
		for ( C_File *file = p->GetFirstFile(FILETYPE_MOD); file; file = p->GetNextFile(file) )
4194
		{
4417
		{
4195
			if ( !file->IsFakePatch() ) continue;
4418
			if ( !file->IsFakePatch() ) continue;
Line 4212... Line 4435...
4212
		// first add all the packages that dont need to be installed after
4435
		// first add all the packages that dont need to be installed after
4213
		for ( CListNode<CBaseFile> *pNode = packages.Front(); pNode; pNode = pNode->next() )
4436
		for ( CListNode<CBaseFile> *pNode = packages.Front(); pNode; pNode = pNode->next() )
4214
		{
4437
		{
4215
			CBaseFile *p = pNode->Data();
4438
			CBaseFile *p = pNode->Data();
4216
			// we have a before and not after
4439
			// we have a before and not after
4217
			if ( !p->GetFakePatchBeforeOrder().Empty() && p->GetFakePatchAfterOrder().Empty() )
4440
			if ( !p->getFakePatchBeforeOrder().empty() && p->getFakePatchAfterOrder().empty() )
4218
			{
4441
			{
4219
				// if we have to install before, check if any on the list
4442
				// if we have to install before, check if any on the list
4220
				int earliestPos = -1;
4443
				int earliestPos = -1;
4221
				bool notAdded = true;
4444
				bool notAdded = true;
4222
				for ( SStringList *str = p->GetFakePatchBeforeOrder().Head(); str; str = str->next )
4445
				auto& list = p->getFakePatchBeforeOrder();
-
 
4446
				for(auto itr = list.begin(); itr != list.end(); itr++)
4223
				{
4447
				{
4224
					int pos = 0;
4448
					int pos = 0;
4225
					for ( CListNode<CBaseFile> *sNode = sortedPackages.Front(); sNode; sNode = sNode->next() )
4449
					for ( CListNode<CBaseFile> *sNode = sortedPackages.Front(); sNode; sNode = sNode->next() )
4226
					{
4450
					{
4227
						if ( str->str.Compare(CyString(sNode->Data()-&gt;name())) &;&; str->data.Compare(CyString(sNode->Data()->author())) )
4451
						if ((*itr)->str.Compare(sNode->Data()->name()) &amp;&; (*itr)->data.Compare(sNode->Data()->author()) )
4228
						{
4452
						{
4229
							if ( earliestPos == -1 || pos < earliestPos )
4453
							if ( earliestPos == -1 || pos < earliestPos )
4230
								earliestPos = pos;
4454
								earliestPos = pos;
4231
							break;
4455
							break;
4232
						}
4456
						}
Line 4248... Line 4472...
4248
		// now do the packages that have both before and after
4472
		// now do the packages that have both before and after
4249
		packages.RemoveEmpty();
4473
		packages.RemoveEmpty();
4250
		for ( CListNode<CBaseFile> *pNode = packages.Front(); pNode; pNode = pNode->next() )
4474
		for ( CListNode<CBaseFile> *pNode = packages.Front(); pNode; pNode = pNode->next() )
4251
		{
4475
		{
4252
			CBaseFile *p = pNode->Data();
4476
			CBaseFile *p = pNode->Data();
4253
			if ( !p->GetFakePatchBeforeOrder().Empty() && !p->GetFakePatchAfterOrder().Empty() )
4477
			if ( !p->getFakePatchBeforeOrder().empty() && !p->getFakePatchAfterOrder().empty() )
4254
			{
4478
			{
4255
			}
4479
			}
4256
		}
4480
		}
4257
 
4481
 
4258
		// add them onto the list
4482
		// add them onto the list
4259
		for ( CListNode<CBaseFile> *pNode = sortedPackages.Front(); pNode; pNode = pNode->next() )
4483
		for ( CListNode<CBaseFile> *pNode = sortedPackages.Front(); pNode; pNode = pNode->next() )
4260
			fakePatchOrder.PushBack(CyString(pNode->Data()->name()), CyString(pNode-&gt;Data()->author()));
4484
			fakePatchOrder.pushBack(pNode->Data()->name(), pNode-&gt;Data()->author());
4261
	}
4485
	}
4262
 
4486
 
4263
	// now add to do list
4487
	// now add to do list
4264
	for ( CListNode<CBaseFile> *pNode = packages.Front(); pNode; pNode = pNode->next() )
4488
	for ( CListNode<CBaseFile> *pNode = packages.Front(); pNode; pNode = pNode->next() )
4265
		fakePatchOrder.PushBack(CyString(pNode->Data()->name()), CyString(pNode-&gt;Data()->author()));
4489
		fakePatchOrder.pushBack(pNode->Data()->name(), pNode-&gt;Data()->author());
4266
 
4490
		*/
4267
	for ( SStringList *str = fakePatchOrder.Head(); str; str = str->;next )
4491
	for(auto itr = order.begin(); itr != order.end(); itr++)
4268
	{
4492
	{
4269
		CBaseFile *package = FindPackage(str->str, str->data);
4493
		CBaseFile *package = *itr;
4270
		if ( package )
4494
		if ( package )
4271
		{
4495
		{
4272
			// might have more than 1 fake patch for the file, so we'll need the lowest
4496
			// might have more than 1 fake patch for the file, so we'll need the lowest
4273
			while ( true )
4497
			while ( true )
4274
			{
4498
			{
Line 4310... Line 4534...
4310
						ShufflePatchTo(moveFile, FindLastFakePatch(), errors);
4534
						ShufflePatchTo(moveFile, FindLastFakePatch(), errors);
4311
					}
4535
					}
4312
 
4536
 
4313
					// space should be free, now lets shuffle it
4537
					// space should be free, now lets shuffle it
4314
					ShufflePatchTo(lowestFile, lowest, errors);
4538
					ShufflePatchTo(lowestFile, lowest, errors);
4315
				}
4539
				}
4316
 
4540
 
4317
				doneList.push_back(lowestFile); // we've done this file now
4541
				doneList.push_back(lowestFile); // we've done this file now
4318
				lowest++; // move up the lowest ready for the next patch
4542
				lowest++; // move up the lowest ready for the next patch
4319
			}
4543
			}
4320
		}
4544
		}
4321
	}
4545
	}
Line 4337... Line 4561...
4337
		if ( !f->IsFakePatch() )
4561
		if ( !f->IsFakePatch() )
4338
			continue;
4562
			continue;
4339
 
4563
 
4340
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4564
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4341
		if ( !f->CheckFileExt("cat") )
4565
		if ( !f->CheckFileExt("cat") )
4342
			continue;
4566
			continue;
4343
 
4567
 
4344
		// now lets check if its greater than our gap
4568
		// now lets check if its greater than our gap
4345
		int check = FindNextFakePatch();
4569
		int check = FindNextFakePatch();
4346
		int patchNum = f->filename().token(".", 1).toInt();
4570
		int patchNum = f->filename().token(".", 1).toInt();
4347
		if ( patchNum <= check )
4571
		if ( patchNum <= check )
Line 4392... Line 4616...
4392
	else
4616
	else
4393
		this->AddLogEntry(SPKINSTALL_FAKEPATCH_FAIL, file->name() + "~" + newName, errors);
4617
		this->AddLogEntry(SPKINSTALL_FAKEPATCH_FAIL, file->name() + "~" + newName, errors);
4394
}
4618
}
4395
 
4619
 
4396
int CPackages::FindLowestFakePatchInstalled()
4620
int CPackages::FindLowestFakePatchInstalled()
4397
{
4621
{
4398
	int lowest = 99;
4622
	int lowest = 99;
4399
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4623
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4400
	{
4624
	{
4401
		CBaseFile *p = node->Data();
4625
		CBaseFile *p = node->Data();
4402
		if ( !p->IsEnabled() ) continue;
4626
		if ( !p->IsEnabled() ) continue;
Line 4420... Line 4644...
4420
{
4644
{
4421
	CDirIO Dir((dir.Empty()) ? m_sCurrentDir : dir);
4645
	CDirIO Dir((dir.Empty()) ? m_sCurrentDir : dir);
4422
 
4646
 
4423
	int check = start;
4647
	int check = start;
4424
	while ( check > 0 )
4648
	while ( check > 0 )
4425
	{
4649
	{
4426
		Utils::String checkStr = Utils::String::PadNumber(check, 2);
4650
		Utils::String checkStr = Utils::String::PadNumber(check, 2);
4427
 
4651
 
4428
		// check if a cat file exists
4652
		// check if a cat file exists
4429
		if ( !Dir.exists(checkStr + ".cat") )
4653
		if ( !Dir.exists(checkStr + ".cat") )
4430
		{
4654
		{
4431
			// it doen't, check if theres a dat file (incase of package error)
4655
			// it doen't, check if theres a dat file (incase of package error)
4432
			if ( !Dir.exists(checkStr + ".dat") )
4656
			if ( !Dir.exists(checkStr + ".dat") )
4433
				break;
4657
				break;
4434
		}
4658
		}
4435
		--check;
4659
		--check;
4436
	}
4660
	}
4437
 
4661
 
4438
	return check;
4662
	return check;
4439
}
4663
}
4440
 
4664
 
4441
/**
4665
/**
4442
 * Find next fake patch
4666
 * Find next fake patch
4443
 *
4667
 *
4444
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4668
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4445
 */
4669
 */
4446
int CPackages::FindNextFakePatch(int start, CyString dir)
4670
int CPackages::FindNextFakePatch(int start, CyString dir)
4447
{
4671
{
4448
	CDirIO Dir((dir.Empty()) ? m_sCurrentDir : dir);
4672
	CDirIO Dir((dir.Empty()) ? m_sCurrentDir : dir);
4449
 
4673
 
4450
	int check = start;
4674
	int check = start;
4451
	while ( check < 99 )
4675
	while ( check < 99 )
4452
	{
4676
	{
4453
		++check;
4677
		++check;
4454
		Utils::String checkStr = Utils::String::PadNumber(check, 2);
4678
		Utils::String checkStr = Utils::String::PadNumber(check, 2);
4455
 
4679
 
4456
		// check if a cat file exists
4680
		// check if a cat file exists
4457
		if ( !Dir.exists(checkStr + ".cat") )
4681
		if ( !Dir.exists(checkStr + ".cat") )
4458
		{
4682
		{
4459
			// it doen't, check if theres a dat file (incase of package error)
4683
			// it doen't, check if theres a dat file (incase of package error)
4460
			if ( !Dir.exists(checkStr + ".dat") )
4684
			if ( !Dir.exists(checkStr + ".dat") )
4461
				break;
4685
				break;
4462
		}
4686
		}
4463
	}
4687
	}
4464
 
4688
 
4465
	return check;
4689
	return check;
4466
}
4690
}
4467
 
4691
 
4468
/**
4692
/**
Line 4471... Line 4695...
4471
 * Searching for the next gap in automatic text files, start with 0004-LXXX or XX0004
4695
 * Searching for the next gap in automatic text files, start with 0004-LXXX or XX0004
4472
 */
4696
 */
4473
unsigned int CPackages::findNextTextFile(unsigned int start) const
4697
unsigned int CPackages::findNextTextFile(unsigned int start) const
4474
{
4698
{
4475
	return findNextTextFile(Utils::String::Null(), start);
4699
	return findNextTextFile(Utils::String::Null(), start);
4476
}
4700
}
4477
unsigned int CPackages::findNextTextFile(const Utils::String &dir, unsigned int start) const
4701
unsigned int CPackages::findNextTextFile(const Utils::String &dir, unsigned int start) const
4478
{
4702
{
4479
	int check = start;
4703
	int check = start;
4480
	if ( check < 2 ) check = 2;
4704
	if ( check < 2 ) check = 2;
4481
	while ( check < 9999 )
4705
	while ( check < 9999 )
Line 4483... Line 4707...
4483
		++check;
4707
		++check;
4484
		Utils::String newFilename = SPK::FormatTextName(check, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4708
		Utils::String newFilename = SPK::FormatTextName(check, m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4485
 
4709
 
4486
		// check the vfs
4710
		// check the vfs
4487
		if ( m_pGameVFS.isFileAvailable("t/" + newFilename + ".pck") ) continue;
4711
		if ( m_pGameVFS.isFileAvailable("t/" + newFilename + ".pck") ) continue;
4488
		if ( m_pGameVFS.isFileAvailable("t/" + newFilename + ".xml") ) continue;
4712
		if ( m_pGameVFS.isFileAvailable("t/" + newFilename + ".xml") ) continue;
4489
 
4713
 
4490
		break;
4714
		break;
4491
	}
4715
	}
4492
 
4716
 
4493
	return check;
4717
	return check;
4494
}
4718
}
Line 4508... Line 4732...
4508
		if ( !Dir.exists(newFilename + ".pck") )
4732
		if ( !Dir.exists(newFilename + ".pck") )
4509
		{
4733
		{
4510
			// it doen't, check if theres an unpacked file
4734
			// it doen't, check if theres an unpacked file
4511
			if ( !Dir.exists(newFilename + ".xml") )
4735
			if ( !Dir.exists(newFilename + ".xml") )
4512
				break;
4736
				break;
4513
		}
4737
		}
4514
	}
4738
	}
4515
 
4739
 
4516
	return check;
4740
	return check;
4517
}
4741
}
4518
 
4742
 
4519
/**
4743
/**
4520
 * Read game language
4744
 * Read game language
4521
 *
4745
 *
4522
 * Reads the lang.dat file from the game directory for the language id
4746
 * Reads the lang.dat file from the game directory for the language id
4523
 */
4747
 */
4524
void CPackages::ReadGameLanguage(bool force)
4748
void CPackages::ReadGameLanguage(bool force)
4525
{
4749
{
4526
	// check if lauguage is already set
4750
	// check if lauguage is already set
4527
	if ( !force && m_iLanguage )
4751
	if ( !force && m_iLanguage )
4528
		return;
4752
		return;
4529
 
4753
 
4530
	CDirIO Dir(m_sCurrentDir);
4754
	CDirIO Dir(m_sCurrentDir);
4531
 
4755
 
4532
	// check for lang.dat file
4756
	// check for lang.dat file
4533
	if ( Dir.exists("lang.dat") )
4757
	if ( Dir.exists("lang.dat") )
4534
	{
4758
	{
4535
		CFileIO File(Dir.File("lang.dat"));
4759
		CFileIO File(Dir.file("lang.dat"));
4536
 
4760
 
4537
		size_t size;
4761
		size_t size;
4538
		char *data = File.ReadToData(&size);
4762
		char *data = File.ReadToData(&size);
4539
 
4763
 
4540
		if ( data )
4764
		if ( data )
4541
		{
4765
		{
4542
			CyString str(data);
4766
			Utils::String str(data);
4543
			m_iLanguage = str.GetToken("\n", 1, 1).GetToken(" ", 1, 1).ToInt();
4767
			m_iLanguage = str.token("\n", 1).token(" ", 1).toInt();
4544
		}
4768
		}
4545
	}
4769
	}
4546
}
4770
}
4547
 
4771
 
4548
/**
4772
/**
4549
 * Create Language Text File
4773
 * Create Language Text File
4550
 *
4774
 *
4551
 * Creates text files for all packages into the correct language
4775
 * Creates text files for all packages into the correct language
4552
 */
4776
 */
4553
void CPackages::CreateLanguageTextFiles(CyStringList *errors)
4777
void CPackages::CreateLanguageTextFiles(Utils::CStringList *errors)
4554
{
4778
{
4555
	// no need to create them if theres no language to use
4779
	// no need to create them if theres no language to use
4556
	if ( !m_iLanguage )
4780
	if ( !m_iLanguage )
4557
		return;
4781
		return;
4558
 
4782
 
4559
	// find all text files
4783
	// find all text files
4560
	CyStringList ids;
4784
	Utils::CStringList ids;
4561
 
4785
 
4562
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4786
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
4563
	{
4787
	{
4564
		C_File *f = node->Data();
4788
		C_File *f = node->Data();
4565
		// only do text fiels
4789
		// only do text fiels
4566
		if ( f->GetFileType() != FILETYPE_TEXT )
4790
		if ( f->GetFileType() != FILETYPE_TEXT )
4567
			continue;
4791
			continue;
4568
 
4792
 
4569
		CyString id, lang;
4793
		Utils::String id, lang;
4570
		if ( m_iGameFlags & EXEFLAG_TCTEXT )
4794
		if ( m_iGameFlags & EXEFLAG_TCTEXT )
4571
		{
4795
		{
4572
			id = f->GetBaseName().GetToken("-", 1, 1);
4796
			id = f->baseName().token("-", 1);
4573
			lang = f->GetBaseName().GetToken("-", 2, 2);
4797
			lang = f->baseName().token("-", 2);
4574
			if ( lang.Empty() )
4798
			if ( lang.empty() )
4575
				lang = "NULL";
4799
				lang = "NULL";
4576
			else
4800
			else
4577
				lang = lang.Erase(0, 1);  // remove the "L"
4801
				lang = lang.erase(0, 1);  // remove the "L"
4578
		}
4802
		}
4579
		else
4803
		else
4580
		{
4804
		{
4581
			lang = f->GetBaseName().Left((int)f->GetBaseName().Length() - 4).PadNumber(3);
4805
			lang = Utils::String::PadNumber(f->baseName().left((int)f->baseName().length() - 4), 3);
4582
			id = f->GetBaseName().Mid(((int)f->GetBaseName().Length() - 4) + 1, 4);
4806
			id = f->baseName().mid(((int)f->baseName().length() - 4) + 1, 4);
4583
		}
4807
		}
4584
 
4808
 
4585
		SStringList *strList = ids.FindString(id);
-
 
4586
 
4809
 
4587
		// not added, add a new one
4810
		// not added, add a new one
4588
		if ( !strList )
4811
		if (!ids.contains(id))
4589
			strList = ids.PushBack(id, lang);
4812
			ids.pushBack(id, lang);
4590
		else
4813
		else
4591
		{
4814
		{
-
 
4815
			Utils::String data = ids.findString(id);
4592
			if ( strList->data.Empty() )
4816
			if (data.empty())
4593
				strList->data = lang;
4817
				data = lang;
4594
			else
4818
			else
4595
			{
4819
			{
4596
				strList->data += ":";
4820
				data += ":";
4597
				strList->data += lang;
4821
				data += lang;
4598
			}
4822
			}
-
 
4823
			ids.changeData(id, data);
4599
		}
4824
		}
4600
	}
4825
	}
4601
 
4826
 
4602
	// we should now have a list of all text files, we need to remove those that have a matching language
4827
	// we should now have a list of all text files, we need to remove those that have a matching language
4603
	for ( SStringList *sNode = ids.Head(); sNode; sNode = sNode->;next )
4828
	for(auto itr = ids.begin(); itr != ids.end(); itr++)
4604
	{
4829
	{
4605
		int size = 0;
4830
		int size = 0;
4606
		CyString *data = sNode->data.SplitToken(&apos;:&apos;, &size);
4831
		Utils::String *data = (*itr)->data.tokenise(&quot;:&quot;, &size);
4607
 
4832
 
4608
		// huh ? we shouldn't have this
4833
		// huh ? we shouldn't have this
4609
		if ( !size )
4834
		if ( !size )
4610
			continue;
4835
			continue;
4611
 
4836
 
Line 4616... Line 4841...
4616
		{
4841
		{
4617
			if ( data[i] == "NULL" )
4842
			if ( data[i] == "NULL" )
4618
				useId = -1;
4843
				useId = -1;
4619
			else
4844
			else
4620
			{
4845
			{
4621
				int num = data[i].ToInt();
4846
				int num = data[i].toInt();
4622
				if ( num == m_iLanguage )
4847
				if ( num == m_iLanguage )
4623
				{
4848
				{
4624
					found = true;
4849
					found = true;
4625
					useId = m_iLanguage;
4850
					useId = m_iLanguage;
4626
					break;
4851
					break;
Line 4635... Line 4860...
4635
				else if ( !useId )
4860
				else if ( !useId )
4636
					useId = num;
4861
					useId = num;
4637
			}
4862
			}
4638
		}
4863
		}
4639
 
4864
 
4640
		if ( found )
4865
		if (found)
-
 
4866
		{
-
 
4867
			CLEANSPLIT(data, size);
4641
			continue;
4868
			continue;
-
 
4869
		}
4642
 
4870
 
4643
		if ( !useId )
4871
		if ( !useId )
4644
			useId = data[0].ToInt();
4872
			useId = data[0].toInt();
4645
		if ( !useId )
4873
		if ( !useId )
4646
			useId = -1;
4874
			useId = -1;
4647
 
4875
 
4648
		CLEANSPLIT(data, size);
4876
		CLEANSPLIT(data, size);
4649
 
-
 
4650
		RenameTextFile(sNode->str, useId, errors);
4877
		RenameTextFile((*itr)->str, useId, errors);
4651
	}
4878
	}
4652
}
4879
}
4653
 
4880
 
4654
/**
4881
/**
4655
 * Rename a text file
4882
 * Rename a text file
4656
 *
4883
 *
4657
 * Creates a new text file and copies an existing one
4884
 * Creates a new text file for the selected langage by copying an existing one
4658
 */
4885
 */
4659
bool CPackages::RenameTextFile(CyString textid, int languageid, CyStringList *errors)
4886
bool CPackages::RenameTextFile(const Utils::String &textid, int languageid, Utils::CStringList *errors)
4660
{
4887
{
4661
	// lets check if the file already exists
4888
	// lets check if the file already exists
4662
	Utils::String newFilename = SPK::FormatTextName(textid.ToInt(), m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4889
	Utils::String newFilename = SPK::FormatTextName(textid.toInt(), m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4663
	C_File *addFile = FindFile(FILETYPE_TEXT, newFilename + ".xml");
4890
	C_File *addFile = FindFile(FILETYPE_TEXT, newFilename + ".xml");
4664
	if ( !addFile )
4891
	if ( !addFile )
4665
		addFile = FindFile(FILETYPE_TEXT, newFilename + ".pck");
4892
		addFile = FindFile(FILETYPE_TEXT, newFilename + ".pck");
4666
 
4893
 
4667
	// we have found the file, lets just add it to our scripts
4894
	// we have found the file, lets just add it to our scripts
Line 4672... Line 4899...
4672
	}
4899
	}
4673
 
4900
 
4674
	// first we need to find our text file
4901
	// first we need to find our text file
4675
	Utils::String filename;
4902
	Utils::String filename;
4676
	if ( languageid != -1 )
4903
	if ( languageid != -1 )
4677
		filename = SPK::FormatTextName(textid.ToInt(), languageid, (m_iGameFlags & EXEFLAG_TCTEXT));
4904
		filename = SPK::FormatTextName(textid.toInt(), languageid, (m_iGameFlags & EXEFLAG_TCTEXT));
4678
	else
4905
	else
4679
		filename = textid.ToString();
4906
		filename = textid;
4680
 
4907
 
4681
	C_File *textFile = FindFile(FILETYPE_TEXT, filename + ".xml");
4908
	C_File *textFile = FindFile(FILETYPE_TEXT, filename + ".xml");
4682
	if ( !textFile )
4909
	if ( !textFile )
4683
	{
4910
	{
4684
		textFile = FindFile(FILETYPE_TEXT, filename + ".pck");
4911
		textFile = FindFile(FILETYPE_TEXT, filename + ".pck");
4685
		if ( !textFile )
4912
		if ( !textFile )
4686
			return false;
4913
			return false;
4687
	}
4914
	}
4688
 
4915
 
4689
	// now lets create out new text file
4916
	// now lets create out new text file
4690
	CFileIO readFile(textFile->GetFilePointer());
4917
	CFileIO readFile(textFile->filePointer());
4691
	std::vector<CyString> *lines = readFile.ReadLines();
4918
	std::vector<Utils::String> *lines = readFile.readLines();
4692
 
4919
 
4693
	// find the language id in the lines
4920
	// find the language id in the lines
4694
	std::vector<CyString> frontLines;
4921
	std::vector<Utils::String> frontLines;
4695
	for(std::vector<CyString>::iterator it = lines->begin(); it != lines->end(); ++it)
4922
	for(std::vector<Utils::String>::iterator it = lines->begin(); it != lines->end(); ++it)
4696
	{
4923
	{
4697
		CyString line = *it;
4924
		Utils::String line = *it;
4698
		int pos = line.FindPos("<language id");
4925
		int pos = line.findPos("<language id");
4699
		if ( pos != -1)
4926
		if ( pos != -1)
4700
		{
4927
		{
4701
			CyString newLine = "<language id=\"";
4928
			Utils::String newLine = "<language id=\"";
4702
			newLine += CyString::Number(m_iLanguage);
4929
			newLine += Utils::String::Number(m_iLanguage);
4703
			newLine += "\">";
4930
			newLine += "\">";
4704
			newLine += line.GetToken(">", 2);
4931
			newLine += line.tokens(">", 2);
4705
 
4932
 
4706
			frontLines.insert(frontLines.begin(), newLine);
4933
			frontLines.insert(frontLines.begin(), newLine);
4707
 
4934
 
4708
			lines->erase(lines->begin(), ++it);
4935
			lines->erase(lines->begin(), ++it);
4709
			break;
4936
			break;
4710
		}
4937
		}
4711
		frontLines.insert(frontLines.begin(), line);
4938
		frontLines.insert(frontLines.begin(), line);
4712
	}
4939
	}
4713
 
4940
 
4714
	for(std::vector<CyString>::iterator it = frontLines.begin(); it != frontLines.end(); ++it)
4941
	for(std::vector<Utils::String>::iterator it = frontLines.begin(); it != frontLines.end(); ++it)
4715
		lines->insert(lines->begin(), *it);
4942
		lines->insert(lines->begin(), *it);
4716
 
4943
 
4717
	addFile = new C_File(newFilename + ".xml");
4944
	addFile = new C_File(newFilename + ".xml");
4718
	addFile->SetFileType(FILETYPE_TEXT);
4945
	addFile->setFileType(FILETYPE_TEXT);
4719
 
4946
 
4720
	CFileIO writeFile(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
4947
	CFileIO writeFile(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
4721
	if ( writeFile.WriteFile(lines) )
4948
	if ( writeFile.writeFile(lines) )
4722
	{
4949
	{
4723
		this->AddLogEntry(SPKINSTALL_WRITEFILE, addFile->getNameDirectory(NULL), errors);
4950
		this->addLogEntry(SPKINSTALL_WRITEFILE, addFile->getNameDirectory(NULL), errors);
4724
 
4951
 
4725
		addFile->SetFilename(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
4952
		addFile->SetFilename(m_sCurrentDir + "/" + addFile->getNameDirectory(NULL));
4726
		// now we have the file wrriten, we need to add it to all scripts that need it
4953
		// now we have the file wrriten, we need to add it to all scripts that need it
4727
		// first we add it to the global list
4954
		// first we add it to the global list
4728
		m_lFiles.push_back(addFile);
4955
		m_lFiles.push_back(addFile);
Line 4730... Line 4957...
4730
		// now add it to the scripts
4957
		// now add it to the scripts
4731
		AddTextFileToScripts(addFile, textid);
4958
		AddTextFileToScripts(addFile, textid);
4732
	}
4959
	}
4733
	else
4960
	else
4734
	{
4961
	{
4735
		this->AddLogEntry(SPKINSTALL_WRITEFILE_FAIL, addFile->getNameDirectory(NULL), errors);
4962
		this->addLogEntry(SPKINSTALL_WRITEFILE_FAIL, addFile->getNameDirectory(NULL), errors);
4736
		if ( lines )
4963
		if ( lines )
4737
			delete lines;
4964
			delete lines;
4738
		return false;
4965
		return false;
4739
	}
4966
	}
4740
 
4967
 
Line 4918... Line 5145...
4918
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5145
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
4919
		node->Data()->SetNum(num++);
5146
		node->Data()->SetNum(num++);
4920
}
5147
}
4921
 
5148
 
4922
Utils::String CPackages::findDataDir(const Utils::String &dir, const Utils::String &file)
5149
Utils::String CPackages::findDataDir(const Utils::String &dir, const Utils::String &file)
4923
{
5150
{
4924
	CDirIO Dir(dir);
5151
	CDirIO Dir(dir);
4925
 
5152
 
4926
	// data files could be in 4 places depending on what program is used, check for all of these
5153
	// data files could be in 4 places depending on what program is used, check for all of these
4927
	if (Dir.exists(file))
5154
	if (Dir.exists(file))
4928
		return Dir.file(file);
5155
		return Dir.file(file);
4929
	else if (Dir.exists("Data/" + file))
5156
	else if (Dir.exists("Data/" + file))
4930
		return Dir.file("Data/" + file);
5157
		return Dir.file("Data/" + file);
Line 4932... Line 5159...
4932
		return Dir.file("../" + file);
5159
		return Dir.file("../" + file);
4933
	else if (Dir.exists("../Data/" + file))
5160
	else if (Dir.exists("../Data/" + file))
4934
		return Dir.file("../Data/" + file);
5161
		return Dir.file("../Data/" + file);
4935
 
5162
 
4936
	return Utils::String::Null();
5163
	return Utils::String::Null();
4937
}
5164
}
4938
 
5165
 
4939
void CPackages::startup(const Utils::String &dir, const Utils::String &tempDir, const Utils::String &myDoc)
5166
void CPackages::startup(const Utils::String &dir, const Utils::String &tempDir, const Utils::String &myDoc)
4940
{
5167
{
4941
	this->setTempDirectory(tempDir);
5168
	this->setTempDirectory(tempDir);
4942
	this->setMyDocuments(myDoc);
5169
	this->setMyDocuments(myDoc);
Line 4960... Line 5187...
4960
}
5187
}
4961
void CPackages::startup(const Utils::String &dir, const Utils::String &tempDir, const Utils::String &myDoc, const Utils::String &mod)
5188
void CPackages::startup(const Utils::String &dir, const Utils::String &tempDir, const Utils::String &myDoc, const Utils::String &mod)
4962
{
5189
{
4963
	startup(dir, tempDir, myDoc);
5190
	startup(dir, tempDir, myDoc);
4964
	m_sSetMod = mod;
5191
	m_sSetMod = mod;
4965
}
5192
}
4966
/*
5193
/*
4967
void CPackages::Startup(CyString dir, CyString tempDir, CyString myDoc, CyString mod)
5194
void CPackages::Startup(CyString dir, CyString tempDir, CyString myDoc, CyString mod)
4968
{
5195
{
4969
	startup(dir.ToString(), tempDir.ToString(), myDoc.ToString(), mod.ToString());
5196
	startup(dir.ToString(), tempDir.ToString(), myDoc.ToString(), mod.ToString());
4970
}*/
5197
}*/
Line 4988... Line 5215...
4988
	{
5215
	{
4989
		CFileIO File(Dir.file("lang.dat"));
5216
		CFileIO File(Dir.file("lang.dat"));
4990
 
5217
 
4991
		size_t size;
5218
		size_t size;
4992
		char *data = File.ReadToData(&size);
5219
		char *data = File.ReadToData(&size);
4993
 
5220
 
4994
		if ( data )
5221
		if ( data )
4995
		{
5222
		{
4996
			Utils::String str(data);
5223
			Utils::String str(data);
4997
			return str.token("\n", 1).token(" ", 1).toLong();
5224
			return str.token("\n", 1).token(" ", 1).toLong();
4998
		}
5225
		}
Line 5030... Line 5257...
5030
CyString CPackages::GetProperDir(CyString dir)
5257
CyString CPackages::GetProperDir(CyString dir)
5031
{
5258
{
5032
	return m_gameExe.GetProperDir((dir.Empty()) ? m_sCurrentDir : dir.ToString());
5259
	return m_gameExe.GetProperDir((dir.Empty()) ? m_sCurrentDir : dir.ToString());
5033
}
5260
}
5034
CyString CPackages::GetAddonDir(CyString dir)
5261
CyString CPackages::GetAddonDir(CyString dir)
5035
{
5262
{
5036
	return m_gameExe.GetAddonDir((dir.Empty()) ? m_sCurrentDir : dir.ToString());
5263
	return m_gameExe.GetAddonDir((dir.Empty()) ? m_sCurrentDir : dir.ToString());
5037
}
5264
}
5038
Utils::String CPackages::getProperDir() const
5265
Utils::String CPackages::getProperDir() const
5039
{
5266
{
5040
	return getProperDir(m_sCurrentDir);
5267
	return getProperDir(m_sCurrentDir);
Line 5059... Line 5286...
5059
{
5286
{
5060
	return m_gameExe.GetGameAddons(m_sCurrentDir, exes);
5287
	return m_gameExe.GetGameAddons(m_sCurrentDir, exes);
5061
}
5288
}
5062
 
5289
 
5063
Utils::String CPackages::getGameTypesString(CBaseFile *package, bool includeVersion)
5290
Utils::String CPackages::getGameTypesString(CBaseFile *package, bool includeVersion)
5064
{
5291
{
5065
	if ( !package->AnyGameCompatability() )
5292
	if ( !package->AnyGameCompatability() )
5066
		return "";
5293
		return "";
5067
 
5294
 
5068
	Utils::String sGames;
5295
	Utils::String sGames;
5069
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5296
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
Line 5086... Line 5313...
5086
{
5313
{
5087
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5314
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5088
		if ( gNode->Data()->iGame == m_iGame ) {
5315
		if ( gNode->Data()->iGame == m_iGame ) {
5089
			return m_gameExe.GetGameVersionFromType(m_iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
5316
			return m_gameExe.GetGameVersionFromType(m_iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
5090
		}
5317
		}
5091
	}
5318
	}
5092
 
5319
 
5093
	return NullString;
5320
	return NullString;
5094
}
5321
}
5095
 
5322
 
5096
CyString CPackages::GetGameVersionFromType(int game, int version, CyString sVersion)
5323
CyString CPackages::GetGameVersionFromType(int game, int version, CyString sVersion)
5097
{
5324
{
Line 5143... Line 5370...
5143
	if ( addonDir.Empty() ) addonDir = this->GetAddonDir(dir);
5370
	if ( addonDir.Empty() ) addonDir = this->GetAddonDir(dir);
5144
 
5371
 
5145
	if ( m_pEnabledMod && m_pEnabledMod->AnyFileType(FILETYPE_MOD) )
5372
	if ( m_pEnabledMod && m_pEnabledMod->AnyFileType(FILETYPE_MOD) )
5146
	{
5373
	{
5147
		for ( C_File *file = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); file; file = m_pEnabledMod->GetNextFile(file) )
5374
		for ( C_File *file = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); file; file = m_pEnabledMod->GetNextFile(file) )
5148
		{
5375
		{
5149
			if ( !file->CheckFileExt("cat") )
5376
			if ( !file->CheckFileExt("cat") )
5150
				continue;
5377
				continue;
5151
 
5378
 
5152
			CCatFile catFile;
5379
			CCatFile catFile;
5153
			if ( catFile.open(file->filePointer(), addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
5380
			if ( catFile.open(file->filePointer(), addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
5154
			{
5381
			{
5155
				if ( catFile.ExtractFile(aFilename, aTo) )
5382
				if ( catFile.ExtractFile(aFilename, aTo) )
5156
					return 1;
5383
					return 1;
5157
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5384
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5158
				{
5385
				{
5159
					if ( catFile.ExtractFile(aFilename) )
5386
					if ( catFile.ExtractFile(aFilename) )
5160
						return -1;
5387
						return -1;
5161
				}
5388
				}
5162
 
5389
 
5163
			}
5390
			}
5164
		}
5391
		}
5165
	}
5392
	}
5166
	else if ( !m_sSetMod.Empty() )
5393
	else if ( !m_sSetMod.empty() )
5167
	{
5394
	{
5168
		if ( CFileIO::Exists(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ".cat"))
5395
		if ( CFileIO::Exists(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat"))
5169
		{
5396
		{
5170
			CCatFile catFile;
5397
			CCatFile catFile;
5171
			if (catFile.open(m_sCurrentDir + "/mods/" + m_sSetMod.ToString() + ".cat", addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
5398
			if (catFile.open(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat", addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
5172
			{
5399
			{
5173
				if ( catFile.ExtractFile(aFilename, aTo) )
5400
				if ( catFile.ExtractFile(aFilename, aTo) )
5174
					return 1;
5401
					return 1;
5175
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5402
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5176
				{
5403
				{
Line 5216... Line 5443...
5216
	for ( int i = 0; i < WAREBUFFERS; i++ )
5443
	for ( int i = 0; i < WAREBUFFERS; i++ )
5217
	{
5444
	{
5218
		// its empty, no need to create ware files
5445
		// its empty, no need to create ware files
5219
		if ( !m_lGameWares[i].size() )
5446
		if ( !m_lGameWares[i].size() )
5220
			continue;
5447
			continue;
5221
 
5448
 
5222
		// lets extract the ware file
5449
		// lets extract the ware file
5223
		char wareType = CPackages::ConvertWareTypeBack(i);
5450
		char wareType = CPackages::ConvertWareTypeBack(i);
5224
		Utils::String wareFile = "TWare";
5451
		Utils::String wareFile = "TWare";
5225
		wareFile += (char)UPPER(wareType);
5452
		wareFile += (char)UPPER(wareType);
5226
 
5453
 
Line 5238... Line 5465...
5238
		}
5465
		}
5239
 
5466
 
5240
		if ( !openFile.Empty() )
5467
		if ( !openFile.Empty() )
5241
		{
5468
		{
5242
			// read the file into memory
5469
			// read the file into memory
5243
			CyStringList wareLines;
5470
			Utils::CStringList wareLines;
5244
			int oldSize = -1;
5471
			size_t oldSize = -1;
5245
			int version = -1;
5472
			int version = -1;
5246
 
5473
 
5247
			// read first number
5474
			// read first number
5248
			CFileIO readFile(m_sTempDir + "/" + wareFile + ".txt");
5475
			CFileIO readFile(m_sTempDir + "/" + wareFile + ".txt");
5249
			CyStringList *lines = readFile.ReadLinesStr();
5476
			Utils::CStringList *lines = readFile.readLinesStr();
5250
			if ( lines )
5477
			if ( lines )
5251
			{
5478
			{
5252
				for ( SStringList *str = lines->;Head(); str; str = str->next )
5479
				for(auto itr = lines->;begin(); itr != lines->end(); itr++)
5253
				{
5480
				{
5254
					CyString line(str->str);
5481
					Utils::String line((*itr)->str);
5255
					line.RemoveFirstSpace();
5482
					line.removeFirstSpace();
5256
					line.RemoveChar(9);
5483
					line.removeChar(9);
5257
					line.RemoveChar('\r');
5484
					line.removeChar('\r');
5258
					if ( line.Empty() )
5485
					if ( line.empty() )
5259
						continue;
5486
						continue;
5260
					if ( line[0] == '/' )
5487
					if ( line[0] == '/' )
5261
						continue;
5488
						continue;
5262
 
5489
 
5263
					if ( oldSize == -1 )
5490
					if ( oldSize == -1 )
5264
					{
5491
					{
5265
						version = line.GetToken(";", 1, 1).ToInt();
5492
						version = line.token(";", 1).toInt();
5266
						oldSize = line.GetToken(";", 2, 2).ToInt();
5493
						oldSize = line.token(";", 2).toInt();
5267
					}
5494
					}
5268
					else
5495
					else
5269
					{
5496
					{
5270
						line.RemoveEndSpace();
5497
						line.removeEndSpace();
5271
						if ( line.Right(1) != ';' )
5498
						if ( line.back() != ';')
5272
							line += ";";
5499
							line += ";";
5273
						wareLines.PushBack(line);
5500
						wareLines.pushBack(line);
5274
						if ( wareLines.Count() >= oldSize )
5501
						if ( wareLines.size() >= oldSize )
5275
							break;
5502
							break;
5276
					}
5503
					}
5277
				}
5504
				}
5278
 
5505
 
5279
				delete lines;
5506
				delete lines;
5280
 
5507
 
5281
				// apply the buffer
5508
				// apply the buffer
5282
				if ( m_iWareBuffer[i] <= 0 )
5509
				if ( m_iWareBuffer[i] <= 0 )
5283
					m_iWareBuffer[i] = wareLines.Count() + 10;
5510
					m_iWareBuffer[i] = wareLines.size() + 10;
5284
				// last resort, readjust the buffer
5511
				// last resort, readjust the buffer
5285
				else if ( wareLines.Count() > m_iWareBuffer[i] )
5512
				else if ( wareLines.size() > static_cast<size_t>(m_iWareBuffer[i]) )
5286
					m_iWareBuffer[i] = wareLines.Count();
5513
					m_iWareBuffer[i] = wareLines.size();
5287
 
5514
 
5288
				// add the buffers
5515
				// add the buffers
5289
				while ( wareLines.Count() < m_iWareBuffer[i] )
5516
				while ( wareLines.size() < static_cast<size_t>(m_iWareBuffer[i]) )
5290
					wareLines.PushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_FILLER;");
5517
					wareLines.pushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_FILLER;");
5291
 
5518
 
5292
				// add the ware lines
5519
				// add the ware lines
5293
				bool create = false;
5520
				bool create = false;
5294
				for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
5521
				for ( CListNode<SGameWare> *node = m_lGameWares[i].Front(); node; node = node->next() )
5295
				{
5522
				{
Line 5298... Line 5525...
5298
					if ( w->iType == WARETYPE_NONE )
5525
					if ( w->iType == WARETYPE_NONE )
5299
						continue;
5526
						continue;
5300
					else if ( w->iType == WARETYPE_DISABLED )
5527
					else if ( w->iType == WARETYPE_DISABLED )
5301
					{
5528
					{
5302
						create = true;
5529
						create = true;
5303
						wareLines.PushBack(CyString("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;") + w->sWareName + "_DISABLED;");
5530
						wareLines.pushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;" + w->sWareName + "_DISABLED;");
5304
					}
5531
					}
5305
					else if ( w->iType == WARETYPE_DELETED || !w->pWare )
5532
					else if ( w->iType == WARETYPE_DELETED || !w->pWare )
5306
					{
5533
					{
5307
						create = true;
5534
						create = true;
5308
						wareLines.PushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_DELETED;");
5535
						wareLines.pushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_DELETED;");
5309
					}
5536
					}
5310
					else if ( w->iType == WARETYPE_ADDED )
5537
					else if ( w->iType == WARETYPE_ADDED )
5311
					{
5538
					{
5312
						create = true;
5539
						create = true;
5313
						w->pWare->iDescID = wareTextID;
5540
						w->pWare->iDescID = wareTextID;
5314
						w->iText = wareTextID;
5541
						w->iText = wareTextID;
5315
						wareTextID += 10;
5542
						wareTextID += 10;
5316
						w->iPos = wareLines.Count();
5543
						w->iPos = wareLines.size();
5317
						long price = this->customWareOveridePrice(w->pWare->sID);
5544
						long price = this->customWareOveridePrice(w->pWare->sID);
5318
						int notority = w->pWare->iNotority;
5545
						int notority = w->pWare->iNotority;
5319
						if ( !this->customWareOverideNoto(w->pWare->sID, &notority) ) notority = w->pWare->iNotority;
5546
						if ( !this->customWareOverideNoto(w->pWare->sID, &notority) ) notority = w->pWare->iNotority;
5320
						if ( !price ) price = w->pWare->iPrice;
5547
						if ( !price ) price = w->pWare->iPrice;
5321
 
5548
 
5322
						wareLines.PushBack(CyString("28;0;0;0;0;") + (long)wareLines.Count() + ";" + (long)(w->iText + 3) + ";" + (long)w->pWare->iVolumn + ";" + price + ";1;1;" + (long)w->pWare->iSize + ";" + price + ";" + (long)notority + ";0;0;" + w->sWareName.ToUpper() + ";");
5549
						wareLines.pushBack(Utils::String("28;0;0;0;0;") + (long)wareLines.size() + ";" + (long)(w->iText + 3) + ";" + (long)w->pWare->iVolumn + ";" + price + ";1;1;" + (long)w->pWare->iSize + ";" + price + ";" + (long)notority + ";0;0;" + w->sWareName.upper() + ";");
5323
					}
5550
					}
5324
				}
5551
				}
5325
 
5552
 
5326
				if ( create )
5553
				if ( create )
5327
				{
5554
				{
5328
					wareLines.PushFront(CyString::Number(version) + ";" + CyString::Number(wareLines.Count()) + ";", NullString);
5555
					wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5329
					CyString strV;
5556
					Utils::String strV;
5330
					strV.FromFloat(GetLibraryVersion(), 2);
5557
					strV.FromFloat(GetLibraryVersion(), 2);
5331
					wareLines.PushFront(CyString("// Created by SPKInstaller Libraries V") + strV, NullString);
5558
					wareLines.pushFront("// Created by SPKInstaller Libraries V" + strV, Utils::String::Null());
5332
					if ( readFile.WriteFile(&wareLines) )
5559
					if ( readFile.writeFile(&wareLines) )
5333
						this->PackFile(&readFile, CyString("types\\") + wareFile + ".pck");
5560
						this->PackFile(&readFile, CyString("types\\") + wareFile + ".pck");
5334
				}
5561
				}
5335
			}
5562
			}
5336
			readFile.remove();
5563
			readFile.remove();
5337
		}
5564
		}
5338
	}
5565
	}
5339
}
5566
}
5340
 
5567
 
5341
Utils::String CPackages::empWaresForGame(int *maxsize)
5568
Utils::String CPackages::empWaresForGame(size_t *maxsize)
5342
{
5569
{
5343
	if ( maxsize ) (*maxsize) = 0;
5570
	if ( maxsize ) (*maxsize) = 0;
5344
 
5571
 
5345
	if ( m_iGame == GAME_X3TC )
5572
	if ( m_iGame == GAME_X3TC )
5346
	{
5573
	{
Line 5425... Line 5652...
5425
 
5652
 
5426
 
5653
 
5427
void CPackages::CreateEMPFile(CyString progDir)
5654
void CPackages::CreateEMPFile(CyString progDir)
5428
{
5655
{
5429
	// do emp wares
5656
	// do emp wares
5430
	int maxsize = 0;
5657
	size_t maxsize = 0;
5431
	Utils::String empWares = empWaresForGame(&maxsize);
5658
	Utils::String empWares = empWaresForGame(&maxsize);
5432
 
5659
 
5433
	if ( maxsize )
5660
	if ( maxsize )
5434
	{
5661
	{
5435
		int e = ExtractGameFile("types/TWareT.pck", m_sTempDir + "/TWareT.txt");
5662
		int e = ExtractGameFile("types/TWareT.pck", m_sTempDir + "/TWareT.txt");
5436
		if ( e )
5663
		if ( e )
5437
		{
5664
		{
5438
			// read the file into memory
5665
			// read the file into memory
5439
			CyStringList wareLines;
5666
			Utils::CStringList wareLines;
5440
			int oldSize = -1;
5667
			size_t oldSize = -1;
5441
			int version = -1;
5668
			int version = -1;
5442
 
5669
 
5443
			// read first number
5670
			// read first number
5444
			CFileIO readFile((e == -1) ? "TWareT.txt" : m_sTempDir + "/TWareT.txt");
5671
			CFileIO readFile((e == -1) ? "TWareT.txt" : m_sTempDir + "/TWareT.txt");
5445
			std::vector<Utils::String> *lines = readFile.readLines();
5672
			std::vector<Utils::String> *lines = readFile.readLines();
Line 5492... Line 5719...
5492
							if ( this->empOverideNoto(i - 116, &noto) ) {
5719
							if ( this->empOverideNoto(i - 116, &noto) ) {
5493
								line = line.replaceToken(";", 14, Utils::String::Number(noto));
5720
								line = line.replaceToken(";", 14, Utils::String::Number(noto));
5494
							}
5721
							}
5495
						}
5722
						}
5496
 
5723
 
5497
						wareLines.PushBack(CyString(line));
5724
						wareLines.pushBack(line);
5498
						if ( wareLines.Count() >= oldSize )
5725
						if ( wareLines.size() >= oldSize )
5499
							break;
5726
							break;
5500
					}
5727
					}
5501
				}
5728
				}
5502
 
5729
 
5503
				delete lines;
5730
				delete lines;
5504
			}
5731
			}
5505
 
5732
 
5506
			// now we too add/remove entries to match
5733
			// now we too add/remove entries to match
5507
			// need filler entries
5734
			// need filler entries
5508
			while ( wareLines.Count() < maxsize )
5735
			while ( wareLines.size() < maxsize )
5509
				wareLines.PushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_FILLER;");
5736
				wareLines.pushBack("27;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;SS_WARE_FILLER;");
5510
 
5737
 
5511
			int empEntries = 0;
5738
			int empEntries = 0;
5512
			Utils::String *empStr = empWares.tokenise("\n", &empEntries);
5739
			Utils::String *empStr = empWares.tokenise("\n", &empEntries);
5513
 
5740
 
5514
			if ( empEntries && empStr )
5741
			if ( empEntries && empStr )
Line 5528... Line 5755...
5528
				}
5755
				}
5529
				// remove any empty end entries
5756
				// remove any empty end entries
5530
				while ( empStr[empEntries - 1].empty() )
5757
				while ( empStr[empEntries - 1].empty() )
5531
					--empEntries;
5758
					--empEntries;
5532
 
5759
 
5533
				CyStringList addAfter;
5760
				Utils::CStringList addAfter;
5534
				if ( wareLines.Count() > maxsize )
5761
				if ( wareLines.size() > maxsize )
5535
				{
5762
				{
5536
					// force emp, remove entries to allow them to be added
5763
					// force emp, remove entries to allow them to be added
5537
					if ( m_bForceEMP )
5764
					if ( m_bForceEMP )
5538
					{
5765
					{
5539
						// more after emp
5766
						// more after emp
5540
						if ( wareLines.Count() > (maxsize + empEntries) )
5767
						if ( wareLines.size() > (maxsize + empEntries) )
5541
						{
5768
						{
5542
							SStringList *node = wareLines.GetAt(maxsize + empEntries);
5769
							for (size_t i = (maxsize + empEntries); i < wareLines.size(); i++)
5543
							while ( node )
-
 
5544
							{
5770
							{
5545
								addAfter.PushBack(node->str);
5771
								auto node = wareLines.get(i);
5546
								node = node->next;
5772
								addAfter.pushBack(node->str);
5547
							}
5773
							}
5548
						}
5774
						}
5549
 
5775
 
5550
						// no remove them all
5776
						// no remove them all
5551
						wareLines.DeleteFrom(maxsize);
5777
						while (wareLines.size() > maxsize)
-
 
5778
							wareLines.removeAt(wareLines.size() - 1);
5552
					}
5779
					}
5553
					else if ( m_iGame == GAME_X3TC || m_iGame == GAME_X3AP || m_iGame == GAME_X3FL) // check if old emp is included, and convert it
5780
					else if ( m_iGame == GAME_X3TC || m_iGame == GAME_X3AP || m_iGame == GAME_X3FL) // check if old emp is included, and convert it
5554
					{
5781
					{
5555
						if ( wareLines.Count() > 128 )
5782
						if ( wareLines.size() > 128 )
5556
						{
5783
						{
5557
							CyString test = wareLines.GetAt(128)->str;
5784
							Utils::String test = wareLines.get(128)->str;
5558
							if ( test.GetToken(";", -2).Compare("SS_WARE_SW_CUSTOM16_1;") )
5785
							if ( test.tokens(";", -2).Compare("SS_WARE_SW_CUSTOM16_1;") )
5559
							{
5786
							{
5560
								// if theres any at the end, remove the last emp entry
5787
								// if theres any at the end, remove the last emp entry
5561
								if ( wareLines.Count() > (maxsize + empEntries - 1) )
5788
								if ( wareLines.size() > (maxsize + empEntries - 1) )
5562
								{
5789
								{
5563
									SStringList *node = wareLines.GetAt(maxsize + empEntries - 2);
5790
									wareLines.removeAt(maxsize + empEntries - 2);
5564
									if ( node )
-
 
5565
										node->remove = true;
-
 
5566
								}
5791
								}
5567
								wareLines.Insert(128, "0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;128;");
5792
								wareLines.insertAt(128, "0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;128;");
5568
								wareLines.RemoveMarked();
-
 
5569
							}
5793
							}
5570
						}
5794
						}
5571
					}
5795
					}
5572
				}
5796
				}
5573
 
5797
 
5574
				// too many entries, need to remove the first set of EMP wares
5798
				// too many entries, need to remove the first set of EMP wares
5575
				int i = 0;
5799
				int i = 0;
5576
				if ( wareLines.Count() > maxsize )
5800
				if ( wareLines.size() > maxsize )
5577
					i = wareLines.Count() - maxsize;
5801
					i = wareLines.size() - maxsize;
5578
 
5802
 
5579
				for ( ; i < empEntries; i++ )
5803
				for ( ; i < empEntries; i++ )
5580
				{
5804
				{
5581
					CyString str = empStr[i];
5805
					Utils::String str = empStr[i];
5582
					str.RemoveEndSpace();
5806
					str.removeEndSpace();
5583
					str.RemoveChar(9);
5807
					str.removeChar(9);
5584
					str.RemoveChar('\r');
5808
					str.removeChar('\r');
5585
					if ( str.Empty() )
5809
					if ( str.empty() )
5586
						continue;
5810
						continue;
5587
					if ( str.Right(1) != ";" )
5811
					if ( str.right(1) != ";")
5588
						str += ";";
5812
						str += ";";
5589
					wareLines.PushBack(str);
5813
					wareLines.pushBack(str);
5590
				}
5814
				}
5591
 
5815
 
5592
				for ( SStringList *afterNode = addAfter.Head(); afterNode; afterNode = afterNode->;next )
5816
				for(auto afterItr = addAfter.begin(); afterItr != addAfter.end(); afterItr++)
5593
					wareLines.PushBack(afterNode->str);
5817
					wareLines.pushBack((*afterItr)->str);
5594
 
5818
 
5595
				// finally we write the whole file
5819
				// finally we write the whole file
5596
				wareLines.PushFront(CyString::Number(version) + ";" + CyString::Number(wareLines.Count()) + ";", NullString);
5820
				wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5597
				CyString strV;
-
 
5598
				strV.FromFloat(GetLibraryVersion(), 2);
-
 
5599
				wareLines.PushFront(CyString(";// Created by SPKInstaller Libraries V") + strV, NullString);
5821
				wareLines.pushFront(";// Created by SPKInstaller Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2), Utils::String::Null());
5600
				if ( readFile.WriteFile(&wareLines) )
5822
				if ( readFile.writeFile(&wareLines) )
5601
					this->PackFile(&readFile, "types\\TWareT.pck");
5823
					this->PackFile(&readFile, "types\\TWareT.pck");
5602
			}
5824
			}
5603
			CLEANSPLIT(empStr, empEntries);
5825
			CLEANSPLIT(empStr, empEntries);
5604
		}
5826
		}
5605
	}
5827
	}
Line 5677... Line 5899...
5677
	if ( !lang || lang < 0 )
5899
	if ( !lang || lang < 0 )
5678
		lang = 44;
5900
		lang = 44;
5679
 
5901
 
5680
	CDirIO Dir(m_sCurrentDir);
5902
	CDirIO Dir(m_sCurrentDir);
5681
	if ( !Dir.exists("t") )
5903
	if ( !Dir.exists("t") )
5682
		Dir.Create("t");
5904
		Dir.create("t");
5683
 
5905
 
5684
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5906
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5685
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5907
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5686
 
5908
 
5687
	std::vector<CyString> writeData;
5909
	std::vector<Utils::String> writeData;
5688
 
5910
 
5689
	writeData.push_back(CyString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"));
5911
	writeData.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
5690
	writeData.push_back(CyString("<language id=\"") + CyString::Number(lang) + "\">");
5912
	writeData.push_back("<language id=\"" + Utils::String::Number(lang) + "\">");
5691
 
5913
 
5692
	if ( !gameNumber )
5914
	if ( !gameNumber )
5693
		writeData.push_back(CyString("	<page id=\"") + CyString::Number(PMTEXTFILE) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5915
		writeData.push_back("	<page id=\"" + Utils::String::Number(PMTEXTFILE) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5694
	else
5916
	else
5695
		writeData.push_back(CyString(&quot;	&lt;page id=\"") + (long)gameNumber + CyString::Number(PMTEXTFILE).PadNumber(4) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5917
		writeData.push_back(&quot;	&lt;page id=\"" + (long)gameNumber + Utils::String::PadNumber(PMTEXTFILE, 4) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5696
 
5918
 
5697
	writeData.push_back(CyString("		<t id=\"99998\">[author]Plugin Manager[/author]It appears the plugin manager hasn't been closed properly.  Make sure its closed before running the game otherwise things may not work correctly</t>"));
5919
	writeData.push_back("		<t id=\"99998\">[author]Plugin Manager[/author]It appears the plugin manager hasn't been closed properly.  Make sure its closed before running the game otherwise things may not work correctly</t>");
5698
	writeData.push_back(CyString("		<t id=\"99999\">2</t>"));
5920
	writeData.push_back("		<t id=\"99999\">2</t>");	
-
 
5921
	writeData.push_back("	</page>");
5699
 
5922
 
5700
	writeData.push_back(CyString("	</page>"));
-
 
5701
 
-
 
5702
	writeData.push_back(CyString("</language>"));
5923
	writeData.push_back("</language>");
5703
	textFile.WriteFileUTF(&writeData);
5924
	textFile.writeFileUTF(&writeData);
5704
 
5925
 
5705
	size_t fileSize;
5926
	size_t fileSize;
5706
	char *fileData = CFileIO(textFile.fullFilename()).ReadToData(&fileSize);
5927
	char *fileData = CFileIO(textFile.fullFilename()).ReadToData(&fileSize);
5707
 
5928
 
5708
	if ( fileData && fileSize)
5929
	if ( fileData && fileSize)
Line 5727... Line 5948...
5727
	if ( !lang || lang < 0 )
5948
	if ( !lang || lang < 0 )
5728
		lang = 44;
5949
		lang = 44;
5729
 
5950
 
5730
	CDirIO Dir(m_sCurrentDir);
5951
	CDirIO Dir(m_sCurrentDir);
5731
	if ( !Dir.exists("t") )
5952
	if ( !Dir.exists("t") )
5732
		Dir.Create("t");
5953
		Dir.create("t");
5733
 
5954
 
5734
	m_iLastUpdated = (int)time(NULL);
5955
	m_iLastUpdated = (int)time(NULL);
5735
 
5956
 
5736
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5957
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5737
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5958
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5738
 
5959
 
5739
	std::vector<CyString> writeData;
5960
	std::vector<Utils::String> writeData;
5740
 
5961
 
5741
	CLinkList<SGameWare> lWares;
5962
	CLinkList<SGameWare> lWares;
5742
	CLinkList<SGameShip> lShips;
5963
	CLinkList<SGameShip> lShips;
5743
	for ( int i = 0; i < WAREBUFFERS; i++ )
5964
	for ( int i = 0; i < WAREBUFFERS; i++ )
5744
	{
5965
	{
Line 5755... Line 5976...
5755
		if ( node->Data()->iType == WARETYPE_NONE )
5976
		if ( node->Data()->iType == WARETYPE_NONE )
5756
			continue;
5977
			continue;
5757
		lShips.push_back(node->Data());
5978
		lShips.push_back(node->Data());
5758
	}
5979
	}
5759
 
5980
 
5760
	writeData.push_back(CyString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"));
5981
	writeData.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
5761
	writeData.push_back(CyString("<language id=\"") + CyString::Number(lang) + "\">");
5982
	writeData.push_back("<language id=\"" + Utils::String::Number(lang) + "\">");
5762
 
5983
 
5763
	if ( !gameNumber )
5984
	if ( !gameNumber )
5764
		writeData.push_back(CyString("	<page id=\"") + CyString::Number(PMTEXTFILE) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5985
		writeData.push_back("	<page id=\"" + Utils::String::Number(PMTEXTFILE) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5765
	else
5986
	else
5766
		writeData.push_back(CyString(&quot;	&lt;page id=\"") + (long)gameNumber + CyString::Number(PMTEXTFILE).PadNumber(4) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5987
		writeData.push_back(&quot;	&lt;page id=\"" + (long)gameNumber + Utils::String::PadNumber(PMTEXTFILE, 4) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
5767
 
5988
 
5768
	// write the heading
5989
	// write the heading
5769
	int start = 10000;
5990
	int start = 10000;
5770
	writeData.push_back(CyString("		<t id=\"1\">") + CyString::Number(m_iLastUpdated) + "</t>");
5991
	writeData.push_back("		<t id=\"1\">" + Utils::String::Number(m_iLastUpdated) + "</t>");
5771
	writeData.push_back(CyString("		<t id=\"2\">") + CyString::Number(this->CountPackages(TYPE_SPK, true)) + "</t>");
5992
	writeData.push_back("		<t id=\"2\">" + Utils::String::Number(this->CountPackages(TYPE_SPK, true)) + "</t>");
5772
	writeData.push_back(CyString("		<t id=\"3\">") + CyString::Number(start) + "</t>");
5993
	writeData.push_back("		<t id=\"3\">" + Utils::String::Number(start) + "</t>");
5773
	writeData.push_back(CyString("		<t id=\"4\">") + CyString::Number(lWares.size()) + "</t>");
5994
	writeData.push_back("		<t id=\"4\">" + Utils::String::Number(lWares.size()) + "</t>");
5774
	writeData.push_back(CyString("		<t id=\"6\">") + CyString::Number(lShips.size()) + "</t>");
5995
	writeData.push_back("		<t id=\"6\">" + Utils::String::Number(lShips.size()) + "</t>");
5775
 
5996
 
5776
	// write some generic texts
5997
	// write some generic texts
5777
	writeData.push_back(CyString("		&lt;t id=\&quot;110\&quot;&gt;") + (long)m_iLanguage + "</t>");
5998
	writeData.push_back(&quot;		<;t id=\&quot;110\&quot;&gt;" + Utils::String::Number((long)m_iLanguage) + "</t>");
5778
	writeData.push_back(CyString("		<t id=\"109\">Plugin Manager: \\033GPoll Gui Data\\033X</t>"));
5999
	writeData.push_back("		<t id=\"109\">Plugin Manager: \\033GPoll Gui Data\\033X</t>");
5779
	writeData.push_back(CyString("		<t id=\"107\">Plugin Manager: \\033GExport Game Data\\033X </t>"));
6000
	writeData.push_back("		<t id=\"107\">Plugin Manager: \\033GExport Game Data\\033X </t>");
5780
	writeData.push_back(CyString("		<t id=\"100\">\\n</t>"));
6001
	writeData.push_back("		<t id=\"100\">\\n</t>");
5781
	writeData.push_back(CyString("		<t id=\"101\">\\033B</t>"));
6002
	writeData.push_back("		<t id=\"101\">\\033B</t>");
5782
	writeData.push_back(CyString("		<t id=\"102\">\\033G</t>"));
6003
	writeData.push_back("		<t id=\"102\">\\033G</t>");
5783
	writeData.push_back(CyString("		<t id=\"103\">\\033B</t>"));
6004
	writeData.push_back("		<t id = \"103\">\\033B</t>");
5784
	writeData.push_back(CyString("		<t id=\"104\">\\033X</t>"));
6005
	writeData.push_back("		<t id=\"104\">\\033X</t>");
5785
	writeData.push_back(CyString("		<t id=\"105\">\\033Y</t>"));
6006
	writeData.push_back("		<t id=\"105\">\\033Y</t>");
5786
	writeData.push_back(CyString("		<t id=\"106\">\\033C</t>"));
6007
	writeData.push_back("		<t id=\"106\">\\033C</t>");
5787
	writeData.push_back(CyString("		<t id=\"108\">\\033</t>"));
6008
	writeData.push_back("		<t id=\"108\">\\033</t>");
5788
 
6009
 
5789
	writeData.push_back(CyString("		<t id=\"99998\">[author]Plugin Manager[/author]It appears the plugin manager hasn't been closed properly.  Make sure its closed before running the game otherwise things may not work correctly</t>"));
6010
	writeData.push_back("		<t id=\"99998\">[author]Plugin Manager[/author]It appears the plugin manager hasn't been closed properly.  Make sure its closed before running the game otherwise things may not work correctly</t>");
5790
	writeData.push_back(CyString("		<t id=\"99999\">1</t>"));
6011
	writeData.push_back("		<t id=\"99999\">1</t>");
5791
	// now write each package
6012
	// now write each package
5792
	int settingStart = 100000;
6013
	int settingStart = 100000;
5793
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
6014
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5794
	{
6015
	{
5795
		CBaseFile *p = node->Data();
6016
		CBaseFile *p = node->Data();
Line 5800... Line 6021...
5800
			continue;
6021
			continue;
5801
 
6022
 
5802
		CSpkFile *spk = (CSpkFile *)p;
6023
		CSpkFile *spk = (CSpkFile *)p;
5803
 
6024
 
5804
		// count text files
6025
		// count text files
5805
		CyString textEntries;
6026
		Utils::String textEntries;
5806
		int textCount = 0;
6027
		int textCount = 0;
5807
		C_File *f = p->GetFirstFile(FILETYPE_TEXT);
6028
		C_File *f = p->GetFirstFile(FILETYPE_TEXT);
5808
		while ( f )
6029
		while ( f )
5809
		{
6030
		{
5810
			CyString sLang;
6031
			Utils::String sLang;
5811
			CyString id;
6032
			Utils::String id;
5812
			if ( m_iGameFlags & EXEFLAG_TCTEXT )
6033
			if ( m_iGameFlags & EXEFLAG_TCTEXT )
5813
			{
6034
			{
5814
				id = f->GetBaseName().GetToken("-", 1, 1);
6035
				id = f->baseName().token("-", 1);
5815
				sLang = f->GetBaseName().GetToken("-", 2, 2);
6036
				sLang = f->baseName().token("-", 2);
5816
				if ( sLang.Empty() )
6037
				if ( sLang.empty() )
5817
					sLang = "NULL";
6038
					sLang = "NULL";
5818
				else
6039
				else
5819
					sLang = sLang.Erase(0, 1);  // remove the "L"
6040
					sLang = sLang.erase(0, 1);  // remove the "L"
5820
			}
6041
			}
5821
			else
6042
			else
5822
			{
6043
			{
5823
				sLang = f->GetBaseName().Left((int)f->GetBaseName().Length() - 4).PadNumber(3);
6044
				sLang = f->baseName().left((int)f->baseName().length() - 4).padNumber(3);
5824
				id = f->GetBaseName().Mid(((int)f->GetBaseName().Length() - 4) + 1, 4);
6045
				id = f->baseName().mid(((int)f->baseName().length() - 4) + 1, 4);
5825
			}
6046
			}
5826
 
6047
 
5827
			if ( sLang != "NULL" )
6048
			if ( sLang != "NULL" )
5828
			{
6049
			{
5829
				if ( sLang.ToInt() == lang )
6050
				if ( sLang.toInt() == lang )
5830
				{
6051
				{
5831
					++textCount;
6052
					++textCount;
5832
					if ( !textEntries.Empty() )
6053
					if ( !textEntries.empty() )
5833
						textEntries += " ";
6054
						textEntries += " ";
5834
					textEntries += id;
6055
					textEntries += id;
5835
				}
6056
				}
5836
			}
6057
			}
5837
			f = p->GetNextFile(f);
6058
			f = p->GetNextFile(f);
5838
		}
6059
		}
5839
 
6060
 
5840
		CyString sTextCount((long)textCount);
6061
		Utils::String sTextCount((long)textCount);
5841
		writeData.push_back(CyString("		<t id=\"") + (long)start + "\">" + this->ConvertTextString(p->name()) + "</t>");
6062
		writeData.push_back("		<t id=\"" + Utils::String::Number((long)start) + "\">" + this->ConvertTextString(p->name()) + "</t>");
5842
		writeData.push_back(CyString("		&lt;t id=\"&quot;) + (long)(start + 1) + "\">" + this->ConvertTextString(p->author()) + "</t>");
6063
		writeData.push_back(&quot;		<;t id=\"&quot; + Utils::String::Number((long)(start + 1)) + "\">" + this->ConvertTextString(p->author()) + "</t>");
5843
		writeData.push_back(CyString("		&lt;t id=\"&quot;) + (long)(start + 2) + "\">" + this->ConvertTextString(p->version()) + "</t>");
6064
		writeData.push_back(&quot;		<;t id=\"&quot; + Utils::String::Number((long)(start + 2)) + "\">" + this->ConvertTextString(p->version()) + "</t>");
5844
		writeData.push_back(CyString("		&lt;t id=\"&quot;) + (long)(start + 3) + "\">" + this->ConvertTextString(p->GetLanguageName(lang).ToString()) + "</t>");
6065
		writeData.push_back(&quot;		<;t id=\"&quot; + Utils::String::Number((long)(start + 3)) + "\">" + this->ConvertTextString(p->GetLanguageName(lang).ToString()) + "</t>");
5845
 
6066
 
5846
		CLinkList<SSettingType> *settings = spk->GetSettingsList();
6067
		CLinkList<SSettingType> *settings = spk->GetSettingsList();
5847
		if ( settings && settings->size() )
6068
		if ( settings && settings->size() )
5848
		{
6069
		{
5849
			writeData.push_back(CyString("		<t id=\"") + (long)(start + 4) + "\">" + (long)settings->size() + "</t>");
6070
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 4) + "\">" + (long)settings->size() + "</t>");
5850
			writeData.push_back(CyString("		<t id=\"") + (long)(start + 5) + "\">" + (long)settingStart + "</t>");
6071
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 5) + "\">" + (long)settingStart + "</t>");
5851
 
6072
 
5852
			for ( CListNode<SSettingType> *sNode = settings->Front(); sNode; sNode = sNode->next() )
6073
			for ( CListNode<SSettingType> *sNode = settings->Front(); sNode; sNode = sNode->next() )
5853
			{
6074
			{
5854
				SSettingType *st = sNode->Data();
6075
				SSettingType *st = sNode->Data();
5855
				writeData.push_back(CyString("		<t id=\"") + (long)(settingStart++) + "\">" + st->sKey + "</t>");
6076
				writeData.push_back(Utils::String("		<t id=\"") + (long)(settingStart++) + "\">" + st->sKey + "</t>");
5856
				writeData.push_back(CyString("		<t id=\"") + (long)(settingStart++) + "\">" + spk->GetSetting(st) + "</t>");
6077
				writeData.push_back(Utils::String("		<t id=\"") + (long)(settingStart++) + "\">" + spk->GetSetting(st) + "</t>");
5857
			}
6078
			}
5858
		}
6079
		}
5859
		else
6080
		else
5860
			writeData.push_back(CyString("		<t id=\"") + (long)(start + 4) + "\">0</t>");
6081
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 4) + "\">0</t>");
5861
 
6082
 
5862
		writeData.push_back(CyString("		<t id=\"") + (long)(start + 6) + "\">" + sTextCount + "</t>");
6083
		writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 6) + "\">" + sTextCount + "</t>");
5863
		if ( textCount )
6084
		if ( textCount )
5864
			writeData.push_back(CyString("		<t id=\"") + (long)(start + 7) + "\">" + textEntries + "</t>");
6085
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 7) + "\">" + textEntries + "</t>");
5865
 
6086
 
5866
		start += 10;
6087
		start += 10;
5867
	}
6088
	}
5868
 
6089
 
5869
	// write ware names
6090
	// write ware names
5870
	if ( lWares.size() )
6091
	if ( lWares.size() )
5871
	{
6092
	{
5872
		writeData.push_back(CyString("		<t id=\"5\">") + CyString::Number(start) + "</t>");
6093
		writeData.push_back("		<t id=\"5\">" + Utils::String::Number(start) + "</t>");
5873
		for ( CListNode<SGameWare> *node = lWares.Front(); node; node = node->next() )
6094
		for ( CListNode<SGameWare> *node = lWares.Front(); node; node = node->next() )
5874
		{
6095
		{
5875
			SGameWare *w = node->Data();
6096
			SGameWare *w = node->Data();
5876
			if ( w->pWare && w->iType == WARETYPE_ADDED )
6097
			if ( w->pWare && w->iType == WARETYPE_ADDED )
5877
				writeData.push_back(CyString("		<t id=\"") + (long)start + "\">" + this->ConvertTextString(w->sWareName.ToString()) + "</t>");
6098
				writeData.push_back(Utils::String("		<t id=\"") + (long)start + "\">" + this->ConvertTextString(w->sWareName) + "</t>");
5878
			else
6099
			else
5879
				writeData.push_back(CyString("		<t id=\"") + (long)start + "\">-1</t>");
6100
				writeData.push_back(Utils::String("		<t id=\"") + (long)start + "\">-1</t>");
5880
			writeData.push_back(CyString("		<t id=\"") + (long)(start + 1) + "\">" + CyString((char)w->cType) + "</t>");
6101
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 1) + "\">" + Utils::String((char)w->cType) + "</t>");
5881
			writeData.push_back(CyString("		<t id=\"") + (long)(start + 2) + "\">" + (long)w->iPos + "</t>");
6102
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 2) + "\">" + (long)w->iPos + "</t>");
5882
			start += 10;
6103
			start += 10;
5883
		}
6104
		}
5884
	}
6105
	}
5885
 
6106
 
5886
	if ( lShips.size() )
6107
	if ( lShips.size() )
5887
	{
6108
	{
5888
		writeData.push_back(CyString("		<t id=\"7\">") + CyString::Number(start) + "</t>");
6109
		writeData.push_back("		<t id=\"7\">" + Utils::String::Number(start) + "</t>");
5889
		for ( CListNode<SGameShip> *node = lShips.Front(); node; node = node->next() )
6110
		for ( CListNode<SGameShip> *node = lShips.Front(); node; node = node->next() )
5890
		{
6111
		{
5891
			SGameShip *gs = node->Data();
6112
			SGameShip *gs = node->Data();
5892
			if ( gs->iType == WARETYPE_NONE )
6113
			if ( gs->iType == WARETYPE_NONE )
5893
				continue;
6114
				continue;
5894
			if ( gs->pPackage && gs->iType == WARETYPE_ADDED )
6115
			if ( gs->pPackage && gs->iType == WARETYPE_ADDED )
5895
				writeData.push_back(CyString("		<t id=\"") + (long)start + "\">" + gs->sShipID + "</t>");
6116
				writeData.push_back(Utils::String("		<t id=\"") + (long)start + "\">" + gs->sShipID + "</t>");
5896
			else
6117
			else
5897
				writeData.push_back(CyString("		<t id=\"") + (long)start + "\">-1</t>");
6118
				writeData.push_back(Utils::String("		<t id=\"") + (long)start + "\">-1</t>");
5898
			writeData.push_back(CyString("		<t id=\"") + (long)(start + 1) + "\">" + (long)gs->iPos + "</t>");
6119
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 1) + "\">" + (long)gs->iPos + "</t>");
5899
			writeData.push_back(CyString("		<t id=\"") + (long)(start + 2) + "\">Ship</t>");
6120
			writeData.push_back(Utils::String("		<t id=\"") + (long)(start + 2) + "\">Ship</t>");
5900
 
6121
 
5901
			// write shipyard info
6122
			// write shipyard info
5902
			if ( gs->pPackage )
6123
			if ( gs->pPackage )
5903
			{
6124
			{
5904
				int doStart = start + 5;
6125
				int doStart = start + 5;
5905
				for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
6126
				for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
5906
				{
6127
				{
5907
					writeData.push_back(CyString("		<t id=\"") + (long)(doStart) + "\">" + ((gs->pPackage->IsShipyard(i)) ? CyString::Number(1) : CyString::Number(0)) + "</t>");
6128
					writeData.push_back(Utils::String("		<t id=\"") + (long)(doStart) + "\">" + ((gs->pPackage->IsShipyard(i)) ? Utils::String::Number(1) : Utils::String::Number(0)) + "</t>");
5908
					++doStart;
6129
					++doStart;
5909
				}
6130
				}
5910
			}
6131
			}
5911
 
6132
 
5912
			start += 20;
6133
			start += 20;
5913
		}
6134
		}
5914
	}
6135
	}
5915
 
6136
 
5916
	writeData.push_back(CyString("	</page>"));
6137
	writeData.push_back("	</page>");
-
 
6138
 
-
 
6139
	// do emp
-
 
6140
	if (m_iGame == GAME_X3TC || m_iGame == GAME_X3 || m_iGame == GAME_X3AP || m_iGame == GAME_X3FL)
-
 
6141
	{
-
 
6142
		writeData.push_back("  <page id=\"17\" title=\"Plugin Manager Objects\">");
-
 
6143
		writeData.push_back(GetEMPText());
-
 
6144
		writeData.push_back("  </page>");
-
 
6145
	}
5917
 
6146
 
5918
	// wares
6147
	// wares
5919
	if ( m_iGame == GAME_X3AP || m_iGame == GAME_X3TC || m_iGame == GAME_X3FL || m_iGame == GAME_X3 || lWares.size() || lShips.size() )
6148
	if ( m_iGame == GAME_X3AP || m_iGame == GAME_X3TC || m_iGame == GAME_X3FL || m_iGame == GAME_X3 || lWares.size() || lShips.size() )
5920
	{
6149
	{
-
 
6150
 
5921
		if ( !gameNumber )
6151
		if ( !gameNumber )
5922
			writeData.push_back(CyString("  <page id=\"17\" title=\"Plugin Manager Objects\">"));
6152
			writeData.push_back("  <page id=\"17\" title=\"Plugin Manager Objects\">");
5923
		else
6153
		else
5924
			writeData.push_back(CyString("  <page id=\"") + (long)gameNumber + "0017\" title=\"Plugin Manager Objects\">");
6154
			writeData.push_back(Utils::String("  <page id=\"") + (long)gameNumber + "0017\" title=\"Plugin Manager Objects\">");
5925
 
6155
 
5926
		writeData.push_back(CyString("		<t id=\"") + (long)(SHIPSTARTTEXT - 1) + "\">ZZ_BLANKSHIP</t>");
6156
		writeData.push_back(Utils::String("		<t id=\"") + (long)(SHIPSTARTTEXT - 1) + "\">ZZ_BLANKSHIP</t>");
5927
		// do emp
-
 
5928
		if ( m_iGame == GAME_X3TC || m_iGame == GAME_X3 || m_iGame == GAME_X3AP || m_iGame == GAME_X3FL)
-
 
5929
			writeData.push_back(GetEMPText());
-
 
5930
 
6157
 
5931
		// object names
6158
		// object names
5932
		for ( CListNode<SGameWare> *node = lWares.Front(); node; node = node->next() )
6159
		for ( CListNode<SGameWare> *node = lWares.Front(); node; node = node->next() )
5933
		{
6160
		{
5934
			SGameWare *w = node->Data();
6161
			SGameWare *w = node->Data();
5935
			if ( !w->pWare || w->iType != WARETYPE_ADDED )
6162
			if ( !w->pWare || w->iType != WARETYPE_ADDED )
5936
				continue;
6163
				continue;
5937
 
6164
 
5938
			// find the correct text for the language
6165
			// find the correct text for the language
5939
			Utils::String name = CSpkFile::GetWareText(w->pWare, m_iLanguage);
6166
			Utils::String name = CSpkFile::GetWareText(w->pWare, m_iLanguage);
5940
			Utils::String desc = CSpkFile::GetWareDesc(w->pWare, m_iLanguage);
6167
			Utils::String desc = CSpkFile::GetWareDesc(w->pWare, m_iLanguage);
5941
			if ( !name.empty() )
6168
			if ( !name.empty() )
5942
				writeData.push_back(CyString("		<t id=\"") + (long)(w->iText + 3) + "\">" + this->ConvertTextString(name) + "</t>");
6169
				writeData.push_back(Utils::String("		<t id=\"") + (long)(w->iText + 3) + "\">" + this->ConvertTextString(name) + "</t>");
5943
			if ( !desc.empty() )
6170
			if ( !desc.empty() )
5944
				writeData.push_back(CyString("		<t id=\"") + (long)(w->iText + 4) + "\">" + this->ConvertTextString(desc) + "</t>");
6171
				writeData.push_back(Utils::String("		<t id=\"") + (long)(w->iText + 4) + "\">" + this->ConvertTextString(desc) + "</t>");
5945
		}
6172
		}
5946
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6173
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
5947
		{
6174
		{
5948
			SGameShip *s = node->Data();
6175
			SGameShip *s = node->Data();
5949
			if ( !s->pPackage || s->iType != WARETYPE_ADDED )
6176
			if ( !s->pPackage || s->iType != WARETYPE_ADDED )
Line 5952... Line 6179...
5952
				continue;
6179
				continue;
5953
 
6180
 
5954
			Utils::String name = s->pPackage->GetTextName(m_iLanguage);
6181
			Utils::String name = s->pPackage->GetTextName(m_iLanguage);
5955
			Utils::String desc = s->pPackage->GetTextDescription(m_iLanguage);
6182
			Utils::String desc = s->pPackage->GetTextDescription(m_iLanguage);
5956
			if ( !name.empty() )
6183
			if ( !name.empty() )
5957
				writeData.push_back(CyString("		<t id=\"") + (long)s->iText + "\">" + this->ConvertTextString(name) + "</t>");
6184
				writeData.push_back(Utils::String("		<t id=\"") + (long)s->iText + "\">" + this->ConvertTextString(name) + "</t>");
5958
			if ( !desc.empty() )
6185
			if ( !desc.empty() )
5959
				writeData.push_back(CyString("		<t id=\"") + (long)(s->iText + 1) + "\">" + this->ConvertTextString(desc) + "</t>");
6186
				writeData.push_back(Utils::String("		<t id=\"") + (long)(s->iText + 1) + "\">" + this->ConvertTextString(desc) + "</t>");
5960
		}
6187
		}
5961
		writeData.push_back(CyString("  </page>"));
6188
		writeData.push_back("  </page>");
5962
	}
6189
	}
5963
	writeData.push_back(CyString("</language>"));
6190
	writeData.push_back("</language>");
5964
	textFile.WriteFileUTF(&writeData);
6191
	textFile.writeFileUTF(&writeData);
5965
 
6192
 
5966
	size_t fileSize;
6193
	size_t fileSize;
5967
	char *fileData = CFileIO(textFile.fullFilename()).ReadToData(&fileSize);
6194
	char *fileData = CFileIO(textFile.fullFilename()).ReadToData(&fileSize);
5968
 
6195
 
5969
	if ( fileData && fileSize)
6196
	if ( fileData && fileSize)
Line 5983... Line 6210...
5983
bool CPackages::isCurrentDir(const Utils::String &dir) const
6210
bool CPackages::isCurrentDir(const Utils::String &dir) const
5984
{
6211
{
5985
	Utils::String cur = m_sCurrentDir;
6212
	Utils::String cur = m_sCurrentDir;
5986
 
6213
 
5987
	if ( dir.Compare(cur) )
6214
	if ( dir.Compare(cur) )
5988
		return true;
6215
		return true;
5989
 
6216
 
5990
	Utils::String checkDir = cur;
6217
	Utils::String checkDir = cur;
5991
	checkDir = checkDir.findReplace("/", "\\");
6218
	checkDir = checkDir.findReplace("/", "\\");
5992
	if ( checkDir.Compare(dir) )
6219
	if ( checkDir.Compare(dir) )
5993
		return true;
6220
		return true;
5994
 
6221
 
5995
	checkDir = checkDir.findReplace("\\", "/");
6222
	checkDir = checkDir.findReplace("\\", "/");
5996
	if ( checkDir.Compare(dir) )
6223
	if ( checkDir.Compare(dir) )
5997
		return true;
6224
		return true;
5998
 
6225
 
5999
	return false;
6226
	return false;
6000
}
6227
}
6001
 
6228
 
6002
void CPackages::backupSaves(bool vanilla)
6229
void CPackages::backupSaves(bool vanilla)
6003
{
6230
{
6004
	if (!_sSaveDir.empty())
6231
	if (!_sSaveDir.empty())
6005
	{
6232
	{
6006
		// copy any saves into the vanilla directory
6233
		// copy any saves into the vanilla directory
6007
		Utils::String dir = (vanilla) ? "Vanilla" : "Modified";
6234
		Utils::String dir = (vanilla) ? "Vanilla" : "Modified";
6008
 
6235
 
6009
		// make sure the directory exists
6236
		// make sure the directory exists
6010
		CDirIO saveDir(this->saveDirectory());
6237
		CDirIO saveDir(this->saveDirectory());
6011
		CDirIO gameSaveDir(saveDir.dir(_sSaveDir));
6238
		CDirIO gameSaveDir(saveDir.dir(_sSaveDir));
6012
 
6239
 
6013
		if (!gameSaveDir.exists())
6240
		if (!gameSaveDir.exists())
6014
			gameSaveDir.Create();
6241
			gameSaveDir.create();
6015
		if (!gameSaveDir.exists(dir))
6242
		if (!gameSaveDir.exists(dir))
6016
			gameSaveDir.Create(dir);
6243
			gameSaveDir.create(dir);
6017
		gameSaveDir.cd(dir);
6244
		gameSaveDir.cd(dir);
6018
 
6245
 
6019
		// backup the saves
6246
		// backup the saves
6020
		Utils::CStringList files;
6247
		Utils::CStringList files;
6021
		if(saveDir.dirList(files, Utils::String::Null(), "*.sav"))
6248
		if(saveDir.dirList(files, Utils::String::Null(), "*.sav"))
6022
		{
6249
		{
6023
			for(auto itr = files.begin(); itr != files.end(); ++itr)
6250
			for(auto itr = files.begin(); itr != files.end(); ++itr)
6024
			{
6251
			{
6025
				CFileIO File(saveDir.file((*itr)->str));
6252
				CFileIO File(saveDir.file((*itr)->str));
6026
				if (!File.CheckFileExtension("sav"))
6253
				if (!File.isFileExtension("sav"))
6027
					continue;
6254
					continue;
6028
				// remove the file if already exists
6255
				// remove the file if already exists
6029
				if (gameSaveDir.exists((*itr)->str))
6256
				if (gameSaveDir.exists((*itr)->str))
6030
					CFileIO::Remove(gameSaveDir.file((*itr)->str));
6257
					CFileIO::Remove(gameSaveDir.file((*itr)->str));
6031
 
6258
 
Line 6056... Line 6283...
6056
					for (SStringList *node = files->Head(); node; node = node->next)
6283
					for (SStringList *node = files->Head(); node; node = node->next)
6057
					{
6284
					{
6058
						CFileIO saveFile(toDir.File(node->str));
6285
						CFileIO saveFile(toDir.File(node->str));
6059
						if (saveFile.extension().Compare("sav")) {
6286
						if (saveFile.extension().Compare("sav")) {
6060
							saveFile.remove();
6287
							saveFile.remove();
6061
						}
6288
						}
6062
					}
6289
					}
6063
					delete files;
6290
					delete files;
6064
				}
6291
				}
6065
			}
6292
			}
6066
			*/
6293
			*/
6067
 
6294
 
6068
			// now we copy of the backed up save games
6295
			// now we copy of the backed up save games
6069
			Utils::CStringList files;
6296
			Utils::CStringList files;
6070
			if(restoreDir.dirList(files, Utils::String::Null(), "*.sav"))
6297
			if(restoreDir.dirList(files, Utils::String::Null(), "*.sav"))
6071
			{
6298
			{
6072
				for(auto itr = files.begin(); itr != files.end(); itr++)
6299
				for(auto itr = files.begin(); itr != files.end(); itr++)
6073
				{
6300
				{
6074
					CFileIO File(restoreDir.file((*itr)->str));
6301
					CFileIO File(restoreDir.file((*itr)->str));
6075
					// remove the file if already exists
6302
					// remove the file if already exists
6076
					if (toDir.exists((*itr)->str)) CFileIO::Remove(toDir.file((*itr)->str));
6303
					if (toDir.exists((*itr)->str)) CFileIO::Remove(toDir.file((*itr)->str));
Line 6097... Line 6324...
6097
	this->Reset();
6324
	this->Reset();
6098
	m_bLoaded = false;
6325
	m_bLoaded = false;
6099
 
6326
 
6100
	// clear the plugin manager directory
6327
	// clear the plugin manager directory
6101
	CDirIO Dir(m_sCurrentDir);
6328
	CDirIO Dir(m_sCurrentDir);
6102
	Dir.RemoveDir("PluginManager", true, true, 0);
6329
	Dir.removeDir("PluginManager", true, true, 0);
6103
	Dir.RemoveDir("dds", false, true, 0);
6330
	Dir.removeDir("dds", false, true, 0);
6104
	Dir.RemoveDir("objects", false, true, 0);
6331
	Dir.removeDir("objects", false, true, 0);
6105
	Dir.RemoveDir("types", false, true, 0);
6332
	Dir.removeDir("types", false, true, 0);
6106
	Dir.RemoveDir("textures", false, true, 0);
6333
	Dir.removeDir("textures", false, true, 0);
6107
 
6334
 
6108
	// remove the plugin manager mod files
6335
	// remove the plugin manager mod files
6109
	if ( Dir.exists("mods/PluginManager.cat") )	CFileIO::Remove(Dir.file("mods/PluginManager.cat"));
6336
	if ( Dir.exists("mods/PluginManager.cat") )	CFileIO::Remove(Dir.file("mods/PluginManager.cat"));
6110
	if ( Dir.exists("mods/PluginManager.dat") )	CFileIO::Remove(Dir.file("mods/PluginManager.dat"));
6337
	if ( Dir.exists("mods/PluginManager.dat") )	CFileIO::Remove(Dir.file("mods/PluginManager.dat"));
6111
 
6338
 
Line 6126... Line 6353...
6126
	{
6353
	{
6127
		// read the dummies
6354
		// read the dummies
6128
		CFileIO File;
6355
		CFileIO File;
6129
		if ( File.open((e == -1) ? "Dummies.txt" : m_sTempDir + "/Dummies.txt") )
6356
		if ( File.open((e == -1) ? "Dummies.txt" : m_sTempDir + "/Dummies.txt") )
6130
		{
6357
		{
6131
			std::vector<CyString> *lines = File.ReadLines();
6358
			std::vector<Utils::String> *lines = File.readLines();
6132
			if ( lines )
6359
			if ( lines )
6133
			{
6360
			{
6134
				int insection = 0;
6361
				int insection = 0;
6135
				SDummyEntry *currentSection = NULL;
6362
				SDummyEntry *currentSection = NULL;
6136
				for ( int j = 0; j < (int)lines->size(); j++ )
6363
				for ( int j = 0; j < (int)lines->size(); j++ )
6137
				{
6364
				{
6138
					CyString line(lines->at(j));
6365
					Utils::String line(lines->at(j));
6139
					line.RemoveChar(9);
6366
					line.removeChar(9);
6140
					line.RemoveChar('\r');
6367
					line.removeChar('\r');
6141
					line.RemoveFirstSpace();
6368
					line.removeFirstSpace();
6142
					line.RemoveEndSpace();
6369
					line.removeEndSpace();
6143
					if ( line.Empty() )
6370
					if ( line.empty() )
6144
						continue;
6371
						continue;
6145
					if ( line[0] == '/' )
6372
					if ( line[0] == '/' )
6146
						continue;
6373
						continue;
6147
 
6374
 
6148
					// read the section, first entry is section, second is size
6375
					// read the section, first entry is section, second is size
6149
					while ( !line.Empty() )
6376
					while ( !line.empty() )
6150
					{
6377
					{
6151
						if ( !insection )
6378
						if ( !insection )
6152
						{
6379
						{
6153
							CyString section = line.GetToken(";", 1, 1);
6380
							CyString section = line.token(";", 1);
6154
							insection = line.GetToken(";", 2, 2).ToInt();
6381
							insection = line.token(";", 2).toInt();
6155
 
6382
 
6156
							// search for the sections
6383
							// search for the sections
6157
							currentSection = NULL;
6384
							currentSection = NULL;
6158
							for ( CListNode<SDummyEntry> *node = dummyList.Front(); node; node = node->next() )
6385
							for ( CListNode<SDummyEntry> *node = dummyList.Front(); node; node = node->next() )
6159
							{
6386
							{
Line 6171... Line 6398...
6171
								currentSection->sSection = section;
6398
								currentSection->sSection = section;
6172
								dummyList.push_back(currentSection);
6399
								dummyList.push_back(currentSection);
6173
							}
6400
							}
6174
 
6401
 
6175
							// we have some more ?
6402
							// we have some more ?
6176
							line = line.DelToken(";", 1, 2);
6403
							line = line.remTokens(";", 1, 2);
6177
						}
6404
						}
6178
						else
6405
						else
6179
						{
6406
						{
6180
							--insection;
6407
							--insection;
6181
							// check the last entry for number of states
6408
							// check the last entry for number of states
6182
							if ( currentSection->sSection.Compare("SDTYPE_GUN") )
6409
							if ( currentSection->sSection.Compare("SDTYPE_GUN") )
6183
							{
6410
							{
6184
								int states = line.GetToken(";", 3, 3).ToInt();
6411
								int states = line.token(";", 3).toInt();
6185
								int parts = line.GetToken(";", 4 + (states * 2), 4 + (states * 2)).ToInt();
6412
								int parts = line.token(";", 4 + (states * 2)).toInt();
6186
								CyString data = line.GetToken(";", 1, 4 + (states * 2) + (parts * 2)) + ";";
6413
								Utils::String data = line.tokens(";", 1, 4 + (states * 2) + (parts * 2)) + ";";
6187
								currentSection->lEntries.PushBack(data);
6414
								currentSection->lEntries.PushBack(CyString(data));
6188
 
6415
 
6189
								// remove done
6416
								// remove done
6190
								line = line.DelToken(";", 1, 4 + (states * 2) + (parts * 2));
6417
								line = line.remTokens(";", 1, 4 + (states * 2) + (parts * 2));
6191
							}
6418
							}
6192
							else
6419
							else
6193
							{
6420
							{
6194
								int states = line.GetToken(";", 3, 3).ToInt();
6421
								int states = line.token(";", 3).toInt();
6195
								CyString data = line.GetToken(";", 1, 3 + (states * 2)) + ";";
6422
								Utils::String data = line.tokens(";", 1, 3 + (states * 2)) + ";";
6196
								currentSection->lEntries.PushBack(data);
6423
								currentSection->lEntries.PushBack(CyString(data));
6197
 
6424
 
6198
								// remove done
6425
								// remove done
6199
								line = line.DelToken(";", 1, 3 + (states * 2));
6426
								line = line.remTokens(";", 1, 3 + (states * 2));
6200
							}
6427
							}
6201
						}
6428
						}
6202
					}
6429
					}
6203
				}
6430
				}
6204
 
6431
 
Line 6258... Line 6485...
6258
				found->lEntries.PushBack(CyString(dummy->sData));
6485
				found->lEntries.PushBack(CyString(dummy->sData));
6259
			}
6486
			}
6260
		}
6487
		}
6261
 
6488
 
6262
		// finally, write the file
6489
		// finally, write the file
6263
		std::vector<CyString> lines;
6490
		std::vector<Utils::String> lines;
6264
		lines.push_back(CyString("// Dummies file, created by SPK Libraries V") + CyString::CreateFromFloat(GetLibraryVersion(), 2));
6491
		lines.push_back("// Dummies file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6265
		for ( SDummyEntry *dummy = dummyList.First(); dummy; dummy = dummyList.Next() )
6492
		for ( SDummyEntry *dummy = dummyList.First(); dummy; dummy = dummyList.Next() )
6266
		{
6493
		{
6267
			lines.push_back("");
6494
			lines.push_back("");
6268
			lines.push_back(CyString("// Section: ") + dummy-&gt;sSection + " Entries: " + (long)dummy->lEntries.Count());
6495
			lines.push_back("// Section: " + dummy-&gt;sSection.ToString() + " Entries: " + Utils::String::Number((long)dummy->lEntries.Count()));
6269
			lines.push_back(dummy->sSection + ";" + CyString::Number(dummy->lEntries.Count()) + ";");
6496
			lines.push_back(dummy->sSection.ToString() + ";" + Utils::String::Number(dummy->lEntries.Count()) + ";");
6270
			for ( SStringList *str = dummy->lEntries.Head(); str; str = str->next )
6497
			for ( SStringList *str = dummy->lEntries.Head(); str; str = str->next )
6271
			{
6498
			{
6272
				CyString strLine = str->str;
6499
				Utils::String strLine = str->str.ToString();
6273
				strLine.RemoveChar(9);
6500
				strLine.removeChar(9);
6274
				strLine.RemoveChar('\r');
6501
				strLine.removeChar('\r');
6275
				strLine.RemoveEndSpace();
6502
				strLine.removeEndSpace();
6276
				strLine.RemoveFirstSpace();
6503
				strLine.removeFirstSpace();
6277
				strLine = strLine.FindReplace("<::PiPe::>", "|");
6504
				strLine = strLine.findReplace("<::PiPe::>", "|");
6278
				if ( strLine.Right(1) != ";" )
6505
				if ( strLine.right(1) != ";" )
6279
					strLine += ";";
6506
					strLine += ";";
6280
				lines.push_back(strLine);
6507
				lines.push_back(strLine);
6281
			}
6508
			}
6282
		}
6509
		}
6283
		lines.push_back("");
6510
		lines.push_back("");
6284
 
6511
 
6285
		// write the file to disk
6512
		// write the file to disk
6286
		CFileIO WriteFile(m_sTempDir + "/dummies.txt");
6513
		CFileIO WriteFile(m_sTempDir + "/dummies.txt");
6287
		if ( WriteFile.WriteFile(&lines) )
6514
		if ( WriteFile.writeFile(&lines) )
6288
		{
6515
		{
6289
			this->PackFile(&WriteFile, "types\\dummies.pck");
6516
			this->PackFile(&WriteFile, "types\\dummies.pck");
6290
			WriteFile.remove();
6517
			WriteFile.remove();
6291
		}
6518
		}
6292
	}
6519
	}
Line 6297... Line 6524...
6297
	// first check we have any ships
6524
	// first check we have any ships
6298
	if ( m_lGameShips.empty() || !this->CountPackages(TYPE_XSP, true) )
6525
	if ( m_lGameShips.empty() || !this->CountPackages(TYPE_XSP, true) )
6299
		return;
6526
		return;
6300
 
6527
 
6301
	bool found = false;
6528
	bool found = false;
6302
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6529
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6303
	{
6530
	{
6304
		SGameShip *s = node->Data();
6531
		SGameShip *s = node->Data();
6305
		if ( s->iType != WARETYPE_ADDED || !s->pPackage )
6532
		if ( s->iType != WARETYPE_ADDED || !s->pPackage )
6306
			continue;
6533
			continue;
6307
 
6534
 
6308
		// no dummies to add?
6535
		// no dummies to add?
6309
		if ( !s->pPackage->AnyCutData() )
6536
		if ( !s->pPackage->AnyCutData() )
6310
			continue;
6537
			continue;
6311
		found = true;
6538
		found = true;
6312
		break;
6539
		break;
6313
	}
6540
	}
6314
 
6541
 
6315
	if ( !found )
6542
	if ( !found )
6316
		return;
6543
		return;
6317
 
6544
 
6318
	CyStringList cutList;
6545
	CyStringList cutList;
6319
	int e = ExtractGameFile("types/CutData.pck", m_sTempDir + "/CutData.txt");
6546
	int e = ExtractGameFile("types/CutData.pck", m_sTempDir + "/CutData.txt");
6320
	if ( e )
6547
	if ( e )
6321
	{
6548
	{
6322
		CFileIO File;
6549
		CFileIO File;
6323
		if ( File.open((e == -1) ? "CutData.txt" : m_sTempDir + "/CutData.txt") )
6550
		if ( File.open((e == -1) ? "CutData.txt" : m_sTempDir + "/CutData.txt") )
6324
		{
6551
		{
6325
			std::vector<CyString> *lines = File.ReadLines();
6552
			std::vector<Utils::String> *lines = File.readLines();
6326
			if ( lines )
6553
			if ( lines )
6327
			{
6554
			{
6328
				int entries = -1;
6555
				int entries = -1;
6329
				for ( int j = 0; j < (int)lines->size(); j++ )
6556
				for ( int j = 0; j < (int)lines->size(); j++ )
6330
				{
6557
				{
6331
					CyString line(lines->at(j));
6558
					Utils::String line(lines->at(j));
6332
					line.RemoveChar(9);
6559
					line.removeChar(9);
6333
					line.RemoveChar('\r');
6560
					line.removeChar('\r');
6334
					line.RemoveChar(' ');
6561
					line.removeChar(' ');
6335
					if ( line.Empty() || line[0] == '/' )
6562
					if ( line.empty() || line[0] == '/' )
6336
						continue;
6563
						continue;
6337
					if ( entries == -1 )
6564
					if ( entries == -1 )
6338
						entries = line.GetToken(";", 1, 1).ToInt();
6565
						entries = line.token(";", 1).toInt();
6339
					else
6566
					else
6340
					{
6567
					{
6341
						if ( line.Right(1) != ";" )
6568
						if ( line.right(1) != ";" )
6342
							line += ";";
6569
							line += ";";
6343
						cutList.PushBack(line);
6570
						cutList.PushBack(CyString(line));
6344
						if ( cutList.Count() == entries )
6571
						if ( cutList.Count() == entries )
6345
							break;
6572
							break;
6346
					}
6573
					}
6347
				}
6574
				}
6348
 
6575
 
6349
				delete lines;
6576
				delete lines;
6350
			}
6577
			}
6351
 
6578
 
6352
			File.remove();
6579
			File.remove();
6353
		}
6580
		}
6354
	}
6581
	}
6355
 
6582
 
6356
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6583
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
Line 6381... Line 6608...
6381
	// write the file to disk
6608
	// write the file to disk
6382
	CFileIO WriteFile(m_sTempDir + "/CutData.txt");
6609
	CFileIO WriteFile(m_sTempDir + "/CutData.txt");
6383
	if ( WriteFile.WriteFile(&cutList) )
6610
	if ( WriteFile.WriteFile(&cutList) )
6384
	{
6611
	{
6385
		this->PackFile(&WriteFile, "types\\CutData.pck");
6612
		this->PackFile(&WriteFile, "types\\CutData.pck");
6386
		WriteFile.remove();
6613
		WriteFile.remove();
6387
	}
6614
	}
6388
}
6615
}
6389
 
6616
 
6390
void CPackages::CreateAnimations()
6617
void CPackages::CreateAnimations()
6391
{
6618
{
Line 6415... Line 6642...
6415
	if ( e )
6642
	if ( e )
6416
	{
6643
	{
6417
		CFileIO File;
6644
		CFileIO File;
6418
		if ( File.open((e == -1) ? "Animations.txt" : m_sTempDir + "/Animations.txt") )
6645
		if ( File.open((e == -1) ? "Animations.txt" : m_sTempDir + "/Animations.txt") )
6419
		{
6646
		{
6420
			std::vector<CyString> *lines = File.ReadLines();
6647
			std::vector<Utils::String> *lines = File.readLines();
6421
			if ( lines )
6648
			if ( lines )
6422
			{
6649
			{
6423
				for ( int j = 0; j < (int)lines->size(); j++ )
6650
				for ( int j = 0; j < (int)lines->size(); j++ )
6424
				{
6651
				{
6425
					CyString line(lines->at(j));
6652
					Utils::String line(lines->at(j));
6426
					aniList.PushBack(line);
6653
					aniList.PushBack(CyString(line));
6427
				}
6654
				}
6428
 
6655
 
6429
				delete lines;
6656
				delete lines;
6430
			}
6657
			}
6431
 
6658
 
Line 6438... Line 6665...
6438
 
6665
 
6439
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6666
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6440
	{
6667
	{
6441
		SGameShip *s = node->Data();
6668
		SGameShip *s = node->Data();
6442
		if ( s->iType != WARETYPE_ADDED || !s->pPackage )
6669
		if ( s->iType != WARETYPE_ADDED || !s->pPackage )
6443
			continue;
6670
			continue;
6444
 
6671
 
6445
		// no dummies to add?
6672
		// no dummies to add?
6446
		if ( !s->pPackage->AnyAnimations() )
6673
		if ( !s->pPackage->AnyAnimations() )
6447
			continue;
6674
			continue;
6448
 
6675
 
Line 6472... Line 6699...
6472
		CyString line = strNode->str.GetToken("//", 1, 1);
6699
		CyString line = strNode->str.GetToken("//", 1, 1);
6473
 
6700
 
6474
		// split into seperate lines
6701
		// split into seperate lines
6475
		CyString first = line.GetToken(";", 1, 1);
6702
		CyString first = line.GetToken(";", 1, 1);
6476
		if ( first.Compare("TAT_TAGSINGLESTEP") )
6703
		if ( first.Compare("TAT_TAGSINGLESTEP") )
6477
		{
6704
		{
6478
			formatedAniList.PushBack(line.GetToken(";", 1, 5) + ";");
6705
			formatedAniList.PushBack(line.GetToken(";", 1, 5) + ";");
6479
			int max;
6706
			int max;
6480
			CyString *sLines = line.GetToken(";", 6).SplitToken(";", &max);
6707
			CyString *sLines = line.GetToken(";", 6).SplitToken(";", &max);
6481
			if ( max && sLines )
6708
			if ( max && sLines )
6482
			{
6709
			{
6483
				if ( sLines[max - 1].Empty() )
6710
				if ( sLines[max - 1].Empty() )
6484
					--max; // remove the last ";"
6711
					--max; // remove the last ";"
6485
 
6712
 
6486
				for ( int i = 0; i < max; i++ )
6713
				for ( int i = 0; i < max; i++ )
6487
				{
6714
				{
6488
					CyString l = CyString("\t") + sLines[i] + ";";
6715
					CyString l = CyString("\t") + sLines[i] + ";";
6489
					if ( i == (max - 1) )
6716
					if ( i == (max - 1) )
6490
						formatedAniList.PushBack(l + comment);
6717
						formatedAniList.PushBack(l + comment);
6491
					else
6718
					else
6492
						formatedAniList.PushBack(l);
6719
						formatedAniList.PushBack(l);
6493
				}
6720
				}
6494
			}
6721
			}
6495
			CLEANSPLIT(sLines, max);
6722
			CLEANSPLIT(sLines, max);
6496
		}
6723
		}
6497
		else if ( (first.Compare("TAT_TAGONESHOT") || first.Compare("TAT_TAGLOOP")) && (line.IsIn("TATF_COORDS")) )
6724
		else if ( (first.Compare("TAT_TAGONESHOT") || first.Compare("TAT_TAGLOOP")) && (line.IsIn("TATF_COORDS")) )
6498
		{
6725
		{
6499
			formatedAniList.PushBack(line.GetToken(";", 1, 5) + ";");
6726
			formatedAniList.PushBack(line.GetToken(";", 1, 5) + ";");
6500
			int max;
6727
			int max;
6501
			CyString *sLines = line.GetToken(";", 6).SplitToken(";", &max);
6728
			CyString *sLines = line.GetToken(";", 6).SplitToken(";", &max);
Line 6526... Line 6753...
6526
			formatedAniList.PushBack(line + comment);
6753
			formatedAniList.PushBack(line + comment);
6527
	}
6754
	}
6528
 
6755
 
6529
	formatedAniList.PushFront(CyString::Number(parsedAniList.Count()) + ";");
6756
	formatedAniList.PushFront(CyString::Number(parsedAniList.Count()) + ";");
6530
	formatedAniList.PushFront(CyString("// Animations, created by SPK Libraries V") + CyString::CreateFromFloat(GetLibraryVersion(), 2));
6757
	formatedAniList.PushFront(CyString("// Animations, created by SPK Libraries V") + CyString::CreateFromFloat(GetLibraryVersion(), 2));
6531
 
6758
 
6532
	// write the file to disk
6759
	// write the file to disk
6533
	CFileIO WriteFile(m_sTempDir + "/Animations.txt");
6760
	CFileIO WriteFile(m_sTempDir + "/Animations.txt");
6534
	if ( WriteFile.WriteFile(&formatedAniList) )
6761
	if ( WriteFile.WriteFile(&formatedAniList) )
6535
	{
6762
	{
6536
		this->PackFile(&WriteFile, "types\\Animations.pck");
6763
		this->PackFile(&WriteFile, "types\\Animations.pck");
Line 6568... Line 6795...
6568
	if ( e )
6795
	if ( e )
6569
	{
6796
	{
6570
		CFileIO File;
6797
		CFileIO File;
6571
		if ( File.open((e == -1) ? "Bodies.txt" : m_sTempDir + "/Bodies.txt") )
6798
		if ( File.open((e == -1) ? "Bodies.txt" : m_sTempDir + "/Bodies.txt") )
6572
		{
6799
		{
6573
			std::vector<CyString> *lines = File.ReadLines();
6800
			std::vector<Utils::String> *lines = File.readLines();
6574
			if ( lines )
6801
			if ( lines )
6575
			{
6802
			{
6576
				int entries = 0;
6803
				int entries = 0;
6577
				for ( int j = 0; j < (int)lines->size(); j++ )
6804
				for ( int j = 0; j < (int)lines->size(); j++ )
6578
				{
6805
				{
6579
					CyString line(lines->at(j));
6806
					Utils::String line(lines->at(j));
6580
					line.RemoveChar(' ');
6807
					line.removeChar(' ');
6581
					line.RemoveChar(9);
6808
					line.removeChar(9);
6582
					if ( line.Empty() || line[0] == '/' )
6809
					if ( line.empty() || line[0] == '/' )
6583
						continue;
6810
						continue;
6584
					if ( entries <= 0 )
6811
					if ( entries <= 0 )
6585
					{
6812
					{
6586
						entries = line.GetToken(";", 2, 2).ToInt();
6813
						entries = line.token(";", 2).toInt();
6587
						currentSection = new SBodies;
6814
						currentSection = new SBodies;
6588
						currentSection->sSection = line.GetToken(";", 1, 1);
6815
						currentSection->sSection = line.token(";", 1);
6589
						bodiesList.push_back(currentSection);
6816
						bodiesList.push_back(currentSection);
6590
					}
6817
					}
6591
					else if ( currentSection )
6818
					else if ( currentSection )
6592
					{
6819
					{
6593
						int num;
6820
						int num;
6594
						CyString *strs = line.SplitToken(";", &num);
6821
						Utils::String *strs = line.tokenise(";", &num);
6595
						if ( num && strs )
6822
						if ( num && strs )
6596
						{
6823
						{
6597
							for ( int i = 0; i < num; i++ )
6824
							for ( int i = 0; i < num; i++ )
6598
							{
6825
							{
6599
								if ( strs[i].Empty() )
6826
								if ( strs[i].empty() )
6600
									continue;
6827
									continue;
-
 
6828
								if(!currentSection->lEntries.contains(strs[i] + ";"))
6601
								currentSection->lEntries.PushBack(strs[i] + ";", true);
6829
									currentSection->lEntries.pushBack(strs[i] + ";");
6602
								--entries;
6830
								--entries;
6603
							}
6831
							}
6604
						}
6832
						}
6605
						CLEANSPLIT(strs, num);
6833
						CLEANSPLIT(strs, num);
6606
					}
6834
					}
Line 6633... Line 6861...
6633
 
6861
 
6634
			// find the section to add into
6862
			// find the section to add into
6635
			SBodies *foundSection = NULL;
6863
			SBodies *foundSection = NULL;
6636
			for ( CListNode<SBodies> *checkBody = bodiesList.Front(); checkBody; checkBody = checkBody->next() )
6864
			for ( CListNode<SBodies> *checkBody = bodiesList.Front(); checkBody; checkBody = checkBody->next() )
6637
			{
6865
			{
6638
				if ( checkBody->Data()->sSection.Compare(section) )
6866
				if ( checkBody->Data()->sSection.Compare(section.ToString()))
6639
				{
6867
				{
6640
					foundSection = checkBody->Data();
6868
					foundSection = checkBody->Data();
6641
					break;
6869
					break;
6642
				}
6870
				}
6643
			}
6871
			}
6644
 
6872
 
6645
			if ( !foundSection )
6873
			if ( !foundSection )
6646
			{
6874
			{
6647
				foundSection = new SBodies;
6875
				foundSection = new SBodies;
6648
				foundSection->sSection = section;
6876
				foundSection->sSection = section.ToString();
6649
				bodiesList.push_back(foundSection);
6877
				bodiesList.push_back(foundSection);
6650
			}
6878
			}
-
 
6879
			if(!foundSection->lEntries.contains(body.ToString()))
6651
			foundSection->lEntries.PushBack(body, true);
6880
				foundSection->lEntries.pushBack(body.ToString());
6652
		}
6881
		}
6653
	}
6882
	}
6654
 
6883
 
6655
	// now write the file
6884
	// now write the file
6656
	CyStringList writeList;
6885
	std::vector<Utils::String> writeList;
6657
	// the header first
6886
	// the header first
6658
	writeList.PushBack(CyString("// Bodies file, created by SPK Libraries V") + CyString::CreateFromFloat(GetLibraryVersion(), 2));
6887
	writeList.push_back("// Bodies file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6659
	writeList.PushBack("//body type;num bodies;");
6888
	writeList.push_back("//body type;num bodies;");
6660
	writeList.PushBack("//[body id/name]");
6889
	writeList.push_back("//[body id/name]");
6661
 
6890
 
6662
	// now our sections
6891
	// now our sections
6663
	for ( SBodies *bSection = bodiesList.First(); bSection; bSection = bodiesList.Next() )
6892
	for ( SBodies *bSection = bodiesList.First(); bSection; bSection = bodiesList.Next() )
6664
	{
6893
	{
6665
		writeList.PushBack("");
6894
		writeList.push_back("");
6666
		writeList.PushBack(CyString("// Section: ") + bSection->sSection);
6895
		writeList.push_back("// Section: " + bSection->sSection);
6667
		writeList.PushBack(bSection->sSection + ";" + CyString::Number(bSection->lEntries.Count()) + ";");
6896
		writeList.push_back(bSection->sSection + ";" + Utils::String::Number(bSection->lEntries.size()) + ";");
6668
		for ( SStringList *strNode = bSection->lEntries.Head(); strNode; strNode = strNode->next )
6897
		for(auto itr = bSection->lEntries.begin(); itr != bSection->lEntries.end(); itr++)
6669
		{
6898
		{
6670
			CyString str = strNode->str;
6899
			Utils::String str = (*itr)->str;
6671
			str.RemoveChar(9);
6900
			str.removeChar(9);
6672
			str.RemoveChar(' ');
6901
			str.removeChar(' ');
6673
			if ( str.Right(1) != ";" )
6902
			if ( str.right(1) != ";" )
6674
				str += ";";
6903
				str += ";";
6675
			writeList.PushBack(str);
6904
			writeList.push_back(str);
6676
		}
6905
		}
6677
	}
6906
	}
6678
 
6907
 
6679
	// write the file to disk
6908
	// write the file to disk
6680
	CFileIO WriteFile(m_sTempDir + "/Bodies.txt");
6909
	CFileIO WriteFile(m_sTempDir + "/Bodies.txt");
6681
	if ( WriteFile.WriteFile(&writeList) )
6910
	if ( WriteFile.writeFile(&writeList) )
6682
	{
6911
	{
6683
		this->PackFile(&WriteFile, "types\\Bodies.pck");
6912
		this->PackFile(&WriteFile, "types\\Bodies.pck");
6684
		WriteFile.remove();
6913
		WriteFile.remove();
6685
	}
6914
	}
6686
}
6915
}
6687
 
6916
 
6688
void CPackages::CreateCustomStarts()
6917
void CPackages::CreateCustomStarts()
6689
{
6918
{
6690
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
6919
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
6691
	{
6920
	{
6692
		// find all spk files (only ones that can be custom starts
6921
		// find all spk files (only ones that can be custom starts
6693
		if ( node->Data()->GetType() != TYPE_SPK )
6922
		if ( node->Data()->GetType() != TYPE_SPK )
6694
			continue;
6923
			continue;
6695
 
6924
 
6696
		CSpkFile *p = (CSpkFile *)node->Data();
6925
		CSpkFile *p = (CSpkFile *)node->Data();
6697
 
6926
 
6698
		// only use custom starts
6927
		// only use custom starts
6699
		if ( !p->IsCustomStart() )
6928
		if ( !p->IsCustomStart() )
6700
			continue;
6929
			continue;
6701
 
6930
 
6702
		// get the name of the start to use
6931
		// get the name of the start to use
6703
		CyString name = p->GetCustomStartName();
6932
		CyString name = p->GetCustomStartName();
6704
		if ( name.Empty() )
6933
		if ( name.Empty() )
6705
			continue;
6934
			continue;
6706
 
6935
 
Line 6726... Line 6955...
6726
					CFileIO File((e == -1) ? (str->data + ".pck") : (m_sTempDir + "/" + str->data.ToString() + ".pck"));
6955
					CFileIO File((e == -1) ? (str->data + ".pck") : (m_sTempDir + "/" + str->data.ToString() + ".pck"));
6727
					if ( File.exists() )
6956
					if ( File.exists() )
6728
					{
6957
					{
6729
						File.Rename(m_sCurrentDir + "/" + dir + "/" + str->str.ToString() + ".pck");
6958
						File.Rename(m_sCurrentDir + "/" + dir + "/" + str->str.ToString() + ".pck");
6730
						this->AddCreatedFile(dir + "/" + str->str.ToString() + ".pck");
6959
						this->AddCreatedFile(dir + "/" + str->str.ToString() + ".pck");
6731
					}
6960
					}
6732
				}
6961
				}
6733
			}
6962
			}
6734
		}
6963
		}
6735
	}
6964
	}
6736
}
6965
}
6737
 
6966
 
6738
void CPackages::AddCreatedFile(CyString file)
6967
void CPackages::AddCreatedFile(CyString sFile)
6739
{
6968
{
-
 
6969
	Utils::String file = sFile.ToString();
6740
	file = file.Remove(m_sCurrentDir);
6970
	file = file.findRemove(m_sCurrentDir);
6741
	while ( file[0] == '/' )
6971
	while ( file[0] == '/' )
6742
		file.Erase(0, 1);
6972
		file.erase(0, 1);
6743
	while ( file[0] == '\\' )
6973
	while ( file[0] == '\\' )
6744
		file.Erase(0, 1);
6974
		file.erase(0, 1);
6745
 
6975
 
-
 
6976
	if(!m_lCreatedFiles.contains(file, true))
6746
	m_lCreatedFiles.PushBack(file, true);
6977
		m_lCreatedFiles.pushBack(file);
6747
}
6978
}
6748
 
6979
 
6749
void CPackages::CreateComponants()
6980
void CPackages::CreateComponants()
6750
{
6981
{
6751
	// first check we have any ships
6982
	// first check we have any ships
Line 6760... Line 6991...
6760
	{
6991
	{
6761
		// read the dummies
6992
		// read the dummies
6762
		CFileIO File;
6993
		CFileIO File;
6763
		if ( File.open((e == -1) ? "Components.txt" : m_sTempDir + "/Components.txt") )
6994
		if ( File.open((e == -1) ? "Components.txt" : m_sTempDir + "/Components.txt") )
6764
		{
6995
		{
6765
			std::vector<CyString> *lines = File.ReadLines();
6996
			std::vector<Utils::String> *lines = File.readLines();
6766
			if ( lines )
6997
			if ( lines )
6767
			{
6998
			{
6768
				int insection = 0;
6999
				int insection = 0;
6769
				int insubsection = 0;
7000
				int insubsection = 0;
6770
				SComponantEntry *currentSection = NULL;
7001
				SComponantEntry *currentSection = NULL;
6771
				SComponantEntry2 *currentSubSection = NULL;
7002
				SComponantEntry2 *currentSubSection = NULL;
6772
				for ( int j = 0; j < (int)lines->size(); j++ )
7003
				for ( int j = 0; j < (int)lines->size(); j++ )
6773
				{
7004
				{
6774
					CyString line(lines->at(j));
7005
					Utils::String line(lines->at(j));
6775
					if ( line[0] == '/' )
7006
					if ( line[0] == '/' )
6776
						continue;
7007
						continue;
6777
					line.RemoveChar('\r');
7008
					line.removeChar('\r');
6778
					line = line.RemoveFirstSpace();
7009
					line = line.removeFirstSpace();
6779
					line = line.RemoveEndSpace();
7010
					line = line.removeEndSpace();
6780
					if ( line.Empty() )
7011
					if ( line.empty() )
6781
						continue;
7012
						continue;
6782
 
7013
 
6783
 
7014
 
6784
					// read the section, first entry is section, second is size
7015
					// read the section, first entry is section, second is size
6785
					while ( !line.Empty() )
7016
					while ( !line.empty() )
6786
					{
7017
					{
6787
						line = line.RemoveFirstSpace();
7018
						line = line.removeFirstSpace();
6788
						if ( line.Empty() )
7019
						if ( line.empty() )
6789
							break;
7020
							break;
6790
 
7021
 
6791
						if ( !insection && !insubsection )
7022
						if ( !insection && !insubsection )
6792
						{
7023
						{
6793
							CyString section = line.GetToken(";", 1, 1);
7024
							Utils::String section = line.token(";", 1);
6794
							insection = line.GetToken(";", 2, 2).ToInt();
7025
							insection = line.token(";", 2).toInt();
6795
 
7026
 
6796
							// search for the sections
7027
							// search for the sections
6797
							currentSection = NULL;
7028
							currentSection = NULL;
6798
							for ( CListNode<SComponantEntry> *node = dummyList.Front(); node; node = node->next() )
7029
							for ( CListNode<SComponantEntry> *node = dummyList.Front(); node; node = node->next() )
6799
							{
7030
							{
6800
								SComponantEntry *d = node->Data();
7031
								SComponantEntry *d = node->Data();
6801
								if ( d->sSection.Compare(section) )
7032
								if ( d->sSection.Compare(CyString(section)) )
6802
								{
7033
								{
6803
									currentSection = node->Data();
7034
									currentSection = node->Data();
6804
									break;
7035
									break;
6805
								}
7036
								}
6806
							}
7037
							}
Line 6811... Line 7042...
6811
								currentSection->sSection = section;
7042
								currentSection->sSection = section;
6812
								dummyList.push_back(currentSection);
7043
								dummyList.push_back(currentSection);
6813
							}
7044
							}
6814
 
7045
 
6815
							// we have some more ?
7046
							// we have some more ?
6816
							line = line.DelToken(";", 1, 2);
7047
							line = line.remTokens(";", 1, 2);
6817
						}
7048
						}
6818
						else if ( !insubsection )
7049
						else if ( !insubsection )
6819
						{
7050
						{
6820
							--insection;
7051
							--insection;
6821
							CyString section = line.GetToken(";", 1, 1);
7052
							Utils::String section = line.token(";", 1);
6822
							insubsection = line.GetToken(";", 2, 2).ToInt();
7053
							insubsection = line.token(";", 2).toInt();
6823
 
7054
 
6824
							currentSubSection = new SComponantEntry2;
7055
							currentSubSection = new SComponantEntry2;
6825
							currentSubSection->sSection = section;
7056
							currentSubSection->sSection = section;
6826
							currentSection->lEntries.push_back(currentSubSection);
7057
							currentSection->lEntries.push_back(currentSubSection);
6827
 
7058
 
6828
							line = line.DelToken(";", 1, 2);
7059
							line = line.remTokens(";", 1, 2);
6829
						}
7060
						}
6830
						else
7061
						else
6831
						{
7062
						{
6832
							--insubsection;
7063
							--insubsection;
6833
							currentSubSection->lEntries.PushBack(line.Remove(' '), true);
7064
							currentSubSection->lEntries.PushBack(CyString(line.remove(' ')), true);
6834
							line = "";
7065
							line = "";
6835
						}
7066
						}
6836
					}
7067
					}
6837
				}
7068
				}
6838
 
7069
 
Line 6914... Line 7145...
6914
				found2->lEntries.PushBack(CyString(dummy->sData.remove(' ')));
7145
				found2->lEntries.PushBack(CyString(dummy->sData.remove(' ')));
6915
			}
7146
			}
6916
		}
7147
		}
6917
 
7148
 
6918
		// finally, write the file
7149
		// finally, write the file
6919
		std::vector<CyString> lines;
7150
		std::vector<Utils::String> lines;
6920
		lines.push_back(CyString("// Components file, created by SPK Libraries V") + CyString::CreateFromFloat(GetLibraryVersion(), 2));
7151
		lines.push_back("// Components file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6921
		for ( SComponantEntry *dummy = dummyList.First(); dummy; dummy = dummyList.Next() )
7152
		for ( SComponantEntry *dummy = dummyList.First(); dummy; dummy = dummyList.Next() )
6922
		{
7153
		{
6923
			lines.push_back("");
7154
			lines.push_back("");
6924
			lines.push_back(CyString("// Section: ") + dummy-&gt;sSection + " Entries: " + (long)dummy->lEntries.size());
7155
			lines.push_back("// Section: " + dummy-&gt;sSection.ToString() + " Entries: " + Utils::String::Number((long)dummy->lEntries.size()));
6925
			lines.push_back(dummy->sSection + ";" + CyString::Number(dummy->lEntries.size()) + ";");
7156
			lines.push_back(dummy->sSection.ToString() + ";" + Utils::String::Number(dummy->lEntries.size()) + ";");
6926
			for ( CListNode<SComponantEntry2> *comp = dummy->lEntries.Front(); comp; comp = comp->next() )
7157
			for ( CListNode<SComponantEntry2> *comp = dummy->lEntries.Front(); comp; comp = comp->next() )
6927
			{
7158
			{
6928
				lines.push_back(comp->Data()->sSection + ";&quot; + (long)comp->;Data()->lEntries.Count() + ";");
7159
				lines.push_back(comp->Data()->sSection.ToString() + ";&quot; + Utils::String::Number((long)comp->;Data()->lEntries.Count()) + ";");
6929
				for ( SStringList *str = comp->Data()->lEntries.Head(); str; str = str->next )
7160
				for ( SStringList *str = comp->Data()->lEntries.Head(); str; str = str->next )
6930
				{
7161
				{
6931
					CyString cStr = str->str;
7162
					Utils::String cStr = str->str.ToString();
6932
					cStr.RemoveEndSpace();
7163
					cStr.removeEndSpace();
6933
					cStr.RemoveChar(9);
7164
					cStr.removeChar(9);
6934
					cStr.RemoveChar('\r');
7165
					cStr.removeChar('\r');
6935
					if ( cStr.Right(1) != ";" )
7166
					if ( cStr.right(1) != ";" )
6936
						cStr += ";";
7167
						cStr += ";";
6937
					lines.push_back(cStr);
7168
					lines.push_back(cStr);
6938
				}
7169
				}
6939
			}
7170
			}
6940
		}
7171
		}
6941
 
7172
 
6942
		// write the file to disk
7173
		// write the file to disk
6943
		CFileIO WriteFile(m_sTempDir + "/Components.txt");
7174
		CFileIO WriteFile(m_sTempDir + "/Components.txt");
6944
		if ( WriteFile.WriteFile(&lines) )
7175
		if ( WriteFile.writeFile(&lines) )
6945
		{
7176
		{
6946
			this->PackFile(&WriteFile, "types\\Components.pck");
7177
			this->PackFile(&WriteFile, "types\\Components.pck");
6947
			WriteFile.remove();
7178
			WriteFile.remove();
6948
		}
7179
		}
6949
	}
7180
	}
Line 6952... Line 7183...
6952
bool CPackages::readWares(int iLang, CLinkList<SWareEntry> &list)
7183
bool CPackages::readWares(int iLang, CLinkList<SWareEntry> &list)
6953
{
7184
{
6954
	if ( iLang == 0 ) iLang = m_iLanguage;
7185
	if ( iLang == 0 ) iLang = m_iLanguage;
6955
 
7186
 
6956
	Utils::String empWares = this->empWaresForGame();
7187
	Utils::String empWares = this->empWaresForGame();
6957
 
7188
 
6958
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
7189
	for(CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next()) {
6959
		if ( !node->Data()->IsEnabled() ) continue;
7190
		if ( !node->Data()->IsEnabled() ) continue;
6960
		node->Data()->readWares(iLang, list, empWares);
7191
		node->Data()->readWares(iLang, list, empWares);
6961
	}
7192
	}
6962
 
7193
 
Line 7077... Line 7308...
7077
	{
7308
	{
7078
		CFileIO File((e == -1) ? "Globals.txt" : m_sTempDir + "/Globals.txt");
7309
		CFileIO File((e == -1) ? "Globals.txt" : m_sTempDir + "/Globals.txt");
7079
		if ( File.exists() )
7310
		if ( File.exists() )
7080
		{
7311
		{
7081
			CyStringList *lines = File.ReadLinesStr();
7312
			CyStringList *lines = File.ReadLinesStr();
7082
			if ( lines )
7313
			if ( lines )
7083
			{
7314
			{
7084
				int entries = -1;
7315
				int entries = -1;
7085
				for ( SStringList *str = lines->Head(); str; str = str->next )
7316
				for ( SStringList *str = lines->Head(); str; str = str->next )
7086
				{
7317
				{
7087
					str->str.RemoveChar('\r');
7318
					str->str.RemoveChar('\r');
Line 7106... Line 7337...
7106
 
7337
 
7107
				delete lines;
7338
				delete lines;
7108
 
7339
 
7109
				return true;
7340
				return true;
7110
			}
7341
			}
7111
		}
7342
		}
7112
	}
7343
	}
7113
 
7344
 
7114
	return false;
7345
	return false;
7115
}
7346
}
7116
 
7347
 
7117
void CPackages::CreateGlobals()
7348
void CPackages::CreateGlobals()
7118
{
7349
{
7119
	if ( m_lGlobals.Empty() )
7350
	if ( m_lGlobals.empty() )
7120
		return; // no global settings
7351
		return; // no global settings
7121
 
7352
 
7122
	CyStringList globals;
7353
	CyStringList globals;
7123
	if ( ReadGlobals(globals) )
7354
	if ( ReadGlobals(globals) )
7124
	{
7355
	{
7125
		// apply out settings
7356
		// apply out settings
7126
		for ( SStringList *str = m_lGlobals.Head(); str; str = str->;next )
7357
		for(auto itr = m_lGlobals.begin(); itr != m_lGlobals.end(); itr++)
7127
		{
7358
		{
7128
			SStringList *found = globals.FindString(str->str);
7359
			SStringList *found = globals.FindString((*itr)->str);
7129
			if ( found )
7360
			if ( found )
7130
				found->data = str->data;
7361
				found->data = (*itr)->data;
7131
		}
7362
		}
7132
 
7363
 
7133
		// now write it
7364
		// now write it
7134
		CyStringList writeList;
7365
		CyStringList writeList;
7135
		for ( SStringList *str = globals.Head(); str; str = str->next )
7366
		for ( SStringList *str = globals.Head(); str; str = str->next )
7136
			writeList.PushBack(str->str + ";" + str->data + ";");
7367
			writeList.PushBack(str->str + ";" + str->data + ";");
Line 7142... Line 7373...
7142
		CFileIO WriteFile(m_sTempDir + "/Globals.txt");
7373
		CFileIO WriteFile(m_sTempDir + "/Globals.txt");
7143
		if ( WriteFile.WriteFile(&writeList) )
7374
		if ( WriteFile.WriteFile(&writeList) )
7144
		{
7375
		{
7145
			this->PackFile(&WriteFile, "types/Globals.pck");
7376
			this->PackFile(&WriteFile, "types/Globals.pck");
7146
			WriteFile.remove();
7377
			WriteFile.remove();
7147
		}
7378
		}
7148
	}
7379
	}
7149
}
7380
}
7150
 
7381
 
7151
void CPackages::CreateTShips()
7382
void CPackages::CreateTShips()
7152
{
7383
{
7153
	// no ships ?
7384
	// no ships ?
7154
	if ( m_lGameShips.empty() )
7385
	if ( m_lGameShips.empty() )
7155
		return;
7386
		return;
7156
 
7387
 
7157
	// get the cockpit list to match with ships turrets
7388
	// get the cockpit list to match with ships turrets
7158
	CyStringList Cockpits;
7389
	CyStringList Cockpits;
7159
	CyStringList *cockpitList = this->CreateCockpits();
7390
	CyStringList *cockpitList = this->CreateCockpits();
7160
	if ( cockpitList )
7391
	if ( cockpitList )
7161
	{
7392
	{
Line 7182... Line 7413...
7182
	int e = ExtractGameFile("types/TShips.pck", m_sTempDir + "/TShips.txt");
7413
	int e = ExtractGameFile("types/TShips.pck", m_sTempDir + "/TShips.txt");
7183
	if ( e )
7414
	if ( e )
7184
	{
7415
	{
7185
		int fileType = 51;
7416
		int fileType = 51;
7186
		CyStringList tshipsList;
7417
		CyStringList tshipsList;
7187
 
7418
 
7188
		// if we have no buffer, lets create one
7419
		// if we have no buffer, lets create one
7189
		CFileIO File;
7420
		CFileIO File;
7190
		if ( File.open((e == -1) ? "TShips.txt" : m_sTempDir + "/TShips.txt") )
7421
		if ( File.open((e == -1) ? "TShips.txt" : m_sTempDir + "/TShips.txt") )
7191
		{
7422
		{
7192
			int shiptext = SHIPSTARTTEXT;
7423
			int shiptext = SHIPSTARTTEXT;
7193
 
7424
 
7194
			std::vector<CyString> *lines = File.ReadLines();
7425
			std::vector<Utils::String> *lines = File.readLines();
7195
			if ( lines )
7426
			if ( lines )
7196
			{
7427
			{
7197
				int count = -1;
7428
				int count = -1;
7198
				for ( int j = 0; j < (int)lines->size(); j++ )
7429
				for ( int j = 0; j < (int)lines->size(); j++ )
7199
				{
7430
				{
7200
					CyString line(lines->at(j));
7431
					Utils::String line(lines->at(j));
7201
					if ( line[0] == '/' )
7432
					if ( line[0] == '/' )
7202
						continue;
7433
						continue;
7203
					line.RemoveChar('\r');
7434
					line.removeChar('\r');
7204
					line.RemoveChar(9);
7435
					line.removeChar(9);
7205
					line = line.RemoveFirstSpace();
7436
					line = line.removeFirstSpace();
7206
					line = line.RemoveEndSpace();
7437
					line = line.removeEndSpace();
7207
					if ( line.Empty() )
7438
					if ( line.empty() )
7208
						continue;
7439
						continue;
7209
 
7440
 
7210
					if ( count == -1 )
7441
					if ( count == -1 )
7211
					{
7442
					{
7212
						fileType = line.GetToken(";", 1, 1).ToInt();
7443
						fileType = line.token(";", 1).toInt();
7213
						count = line.GetToken(";", 2, 2).ToInt();
7444
						count = line.token(";", 2).toInt();
7214
					}
7445
					}
7215
					else
7446
					else
7216
					{
7447
					{
7217
						if ( line.Right(1) != ";" )
7448
						if ( line.right(1) != ";" )
7218
							line += ";";
7449
							line += ";";
7219
 
7450
 
7220
						// check for any ship overrides
7451
						// check for any ship overrides
7221
						bool added = false;
7452
						bool added = false;
7222
						if ( !shipOverrides.empty() )
7453
						if ( !shipOverrides.empty() )
Line 7240... Line 7471...
7240
								}
7471
								}
7241
							}
7472
							}
7242
						}
7473
						}
7243
 
7474
 
7244
						if ( !added )
7475
						if ( !added )
7245
							tshipsList.PushBack(line);
7476
							tshipsList.PushBack(CyString(line));
7246
						--count;
7477
						--count;
7247
						if ( count < 0 )
7478
						if ( count < 0 )
7248
							break;
7479
							break;
7249
					}
7480
					}
7250
				}
7481
				}
Line 7320... Line 7551...
7320
	{
7551
	{
7321
		size_t newFileSize;
7552
		size_t newFileSize;
7322
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7553
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7323
		if ( pckData )
7554
		if ( pckData )
7324
		{
7555
		{
7325
			CyString ext = "pck";
7556
			Utils::String ext = "pck";
7326
			if ( File.CheckFileExtension("bob") )
7557
			if ( File.isFileExtension("bob") )
7327
				ext = "pbb";
7558
				ext = "pbb";
7328
			else if ( File.CheckFileExtension("bod") )
7559
			else if ( File.isFileExtension("bod") )
7329
				ext = "pbd";
7560
				ext = "pbd";
7330
			CFileIO pckFile(File.ChangeFileExtension(ext));
7561
			CFileIO pckFile(File.changeFileExtension(ext));
7331
			if ( !CDirIO(pckFile.dir()).exists() )
7562
			if ( !CDirIO(pckFile.dir()).exists() )
7332
				CDirIO(pckFile.dir()).Create();
7563
				CDirIO(pckFile.dir()).create();
7333
			pckFile.WriteData((char *)pckData, newFileSize);
7564
			pckFile.WriteData((char *)pckData, newFileSize);
7334
			return true;
7565
			return true;
7335
		}
7566
		}
7336
	}
7567
	}
7337
 
7568
 
Line 7352... Line 7583...
7352
		if ( !pckData )
7583
		if ( !pckData )
7353
			pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7584
			pckData = UnPCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7354
 
7585
 
7355
		if ( pckData )
7586
		if ( pckData )
7356
		{
7587
		{
7357
			CyString ext = "txt";
7588
			Utils::String ext = "txt";
7358
			if ( File.CheckFileExtension("pbb") )
7589
			if ( File.isFileExtension("pbb") )
7359
				ext = "bob";
7590
				ext = "bob";
7360
			else if ( File.CheckFileExtension("pbd") )
7591
			else if ( File.isFileExtension("pbd") )
7361
				ext = "bod";
7592
				ext = "bod";
7362
			CFileIO pckFile(File.ChangeFileExtension(ext));
7593
			CFileIO pckFile(File.changeFileExtension(ext));
7363
			if ( !CDirIO(pckFile.dir()).exists() )
7594
			if ( !CDirIO(pckFile.dir()).exists() )
7364
				CDirIO(pckFile.dir()).Create();
7595
				CDirIO(pckFile.dir()).create();
7365
			pckFile.WriteData((char *)pckData, newFileSize);
7596
			pckFile.WriteData((char *)pckData, newFileSize);
7366
 
7597
 
7367
			// check for xml and rename
7598
			// check for xml and rename
7368
			if ( checkxml )
7599
			if ( checkxml )
7369
			{
7600
			{
Line 7434... Line 7665...
7434
			{
7665
			{
7435
//				if ( !this->GetAddonDir().Empty() && CCatFile::IsAddonDir(filename) )
7666
//				if ( !this->GetAddonDir().Empty() && CCatFile::IsAddonDir(filename) )
7436
//					filename = this->GetAddonDir() + "/" + filename;
7667
//					filename = this->GetAddonDir() + "/" + filename;
7437
				CFileIO pckFile(m_sCurrentDir + "/" + filename);
7668
				CFileIO pckFile(m_sCurrentDir + "/" + filename);
7438
				if ( !CDirIO(pckFile.dir()).exists() )
7669
				if ( !CDirIO(pckFile.dir()).exists() )
7439
					CDirIO(pckFile.dir()).Create();
7670
					CDirIO(pckFile.dir()).create();
7440
				pckFile.WriteData((char *)pckData, newFileSize);
7671
				pckFile.WriteData((char *)pckData, newFileSize);
7441
				this->AddCreatedFile(pckFile.fullFilename());
7672
				this->AddCreatedFile(pckFile.fullFilename());
7442
				return true;
7673
				return true;
7443
			}
7674
			}
7444
		}
7675
		}
Line 8080... Line 8311...
8080
{
8311
{
8081
	CFileIO File;
8312
	CFileIO File;
8082
	bool deleteFile = false;
8313
	bool deleteFile = false;
8083
 
8314
 
8084
	// load from cat file
8315
	// load from cat file
8085
	if ( CFileIO(file).CheckFileExtension("cat") )
8316
	if ( CFileIO(file).isFileExtension("cat") )
8086
	{
8317
	{
8087
		CCatFile cat;
8318
		CCatFile cat;
8088
		if ( cat.open(file.ToString(), this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
8319
		if ( cat.open(file.ToString(), this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
8089
			return false;
8320
			return false;
8090
 
8321
 
Line 8093... Line 8324...
8093
 
8324
 
8094
		File.open(m_sTempDir + "/tships.txt");
8325
		File.open(m_sTempDir + "/tships.txt");
8095
		deleteFile = true;
8326
		deleteFile = true;
8096
	}
8327
	}
8097
	// otherwise its a normal file
8328
	// otherwise its a normal file
8098
	else if ( CFileIO(file).CheckFileExtension("pck") )
8329
	else if ( CFileIO(file).isFileExtension("pck") )
8099
	{
8330
	{
8100
		C_File f(file.ToString());
8331
		C_File f(file.ToString());
8101
		if ( !f.ReadFromFile() )
8332
		if ( !f.ReadFromFile() )
8102
			return false;
8333
			return false;
8103
		f.UnPCKFile();
8334
		f.UnPCKFile();
Line 8187... Line 8418...
8187
{
8418
{
8188
	CFileIO File;
8419
	CFileIO File;
8189
	bool deleteFile = false;
8420
	bool deleteFile = false;
8190
 
8421
 
8191
	// read all text files from mod
8422
	// read all text files from mod
8192
	if ( CFileIO(file).CheckFileExtension("cat") )
8423
	if ( CFileIO(file).isFileExtension("cat") )
8193
	{
8424
	{
8194
		bool done = false;
8425
		bool done = false;
8195
 
8426
 
8196
		CCatFile cat;
8427
		CCatFile cat;
8197
		if ( cat.open(file.ToString(), this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
8428
		if ( cat.open(file.ToString(), this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
Line 8230... Line 8461...
8230
		}
8461
		}
8231
 
8462
 
8232
		return done;
8463
		return done;
8233
	}
8464
	}
8234
	// otherwise its a normal file
8465
	// otherwise its a normal file
8235
	else if ( CFileIO(file).CheckFileExtension("pck") )
8466
	else if ( CFileIO(file).isFileExtension("pck") )
8236
	{
8467
	{
8237
		C_File f(file.ToString());
8468
		C_File f(file.ToString());
8238
		if ( !f.ReadFromFile() )
8469
		if ( !f.ReadFromFile() )
8239
			return false;
8470
			return false;
8240
		f.UnPCKFile();
8471
		f.UnPCKFile();
Line 8338... Line 8569...
8338
int CPackages::AdjustFileType(CyString file, int filetype)
8569
int CPackages::AdjustFileType(CyString file, int filetype)
8339
{
8570
{
8340
	CFileIO File(file);
8571
	CFileIO File(file);
8341
	Utils::String dir = File.GetDirIO().topDir();
8572
	Utils::String dir = File.GetDirIO().topDir();
8342
	CyString basename = File.baseName();
8573
	CyString basename = File.baseName();
-
 
8574
 
-
 
8575
	Utils::String ext = File.extension();
8343
 
8576
 
8344
	// mod files
8577
	// mod files
8345
	if ( File.CheckFileExtension("cat") || File.CheckFileExtension("dat") )
8578
	if (ext.Compare("cat") || ext.Compare("dat"))
8346
		return FILETYPE_MOD;
8579
		return FILETYPE_MOD;
8347
	// check for text files
8580
	// check for text files
8348
	if ( File.filename().isin("-L") && File.filename().left(4).isNumber() )
8581
	if ( File.filename().isin("-L") && File.filename().left(4).isNumber() )
8349
		return FILETYPE_TEXT;
8582
		return FILETYPE_TEXT;
8350
	if ( File.baseName().Compare("conversations") )
8583
	if ( File.baseName().Compare("conversations") )
8351
		return FILETYPE_TEXT;
8584
		return FILETYPE_TEXT;
8352
	if ( basename.Length() <= 4 && basename.IsNumber() && (File.CheckFileExtension("xml") || File.CheckFileExtension("pck")) )
8585
	if ( basename.Length() <= 4 && basename.IsNumber() && (File.isFileExtension("xml") || File.isFileExtension("pck")) )
8353
		return FILETYPE_TEXT;
8586
		return FILETYPE_TEXT;
8354
	// X2/X3 text file
8587
	// X2/X3 text file
8355
	if ( basename.Length() >= 5 && basename.Length() <= 8 && ((int)File.baseName()) )
8588
	if ( basename.Length() >= 5 && basename.Length() <= 8 && ((int)File.baseName()) )
8356
		return FILETYPE_TEXT;
8589
		return FILETYPE_TEXT;
8357
	if ( filetype == FILETYPE_TEXT ) // should no longer be anything text
8590
	if ( filetype == FILETYPE_TEXT ) // should no longer be anything text
8358
		return FILETYPE_SCRIPT;
8591
		return FILETYPE_SCRIPT;
8359
	if ( File.CheckFileExtension("wav") || File.CheckFileExtension("mp3") )
8592
	if ( File.isFileExtension("wav") || File.isFileExtension("mp3") )
8360
		return FILETYPE_SOUND;
8593
		return FILETYPE_SOUND;
8361
	return filetype;
8594
	return filetype;
8362
}
8595
}
8363
 
8596
 
8364
void CPackages::RemoveFailedFiles()
8597
void CPackages::RemoveFailedFiles()
8365
{
8598
{
-
 
8599
	Utils::CStringList removed;
8366
	for ( SStringList *str = m_lNonRemovedFiles.Head(); str; str = str->next )
8600
	for (auto itr = m_lNonRemovedFiles.begin(); itr != m_lNonRemovedFiles.end(); itr++)
8367
	{
8601
	{
8368
		if ( CFileIO::Remove(str->str.ToString()) )
8602
		if (CFileIO::Remove((*itr)->str))
8369
			str->remove = true;
8603
			removed.pushBack((*itr)->str);
8370
	}
8604
	}
8371
 
-
 
-
 
8605
	for (auto itr = removed.begin(); itr != removed.end(); itr++)
8372
	m_lNonRemovedFiles.RemoveMarked();
8606
		m_lNonRemovedFiles.remove((*itr)->str);
8373
}
8607
}
8374
 
8608
 
8375
CXspFile *CPackages::extractShip(const Utils::String &sCatFile, const Utils::String &sId, CProgressInfo *progress)
8609
CXspFile *CPackages::extractShip(const Utils::String &sCatFile, const Utils::String &sId, CProgressInfo *progress)
8376
{
8610
{
8377
	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
8611
	CVirtualFileSystem *pVfs = new CVirtualFileSystem();
8378
	if ( !pVfs->addMod(sCatFile) ) {
8612
	if ( !pVfs->addMod(sCatFile) ) {
8379
		delete pVfs;
8613
		delete pVfs;
8380
		return NULL;
8614
		return NULL;
8381
	}
8615
	}
8382
 
8616
 
8383
	CXspFile *newShip = new CXspFile;
8617
	CXspFile *newShip = new CXspFile;
8384
	if ( !newShip->extractShip(pVfs, sId, progress) ) {
8618
	if ( !newShip->extractShip(pVfs, sId, progress) ) {
8385
		delete newShip;
8619
		delete newShip;
8386
		newShip = NULL;
8620
		newShip = NULL;
8387
	}
8621
	}
8388
 
8622
 
8389
	delete pVfs;
8623
	delete pVfs;
8390
 
8624
 
8391
	return newShip;
8625
	return newShip;
8392
}
8626
}
8393
 
8627
 
8394
void CPackages::getMergedFiles(Utils::CStringList &list, CCatFile *cat1, CCatFile *cat2)
8628
void CPackages::getMergedFiles(Utils::CStringList &list, CCatFile *cat1, CCatFile *cat2)
8395
{
8629
{
8396
	// first add all files from the "primary" mod
8630
	// first add all files from the "primary" mod
8397
	for (auto itr = cat1->GetFiles()->cbegin(); itr != cat1->GetFiles()->cend(); itr++)
8631
	for (auto itr = cat1->GetFiles()->cbegin(); itr != cat1->GetFiles()->cend(); itr++)
Line 8470... Line 8704...
8470
			{
8704
			{
8471
				if ( !newCat.WriteFromCat(mod1, (*itr)->str) )
8705
				if ( !newCat.WriteFromCat(mod1, (*itr)->str) )
8472
				{
8706
				{
8473
					if ( cantMerge )
8707
					if ( cantMerge )
8474
						cantMerge->PushBack(CyString((*itr)->str), "1");
8708
						cantMerge->PushBack(CyString((*itr)->str), "1");
8475
				}
8709
				}
8476
			}
8710
			}
8477
		}
8711
		}
8478
	}
8712
	}
8479
 
8713
 
8480
	/* 
8714
	/* 
8481
		Merging Files
8715
		Merging Files
8482
 
8716
 
8483
		* Text Files: Join all text entries into a single file (excluding page 17)
8717
		* Text Files: Join all text entries into a single file (excluding page 17)
8484
		* Weapons: TBullets and TLaser (grab matching entrys from text files and adjust ids)
8718
		* Weapons: TBullets and TLaser (grab matching entrys from text files and adjust ids)
8485
	*/
8719
	*/
8486
	// new merge the conflicting files
8720
	// new merge the conflicting files
8487
	// first the text files
8721
	// first the text files
Line 8492... Line 8726...
8492
	if ( !newCat.WriteCatFile() )
8726
	if ( !newCat.WriteCatFile() )
8493
		return false;
8727
		return false;
8494
 
8728
 
8495
	return true;
8729
	return true;
8496
}
8730
}
8497
 
8731
 
8498
/**
8732
/**
8499
 * Gets the file list from a mod that might have compatability problems
8733
 * Gets the file list from a mod that might have compatability problems
8500
 *
8734
 *
8501
 * This includes all types and text files
8735
 * This includes all types and text files
8502
 *
8736
 *
Line 8512... Line 8746...
8512
	// we need to read the file list for the mod
8746
	// we need to read the file list for the mod
8513
	CCatFile cat;
8747
	CCatFile cat;
8514
	if ( cat.open(file->filePointer(), this->getAddonDir(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
8748
	if ( cat.open(file->filePointer(), this->getAddonDir(), CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
8515
	{
8749
	{
8516
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8750
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8517
		{
8751
		{
8518
			SInCatFile *f = cat.GetFile(i);
8752
			SInCatFile *f = cat.GetFile(i);
8519
			CyString filename = f->sFile;
8753
			CyString filename = f->sFile;
8520
			filename = filename.FindReplace("\\", "/");
8754
			filename = filename.FindReplace("\\", "/");
8521
			bool found = false;
8755
			bool found = false;
8522
			if ( filename.Left(2).Compare("t/") || filename.Left(6).Compare("types/") )
8756
			if ( filename.Left(2).Compare("t/") || filename.Left(6).Compare("types/") )
Line 8637... Line 8871...
8637
		if ( !f->IsFakePatch() ) continue;
8871
		if ( !f->IsFakePatch() ) continue;
8638
		if ( !f->CheckFileExt("cat") ) continue;
8872
		if ( !f->CheckFileExt("cat") ) continue;
8639
 
8873
 
8640
		if ( newFile->ExtractFile(f, m_sTempDir) )
8874
		if ( newFile->ExtractFile(f, m_sTempDir) )
8641
			f->SetFullDir(m_sTempDir);
8875
			f->SetFullDir(m_sTempDir);
8642
	}
8876
	}
8643
 
8877
 
8644
	// compare mod files against all installed packages
8878
	// compare mod files against all installed packages
8645
	int count = 0;
8879
	int count = 0;
8646
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
8880
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
8647
	{
8881
	{
8648
		if ( !node->Data() ) continue;
8882
		if ( !node->Data() ) continue;
8649
		CBaseFile *p = node->Data();
8883
		CBaseFile *p = node->Data();
8650
		if ( !p->IsEnabled() ) continue;
8884
		if ( !p->IsEnabled() ) continue;
8651
		if ( !p->AnyFileType(FILETYPE_MOD) ) continue;
8885
		if ( !p->AnyFileType(FILETYPE_MOD) ) continue;
8652
 
8886
 
8653
		if ( this->IsSamePackage(p, newFile) ) continue; // dont include self
8887
		if ( this->IsSamePackage(p, newFile) ) continue; // dont include self
8654
 
8888
 
8655
		if ( CheckCompatabilityBetweenMods(newFile, p, list) )
8889
		if ( CheckCompatabilityBetweenMods(newFile, p, list) )
8656
		{
8890
		{
8657
			++count;
8891
			++count;
8658
			if ( packages && !packages->FindData(p) )
8892
			if ( packages && !packages->FindData(p) )
8659
				packages->push_back(p);
8893
				packages->push_back(p);
Line 8664... Line 8898...
8664
	{
8898
	{
8665
		C_File *f = fNode->Data();
8899
		C_File *f = fNode->Data();
8666
		CFileIO::Remove(f->filePointer());
8900
		CFileIO::Remove(f->filePointer());
8667
		f->SetFullDir("");
8901
		f->SetFullDir("");
8668
	}
8902
	}
8669
 
8903
 
8670
	return count;
8904
	return count;
8671
}
8905
}
8672
 
8906
 
8673
bool CPackages::IsSamePackage(CBaseFile *p1, CBaseFile *p2)
8907
bool CPackages::IsSamePackage(CBaseFile *p1, CBaseFile *p2)
8674
{
8908
{
8675
	if ( !p1 || !p2 ) return false;
8909
	if ( !p1 || !p2 ) return false;
8676
	if ( p1 == p2 ) return true;
8910
	if ( p1 == p2 ) return true;
8677
 
8911
 
8678
	if ( p1->name().Compare(p2->name()) && p1->author().Compare(p2->author()) )
8912
	if ( p1->name().Compare(p2->name()) && p1->author().Compare(p2->author()) )
8679
		return true;
8913
		return true;
8680
	return false;
8914
	return false;
8681
}
8915
}
8682
 
8916
 
8683
void CPackages::ApplyFakePatchOrder(CyStringList *list)
8917
void CPackages::ApplyFakePatchOrder(Utils::CStringList *list)
8684
{
8918
{
8685
	if ( !list ) return;
8919
	if ( !list ) return;
8686
	m_lFakePatchOrder.Clear();
8920
	m_lFakePatchOrder.clear();
8687
	for ( SStringList *str = list->;Head(); str; str = str->next )
8921
	for(auto itr = list->;begin(); itr != list->end(); itr++)
8688
		m_lFakePatchOrder.PushBack(str->str, str->data);
8922
		m_lFakePatchOrder.pushBack((*itr)->str, (*itr)->data);
8689
}
8923
}
8690
 
8924
 
8691
SAvailablePackage *CPackages::CreateAvailablePackageData(CBaseFile *package)
8925
SAvailablePackage *CPackages::CreateAvailablePackageData(CBaseFile *package)
8692
{
8926
{
8693
	if ( !package ) return NULL;
8927
	if ( !package ) return NULL;
Line 8909... Line 9143...
8909
		File.close();
9143
		File.close();
8910
	}
9144
	}
8911
 
9145
 
8912
	list->PushBack("http://xpluginmanager.co.uk/tcscripts", true);
9146
	list->PushBack("http://xpluginmanager.co.uk/tcscripts", true);
8913
	list->PushBack("http://xpluginmanager.co.uk/apscripts", true);
9147
	list->PushBack("http://xpluginmanager.co.uk/apscripts", true);
-
 
9148
	list->PushBack("http://xpluginmanager.co.uk/flscripts", true);
8914
 
9149
 
8915
	return list->Count();
9150
	return list->Count();
8916
}
9151
}
8917
 
9152
 
8918
void CPackages::ReadArchiveData(CyString filename, CBaseFile *archive)
9153
void CPackages::ReadArchiveData(CyString filename, CBaseFile *archive)
Line 9043... Line 9278...
9043
 
9278
 
9044
	HeaderData.CmtBuf=NULL;
9279
	HeaderData.CmtBuf=NULL;
9045
	memset(&OpenArchiveData.Reserved,0,sizeof(OpenArchiveData.Reserved));
9280
	memset(&OpenArchiveData.Reserved,0,sizeof(OpenArchiveData.Reserved));
9046
 
9281
 
9047
	bool error = false;
9282
	bool error = false;
9048
	CyString extractedFile = CDirIO(m_sTempDir).File("extracted.tst").findreplace("/", "\\").findreplace("\\\\", "\\");
9283
	Utils::String extractedFile = CDirIO(m_sTempDir).file("extracted.tst").findReplace("/", "\\").findReplace("\\\\", "\\");
9049
	while ((RHCode=RARReadHeaderEx(hArcData,&HeaderData))==0)
9284
	while ((RHCode=RARReadHeaderEx(hArcData,&HeaderData))==0)
9050
	{
9285
	{
9051
		CyString fileName = HeaderData.FileName;
9286
		Utils::String fileName = HeaderData.FileName;
9052
 
9287
 
9053
		if ( HeaderData.FileAttr == 16 )
9288
		if ( HeaderData.FileAttr == 16 )
9054
			continue;
9289
			continue;
9055
		wchar_t wText[200];
9290
		wchar_t wText[200];
9056
		::MultiByteToWideChar(CP_ACP, NULL, (char *)extractedFile.c_str(), -1, wText, extractedFile.Length() + 1);
9291
		::MultiByteToWideChar(CP_ACP, NULL, (char *)extractedFile.c_str(), -1, wText, extractedFile.length() + 1);
9057
		PFCode=RARProcessFileW(hArcData, RAR_EXTRACT, NULL, NULL);
9292
		PFCode=RARProcessFileW(hArcData, RAR_EXTRACT, NULL, NULL);
9058
		if (PFCode!=0)
9293
		if (PFCode!=0)
9059
		{
9294
		{
9060
			error = true;
9295
			error = true;
9061
			break;
9296
			break;
Line 9212... Line 9447...
9212
 
9447
 
9213
CBaseFile *CPackages::CreateFromArchive(CyString filename, bool toInstall )
9448
CBaseFile *CPackages::CreateFromArchive(CyString filename, bool toInstall )
9214
{
9449
{
9215
	// make sure we can open the zip file
9450
	// make sure we can open the zip file
9216
	CBaseFile *archive = NULL;
9451
	CBaseFile *archive = NULL;
9217
	if ( CFileIO(filename).CheckFileExtension("rar") )
9452
	if ( CFileIO(filename).isFileExtension("rar") )
9218
		archive = this->_archive_fromRar(filename, toInstall);
9453
		archive = this->_archive_fromRar(filename, toInstall);
9219
	else if ( CFileIO(filename).CheckFileExtension("zip") )
9454
	else if ( CFileIO(filename).isFileExtension("zip") )
9220
		archive = this->_archive_fromZip(filename, toInstall);
9455
		archive = this->_archive_fromZip(filename, toInstall);
9221
 
9456
 
9222
	if ( archive ) {
9457
	if ( archive ) {
9223
		archive->setFilename(CFileIO(filename).ChangeFileExtension("spk").ToString());
9458
		archive->setFilename(CFileIO(filename).changeFileExtension("spk"));
9224
		if ( toInstall )
9459
		if ( toInstall )
9225
			archive->setName(CFileIO(filename).filename());
9460
			archive->setName(CFileIO(filename).filename());
9226
		else
9461
		else
9227
			archive->setName(CFileIO(filename).baseName());
9462
			archive->setName(CFileIO(filename).baseName());
9228
	}
9463
	}
Line 9259... Line 9494...
9259
	}
9494
	}
9260
 
9495
 
9261
	return Utils::String::Null();
9496
	return Utils::String::Null();
9262
}
9497
}
9263
 
9498
 
9264
int CPackages::GeneratePackageUpdateData(CyString dir, bool includeSingle)
9499
int CPackages::GeneratePackageUpdateData(const Utils::String &dir, bool includeSingle)
9265
{
9500
{
9266
	Utils::CStringList filedata;
9501
	Utils::CStringList filedata;
9267
 
9502
 
9268
	CPackages packages;
9503
	CPackages packages;
9269
 
9504
 
Line 9284... Line 9519...
9284
				CBaseFile *p = packages.OpenPackage(Dir.file((*itr)->str), &error, 0, SPKREAD_NODATA);
9519
				CBaseFile *p = packages.OpenPackage(Dir.file((*itr)->str), &error, 0, SPKREAD_NODATA);
9285
				if ( !p )
9520
				if ( !p )
9286
					continue;
9521
					continue;
9287
 
9522
 
9288
				if ( includeSingle )
9523
				if ( includeSingle )
9289
					p->createUpdateFile(dir.ToString());
9524
					p->createUpdateFile(dir);
9290
				filedata.pushBack(CPackages::FormatAvailablePackageData(p));
9525
				filedata.pushBack(CPackages::FormatAvailablePackageData(p));
9291
				delete p;
9526
				delete p;
9292
			}
9527
			}
9293
		}
9528
		}
9294
	}
9529
	}