Subversion Repositories spk

Rev

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

Rev 181 Rev 182
Line 83... Line 83...
83
	_pCurrentDir = new GameDirectory();
83
	_pCurrentDir = new GameDirectory();
84
	_pCurrentDir->dir = dir;
84
	_pCurrentDir->dir = dir;
85
	_pCurrentDir->id = -1;
85
	_pCurrentDir->id = -1;
86
 
86
 
87
	m_gameExe.GetDirectoryData(_pCurrentDir);
87
	m_gameExe.GetDirectoryData(_pCurrentDir);
88
	_pCurrentDir->langid = this->GetGameLanguage(_pCurrentDir->dir);
88
	_pCurrentDir->langid = this->getGameLanguage(_pCurrentDir->dir);
89
	if (_pCurrentDir->langid > 0)
89
	if (_pCurrentDir->langid > 0)
90
		_pCurrentDir->langname = this->ConvertLanguage(_pCurrentDir->langid);
90
		_pCurrentDir->langname = this->ConvertLanguage(_pCurrentDir->langid);
91
 
91
 
92
	updateFoundPackages("");
92
	updateFoundPackages("");
93
}
93
}
Line 250... Line 250...
250
			delete readFile;
250
			delete readFile;
251
		}
251
		}
252
	}
252
	}
253
 
253
 
254
	return oldPlugin;
254
	return oldPlugin;
255
}
-
 
256
 
-
 
257
bool CPackages::Read(CyString dir, CProgressInfo* progress)
-
 
258
{
-
 
259
	return read(dir.ToString(), progress);
-
 
260
}
255
}
261
 
256
 
