Subversion Repositories spk

Rev

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

Rev 217 Rev 218
Line 332... Line 332...
332
 
332
 
333
	return name;
333
	return name;
334
}
334
}
335
 
335
 
336
//TODO: split this up
336
//TODO: split this up
337
bool CXspFile::ConvertOld(const Utils::String &file)
337
bool CXspFile::convertOld(const Utils::WString &file)
338
{
338
{
339
	// open the file
339
	// open the file
340
	FILE *id = fopen(file.c_str(), "rb");
340
	FILE *id = _wfopen(file.c_str(), L"rb");
341
	if ( !id )
341
	if ( !id )
342
		return false;
342
		return false;
343
 
343
 
344
	// read to memory
344
	// read to memory
345
	fseek(id, 0, SEEK_END);
345
	fseek(id, 0, SEEK_END);
Line 352... Line 352...
352
 
352
 
353
	// uncompress the file
353
	// uncompress the file
354
	size_t len;
354
	size_t len;
355
	unsigned char *compr = LZMADecode_C ( data, size, &len, NULL );
355
	unsigned char *compr = LZMADecode_C ( data, size, &len, NULL );
356
 
356
 
357
	delete data;
357
	delete[] data;
358
 
358
 
359
	if ( !compr )
359
	if ( !compr )
360
		return false;
360
		return false;
361
 
361
 
362
	this->Delete();
362
	this->Delete();
Line 369... Line 369...
369
	while ( pos < len )
369
	while ( pos < len )
370
	{
370
	{
371
		while ( compr[pos++] != '\n' && pos < len );
371
		while ( compr[pos++] != '\n' && pos < len );
372
 
372
 
373
		compr[pos - 1] = '\0';
373
		compr[pos - 1] = '\0';
374
		Utils::String line = (char *)(compr + start);
374
		Utils::WString line = Utils::WString::FromString((char *)(compr + start));
375
		start = pos;
375
		start = pos;
376
		if ( line.empty() )
376
		if ( line.empty() )
377
			continue;
377
			continue;
378
		Utils::String first = line.token(":", 1);
378
		Utils::WString first = line.token(L":", 1);
379
		Utils::String rest = line.tokens(":", 2);
379
		Utils::WString rest = line.tokens(L":", 2);
380
		rest = rest.removeFirstSpace();
380
		rest = rest.removeFirstSpace();
381
 
381
 
382
		// now check each line
382
		// now check each line
383
		if ( first.Compare("Packager") )
383
		if ( first.Compare(L"Packager") )
384
			packageVersion = rest;
384
			packageVersion = rest;
385
		else if ( first.Compare("Shipyard") )
385
		else if ( first.Compare(L"Shipyard") )
386
		{
386
		{
387
			int max;
-
 
388
			Utils::String *strs = rest.tokenise(";", &max);
387
			std::vector<Utils::WString> strs;
389
			if ( strs && max )
388
			if(rest.tokenise(L";", strs))
390
			{
389
			{
391
				int cur = 1;
390
				int cur = 1;
392
				for ( int i = 0; i < max; i++, cur *= 2 )
391
				for (size_t i = 0; i < strs.size(); i++, cur *= 2 )
393
				{
392
				{
394
					if ( strs[i] == "1" )
393
					if ( strs[i] == L"1" )
395
						this->AddShipyard(cur);
394
						this->AddShipyard(cur);
396
				}
395
				}
397
			}
396
			}
398
			CLEANSPLIT(strs, max)
-
 
399
		}
397
		}
400
		else if ( first.Compare("ScreenShot") )
398
		else if ( first.Compare("ScreenShot") )
401
		{
399
		{
402
			int size = rest.token(" ", 1);
400
			int size = rest.token(L" ", 1);
403
			Utils::WString ext = rest.token(" ", 2);
401
			Utils::WString ext = rest.token(L" ", 2);
404
 
402
 
405
			C_File *newFile = this->addFile(m_sID + L"_" + (long)(this->countFiles(FILETYPE_SCREEN) + 1) + L"." + ext, L"", FILETYPE_SCREEN);
403
			C_File *newFile = this->addFile(m_sID + L"_" + (long)(this->countFiles(FILETYPE_SCREEN) + 1) + L"." + ext, L"", FILETYPE_SCREEN);
406
			newFile->ReadFromData((char *)(compr + pos), size); 
404
			newFile->ReadFromData((char *)(compr + pos), size); 
407
 
405
 
408
			start += (size + 1);
406
			start += (size + 1);
409
		}
407
		}
410
		else if ( first.Compare("SceneFile") )
408
		else if ( first.Compare(L"SceneFile") )
411
		{
409
		{
412
			Utils::WString file = rest.tokens(" ", 3);
410
			Utils::WString file = rest.tokens(L" ", 3);
413
			m_pSceneFile = this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPSCENE);
411
			m_pSceneFile = this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPSCENE);
414
			m_pSceneFile->SetCreationTime((long)rest.token(" ", 1));
412
			m_pSceneFile->SetCreationTime((long)rest.token(L" ", 1));
415
			m_pSceneFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
413
			m_pSceneFile->ReadFromData((char *)(compr + pos), rest.token(L" ", 2));
416
 
414
 
417
			start += m_pSceneFile->GetDataSize();
415
			start += m_pSceneFile->GetDataSize();
418
		}
416
		}
419
		else if ( first.Compare("CockpitFile") )
417
		else if ( first.Compare(L"CockpitFile") )
420
		{
418
		{
421
			Utils::WString file = rest.tokens(" ", 3);
419
			Utils::WString file = rest.tokens(L" ", 3);
422
			m_pCockpitFile = this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_COCKPITSCENE);
420
			m_pCockpitFile = this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_COCKPITSCENE);
423
			m_pCockpitFile->SetCreationTime((long)rest.token(" ", 1));
421
			m_pCockpitFile->SetCreationTime((long)rest.token(L" ", 1));
424
			m_pCockpitFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
422
			m_pCockpitFile->ReadFromData((char *)(compr + pos), rest.token(L" ", 2));
425
 
423
 
426
			start += m_pCockpitFile->GetDataSize();
424
			start += m_pCockpitFile->GetDataSize();
427
		}
425
		}
428
		else if ( first.Compare("Model") )
426
		else if ( first.Compare(L"Model") )
429
		{
427
		{
430
			Utils::WString file = rest.tokens(" ", 3);
428
			Utils::WString file = rest.tokens(L" ", 3);
431
			C_File *newFile= this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPMODEL);
429
			C_File *newFile= this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPMODEL);
432
			newFile->SetCreationTime((long)rest.token(" ", 1));
430
			newFile->SetCreationTime((long)rest.token(L" ", 1));
433
			newFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
431
			newFile->ReadFromData((char *)(compr + pos), rest.token(L" ", 2));
434
 
432
 
435
			start += (newFile->GetDataSize() + 1);
433
			start += (newFile->GetDataSize() + 1);
436
		}
434
		}
437
		else if ( first.Compare("Files") )
435
		else if ( first.Compare(L"Files") )
438
		{
436
		{
439
			Utils::WString file = rest.tokens(" ", 3);
437
			Utils::WString file = rest.tokens(L" ", 3);
440
 
438
 
441
			C_File *newFile = NULL;
439
			C_File *newFile = NULL;
442
			int special = 0;
440
			int special = 0;
443
			if ( file.Compare(L"types/CutData.txt") || file.Compare(L"types/CutData.pck") )
441
			if ( file.Compare(L"types/CutData.txt") || file.Compare(L"types/CutData.pck") )
444
			{
442
			{
Line 456... Line 454...
456
				special = 3;
454
				special = 3;
457
			}
455
			}
458
			else
456
			else
459
			{
457
			{
460
				newFile = this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPOTHER);
458
				newFile = this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPOTHER);
461
				newFile->SetCreationTime((long)rest.token(" ", 1));
459
				newFile->SetCreationTime((long)rest.token(L" ", 1));
462
			}
460
			}
463
			newFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
461
			newFile->ReadFromData((char *)(compr + pos), rest.token(L" ", 2));
464
			start += (newFile->GetDataSize() + 1);
462
			start += (newFile->GetDataSize() + 1);
465
 
463
 
466
			if ( special )
464
			if ( special )
