Subversion Repositories spk

Rev

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

Rev 108 Rev 109
Line 1... Line 1...
1
#include "XspFile.h"
1
#include "XspFile.h"
2
#include "File_IO.h"
2
#include "File_IO.h"
3
#include "Packages.h"
3
#include "Packages.h"
4
#include "CatFile.h"
4
#include "CatFile.h"
5
 
5
 
-
 
6
#define ADDSECTIONLIST(T, L) for(CListNode<T> *node = L.Front(); node; node = node->next()) \
-
 
7
		_addSection(list, node->Data()->sSection, node->Data()->sData);
-
 
8
 
-
 
9
#define GENERATESECTION(F, T, L) if ( !L.empty() ) {						\
-
 
10
									type = F;								\
-
 
11
									std::vector<STypesSection *> list;		\
-
 
12
									ADDSECTIONLIST(T, L);					\
-
 
13
									data = CXspFile::TypesListToString(list, true); \
-
 
14
								}
-
 
15
 
-
 
16
#define GENERATESTRINGSECTION(F, L) if ( !L.Empty() ) {						\
-
 
17
									type = F;								\
-
 
18
									std::vector<STypesSection *> list;		\
-
 
19
									_addDataSection(L, list);				\
-
 
20
									data = CXspFile::TypesListToString(list, true); \
-
 
21
								}
-
 
22
 
-
 
23
 
6
CXspFile::CXspFile () : CBaseFile()
24
CXspFile::CXspFile () : CBaseFile()
7
{
25
{
8
	SetDefaults ();
26
	SetDefaults ();
9
}
27
}
10
 
28
 
Line 884... Line 902...
884
	}
902
	}
885
 
903
 
886
	return true;
904
	return true;
887
}
905
}
888
 
906
 
-
 
907
void CXspFile::_addSection(std::vector<STypesSection *> &list, const Utils::String &section, const Utils::String &data)
-
 
908
{
-
 
909
	STypesSection *currentSubSection = NULL;
-
 
910
	for(std::vector<STypesSection *>::iterator itr = list.begin(); itr != list.end(); itr++) {
-
 
911
		if ( (*itr)->sSection.Compare(section) ) {
-
 
912
			currentSubSection = *itr;
-
 
913
			break;
-
 
914
		}
-
 
915
	}
-
 
916
 
-
 
917
	if ( !currentSubSection ) {
-
 
918
		currentSubSection = new STypesSection;
-
 
919
		currentSubSection->sSection = section;
-
 
920
		list.push_back(currentSubSection);
-
 
921
	}
-
 
922
 
-
 
923
	currentSubSection->lEntries.pushBack(data, "");
-
 
924
}
-
 
925
 
-
 
926
void CXspFile::_addDataSection(CyStringList &list, std::vector<STypesSection *> &sectionList)
-
 
927
{
-
 
928
	for(SStringList *str = list.Head(); str; str = str->next) {
-
 
929
		_addSection(sectionList, str->str.ToString(), str->data.ToString());
-
 
930
	}
-
 
931
}
-
 
932
 
-
 
933
void CXspFile::addDummiesToList(std::vector<STypesSection *> &list)
-
 
934
{
-
 
935
	ADDSECTIONLIST(SDummy, m_lDummy);
-
 
936
}
-
 
937
 
-
 
938
void CXspFile::addComponentsToList(CLinkList<SComponentEntry> &componentList)
-
 
939
{
-
 
940
	for(CListNode<SComponent> *node = m_lComponent.Front(); node; node = node->next()) {
-
 
941
		SComponentEntry *currentSection = NULL;
-
 
942
		for(CListNode<SComponentEntry> *cNode = componentList.Front(); cNode; cNode = cNode->next()) {
-
 
943
			if ( cNode->Data()->sSection.Compare(node->Data()->sSection) ) {
-
 
944
				currentSection = cNode->Data();
-
 
945
				break;
-
 
946
			}
-
 
947
		}
-
 
948
 
-
 
949
		if ( !currentSection ) {
-
 
950
			currentSection = new SComponentEntry();
-
 
951
			currentSection->sSection = node->Data()->sSection;
-
 
952
			componentList.push_back(currentSection);
-
 
953
		}
-
 
954
 
-
 
955
		_addSection(currentSection->lEntries, node->Data()->sSection2, node->Data()->sData);
-
 
956
	}
-
 
957
}
-
 
958
 
-
 
959
void CXspFile::addCutDataToList(std::vector<STypesSection *> &list)
-
 
960
{
-
 
961
	_addDataSection(this->m_lCutData, list);
-
 
962
}
-
 
963
 
-
 
964
void CXspFile::addBodiesToList(std::vector<STypesSection *> &list)
-
 
965
{
-
 
966
	_addDataSection(this->m_lBodies, list);
-
 
967
}
-
 
968
 
-
 
969
void CXspFile::addAnimationsToList(std::vector<STypesSection *> &list)
-
 
970
{
-
 
971
	_addDataSection(this->m_lAnimations, list);
-
 
972
}
-
 