262
bool CPackages::read(const Utils::String& dir, CProgressInfo* progress)
257
bool CPackages::read(const Utils::String& dir, CProgressInfo* progress)
263
{
258
{
264
	m_sCurrentDir = dir;
259
	m_sCurrentDir = dir;
Line 774... Line 769...
774
	// now lets find the fake patch
769
	// now lets find the fake patch
775
	Utils::String useFile;
770
	Utils::String useFile;
776
	if ( m_iFakePatch > 0 )
771
	if ( m_iFakePatch > 0 )
777
	{
772
	{
778
		Utils::String file = Utils::String::PadNumber(m_iFakePatch, 2);
773
		Utils::String file = Utils::String::PadNumber(m_iFakePatch, 2);
779
		if ( CheckValidPluginManagerFile(file) )
774
		if (checkValidPluginManagerFile(file))
780
			useFile = file;
775
			useFile = file;
781
		else if ( CheckIfPluginManagerFile(file) )
776
		else if (checkIfPluginManagerFile(file))
782
			useFile = file;
777
			useFile = file;
783
	}
778
	}
784
 
779
 
785
	if ( useFile.empty() )
780
	if ( useFile.empty() )
786
	{
781
	{
787
		int nextfree = this->FindNextFakePatch();
782
		int nextfree = this->findNextFakePatch();
788
		--nextfree; // gets the end fake patch
783
		--nextfree; // gets the end fake patch
789
 
784
 
790
		// work backwards till we find a valid one
785
		// work backwards till we find a valid one
791
		while ( nextfree > m_iMaxPatch )
786
		while ( nextfree > m_iMaxPatch )
792
		{
787
		{
793
			Utils::String file = Utils::String::PadNumber(nextfree, 2);
788
			Utils::String file = Utils::String::PadNumber(nextfree, 2);
794
			if ( CheckValidPluginManagerFile(file) )
789
			if (checkValidPluginManagerFile(file))
795
			{
790
			{
796
				useFile = file;
791
				useFile = file;
797
				break;
792
				break;
798
			}
793
			}
799
			--nextfree;
794
			--nextfree;
800
		}
795
		}
801
	}
796
	}
802
 
797
 
803
	CyString addonDir = this->GetAddonDir();
798
	Utils::String addonDir = this->getAddonDir();
804
 
799
 
805
	// couldn't find the correct file, lets search for it
800
	// couldn't find the correct file, lets search for it
806
	if ( useFile.empty() ) {
801
	if ( useFile.empty() ) {
807
		int nextfree = this->FindNextFakePatch();
802
		int nextfree = this->findNextFakePatch();
808
		--nextfree; // gets the end fake patch
803
		--nextfree; // gets the end fake patch
809
 
804
 
810
		// work backwards till we find a valid one
805
		// work backwards till we find a valid one
811
		while ( nextfree > m_iMaxPatch )
806
		while ( nextfree > m_iMaxPatch )
812
		{
807
		{
813
			Utils::String file = Utils::String::PadNumber(nextfree, 2);
808
			Utils::String file = Utils::String::PadNumber(nextfree, 2);
814
			if ( CheckIfPluginManagerFile(file) )
809
			if (checkIfPluginManagerFile(file))
815
			{
810
			{
816
				useFile = file;
811
				useFile = file;
817
				break;
812
				break;
818
			}
813
			}
819
			--nextfree;
814
			--nextfree;
Line 822... Line 817...
822
 
817
 
823
	if ( !useFile.empty() )
818
	if ( !useFile.empty() )
824
	{
819
	{
825
		// lets check whats in the file first
820
		// lets check whats in the file first
826
		CCatFile openCat;
821
		CCatFile openCat;
827
		if ( openCat.open(m_sCurrentDir + "/" + useFile + ".cat", addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
822
		if ( openCat.open(m_sCurrentDir + "/" + useFile + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE )
828
		{
823
		{
829
			std::vector<SInCatFile *> *files = openCat.GetFiles();
824
			std::vector<SInCatFile *> *files = openCat.GetFiles();
830
			bool found = false;
825
			bool found = false;
831
			if ( files )
826
			if ( files )
832
			{
827
			{
833
				Utils::String useAddonDir = addonDir.ToString();
828
				Utils::String useAddonDir = addonDir;
834
				if ( !useAddonDir.empty() ) useAddonDir += "\\";
829
				if ( !useAddonDir.empty() ) useAddonDir += "\\";
835
				for (auto itr = files->cbegin(); itr != files->cend(); itr++)
830
				for (auto itr = files->cbegin(); itr != files->cend(); itr++)
836
				{
831
				{
837
					if ((*itr)->sFile.Compare("PlugMan\\TFake.pck") )
832
					if ((*itr)->sFile.Compare("PlugMan\\TFake.pck") )
838
						continue;
833
						continue;
Line 888... Line 883...
888
	// otherwise we didn't need to (hopefully)
883
	// otherwise we didn't need to (hopefully)
889
	return true;
884
	return true;
890
}
885
}
891
 
886
 
892
 
887
 
893
bool CPackages::CheckIfPluginManagerFile(CyString filename)
888
bool CPackages::checkIfPluginManagerFile(const Utils::String &filename) const
894
{
889
{
895
	bool found = false;
890
	bool found = false;
896
 
891
 
897
	CFileIO catFile(m_sCurrentDir + "/" + filename.ToString() + ".cat");
892
	CFileIO catFile(m_sCurrentDir + "/" + filename + ".cat");
898
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + "/" + filename.ToString() + ".dat"))
893
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + "/" + filename + ".dat"))
899
	{
894
	{
900
		CCatFile openFile;
895
		CCatFile openFile;
901
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
896
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
902
		{
897
		{
903
//			if ( openFile.internaldatFilename().Compare("PlugMan_Fake.dat") ) return true;
898
//			if ( openFile.internaldatFilename().Compare("PlugMan_Fake.dat") ) return true;
Line 924... Line 919...
924
	}
919
	}
925
 
920
 
926
	return found;
921
	return found;
927
}
922
}
928
 
923
 
929
bool CPackages::CheckValidPluginManagerFile(CyString filename)
924
bool CPackages::checkValidPluginManagerFile(const Utils::String &filename) const
930
{
925
{
931
	// both the cat file and dat file exists, lets open it
926
	// both the cat file and dat file exists, lets open it
932
	CFileIO catFile(m_sCurrentDir + "/" + filename.ToString() + ".cat");
927
	CFileIO catFile(m_sCurrentDir + "/" + filename + ".cat");
933
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + "/" + filename.ToString() + ".dat"))
928
	if ( catFile.exists() && CFileIO::Exists(m_sCurrentDir + "/" + filename + ".dat"))
934
	{
929
	{
935
		CCatFile openFile;
930
		CCatFile openFile;
936
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
931
		if ( openFile.open(catFile.fullFilename(), this->getAddonDir(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
937
		{
932
		{
938
			if ( openFile.findData("PlugMan\\TFake.pck") )
933
			if ( openFile.findData("PlugMan\\TFake.pck") )
Line 1067... Line 1062...
1067
 
1062
 
1068
	// check for another mod
1063
	// check for another mod
1069
	if ( !package->IsAnotherMod() )
1064
	if ( !package->IsAnotherMod() )
1070
		return;
1065
		return;
1071
 
1066
 
1072
	package->SetParent((CSpkFile *)FindSpkPackage(package->GetOtherName(), package->GetOtherAuthor()));
1067
	package->SetParent((CSpkFile *)findSpkPackage(package->GetOtherName(), package->GetOtherAuthor()));
1073
}
1068
}
1074
 
1069
 
1075
/**
1070
/**
1076
 * Updates the package list once data has been read
1071
 * Updates the package list once data has been read
1077
 *
1072
 *
Line 1120... Line 1115...
1120
 
1115
 
1121
	m_bRedo = false;
1116
	m_bRedo = false;
1122
	return true;
1117
	return true;
1123
}
1118
}
1124
 
1119
 
1125
int CPackages::CheckOpenPackage(CyString file, int *error)
1120
int CPackages::checkOpenPackage(const Utils::String &file, int *error)
1126
{
1121
{
1127
	// first check if it exists
1122
	// first check if it exists
1128
	if ( !CFileIO(file).ExistsOld() )
1123
	if (!CFileIO::Exists(file))
1129
	{
1124
	{
1130
		*error = INSTALLERR_NOEXIST;
1125
		*error = INSTALLERR_NOEXIST;
1131
		return -1;
1126
		return -1;
1132
	}
1127
	}
1133
 
1128
 
1134
	// open the spk file
1129
	// open the spk file
1135
	float fVersion = 0.0f;
1130
	float fVersion = 0.0f;
1136
	int check = CBaseFile::CheckFile(file.ToString(), &fVersion);
1131
	int check = CBaseFile::CheckFile(file, &fVersion);
1137
 
1132
 
1138
	// wrong version
1133
	// wrong version
1139
	if ( fVersion > (float)FILEVERSION )
1134
	if ( fVersion > (float)FILEVERSION )
1140
	{
1135
	{
1141
		*error = INSTALLERR_VERSION;
1136
		*error = INSTALLERR_VERSION;
Line 1143... Line 1138...
1143
	}
1138
	}
1144
 
1139
 
1145
	return check;
1140
	return check;
1146
}
1141
}
1147
 
1142
 
1148
CMultiSpkFile *CPackages::OpenMultiPackage(CyString file, int *error, CProgressInfo *progress)
1143
CMultiSpkFile *CPackages::openMultiPackage(const Utils::String &file, int *error, CProgressInfo *progress)
1149
{
1144
{
1150
	int check = CheckOpenPackage(file, error);
1145
	int check = checkOpenPackage(file, error);
1151
	if ( *error == -1 )
1146
	if ( *error == -1 )
1152
		return false;
1147
		return false;
1153
 
1148
 
1154
	if ( check != SPKFILE_MULTI )
1149
	if ( check != SPKFILE_MULTI )
1155
	{
1150
	{
Line 1160... Line 1155...
1160
	*error = INSTALLERR_NONE;
1155
	*error = INSTALLERR_NONE;
1161
 
1156
 
1162
	CMultiSpkFile *package = new CMultiSpkFile;
1157
	CMultiSpkFile *package = new CMultiSpkFile;
1163
 
1158
 
1164
	bool ret = false;
1159
	bool ret = false;
1165
	if ( package->readFile(file.ToString(), true))
1160
	if ( package->readFile(file, true))
1166
	{
1161
	{
1167
		if ( package->readAllPackages(SPKREAD_NODATA) )
1162
		if ( package->readAllPackages(SPKREAD_NODATA) )
1168
		{
1163
		{
1169
			for ( CListNode<SMultiSpkFile> *node = package->GetFileList()->Front(); node; node = node->next() )
1164
			for ( CListNode<SMultiSpkFile> *node = package->GetFileList()->Front(); node; node = node->next() )
1170
				this->ConvertOldPackage(node->Data()->pFile);
1165
				this->ConvertOldPackage(node->Data()->pFile);
Line 1178... Line 1173...
1178
 
1173
 
1179
	delete package;
1174
	delete package;
1180
	return NULL;
1175
	return NULL;
1181
}
1176
}
1182
 
1177
 
1183
bool CPackages::OpenMultiPackage ( CyString file, CLinkList<CBaseFile> *packageList, int *error, CProgressInfo *progress )
1178
bool CPackages::openMultiPackage(const Utils::String &file, CLinkList<CBaseFile> *packageList, int *error, CProgressInfo *progress )
1184
{
1179
{
1185
	int check = CheckOpenPackage(file, error);
1180
	int check = checkOpenPackage(file, error);
1186
	if ( *error == -1 )
1181
	if ( *error == -1 )
1187
		return false;
1182
		return false;
1188
 
1183
 
1189
	if ( check != SPKFILE_MULTI )
1184
	if ( check != SPKFILE_MULTI )
1190
	{
1185
	{
Line 1195... Line 1190...
1195
	*error = INSTALLERR_NONE;
1190
	*error = INSTALLERR_NONE;
1196
 
1191
 
1197
	CMultiSpkFile *package = new CMultiSpkFile;
1192
	CMultiSpkFile *package = new CMultiSpkFile;
1198
 
1193
 
1199
	bool ret = false;
1194
	bool ret = false;
1200
	if ( package->readFile(file.ToString(), true))
1195
	if ( package->readFile(file, true))
1201
	{
1196
	{
1202
		if ( package->readAllPackages(SPKREAD_ALL, packageList) )
1197
		if ( package->readAllPackages(SPKREAD_ALL, packageList) )
1203
		{
1198
		{
1204
			for ( CListNode<CBaseFile> *node = packageList->Front(); node; node = node->next() )
1199
			for ( CListNode<CBaseFile> *node = packageList->Front(); node; node = node->next() )
1205
				this->ConvertOldPackage(node->Data());
1200
				this->ConvertOldPackage(node->Data());
Line 1212... Line 1207...
1212
	delete package;
1207
	delete package;
1213
 
1208
 
1214
	return ret;
1209
	return ret;
1215
}
1210
}
1216
 
1211
 
1217
int CPackages::PrepareMultiPackage ( CyString file, CLinkList<CBaseFile> *errorPackageList, int *error, CProgressInfo *progress )
1212
int CPackages::prepareMultiPackage(const Utils::String &file, CLinkList<CBaseFile> *errorPackageList, int *error, CProgressInfo *progress)
1218
{
1213
{
1219
	int check = CheckOpenPackage(file, error);
1214
	int check = checkOpenPackage(file, error);
1220
	if ( *error == -1 )
1215
	if ( *error == -1 )
1221
		return 0;
1216
		return 0;
1222
 
1217
 
1223
	if ( check != SPKFILE_MULTI )
1218
	if ( check != SPKFILE_MULTI )
1224
	{
1219
	{
Line 1229... Line 1224...
1229
	*error = INSTALLERR_NONE;
1224
	*error = INSTALLERR_NONE;
1230
 
1225
 
1231
	CMultiSpkFile *package = new CMultiSpkFile;
1226
	CMultiSpkFile *package = new CMultiSpkFile;
1232
 
1227
 
1233
	int count = 0;
1228
	int count = 0;
1234
	if ( package->readFile(file.ToString(), true))
1229
	if ( package->readFile(file, true))
1235
	{
1230
	{
1236
		CLinkList<CBaseFile> packageList;
1231
		CLinkList<CBaseFile> packageList;
1237
		if ( package->readAllPackages(SPKREAD_ALL, &packageList) )
1232
		if ( package->readAllPackages(SPKREAD_ALL, &packageList) )
1238
		{
1233
		{
1239
			for ( CListNode<CBaseFile> *node = packageList.Front(); node; node = node->next() )
1234
			for ( CListNode<CBaseFile> *node = packageList.Front(); node; node = node->next() )
Line 1258... Line 1253...
1258
	delete package;
1253
	delete package;
1259
 
1254
 
1260
	return count;
1255
	return count;
1261
}
1256
}
1262
 
1257
 
1263
CBaseFile *CPackages::OpenPackage(CyString file, int *error, CProgressInfo *progress, int readtype, int flags)
1258
CBaseFile *CPackages::openPackage(const Utils::String &file, int *error, CProgressInfo *progress, int readtype, int flags)
1264
{
1259
{
1265
	int check = CheckOpenPackage(file, error);
1260
	int check = checkOpenPackage(file, error);
1266
	if ( *error == -1 )
1261
	if ( *error == -1 )
1267
		return NULL;
1262
		return NULL;
1268
 
1263
 
1269
	CBaseFile *installFile = 0;
1264
	CBaseFile *installFile = 0;
1270
 
1265
 
Line 1279... Line 1274...
1279
		case SPKFILE_INVALID:
1274
		case SPKFILE_INVALID:
1280
			// convert xsp
1275
			// convert xsp
1281
			if ( CFileIO(file).isFileExtension("xsp") )
1276
			if ( CFileIO(file).isFileExtension("xsp") )
1282
			{
1277
			{
1283
				installFile = new CXspFile();
1278
				installFile = new CXspFile();
1284
				if ( !((CXspFile *)installFile)->ConvertOld(file.ToString()) )
1279
				if ( !((CXspFile *)installFile)->ConvertOld(file) )
1285
				{
1280
				{
1286
					delete installFile;
1281
					delete installFile;
1287
					return NULL;
1282
					return NULL;
1288
				}
1283
				}
1289
				break;
1284
				break;
1290
			}
1285
			}
1291
			*error = INSTALLERR_INVALID;
1286
			*error = INSTALLERR_INVALID;
1292
			return NULL;
1287
			return NULL;
1293
		case SPKFILE_BASE:
1288
		case SPKFILE_BASE:
1294
			installFile = new CBaseFile();
1289
			installFile = new CBaseFile();
1295
			if ( !installFile->readFile(file.ToString(), readtype, progress) )
1290
			if ( !installFile->readFile(file, readtype, progress) )
1296
			{
1291
			{
1297
				delete installFile;
1292
				delete installFile;
1298
				return NULL;
1293
				return NULL;
1299
			}
1294
			}
1300
			break;
1295
			break;
1301
		case SPKFILE_SINGLE:
1296
		case SPKFILE_SINGLE:
1302
			installFile = new CSpkFile();
1297
			installFile = new CSpkFile();
1303
			if ( !((CSpkFile *)installFile)->readFile(file.ToString(), readtype, progress) )
1298
			if ( !((CSpkFile *)installFile)->readFile(file, readtype, progress) )
1304
			{
1299
			{
1305
				delete installFile;
1300
				delete installFile;
1306
				return NULL;
1301
				return NULL;
1307
			}
1302
			}
1308
			break;
1303
			break;
1309
		case SPKFILE_MULTI:
1304
		case SPKFILE_MULTI:
1310
			*error = INSTALLERR_NOMULTI;
1305
			*error = INSTALLERR_NOMULTI;
1311
			return NULL;
1306
			return NULL;
1312
		case SPKFILE_SINGLESHIP:
1307
		case SPKFILE_SINGLESHIP:
1313
			installFile = new CXspFile();
1308
			installFile = new CXspFile();
1314
			if ( !((CXspFile *)installFile)->readFile(file.ToString(), readtype, progress))
1309
			if ( !((CXspFile *)installFile)->readFile(file, readtype, progress))
1315
			{
1310
			{
1316
				delete installFile;
1311
				delete installFile;
1317
				return NULL;
1312
				return NULL;
1318
			}
1313
			}
1319
			break;
1314
			break;
Line 1454... Line 1449...
1454
{
1449
{
1455
	CLog::logf(CLog::Log_Install, 1, "Starting to install new package, %s by %s (Version: %s)", package->name().c_str(), package->author().c_str(), package->version().c_str());
1450
	CLog::logf(CLog::Log_Install, 1, "Starting to install new package, %s by %s (Version: %s)", package->name().c_str(), package->author().c_str(), package->version().c_str());
1456
	
1451
	
1457
	Utils::CStringList lErrors;
1452
	Utils::CStringList lErrors;
1458
 
1453
 
1459
	CBaseFile *oldPackage = FindPackage(package);
1454
	CBaseFile *oldPackage = findPackage(package);
1460
	disabled = _checkForDisable(package, disabled, oldPackage);
1455
	disabled = _checkForDisable(package, disabled, oldPackage);
1461
 
1456
 
1462
	// update packages must have an old package installed already (should have been checked for already)
1457
	// update packages must have an old package installed already (should have been checked for already)
1463
	if ( package->GetType() == TYPE_SPK )
1458
	if ( package->GetType() == TYPE_SPK )
1464
	{
1459
	{
Line 1619... Line 1614...
1619
				{
1614
				{
1620
					if ( f->Data()->baseName().left(5).Compare("fake_") )
1615
					if ( f->Data()->baseName().left(5).Compare("fake_") )
1621
					{
1616
					{
1622
						shuffle = true;
1617
						shuffle = true;
1623
						C_File *match = package->findMatchingMod(f->Data());
1618
						C_File *match = package->findMatchingMod(f->Data());
1624
						Utils::String next = Utils::String::PadNumber(this->FindNextFakePatch(), 2);
1619
						Utils::String next = Utils::String::PadNumber(this->findNextFakePatch(), 2);
1625
						
1620
						
1626
						Utils::String oldFilePointer = f->Data()->filePointer();
1621
						Utils::String oldFilePointer = f->Data()->filePointer();
1627
						f->Data()->setDir("");
1622
						f->Data()->setDir("");
1628
						f->Data()->changeBaseName(next);
1623
						f->Data()->changeBaseName(next);
1629
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
1624
						if ( CFileIO(oldFilePointer).Rename(m_sCurrentDir + "/" + f->Data()->getNameDirectory(package)) )
Line 1794... Line 1789...
1794
	// now we need to link any child/parent packages
1789
	// now we need to link any child/parent packages
1795
	if ( package->GetType() == TYPE_SPK )
1790
	if ( package->GetType() == TYPE_SPK )
1796
	{
1791
	{
1797
		CSpkFile *spk = (CSpkFile *)package;
1792
		CSpkFile *spk = (CSpkFile *)package;
1798
		if ( spk->IsAnotherMod() ) {
1793
		if ( spk->IsAnotherMod() ) {
1799
			spk->SetParent((CSpkFile *)FindSpkPackage(spk->GetOtherName(), spk->GetOtherAuthor()));
1794
			spk->SetParent((CSpkFile *)findSpkPackage(spk->GetOtherName(), spk->GetOtherAuthor()));
1800
			CLog::logf(CLog::Log_Install, 2, "Linking to parent package: %s by %s (Version: %s)", spk->name().c_str(), spk->author().c_str(), spk->version().c_str());
1795
			CLog::logf(CLog::Log_Install, 2, "Linking to parent package: %s by %s (Version: %s)", spk->name().c_str(), spk->author().c_str(), spk->version().c_str());
1801
		}
1796
		}
1802
	}
1797
	}
1803
 
1798
 
1804
	// store enabled mod
1799
	// store enabled mod
Line 2386... Line 2381...
2386
			gw->sShipClass = p->GetShipClass();
2381
			gw->sShipClass = p->GetShipClass();
2387
			gw->pPackage = p;
2382
			gw->pPackage = p;
2388
			m_lGameShips.push_back(gw);
2383
			m_lGameShips.push_back(gw);
2389
		}
2384
		}
2390
		gw->iType = WARETYPE_ADDED;
2385
		gw->iType = WARETYPE_ADDED;
2391
	}
2386
	}
2392
}
2387
}
2393
 
2388
 
2394
void CPackages::SetupWares()
2389
void CPackages::SetupWares()
2395
{
2390
{
2396
	for ( int i = 0; i < WAREBUFFERS; i++ )
2391
	for ( int i = 0; i < WAREBUFFERS; i++ )
2397
	{
2392
	{
2398
		for ( CListNode<SGameWare> *wNode = m_lGameWares[i].Front(); wNode; wNode = wNode->next() )
2393
		for ( CListNode<SGameWare> *wNode = m_lGameWares[i].Front(); wNode; wNode = wNode->next() )
Line 2526... Line 2521...
2526
		if ( !CDirIO(m_sCurrentDir).exists("mods") )
2521
		if ( !CDirIO(m_sCurrentDir).exists("mods") )
2527
			CDirIO(m_sCurrentDir).create("mods");
2522
			CDirIO(m_sCurrentDir).create("mods");
2528
 
2523
 
2529
		SetupWares();
2524
		SetupWares();
2530
		SetupShips();
2525
		SetupShips();
2531
		CreateEMPFile();
2526
		createEMPFile();
2532
		CreateWareFiles();
2527
		CreateWareFiles();
2533
		CreateDummies();
2528
		CreateDummies();
2534
		CreateComponants();
2529
		CreateComponants();
2535
		CreateTShips();
2530
		CreateTShips();
2536
		CreateCutData();
2531
		CreateCutData();
Line 2564... Line 2559...
2564
 
2559
 
2565
	m_bLoaded = false;
2560
	m_bLoaded = false;
2566
	return true;
2561
	return true;
2567
}
2562
}
2568
 
2563
 
2569
CyString CPackages::GetModKey()
2564
Utils::String CPackages::getModKey() const
2570
{
2565
{
2571
	return m_gameExe.GetModKey(m_iGame - 1);
2566
	return m_gameExe.getModKey(m_iGame - 1);
2572
}
2567
}
2573
Utils::String CPackages::selectedModName() const
2568
Utils::String CPackages::selectedModName() const
2574
{
2569
{
2575
	if ( !m_pEnabledMod )
2570
	if ( !m_pEnabledMod )
2576
	{
2571
	{
Line 2648... Line 2643...
2648
			datFile.copy(datFile.dir() + "/Backup/" + datFile.filename());
2643
			datFile.copy(datFile.dir() + "/Backup/" + datFile.filename());
2649
		}
2644
		}
2650
 
2645
 
2651
 
2646
 
2652
		// find next available fake patch
2647
		// find next available fake patch
2653
		m_iFakePatch = this->FindNextFakePatch();
2648
		m_iFakePatch = this->findNextFakePatch();
2654
		CLog::log(CLog::Log_Directory, 2, "Finding next available fake patch number: " + (long)m_iFakePatch);
2649
		CLog::log(CLog::Log_Directory, 2, "Finding next available fake patch number: " + (long)m_iFakePatch);
2655
 
2650
 
2656
		Utils::String filename = Utils::String::PadNumber(m_iFakePatch, 2);
2651
		Utils::String filename = Utils::String::PadNumber(m_iFakePatch, 2);
2657
		CLog::log(CLog::Log_Directory, 2, "Renaming cat file to: " + filename + ".cat");
2652
		CLog::log(CLog::Log_Directory, 2, "Renaming cat file to: " + filename + ".cat");
2658
		if ( catFile.Rename(m_sCurrentDir + "/" + filename + ".cat") )
2653
		if ( catFile.Rename(m_sCurrentDir + "/" + filename + ".cat") )
Line 2911... Line 2906...
2911
 * Gets a list of all files, includes any child package files
2906
 * Gets a list of all files, includes any child package files
2912
 */
2907
 */
2913
int CPackages::GetAllPackageFiles(CBaseFile *package, CLinkList<C_File> *fileList, bool includeChild)
2908
int CPackages::GetAllPackageFiles(CBaseFile *package, CLinkList<C_File> *fileList, bool includeChild)
2914
{
2909
{
2915
	for ( CListNode<C_File> *node = package->GetFileList()->Front(); node; node = node->next() )
2910
	for ( CListNode<C_File> *node = package->GetFileList()->Front(); node; node = node->next() )
2916
	{
2911
	{
2917
		C_File *f = node->Data();
2912
		C_File *f = node->Data();
2918
		if ( !fileList->FindData(f) )
2913
		if ( !fileList->FindData(f) )
2919
			fileList->push_back(f);
2914
			fileList->push_back(f);
2920
	}
2915
	}
2921
 
2916
 
2922
	if ( includeChild )
2917
	if ( includeChild )
Line 2959... Line 2954...
2959
{
2954
{
2960
	if (!errors)
2955
	if (!errors)
2961
		return;
2956
		return;
2962
 
2957
 
2963
	errors->PushBack(args, ERRORLOG_OLD(type));
2958
	errors->PushBack(args, ERRORLOG_OLD(type));
2964
}
2959
}
2965
void CPackages::addLogEntry(int type, const Utils::String &args, Utils::CStringList *errors)
2960
void CPackages::addLogEntry(int type, const Utils::String &args, Utils::CStringList *errors)
2966
{
2961
{
2967
	if (!errors)
2962
	if (!errors)
2968
		return;
2963
		return;
2969
 
2964
 
2970
	errors->pushBack(args, ERRORLOG(type));
2965
	errors->pushBack(args, ERRORLOG(type));
2971
}
2966
}
2972
 
2967
 
2973
/**
2968
/**
2974
 * Enable a package
2969
 * Enable a package
2975
 *
2970
 *
2976
 * Enables all files in the package, unless they are already enabled, ie, used by other packages
2971
 * Enables all files in the package, unless they are already enabled, ie, used by other packages
2977
 * Backs up any original files before attempting to enable the file
2972
 * Backs up any original files before attempting to enable the file
2978
 *
2973
 *
2979
 * Fake patches are renamed to the next available slot
2974
 * Fake patches are renamed to the next available slot
2980
 *
2975
 *
2981
 * Clears up the "PluginManager/Disabled" directory
2976
 * Clears up the "PluginManager/Disabled" directory
2982
 *
2977
 *
2983
 * param: package		- The package class to be removed
2978
 * param: package		- The package class to be removed
2984
 * param: errors		- The string list for all the status for debugging, ie has an entry for whats happened to every file
2979
 * param: errors		- The string list for all the status for debugging, ie has an entry for whats happened to every file
2985
 * param: progress		- The progress class, updates a progress screen of the derived class
2980
 * param: progress		- The progress class, updates a progress screen of the derived class
Line 3008... Line 3003...
3008
		return false;
3003
		return false;
3009
	}
3004
	}
3010
 
3005
 
3011
	if ( this->PrepareEnablePackage(package) )
3006
	if ( this->PrepareEnablePackage(package) )
3012
		return this->EnablePreparedPackages(errors, progress);
3007
		return this->EnablePreparedPackages(errors, progress);
3013
 
3008
 
3014
	return false;
3009
	return false;
3015
}
3010
}
3016
bool CPackages::EnablePreparedPackages ( CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *enabledPackages )
3011
bool CPackages::EnablePreparedPackages ( CyStringList *errors, CProgressInfo *progress, CLinkList<CBaseFile> *enabledPackages )
3017
{
3012
{
3018
	ClearError();
3013
	ClearError();
Line 3041... Line 3036...
3041
		}
3036
		}
3042
 
3037
 
3043
		if ( progress )
3038
		if ( progress )
3044
		{
3039
		{
3045
			progress->UpdateProgress(fileCount++, maxFiles);
3040
			progress->UpdateProgress(fileCount++, maxFiles);
3046
			progress->UpdateFile(f);
3041
			progress->UpdateFile(f);
3047
		}
3042
		}
3048
 
3043
 
3049
		// only move fiels that are disabled
3044
		// only move fiels that are disabled
3050
		if ( !f->IsDisabled() )
3045
		if ( !f->IsDisabled() )
3051
			continue;
3046
			continue;
3052
 
3047
 
3053
		// make the directory if it dont exist
3048
		// make the directory if it dont exist
Line 3079... Line 3074...
3079
			if (fakePatches.contains(f->baseName()))
3074
			if (fakePatches.contains(f->baseName()))
3080
				newFilename = fakePatches.findString(f->baseName()) + "." + f->fileExt();
3075
				newFilename = fakePatches.findString(f->baseName()) + "." + f->fileExt();
3081
			// we need to find the next available number instead
3076
			// we need to find the next available number instead
3082
			else
3077
			else
3083
			{
3078
			{
3084
				Utils::String newPos = Utils::String::PadNumber(FindNextFakePatch(), 2);
3079
				Utils::String newPos = Utils::String::PadNumber(findNextFakePatch(), 2);
3085
				newFilename = newPos + "." + f->fileExt();
3080
				newFilename = newPos + "." + f->fileExt();
3086
				// and wee need to push this onto the string list so we can adjust the matchign pair
3081
				// and wee need to push this onto the string list so we can adjust the matchign pair
3087
				fakePatches.pushBack(f->baseName(), newPos);
3082
				fakePatches.pushBack(f->baseName(), newPos);
3088
			}
3083
			}
3089
		}
3084
		}
Line 3094... Line 3089...
3094
		CFileIO newFile(m_sCurrentDir + "/" + newFilename);
3089
		CFileIO newFile(m_sCurrentDir + "/" + newFilename);
3095
		if ( !currentFile.exists() )
3090
		if ( !currentFile.exists() )
3096
		{
3091
		{
3097
			// missing file ??
3092
			// missing file ??
3098
			if ( !newFile.exists() )
3093
			if ( !newFile.exists() )
3099
			{
3094
			{
3100
				this->AddLogEntry(SPKINSTALL_MISSINGFILE, newFilename, errors);
3095
				this->AddLogEntry(SPKINSTALL_MISSINGFILE, newFilename, errors);
3101
				continue;
3096
				continue;
3102
			}
3097
			}
3103
		}
3098
		}
3104
		// remove existing file
3099
		// remove existing file
Line 3175... Line 3170...
3175
	CyStringList removeDirs;
3170
	CyStringList removeDirs;
3176
 
3171
 
3177
	// get all files, including children
3172
	// get all files, including children
3178
	CLinkList<C_File> fileList;
3173
	CLinkList<C_File> fileList;
3179
	int maxFiles = this->GetAllPackageFiles(&m_lDisableList, &fileList, true);
3174
	int maxFiles = this->GetAllPackageFiles(&m_lDisableList, &fileList, true);
3180
 
3175
 
3181
	// interate through all the files in the package
3176
	// interate through all the files in the package
3182
	int fileCount = 0;
3177
	int fileCount = 0;
3183
	for ( CListNode<C_File> *node = fileList.Front(); node; node = node->next() )
3178
	for ( CListNode<C_File> *node = fileList.Front(); node; node = node->next() )
3184
	{
3179
	{
3185
		C_File *f = node->Data();
3180
		C_File *f = node->Data();
Line 3398... Line 3393...
3398
 *
3393
 *
3399
 * Finds a matching package so we can find if one is already installed
3394
 * Finds a matching package so we can find if one is already installed
3400
 *
3395
 *
3401
 * Uses seperate functions for each package type, ie for SPK and XSP packages
3396
 * Uses seperate functions for each package type, ie for SPK and XSP packages
3402
 */
3397
 */
3403
CBaseFile* CPackages::FindPackage(CBaseFile* package)
3398
CBaseFile* CPackages::findPackage(CBaseFile* package) const
3404
{
3399
{
3405
	// no point checking if we've been sent a null pointer
3400
	// no point checking if we've been sent a null pointer
3406
	if ( !package )
3401
	if ( !package )
3407
		return 0;
3402
		return 0;
3408
 
3403
 
3409
	// we are checking against a SPK package, so we match the name and author
3404
	// we are checking against a SPK package, so we match the name and author
3410
	if ( package->GetType() == TYPE_SPK )
3405
	if ( package->GetType() == TYPE_SPK )
3411
		return FindSpkPackage(package->name(), package->author());
3406
		return findSpkPackage(package->name(), package->author());
3412
	else if ( package->GetType() == TYPE_XSP )
3407
	else if ( package->GetType() == TYPE_XSP )
3413
		return FindXspPackage(((CXspFile *)package)->GetShipID());
3408
		return findXspPackage(((CXspFile *)package)->GetShipID());
3414
	else if ( package->GetType() == TYPE_ARCHIVE )
3409
	else if ( package->GetType() == TYPE_ARCHIVE )
3415
		return FindArchivePackage(package->name());
3410
		return findArchivePackage(package->name());
3416
 
3411
 
3417
	// nothing found obviously
3412
	// nothing found obviously
3418
	return 0;
3413
	return 0;
3419
}
3414
}
3420
 
3415
 
3421
CBaseFile *CPackages::FindFirstPackageWithFile(C_File *f)
3416
CBaseFile *CPackages::findFirstPackageWithFile(C_File *f) const
3422
{
3417
{
3423
	return FindNextPackageWithFile(NULL, f);
3418
	return findNextPackageWithFile(NULL, f);
3424
}
3419
}
3425
 
3420
 
3426
CBaseFile *CPackages::FindNextPackageWithFile(CBaseFile *p, C_File *f)
3421
CBaseFile *CPackages::findNextPackageWithFile(CBaseFile *p, C_File *f) const
3427
{
3422
{
3428
	bool startCheck = (p) ? false : true;
3423
	bool startCheck = (p) ? false : true;
3429
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3424
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3430
	{
3425
	{
3431
		if ( startCheck )
3426
		if ( startCheck )
Line 3444... Line 3439...
3444
/**
3439
/**
3445
 * Find a File
3440
 * Find a File
3446
 *
3441
 *
3447
 * Searches for a file matching the filetype and filename
3442
 * Searches for a file matching the filetype and filename
3448
 * Optional dir is used for extras files
3443
 * Optional dir is used for extras files
3449
 */
3444
 */
3450
C_File *CPackages::FindFile(int filetype, CyString filename, CyString dir)
3445
C_File *CPackages::findFile(FileType filetype, const Utils::String &filename, const Utils::String &dir) const
3451
{
3446
{
3452
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
3447
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
3453
	{
3448
	{
3454
		C_File *f = node->Data();
3449
		C_File *f = node->Data();
3455
		if ( f->GetFileType() != filetype )
3450
		if ( f->GetFileType() != filetype )
3456
			continue;
3451
			continue;
3457
 
3452
 
3458
		if ( !f->filename().Compare(filename.ToString()) )
3453
		if ( !f->filename().Compare(filename) )
3459
			continue;
3454
			continue;
3460
 
3455
 
3461
		if ( !dir.Empty() && f->dir().Compare(dir.ToString()) )
3456
		if ( !dir.empty() && f->dir().Compare(dir) )
3462
			continue;
3457
			continue;
3463
 
3458
 
3464
		return f;
3459
		return f;
3465
	}
3460
	}
3466
 
3461
 
3467
	return NULL;
3462
	return NULL;
3468
}
3463
}
3469
 
3464
 
3470
CArchiveFile *CPackages::FindArchivePackage(CyString name)
3465
CArchiveFile *CPackages::findArchivePackage(const Utils::String &name) const
3471
{
3466
{
3472
	// interate through all packages
3467
	// interate through all packages
3473
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3468
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3474
	{
3469
	{
3475
		CBaseFile *file = node->Data();
3470
		CBaseFile *file = node->Data();
3476
 
3471
 
3477
		// only look for archive packages
3472
		// only look for archive packages
3478
		if ( file->GetType() != TYPE_ARCHIVE )
3473
		if ( file->GetType() != TYPE_ARCHIVE )
3479
			continue;
3474
			continue;
3480
 
3475
 
3481
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3476
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3482
		if ( file->name().Compare(name.ToString()) )
3477
		if ( file->name().Compare(name) )
3483
			return (CArchiveFile *)file;
3478
			return (CArchiveFile *)file;
3484
	}
3479
	}
3485
 
3480
 
3486
	// nothing found
3481
	// nothing found
3487
	return 0;
3482
	return 0;
3488
}
3483
}
3489
 
3484
 
3490
/**
3485
/**
3491
 * Find a SPK Package
3486
 * Find a SPK Package
3492
 *
3487
 *
3493
 * This searching all installed packages for a SPK Package matching the name and author
3488
 * This searching all installed packages for a SPK Package matching the name and author
3494
 */
3489
 */
3495
CBaseFile *CPackages::FindSpkPackage(CyString name, CyString author)
-
 
3496
{
-
 
3497
	return findSpkPackage(name.ToString(), author.ToString());
-
 
3498
}
-
 
3499
CBaseFile *CPackages::findSpkPackage(const Utils::String &name, const Utils::String &author) const
3490
CBaseFile *CPackages::findSpkPackage(const Utils::String &name, const Utils::String &author) const
3500
{
3491
{
3501
	// interate through all packages
3492
	// interate through all packages
3502
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3493
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3503
	{
3494
	{
3504
		CBaseFile *file = node->Data();
3495
		CBaseFile *file = node->Data();
3505
 
3496
 
3506
		// only look for spk packages
3497
		// only look for spk packages
3507
		if ( file->GetType() != TYPE_SPK )
3498
		if ( file->GetType() != TYPE_SPK )
3508
			continue;
3499
			continue;
3509
 
3500
 
3510
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3501
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3511
		if ( file->name().Compare(name) && file->author().Compare(author) )
3502
		if ( file->name().Compare(name) && file->author().Compare(author) )
3512
			return file;
3503
			return file;
3513
	}
3504
	}
3514
 
3505
 
3515
	// nothing found
3506
	// nothing found
3516
	return 0;
3507
	return 0;
3517
}
3508
}
3518
 
3509
 
3519
CBaseFile* CPackages::findPackage(const Utils::String &name, const Utils::String &author) const
3510
CBaseFile* CPackages::findPackage(const Utils::String &name, const Utils::String &author) const
3520
{
3511
{
Line 3523... Line 3514...
3523
	{
3514
	{
3524
		CBaseFile* file = node->Data();
3515
		CBaseFile* file = node->Data();
3525
 
3516
 
3526
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3517
		// now compare the name and author, "Compare" is a non case senseative check, opposed to ==.
3527
		if (file->name().Compare(name) && file->author().Compare(author))
3518
		if (file->name().Compare(name) && file->author().Compare(author))
3528
			return file;
3519
			return file;
3529
	}
3520
	}
3530
 
3521
 
3531
	// nothing found
3522
	// nothing found
3532
	return 0;
3523
	return 0;
3533
}
-
 
3534
CBaseFile* CPackages::FindPackage(CyString name, CyString author)
-
 
3535
{
-
 
3536
	return findPackage(name.ToString(), author.ToString());
-
 
3537
}
3524
}
3538
 
3525
 
3539
/**
3526
/**
3540
 * Find a XSP Package
3527
 * Find a XSP Package
3541
 *
3528
 *
3542
 * 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
3543
 */
3530
 */
3544
CBaseFile *CPackages::FindXspPackage(CyString id)
3531
CBaseFile *CPackages::findXspPackage(const Utils::String &id) const
3545
{
3532
{
3546
	// interate through all packages
3533
	// interate through all packages
3547
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3534
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
3548
	{
3535
	{
3549
		CBaseFile *file = node->Data();
3536
		CBaseFile *file = node->Data();
3550
 
3537
 
3551
		// only look for spk packages
3538
		// only look for spk packages
3552
		if ( file->GetType() != TYPE_XSP )
3539
		if ( file->GetType() != TYPE_XSP )
3553
			continue;
3540
			continue;
3554
 
3541
 
3555
		// now compare the id, "Compare" is a non case senseative check, opposed to ==.
3542
		// now compare the id, "Compare" is a non case senseative check, opposed to ==.
3556
		if ( ((CXspFile *)file)->GetShipID().Compare(id.ToString()) )
3543
		if ( ((CXspFile *)file)->GetShipID().Compare(id) )
3557
			return file;
3544
			return file;
3558
	}
3545
	}
3559
 
3546
 
3560
	// nothing found
3547
	// nothing found
3561
	return 0;
3548
	return 0;
Line 3572... Line 3559...
3572
	CListNode<C_File> *fnode = m_lFiles.Front();
3559
	CListNode<C_File> *fnode = m_lFiles.Front();
3573
	while ( fnode )
3560
	while ( fnode )
3574
	{
3561
	{
3575
		fnode->Data()->clearUsed();
3562
		fnode->Data()->clearUsed();
3576
		fnode = fnode->next();
3563
		fnode = fnode->next();
3577
	}
3564
	}
3578
 
3565
 
3579
	// update for all packages
3566
	// update for all packages
3580
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node= node->next() )
3567
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node= node->next() )
3581
	{
3568
	{
3582
		CBaseFile *file = node->Data();
3569
		CBaseFile *file = node->Data();
3583
		if ( (ignoreList) && (ignoreList->FindData(file)) )
3570
		if ( (ignoreList) && (ignoreList->FindData(file)) )
Line 3663... Line 3650...
3663
{
3650
{
3664
	if ( package->GetType() == TYPE_XSP && m_iGame == GAME_X2 )
3651
	if ( package->GetType() == TYPE_XSP && m_iGame == GAME_X2 )
3665
		return INSTALLCHECK_NOSHIP;
3652
		return INSTALLCHECK_NOSHIP;
3666
 
3653
 
3667
	// search for an old version
3654
	// search for an old version
3668
	CBaseFile *oldPackage = FindPackage(package);
3655
	CBaseFile *oldPackage = findPackage(package);
3669
 
3656
 
3670
	// check versions are newer
3657
	// check versions are newer
3671
	if (oldPackage && (check & IC_OLDVERSION))
3658
	if (oldPackage && (check & IC_OLDVERSION))
3672
	{
3659
	{
3673
		if ( oldPackage->version().compareVersion(package->version()) == COMPARE_OLDER )
3660
		if ( oldPackage->version().compareVersion(package->version()) == COMPARE_OLDER )
Line 3702... Line 3689...
3702
	if ( package->GetType() == TYPE_SPK )
3689
	if ( package->GetType() == TYPE_SPK )
3703
	{
3690
	{
3704
		CSpkFile *spk = (CSpkFile *)package;
3691
		CSpkFile *spk = (CSpkFile *)package;
3705
		if ( spk->IsAnotherMod() )
3692
		if ( spk->IsAnotherMod() )
3706
		{
3693
		{
3707
			if ( !FindSpkPackage(spk->GetOtherName(), spk->GetOtherAuthor()) )
3694
			if ( !findSpkPackage(spk->GetOtherName(), spk->GetOtherAuthor()) )
3708
			{
3695
			{
3709
				// check the install list
3696
				// check the install list
3710
				if ( m_lInstallList.empty() )
3697
				if ( m_lInstallList.empty() )
3711
					return false;
3698
					return false;
3712
 
3699
 
Line 3719... Line 3706...
3719
						break;
3706
						break;
3720
					}
3707
					}
3721
				}
3708
				}
3722
 
3709
 
3723
				if ( !found )
3710
				if ( !found )
3724
					return false;
3711
					return false;
3725
			}
3712
			}
3726
		}
3713
		}
3727
	}
3714
	}
3728
 
3715
 
3729
	return true;
3716
	return true;
3730
}
3717
}
3731
 
3718
 
3732
bool CPackages::CheckEnabledDependacy(CBaseFile *p)
3719
bool CPackages::CheckEnabledDependacy(CBaseFile *p)
3733
{
3720
{
3734
	// check the for another mod
3721
	// check the for another mod
3735
	if ( p->GetType() == TYPE_SPK )
3722
	if ( p->GetType() == TYPE_SPK )
3736
	{
3723
	{
3737
		if ( ((CSpkFile *)p)->IsAnotherMod() )
3724
		if ( ((CSpkFile *)p)->IsAnotherMod() )
3738
		{
3725
		{
3739
			CBaseFile *parent = this->FindSpkPackage(((CSpkFile *)p)->GetOtherName(), ((CSpkFile *)p)->GetOtherAuthor());
3726
			CBaseFile *parent = this->findSpkPackage(((CSpkFile *)p)->GetOtherName(), ((CSpkFile *)p)->GetOtherAuthor());
3740
			if ( parent )
3727
			if ( parent )
3741
			{
3728
			{
3742
				if ( !parent->IsEnabled() )
3729
				if ( !parent->IsEnabled() )
3743
					return false;
3730
					return false;
3744
			}
3731
			}
3745
			else
3732
			else
3746
				return false;
3733
				return false;
3747
		}
3734
		}
3748
	}
3735
	}
3749
 
3736
 
3750
	// check any dependacies
3737
	// check any dependacies
3751
	if ( p->AnyDependacies() )
3738
	if ( p->AnyDependacies() )
Line 3760... Line 3747...
3760
	}
3747
	}
3761
 
3748
 
3762
	return true;
3749
	return true;
3763
}
3750
}
3764
 
3751
 
3765
bool CPackages::CheckInstalledDependacy(CyString name, CyString author, CyString version, bool onlyEnabled, bool includePrepared)
-
 
3766
{
-
 
3767
	bool ret = checkInstalledDependacy(name.ToString(), author.ToString(), version.ToString(), onlyEnabled, includePrepared);
-
 
3768
	m_lInstallList.RemoveEmpty();
-
 
3769
	return ret;
-
 
3770
}
-
 
3771
bool CPackages::checkInstalledDependacy(const Utils::String &name, const Utils::String &author, const Utils::String &version, bool onlyEnabled, bool includePrepared) const
3752
bool CPackages::checkInstalledDependacy(const Utils::String &name, const Utils::String &author, const Utils::String &version, bool onlyEnabled, bool includePrepared) const
3772
{
3753
{
3773
	CBaseFile *p = this->findSpkPackage(name, author);
3754
	CBaseFile *p = this->findSpkPackage(name, author);
3774
	if ( p )
3755
	if ( p )
3775
	{
3756
	{
Line 4262... Line 4243...
4262
 *
4243
 *
4263
 * IE, when one is removed, the rest need to be shuffled down so theres no gaps
4244
 * IE, when one is removed, the rest need to be shuffled down so theres no gaps
4264
 */
4245
 */
4265
void CPackages::ShuffleFakePatches(CyStringList *errors)
4246
void CPackages::ShuffleFakePatches(CyStringList *errors)
4266
{
4247
{
4267
	int check = FindNextFakePatch();
4248
	int check = findNextFakePatch();
4268
 
4249
 
4269
	// lets make sure our order is correct
4250
	// lets make sure our order is correct
4270
	// find Lowest Fake Patch Installed
4251
	// find Lowest Fake Patch Installed
4271
	CLinkList<C_File> doneList;
4252
	CLinkList<C_File> doneList;
4272
	int lowest = FindLowestFakePatchInstalled();
4253
	int lowest = FindLowestFakePatchInstalled();
Line 4284... Line 4265...
4284
 
4265
 
4285
		if (p->AnyDependacies())
4266
		if (p->AnyDependacies())
4286
		{
4267
		{
4287
			for (SNeededLibrary* nl = p->GetNeededLibraries()->First(); nl; nl = p->GetNeededLibraries()->Next())
4268
			for (SNeededLibrary* nl = p->GetNeededLibraries()->First(); nl; nl = p->GetNeededLibraries()->Next())
4288
			{
4269
			{
4289
				auto package = FindPackage(nl->sName, nl->sAuthor);
4270
				auto package = findPackage(nl->sName, nl->sAuthor);
4290
				if (package)
4271
				if (package)
4291
				{
4272
				{
4292
					packagesBefore.insert(package);
4273
					packagesBefore.insert(package);
4293
					packagesAfter[p].insert(package);
4274
					packagesAfter[p].insert(package);
4294
				}
4275
				}
Line 4297... Line 4278...
4297
		CSpkFile* spk = dynamic_cast<CSpkFile*>(p);
4278
		CSpkFile* spk = dynamic_cast<CSpkFile*>(p);
4298
		if (spk)
4279
		if (spk)
4299
		{
4280
		{
4300
			if (spk->IsAnotherMod())
4281
			if (spk->IsAnotherMod())
4301
			{
4282
			{
4302
				auto package = FindPackage(spk->otherName(), spk->otherAuthor());
4283
				auto package = findPackage(spk->otherName(), spk->otherAuthor());
4303
				if (package)
4284
				if (package)
4304
				{
4285
				{
4305
					packagesBefore.insert(package);
4286
					packagesBefore.insert(package);
4306
					packagesAfter[p].insert(package);
4287
					packagesAfter[p].insert(package);
4307
				}
4288
				}
Line 4312... Line 4293...
4312
		{
4293
		{
4313
			packagesBefore.insert(p);
4294
			packagesBefore.insert(p);
4314
			auto& list = p->getFakePatchBeforeOrder();
4295
			auto& list = p->getFakePatchBeforeOrder();
4315
			for (auto itr = list.begin(); itr != list.end(); itr++)
4296
			for (auto itr = list.begin(); itr != list.end(); itr++)
4316
			{
4297
			{
4317
				auto package = FindPackage((*itr)->str, (*itr)->data);
4298
				auto package = findPackage((*itr)->str, (*itr)->data);
4318
				if (package)				
4299
				if (package)				
4319
					packagesAfter[package].insert(p);
4300
					packagesAfter[package].insert(p);
4320
			}
4301
			}
4321
		}
4302
		}
4322
		if (!p->getFakePatchAfterOrder().empty())
4303
		if (!p->getFakePatchAfterOrder().empty())
4323
		{
4304
		{
4324
			auto& list = p->getFakePatchAfterOrder();
4305
			auto& list = p->getFakePatchAfterOrder();
4325
			for (auto itr = list.begin(); itr != list.end(); itr++)
4306
			for (auto itr = list.begin(); itr != list.end(); itr++)
4326
			{
4307
			{
4327
				auto package = FindPackage((*itr)->str, (*itr)->data);
4308
				auto package = findPackage((*itr)->str, (*itr)->data);
4328
				if (package)
4309
				if (package)
4329
				{
4310
				{
4330
					packagesBefore.insert(package);
4311
					packagesBefore.insert(package);
4331
					packagesAfter[p].insert(package);
4312
					packagesAfter[p].insert(package);
4332
				}
4313
				}
Line 4592... Line 4573...
4592
					// if the file already exists, we need to move it elsewhere
4573
					// if the file already exists, we need to move it elsewhere
4593
					Utils::String nextName = Utils::String::PadNumber(lowest, 2);
4574
					Utils::String nextName = Utils::String::PadNumber(lowest, 2);
4594
					if ( CFileIO::Exists(m_sCurrentDir + "/" + nextName + ".cat") )
4575
					if ( CFileIO::Exists(m_sCurrentDir + "/" + nextName + ".cat") )
4595
					{
4576
					{
4596
						// find the file in our internal file list
4577
						// find the file in our internal file list
4597
						C_File *moveFile = FindFile(FILETYPE_MOD, nextName + ".cat");
4578
						C_File *moveFile = findFile(FILETYPE_MOD, nextName + ".cat");
4598
						if ( !moveFile ) // must not have it in our list ? lets move to the next
4579
						if ( !moveFile ) // must not have it in our list ? lets move to the next
4599
						{
4580
						{
4600
							lowest++;
4581
							lowest++;
4601
							continue;
4582
							continue;
4602
						}
4583
						}
4603
 
4584
 
4604
						// now we can move the the cat/dat file elsewhere, lets shuffle it to the highest free number
4585
						// now we can move the the cat/dat file elsewhere, lets shuffle it to the highest free number
4605
						ShufflePatchTo(moveFile, FindLastFakePatch(), errors);
4586
						ShufflePatchTo(moveFile, findLastFakePatch(), errors);
4606
					}
4587
					}
4607
 
4588
 
4608
					// space should be free, now lets shuffle it
4589
					// space should be free, now lets shuffle it
4609
					ShufflePatchTo(lowestFile, lowest, errors);
4590
					ShufflePatchTo(lowestFile, lowest, errors);
4610
				}
4591
				}
Line 4635... Line 4616...
4635
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4616
		// we only want cat and dat files, all fake patchs should be, but incase theres an error in the package somewhere we can check
4636
		if (!f->checkFileExt("cat"))
4617
		if (!f->checkFileExt("cat"))
4637
			continue;
4618
			continue;
4638
 
4619
 
4639
		// now lets check if its greater than our gap
4620
		// now lets check if its greater than our gap
4640
		int check = FindNextFakePatch();
4621
		int check = findNextFakePatch();
4641
		int patchNum = f->filename().token(".", 1).toInt();
4622
		int patchNum = f->filename().token(".", 1).toInt();
4642
		if ( patchNum <= check )
4623
		if ( patchNum <= check )
4643
			continue;
4624
			continue;
4644
 
4625
 
4645
		ShufflePatchTo(f, check, errors);
4626
		ShufflePatchTo(f, check, errors);
Line 4709... Line 4690...
4709
	}
4690
	}
4710
 
4691
 
4711
	return lowest;
4692
	return lowest;
4712
}
4693
}
4713
 
4694
 
4714
int CPackages::FindLastFakePatch(int start, CyString dir)
4695
int CPackages::findLastFakePatch(int start, const Utils::String &dir) const
4715
{
4696
{
4716
	CDirIO Dir((dir.Empty()) ? m_sCurrentDir : dir);
4697
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4717
 
4698
 
4718
	int check = start;
4699
	int check = start;
4719
	while ( check > 0 )
4700
	while ( check > 0 )
4720
	{
4701
	{
4721
		Utils::String checkStr = Utils::String::PadNumber(check, 2);
4702
		Utils::String checkStr = Utils::String::PadNumber(check, 2);
Line 4736... Line 4717...
4736
/**
4717
/**
4737
 * Find next fake patch
4718
 * Find next fake patch
4738
 *
4719
 *
4739
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4720
 * Searching for the next gap in patches, starting with 01.cat to 99.cat
4740
 */
4721
 */
4741
int CPackages::FindNextFakePatch(int start, CyString dir)
4722
int CPackages::findNextFakePatch(int start, const Utils::String &dir) const
4742
{
4723
{
4743
	CDirIO Dir((dir.Empty()) ? m_sCurrentDir : dir);
4724
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4744
 
4725
 
4745
	int check = start;
4726
	int check = start;
4746
	while ( check < 99 )
4727
	while ( check < 99 )
4747
	{
4728
	{
4748
		++check;
4729
		++check;
Line 4786... Line 4767...
4786
	}
4767
	}
4787
 
4768
 
4788
	return check;
4769
	return check;
4789
}
4770
}
4790
 
4771
 
4791
int CPackages::FindLastTextFile(int start, CyString dir)
4772
int CPackages::findLastTextFile(int start, const Utils::String& dir) const
4792
{
4773
{
4793
	CDirIO Dir((dir.Empty()) ? m_sCurrentDir : dir);
4774
	CDirIO Dir((dir.empty()) ? m_sCurrentDir : dir);
4794
	Dir.cd("t");
4775
	Dir.cd("t");
4795
 
4776
 
4796
	int check = start;
4777
	int check = start;
4797
	while ( check < 9999 )
4778
	while ( check < 9999 )
4798
	{
4779
	{
Line 4956... Line 4937...
4956
 */
4937
 */
4957
bool CPackages::RenameTextFile(const Utils::String &textid, int languageid, Utils::CStringList *errors)
4938
bool CPackages::RenameTextFile(const Utils::String &textid, int languageid, Utils::CStringList *errors)
4958
{
4939
{
4959
	// lets check if the file already exists
4940
	// lets check if the file already exists
4960
	Utils::String newFilename = SPK::FormatTextName(textid.toInt(), m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4941
	Utils::String newFilename = SPK::FormatTextName(textid.toInt(), m_iLanguage, (m_iGameFlags & EXEFLAG_TCTEXT));
4961
	C_File *addFile = FindFile(FILETYPE_TEXT, newFilename + ".xml");
4942
	C_File *addFile = findFile(FILETYPE_TEXT, newFilename + ".xml");
4962
	if ( !addFile )
4943
	if ( !addFile )
4963
		addFile = FindFile(FILETYPE_TEXT, newFilename + ".pck");
4944
		addFile = findFile(FILETYPE_TEXT, newFilename + ".pck");
4964
 
4945
 
4965
	// we have found the file, lets just add it to our scripts
4946
	// we have found the file, lets just add it to our scripts
4966
	if ( addFile )
4947
	if ( addFile )
4967
	{
4948
	{
4968
		AddTextFileToScripts(addFile, textid);
4949
		addTextFileToScripts(addFile, textid);
4969
		return true;
4950
		return true;
4970
	}
4951
	}
4971
 
4952
 
4972
	// first we need to find our text file
4953
	// first we need to find our text file
4973
	Utils::String filename;
4954
	Utils::String filename;
4974
	if ( languageid != -1 )
4955
	if ( languageid != -1 )
4975
		filename = SPK::FormatTextName(textid.toInt(), languageid, (m_iGameFlags & EXEFLAG_TCTEXT));
4956
		filename = SPK::FormatTextName(textid.toInt(), languageid, (m_iGameFlags & EXEFLAG_TCTEXT));
4976
	else
4957
	else
4977
		filename = textid;
4958
		filename = textid;
4978
 
4959
 
4979
	C_File *textFile = FindFile(FILETYPE_TEXT, filename + ".xml");
4960
	C_File *textFile = findFile(FILETYPE_TEXT, filename + ".xml");
4980
	if ( !textFile )
4961
	if ( !textFile )
4981
	{
4962
	{
4982
		textFile = FindFile(FILETYPE_TEXT, filename + ".pck");
4963
		textFile = findFile(FILETYPE_TEXT, filename + ".pck");
4983
		if ( !textFile )
4964
		if ( !textFile )
4984
			return false;
4965
			return false;
4985
	}
4966
	}
4986
 
4967
 
4987
	// now lets create out new text file
4968
	// now lets create out new text file
Line 5024... Line 5005...
5024
		// now we have the file wrriten, we need to add it to all scripts that need it
5005
		// now we have the file wrriten, we need to add it to all scripts that need it
5025
		// first we add it to the global list
5006
		// first we add it to the global list
5026
		m_lFiles.push_back(addFile);
5007
		m_lFiles.push_back(addFile);
5027
 
5008
 
5028
		// now add it to the scripts
5009
		// now add it to the scripts
5029
		AddTextFileToScripts(addFile, textid);
5010
		addTextFileToScripts(addFile, textid);
5030
	}
5011
	}
5031
	else
5012
	else
5032
	{
5013
	{
5033
		this->addLogEntry(SPKINSTALL_WRITEFILE_FAIL, addFile->getNameDirectory(NULL), errors);
5014
		this->addLogEntry(SPKINSTALL_WRITEFILE_FAIL, addFile->getNameDirectory(NULL), errors);
5034
		if ( lines )
5015
		if ( lines )
Line 5046... Line 5027...
5046
/**
5027
/**
5047
 * Add file to scripts
5028
 * Add file to scripts
5048
 *
5029
 *
5049
 * Adds a file to all scripts that need it
5030
 * Adds a file to all scripts that need it
5050
 */
5031
 */
5051
void CPackages::AddTextFileToScripts(C_File *file, CyString textid)
5032
void CPackages::addTextFileToScripts(C_File *file, const Utils::String &textid)
5052
{
5033
{
5053
	// now we need to find all scripts that have a matching file and add this to the list
5034
	// now we need to find all scripts that have a matching file and add this to the list
5054
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5035
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5055
	{
5036
	{
5056
		CBaseFile *package = node->Data();
5037
		CBaseFile *package = node->Data();
Line 5065... Line 5046...
5065
			C_File *tFile = fNode->Data();
5046
			C_File *tFile = fNode->Data();
5066
			if ( tFile->GetFileType() != FILETYPE_TEXT )
5047
			if ( tFile->GetFileType() != FILETYPE_TEXT )
5067
				continue;
5048
				continue;
5068
 
5049
 
5069
			Utils::String id = tFile->baseName().token("-", 1);
5050
			Utils::String id = tFile->baseName().token("-", 1);
5070
			if ( id == textid.ToString() )
5051
			if ( id == textid )
5071
			{
5052
			{
5072
				found = true;
5053
				found = true;
5073
				break;
5054
				break;
5074
			}
5055
			}
5075
		}
5056
		}
Line 5174... Line 5155...
5174
/**
5155
/**
5175
 * Get Install Before Text
5156
 * Get Install Before Text
5176
 *
5157
 *
5177
 * Returns the install before text for the package in the correct language
5158
 * Returns the install before text for the package in the correct language
5178
 */
5159
 */
5179
CyString CPackages::GetInstallBeforeText(CBaseFile *package)
5160
Utils::String CPackages::getInstallBeforeText(CBaseFile *package) const
5180
{
5161
{
5181
	return package->installText(m_iLanguage, true);
5162
	return package->installText(m_iLanguage, true);
5182
}
5163
}
5183
CyString CPackages::GetInstallAfterText(CBaseFile *package)
5164
Utils::String CPackages::getInstallAfterText(CBaseFile *package) const
5184
{
5165
{
5185
	return package->installText(m_iLanguage, false);
5166
	return package->installText(m_iLanguage, false);
5186
}
5167
}
5187
CyString CPackages::GetUninstallBeforeText(CBaseFile *package)
5168
Utils::String CPackages::getUninstallBeforeText(CBaseFile *package) const
5188
{
5169
{
5189
	return package->uninstallText(m_iLanguage, true);
5170
	return package->uninstallText(m_iLanguage, true);
5190
}
5171
}
5191
CyString CPackages::GetUninstallAfterText(CBaseFile *package)
5172
Utils::String CPackages::getUninstallAfterText(CBaseFile *package) const
5192
{
5173
{
5193
	return package->uninstallText(m_iLanguage, false);
5174
	return package->uninstallText(m_iLanguage, false);
5194
}
5175
}
5195
 
5176
 
5196
int CPackages::GetChildPackages(CBaseFile *package, CLinkList<CBaseFile> *children, bool recursive)
5177
int CPackages::GetChildPackages(CBaseFile *package, CLinkList<CBaseFile> *children, bool recursive)
Line 5265... Line 5246...
5265
void CPackages::Startup(CyString dir, CyString tempDir, CyString myDoc, CyString mod)
5246
void CPackages::Startup(CyString dir, CyString tempDir, CyString myDoc, CyString mod)
5266
{
5247
{
5267
	startup(dir.ToString(), tempDir.ToString(), myDoc.ToString(), mod.ToString());
5248
	startup(dir.ToString(), tempDir.ToString(), myDoc.ToString(), mod.ToString());
5268
}*/
5249
}*/
5269
 
5250
 
5270
int CPackages::GetGameLanguage() const
5251
int CPackages::getGameLanguage() const
5271
{
5252
{
5272
	return this->GetGameLanguage(m_sCurrentDir);
5253
	return this->getGameLanguage(m_sCurrentDir);
5273
}
5254
}
5274
int CPackages::GetGameLanguage(const Utils::String &sDir) const
5255
int CPackages::getGameLanguage(const Utils::String &sDir) const
5275
{
5256
{
5276
	Utils::String dir = sDir;
5257
	Utils::String dir = sDir;
5277
	if (dir.empty())
5258
	if (dir.empty())
5278
		dir = m_sCurrentDir;
5259
		dir = m_sCurrentDir;
5279
	else
5260
	else
Line 5296... Line 5277...
5296
		}
5277
		}
5297
	}
5278
	}
5298
 
5279
 
5299
	return 0;
5280
	return 0;
5300
}
5281
}
5301
Utils::String CPackages::GetGameRunExe(const Utils::String &dir)
5282
Utils::String CPackages::getGameRunExe(const Utils::String &dir) const
5302
{
5283
{
5303
	return m_gameExe.GetGameRunExe(dir);
5284
	return m_gameExe.GetGameRunExe(dir);
5304
}
5285
}
5305
Utils::String CPackages::GetGameRunExe()
5286
Utils::String CPackages::getGameRunExe() const
5306
{
5287
{
5307
	return m_gameExe.GetGameRunExe(m_sCurrentDir);
5288
	return m_gameExe.GetGameRunExe(m_sCurrentDir);
5308
}
5289
}
5309
 
5290
 
5310
CyString CPackages::GetGameNameFromType(int game)
5291
Utils::String CPackages::getGameNameFromType(int game) const
5311
{
5292
{
5312
	return m_gameExe.GetGameNameFromType(game - 1);
5293
	return m_gameExe.GetGameNameFromType(game - 1);
5313
}
5294
}
5314
Utils::String CPackages::getGameName() const
5295
Utils::String CPackages::getGameName() const
5315
{
5296
{
Line 5319... Line 5300...
5319
Utils::String CPackages::getGameName(const Utils::String &dir) const
5300
Utils::String CPackages::getGameName(const Utils::String &dir) const
5320
{
5301
{
5321
	return m_gameExe.GetGameName(dir.empty() ? m_sCurrentDir : dir);
5302
	return m_gameExe.GetGameName(dir.empty() ? m_sCurrentDir : dir);
5322
}
5303
}
5323
 
5304
 
5324
CyString CPackages::GetGameName(CyString dir)
-
 
5325
{
-
 
5326
	return m_gameExe.GetGameName((dir.Empty()) ? m_sCurrentDir : dir.ToString());
-
 
5327
}
-
 
5328
CyString CPackages::GetProperDir(CyString dir)
-
 
5329
{
-
 
5330
	return m_gameExe.GetProperDir((dir.Empty()) ? m_sCurrentDir : dir.ToString());
-
 
5331
}
-
 
5332
CyString CPackages::GetAddonDir(CyString dir)
-
 
5333
{
-
 
5334
	return m_gameExe.GetAddonDir((dir.Empty()) ? m_sCurrentDir : dir.ToString());
-
 
5335
}
-
 
5336
Utils::String CPackages::getProperDir() const
5305
Utils::String CPackages::getProperDir() const
5337
{
5306
{
5338
	return getProperDir(m_sCurrentDir);
5307
	return getProperDir(m_sCurrentDir);
5339
}
5308
}
5340
Utils::String CPackages::getProperDir(const Utils::String &dir) const
5309
Utils::String CPackages::getProperDir(const Utils::String &dir) const
Line 5347... Line 5316...
5347
}
5316
}
5348
Utils::String CPackages::getAddonDir(const Utils::String &dir) const
5317
Utils::String CPackages::getAddonDir(const Utils::String &dir) const
5349
{
5318
{
5350
	return m_gameExe.GetAddonDir((dir.empty()) ? m_sCurrentDir : dir);
5319
	return m_gameExe.GetAddonDir((dir.empty()) ? m_sCurrentDir : dir);
5351
}
5320
}
5352
int CPackages::GetGameAddons(Utils::CStringList &exes, const Utils::String &dir)
5321
int CPackages::getGameAddons(Utils::CStringList &exes, const Utils::String &dir) const
5353
{
5322
{
5354
	return m_gameExe.GetGameAddons((dir.empty()) ? m_sCurrentDir : dir, exes);
5323
	return m_gameExe.getGameAddons((dir.empty()) ? m_sCurrentDir : dir, exes);
5355
}
5324
}
5356
int CPackages::GetGameAddons(Utils::CStringList &exes)
5325
int CPackages::getGameAddons(Utils::CStringList &exes) const
5357
{
5326
{
5358
	return m_gameExe.GetGameAddons(m_sCurrentDir, exes);
5327
	return m_gameExe.getGameAddons(m_sCurrentDir, exes);
5359
}
5328
}
5360
 
5329
 
5361
Utils::String CPackages::getGameTypesString(CBaseFile *package, bool includeVersion)
5330
Utils::String CPackages::getGameTypesString(CBaseFile *package, bool includeVersion) const
5362
{
5331
{
5363
	if ( !package->AnyGameCompatability() )
5332
	if ( !package->AnyGameCompatability() )
5364
		return "";
5333
		return "";
5365
 
5334
 
5366
	Utils::String sGames;
5335
	Utils::String sGames;
Line 5378... Line 5347...
5378
		}
5347
		}
5379
	}
5348
	}
5380
	return sGames;
5349
	return sGames;
5381
}
5350
}
5382
 
5351
 
5383
CyString CPackages::GetGameVersionString(CBaseFile *package)
5352
Utils::String CPackages::getGameVersionString(CBaseFile *package) const
5384
{
5353
{
5385
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5354
	for ( CListNode<SGameCompat> *gNode = package->GetGameCompatabilityList()->Front(); gNode; gNode = gNode->next() ) {
5386
		if ( gNode->Data()->iGame == m_iGame ) {
5355
		if ( gNode->Data()->iGame == m_iGame ) {
5387
			return m_gameExe.GetGameVersionFromType(m_iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
5356
			return m_gameExe.GetGameVersionFromType(m_iGame - 1, gNode->Data()->iVersion - 1, gNode->Data()->sVersion);
5388
		}
5357
		}
5389
	}
5358
	}
5390
 
5359
 
5391
	return NullString;
5360
	return Utils::String::Null();
5392
}
5361
}
5393
 
5362
 
5394
CyString CPackages::GetGameVersionFromType(int game, int version, CyString sVersion)
5363
Utils::String CPackages::getGameVersionFromType(int game, int version, const Utils::String &sVersion) const
5395
{
5364
{
5396
	return m_gameExe.GetGameVersionFromType(game - 1, version - 1, sVersion.ToString());
5365
	return m_gameExe.GetGameVersionFromType(game - 1, version - 1, sVersion);
5397
}
5366
}
5398
 
5367
 
5399
int CPackages::CountBuiltInPackages(bool onlyEnabled)
5368
int CPackages::CountBuiltInPackages(bool onlyEnabled)
5400
{
5369
{
5401
	int count = 0;
5370
	int count = 0;
5402
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5371
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5403
	{
5372
	{
5404
		if ( !node->Data()->CheckGameCompatability(m_iGame) )
5373
		if ( !node->Data()->CheckGameCompatability(m_iGame) )
5405
			continue;
5374
			continue;
5406
		if ( onlyEnabled && !node->Data()->IsEnabled() )
5375
		if ( onlyEnabled && !node->Data()->IsEnabled() )
5407
			continue;
5376
			continue;
5408
		if ( node->Data()->author().Compare("PluginManager") )
5377
		if ( node->Data()->author().Compare("PluginManager") )
5409
			++count;
5378
			++count;
5410
	}
5379
	}
5411
 
5380
 
5412
	return count;
5381
	return count;
5413
}
5382
}
5414
 
5383
 
5415
int CPackages::countPackages(int type, bool onlyEnabled) const
5384
int CPackages::countPackages(int type, bool onlyEnabled) const
5416
{
5385
{
5417
	int count = 0;
5386
	int count = 0;
5418
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5387
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
Line 5527... Line 5496...
5527
 
5496
 
5528
		int e;
5497
		int e;
5529
		if ( i == WARES_TECH && CFileIO::Exists(m_sTempDir + "/TWareT.txt") )
5498
		if ( i == WARES_TECH && CFileIO::Exists(m_sTempDir + "/TWareT.txt") )
5530
			openFile = m_sTempDir + "/TWareT.txt";
5499
			openFile = m_sTempDir + "/TWareT.txt";
5531
		else {
5500
		else {
5532
			e = ExtractGameFile("types/" + wareFile + ".pck", m_sTempDir + "/" + wareFile + ".txt");
5501
			e = extractGameFile("types/" + wareFile + ".pck", m_sTempDir + "/" + wareFile + ".txt");
5533
			if ( e == 1 )
5502
			if ( e == 1 )
5534
				openFile = m_sTempDir + "/" + wareFile + ".txt";
5503
				openFile = m_sTempDir + "/" + wareFile + ".txt";
5535
			else if ( e == -2 )
5504
			else if ( e == -2 )
5536
				openFile = wareFile + ".txt";
5505
				openFile = wareFile + ".txt";
5537
		}
5506
		}
Line 5617... Line 5586...
5617
						int notority = w->pWare->iNotority;
5586
						int notority = w->pWare->iNotority;
5618
						if ( !this->customWareOverideNoto(w->pWare->sID, &notority) ) notority = w->pWare->iNotority;
5587
						if ( !this->customWareOverideNoto(w->pWare->sID, &notority) ) notority = w->pWare->iNotority;
5619
						if ( !price ) price = w->pWare->iPrice;
5588
						if ( !price ) price = w->pWare->iPrice;
5620
 
5589
 
5621
						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() + ";");
5590
						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() + ";");
5622
					}
5591
					}
5623
				}
5592
				}
5624
 
5593
 
5625
				if ( create )
5594
				if ( create )
5626
				{
5595
				{
5627
					wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5596
					wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5628
					Utils::String strV;
5597
					Utils::String strV;
5629
					strV.FromFloat(GetLibraryVersion(), 2);
5598
					strV.FromFloat(GetLibraryVersion(), 2);
5630
					wareLines.pushFront("// Created by SPKInstaller Libraries V" + strV, Utils::String::Null());
5599
					wareLines.pushFront("// Created by SPKInstaller Libraries V" + strV, Utils::String::Null());
5631
					if ( readFile.writeFile(&wareLines) )
5600
					if ( readFile.writeFile(&wareLines) )
5632
						this->PackFile(&readFile, CyString("types\\") + wareFile + ".pck");
5601
						this->packFile(&readFile, "types\\" + wareFile + ".pck");
5633
				}
5602
				}
5634
			}
5603
			}
5635
			readFile.remove();
5604
			readFile.remove();
5636
		}
5605
		}
5637
	}
5606
	}
5638
}
5607
}
5639
 
5608
 
5640
Utils::String CPackages::empWaresForGame(size_t *maxsize)
5609
Utils::String CPackages::empWaresForGame(size_t *maxsize)
5641
{
5610
{
5642
	if ( maxsize ) (*maxsize) = 0;
5611
	if ( maxsize ) (*maxsize) = 0;
5643
 
5612
 
5644
	if ( m_iGame == GAME_X3TC )
5613
	if ( m_iGame == GAME_X3TC )
5645
	{
5614
	{
5646
		if ( maxsize ) (*maxsize) = EMP_X3TC;
5615
		if ( maxsize ) (*maxsize) = EMP_X3TC;
5647
		return GetX3TCEmp();
5616
		return GetX3TCEmp();
5648
	}
5617
	}
5649
	else if (m_iGame == GAME_X3AP)
5618
	else if (m_iGame == GAME_X3AP)
5650
	{
5619
	{
5651
		if (maxsize) (*maxsize) = EMP_X3AP;
5620
		if (maxsize) (*maxsize) = EMP_X3AP;
5652
		return GetX3TCEmp();
5621
		return GetX3TCEmp();
5653
	}
5622
	}
5654
	else if (m_iGame == GAME_X3FL)
5623
	else if (m_iGame == GAME_X3FL)
5655
	{
5624
	{
5656
		if (maxsize) (*maxsize) = EMP_X3FL;
5625
		if (maxsize) (*maxsize) = EMP_X3FL;
5657
		return GetX3TCEmp();
5626
		return GetX3TCEmp();
5658
	}
5627
	}
5659
	else if ( m_iGame == GAME_X3 )
5628
	else if ( m_iGame == GAME_X3 )
5660
	{
5629
	{
Line 5698... Line 5667...
5698
}
5667
}
5699
 
5668
 
5700
void CPackages::addEMPNotoOverride(int empId, int noto)
5669
void CPackages::addEMPNotoOverride(int empId, int noto)
5701
{
5670
{
5702
	_addWareOverride(Ware_EMP, empId, Utils::String::Null(), noto, true);
5671
	_addWareOverride(Ware_EMP, empId, Utils::String::Null(), noto, true);
5703
}
5672
}
5704
 
5673
 
5705
void CPackages::addBuiltInWarePriceOverride(int empId, int price)
5674
void CPackages::addBuiltInWarePriceOverride(int empId, int price)
5706
{
5675
{
5707
	_addWareOverride(Ware_BuiltIn, empId, Utils::String::Null(), price, false);
5676
	_addWareOverride(Ware_BuiltIn, empId, Utils::String::Null(), price, false);
5708
}
5677
}
5709
 
5678
 
5710
void CPackages::addBuiltInWareNotoOverride(int empId, int noto)
5679
void CPackages::addBuiltInWareNotoOverride(int empId, int noto)
5711
{
5680
{
5712
	_addWareOverride(Ware_BuiltIn, empId, Utils::String::Null(), noto, false);
5681
	_addWareOverride(Ware_BuiltIn, empId, Utils::String::Null(), noto, false);
5713
}
5682
}
5714
 
5683
 
5715
void CPackages::addCustomWarePriceOverride(const Utils::String &id, int price)
5684
void CPackages::addCustomWarePriceOverride(const Utils::String &id, int price)
5716
{
5685
{
5717
	_addWareOverride(Ware_Custom, 0, id, price, false);
5686
	_addWareOverride(Ware_Custom, 0, id, price, false);
5718
}
5687
}
5719
 
5688
 
5720
void CPackages::addCustomWareNotoOverride(const Utils::String &id, int noto)
5689
void CPackages::addCustomWareNotoOverride(const Utils::String &id, int noto)
5721
{
5690
{
5722
	_addWareOverride(Ware_Custom, 0, id, noto, true);
5691
	_addWareOverride(Ware_Custom, 0, id, noto, true);
5723
}
5692
}
5724
 
5693
 
5725
 
5694
 
5726
void CPackages::CreateEMPFile(CyString progDir)
5695
void CPackages::createEMPFile(const Utils::String &progDir)
5727
{
5696
{
5728
	// do emp wares
5697
	// do emp wares
5729
	size_t maxsize = 0;
5698
	size_t maxsize = 0;
5730
	Utils::String empWares = empWaresForGame(&maxsize);
5699
	Utils::String empWares = empWaresForGame(&maxsize);
5731
 
5700
 
5732
	if ( maxsize )
5701
	if ( maxsize )
5733
	{
5702
	{
5734
		int e = ExtractGameFile("types/TWareT.pck", m_sTempDir + "/TWareT.txt");
5703
		int e = extractGameFile("types/TWareT.pck", m_sTempDir + "/TWareT.txt");
5735
		if ( e )
5704
		if (e)
5736
		{
5705
		{
5737
			// read the file into memory
5706
			// read the file into memory
5738
			Utils::CStringList wareLines;
5707
			Utils::CStringList wareLines;
5739
			size_t oldSize = -1;
5708
			size_t oldSize = -1;
5740
			int version = -1;
5709
			int version = -1;
5741
 
5710
 
5742
			// read first number
5711
			// read first number
5743
			CFileIO readFile((e == -1) ? "TWareT.txt" : m_sTempDir + "/TWareT.txt");
5712
			CFileIO readFile((e == -1) ? "TWareT.txt" : m_sTempDir + "/TWareT.txt");
5744
			std::vector<Utils::String> *lines = readFile.readLines();
5713
			std::vector<Utils::String> lines;
5745
			if ( lines )
5714
			if(readFile.readLines(lines))
5746
			{
5715
			{
5747
				for ( int i = 0; i < (int)lines->size(); i++ )
5716
				for ( int i = 0; i < (int)lines.size(); i++ )
5748
				{
5717
				{
5749
					Utils::String line(lines->at(i));
5718
					Utils::String line(lines.at(i));
5750
					line.removeFirstSpace();
5719
					line.removeFirstSpace();
5751
					line.removeChar('\r');
5720
					line.removeChar('\r');
5752
					line.removeChar(9);
5721
					line.removeChar(9);
5753
					if ( line[0] == '/' )
5722
					if ( line[0] == '/' )
5754
						continue;
5723
						continue;
5755
 
5724
 
5756
					if ( oldSize == -1 )
5725
					if ( oldSize == -1 )
5757
					{
5726
					{
5758
						version = line.token(";", 1).toLong();
5727
						version = line.token(";", 1).toLong();
5759
						oldSize = line.token(";", 2).toLong();
5728
						oldSize = line.token(";", 2).toLong();
5760
					}
5729
					}
5761
					else
5730
					else
5762
					{
5731
					{
5763
						line.removeEndSpace();
5732
						line.removeEndSpace();
5764
						if ( line.right(1) != ";" )
5733
						if ( line.right(1) != ";" )
5765
							line += ";";
5734
							line += ";";
5766
 
5735
 
5767
						// check for any override values for built in wares
5736
						// check for any override values for built in wares
Line 5773... Line 5742...
5773
								line = line.replaceToken(";", 13, Utils::String::Number(price));
5742
								line = line.replaceToken(";", 13, Utils::String::Number(price));
5774
							}
5743
							}
5775
 
5744
 
5776
							int noto = 0;
5745
							int noto = 0;
5777
							if ( this->builtInWareOverideNoto(pos, &noto) ) {
5746
							if ( this->builtInWareOverideNoto(pos, &noto) ) {
5778
								line = line.replaceToken(";", 14, Utils::String::Number(noto));
5747
								line = line.replaceToken(";", 14, Utils::String::Number(noto));
5779
							}
5748
							}
5780
						}
5749
						}
5781
 
5750
 
5782
						// check for any override values for EMP
5751
						// check for any override values for EMP
5783
						if ( i >= 116 ) {
5752
						if ( i >= 116 ) {
5784
							int price = this->empOveridePrice(i - 116);
5753
							int price = this->empOveridePrice(i - 116);
5785
							if ( price ) {
5754
							if ( price ) {
5786
								line = line.replaceToken(";", 9, Utils::String::Number(price));
5755
								line = line.replaceToken(";", 9, Utils::String::Number(price));
5787
								line = line.replaceToken(";", 13, Utils::String::Number(price));
5756
								line = line.replaceToken(";", 13, Utils::String::Number(price));
5788
							}
5757
							}
5789
 
5758
 
5790
							int noto = 0;
5759
							int noto = 0;
5791
							if ( this->empOverideNoto(i - 116, &noto) ) {
5760
							if ( this->empOverideNoto(i - 116, &noto) ) {
5792
								line = line.replaceToken(";", 14, Utils::String::Number(noto));
5761
								line = line.replaceToken(";", 14, Utils::String::Number(noto));
5793
							}
5762
							}
5794
						}
5763
						}
5795
 
5764
 
5796
						wareLines.pushBack(line);
5765
						wareLines.pushBack(line);
5797
						if ( wareLines.size() >= oldSize )
5766
						if ( wareLines.size() >= oldSize )
5798
							break;
5767
							break;
5799
					}
5768
					}
5800
				}
5769
				}
5801
 
-
 
5802
				delete lines;
-
 
5803
			}
5770
			}
5804
 
5771
 
5805
			// now we too add/remove entries to match
5772
			// now we too add/remove entries to match
5806
			// need filler entries
5773
			// need filler entries
5807
			while ( wareLines.size() < maxsize )
5774
			while ( wareLines.size() < maxsize )
Line 5840... Line 5807...
5840
						{
5807
						{
5841
							for (size_t i = (maxsize + empEntries); i < wareLines.size(); i++)
5808
							for (size_t i = (maxsize + empEntries); i < wareLines.size(); i++)
5842
							{
5809
							{
5843
								auto node = wareLines.get(i);
5810
								auto node = wareLines.get(i);
5844
								addAfter.pushBack(node->str);
5811
								addAfter.pushBack(node->str);
5845
							}
5812
							}
5846
						}
5813
						}
5847
 
5814
 
5848
						// no remove them all
5815
						// no remove them all
5849
						while (wareLines.size() > maxsize)
5816
						while (wareLines.size() > maxsize)
5850
							wareLines.removeAt(wareLines.size() - 1);
5817
							wareLines.removeAt(wareLines.size() - 1);
5851
					}
5818
					}
Line 5890... Line 5857...
5890
 
5857
 
5891
				// finally we write the whole file
5858
				// finally we write the whole file
5892
				wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5859
				wareLines.pushFront(Utils::String::Number(version) + ";" + Utils::String::Number(wareLines.size()) + ";", Utils::String::Null());
5893
				wareLines.pushFront("// Created by SPKInstaller Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2), Utils::String::Null());
5860
				wareLines.pushFront("// Created by SPKInstaller Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2), Utils::String::Null());
5894
				if ( readFile.writeFile(&wareLines) )
5861
				if ( readFile.writeFile(&wareLines) )
5895
					this->PackFile(&readFile, "types\\TWareT.pck");
5862
					this->packFile(&readFile, "types\\TWareT.pck");
5896
			}
5863
			}
5897
			CLEANSPLIT(empStr, empEntries);
5864
			CLEANSPLIT(empStr, empEntries);
5898
		}
5865
		}
5899
	}
5866
	}
5900
}
5867
}
5901
 
5868
 
Line 5923... Line 5890...
5923
		pos = sStr.find_first_of("&", pos + 1);
5890
		pos = sStr.find_first_of("&", pos + 1);
5924
	}
5891
	}
5925
 
5892
 
5926
	// replace the & now
5893
	// replace the & now
5927
	newStr = newStr.findReplace("&", "&amp;");
5894
	newStr = newStr.findReplace("&", "&amp;");
5928
 
5895
 
5929
	// restore the commands
5896
	// restore the commands
5930
	for ( SStringList *strNode = changes.Head(); strNode; strNode = strNode->next ) {
5897
	for ( SStringList *strNode = changes.Head(); strNode; strNode = strNode->next ) {
5931
		newStr = newStr.findReplace(strNode->data.ToString(), strNode->str.ToString());
5898
		newStr = newStr.findReplace(strNode->data.ToString(), strNode->str.ToString());
5932
	}
5899
	}
5933
 
5900
 
Line 5962... Line 5929...
5962
		default: return 0;
5929
		default: return 0;
5963
	}
5930
	}
5964
}
5931
}
5965
 
5932
 
5966
void CPackages::createPluginManagerOpenText()
5933
void CPackages::createPluginManagerOpenText()
5967
{
5934
{
5968
	int gameNumber = _gameTextNumber();
5935
	int gameNumber = _gameTextNumber();
5969
 
5936
 
5970
	int lang = m_iLanguage;
5937
	int lang = m_iLanguage;
5971
	if ( !lang || lang < 0 )
5938
	if ( !lang || lang < 0 )
5972
		lang = 44;
5939
		lang = 44;
5973
 
5940
 
5974
	CDirIO Dir(m_sCurrentDir);
5941
	CDirIO Dir(m_sCurrentDir);
5975
	if ( !Dir.exists("t") )
5942
	if ( !Dir.exists("t") )
5976
		Dir.create("t");
5943
		Dir.create("t");
5977
 
5944
 
5978
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5945
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5979
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5946
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5980
 
5947
 
5981
	std::vector<Utils::String> writeData;
5948
	std::vector<Utils::String> writeData;
Line 6004... Line 5971...
6004
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
5971
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
6005
		if ( pckData )
5972
		if ( pckData )
6006
		{
5973
		{
6007
			CFileIO pckFile(m_sCurrentDir + "/t/" + filename + ".pck");
5974
			CFileIO pckFile(m_sCurrentDir + "/t/" + filename + ".pck");
6008
			pckFile.WriteData((char *)pckData, newFileSize);
5975
			pckFile.WriteData((char *)pckData, newFileSize);
6009
			this->AddCreatedFile(pckFile.fullFilename());
5976
			this->addCreatedFile(pckFile.fullFilename());
6010
		}
5977
		}
6011
	}
5978
	}
6012
	textFile.remove();
5979
	textFile.remove();
6013
}
5980
}
6014
 
5981
 
Line 6021... Line 5988...
6021
		lang = 44;
5988
		lang = 44;
6022
 
5989
 
6023
	CDirIO Dir(m_sCurrentDir);
5990
	CDirIO Dir(m_sCurrentDir);
6024
	if ( !Dir.exists("t") )
5991
	if ( !Dir.exists("t") )
6025
		Dir.create("t");
5992
		Dir.create("t");
6026
 
5993
 
6027
	m_iLastUpdated = (int)time(NULL);
5994
	m_iLastUpdated = (int)time(NULL);
6028
 
5995
 
6029
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
5996
	Utils::String filename = SPK::FormatTextName(PMTEXTFILE, lang, (m_iGameFlags & EXEFLAG_TCTEXT));
6030
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
5997
	CFileIO textFile(m_sCurrentDir + "/t/" + filename + ".xml");
6031
 
5998
 
6032
	std::vector<Utils::String> writeData;
5999
	std::vector<Utils::String> writeData;
6033
 
6000
 
Line 6271... Line 6238...
6271
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
6238
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
6272
		if ( pckData )
6239
		if ( pckData )
6273
		{
6240
		{
6274
			CFileIO pckFile(m_sCurrentDir + "/t/" + filename + ".pck");
6241
			CFileIO pckFile(m_sCurrentDir + "/t/" + filename + ".pck");
6275
			pckFile.WriteData((char *)pckData, newFileSize);
6242
			pckFile.WriteData((char *)pckData, newFileSize);
6276
			this->AddCreatedFile(pckFile.fullFilename());
6243
			this->addCreatedFile(pckFile.fullFilename());
6277
		}
6244
		}
6278
	}
6245
	}
6279
	textFile.remove();
6246
	textFile.remove();
6280
}
6247
}
6281
 
6248
 
Line 6286... Line 6253...
6286
	if ( dir.Compare(cur) )
6253
	if ( dir.Compare(cur) )
6287
		return true;
6254
		return true;
6288
 
6255
 
6289
	Utils::String checkDir = cur;
6256
	Utils::String checkDir = cur;
6290
	checkDir = checkDir.findReplace("/", "\\");
6257
	checkDir = checkDir.findReplace("/", "\\");
6291
	if ( checkDir.Compare(dir) )
6258
	if ( checkDir.Compare(dir) )
6292
		return true;
6259
		return true;
6293
 
6260
 
6294
	checkDir = checkDir.findReplace("\\", "/");
6261
	checkDir = checkDir.findReplace("\\", "/");
6295
	if ( checkDir.Compare(dir) )
6262
	if ( checkDir.Compare(dir) )
6296
		return true;
6263
		return true;
Line 6418... Line 6385...
6418
		return;
6385
		return;
6419
 
6386
 
6420
	CLinkList<SDummyEntry> dummyList;
6387
	CLinkList<SDummyEntry> dummyList;
6421
 
6388
 
6422
	// now extract the existing dummies
6389
	// now extract the existing dummies
6423
	int e = ExtractGameFile("types/Dummies.pck", m_sTempDir + "/Dummies.txt");
6390
	int e = extractGameFile("types/Dummies.pck", m_sTempDir + "/Dummies.txt");
6424
	if ( e )
6391
	if ( e )
6425
	{
6392
	{
6426
		// read the dummies
6393
		// read the dummies
6427
		CFileIO File;
6394
		CFileIO File;
6428
		if ( File.open((e == -1) ? "Dummies.txt" : m_sTempDir + "/Dummies.txt") )
6395
		if ( File.open((e == -1) ? "Dummies.txt" : m_sTempDir + "/Dummies.txt") )
Line 6549... Line 6516...
6549
							break;
6516
							break;
6550
						}
6517
						}
6551
					}
6518
					}
6552
 
6519
 
6553
					if ( f )
6520
					if ( f )
6554
						continue;
6521
						continue;
6555
				}
6522
				}
6556
 
6523
 
6557
				found->lEntries.PushBack(CyString(dummy->sData));
6524
				found->lEntries.PushBack(CyString(dummy->sData));
6558
			}
6525
			}
6559
		}
6526
		}
Line 6583... Line 6550...
6583
 
6550
 
6584
		// write the file to disk
6551
		// write the file to disk
6585
		CFileIO WriteFile(m_sTempDir + "/dummies.txt");
6552
		CFileIO WriteFile(m_sTempDir + "/dummies.txt");
6586
		if ( WriteFile.writeFile(&lines) )
6553
		if ( WriteFile.writeFile(&lines) )
6587
		{
6554
		{
6588
			this->PackFile(&WriteFile, "types\\dummies.pck");
6555
			this->packFile(&WriteFile, "types\\dummies.pck");
6589
			WriteFile.remove();
6556
			WriteFile.remove();
6590
		}
6557
		}
6591
	}
6558
	}
6592
}
6559
}
6593
 