467
			{
465
			{
468
				if (newFile->checkFileExt(L"pck"))
466
				if (newFile->checkFileExt(L"pck"))
469
					newFile->UnPCKFile();
467
					newFile->UnPCKFile();
470
 
468
 
471
				// read data into lines
469
				// read data into lines
472
				Utils::String data((const char *)newFile->GetData());
470
				Utils::WString data = Utils::WString::FromString((const char *)newFile->GetData());
473
				data.removeChar('\r');
471
				data.removeChar('\r');
474
				int iLines;
472
 
475
				Utils::String *sLines = data.tokenise("\n", &iLines);
473
				std::vector<Utils::WString> sLines;
476
				
-
 
477
				if ( sLines && iLines )
474
				if(data.tokenise(L"\n", sLines))
478
				{
475
				{
479
					// cut data
476
					// cut data
480
					size_t entries = -1;
477
					size_t entries = -1;
481
					if ( special == 1 )
478
					if ( special == 1 )
482
					{
479
					{
483
						Utils::CStringList newLines;
480
						Utils::WStringList newLines;
484
						for ( int i = 0; i < iLines; i++ )
481
						for (size_t i = 0; i < sLines.size(); i++)
485
						{
482
						{
486
							Utils::String line = sLines[i];
483
							Utils::WString line = sLines[i];
487
							line.removeChar(' ');
484
							line.removeChar(' ');
488
							line.removeChar(9);
485
							line.removeChar(9);
489
							if ( line.empty() || line[0] == '/' )
486
							if ( line.empty() || line[0] == '/' )
490
								continue;
487
								continue;
491
							if ( entries == -1 )
488
							if ( entries == -1 )
492
							{
489
							{
493
								entries	= line.token(";", 1).toInt() - 36;
490
								entries	= line.token(L";", 1).toInt() - 36;
494
								if ( entries <= 0 )
491
								if ( entries <= 0 )
495
									break;
492
									break;
496
							}
493
							}
497
							else
494
							else
498
							{
495
							{
499
								int id = line.token(";", 1).toInt();
496
								int id = line.token(L";", 1).toInt();
500
								if ( id >= 9000 && id <= 9017 )
497
								if ( id >= 9000 && id <= 9017 )
501
									continue;
498
									continue;
502
 
499
 
503
								switch (id)
500
								switch (id)
504
								{
501
								{
Line 535... Line 532...
535
					}
532
					}
536
					// bodies
533
					// bodies
537
					else if ( special == 2 )
534
					else if ( special == 2 )
538
					{
535
					{
539
						entries = 0;
536
						entries = 0;
540
						Utils::String section;
537
						Utils::WString section;
541
						for ( int i = 0; i < iLines; i++ )
538
						for (size_t i = 0; i < sLines.size(); i++ )
542
						{
539
						{
543
							Utils::String line = sLines[i];
540
							Utils::WString line = sLines[i];
544
							line.removeChar(' ');
541
							line.removeChar(' ');
545
							line.removeChar(9);
542
							line.removeChar(9);
546
							if ( line.empty() || line[0] == '/' )
543
							if ( line.empty() || line[0] == '/' )
547
								continue;
544
								continue;
548
							if ( entries <= 0)
545
							if ( entries <= 0)
549
							{
546
							{
550
								section = line.token(";", 1);
547
								section = line.token(L";", 1);
551
								entries	= line.token(";", 2).toInt();
548
								entries	= line.token(L";", 2).toInt();
552
							}
549
							}
553
							else
550
							else
554
							{
551
							{
555
								if ( !line.isin(";") )
552
								if ( !line.isin(L";") )
556
									continue;
553
									continue;
557
								if ( line.countToken(";") <= 2 )
554
								if ( line.countToken(L";") <= 2 )
558
								{
555
								{
559
									this->addBodies(section + ";" + line.token(";", 1) + ";");
556
									this->addBodies(section + ";" + line.token(L";", 1) + L";");
560
									--entries;
557
									--entries;
561
								}
558
								}
562
								else
559
								else
563
								{
560
								{
564
									bool done = false;
561
									bool done = false;
565
									while (!done)
562
									while (!done)
566
									{
563
									{
567
										int num;
-
 
568
										Utils::String *strs = line.tokenise(";", &num);
564
										std::vector<Utils::WString> strs;
569
										done = true;
565
										done = true;
-
 
566
										line.tokenise(L";", strs);
570
										for ( int j = 0; j < num; j++ )
567
										for (size_t j = 0; j < strs.size(); j++)
571
										{
568
										{
572
											if ( !entries )
569
											if ( !entries )
573
											{
570
											{
574
												line = line.tokens(";", j + 1);
571
												line = line.tokens(L";", j + 1);
575
												if ( !line.empty() )
572
												if ( !line.empty() )
576
													done = false;
573
													done = false;
577
												break;
574
												break;
578
											}
575
											}
579
 
576
 
580
											if ( strs[j].empty() )
577
											if ( strs[j].empty() )
581
												continue;
578
												continue;
582
											
579
											
583
											this->addBodies(section + ";" + strs[j] + ";");
580
											this->addBodies(section + L";" + strs[j] + L";");
584
											--entries;
581
											--entries;
585
										}
582
										}
586
										//we must be at another section
583
										//we must be at another section
587
										if ( !done )
584
										if ( !done )
588
										{
585
										{
589
											section = line.token(";", 1);
586
											section = line.token(L";", 1);
590
											entries	= line.token(";", 2).toInt();
587
											entries	= line.token(L";", 2).toInt();
591
											line = line.remToken(";", 1);
588
											line = line.remToken(L";", 1);
592
											line = line.remToken(";", 1);
589
											line = line.remToken(L";", 1);
593
 
590
 
594
											if (line.empty())
591
											if (line.empty())
595
												done = true;
592
												done = true;
596
										}
593
										}
597
 
-
 
598
										CLEANSPLIT(strs, num)
-
 
599
									}									
594
									}									
600
								}
595
								}
601
							}
596
							}
602
						}
597
						}
603
					}
598
					}
604
					// animations
599
					// animations
605
					else if ( special == 3 )
600
					else if ( special == 3 )
606
					{
601
					{
607
						Utils::CStringList in;
602
						Utils::WStringList in;
608
						for ( int i = 0; i < iLines; i++ )
603
						for (size_t i = 0; i < sLines.size(); i++)
609
							in.pushBack(sLines[i]);
604
							in.pushBack(sLines[i]);
610
 
605
 
611
						Utils::CStringList out;
606
						Utils::WStringList out;
612
						if ( CXspFile::ReadAnimations(in, out, 87) )
607
						if ( CXspFile::ReadAnimations(in, out, 87) )
613
							this->addAnimation(out);
608
							this->addAnimation(out);
614
					}
609
					}
615
				}
610
				}
616
				CLEANSPLIT(sLines, iLines)
-
 
617
				delete newFile;
611
				delete newFile;
618
			}
612
			}
619
		}
613
		}
620
		else if ( first.Compare("Script") )
614
		else if ( first.Compare(L"Script") )
621
		{
615
		{
622
			Utils::String file = rest.words(3);
616
			Utils::WString file = rest.words(3);
623
			C_File *newFile= this->addFile(file, Utils::String::Null(), FILETYPE_SCRIPT);
617
			C_File *newFile= this->addFile(file, Utils::WString::Null(), FILETYPE_SCRIPT);
624
			newFile->SetCreationTime((long)rest.word(1));
618
			newFile->SetCreationTime((long)rest.word(1));
625
			newFile->ReadFromData((char *)(compr + pos), rest.word(2));
619
			newFile->ReadFromData((char *)(compr + pos), rest.word(2));
626
 
620
 
627
			start += (newFile->GetDataSize() + 1);
621
			start += (newFile->GetDataSize() + 1);
628
		}
622
		}
629
		else if ( first.Compare("Text") )
623
		else if ( first.Compare(L"Text") )
630
			this->addText(rest.token(":", 1), rest.token(":", 2), rest.tokens(":", 3));
624
			this->addText(rest.token(L":", 1), rest.token(L":", 2), rest.tokens(L":", 3));
631
		else if ( first.Compare("Component") )
625
		else if ( first.Compare(L"Component") )
632
			this->addComponent(rest.token(";", 1), rest.token(";", 2), rest.tokens(";", 3));
626
			this->addComponent(rest.token(L";", 1), rest.token(L";", 2), rest.tokens(L";", 3));
633
		else if ( first.Compare("Dummy") )
627
		else if ( first.Compare(L"Dummy") )
634
		{
628
		{
635
			SDummy *d = new SDummy;
629
			SDummy *d = new SDummy;
636
			d->sData = rest.tokens(";", 2).toWString();
630
			d->sData = rest.tokens(L";", 2);
637
			d->sSection = rest.token(";", 1).toWString();
631
			d->sSection = rest.token(L";", 1);
638
			m_lDummy.push_back ( d );
632
			m_lDummy.push_back ( d );
639
		}
633
		}
640
		else if ( !this->parseValueLine(line) )
634
		else if ( !this->parseValueLine(line) )
641
		{
635
		{
642
		//	printf ( "Command: %s, Rest: %s\n", first.c_str(), rest.c_str());
636
		//	printf ( "Command: %s, Rest: %s\n", first.c_str(), rest.c_str());
Line 1207... Line 1201...
1207
	m_lDummy.RemoveEmpty();
1201
	m_lDummy.RemoveEmpty();
1208
 
1202
 
1209
	return ret;
1203
	return ret;
1210
}
1204
}
1211
 
1205
 
1212
Utils::String CXspFile::GetCockpitData(const Utils::String &cid)
1206
Utils::WString CXspFile::getCockpitData(const Utils::WString &cid)
1213
{
1207
{
1214
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1208
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1215
	{
1209
	{
1216
		Utils::WString id = node->Data()->sCockpit.token(L";", 19);
1210
		Utils::WString id = node->Data()->sCockpit.token(L";", 19);
1217
		if ( id.Compare(cid) )
1211
		if ( id.Compare(cid) )
1218
			return node->Data()->sCockpit.toString();
1212
			return node->Data()->sCockpit;
1219
	}
1213
	}
1220
 
1214
 
1221
	return "";
1215
	return L"";
1222
}
1216
}
1223
 
1217
 
1224
SCockpit *CXspFile::FindCockpit(const Utils::String &cid)
1218
SCockpit *CXspFile::findCockpit(const Utils::WString &cid)
1225
{
1219
{
1226
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1220
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1227
	{
1221
	{
1228
		Utils::WString id = node->Data()->sCockpit.token(L";", 19);
1222
		Utils::WString id = node->Data()->sCockpit.token(L";", 19);
1229
		if ( id.Compare(cid) )
1223
		if ( id.Compare(cid) )
1230
			return node->Data();
1224
			return node->Data();
1231
	}
1225
	}
1232
 
1226
 
1233
	return NULL;
1227
	return nullptr;
1234
}
1228
}
1235
 
1229
 
1236
void CXspFile::EditCockpit(const Utils::String &cid, const Utils::String &cockpit)
1230
void CXspFile::editCockpit(const Utils::WString &cid, const Utils::WString &cockpit)
1237
{
1231
{
1238
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1232
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1239
	{
1233
	{
1240
		Utils::WString id = node->Data()->sCockpit.token(L";", 19);
1234
		Utils::WString id = node->Data()->sCockpit.token(L";", 19);
1241
		if ( id.Compare(cid) )
1235
		if ( id.Compare(cid) )
1242
		{
1236
		{
1243
			node->Data()->sCockpit = cockpit.toWString();
1237
			node->Data()->sCockpit = cockpit;
1244
			break;
1238
			break;
1245
		}
1239
		}
1246
	}
1240
	}
1247
}
1241
}
1248
 
1242
 
1249
void CXspFile::EditCockpit(const Utils::String &cid, const Utils::String &scene, int mask)
1243
void CXspFile::editCockpit(const Utils::WString &cid, const Utils::WString &scene, int mask)
1250
{
1244
{
1251
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1245
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1252
	{
1246
	{
1253
		Utils::WString id = node->Data()->sCockpit.token(L";", 19);
1247
		Utils::WString id = node->Data()->sCockpit.token(L";", 19);
1254
		if ( id.Compare(cid) )
1248
		if ( id.Compare(cid) )
Line 1259... Line 1253...
1259
			node->Data()->sCockpit = cockpit;
1253
			node->Data()->sCockpit = cockpit;
1260
			break;
1254
			break;
1261
		}
1255
		}
1262
	}
1256
	}
1263
}
1257
}
1264
void CXspFile::NewCockpit(const Utils::String &id, const Utils::String &scene, int mask)
1258
void CXspFile::newCockpit(const Utils::WString &id, const Utils::WString &scene, int mask)
1265
{
1259
{
1266
	Utils::WString cockpit = L"0;0;0;0;0;0;0;";
1260
	Utils::WString cockpit = L"0;0;0;0;0;0;0;";
1267
	cockpit += scene.toWString() + L";";
1261
	cockpit += scene + L";";
1268
	cockpit += (long)mask;
1262
	cockpit += (long)mask;
1269
	cockpit += L";0;0;0;0;0;0;-100000;0;0;";
1263
	cockpit += L";0;0;0;0;0;0;-100000;0;0;";
1270
	cockpit += id.toWString() + L";";
1264
	cockpit += id + L";";
1271
	this->addCockpit(cockpit, -1);
1265
	this->addCockpit(cockpit, -1);
1272
}
1266
}
1273
 
1267
 
1274
bool CXspFile::removeCutData(const Utils::WString &cut)
1268
bool CXspFile::removeCutData(const Utils::WString &cut)
1275
{
1269
{
Line 1408... Line 1402...
1408
		_changed();
1402
		_changed();
1409
	}
1403
	}
1410
}
1404
}
1411
 
