Subversion Repositories spk

Rev

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

Rev 171 Rev 173
Line 5422... Line 5422...
5422
	}
5422
	}
5423
 
5423
 
5424
	return count;
5424
	return count;
5425
}
5425
}
5426
 
5426
 
5427
int CPackages::ExtractGameFile(CyString aFilename, CyString aTo, CyString dir, CyString addon)
5427
int CPackages::extractGameFile(const Utils::String &aFilename, const Utils::String &aTo, const Utils::String &aDir, const Utils::String &addon) const
5428
{
5428
{
5429
	// first check the enabled mod
5429
	// first check the enabled mod
-
 
5430
	Utils::String dir = aDir;
5430
	if ( dir.Empty() )
5431
	if (dir.empty())
5431
		dir = m_sCurrentDir;
5432
		dir = m_sCurrentDir;
5432
 
5433
 
5433
	CyString addonDir = addon;
5434
	Utils::String addonDir = addon;
5434
	if ( addonDir.Empty() ) addonDir = this->GetAddonDir(dir);
5435
	if (addonDir.empty()) addonDir = this->getAddonDir(dir);
5435
 
5436
 
5436
	if ( m_pEnabledMod && m_pEnabledMod->AnyFileType(FILETYPE_MOD) )
5437
	if (m_pEnabledMod && m_pEnabledMod->AnyFileType(FILETYPE_MOD))
5437
	{
5438
	{
5438
		for ( C_File *file = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); file; file = m_pEnabledMod->GetNextFile(file) )
5439
		for (C_File* file = m_pEnabledMod->GetFirstFile(FILETYPE_MOD); file; file = m_pEnabledMod->GetNextFile(file))
5439
		{
5440
		{
5440
			if ( !file->CheckFileExt("cat") )
5441
			if (!file->CheckFileExt("cat"))
5441
				continue;
5442
				continue;
5442
 
5443
 
5443
			CCatFile catFile;
5444
			CCatFile catFile;
5444
			if ( catFile.open(file->filePointer(), addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
5445
			if (catFile.open(file->filePointer(), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5445
			{
5446
			{
5446
				if ( catFile.ExtractFile(aFilename, aTo) )
5447
				if (catFile.ExtractFile(aFilename, aTo))
5447
					return 1;
5448
					return 1;
5448
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5449
				if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
5449
				{
5450
				{
5450
					if ( catFile.ExtractFile(aFilename) )
5451
					if (catFile.ExtractFile(aFilename))
5451
						return -1;
5452
						return -1;
5452
				}
5453
				}
5453
 
5454
 
5454
			}
5455
			}
5455
		}
5456
		}
5456
	}
5457
	}
5457
	else if ( !m_sSetMod.empty() )
5458
	else if (!m_sSetMod.empty())
5458
	{
5459
	{
5459
		if ( CFileIO::Exists(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat"))
5460
		if (CFileIO::Exists(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat"))
5460
		{
5461
		{
5461
			CCatFile catFile;
5462
			CCatFile catFile;
5462
			if (catFile.open(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat", addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE)
5463
			if (catFile.open(m_sCurrentDir + "/mods/" + m_sSetMod + ".cat", addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5463
			{
5464
			{
5464
				if ( catFile.ExtractFile(aFilename, aTo) )
5465
				if (catFile.ExtractFile(aFilename, aTo))
5465
					return 1;
5466
					return 1;
5466
				if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5467
				if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
5467
				{
5468
				{
5468
					if ( catFile.ExtractFile(aFilename) )
5469
					if (catFile.ExtractFile(aFilename))
5469
						return -1;
5470
						return -1;
5470
				}
5471
				}
5471
			}
5472
			}
5472
		}
5473
		}
5473
	}
5474
	}
5474
 
5475
 
5475
	// find the highest cat number
5476
	// find the highest cat number
5476
	int catNumber = 1;
5477
	int catNumber = 1;
5477
	while ( CFileIO(dir + "/" + CyString::Number(catNumber).PadNumber(2) + ".cat").ExistsOld() && catNumber < 99 )
5478
	while (CFileIO::Exists(dir + "/" + Utils::String::PadNumber(catNumber, 2) + ".cat") && catNumber < 99)
5478
		++catNumber;
5479
		++catNumber;
5479
 
5480
 
5480
	// get the last one, not the next free one
5481
	// get the last one, not the next free one
5481
	--catNumber;
5482
	--catNumber;
5482
 
5483
 
5483
	// work backwards until we find the file
5484
	// work backwards until we find the file
5484
	for ( ; catNumber; catNumber-- )
5485
	for (; catNumber; catNumber--)
5485
	{
5486
	{
5486
		CCatFile catFile;
5487
		CCatFile catFile;
5487
		if (catFile.open((dir + "/" + CyString::Number(catNumber).PadNumber(2) + ".cat").ToString(), addonDir.ToString(), CATREAD_CATDECRYPT, false) == CATERR_NONE )
5488
		if (catFile.open((dir + "/" + Utils::String::PadNumber(catNumber, 2) + ".cat"), addonDir, CATREAD_CATDECRYPT, false) == CATERR_NONE)
5488
		{
5489
		{
5489
			// check for the file
5490
			// check for the file
5490
			if ( catFile.ExtractFile(aFilename, aTo) )
5491
			if (catFile.ExtractFile(aFilename, aTo))
5491
				return 1;
5492
				return 1;
5492
			if ( catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR )
5493
			if (catFile.error() == CATERR_INVALIDDEST || catFile.error() == CATERR_CANTCREATEDIR)
5493
			{
5494
			{
5494
				if ( catFile.ExtractFile(aFilename) )
5495
				if (catFile.ExtractFile(aFilename))
5495
					return -1;
5496
					return -1;
5496
			}
5497
			}
5497
		}
5498
		}
5498
	}
5499
	}
5499
 
5500
 
Line 7364... Line 7365...
7364
{
7365
{
7365
	_removeWareOverride(Ware_Custom, 0, id);
7366
	_removeWareOverride(Ware_Custom, 0, id);
7366
}
7367
}
7367
 
7368
 
7368
 
7369
 
7369
bool CPackages::ReadGlobals(CyStringList &globals)
7370
bool CPackages::readGlobals(Utils::CStringList &globals) const
7370
{
7371
{
7371
	int e = ExtractGameFile("types/Globals.pck", m_sTempDir);
7372
	int e = extractGameFile("types/Globals.pck", m_sTempDir);
7372
	if ( e )
7373
	if ( e )
7373
	{
7374
	{
7374
		CFileIO File((e == -1) ? "Globals.txt" : m_sTempDir + "/Globals.txt");
7375
		CFileIO File((e == -1) ? "Globals.txt" : m_sTempDir + "/Globals.txt");
7375
		if ( File.exists() )
7376
		if ( File.exists() )
7376
		{
7377
		{
7377
			CyStringList *lines = File.ReadLinesStr();
7378
			std::vector<Utils::String> lines;
7378
			if ( lines )
7379
			if(File.readLines(lines))
7379
			{
7380
			{
7380
				int entries = -1;
7381
				int entries = -1;
7381
				for ( SStringList *str = lines->Head(); str; str = str->next )
7382
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
7382
				{
7383
				{
7383
					str->str.RemoveChar('\r');
7384
					Utils::String str = itr->remove('\r').remove(9);
7384
					str->str.RemoveChar(9);
-
 
7385
					str->str.RemoveFirstSpace();
7385
					str.removeFirstSpace();
7386
 
7386
 
7387
					if ( str->str.Empty() )
7387
					if ( str.empty() )
7388
						continue;
7388
						continue;
7389
					if ( str->str[0] == '/' )
7389
					if ( str[0] == '/' )
7390
						continue;
7390
						continue;
7391
 
7391
 
7392
					// remove comments
7392
					// remove comments
7393
					CyString l = str->str;
-
 
7394
					if ( l.IsIn("/") ) 
7393
					if (str.contains("/") ) 
7395
						l = l.GetToken("/", 1, 1);
7394
						str = str.token("/", 1);
7396
 
7395
 
7397
					if ( entries == -1 )
7396
					if ( entries == -1 )
7398
						entries = l.GetToken(";", 1, 1).ToInt();
7397
						entries = str.token(";", 1).toInt();
7399
					else
7398
					else
7400
						globals.PushBack(l.GetToken(";", 1, 1), l.GetToken(";", 2, 2));
7399
						globals.pushBack(str.token(";", 1), str.token(";", 2));
7401
				}
7400
				}
7402
 
7401
 
7403
				delete lines;
-
 
7404
 
-
 
7405
				return true;
7402
				return true;
7406
			}
7403
			}
7407
		}
7404
		}
7408
	}
7405
	}
7409
 
7406
 
Line 7413... Line 7410...
7413
void CPackages::CreateGlobals()
7410
void CPackages::CreateGlobals()
7414
{
7411
{
7415
	if ( m_lGlobals.empty() )
7412
	if ( m_lGlobals.empty() )
7416
		return; // no global settings
7413
		return; // no global settings
7417
 
7414
 
7418
	CyStringList globals;
7415
	Utils::CStringList globals;
7419
	if ( ReadGlobals(globals) )
7416
	if (readGlobals(globals))
7420
	{
7417
	{
7421
		// apply out settings
7418
		// apply out settings
7422
		for(auto itr = m_lGlobals.begin(); itr != m_lGlobals.end(); itr++)
7419
		for(auto itr = m_lGlobals.begin(); itr != m_lGlobals.end(); itr++)
7423
		{
-
 
7424
			SStringList *found = globals.FindString((*itr)->str);
-
 
7425
			if ( found )
-
 
7426
				found->data = (*itr)->data;
7420
			globals.changeData((*itr)->str, (*itr)->data);
7427
		}
-
 
7428
 
7421
 
7429
		// now write it
7422
		// now write it
7430
		CyStringList writeList;
7423
		Utils::CStringList writeList;
7431
		for ( SStringList *str = globals.Head(); str; str = str->next )
7424
		for(auto itr = globals.begin(); itr != globals.end(); itr++)
7432
			writeList.PushBack(str->str + ";" + str->data + ";");
7425
			writeList.pushBack((*itr)->str + ";" + (*itr)->data + ";");
7433
		
7426
		
7434
		// finally, write the file
7427
		// finally, write the file
7435
		writeList.PushFront(CyString::Number(writeList.Count()) + "; /globals amount", "");
7428
		writeList.pushFront(Utils::String::Number(writeList.size()) + "; /globals amount", "");
7436
		writeList.PushFront(CyString("// Globals file, created by SPK Libraries V") + CyString::CreateFromFloat(GetLibraryVersion(), 2), "");
7429
		writeList.pushFront("// Globals file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2), "");
7437
 
7430
 
7438
		CFileIO WriteFile(m_sTempDir + "/Globals.txt");
7431
		CFileIO WriteFile(m_sTempDir + "/Globals.txt");
7439
		if ( WriteFile.WriteFile(&writeList) )
7432
		if ( WriteFile.writeFile(&writeList) )
7440
		{
7433
		{
7441
			this->PackFile(&WriteFile, "types/Globals.pck");
7434
			this->PackFile(&WriteFile, "types/Globals.pck");
7442
			WriteFile.remove();
7435
			WriteFile.remove();
7443
		}
7436
		}
7444
	}
7437
	}
Line 7758... Line 7751...
7758
	{
7751
	{
7759
		// read the dummies
7752
		// read the dummies
7760
		CFileIO File;
7753
		CFileIO File;
7761
		if ( File.open((e == -1) ? "TCockpits.txt" : m_sTempDir + "/TCockpits.txt") )
7754
		if ( File.open((e == -1) ? "TCockpits.txt" : m_sTempDir + "/TCockpits.txt") )
7762
		{
7755
		{
7763
			CyStringList *lines = File.ReadLinesStr();
7756
			std::vector<Utils::String> lines;
7764
			if ( lines )
7757
			if(File.readLines(lines))
7765
			{
7758
			{
7766
				int count = -1;
7759
				int count = -1;
7767
				for ( SStringList *str = lines->Head(); str; str = str->next )
7760
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
7768
				{
7761
				{
7769
					CyString line(str->str);
7762
					Utils::String line(*itr);
7770
					line.RemoveChar('\r');
7763
					line.removeChar('\r');
7771
					line.RemoveChar(9);
7764
					line.removeChar(9);
7772
					line = line.RemoveFirstSpace();
7765
					line = line.removeFirstSpace();
7773
					line = line.RemoveEndSpace();
7766
					line = line.removeEndSpace();
7774
					if ( line.Empty() )
7767
					if ( line.empty() )
7775
						continue;
7768
						continue;
7776
					if ( line[0] == '/' )
7769
					if ( line[0] == '/' )
7777
						continue;
7770
						continue;
7778
 
7771
 
7779
					if ( count == -1 )
7772
					if ( count == -1 )
7780
					{
7773
					{
7781
						fileType = line.GetToken(";", 1, 1).ToInt();
7774
						fileType = line.token(";", 1).toInt();
7782
						count = line.GetToken(";", 2, 2).ToInt();
7775
						count = line.token(";", 2).toInt();
7783
					}
7776
					}
7784
					else
7777
					else
7785
					{
7778
					{
7786
						while ( !line.Empty() )
7779
						while ( !line.empty() )
7787
						{
7780
						{
7788
							CyString data = line.GetToken(";", 1, 19);
7781
							Utils::String data = line.tokens(";", 1, 19);
7789
							cockpitList->PushBack(data + ";");
7782
							cockpitList->PushBack(CyString(data + ";"));
7790
							line = line.DelToken(";", 1, 19);
7783
							line = line.remTokens(";", 1, 19);
7791
 
7784
 
7792
							--count;
7785
							--count;
7793
							if ( count < 1 )
7786
							if ( count < 1 )
7794
								break;
7787
								break;
7795
						}
7788
						}
7796
					}
7789
					}
7797
				}
7790
				}
7798
 
-
 
7799
				delete lines;
-
 
7800
			}
7791
			}
7801
 
7792
 
7802
			File.remove();
7793
			File.remove();
7803
		}
7794
		}
7804
 
7795
 
Line 8367... Line 8358...
8367
	// now check it exists
8358
	// now check it exists
8368
	if ( !File.exists() )
8359
	if ( !File.exists() )
8369
		return false;
8360
		return false;
8370
 
8361
 
8371
	// now read the file for the correct contents
8362
	// now read the file for the correct contents
8372
	CyStringList *lines = File.ReadLinesStr();
8363
	std::vector<Utils::String> lines;
8373
	if ( !lines )
8364
	if (!File.readLines(lines))
8374
		return false;
8365
		return false;
8375
 
8366
 
8376
	// check that one of the lines is correct
8367
	// check that one of the lines is correct
8377
	for ( SStringList *s = lines->Head(); s; s = s->next )
8368
	for(auto itr = lines.begin(); itr != lines.end(); itr++)
8378
	{
8369
	{
8379
		if ( s->str == "testing access rights" )
8370
		if ( *itr == "testing access rights" )
8380
		{
-
 
8381
			delete lines;
-
 
8382
			return true;
8371
			return true;
8383
		}
-
 
8384
	}
8372
	}
8385
 
8373
 
8386
	delete lines;
-
 
8387
 
-
 
8388
	return false;
8374
	return false;
8389
}
8375
}
8390
 
8376
 
8391
bool CPackages::LoadShipData(CyString file, CyStringList *list)
8377
bool CPackages::LoadShipData(CyString file, CyStringList *list)
8392
{
8378
{
Line 8426... Line 8412...
8426
 
8412
 
8427
	if ( !File.exists() )
8413
	if ( !File.exists() )
8428
		return false;
8414
		return false;
8429
 
8415
 
8430
	bool ret = false;
8416
	bool ret = false;
8431
	CyStringList *lines = File.ReadLinesStr();
8417
	std::vector<Utils::String> lines;
8432
	if ( lines )
8418
	if(File.readLines(lines))
8433
	{
8419
	{
8434
		bool readFirst = false;
8420
		bool readFirst = false;
8435
		for ( SStringList *str = lines->Head(); str; str = str->next )
8421
		for(auto itr = lines.begin(); itr != lines.end(); itr++)
8436
		{
8422
		{
8437
			if ( str->str.Empty() )
8423
			if ( itr->empty() )
8438
				continue;
8424
				continue;
8439
			str->str.RemoveChar('\r');
8425
			Utils::String str = itr->remove('\r').remove(9);
8440
			str->str.RemoveChar(9);
-
 
8441
			str->str.RemoveFirstSpace();
8426
			str = str.removeFirstSpace();
8442
			if ( str->str.Empty() )
8427
			if ( str.empty() )
8443
				continue;
8428
				continue;
8444
			if ( str->str[0] == '/' || str->str[0] == '#' )
8429
			if ( str[0] == '/' || str[0] == '#' )
8445
				continue;
8430
				continue;
8446
 
8431
 
8447
			if ( !readFirst )
8432
			if ( !readFirst )
8448
				readFirst = true;
8433
				readFirst = true;
8449
			else
8434
			else
8450
			{
8435
			{
8451
				CyString t = str->str.GetToken(";", -2);
8436
				Utils::String t = str.tokens(";", -2);
8452
				while ( t.Right(1) == ";" )
8437
				while ( t.right(1) == ";" )
8453
					t.Truncate((int)t.Length() - 1);
8438
					t.truncate((int)t.length() - 1);
8454
				list->PushBack(t, str->str);
8439
				list->PushBack(CyString(t), CyString(str));
8455
			}
8440
			}
8456
		}
8441
		}
8457
 
8442
 
8458
		delete lines;
-
 
8459
		ret = true;
8443
		ret = true;
8460
	}
8444
	}
8461
 
8445
 
8462
	if ( deleteFile )
8446
	if ( deleteFile )
8463
		File.remove();
8447
		File.remove();
Line 8563... Line 8547...
8563
 
8547
 
8564
	if ( !File.exists() )
8548
	if ( !File.exists() )
8565
		return false;
8549
		return false;
8566
 
8550
 
8567
	// open and read file
8551
	// open and read file
8568
	CyStringList *lines = File.ReadLinesStr();
8552
	std::vector<Utils::String> lines;
8569
	if ( !lines )
8553
	if(!File.readLines(lines))
8570
		return false;
8554
		return false;
8571
 
8555
 
8572
	bool inPage = false;
8556
	bool inPage = false;
8573
	for ( SStringList *str = lines->Head(); str; str = str->next )
8557
	for(auto itr = lines.begin(); itr != lines.end(); itr++)
8574
	{
8558
	{
8575
		// search for page
8559
		// search for page
8576
		if ( !inPage )
8560
		if ( !inPage )
8577
		{
8561
		{
8578
			if ( str->str.FindPos("<page") > -1 )
8562
			if (itr->findPos("<page") > -1 )
8579
			{
8563
			{
8580
				// find the page id
8564
				// find the page id
8581
				int pos = str->str.FindPos("\"");
8565
				int pos = itr->findPos("\"");
8582
				if ( pos > -1 )
8566
				if ( pos > -1 )
8583
				{
8567
				{
8584
					int endpos = str->str.FindPos("\"", pos + 1);
8568
					int endpos = itr->findPos("\"", pos + 1);
8585
					if ( endpos > -1 )
8569
					if ( endpos > -1 )
8586
					{
8570
					{
8587
						CyString p = str->str.Mid(pos + 2, endpos - pos - 1);
8571
						Utils::String p = itr->mid(pos + 2, endpos - pos - 1);
8588
						if ( p.Length() > 4 )
8572
						if ( p.length() > 4 )
8589
							p = p.Right(4);
8573
							p = p.right(4);
8590
						int checkPage = p.ToInt();
8574
						int checkPage = p.toInt();
8591
						if ( checkPage == page )
8575
						if ( checkPage == page )
8592
							inPage = true;
8576
							inPage = true;
8593
					}
8577
					}
8594
				}
8578
				}
8595
			}
8579
			}
8596
 
8580
 
8597
		}
8581
		}
8598
		// add each id
8582
		// add each id
8599
		else
8583
		else
8600
		{
8584
		{
8601
			if ( str->str.FindPos("</page") > -1 )
8585
			if (itr->findPos("</page") > -1 )
8602
				break;
8586
				break;
8603
 
8587
 
8604
			if ( str->str.FindPos("<t id") > -1 )
8588
			if (itr->findPos("<t id") > -1 )
8605
			{
8589
			{
8606
				int pos = str->str.FindPos("\"");
8590
				int pos = itr->findPos("\"");
8607
				if ( pos > -1 )
8591
				if ( pos > -1 )
8608
				{
8592
				{
8609
					int endpos = str->str.FindPos("\"", pos + 1);
8593
					int endpos = itr->findPos("\"", pos + 1);
8610
					if ( endpos > -1 )
8594
					if ( endpos > -1 )
8611
					{
8595
					{
8612
						int id = str->str.Mid(pos + 2, endpos - pos - 1).ToInt();
8596
						int id = itr->mid(pos + 2, endpos - pos - 1).toInt();
8613
						pos = str->str.FindPos(">", endpos);
8597
						pos = itr->findPos(">", endpos);
8614
						if ( pos > -1 )
8598
						if ( pos > -1 )
8615
						{
8599
						{
8616
							++pos;
8600
							++pos;
8617
							endpos = str->str.FindPos("</", pos);
8601
							endpos = itr->findPos("</", pos);
8618
							if ( endpos > -1 )
8602
							if ( endpos > -1 )
8619
							{
8603
							{
8620
								CyString text = str->str.Mid(pos + 1, endpos - pos);
8604
								Utils::String text = itr->mid(pos + 1, endpos - pos);
8621
								while ( text.FindPos('(') != -1 && text.FindPos(')') != -1 )
8605
								while ( text.findPos('(') != -1 && text.findPos(')') != -1 )
8622
								{
8606
								{
8623
									int s = text.FindPos('(');
8607
									int s = text.findPos('(');
8624
									text = text.Erase(s, text.FindPos(')') - s + 1);
8608
									text = text.erase(s, text.findPos(')') - s + 1);
8625
								}
8609
								}
8626
								list->PushBack(CyString::Number(id), text, search);
8610
								list->PushBack(CyString::Number(id), CyString(text), search);
8627
							}
8611
							}
8628
						}
8612
						}
8629
					}
8613
					}
8630
				}
8614
				}
8631
			}
8615
			}
8632
		}
8616
		}
8633
	}
8617
	}
8634
 
8618
 
8635
	delete lines;
-
 
8636
 
-
 
8637
	return true;
8619
	return true;
8638
}
8620
}
8639
 
8621
 
8640
CyStringList *CPackages::ReadTextPage(CyString file, bool search, int page)
8622
CyStringList *CPackages::ReadTextPage(CyString file, bool search, int page)
8641
{
8623
{