6560
 
Line 6596... Line 6563...
6596
	// first check we have any ships
6563
	// first check we have any ships
6597
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6564
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6598
		return;
6565
		return;
6599
 
6566
 
6600
	bool found = false;
6567
	bool found = false;
6601
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6568
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6602
	{
6569
	{
6603
		SGameShip *s = node->Data();
6570
		SGameShip *s = node->Data();
6604
		if ( s->iType != WARETYPE_ADDED || !s->pPackage )
6571
		if ( s->iType != WARETYPE_ADDED || !s->pPackage )
6605
			continue;
6572
			continue;
6606
 
6573
 
6607
		// no dummies to add?
6574
		// no dummies to add?
Line 6613... Line 6580...
6613
 
6580
 
6614
	if ( !found )
6581
	if ( !found )
6615
		return;
6582
		return;
6616
 
6583
 
6617
	std::vector<Utils::String> cutList;
6584
	std::vector<Utils::String> cutList;
6618
	int e = ExtractGameFile("types/CutData.pck", m_sTempDir + "/CutData.txt");
6585
	int e = extractGameFile("types/CutData.pck", m_sTempDir + "/CutData.txt");
6619
	if ( e )
6586
	if ( e )
6620
	{
6587
	{
6621
		CFileIO File;
6588
		CFileIO File;
6622
		if ( File.open((e == -1) ? "CutData.txt" : m_sTempDir + "/CutData.txt") )
6589
		if ( File.open((e == -1) ? "CutData.txt" : m_sTempDir + "/CutData.txt") )
6623
		{
6590
		{
Line 6646... Line 6613...
6646
					}
6613
					}
6647
				}
6614
				}
6648
			}
6615
			}