1405
 
1412
 
1406
 
1413
int CXspFile::GetAnimationType(const Utils::String &type)
1407
int CXspFile::GetAnimationType(const Utils::WString &type)
1414
{
1408
{
1415
	if ( type.Compare("TAT_TAGSINGLESTEP") )
1409
	if ( type.Compare(L"TAT_TAGSINGLESTEP") )
1416
		return TAT_SINGLE;
1410
		return TAT_SINGLE;
1417
	else if ( type.Compare("TAT_TAGONESHOT") 
1411
	else if ( type.Compare(L"TAT_TAGONESHOT") 
1418
				|| type.Compare("TAT_TAGONESHOT_REINIT") 
1412
				|| type.Compare(L"TAT_TAGONESHOT_REINIT") 
1419
				|| type.Compare("TAT_PINGPONG")
1413
				|| type.Compare(L"TAT_PINGPONG")
1420
				|| type.Compare("TAT_TAGLOOP") )
1414
				|| type.Compare(L"TAT_TAGLOOP") )
1421
		return TAT_3;
1415
		return TAT_3;
1422
 
1416
 
1423
	return TAT_NONE;
1417
	return TAT_NONE;
1424
}
1418
}
1425
 
1419
 
Line 1439... Line 1433...
1439
	}
1433
	}
1440
 
1434
 
1441
	return data;
1435
	return data;
1442
}
1436
}
1443
 
1437
 