973
 
-
 
974
 
-
 
975
void CXspFile::addGeneratedFiles(HZIP &hz)
-
 
976
{
-
 
977
	TCHAR buf[5000];
-
 
978
 
-
 
979
	CFileIO tmpFile(CPackages::tempDirectory() + "/temp.tmp");
-
 
980
 
-
 
981
	for(int i = 0; i < 5; i++) {
-
 
982
		Utils::String type;
-
 
983
		Utils::String data;
-
 
984
		switch(i) {
-
 
985
			case 0:
-
 
986
				data = "50;1\r\n" + this->m_sData;
-
 
987
				type = "TShips";
-
 
988
				break;
-
 
989
			case 1:
-
 
990
				if ( !this->m_lCockpit.empty() ) {
-
 
991
					data = Utils::String("51;") + (long)this->m_lCockpit.size() + ";\r\n";
-
 
992
					for(CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next()) {
-
 
993
						data += node->Data()->sCockpit + "\r\n";
-
 
994
					}
-
 
995
					type = "TCockpits";
-
 
996
				}
-
 
997
				break;
-
 
998
			case 2:
-
 
999
				if ( !this->m_lComponent.empty() ) {
-
 
1000
					type = "Components";
-
 
1001
					CLinkList<SComponentEntry> componentList;
-
 
1002
					this->addComponentsToList(componentList);
-
 
1003
					for(CListNode<SComponentEntry> *node = componentList.Front(); node; node = node->next()) {
-
 
1004
						data += node->Data()->sSection + "; " + (long)node->Data()->lEntries.size() + ";\r\n";
-
 
1005
						data += CXspFile::TypesListToString(node->Data()->lEntries, true);
-
 
1006
						delete node->Data();
-
 
1007
					}
-
 
1008
				}
-
 
1009
				break;
-
 
1010
			case 3:
-
 
1011
				GENERATESECTION("Dummies", SDummy, this->m_lDummy);
-
 
1012
				break;
-
 
1013
			case 4:
-
 
1014
				GENERATESTRINGSECTION("Bodies", this->m_lBodies);
-
 
1015
				break;
-
 
1016
		}
-
 
1017
 
-
 
1018
		if ( type.empty() ) continue;
-
 
1019
 
-
 
1020
		Utils::String fname = "GENERATED/types/" + type + ".txt";
-
 
1021
		
-
 
1022
		Utils::String fileData = "// Exported " + type + " file, Generated by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2) + "\r\n" + data;
-
 
1023
		if ( tmpFile.startWrite() ) {
-
 
1024
			tmpFile.write(fileData.c_str(), fileData.length());
-
 
1025
			tmpFile.close();
-
 
1026
		}
-
 
1027
 
-
 
1028
		// tships files
-
 
1029
		wsprintf(buf, L"%hs", fname.c_str());
-
 
1030
			
-
 
1031
		if ( tmpFile.startRead() ) {
-
 
1032
			size_t dataSize = 0;
-
 
1033
			unsigned char *data = tmpFile.readAll(&dataSize);
-
 
1034
			ZipAdd(hz, buf, data, dataSize);
-
 
1035
		}
-
 
1036
	}
-
 
1037
}
-
 
1038
 
889
bool CXspFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames)
1039
bool CXspFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames)
890
{
1040
{
891
	if ( sFirst.Compare("Shipyard") )
1041
	if ( sFirst.Compare("Shipyard") )
892
	{
1042
	{
893
		for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
1043
		for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
Line 1254... Line 1404...
1254
		return TAT_3;
1404
		return TAT_3;
1255
 
1405
 
1256
	return TAT_NONE;
1406
	return TAT_NONE;
1257
}
1407
}
1258
 
1408
 
-
 
1409
Utils::String CXspFile::TypesListToString(std::vector<STypesSection *> &list, bool deleteAfter)
-
 
1410
{
-
 
1411
	Utils::String data;
-
 
1412
 
-
 
1413
	for(std::vector<STypesSection *>::iterator itr = list.begin(); itr != list.end(); itr++) {
-
 
1414
		data += (*itr)->sSection + "; " + (long)(*itr)->lEntries.size() + ";\r\n";
-
 
1415
		for(Utils::SStringList *str = (*itr)->lEntries.First(); str; str = (*itr)->lEntries.Next()) {
-
 
1416
			data += str->str + "\r\n";
-
 
1417
		}
-
 
1418
 
-
 
1419
		if ( deleteAfter ) {
-
 
1420
			(*itr)->lEntries.MemoryClear();
-
 
1421
			delete *itr;
-
 
1422
		}
-
 
1423
	}
-
 
1424
 
-
 
1425
	return data;
-
 
1426
}
-
 
1427
 
1259
bool CXspFile::ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord)
1428
bool CXspFile::ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord)
1260
{
1429
{
1261
	Utils::String lastComment;
1430
	Utils::String lastComment;
1262
	Utils::String addEntry;
1431
	Utils::String addEntry;
1263
	int remaining = 0;
1432
	int remaining = 0;