6649
 
6616
 
6650
			File.remove();
6617
			File.remove();
6651
		}
6618
		}
6652
	}
6619
	}
6653
 
6620
 
6654
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6621
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6655
	{
6622
	{
6656
		SGameShip *s = node->Data();
6623
		SGameShip *s = node->Data();
Line 6679... Line 6646...
6679
	cutList.insert(cutList.begin(), "// Cut Data file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6646
	cutList.insert(cutList.begin(), "// Cut Data file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6680
 
6647
 
6681
	// write the file to disk
6648
	// write the file to disk
6682
	CFileIO WriteFile(m_sTempDir + "/CutData.txt");
6649
	CFileIO WriteFile(m_sTempDir + "/CutData.txt");
6683
	if ( WriteFile.writeFile(&cutList) )
6650
	if ( WriteFile.writeFile(&cutList) )
6684
	{
6651
	{
6685
		this->PackFile(&WriteFile, "types\\CutData.pck");
6652
		this->packFile(&WriteFile, "types\\CutData.pck");
6686
		WriteFile.remove();
6653
		WriteFile.remove();
6687
	}
6654
	}
6688
}
6655
}
6689
 
6656
 
6690
void CPackages::CreateAnimations()
6657
void CPackages::CreateAnimations()
6691
{
6658
{
6692
	// first check we have any ships
6659
	// first check we have any ships
Line 6709... Line 6676...
6709
 
6676
 
6710
	if ( !found )
6677
	if ( !found )
6711
		return;
6678
		return;
6712
 
6679
 
6713
	Utils::CStringList aniList;
6680
	Utils::CStringList aniList;
6714
	int e = ExtractGameFile("types/Animations.pck", m_sTempDir + "/Animations.txt");
6681
	int e = extractGameFile("types/Animations.pck", m_sTempDir + "/Animations.txt");
6715
	if ( e )
6682
	if ( e )
6716
	{
6683
	{
6717
		CFileIO File;
6684
		CFileIO File;
6718
		if ( File.open((e == -1) ? "Animations.txt" : m_sTempDir + "/Animations.txt") )
6685
		if ( File.open((e == -1) ? "Animations.txt" : m_sTempDir + "/Animations.txt") )
6719
		{
6686
		{
Line 6831... Line 6798...
6831
 
6798
 
6832
	// write the file to disk
6799
	// write the file to disk
6833
	CFileIO WriteFile(m_sTempDir + "/Animations.txt");
6800
	CFileIO WriteFile(m_sTempDir + "/Animations.txt");
6834
	if ( WriteFile.writeFile(&formatedAniList) )
6801
	if ( WriteFile.writeFile(&formatedAniList) )
6835
	{
6802
	{
6836
		this->PackFile(&WriteFile, "types\\Animations.pck");
6803
		this->packFile(&WriteFile, "types\\Animations.pck");
6837
		WriteFile.remove();
6804
		WriteFile.remove();
6838
	}
6805
	}
6839
}
6806
}
6840
 
6807
 
6841
void CPackages::CreateBodies()
6808
void CPackages::CreateBodies()
Line 6862... Line 6829...
6862
		return;
6829
		return;
6863
 
6830
 
6864
	// lets read our current bodies file
6831
	// lets read our current bodies file
6865
	CLinkList<SBodies> bodiesList;
6832
	CLinkList<SBodies> bodiesList;
6866
	SBodies *currentSection = NULL;
6833
	SBodies *currentSection = NULL;
6867
	int e = ExtractGameFile("types/Bodies.pck", m_sTempDir + "/Bodies.txt");
6834
	int e = extractGameFile("types/Bodies.pck", m_sTempDir + "/Bodies.txt");
6868
	if ( e )
6835
	if ( e )
6869
	{
6836
	{
6870
		CFileIO File;
6837
		CFileIO File;
6871
		if ( File.open((e == -1) ? "Bodies.txt" : m_sTempDir + "/Bodies.txt") )
6838
		if ( File.open((e == -1) ? "Bodies.txt" : m_sTempDir + "/Bodies.txt") )
6872
		{
6839
		{
Line 6980... Line 6947...
6980
 
6947
 
6981
	// write the file to disk
6948
	// write the file to disk
6982
	CFileIO WriteFile(m_sTempDir + "/Bodies.txt");
6949
	CFileIO WriteFile(m_sTempDir + "/Bodies.txt");
6983
	if ( WriteFile.writeFile(&writeList) )
6950
	if ( WriteFile.writeFile(&writeList) )
6984
	{
6951
	{
6985
		this->PackFile(&WriteFile, "types\\Bodies.pck");
6952
		this->packFile(&WriteFile, "types\\Bodies.pck");
6986
		WriteFile.remove();
6953
		WriteFile.remove();
6987
	}
6954
	}
6988
}
6955
}
6989
 
6956
 
6990
void CPackages::CreateCustomStarts()
6957
void CPackages::CreateCustomStarts()
Line 7000... Line 6967...
7000
		// only use custom starts
6967
		// only use custom starts
7001
		if ( !p->IsCustomStart() )
6968
		if ( !p->IsCustomStart() )
7002
			continue;
6969
			continue;
7003
 
6970
 
7004
		// get the name of the start to use
6971
		// get the name of the start to use
7005
		CyString name = p->GetCustomStartName();
6972
		Utils::String name = p->GetCustomStartName();
7006
		if ( name.Empty() )
6973
		if ( name.empty() )
7007
			continue;
6974
			continue;
7008
 
6975
 
7009
		// find if maps file exists
6976
		// find if maps file exists
7010
		CyStringList createFiles;
6977
		Utils::CStringList createFiles;
7011
		createFiles.PushBack(name, "maps/x3_universe");
6978
		createFiles.pushBack(name, "maps/x3_universe");
7012
		createFiles.PushBack(name, "types/Jobs");
6979
		createFiles.pushBack(name, "types/Jobs");
7013
		createFiles.PushBack(name, "types/JobWings");
6980
		createFiles.pushBack(name, "types/JobWings");
7014
 
6981
 
7015
		for ( SStringList *str = createFiles.Head(); str; str = str->;next )
6982
		for(auto itr = createFiles.begin(); itr != createFiles.end(); itr++)
7016
		{
6983
		{
7017
			Utils::String dir = CFileIO(str->data).dir();
6984
			Utils::String dir = CFileIO((*itr)->data).dir();
7018
			FileType type = FileType::FILETYPE_EXTRA;
6985
			FileType type = FileType::FILETYPE_EXTRA;
7019
			if ( dir.Compare("maps") )
6986
			if ( dir.Compare("maps") )
7020
				type = FileType::FILETYPE_MAP;
6987
				type = FileType::FILETYPE_MAP;
7021
 
6988
 
7022
			if ( !p->findFile(str->str.ToString() + &quot;.xml", type) &&amp; !p-&gt;findFile(str->str.ToString() + ".pck", type))
6989
			if ( !p->findFile((*itr)->str + &quot;.xml", type) &amp;&amp; !p->;findFile((*itr)->str + ".pck", type))
7023
			{
6990
			{
7024
				// create a maps files
6991
				// create a maps files
7025
				int e = this->ExtractGameFile(str->data + ".pck", m_sTempDir + "/" + str->data.ToString() + ".pck");
6992
				int e = this->extractGameFile((*itr)->data + ".pck", m_sTempDir + "/" + (*itr)->data + ".pck");
7026
				if ( e )
6993
				if ( e )
7027
				{
6994
				{
7028
					CFileIO File((e == -1) ? (str->data + ".pck") : (m_sTempDir + "/" + str->data.ToString() + ".pck"));
6995
					CFileIO File((e == -1) ? ((*itr)->data + ".pck") : (m_sTempDir + "/" + (*itr)->data + ".pck"));
7029
					if ( File.exists() )
6996
					if ( File.exists() )
7030
					{
6997
					{
7031
						File.Rename(m_sCurrentDir + "/" + dir + "/" + str->str.ToString() + ".pck");
6998
						File.Rename(m_sCurrentDir + "/" + dir + "/" + (*itr)->str + ".pck");
7032
						this->AddCreatedFile(dir + "/" + str->str.ToString() + ".pck");
6999
						this->addCreatedFile(dir + "/" + (*itr)->str + ".pck");
7033
					}
7000
					}
7034
				}
7001
				}
7035
			}
7002
			}
7036
		}
7003
		}
7037
	}
7004
	}
7038
}
7005
}
7039
 
7006
 
7040
void CPackages::AddCreatedFile(CyString sFile)
7007
void CPackages::addCreatedFile(const Utils::String &sFile)
7041
{
7008
{
7042
	Utils::String file = sFile.ToString();
-
 
7043
	file = file.findRemove(m_sCurrentDir);
7009
	Utils::String file = sFile.findRemove(m_sCurrentDir);
7044
	while ( file[0] == '/' )
7010
	while ( file[0] == '/' )
7045
		file.erase(0, 1);
7011
		file.erase(0, 1);
7046
	while ( file[0] == '\\' )
7012
	while ( file[0] == '\\' )
7047
		file.erase(0, 1);
7013
		file.erase(0, 1);
7048
 
7014
 
Line 7057... Line 7023...
7057
		return;
7023
		return;
7058
 
7024
 
7059
	CLinkList<SComponantEntry> dummyList;
7025
	CLinkList<SComponantEntry> dummyList;
7060
 
7026
 
7061
	// now extract the existing dummies
7027
	// now extract the existing dummies
7062
	int e = ExtractGameFile("types/Components.pck", m_sTempDir + "/Components.txt");
7028
	int e = extractGameFile("types/Components.pck", m_sTempDir + "/Components.txt");
7063
	if ( e )
7029
	if ( e )
7064
	{
7030
	{
7065
		// read the dummies
7031
		// read the dummies
7066
		CFileIO File;
7032
		CFileIO File;
7067
		if ( File.open((e == -1) ? "Components.txt" : m_sTempDir + "/Components.txt") )
7033
		if ( File.open((e == -1) ? "Components.txt" : m_sTempDir + "/Components.txt") )
Line 7071... Line 7037...
7071
			{
7037
			{
7072
				int insection = 0;
7038
				int insection = 0;
7073
				int insubsection = 0;
7039
				int insubsection = 0;
7074
				SComponantEntry *currentSection = NULL;
7040
				SComponantEntry *currentSection = NULL;
7075
				SComponantEntry2 *currentSubSection = NULL;
7041
				SComponantEntry2 *currentSubSection = NULL;
7076
				for ( int j = 0; j < (int)lines->size(); j++ )
7042
				for ( int j = 0; j < (int)lines->size(); j++ )
7077
				{
7043
				{
7078
					Utils::String line(lines->at(j));
7044
					Utils::String line(lines->at(j));
7079
					if ( line[0] == '/' )
7045
					if ( line[0] == '/' )
7080
						continue;
7046
						continue;
7081
					line.removeChar('\r');
7047
					line.removeChar('\r');
7082
					line = line.removeFirstSpace();
7048
					line = line.removeFirstSpace();
7083
					line = line.removeEndSpace();
7049
					line = line.removeEndSpace();
7084
					if ( line.empty() )
7050
					if ( line.empty() )
7085
						continue;
7051
						continue;
7086
 
7052
 
7087
 
7053
 
7088
					// read the section, first entry is section, second is size
7054
					// read the section, first entry is section, second is size
7089
					while ( !line.empty() )
7055
					while ( !line.empty() )
7090
					{
7056
					{
7091
						line = line.removeFirstSpace();
7057
						line = line.removeFirstSpace();
7092
						if ( line.empty() )
7058
						if ( line.empty() )
7093
							break;
7059
							break;
7094
 
7060
 
7095
						if ( !insection && !insubsection )
7061
						if ( !insection && !insubsection )
7096
						{
7062
						{
7097
							Utils::String section = line.token(";", 1);
7063
							Utils::String section = line.token(";", 1);
7098
							insection = line.token(";", 2).toInt();
7064
							insection = line.token(";", 2).toInt();
Line 7134... Line 7100...
7134
						else
7100
						else
7135
						{
7101
						{
7136
							--insubsection;
7102
							--insubsection;
7137
							currentSubSection->lEntries.PushBack(CyString(line.remove(' ')), true);
7103
							currentSubSection->lEntries.PushBack(CyString(line.remove(' ')), true);
7138
							line = "";
7104
							line = "";
7139
						}
7105
						}
7140
					}
7106
					}
7141
				}
7107
				}
7142
 
7108
 
7143
				delete lines;
7109
				delete lines;
7144
			}
7110
			}
7145
 
7111
 
7146
			File.remove();
7112
			File.remove();
7147
		}
7113
		}
Line 7149... Line 7115...
7149
		// add the new entries for the ships
7115
		// add the new entries for the ships
7150
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
7116
		for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
7151
		{
7117
		{
7152
			SGameShip *s = node->Data();
7118
			SGameShip *s = node->Data();
7153
			if ( s->iType != WARETYPE_ADDED || !s->pPackage )
7119
			if ( s->iType != WARETYPE_ADDED || !s->pPackage )
7154
				continue;
7120
				continue;
7155
 
7121
 
7156
			// no dummies to add?
7122
			// no dummies to add?
7157
			if ( !s->pPackage->AnyComponents() )
7123
			if ( !s->pPackage->AnyComponents() )
7158
				continue;
7124
				continue;
7159
 
7125
 
Line 7195... Line 7161...
7195
					if ( !found2 )
7161
					if ( !found2 )
7196
					{
7162
					{
7197
						found2 = new SComponantEntry2;
7163
						found2 = new SComponantEntry2;
7198
						found2->sSection = dummy->sSection2;
7164
						found2->sSection = dummy->sSection2;
7199
						found->lEntries.push_back(found2);
7165
						found->lEntries.push_back(found2);
7200
					}
7166
					}
7201
					else
7167
					else
7202
					{
7168
					{
7203
						bool f = false;
7169
						bool f = false;
7204
						for ( SStringList *strNode = found2->lEntries.Head(); strNode; strNode = strNode->next )
7170
						for ( SStringList *strNode = found2->lEntries.Head(); strNode; strNode = strNode->next )
7205
						{
7171
						{
Line 7245... Line 7211...
7245
 
7211
 
7246
		// write the file to disk
7212
		// write the file to disk
7247
		CFileIO WriteFile(m_sTempDir + "/Components.txt");
7213
		CFileIO WriteFile(m_sTempDir + "/Components.txt");
7248
		if ( WriteFile.writeFile(&lines) )
7214
		if ( WriteFile.writeFile(&lines) )
7249
		{
7215
		{
7250
			this->PackFile(&WriteFile, "types\\Components.pck");
7216
			this->packFile(&WriteFile, "types\\Components.pck");
7251
			WriteFile.remove();
7217
			WriteFile.remove();
7252
		}
7218
		}
7253
	}
7219
	}
7254
}
7220
}
7255
 
7221
 
Line 7436... Line 7402...
7436
		writeList.pushFront("// Globals file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2), "");
7402
		writeList.pushFront("// Globals file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2), "");
7437
 
7403
 
7438
		CFileIO WriteFile(m_sTempDir + "/Globals.txt");
7404
		CFileIO WriteFile(m_sTempDir + "/Globals.txt");
7439
		if ( WriteFile.writeFile(&writeList) )
7405
		if ( WriteFile.writeFile(&writeList) )
7440
		{
7406
		{
7441
			this->PackFile(&WriteFile, "types/Globals.pck");
7407
			this->packFile(&WriteFile, "types/Globals.pck");
7442
			WriteFile.remove();
7408
			WriteFile.remove();
7443
		}
7409
		}
7444
	}
7410
	}
7445
}
7411
}
7446
 
7412
 
7447
void CPackages::CreateTShips()
7413
void CPackages::CreateTShips()
7448
{
7414
{
7449
	// no ships ?
7415
	// no ships ?
7450
	if ( m_lGameShips.empty() )
7416
	if ( m_lGameShips.empty() )
7451
		return;
7417
		return;
7452
 
7418
 
7453
	// get the cockpit list to match with ships turrets
7419
	// get the cockpit list to match with ships turrets
Line 7471... Line 7437...
7471
			continue;
7437
			continue;
7472
		shipOverrides.push_back(node->Data());
7438
		shipOverrides.push_back(node->Data());
7473
	}
7439
	}
7474
 
7440
 
7475
	// read the existing tships file
7441
	// read the existing tships file
7476
	int e = ExtractGameFile("types/TShips.pck", m_sTempDir + "/TShips.txt");
7442
	int e = extractGameFile("types/TShips.pck", m_sTempDir + "/TShips.txt");
7477
	if ( e )
7443
	if ( e )
7478
	{
7444
	{
7479
		int fileType = 51;
7445
		int fileType = 51;
7480
		std::vector<Utils::String> tshipsList;
7446
		std::vector<Utils::String> tshipsList;
7481
 
7447
 
Line 7593... Line 7559...
7593
			tshipsList.insert(tshipsList.begin(), "// TShips file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
7559
			tshipsList.insert(tshipsList.begin(), "// TShips file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
7594
 
7560
 
7595
			CFileIO WriteFile(m_sTempDir + "/TShips.txt");
7561
			CFileIO WriteFile(m_sTempDir + "/TShips.txt");
7596
			if ( WriteFile.writeFile(&tshipsList) )
7562
			if ( WriteFile.writeFile(&tshipsList) )
7597
			{
7563
			{
7598
				this->PackFile(&WriteFile, "types/TShips.pck");
7564
				this->packFile(&WriteFile, "types/TShips.pck");
7599
				WriteFile.remove();
7565
				WriteFile.remove();
7600
			}
7566
			}
7601
		}
7567
		}
7602
	}
7568
	}
7603
 
7569
 
7604
}
7570
}
7605
 
7571
 
7606
bool CPackages::PackFile(CyString filename)
7572
bool CPackages::packFile(const Utils::String &filename) const
7607
{
7573
{
7608
	// compress the file
7574
	// compress the file
7609
	CFileIO File(filename);
7575
	CFileIO File(filename);
7610
	size_t fileSize;
7576
	size_t fileSize;
7611
	char *fileData = File.ReadToData(&fileSize);
7577
	char *fileData = File.ReadToData(&fileSize);
Line 7630... Line 7596...
7630
	}
7596
	}
7631
 
7597
 
7632
	return false;
7598
	return false;
7633
}
7599
}
7634
 
7600
 
7635
bool CPackages::UnPackFile(const Utils::String &filename, bool checkxml)
7601
bool CPackages::unPackFile(const Utils::String &filename, bool checkxml) const
7636
{
7602
{
7637
	// compress the file
7603
	// compress the file
7638
	CFileIO File(filename);
7604
	CFileIO File(filename);
7639
	size_t fileSize;
7605
	size_t fileSize;
7640
	char *fileData = File.ReadToData(&fileSize);
7606
	char *fileData = File.ReadToData(&fileSize);
Line 7662... Line 7628...
7662
			if ( checkxml )
7628
			if ( checkxml )
7663
			{
7629
			{
7664
				int readmaxlines = 20;
7630
				int readmaxlines = 20;
7665
				bool isxml = false;
7631
				bool isxml = false;
7666
				do {
7632
				do {
7667
					CyString line = pckFile.readEndOfLine();
7633
					Utils::String line = pckFile.readEndOfLine();
7668
					if ( line.IsIn("<language id=") )
7634
					if ( line.contains("<language id=") )
7669
					{
7635
					{
7670
						isxml = true;
7636
						isxml = true;
7671
						break;
7637
						break;
7672
					}
7638
					}
7673
					else if ( line.IsIn("<page id=") )
7639
					else if ( line.contains("<page id=") )
7674
					{
7640
					{
7675
						isxml = true;
7641
						isxml = true;
7676
						break;
7642
						break;
7677
					}
7643
					}
7678
					else if ( line.IsIn("<?xml") || line.IsIn("<script>") )
7644
					else if ( line.contains("<?xml") || line.contains("<script>") )
7679
					{
7645
					{
7680
						isxml = true;
7646
						isxml = true;
7681
						break;
7647
						break;
7682
					}
7648
					}
7683
					--readmaxlines;
7649
					--readmaxlines;
Line 7697... Line 7663...
7697
	}
7663
	}
7698
 
7664
 
7699
	return false;
7665
	return false;
7700
}
7666
}
7701
 
7667
 
7702
bool CPackages::PackFile(CFileIO* File, CyString sFilename)
-
 
7703
{
-
 
7704
	return packFile(File, sFilename.ToString());
-
 
7705
}
-
 
7706
bool CPackages::packFile(CFileIO* File, const Utils::String &sFilename)
7668
bool CPackages::packFile(CFileIO* File, const Utils::String &sFilename) const
7707
{
7669
{
7708
	Utils::String filename = sFilename.findReplace("\\", "/");
7670
	Utils::String filename = sFilename.findReplace("\\", "/");
7709
	if ( m_iGame == GAME_X3 )
7671
	if ( m_iGame == GAME_X3 )
7710
	{
7672
	{
7711
		CCatFile catFile;
7673
		CCatFile catFile;
Line 7734... Line 7696...
7734
//					filename = this->GetAddonDir() + "/" + filename;
7696
//					filename = this->GetAddonDir() + "/" + filename;
7735
				CFileIO pckFile(m_sCurrentDir + "/" + filename);
7697
				CFileIO pckFile(m_sCurrentDir + "/" + filename);
7736
				if ( !CDirIO(pckFile.dir()).exists() )
7698
				if ( !CDirIO(pckFile.dir()).exists() )
7737
					CDirIO(pckFile.dir()).create();
7699
					CDirIO(pckFile.dir()).create();
7738
				pckFile.WriteData((char *)pckData, newFileSize);
7700
				pckFile.WriteData((char *)pckData, newFileSize);
7739
				this->AddCreatedFile(pckFile.fullFilename());
7701
				const_cast<CPackages *>(this)->addCreatedFile(pckFile.fullFilename());
7740
				return true;
7702
				return true;
7741
			}
7703
			}
7742
		}
7704
		}
7743
	}
7705
	}
7744
 
7706
 
Line 7861... Line 7823...
7861
	}
7823
	}
7862
 
7824
 
7863
	return list.size();
7825
	return list.size();
7864
}
7826
}
7865
 
7827
 
7866
CBaseFile *CPackages::FindScriptByAuthor(CyString author, CBaseFile *prev)
7828
CBaseFile *CPackages::findScriptByAuthor(const Utils::String &author, CBaseFile *prev)
7867
{
7829
{
7868
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
7830
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
7869
	{
7831
	{
7870
		CBaseFile *p = node->Data();
7832
		CBaseFile *p = node->Data();
7871
		if ( prev )
7833
		if ( prev )
7872
		{
7834
		{
7873
			if ( p == prev )
7835
			if ( p == prev )
7874
				prev = NULL;
7836
				prev = NULL;
7875
			continue;
7837
			continue;
7876
		}
7838
		}
7877
		if ( p->author().Compare(author.ToString()) )
7839
		if ( p->author().Compare(author) )
7878
			return p;
7840
			return p;
7879
	}
7841
	}
7880
 
7842
 
7881
	return NULL;
7843
	return NULL;
7882
}
7844
}
Line 8137... Line 8099...
8137
	}
8099
	}
8138
 
8100
 
8139
	return package;
8101
	return package;
8140
}
8102
}
8141
 