1444
bool CXspFile::ReadAnimations(const Utils::WStringList& lIn, Utils::WStringList& lOut, int startRecord)
1438
bool CXspFile::ReadAnimations(const Utils::WStringList &lIn, Utils::WStringList &lOut, int startRecord)
1445
{
1439
{
1446
	Utils::WString lastComment;
1440
	Utils::WString lastComment;
1447
	Utils::WString addEntry;
1441
	Utils::WString addEntry;
1448
	int remaining = 0;
1442
	int remaining = 0;
1449
	Utils::WString lastType;
1443
	Utils::WString lastType;
1450
	int newEntries = 0;
1444
	int newEntries = 0;
1451
	int entries = -1;
1445
	int entries = -1;
1452
	for (auto itr = lIn.begin(); itr != lIn.end(); itr++)
1446
	for(auto itr = lIn.begin(); itr != lIn.end(); itr++)
1453
	{
1447
	{
1454
		Utils::WString line = (*itr)->str;
1448
		Utils::WString line = (*itr)->str;
1455
		line.removeChar('\r');
1449
		line.removeChar('\r');
1456
		line.removeChar(9);
1450
		line.removeChar(9);
1457
		if (line.empty() || line[0] == '/')
1451
		if ( line.empty() || line[0] == '/' )
1458
			continue;
1452
			continue;
1459
		if (entries == -1)
1453
		if ( entries == -1)
1460
		{
1454
		{
1461
			entries = line.token(L";", 1);
1455
			entries	= line.token(L";", 1);
1462
			newEntries = entries - startRecord;
1456
			newEntries = entries - startRecord;
1463
		}
1457
		}
1464
		else
1458
		else
1465
		{
1459
		{
1466
			// remove comments, endspaces and last ;
1460
			// remove comments, endspaces and last ;
1467
			Utils::WString sStriped = line;
1461
			Utils::WString sStriped = line;
1468
			if (sStriped.contains(L"//"))
1462
			if ( sStriped.contains(L"//") )
1469
			{
1463
			{
1470
				if (entries <= newEntries)
1464
				if ( entries <= newEntries )
1471
					lastComment = L"//" + sStriped.tokens(L"//", 2);
1465
					lastComment = L"//" + sStriped.tokens(L"//", 2);
1472
				sStriped = sStriped.token(L"//", 1);
1466
				sStriped = sStriped.token(L"//", 1);
1473
			}
1467
			}
1474
			sStriped.removeEndSpace();
1468
			sStriped.removeEndSpace();
1475
			if (sStriped.right(1) == L";")
1469
			if ( sStriped.right(1) == L";" )
1476
				sStriped.truncate(-1);
1470
				sStriped.truncate(-1);
1477
 
1471
 
1478
			Utils::WString sRemainingLeft;
1472
			Utils::WString sRemainingLeft;
1479
			if (remaining > 0)
-
 
1480
				sRemainingLeft = sStriped;
-
 
1481
			else
-
 
1482
			{
-
 
1483
				// each line should be a new entry, with some exceptions
-
 
1484
				// potection for new lines
-
 
1485
				lastType = sStriped.token(L";", 1);
-
 
1486
 
-
 
1487
				switch (CXspFile::GetAnimationType(lastType.toString()))
-
 
1488
				{
-
 
1489
				case TAT_SINGLE:
-
 
1490
					remaining = (long)sStriped.token(L";", 5) + 1;
-
 
1491
					sRemainingLeft = sStriped.tokens(L";", 6);
-
 
1492
					if (entries <= newEntries)
-
 
1493
						addEntry = sStriped.tokens(L";", 1, 5) + L";";
-
 
1494
					break;
-
 
1495
				case TAT_3:
-
 
1496
					remaining = (long)sStriped.token(L";", 5) + 1;
-
 
1497
					sRemainingLeft = sStriped.tokens(L";", 6);
-
 
1498
					if (entries <= newEntries)
-
 
1499
						addEntry = sStriped.tokens(L";", 1, 5) + L";";
-
 
1500
					break;
-
 
1501
 
-
 
1502
				default:
-
 
1503
					remaining = 0;
-
 
1504
					if (entries <= newEntries)
-
 
1505
						addEntry = sStriped;
-
 
1506
 
-
 
1507
				}
-
 
1508
			}
-
 
1509
 
-
 
1510
			if (!sRemainingLeft.empty())
-
 
1511
			{
-
 
1512
				int tatType = CXspFile::GetAnimationType(lastType.toString());
-
 
1513
				if (tatType == TAT_SINGLE)
-
 
1514
				{
-
 
1515
					if (sRemainingLeft.contains(L";"))
-
 
1516
						remaining -= sRemainingLeft.countToken(L";");
-
 
1517
					else if (!sRemainingLeft.empty())
-
 
1518
						--remaining;
-
 
1519
 
-
 
1520
					if (entries <= newEntries)
-
 
1521
						addEntry += sRemainingLeft + L";";
-
 
1522
				}
-
 
1523
				else if (tatType == TAT_3)
-
 
1524
				{
-
 
1525
					// last entry
-
 
1526
					if (remaining == 1)
-
 
1527
						--remaining;
-
 
1528
					else if (sRemainingLeft.contains(L";"))
-
 
1529
					{
-
 
1530
						if (!sRemainingLeft.contains(L"TATF_COORDS"))
-
 
1531
						{
-
 
1532
							int amt = sRemainingLeft.countToken(L";") / 3;
-
 
1533
							remaining -= amt;
-
 
1534
							if (remaining == 1 && (sRemainingLeft.countToken(L";") - (amt * 3)) == 1)
-
 
1535
								--remaining;
-
 
1536
						}
-
 
1537
						else
-
 
1538
						{
-
 
1539
							int iRem = sRemainingLeft.countToken(L";");
-
 
1540
							int iPos = 1;
-
 
1541
							while (iPos < iRem)
-
 
1542
							{
-
 
1543
								Utils::WString first = sRemainingLeft.token(L";", iPos);
-
 
1544
								if (first.contains(L"TATF_COORDS"))
-
 
1545
									iPos += 5;
-
 
1546
								else
-
 
1547
									iPos += 3;
-
 
1548
								--remaining;
-
 
1549
							}
-
 
1550
 
-
 
1551
							if (remaining == 1 && iPos == iRem)
-
 
1552
								--remaining;
-
 
1553
						}
-
 
1554
					}
-
 
1555
 
-
 
1556
					if (entries <= newEntries)
-
 
1557
						addEntry += sRemainingLeft + L";";
-
 
1558
				}
-
 
1559
			}
-
 
1560
 
-
 
1561
			if (remaining <= 0)
-
 
1562
			{
-
 
1563
				if (entries <= newEntries && !addEntry.empty())
-
 
1564
				{
-
 
1565
					if (addEntry[(int)addEntry.length() - 1] != ';')
-
 
1566
						addEntry += L";";
-
 
1567
					lOut.pushBack(addEntry + lastComment);
-
 
1568
				}
-
 
1569
				--entries;
-
 
1570
			}
-
 
1571
		}
-
 
1572
	}
-
 
1573
 
-
 
1574
	return !lOut.empty();
-
 
1575
}
-
 
1576
 
-
 
1577
 
-
 
1578
bool CXspFile::ReadAnimations(const Utils::CStringList &lIn, Utils::CStringList &lOut, int startRecord)
-
 
1579
{
-
 
1580
	Utils::String lastComment;
-
 
1581
	Utils::String addEntry;
-
 
1582
	int remaining = 0;
-
 
1583
	Utils::String lastType;
-
 
1584
	int newEntries = 0;
-
 
1585
	int entries = -1;
-
 
1586
	for(auto itr = lIn.begin(); itr != lIn.end(); itr++)
-
 
1587
	{
-
 
1588
		Utils::String line = (*itr)->str;
-
 
1589
		line.removeChar('\r');
-
 
1590
		line.removeChar(9);
-
 
1591
		if ( line.empty() || line[0] == '/' )
-
 
1592
			continue;
-
 
1593
		if ( entries == -1)
-
 
1594
		{
-
 
1595
			entries	= line.token(";", 1);
-
 
1596
			newEntries = entries - startRecord;
-
 
1597
		}
-
 
1598
		else
-
 
1599
		{
-
 
1600
			// remove comments, endspaces and last ;
-
 
1601
			Utils::String sStriped = line;
-
 
1602
			if ( sStriped.isin("//") )
-
 
1603
			{
-
 
1604
				if ( entries <= newEntries )
-
 
1605
					lastComment = "//" + sStriped.tokens("//", 2);
-
 
1606
				sStriped = sStriped.token("//", 1);
-
 
1607
			}
-
 
1608
			sStriped.removeEndSpace();
-
 
1609
			if ( sStriped.right(1) == ";" )
-
 
1610
				sStriped.truncate(-1);
-
 
1611
 
-
 
1612
			Utils::String sRemainingLeft;
-
 
1613
			if ( remaining > 0 )
1473
			if ( remaining > 0 )
1614
				sRemainingLeft = sStriped;
1474
				sRemainingLeft = sStriped;
1615
			else
1475
			else
1616
			{
1476
			{
1617
				// each line should be a new entry, with some exceptions
1477
				// each line should be a new entry, with some exceptions
1618
				// potection for new lines
1478
				// potection for new lines
1619
				lastType = sStriped.token(";", 1);
1479
				lastType = sStriped.token(L";", 1);
1620
 
1480
 
1621
				switch (CXspFile::GetAnimationType(lastType))
1481
				switch (CXspFile::GetAnimationType(lastType))
1622
				{
1482
				{
1623
					case TAT_SINGLE:
1483
					case TAT_SINGLE:
1624
						remaining = (long)sStriped.token(";", 5) + 1;
1484
						remaining = (long)sStriped.token(L";", 5) + 1;
1625
						sRemainingLeft = sStriped.tokens(";", 6);
1485
						sRemainingLeft = sStriped.tokens(L";", 6);
1626
						if ( entries <= newEntries )
1486
						if ( entries <= newEntries )
1627
							addEntry = sStriped.tokens(";", 1, 5) + ";";
1487
							addEntry = sStriped.tokens(L";", 1, 5) + L";";
1628
						break;
1488
						break;
1629
					case TAT_3:
1489
					case TAT_3:
1630
						remaining = (long)sStriped.token(";", 5) + 1;
1490
						remaining = (long)sStriped.token(L";", 5) + 1;
1631
						sRemainingLeft = sStriped.tokens(";", 6);
1491
						sRemainingLeft = sStriped.tokens(L";", 6);
1632
						if ( entries <= newEntries )
1492
						if ( entries <= newEntries )
1633
							addEntry = sStriped.tokens(";", 1, 5) + ";";
1493
							addEntry = sStriped.tokens(L";", 1, 5) + L";";
1634
						break;
1494
						break;
1635
 
1495
 
1636
					default:
1496
					default:
1637
						remaining = 0;
1497
						remaining = 0;
1638
						if ( entries <= newEntries )
1498
						if ( entries <= newEntries )
Line 1644... Line 1504...
1644
			if ( !sRemainingLeft.empty() )
1504
			if ( !sRemainingLeft.empty() )
1645
			{
1505
			{
1646
				int tatType = CXspFile::GetAnimationType(lastType);
1506
				int tatType = CXspFile::GetAnimationType(lastType);
1647
				if ( tatType == TAT_SINGLE )
1507
				if ( tatType == TAT_SINGLE )
1648
				{
1508
				{
1649
					if ( sRemainingLeft.isin(";") )
1509
					if ( sRemainingLeft.isin(L";") )
1650
						remaining -= sRemainingLeft.countToken(";");
1510
						remaining -= sRemainingLeft.countToken(L";");
1651
					else if ( !sRemainingLeft.empty() )
1511
					else if ( !sRemainingLeft.empty() )
1652
						--remaining;
1512
						--remaining;
1653
 
1513
 
1654
					if ( entries <= newEntries )
1514
					if ( entries <= newEntries )
1655
						addEntry += sRemainingLeft + ";";
1515
						addEntry += sRemainingLeft + L";";
1656
				}
1516
				}
1657
				else if ( tatType == TAT_3 )
1517
				else if ( tatType == TAT_3 )
1658
				{
1518
				{
1659
					// last entry
1519
					// last entry
1660
					if ( remaining == 1 )
1520
					if ( remaining == 1 )
1661
						--remaining;
1521
						--remaining;
1662
					else if ( sRemainingLeft.isin(";") )
1522
					else if ( sRemainingLeft.isin(L";") )
1663
					{
1523
					{
1664
						if ( !sRemainingLeft.isin("TATF_COORDS") )
1524
						if ( !sRemainingLeft.isin(L"TATF_COORDS") )
1665
						{
1525
						{
1666
							int amt = sRemainingLeft.countToken(";") / 3;
1526
							int amt = sRemainingLeft.countToken(L";") / 3;
1667
							remaining -= amt;
1527
							remaining -= amt;
1668
							if ( remaining == 1 && (sRemainingLeft.countToken(";") - (amt * 3)) == 1 )
1528
							if ( remaining == 1 && (sRemainingLeft.countToken(L";") - (amt * 3)) == 1 )
1669
								--remaining;
1529
								--remaining;
1670
						}
1530
						}
1671
						else
1531
						else
1672
						{
1532
						{
1673
							int iRem = sRemainingLeft.countToken(";");
1533
							int iRem = sRemainingLeft.countToken(L";");
1674
							int iPos = 1;
1534
							int iPos = 1;
1675
							while ( iPos < iRem )
1535
							while ( iPos < iRem )
1676
							{
1536
							{
1677
								Utils::String first = sRemainingLeft.token(";", iPos);
1537
								Utils::WString first = sRemainingLeft.token(L";", iPos);
1678
								if ( first.isin("TATF_COORDS") )
1538
								if ( first.isin(L"TATF_COORDS") )
1679
									iPos += 5;
1539
									iPos += 5;
1680
								else
1540
								else
1681
									iPos += 3;
1541
									iPos += 3;
1682
								--remaining;
1542
								--remaining;
1683
							}
1543
							}
Line 1686... Line 1546...
1686
								--remaining;
1546
								--remaining;
1687
						}
1547
						}
1688
					}
1548
					}
1689
 
1549
 
1690
					if ( entries <= newEntries )
1550
					if ( entries <= newEntries )
1691
						addEntry += sRemainingLeft + ";";
1551
						addEntry += sRemainingLeft + L";";
1692
				}
1552
				}
1693
			}
1553
			}
1694
 
1554
 
1695
			if ( remaining <= 0 )
1555
			if ( remaining <= 0 )
1696
			{
1556
			{
1697
				if ( entries <= newEntries && !addEntry.empty())
1557
				if ( entries <= newEntries && !addEntry.empty())
1698
				{
1558
				{
1699
					if ( addEntry[(int)addEntry.length() - 1] != ';' )
1559
					if ( addEntry[(int)addEntry.length() - 1] != ';' )
1700
						addEntry += ";";
1560
						addEntry += L";";
1701
					lOut.pushBack(addEntry + lastComment);
1561
					lOut.pushBack(addEntry + lastComment);
1702
				}
1562
				}
1703
				--entries;
1563
				--entries;
1704
			}
1564
			}
1705
		}
1565
		}
1706
	}
1566
	}
1707
 
1567
 
1708
	return !lOut.empty();
1568
	return !lOut.empty();
1709
}
1569
}
1710
 
1570
 
1711
void CXspFile::addAnimation(const Utils::CStringList &list)
1571
void CXspFile::addAnimation(const Utils::WStringList &list)
1712
{
1572
{
1713
	for(auto itr = list.begin(); itr != list.end(); itr++)
1573
	for(auto itr = list.begin(); itr != list.end(); itr++)
1714
		this->addAnimation((*itr)->str);
1574
		this->addAnimation((*itr)->str);
1715
	_changed();
1575
	_changed();
1716
}
1576
}
Line 1799... Line 1659...
1799
	// still not found one, return the ships name
1659
	// still not found one, return the ships name
1800
	if ( !this->description().empty() ) return this->description();
1660
	if ( !this->description().empty() ) return this->description();
1801
	return this->shipName(lang);
1661
	return this->shipName(lang);
1802
}
1662
}
1803
 
1663
 
1804
bool CXspFile::startExtractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *pProgress)
1664
bool CXspFile::startExtractShip(CVirtualFileSystem *pVfs, const Utils::WString &sId, CProgressInfo *pProgress)
1805
{
1665
{
1806
	m_sID = sId.toWString().remove('\r');
1666
	m_sID = sId.remove('\r');
1807
	while ( m_sID.right(1) == L";" )
1667
	while ( m_sID.right(1) == L";" )
1808
		m_sID.truncate(-1);
1668
		m_sID.truncate(-1);
1809
 
1669
 
1810
	m_sData = pVfs->getTShipsEntry(m_sID);
1670
	m_sData = pVfs->getTShipsEntry(m_sID);
1811
 
1671
 
Line 1815... Line 1675...
1815
		return false;
1675
		return false;
1816
 
1676
 
1817
	return true;
1677
	return true;
1818
}
1678
}
1819
 
1679
 
1820
bool CXspFile::extractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *progress)
1680
bool CXspFile::extractShip(CVirtualFileSystem *pVfs, const Utils::WString &sId, CProgressInfo *progress)
1821
{
1681
{
1822
	if ( !this->startExtractShip(pVfs, sId, progress) )
1682
	if ( !this->startExtractShip(pVfs, sId, progress) )
1823
		return false;
1683
		return false;
1824
 
1684
 
1825
	// read the scene file and get the files list
1685
	// read the scene file and get the files list
Line 1839... Line 1699...
1839
	m_pCockpitFile = pVfs->extractGameFileToPackage(this, L"objects\\" + m_sData.token(L";", 18) + L".pbd", FILETYPE_COCKPITSCENE, L"objects\\" + m_sData.token(L";", 18) + L".bod");
1699
	m_pCockpitFile = pVfs->extractGameFileToPackage(this, L"objects\\" + m_sData.token(L";", 18) + L".pbd", FILETYPE_COCKPITSCENE, L"objects\\" + m_sData.token(L";", 18) + L".bod");
1840
 
1700
 
1841
	return true;
1701
	return true;
1842
}
1702
}
1843
 