8103
 
8142
CyString CPackages::GetLanguageName() const
8104
Utils::String CPackages::getLanguageName() const
8143
{
8105
{
8144
	return CPackages::ConvertLanguage(m_iLanguage);
8106
	return CPackages::ConvertLanguage(m_iLanguage);
8145
}
8107
}
8146
 
8108
 
8147
size_t CPackages::updateFoundPackages(const Utils::String& dir)
8109
size_t CPackages::updateFoundPackages(const Utils::String& dir)
Line 8215... Line 8177...
8215
			
8177
			
8216
		for(auto itr = files.begin(); itr != files.end(); itr++)
8178
		for(auto itr = files.begin(); itr != files.end(); itr++)
8217
		{
8179
		{
8218
			Utils::String f = Dir.file((*itr)->str);
8180
			Utils::String f = Dir.file((*itr)->str);
8219
			int error = 0;
8181
			int error = 0;
8220
			CBaseFile *p = this->OpenPackage(f, &error, 0, SPKREAD_NODATA, READFLAG_NOUNCOMPRESS);
8182
			CBaseFile *p = this->openPackage(f, &error, 0, SPKREAD_NODATA, READFLAG_NOUNCOMPRESS);
8221
			if (!p)
8183
			if (!p)
8222
				continue;
8184
				continue;
8223
			if (p->IsMod() || this->FindSpkPackage(p->name(), p->author()))
8185
			if (p->IsMod() || this->findSpkPackage(p->name(), p->author()))
8224
			{
8186
			{
8225
				delete p;
8187
				delete p;
8226
				continue;
8188
				continue;
8227
			}
8189
			}
8228
 
8190
 
Line 8336... Line 8298...
8336
	}
8298
	}
8337
 
8299
 
8338
	return Utils::String::Number(lang);
8300
	return Utils::String::Number(lang);
8339
}
8301
}
8340
 
8302
 
8341
bool CPackages::CheckAccessRights(CyString dir)
8303
bool CPackages::checkAccessRights(const Utils::String &aDir) const
8342
{
8304
{
-
 
8305
	Utils::String dir = aDir;
8343
	if ( dir.Empty() )
8306
	if (dir.empty())
8344
		dir = m_sCurrentDir;
8307
		dir = m_sCurrentDir;
8345
 
8308
 
8346
	// write a file, then read the contents
8309
	// write a file, then read the contents
8347
	CFileIO File(dir + "/accessrightscheck.dat");
8310
	CFileIO File(dir + "/accessrightscheck.dat");
8348
 
8311
 
8349
	// check if file exists and remove it
8312
	// check if file exists and remove it
8350
	if ( File.exists() )
8313
	if ( File.exists() )
8351
	{
8314
	{
8352
		// if we cant remove it, we dont have enough rights
8315
		// if we cant remove it, we dont have enough rights
8353
		if ( !File.remove() )
8316
		if ( !File.remove() )
8354
			return false;
8317
			return false;
8355
 
8318
 
8356
		// if its still there, we dont have enough rights
8319
		// if its still there, we dont have enough rights
8357
		if ( File.exists() )
8320
		if ( File.exists() )
8358
			return false;
8321
			return false;
8359
	}
8322
	}
8360
 
8323
 
8361
	// now create the file
8324
	// now create the file
8362
	if ( !File.writeString("testing access rights") )
8325
	if ( !File.writeString("testing access rights") )
8363
		return false;
8326
		return false;
8364
 
8327
 
8365
	// now check it exists
8328
	// now check it exists
Line 8378... Line 8341...
8378
			return true;
8341
			return true;
8379
	}
8342
	}