1703
 
1844
bool CXspFile::readSceneModels(Utils::CStringList& out)
1704
bool CXspFile::readSceneModels(Utils::WStringList& out)
1845
{
1705
{
1846
	// read the scene file
1706
	// read the scene file
1847
	if (!m_pSceneFile)
1707
	if (!m_pSceneFile)
1848
		m_pSceneFile = this->GetFirstFile(FILETYPE_SHIPSCENE);
1708
		m_pSceneFile = this->GetFirstFile(FILETYPE_SHIPSCENE);
1849
 
1709
 
Line 1920... Line 1780...
1920
			}
1780
			}
1921
		}
1781
		}
1922
	}
1782
	}
1923
 
1783
 
1924
	if (deleteData)
1784
	if (deleteData)
1925
		delete data;
1785
		delete []data;
1926
 
1786
 
1927
	return true;
1787
	return true;
1928
}
1788
}
1929
 
1789
 
1930
void CXspFile::extractCutData(CVirtualFileSystem *pVfs, Utils::CStringList &sceneModels, bool add)
1790
void CXspFile::extractCutData(CVirtualFileSystem *pVfs, Utils::WStringList &sceneModels, bool add)
1931
{
1791
{
1932
	std::vector<int> cuts;
1792
	std::vector<int> cuts;
1933
	for ( CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next() )
1793
	for ( CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next() )
1934
	{
1794
	{
1935
		Utils::WString data = node->Data()->sData;
1795
		Utils::WString data = node->Data()->sData;
1936
		int states = data.token(L";", 3);
1796
		int states = data.token(L";", 3);
1937
		for ( int i = 0; i < states; i++ ) {
1797
		for ( int i = 0; i < states; i++ )
-
 
1798
		{
1938
			int cutid = data.token(L";", (i * 2) + 5);
1799
			int cutid = data.token(L";", (i * 2) + 5);
1939
			if ( !cutid ) continue;
1800
			if ( !cutid ) continue;
1940
			cuts.push_back(cutid);
1801
			cuts.push_back(cutid);
1941
		}
1802
		}
1942
	}
1803
	}
Line 1946... Line 1807...
1946
	if ( pVfs->extractGameFile(L"types/CutData.pck", CPackages::tempDirectory() + L"tmp.dat").empty()) return;
1807
	if ( pVfs->extractGameFile(L"types/CutData.pck", CPackages::tempDirectory() + L"tmp.dat").empty()) return;
1947
	
1808
	
1948
	CFileIO File(CPackages::tempDirectory() + L"tmp.dat");
1809
	CFileIO File(CPackages::tempDirectory() + L"tmp.dat");
1949
	if ( !File.exists() ) return;
1810
	if ( !File.exists() ) return;
1950
	
1811
	
1951
	std::vector<Utils::String> lines;
1812
	std::vector<Utils::WString> lines;
1952
	File.readLines(lines);
1813
	File.readLines(lines);
1953
	int count = -1;
1814
	int count = -1;
1954
	for (auto itr = lines.begin(); itr != lines.end(); itr++) {
1815
	for (auto itr = lines.begin(); itr != lines.end(); itr++)
-
 
1816
	{
1955
		Utils::String line = *itr;
1817
		Utils::WString line = *itr;
1956
		line.removeChar('\r');
1818
		line.removeChar('\r');
1957
		line.removeChar(' ');
1819
		line.removeChar(' ');
1958
		line.removeFirstSpace();
1820
		line.removeFirstSpace();
1959
		if ( line[0] == '/' ) continue;
1821
		if ( line[0] == '/' ) continue;
1960
		if ( count == -1 ) count = line.token(";", 1);
1822
		if ( count == -1 ) count = line.token(L";", 1);
1961
		else {
1823
		else 
1962
			int max;
1824
		{
1963
			Utils::String *words = line.tokenise(";", &max);
1825
			std::vector<Utils::WString> words;
1964
			if ( words && max ) {
1826
			if(line.tokenise(L";", words))
-
 
1827
			{
1965
				for ( int i = 0; i < max; i += 2 ) {
1828
				for (size_t i = 0; i < words.size(); i += 2) {
1966
					int cutid = words[i];
1829
					int cutid = words[i];
1967
					if ( !cutid ) continue;
1830
					if ( !cutid ) continue;
1968
					for ( std::vector<int>::iterator itr = cuts.begin(); itr != cuts.end(); itr++ ) {
1831
					for ( std::vector<int>::iterator itr = cuts.begin(); itr != cuts.end(); itr++ )
-
 
1832
					{
1969
						if ( (*itr) == cutid ) {
1833
						if ( (*itr) == cutid )
-
 
1834
						{
1970
							this->addCutData(words[i] + ";" + words[i + 1] + ";");
1835
							this->addCutData(words[i] + L";" + words[i + 1] + L";");
1971
							if ( add ) {
1836
							if ( add ) 
1972
								sceneModels.pushBack(words[i + 1]);
1837
								sceneModels.pushBack(words[i + 1]);
1973
							}
-
 
1974
							break;
1838
							break;
1975
						}
1839
						}
1976
					}
1840
					}
1977
				}
1841
				}
1978
				CLEANSPLIT(words, max);
-
 
1979
			}
1842
			}
1980
		}
1843
		}
1981
	}
1844
	}
1982
}
1845
}
1983
 
1846
 
1984
void CXspFile::extractDummies(CVirtualFileSystem *pVfs, Utils::CStringList& sceneModels, bool add)
1847
void CXspFile::extractDummies(CVirtualFileSystem *pVfs, Utils::WStringList& sceneModels, bool add)
1985
{
1848
{
1986
	if (sceneModels.empty()) return;
1849
	if (sceneModels.empty()) return;
1987
 
1850
 
1988
	bool extracted = false;
1851
	bool extracted = false;
1989
	if ( !pVfs->extractGameFile(L"types/dummies.pck", CPackages::tempDirectory() + L"tmp.dat").empty()) {
1852
	if ( !pVfs->extractGameFile(L"types/dummies.pck", CPackages::tempDirectory() + L"tmp.dat").empty()) 
-
 
1853
	{
1990
		CFileIO File(CPackages::tempDirectory() + L"tmp.dat");
1854
		CFileIO File(CPackages::tempDirectory() + L"tmp.dat");
1991
		if ( File.exists() )
1855
		if ( File.exists() )
1992
		{
1856
		{
1993
			Utils::String section;
1857
			Utils::WString section;
1994
			int secCount = 0;
1858
			int secCount = 0;
1995
			std::vector<Utils::String> lines;
1859
			std::vector<Utils::WString> lines;
1996
			if (File.readLines(lines))
1860
			if (File.readLines(lines))
1997
			{
1861
			{
1998
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
1862
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
1999
				{
1863
				{
2000
					Utils::String str = itr->remove(9).remove('\r');
1864
					Utils::WString str = itr->remove(9).remove('\r');
2001
					str.removeFirstSpace();
1865
					str.removeFirstSpace();
2002
					if (str.empty())
1866
					if (str.empty())
2003
						continue;
1867
						continue;
2004
					if (str[0] == '/')
1868
					if (str[0] == '/')
2005
						continue;
1869
						continue;
2006
 
1870
 
2007
					// not in a section yet
1871
					// not in a section yet
2008
					if (secCount <= 0)
1872
					if (secCount <= 0)
2009
					{
1873
					{
2010
						section = str.token(";", 1);
1874
						section = str.token(L";", 1);
2011
						secCount = str.token(";", 2).toInt();
1875
						secCount = str.token(L";", 2).toInt();
2012
					}
1876
					}
2013
					else
1877
					else
2014
					{
1878
					{
2015
						Utils::String first = str.token(";", 1);
1879
						Utils::WString first = str.token(L";", 1);
2016
						if (sceneModels.contains(first))
1880
						if (sceneModels.contains(first))
2017
						{
1881
						{
2018
							this->addDummy(section, str);
1882
							this->addDummy(section, str);
2019
 
1883
 
2020
							if (add)
1884
							if (add)
2021
							{
1885
							{
2022
								int pos = 4;
1886
								int pos = 4;
2023
								int scene = str.token(";", 3).toInt();
1887
								int scene = str.token(L";", 3).toInt();
2024
								for (int i = 0; i < scene; i++)
1888
								for (int i = 0; i < scene; i++)
2025
								{
1889
								{
2026
									sceneModels.pushBack(str.token(";", 5 + (i * 2)));
1890
									sceneModels.pushBack(str.token(L";", 5 + (i * 2)));
2027
									pos += 2;
1891
									pos += 2;
2028
								}
1892
								}
2029
 
1893
 
2030
								int model = str.token(";", pos).toInt();
1894
								int model = str.token(L";", pos).toInt();
2031
								for (int i = 0; i < model; i++)
1895
								for (int i = 0; i < model; i++)
2032
									sceneModels.pushBack(str.token(";", pos + (i * 2) + 1));
1896
									sceneModels.pushBack(str.token(L";", pos + (i * 2) + 1));
2033
							}
1897
							}
2034
						}
1898
						}
2035
						--secCount;
1899
						--secCount;
2036
 
1900
 
2037
					}
1901
					}
Line 2041... Line 1905...
2041
			File.remove();
1905
			File.remove();
2042
		}
1906
		}
2043
	}
1907
	}
2044
}
1908
}
2045
 
1909
 
2046
void CXspFile::extractComponants(CVirtualFileSystem *pVfs, const Utils::CStringList& sceneModels)
1910
void CXspFile::extractComponants(CVirtualFileSystem *pVfs, const Utils::WStringList& sceneModels)
2047
{
1911
{
2048
	if (sceneModels.empty()) return;
1912
	if (sceneModels.empty()) return;
2049
	if ( !pVfs->extractGameFile(L"types/components.pck", CPackages::tempDirectory() + L"tmp.dat").empty())
1913
	if ( !pVfs->extractGameFile(L"types/components.pck", CPackages::tempDirectory() + L"tmp.dat").empty())
2050
	{
1914
	{
2051
		CFileIO File(CPackages::tempDirectory() + L"tmp.dat");
1915
		CFileIO File(CPackages::tempDirectory() + L"tmp.dat");
2052
		if ( File.exists() )
1916
		if ( File.exists() )
2053
		{
1917
		{
2054
			Utils::String file;
1918
			Utils::WString file;
2055
			Utils::String section;
1919
			Utils::WString section;
2056
			int secCount = 0;
1920
			int secCount = 0;
2057
			int secCount2 = 0;
1921
			int secCount2 = 0;
2058
			std::vector<Utils::String> lines;
1922
			std::vector<Utils::WString> lines;
2059
			if (File.readLines(lines))
1923
			if (File.readLines(lines))
2060
			{
1924
			{
2061
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
1925
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
2062
				{
1926
				{
2063
					Utils::String str = itr->remove(9).remove('\r');
1927
					Utils::WString str = itr->remove(9).remove('\r');
2064
					str.removeFirstSpace();
1928
					str.removeFirstSpace();
2065
					if (str.empty())
1929
					if (str.empty())
2066
						continue;
1930
						continue;
2067
					if (str[0] == '/')
1931
					if (str[0] == '/')
2068
						continue;
1932
						continue;
Line 2074... Line 1938...
2074
							this->addComponent(section, file, str);
1938
							this->addComponent(section, file, str);
2075
						--secCount2;
1939
						--secCount2;
2076
					}
1940
					}
2077
					else if (secCount <= 0)
1941
					else if (secCount <= 0)
2078
					{
1942
					{
2079
						section = str.token(";", 1);
1943
						section = str.token(L";", 1);
2080
						secCount = str.token(";", 2).toInt();
1944
						secCount = str.token(L";", 2).toInt();
2081
					}
1945
					}
2082
					else
1946
					else
2083
					{
1947
					{
2084
						file = str.token(";", 1);
1948
						file = str.token(L";", 1);
2085
						secCount2 = str.token(";", 2).toInt();
1949
						secCount2 = str.token(L";", 2).toInt();
2086
						--secCount;
1950
						--secCount;
2087
					}
1951
					}
2088
				}
1952
				}
2089
			}
1953
			}
2090
 
1954
 
Line 2097... Line 1961...
2097
{
1961
{
2098
	if ( !olddata || !size )
1962
	if ( !olddata || !size )
2099
		return false;
1963
		return false;
2100
 
1964
 
2101
	size_t startLine = 0;
1965
	size_t startLine = 0;
2102
	Utils::String line;
1966
	Utils::WString line;
2103
	size_t pos = 0;
1967
	size_t pos = 0;
2104
 
1968
 
2105
	unsigned char *data = new unsigned char[size];
1969
	unsigned char *data = new unsigned char[size];
2106
	memcpy(data, olddata, size);
1970
	memcpy(data, olddata, size);
2107
 
1971
 
2108
	while ( (pos++) < size )
1972
	while ( (pos++) < size )
2109
	{
1973
	{
2110
		if ( data[pos] == '\n' )
1974
		if ( data[pos] == '\n' )
2111
		{
1975
		{
2112
			data[pos] = '\0';
1976
			data[pos] = '\0';
2113
			line = (char *)(data + startLine);
1977
			line = Utils::WString::FromString((char *)(data + startLine));
2114
			line.removeChar(9);
1978
			line.removeChar(9);
2115
			line.removeChar('\r');
1979
			line.removeChar('\r');
2116
			line.removeFirstSpace();
1980
			line.removeFirstSpace();
2117
 
1981
 
2118
			if ( !line.empty() && line[0] != '/' )
1982
			if ( !line.empty() && line[0] != '/' )
2119
			{
1983
			{
2120
				Utils::String first = line.token(":", 1);
1984
				Utils::WString first = line.token(L":", 1);
2121
				if ( first.Compare("MATERIAL6") )
1985
				if ( first.Compare(L"MATERIAL6") )
2122
				{
1986
				{
2123
					int max;
-
 
2124
					Utils::String material = line.tokens(":", 2);
1987
					Utils::WString material = line.tokens(L":", 2);
2125
					Utils::String *strs = material.tokens(";", 6).tokenise("; ", &max);
1988
					std::vector<Utils::WString> strs;
2126
 
-
 
2127
					int num = material.token(";", 5);
1989
					int num = material.token(L";", 5);
2128
					if ( strs && max >= 2)
1990
					if(material.tokens(L";", 6).tokenise(L"; ", strs))
2129
					{
1991
					{
2130
						for(int i = 0; i < max; i++) {
1992
						for(size_t i = 0; i < strs.size(); i++) {
2131
							Utils::String type = strs[i].token(";", 1);
1993
							Utils::WString type = strs[i].token(L";", 1);
2132
							Utils::String valtype = strs[i].token(";", 2);			
1994
							Utils::WString valtype = strs[i].token(L";", 2);			
2133
							if ( valtype.Compare("SPTYPE_STRING") ) {
1995
							if ( valtype.Compare(L"SPTYPE_STRING") ) {
2134
								Utils::String file = strs[i].token(";", 3);
1996
								Utils::WString file = strs[i].token(L";", 3);
2135
								if(!list.contains(file))
1997
								if(!list.contains(file))
2136
									list.pushBack(file, L"");
1998
									list.pushBack(file, L"");
2137
							}
1999
							}
2138
						}
2000
						}
2139
					}
2001
					}
2140
 
-
 
2141
					CLEANSPLIT(strs, max)
-
 
2142
				}
2002
				}
2143
			}
2003
			}
2144
 
2004
 
2145
			startLine = pos + 1;
2005
			startLine = pos + 1;
2146
		}
2006
		}
Line 2221... Line 2081...
2221
	for(auto itr = lTextures.begin(); itr != lTextures.end(); itr++)
2081
	for(auto itr = lTextures.begin(); itr != lTextures.end(); itr++)
2222
	{
2082
	{
2223
		CFileIO F((*itr)->str);
2083
		CFileIO F((*itr)->str);
2224
		if ( F.isFileExtension(L"fx") ) {
2084
		if ( F.isFileExtension(L"fx") ) {
2225
			/*
2085
			/*
2226
			if ( !pVfs->extractGameFileToPackage(this, "shader\\1_1\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2086
			if ( !pVfs->extractGameFileToPackage(this, "shader\\1_1\\" + Utils::WString(node->str.ToString()), FILETYPE_SHIPOTHER) )
2227
				pVfs->extractGameFileToPackage(this, "shader\\1_1\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2087
				pVfs->extractGameFileToPackage(this, "shader\\1_1\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2228
			if ( !pVfs->extractGameFileToPackage(this, "shader\\1_4\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2088
			if ( !pVfs->extractGameFileToPackage(this, "shader\\1_4\\" + Utils::WString(node->str.ToString()), FILETYPE_SHIPOTHER) )
2229
				pVfs->extractGameFileToPackage(this, "shader\\1_4\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2089
				pVfs->extractGameFileToPackage(this, "shader\\1_4\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2230
			if ( !pVfs->extractGameFileToPackage(this, "shader\\2_0\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2090
			if ( !pVfs->extractGameFileToPackage(this, "shader\\2_0\\" + Utils::WString(node->str.ToString()), FILETYPE_SHIPOTHER) )
2231
				pVfs->extractGameFileToPackage(this, "shader\\2_0\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2091
				pVfs->extractGameFileToPackage(this, "shader\\2_0\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2232
			if ( !pVfs->extractGameFileToPackage(this, "shader\\2_a\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2092
			if ( !pVfs->extractGameFileToPackage(this, "shader\\2_a\\" + Utils::WString(node->str.ToString()), FILETYPE_SHIPOTHER) )
2233
				pVfs->extractGameFileToPackage(this, "shader\\2_a\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2093
				pVfs->extractGameFileToPackage(this, "shader\\2_a\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2234
			if ( !pVfs->extractGameFileToPackage(this, "shader\\2_b\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2094
			if ( !pVfs->extractGameFileToPackage(this, "shader\\2_b\\" + Utils::WString(node->str.ToString()), FILETYPE_SHIPOTHER) )
2235
				pVfs->extractGameFileToPackage(this, "shader\\2_b\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2095
				pVfs->extractGameFileToPackage(this, "shader\\2_b\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2236
			if ( !pVfs->extractGameFileToPackage(this, "shader\\3_0\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2096
			if ( !pVfs->extractGameFileToPackage(this, "shader\\3_0\\" + Utils::WString(node->str.ToString()), FILETYPE_SHIPOTHER) )
2237
				pVfs->extractGameFileToPackage(this, "shader\\3_0\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2097
				pVfs->extractGameFileToPackage(this, "shader\\3_0\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2238
				*/
2098
				*/
2239
		}
2099
		}
2240
		else {
2100
		else {
2241
			if ( pVfs->extractGameFileToPackage(this, L"dds\\" + (*itr)->str, FILETYPE_SHIPOTHER) )
2101
			if ( pVfs->extractGameFileToPackage(this, L"dds\\" + (*itr)->str, FILETYPE_SHIPOTHER) )
Line 2305... Line 2165...
2305
	}
2165
	}
2306
 
2166
 
2307
	return false;
2167
	return false;
2308
}
2168
}
2309
 
2169
 
2310
bool CXspFile::importBodies(const Utils::CStringList &sceneModels, const Utils::String &filename)
2170
bool CXspFile::importBodies(const Utils::WStringList &sceneModels, const Utils::WString &filename)
2311
{
2171
{
2312
	CFileIO File(filename);
2172
	CFileIO File(filename);
2313
	if ( File.exists() )
2173
	if ( File.exists() )
2314
	{
2174
	{
2315
		Utils::String sSection;
2175
		Utils::WString sSection;
2316
		int section = 0;
2176
		int section = 0;
2317
		std::vector<Utils::String> lines;
2177
		std::vector<Utils::WString> lines;
2318
		if (File.readLines(lines))
2178
		if (File.readLines(lines))
2319
		{
2179
		{
2320
			for(auto itr = lines.begin(); itr != lines.end(); itr++)
2180
			for(auto itr = lines.begin(); itr != lines.end(); itr++)
2321
			{
2181
			{
2322
				Utils::String l = *itr;
2182
				Utils::WString l = *itr;
2323
				l.removeChar(9);
2183
				l.removeChar(9);
2324
				l.removeChar('\r');
2184
				l.removeChar('\r');
2325
				l.removeFirstSpace();
2185
				l.removeFirstSpace();
2326
				if (l.empty())
2186
				if (l.empty())
2327
					continue;
2187
					continue;
Line 2329... Line 2189...
2329
					continue;
2189
					continue;
2330
 
2190
 
2331
				// are we looking for a section
2191
				// are we looking for a section
2332
				if (section <= 0)
2192
				if (section <= 0)
2333
				{
2193
				{
2334
					sSection = l.token(";", 1);
2194
					sSection = l.token(L";", 1);
2335
					section = l.token(";", 2).toInt();
2195
					section = l.token(L";", 2).toInt();
2336
				}
2196
				}
2337
				else
2197
				else
2338
				{
2198
				{
2339
					int max;
-
 
2340
					Utils::String* strs = l.tokenise(";", &max);
2199
					std::vector<Utils::WString> strs;
2341
					if (strs && max)
2200
					if(l.tokenise(L";", strs))
2342
					{
2201
					{
2343
						for (int i = 0; i < max; i++)
2202
						for (size_t i = 0; i < strs.size(); i++)
2344
						{
2203
						{
2345
							strs[i].removeEndSpace();
2204
							strs[i].removeEndSpace();
2346
							strs[i].removeFirstSpace();
2205
							strs[i].removeFirstSpace();
2347
							if (strs[i].empty())
2206
							if (strs[i].empty())
2348
								continue;
2207
								continue;
2349
							if (sceneModels.contains(strs[i]))
2208
							if (sceneModels.contains(strs[i]))
2350
								this->addBody(sSection, strs[i]);
2209
								this->addBody(sSection, strs[i]);
2351
							--section;
2210
							--section;
2352
						}
2211
						}
2353
					}
2212
					}
2354
					CLEANSPLIT(strs, max)
-
 
2355
				}
2213
				}
2356
			}
2214
			}
2357
			return true;
2215
			return true;
2358
		}
2216
		}
2359
	}
2217
	}
2360
 
2218
 
2361
	return false;
2219
	return false;
2362
}
2220
}
2363
 
2221
 
2364
bool CXspFile::ImportCockpits(const Utils::String &filename)
2222
bool CXspFile::ImportCockpits(const Utils::WString &filename)
2365
{
2223
{
2366
	CFileIO File(filename);
2224
	CFileIO File(filename);
2367
	if ( File.exists() )
2225
	if ( File.exists() )
2368
	{
2226
	{
2369
		std::vector<Utils::WString> lines;
2227
		std::vector<Utils::WString> lines;
Line 2410... Line 2268...
2410
}
2268
}
2411
 
2269
 
2412
bool CXspFile::extractCockpits(CVirtualFileSystem *pVfs)
2270
bool CXspFile::extractCockpits(CVirtualFileSystem *pVfs)
2413
{
2271
{
2414
	if ( !pVfs->extractGameFile(L"types/TCockpits.pck", CPackages::tempDirectory() + L"tmp.dat").empty() ) {
2272
	if ( !pVfs->extractGameFile(L"types/TCockpits.pck", CPackages::tempDirectory() + L"tmp.dat").empty() ) {
2415
		bool ret = this->ImportCockpits((CPackages::tempDirectory() + L"tmp.dat").toString());
2273
		bool ret = this->ImportCockpits((CPackages::tempDirectory() + L"tmp.dat"));
2416
		CFileIO::Remove(CPackages::tempDirectory() + L"tmp.dat");
2274
		CFileIO::Remove(CPackages::tempDirectory() + L"tmp.dat");
2417
 
2275
 
2418
		return ret;
2276
		return ret;
2419
	}
2277
	}
2420
 
2278
 
2421
	return false;
2279
	return false;
2422
}
2280
}
2423
 
2281
 
2424
bool CXspFile::extractBodies(CVirtualFileSystem *pVfs, const Utils::CStringList &sceneModels)
2282
bool CXspFile::extractBodies(CVirtualFileSystem *pVfs, const Utils::WStringList &sceneModels)
2425
{
2283
{
2426
	if (sceneModels.empty()) return false;
2284
	if (sceneModels.empty()) return false;
2427
 
2285
 
2428
	if ( !pVfs->extractGameFile(L"types/Bodies.pck", CPackages::tempDirectory() + L"tmp.dat").empty() ) {
2286
	if ( !pVfs->extractGameFile(L"types/Bodies.pck", CPackages::tempDirectory() + L"tmp.dat").empty() ) {
2429
		bool ret = this->importBodies(sceneModels, (CPackages::tempDirectory() + L"tmp.dat").toString());
2287
		bool ret = this->importBodies(sceneModels, (CPackages::tempDirectory() + L"tmp.dat"));
2430
		CFileIO::Remove(CPackages::tempDirectory() + L"tmp.dat");
2288
		CFileIO::Remove(CPackages::tempDirectory() + L"tmp.dat");
2431
 
2289
 
2432
		return ret;
2290
		return ret;
2433
	}
2291
	}
2434
 
2292
 
Line 2581... Line 2439...
2581
			CFileIO::Remove(CPackages::tempDirectory() + L"/tmp.dat");
2439
			CFileIO::Remove(CPackages::tempDirectory() + L"/tmp.dat");
2582
		}
2440
		}
2583
	}
2441
	}
2584
}
2442
}
2585
 
2443
 
2586
bool CXspFile::processSceneFileSection(int section, CVirtualFileSystem *pVfs, Utils::CStringList &lModels, CProgressInfo *progress)
2444
bool CXspFile::processSceneFileSection(int section, CVirtualFileSystem *pVfs, Utils::WStringList &lModels, CProgressInfo *progress)
2587
{
2445
{
2588
	if ( progress ) progress->UpdateStatus(section);
2446
	if ( progress ) progress->UpdateStatus(section);
2589
 
2447
 
2590
	switch ( section )
2448
	switch ( section )
2591
	{
2449
	{
Line 2599... Line 2457...
2599
				if (lModels.empty()) return false;
2457
				if (lModels.empty()) return false;
2600
				for(auto itr = lModels.begin(); itr != lModels.end(); itr++)
2458
				for(auto itr = lModels.begin(); itr != lModels.end(); itr++)
2601
				{
2459
				{
2602
					if ((*itr)->str.isNumber() ) // count be componants or dummy
2460
					if ((*itr)->str.isNumber() ) // count be componants or dummy
2603
						continue;
2461
						continue;
2604
					if ( pVfs->extractGameFileToPackage(this, "objects\\" + (*itr)->str + ".pbb", FILETYPE_SHIPMODEL, "objects\\" + (*itr)->str + ".bob") )
2462
					if ( pVfs->extractGameFileToPackage(this, L"objects\\" + (*itr)->str + L".pbb", FILETYPE_SHIPMODEL, L"objects\\" + (*itr)->str + L".bob") )
2605
						continue;
2463
						continue;
2606
					if ( pVfs->extractGameFileToPackage(this, "objects\\" + (*itr)->str + ".pbd", FILETYPE_SHIPMODEL, "objects\\" + (*itr)->str + ".bod") )
2464
					if ( pVfs->extractGameFileToPackage(this, L"objects\\" + (*itr)->str + ".pbd", FILETYPE_SHIPMODEL, L"objects\\" + (*itr)->str + L".bod") )
2607
						continue;
2465
						continue;
2608
				}
2466
				}
2609
			}
2467
			}
2610
			break;
2468
			break;
2611
 
2469
 
Line 2642... Line 2500...
2642
 
2500
 
2643
bool CXspFile::processSceneFiles(CVirtualFileSystem *pVfs, CProgressInfo *progress)
2501
bool CXspFile::processSceneFiles(CVirtualFileSystem *pVfs, CProgressInfo *progress)
2644
{
2502
{
2645
	// now lets parse our files
2503
	// now lets parse our files
2646
	if ( progress ) progress->UpdateStatus(IMPORTSHIP_EXTRACTSCENE);
2504
	if ( progress ) progress->UpdateStatus(IMPORTSHIP_EXTRACTSCENE);
2647
	Utils::CStringList lModels;
2505
	Utils::WStringList lModels;
2648
	if(!readSceneModels(lModels))
2506
	if(!readSceneModels(lModels))
2649
		return false;
2507
		return false;
2650
 
2508
 
2651
	// extract componants, and add extra items to list
2509
	// extract componants, and add extra items to list
2652
	if ( !this->processSceneFileSection(IMPORTSHIP_COMPONANT, pVfs, lModels, progress) )
2510
	if ( !this->processSceneFileSection(IMPORTSHIP_COMPONANT, pVfs, lModels, progress) )