8380
 
8343
 
8381
	return false;
8344
	return false;
8382
}
8345
}
8383
 
8346
 
8384
bool CPackages::LoadShipData(CyString file, CyStringList *list)
8347
size_t CPackages::loadShipData(const Utils::String &file, Utils::CStringList &list) const
8385
{
8348
{
8386
	CFileIO File;
8349
	CFileIO File;
8387
	bool deleteFile = false;
8350
	bool deleteFile = false;
8388
 
8351
 
8389
	// load from cat file
8352
	// load from cat file
8390
	if ( CFileIO(file).isFileExtension("cat") )
8353
	if (CFileIO(file).isFileExtension("cat"))
8391
	{
8354
	{
8392
		CCatFile cat;
8355
		CCatFile cat;
8393
		if ( cat.open(file.ToString(), this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
8356
		if (cat.open(file, this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE)
8394
			return false;
8357
			return false;
8395
 
8358
 
8396
		if ( !cat.extractFile("types\\TShips.pck";, m_sTempDir + "/tships.txt") )
8359
		if (!cat.extractFile("types\\TShips.pck";, m_sTempDir + "/tships.txt"))
8397
			return false;
8360
			return false;
8398
 
8361
 
8399
		File.open(m_sTempDir + "/tships.txt");
8362
		File.open(m_sTempDir + "/tships.txt");
8400
		deleteFile = true;
8363
		deleteFile = true;
8401
	}
8364
	}
8402
	// otherwise its a normal file
8365
	// otherwise its a normal file
8403
	else if ( CFileIO(file).isFileExtension("pck") )
8366
	else if (CFileIO(file).isFileExtension("pck"))
8404
	{
8367
	{
8405
		C_File f(file.ToString());
8368
		C_File f(file);
8406
		if ( !f.ReadFromFile() )
8369
		if (!f.ReadFromFile())
8407
			return false;
8370
			return false;
8408
		f.UnPCKFile();
8371
		f.UnPCKFile();
8409
 
8372
 
8410
		f.setFilename(m_sTempDir + "/tships.txt");
8373
		f.setFilename(m_sTempDir + "/tships.txt");
8411
		if ( !f.writeFilePointer() )
8374
		if (!f.writeFilePointer())
8412
			return false;
8375
			return false;
8413
 
8376
 
8414
		File.open(m_sTempDir + "/tships.txt");
8377
		File.open(m_sTempDir + "/tships.txt");
8415
		deleteFile = true;
8378
		deleteFile = true;
8416
	}
8379
	}
8417
	else
8380
	else
8418
		File.open(file.ToString());
8381
		File.open(file);
8419
 
8382
 
8420
	if ( !File.exists() )
8383
	if (!File.exists())
8421
		return false;
8384
		return false;
8422
 
8385
 
8423
	bool ret = false;
8386
	bool ret = false;
8424
	std::vector<Utils::String> lines;
8387
	std::vector<Utils::String> lines;
8425
	if(File.readLines(lines))
8388
	if (File.readLines(lines))
8426
	{
8389
	{
8427
		bool readFirst = false;
8390
		bool readFirst = false;
8428
		for(auto itr = lines.begin(); itr != lines.end(); itr++)
8391
		for (auto itr = lines.begin(); itr != lines.end(); itr++)
8429
		{
8392
		{
8430
			if ( itr->empty() )
8393
			if (itr->empty())
8431
				continue;
8394
				continue;
8432
			Utils::String str = itr->remove('\r').remove(9);
8395
			Utils::String str = itr->remove('\r').remove(9);
8433
			str = str.removeFirstSpace();
8396
			str = str.removeFirstSpace();
8434
			if ( str.empty() )
8397
			if (str.empty())
8435
				continue;
8398
				continue;
8436
			if ( str[0] == '/' || str[0] == '#' )
8399
			if (str[0] == '/' || str[0] == '#')
8437
				continue;
8400
				continue;
8438
 
8401
 
8439
			if ( !readFirst )
8402
			if (!readFirst)
8440
				readFirst = true;
8403
				readFirst = true;
8441
			else
8404
			else
8442
			{
8405
			{
8443
				Utils::String t = str.tokens(";", -2);
8406
				Utils::String t = str.tokens(";", -2);
8444
				while ( t.right(1) == ";" )
8407
				while (t.right(1) == ";")
8445
					t.truncate((int)t.length() - 1);
8408
					t.truncate((int)t.length() - 1);
8446
				list->PushBack(CyString(t), CyString(str));
8409
				list.pushBack(t, str);
8447
			}
8410
			}
8448
		}
8411
		}
8449
 
8412
 
8450
		ret = true;
8413
		ret = true;
8451
	}
8414
	}
8452
 
8415
 
8453
	if ( deleteFile )
8416
	if (deleteFile)
8454
		File.remove();
8417
		File.remove();
8455
 
8418
 
8456
	return ret;
8419
	return ret;
8457
}
8420
}
8458
 
8421
 
8459
CyString CPackages::ReadShipData(CyString file, CyString id)
8422
Utils::String CPackages::readShipData(const Utils::String &file, const Utils::String &id) const
8460
{
8423
{
8461
	CyStringList *list = this->LoadShipData(file);
8424
	Utils::CStringList list;
8462
	if ( !list )
8425
	if(!this->loadShipData(file, list))
8463
		return NullString;
8426
		return Utils::String::Null();
8464
 
8427
 
8465
	CShipData data;
8428
	CShipData data;
8466
	for ( SStringList *str = list->Head(); str; str = str->;next )
8429
	for(auto itr = list.begin(); itr != list.end(); itr++)
8467
	{
8430
	{
8468
		if ( str->str.Compare(id) )
8431
		if ((*itr)->str.Compare(id))
8469
		{
-
 
8470
			delete list;
-
 
8471
			return str->data;
8432
			return (*itr)->data;
8472
		}
-
 
8473
	}
8433
	}
8474
 
8434
 
8475
	delete list;
-
 
8476
	return NullString;
8435
	return Utils::String::Null();
8477
}
-
 
8478
 
-
 
8479
CyStringList *CPackages::LoadShipData(CyString file)
-
 
8480
{
-
 
8481
	CyStringList *list = new CyStringList;
-
 
8482
	if ( this->LoadShipData(file, list) )
-
 
8483
		return list;
-
 
8484
 
-
 
8485
	delete list;
-
 
8486
	return NULL;
-
 
8487
}
8436
}
8488
 
8437
 
8489
bool CPackages::ReadTextPage(CyString file, CyStringList *list, bool search, int page)
8438
bool CPackages::readTextPage(const Utils::String &file, Utils::CStringList &list, bool search, int page) const
8490
{
8439
{
8491
	CFileIO File;
8440
	CFileIO File;
8492
	bool deleteFile = false;
8441
	bool deleteFile = false;
8493
 
8442
 
8494
	// read all text files from mod
8443
	// read all text files from mod
8495
	if ( CFileIO(file).isFileExtension("cat") )
8444
	if ( CFileIO(file).isFileExtension("cat") )
8496
	{
8445
	{
8497
		bool done = false;
8446
		bool done = false;
8498
 
8447
 
8499
		CCatFile cat;
8448
		CCatFile cat;
8500
		if ( cat.open(file.ToString(), this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
8449
		if ( cat.open(file, this->getAddonDir(), CATREAD_CATDECRYPT, false) != CATERR_NONE )
8501
			return false;
8450
			return false;
8502
 
8451
 
8503
		// extract 1 at a time
8452
		// extract 1 at a time
8504
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8453
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++ )
8505
		{
8454
		{
8506
			SInCatFile *f = cat.GetFile(i);
8455
			SInCatFile *f = cat.GetFile(i);
Line 8508... Line 8457...
8508
			// is a text file
8457
			// is a text file
8509
			sF = sF.FindReplace("\\", "/");
8458
			sF = sF.FindReplace("\\", "/");
8510
			if ( !sF.GetToken("/", 1, 1).Compare("t") )
8459
			if ( !sF.GetToken("/", 1, 1).Compare("t") )
8511
				continue;
8460
				continue;
8512
 
8461
 
8513
			CyString baseFile = CFileIO(sF.ToString()).baseName();
8462
			Utils::String baseFile = CFileIO(sF).baseName();
8514
			// check language
8463
			// check language
8515
			int lang = 0;
8464
			int lang = 0;
8516
			if ( baseFile.FindPos("-L") != -1 ) // new language file
8465
			if ( baseFile.findPos("-L") != -1 ) // new language file
8517
				lang = baseFile.Right(3).ToInt();
8466
				lang = baseFile.right(3).toInt();
8518
			else
8467
			else
8519
			{
8468
			{
8520
				baseFile.Truncate((int)baseFile.Length() - 4);
8469
				baseFile.truncate((int)baseFile.length() - 4);
8521
				lang = baseFile.ToInt();
8470
				lang = baseFile.toInt();
8522
			}
8471
			}
8523
 
8472
 
8524
			if ( lang != m_iLanguage )
8473
			if ( lang != m_iLanguage )
8525
				continue;
8474
				continue;
8526
 
8475
 
8527
			// now extract and parse
8476
			// now extract and parse
8528
			if ( cat.extractFile(f->sFile, m_sTempDir + "/" + CFileIO(f->sFile).baseName() + ".xml") )
8477
			if ( cat.extractFile(f->sFile, m_sTempDir + "/" + CFileIO(f->sFile).baseName() + ".xml") )
8529
			{
8478
			{
8530
				if ( this->ReadTextPage(m_sTempDir + "/" + CFileIO(f->sFile).baseName() + ".xml", list, search, page) )
8479
				if ( this->readTextPage(m_sTempDir + "/" + CFileIO(f->sFile).baseName() + ".xml", list, search, page))
8531
					done = true;
8480
					done = true;
8532
			}
8481
			}
8533
		}
8482
		}
8534
 
8483
 
8535
		return done;
8484
		return done;
8536
	}
8485
	}
8537
	// otherwise its a normal file
8486
	// otherwise its a normal file
8538
	else if ( CFileIO(file).isFileExtension("pck") )
8487
	else if ( CFileIO(file).isFileExtension("pck") )
8539
	{
8488
	{
8540
		C_File f(file.ToString());
8489
		C_File f(file);
8541
		if ( !f.ReadFromFile() )
8490
		if ( !f.ReadFromFile() )
8542
			return false;
8491
			return false;
8543
		f.UnPCKFile();
8492
		f.UnPCKFile();
8544
 
8493
 
8545
		f.setFilename(m_sTempDir + "/textfile.xml");
8494
		f.setFilename(m_sTempDir + "/textfile.xml");
Line 8548... Line 8497...
8548
 
8497
 
8549
		File.open(m_sTempDir + "/textfile.xml");
8498
		File.open(m_sTempDir + "/textfile.xml");
8550
		deleteFile = true;
8499
		deleteFile = true;
8551
	}
8500
	}
8552
	else
8501
	else
8553
		File.open(file.ToString());
8502
		File.open(file);
8554
 
8503
 
8555
	if ( !File.exists() )
8504
	if ( !File.exists() )
8556
		return false;
8505
		return false;
8557
 
8506
 
8558
	// open and read file
8507
	// open and read file
Line 8612... Line 8561...
8612
								while ( text.findPos('(') != -1 && text.findPos(')') != -1 )
8561
								while ( text.findPos('(') != -1 && text.findPos(')') != -1 )
8613
								{
8562
								{
8614
									int s = text.findPos('(');
8563
									int s = text.findPos('(');
8615
									text = text.erase(s, text.findPos(')') - s + 1);
8564
									text = text.erase(s, text.findPos(')') - s + 1);
8616
								}
8565
								}
-
 
8566
								if(!search || !list.contains(Utils::String::Number(id)))
8617
								list->PushBack(CyString::Number(id), CyString(text), search);
8567
									list.pushBack(Utils::String::Number(id), text);
8618
							}
8568
							}
8619
						}
8569
						}
8620
					}
8570
					}
8621
				}
8571
				}
8622
			}
8572
			}
Line 8624... Line 8574...
8624
	}
8574
	}
8625
 
8575
 
8626
	return true;
8576
	return true;
8627
}
8577
}
8628
 
8578
 
8629
CyStringList *CPackages::ReadTextPage(CyString file, bool search, int page)
-
 
8630
{
-
 
8631
	CyStringList *list = new CyStringList;
-
 
8632
	if ( this->ReadTextPage(file, list, search, page) )
-
 
8633
		return list;
-
 
8634
 
-
 
8635
	delete list;
-
 
8636
	return NULL;
-
 
8637
}
-
 
8638
 
8579
 
8639
FileType CPackages::adjustFileType(const Utils::String &file, FileType filetype) const
8580
FileType CPackages::adjustFileType(const Utils::String &file, FileType filetype) const
8640
{
8581
{
8641
	CFileIO File(file);
8582
	CFileIO File(file);
8642
	Utils::String dir = File.GetDirIO().topDir();
8583
	Utils::String dir = File.GetDirIO().topDir();
Line 8693... Line 8634...
8693
	delete pVfs;
8634
	delete pVfs;
8694
 
8635
 
8695
	return newShip;
8636
	return newShip;
8696
}
8637
}
8697
 
8638
 
8698
void CPackages::getMergedFiles(Utils::CStringList &list, CCatFile *cat1, CCatFile *cat2)
8639
void CPackages::getMergedFiles(Utils::CStringList &list, CCatFile *cat1, CCatFile *cat2) const
8699
{
8640
{
8700
	// first add all files from the "primary" mod
8641
	// first add all files from the "primary" mod
8701
	for (auto itr = cat1->GetFiles()->cbegin(); itr != cat1->GetFiles()->cend(); itr++)
8642
	for (auto itr = cat1->GetFiles()->cbegin(); itr != cat1->GetFiles()->cend(); itr++)
8702
		list.pushBack((*itr)->sFile.findReplace("\\", "/"), "1");
8643
		list.pushBack((*itr)->sFile.findReplace("\\", "/"), "1");
8703
 
8644
 
Line 8709... Line 8650...
8709
		if(!list.changeData(sFile, "-1"))
8650
		if(!list.changeData(sFile, "-1"))
8710
			list.pushBack(sFile, "2");
8651
			list.pushBack(sFile, "2");
8711
	}
8652
	}
8712
}
8653
}
8713
 
8654
 
8714
bool CPackages::CanWeMerge(const Utils::String &file) const
8655
bool CPackages::canWeMerge(const Utils::String &file) const
8715
{
8656
{
8716
	return CModDiff::CanBeDiffed(file);
8657
	return CModDiff::CanBeDiffed(file);
8717
}
8658
}
8718
 
8659
 
8719
bool CPackages::NeedToMerge(CyString file)
8660
bool CPackages::needToMerge(const Utils::String &file) const
8720
{
8661
{
8721
	CyString firstDir = file.GetToken("/", 1, 1);
8662
	Utils::String firstDir = file.token("/", 1);
8722
	if ( firstDir.Compare("t") )
8663
	if ( firstDir.Compare("t") )
8723
		return true;
8664
		return true;
8724
	if ( firstDir.Compare("types") )
8665
	if ( firstDir.Compare("types") )
8725
		return true;
8666
		return true;
8726
	if ( firstDir.Compare("maps") )
8667
	if ( firstDir.Compare("maps") )
8727
		return true;
8668
		return true;
8728
 
8669
 
8729
	return false;
8670
	return false;
8730
}
8671
}
8731
 
8672
 
8732
bool CPackages::MergeMods(CCatFile *mod1, CCatFile *mod2, CyString outFile, CyStringList *cantMerge)
8673
bool CPackages::mergeMods(CCatFile *mod1, CCatFile *mod2, const Utils::String &outFile, Utils::CStringList *cantMerge) const
8733
{
8674
{
8734
	CCatFile newCat;
8675
	CCatFile newCat;
8735
	if ( newCat.open(outFile.ToString(), this->getAddonDir()) != CATERR_CREATED )
8676
	if ( newCat.open(outFile, this->getAddonDir()) != CATERR_CREATED )
8736
		return false;
8677
		return false;
8737
 
8678
 
8738
	Utils::CStringList list;
8679
	Utils::CStringList list;
8739
	this->getMergedFiles(list, mod1, mod2);
8680
	this->getMergedFiles(list, mod1, mod2);
8740
	if (list.empty())
8681
	if (list.empty())
Line 8748... Line 8689...
8748
		if ( status == 1 )
8689
		if ( status == 1 )
8749
		{
8690
		{
8750
			if ( !newCat.writeFromCat(mod1, (*itr)->str) )
8691
			if ( !newCat.writeFromCat(mod1, (*itr)->str) )
8751
			{
8692
			{
8752
				if ( cantMerge )
8693
				if ( cantMerge )
8753
					cantMerge->PushBack(CyString((*itr)->str), "1");
8694
					cantMerge->pushBack((*itr)->str, "1");
8754
			}
8695
			}
8755
		}
8696
		}
8756
		else if ( status == 2 )
8697
		else if ( status == 2 )
8757
		{
8698
		{
8758
			if ( !newCat.writeFromCat(mod2, (*itr)->str) )
8699
			if ( !newCat.writeFromCat(mod2, (*itr)->str) )
8759
			{
8700
			{
8760
				if ( cantMerge )
8701
				if ( cantMerge )
8761
					cantMerge->PushBack(CyString((*itr)->str), "2");
8702
					cantMerge->pushBack((*itr)->str, "2");
8762
			}
8703
			}
8763
		}
8704
		}
8764
		else if ( status == -1 )
8705
		else if ( status == -1 )
8765
		{
8706
		{
8766
			if ( this->NeedToMerge((*itr)->str) )
8707
			if ( this->needToMerge((*itr)->str) )
8767
			{
8708
			{
8768
				if ( this->CanWeMerge((*itr)->str) )
8709
				if ( this->canWeMerge((*itr)->str) )
8769
					conflicts.pushBack((*itr)->str);
8710
					conflicts.pushBack((*itr)->str);
8770
				else if ( cantMerge )
8711
				else if ( cantMerge )
8771
					cantMerge->PushBack(CyString((*itr)->str), "-1");
8712
					cantMerge->pushBack((*itr)->str, "-1");
8772
			}
8713
			}
8773
			else
8714
			else
8774
			{
8715
			{
8775
				if ( !newCat.writeFromCat(mod1, (*itr)->str) )
8716
				if ( !newCat.writeFromCat(mod1, (*itr)->str) )
8776
				{
8717
				{
8777
					if ( cantMerge )
8718
					if ( cantMerge )
8778
						cantMerge->PushBack(CyString((*itr)->str), "1");
8719
						cantMerge->pushBack((*itr)->str, "1");
8779
				}
8720
				}
8780
			}
8721
			}
8781
		}
8722
		}
8782
	}
8723
	}
8783
 
8724
 
Line 8804... Line 8745...
8804
 *
8745
 *
8805
 * This includes all types and text files
8746
 * This includes all types and text files
8806
 *
8747
 *
8807
 * Returns true if it finds any files
8748
 * Returns true if it finds any files
8808
 */
8749
 */
8809
bool CPackages::getModCompatabilityList(C_File *file, Utils::CStringList *list)
8750
bool CPackages::getModCompatabilityList(C_File *file, Utils::CStringList *list) const
8810
{
8751
{
8811
	// not a valid file
8752
	// not a valid file
8812
	if ( !file ) return false;
8753
	if ( !file ) return false;
8813
	if ( file->GetFileType() != FILETYPE_MOD ) return false;
8754
	if ( file->GetFileType() != FILETYPE_MOD ) return false;
8814
	if ( !file->fileExt().Compare("cat") ) return false;
8755
	if ( !file->fileExt().Compare("cat") ) return false;
Line 8828... Line 8769...
8828
				found = true;
8769
				found = true;
8829
			else if (filename.left(8).Compare("addon/t/") || filename.left(12).Compare("addon/types/"))
8770
			else if (filename.left(8).Compare("addon/t/") || filename.left(12).Compare("addon/types/"))
8830
				found = true;
8771
				found = true;
8831
			else if (filename.left(9).Compare("addon2/t/") || filename.left(13).Compare("addon2/types/"))
8772
			else if (filename.left(9).Compare("addon2/t/") || filename.left(13).Compare("addon2/types/"))
8832
				found = true;
8773
				found = true;
8833
 
8774
 
8834
			if ( found ) {
8775
			if ( found ) {
8835
				if ( list )
8776
				if ( list )
8836
					list->pushBack(filename, Utils::String::Number(f->lSize));
8777
					list->pushBack(filename, Utils::String::Number(f->lSize));
8837
				else
8778
				else
8838
					return true;
8779
					return true;
8839
			}
8780
			}
8840
		}
8781
		}
8841
	}
8782
	}
8842
 
8783
 
8843
	if ( list && !list->empty() )
8784
	if ( list && !list->empty() )
8844
		return true;
8785
		return true;
8845
 
8786
 
Line 8851... Line 8792...
8851
 *
8792
 *
8852
 * Returns true if theres any files that are not compatable
8793
 * Returns true if theres any files that are not compatable
8853
 *
8794
 *
8854
 * If list is specified, fills up with all files that were found
8795
 * If list is specified, fills up with all files that were found
8855
 */
8796
 */
8856
bool CPackages::CheckCompatabilityBetweenModFiles(C_File *from, C_File *to, CyStringList *list)
8797
bool CPackages::checkCompatabilityBetweenModFiles(C_File *from, C_File *to, Utils::CStringList *list) const
8857
{
8798
{
8858
	// not a valid file
8799
	// not a valid file
8859
	if ( !from || !to ) return false;
8800
	if ( !from || !to ) return false;
8860
	if ( from->GetFileType() != FILETYPE_MOD ) return false;
8801
	if ( from->GetFileType() != FILETYPE_MOD ) return false;
8861
	if ( to->GetFileType() != FILETYPE_MOD ) return false;
8802
	if ( to->GetFileType() != FILETYPE_MOD ) return false;
Line 8881... Line 8822...
8881
					toFile = toFile.findReplace("\\", "/");
8822
					toFile = toFile.findReplace("\\", "/");
8882
					toFile = toFile.findReplace("//", "/");
8823
					toFile = toFile.findReplace("//", "/");
8883
					if ( fromFile.Compare(toFile) )
8824
					if ( fromFile.Compare(toFile) )
8884
					{
8825
					{
8885
						if ( list )
8826
						if ( list )
8886
							list->PushBack(CyString((from->filename() + "::" + (*itr)->str, to->filename() + "::" + (*itr)->str)).c_str());
8827
							list->pushBack(from->filename() + "::" + (*itr)->str, to->filename() + "::" + (*itr)->str);
8887
						else
8828
						else
8888
							return true;
8829
							return true;
8889
					}
8830
					}
8890
				}
8831
				}
8891
			}
8832
			}
8892
		}
8833
		}
8893
	}
8834
	}
8894
 
8835
 
8895
	if ( list && !list->Empty() )
8836
	if ( list && !list->empty() )
8896
		return true;
8837
		return true;
8897
 
8838
 
8898
	return false;
8839
	return false;
8899
}
8840
}
8900
 
8841
 
8901
bool CPackages::CheckCompatabilityBetweenMods(CBaseFile *from, CBaseFile *to, CyStringList *list)
8842
bool CPackages::checkCompatabilityBetweenMods(CBaseFile *from, CBaseFile *to, Utils::CStringList *list) const
8902
{
8843
{
8903
	if ( !from || !to ) return false;
8844
	if ( !from || !to ) return false;
8904
	if ( !from->IsEnabled() || !to->IsEnabled() ) return false;
8845
	if ( !from->IsEnabled() || !to->IsEnabled() ) return false;
8905
	if ( !from->AnyFileType(FILETYPE_MOD) ) return false;
8846
	if ( !from->AnyFileType(FILETYPE_MOD) ) return false;
8906
	if ( !to->AnyFileType(FILETYPE_MOD) ) return false;
8847
	if ( !to->AnyFileType(FILETYPE_MOD) ) return false;
Line 8918... Line 8859...
8918
			if ( compareFile == f ) continue; // same file we're checking against
8859
			if ( compareFile == f ) continue; // same file we're checking against
8919
			if ( !compareFile->IsFakePatch() ) continue;
8860
			if ( !compareFile->IsFakePatch() ) continue;
8920
			if ( compareFile->fileExt().Compare("dat") ) continue;
8861
			if ( compareFile->fileExt().Compare("dat") ) continue;
8921
 
8862
 
8922
			// now we have to files to compare
8863
			// now we have to files to compare
8923
			if ( CheckCompatabilityBetweenModFiles(f, compareFile, list) )
8864
			if (checkCompatabilityBetweenModFiles(f, compareFile, list))
8924
				++count;
8865
				++count;
8925
		}
8866
		}
8926
	}
8867
	}
8927
 
8868
 
8928
	if ( count )
8869
	if ( count )
8929
		return true;
8870
		return true;
8930
 
8871
 
8931
	return false;
8872
	return false;
8932
}
8873
}
8933
 
8874
 
8934
int CPackages::CheckCompatabilityAgainstPackages(CBaseFile *newFile, CyStringList *list, CLinkList<CBaseFile> *packages)
8875
int CPackages::checkCompatabilityAgainstPackages(CBaseFile *newFile, Utils::CStringList *list, CLinkList<CBaseFile> *packages) const
8935
{
8876
{
8936
	if ( !newFile->IsEnabled() ) return 0;
8877
	if ( !newFile->IsEnabled() ) return 0;
8937
	if ( !newFile->AnyFileType(FILETYPE_MOD) ) return 0;
8878
	if ( !newFile->AnyFileType(FILETYPE_MOD) ) return 0;
8938
 
8879
 
8939
	// we need to extract all mod files
8880
	// we need to extract all mod files
Line 8955... Line 8896...
8955
		if ( !node->Data() ) continue;
8896
		if ( !node->Data() ) continue;
8956
		CBaseFile *p = node->Data();
8897
		CBaseFile *p = node->Data();
8957
		if ( !p->IsEnabled() ) continue;
8898
		if ( !p->IsEnabled() ) continue;
8958
		if ( !p->AnyFileType(FILETYPE_MOD) ) continue;
8899
		if ( !p->AnyFileType(FILETYPE_MOD) ) continue;
8959
 
8900
 
8960
		if ( this->IsSamePackage(p, newFile) ) continue; // dont include self
8901
		if ( this->isSamePackage(p, newFile) ) continue; // dont include self
8961
 
8902
 
8962
		if ( CheckCompatabilityBetweenMods(newFile, p, list) )
8903
		if (checkCompatabilityBetweenMods(newFile, p, list))
8963
		{
8904
		{
8964
			++count;
8905
			++count;
8965
			if ( packages && !packages->FindData(p) )
8906
			if ( packages && !packages->FindData(p) )
8966
				packages->push_back(p);
8907
				packages->push_back(p);
8967
		}
8908
		}
Line 8975... Line 8916...
8975
	}
8916
	}
8976
 
8917
 
8977
	return count;
8918
	return count;
8978
}
8919
}
8979
 
8920
 
8980
bool CPackages::IsSamePackage(CBaseFile *p1, CBaseFile *p2)
8921
bool CPackages::isSamePackage(CBaseFile *p1, CBaseFile *p2) const
8981
{
8922
{
8982
	if ( !p1 || !p2 ) return false;
8923
	if ( !p1 || !p2 ) return false;
8983
	if ( p1 == p2 ) return true;
8924
	if ( p1 == p2 ) return true;
8984
 
8925
 
8985
	if ( p1->name().Compare(p2->name()) && p1->author().Compare(p2->author()) )
8926
	if ( p1->name().Compare(p2->name()) && p1->author().Compare(p2->author()) )
Line 9385... Line 9326...
9385
		list->pushBack("http://xpluginmanager.co.uk/flscripts");
9326
		list->pushBack("http://xpluginmanager.co.uk/flscripts");
9386
 
9327
 
9387
	return list->size();
9328
	return list->size();
9388
}
9329
}
9389
 
9330
 
9390
void CPackages::ReadArchiveData(CyString filename, CBaseFile *archive)
9331
void CPackages::readArchiveData(const Utils::String &filename, CBaseFile *archive) const
9391
{
9332
{
9392
	size_t size;
9333
	size_t size;
9393
	char *data = CFileIO(filename).ReadToData(&size);
9334
	char *data = CFileIO(filename).ReadToData(&size);
9394
	if ( size && data )
9335
	if ( size && data )
9395
		ReadArchiveData(data, size, archive);
9336
		readArchiveData(data, size, archive);
9396
}
9337
}
9397
 
9338
 
9398
void CPackages::ReadArchiveData(const char *buf, size_t len, CBaseFile *archive)
9339
void CPackages::readArchiveData(const char *buf, size_t len, CBaseFile *archive) const
9399
{
9340
{
9400
	Utils::CStringList otherGames;
9341
	Utils::CStringList otherGames;
9401
	Utils::CStringList gameAddons;
9342
	Utils::CStringList gameAddons;
9402
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
9343
	for (unsigned int i = 0; i < m_gameExe.gameCount(); ++i)
9403
	{
9344
	{
Line 9462... Line 9403...
9462
	}
9403
	}
9463
 
9404
 
9464
	CLEANSPLIT(str, max)
9405
	CLEANSPLIT(str, max)
9465
}
9406
}
9466
 
9407
 
9467
CBaseFile *CPackages::_archive_fromRar(CyString filename, bool toInstall )
9408
CBaseFile *CPackages::_archive_fromRar(const Utils::String &filename, bool toInstall) const
9468
{
9409
{
9469
	// make sure we can open the zip file
9410
	// make sure we can open the zip file
9470
	CBaseFile *archive = NULL;
9411
	CBaseFile *archive = NULL;
9471
#ifdef _RAR
9412
#ifdef _RAR
9472
	HANDLE hArcData;
9413
	HANDLE hArcData;
Line 9535... Line 9476...
9535
 
9476
 
9536
		CFileIO File(fileName);
9477
		CFileIO File(fileName);
9537
		if ( File.exists() )
9478
		if ( File.exists() )
9538
		{
9479
		{
9539
			if ( fileName.Compare("pluginmanager.txt") )
9480
			if ( fileName.Compare("pluginmanager.txt") )
9540
				this->ReadArchiveData(File.fullFilename(), archive);
9481
				this->readArchiveData(File.fullFilename(), archive);
9541
			else
9482
			else
9542
			{
9483
			{
9543
				Utils::String extradir;
9484
				Utils::String extradir;
9544
				int type = SPK::GetAutomaticFiletype(fileName, &extradir, true);
9485
				int type = SPK::GetAutomaticFiletype(fileName, &extradir, true);
9545
				// check for special file types
9486
				// check for special file types
Line 9574... Line 9515...
9574
#endif
9515
#endif
9575
 
9516
 
9576
	return archive;
9517
	return archive;
9577
}
9518
}
9578
 
9519
 
9579
CBaseFile *CPackages::_archive_fromZip(CyString filename, bool toInstall)
9520
CBaseFile *CPackages::_archive_fromZip(const Utils::String &filename, bool toInstall) const
9580
{
9521
{
9581
	CBaseFile *archive = NULL;
9522
	CBaseFile *archive = NULL;
9582
 
9523
 
9583
	TCHAR buf[5000];
9524
	TCHAR buf[5000];
9584
	wsprintf(buf, L"%hs", filename.c_str());
9525
	wsprintf(buf, L"%hs", filename.c_str());
Line 9626... Line 9567...
9626
		Utils::String Name(CyString(ze.name).ToString());
9567
		Utils::String Name(CyString(ze.name).ToString());
9627
 
9568
 
9628
		// if its the data file, dont add it, but extract to get settings from
9569
		// if its the data file, dont add it, but extract to get settings from
9629
		if ( Name.Compare("pluginmanager.txt") )
9570
		if ( Name.Compare("pluginmanager.txt") )
9630
		{
9571
		{
9631
			this->ReadArchiveData(iBuf, ze.unc_size, archive);
9572
			this->readArchiveData(iBuf, ze.unc_size, archive);
9632
			delete[] iBuf;
9573
			delete[] iBuf;
9633
		}
9574
		}
9634
		else
9575
		else
9635
		{
9576
		{
9636
			Utils::String extradir;
9577
			Utils::String extradir;
Line 9680... Line 9621...
9680
		archive = NULL;
9621
		archive = NULL;
9681
	}
9622
	}
9682
	return archive;
9623
	return archive;
9683
}
9624
}
9684
 
9625
 
9685
CBaseFile *CPackages::CreateFromArchive(CyString filename, bool toInstall )
9626
CBaseFile *CPackages::createFromArchive(const Utils::String &filename, bool toInstall) const
9686
{
9627
{
9687
	// make sure we can open the zip file
9628
	// make sure we can open the zip file
9688
	CBaseFile *archive = NULL;
9629
	CBaseFile *archive = NULL;
9689
	if ( CFileIO(filename).isFileExtension("rar") )
9630
	if ( CFileIO(filename).isFileExtension("rar") )
9690
		archive = this->_archive_fromRar(filename, toInstall);
9631
		archive = this->_archive_fromRar(filename, toInstall);
Line 9751... Line 9692...
9751
		if(Dir.dirList(files, "", pattern))
9692
		if(Dir.dirList(files, "", pattern))
9752
		{
9693
		{
9753
			for(auto itr = files.begin(); itr != files.end(); itr++)
9694
			for(auto itr = files.begin(); itr != files.end(); itr++)
9754
			{
9695
			{
9755
				int error = 0;
9696
				int error = 0;
9756
				CBaseFile *p = packages.OpenPackage(Dir.file((*itr)->str), &error, 0, SPKREAD_NODATA);
9697
				CBaseFile *p = packages.openPackage(Dir.file((*itr)->str), &error, 0, SPKREAD_NODATA);
9757
				if ( !p )
9698
				if ( !p )
9758
					continue;
9699
					continue;
9759
 
9700
 
9760
				if ( includeSingle )
9701
				if ( includeSingle )
9761
					p->createUpdateFile(dir);
9702
					p->createUpdateFile(dir);
Line 9773... Line 9714...
9773
	}
9714
	}
9774
 
9715
 
9775
	return 0;
9716
	return 0;
9776
}
9717
}
9777
 
9718
 
9778
int CPackages::VerifyInstalledFiles(CyStringList *missingFiles, bool getPackages)
9719
size_t CPackages::verifyInstalledFiles(Utils::CStringList *missingFiles, bool getPackages) const
9779
{
9720
{
9780
	int count = 0;
9721
	int count = 0;
9781
	for ( CListNode<C_File> *fn = m_lFiles.Front(); fn; fn = fn->next() )
9722
	for ( CListNode<C_File> *fn = m_lFiles.Front(); fn; fn = fn->next() )
9782
	{
9723
	{
9783
		C_File *f = fn->Data();
9724
		C_File *f = fn->Data();
Line 9817... Line 9758...
9817
						}
9758
						}
9818
					}
9759
					}
9819
				}
9760
				}
9820
				Utils::String filename = f->filePointer();
9761
				Utils::String filename = f->filePointer();
9821
				filename = filename.findRemove(m_sCurrentDir);
9762
				filename = filename.findRemove(m_sCurrentDir);
9822
				missingFiles->PushBack(CyString(filename), CyString(packages), false);
9763
				missingFiles->pushBack(filename, packages);
9823
			}
9764
			}
9824
		}
9765
		}
9825
	}
9766
	}
9826
	return count;
9767
	return count;
9827
}
9768
}