Subversion Repositories spk

Rev

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

Rev 125 Rev 160
Line 343... Line 343...
343
 
343
 
344
bool CModDiff::WriteDiff(const Utils::String &file)
344
bool CModDiff::WriteDiff(const Utils::String &file)
345
{
345
{
346
	if ( m_lFiles.empty() ) return false;
346
	if ( m_lFiles.empty() ) return false;
347
 
347
 
348
	CyStringList lines;
348
	Utils::CStringList lines;
349
	
349
	
350
	for ( CListNode<SDiffFile> *node = m_lFiles.Front(); node; node = node->next() )
350
	for ( CListNode<SDiffFile> *node = m_lFiles.Front(); node; node = node->next() )
351
	{
351
	{
352
		lines.PushBack(CyString("$$") + node->Data()->sFile);
352
		lines.pushBack("$$" + node->Data()->sFile);
353
		for ( CListNode<SDiffEntry> *node2 = node->Data()->m_lEntries.Front(); node2; node2 = node2->next() )
353
		for ( CListNode<SDiffEntry> *node2 = node->Data()->m_lEntries.Front(); node2; node2 = node2->next() )
354
		{
354
		{
355
			switch(node2->Data()->iType)
355
			switch(node2->Data()->iType)
356
			{
356
			{
357
				case DIFFTYPE_ADDITION:
357
				case DIFFTYPE_ADDITION:
358
					lines.PushBack(CyString("+++:";) + (long)node2->Data()->iID + ":" + ((SDiffEntryAddition *)node2->Data())->sEntry);
358
					lines.pushBack("+++:"; + Utils::String::Number((long)node2->Data()->iID) + ":" + ((SDiffEntryAddition *)node2->Data())->sEntry);
359
					break;
359
					break;
360
				case DIFFTYPE_REMOVAL:
360
				case DIFFTYPE_REMOVAL:
361
					lines.PushBack(CyString("---:";) + (long)node2->Data()->iID);
361
					lines.pushBack(";---:" + Utils::String::Number((long)node2->Data()->iID));
362
					break;
362
					break;
363
				case DIFFTYPE_CHANGE:
363
				case DIFFTYPE_CHANGE:
364
					lines.PushBack(CyString(&quot;///:") + (long)node2->Data()->iID + ";:"; + (long)((SDiffEntryChange *)node2->Data())->iPos + ":" + ((SDiffEntryChange *)node2->Data())->sEntry);
364
					lines.pushBack(&quot;///:" + Utils::String::Number((long)node2->Data()->iID) + ";:"; + Utils::String::Number((long)((SDiffEntryChange *)node2->Data())->iPos) + ":" + ((SDiffEntryChange *)node2->Data())->sEntry);
365
					break;
365
					break;
366
			}
366
			}
367
		}
367
		}
368
	}
368
	}
369
	
369
	
370
 
370
 
371
	CFileIO File(file);
371
	CFileIO File(file);
372
	return File.WriteFile(&lines);
372
	return File.writeFile(&lines);
373
}
373
}
374
 
374
 
375
bool CModDiff::ReadDiff(const Utils::String &file)
375
bool CModDiff::ReadDiff(const Utils::String &file)
376
{
376
{
377
	Clean();
377
	Clean();
Line 448... Line 448...
448
	for ( CListNode<SDiffFile> *node = m_lFiles.Front(); node; node = node->next() )
448
	for ( CListNode<SDiffFile> *node = m_lFiles.Front(); node; node = node->next() )
449
	{
449
	{
450
		// extract the file from the game
450
		// extract the file from the game
451
		SDiffFile *f = node->Data();
451
		SDiffFile *f = node->Data();
452
 
452
 
453
		CyStringList writeLines;
453
		Utils::CStringList writeLines;
454
		int id;
454
		int id;
455
		if ( _readGameFile(f->sFile, &writeLines, &id) )
455
		if ( _readGameFile(f->sFile, writeLines, &id) )
456
		{
456
		{
457
			// now apply the diff
457
			// now apply the diff
458
			this->_adjustFile(f->sFile, f, true);
458
			this->_adjustFile(f->sFile, f, true);
459
			for ( CListNode<SDiffEntry> *eNode = f->m_lEntries.Front(); eNode; eNode = eNode->next() )
459
			for ( CListNode<SDiffEntry> *eNode = f->m_lEntries.Front(); eNode; eNode = eNode->next() )
460
			{
460
			{
461
				switch ( eNode->Data()->iType )
461
				switch ( eNode->Data()->iType )
462
				{
462
				{
463
					case DIFFTYPE_ADDITION:
463
					case DIFFTYPE_ADDITION:
464
						writeLines.PushBack(CyString(((SDiffEntryAddition *)eNode->Data())->sEntry));
464
						writeLines.pushBack(((SDiffEntryAddition *)eNode->Data())->sEntry);
465
						break;
465
						break;
466
					case DIFFTYPE_REMOVAL:
466
					case DIFFTYPE_REMOVAL:
467
						writeLines.GetAt(eNode->Data()->iID)->remove = true;
467
						writeLines.removeAt(eNode->Data()->iID);
468
						break;
468
						break;
469
					case DIFFTYPE_CHANGE:
469
					case DIFFTYPE_CHANGE:
470
						{
470
						{
471
							SStringList *strAt = writeLines.GetAt(eNode->Data()->iID);
471
							auto strAt = writeLines.get(eNode->Data()->iID);
472
							if ( strAt )
472
							if ( strAt )
473
								strAt->str.RepToken(";", ((SDiffEntryChange *)eNode->Data())->iPos, ((SDiffEntryChange *)eNode->Data())->sEntry);
473
								strAt->str = strAt->str.replaceToken(";", ((SDiffEntryChange *)eNode->Data())->iPos, ((SDiffEntryChange *)eNode->Data())->sEntry);
474
						}
474
						}
475
						break;
475
						break;
476
				}
476
				}
477
			}
477
			}
478
 
478
 
479
			// add our comments and info
479
			// add our comments and info
480
			writeLines.PushFront(CyString((long)id) + ";" + (long)writeLines.Count() + ";");
480
			writeLines.pushFront(Utils::String((long)id) + ";" + (long)writeLines.size() + ";");
481
			writeLines.PushFront(CyString("// Generated by ModDiff (SPK Version: ") + CyString::CreateFromFloat(GetLibraryVersion(), 2) + ")");
481
			writeLines.pushFront("// Generated by ModDiff (SPK Version: " + Utils::String::FromFloat(GetLibraryVersion(), 2) + ")");
482
 
482
 
483
			// now write the file
483
			// now write the file
484
			CFileIO WriteFile(m_sTempDir + "/" + CFileIO(f->sFile).filename());
484
			CFileIO WriteFile(m_sTempDir + "/" + CFileIO(f->sFile).filename());
485
			if ( WriteFile.WriteFile(&writeLines) )
485
			if ( WriteFile.writeFile(&writeLines) )
486
			{
486
			{
487
				if ( cat.AppendFile(m_sTempDir + "/" + CFileIO(f->sFile).filename(), f->sFile) )
487
				if ( cat.AppendFile(m_sTempDir + "/" + CFileIO(f->sFile).filename(), f->sFile) )
488
				{
488
				{
489
					ret = true;
489
					ret = true;
490
				}
490
				}
Line 497... Line 497...
497
		cat.WriteCatFile();
497
		cat.WriteCatFile();
498
 
498
 
499
	return ret;
499
	return ret;
500
}
500
}
501
 
501
 
502
bool CModDiff::_readGameFile(const Utils::String &file, CyStringList *writeLines, int *id)
502
bool CModDiff::_readGameFile(const Utils::String &file, Utils::CStringList &writeLines, int *id)
503
{
503
{
504
	bool ret = false;
504
	bool ret = false;
505
 
505
 
506
	Utils::String sTo = m_fileSystem.ExtractGameFile(file, m_sTempDir + "/" + CFileIO(file).filename());
506
	Utils::String sTo = m_fileSystem.ExtractGameFile(file, m_sTempDir + "/" + CFileIO(file).filename());
507
	if ( !sTo.empty() ) {
507
	if ( !sTo.empty() ) {
508
		CFileIO File(sTo);
508
		CFileIO File(sTo);
509
 
509
 
510
		CyStringList *lines = File.ReadLinesStr();
510
		Utils::CStringList *lines = File.readLinesStr();
511
		if ( lines )
511
		if ( lines )
512
		{
512
		{
513
			int entries = -1;
513
			int entries = -1;
514
			for ( SStringList *str = lines->;Head(); str; str = str->next )
514
			for(auto itr = lines->;begin(); itr != lines->end(); itr++)
515
			{
515
			{
516
				CyString l = str->str;
516
				Utils::String l = (*itr)->str;
517
				l.RemoveFirstSpace();
517
				l.removeFirstSpace();
518
				if ( l.Empty() ) continue;
518
				if ( l.empty() ) continue;
519
				if ( l.Left(1) == "/" ) continue;
519
				if ( l.left(1) == "/" ) continue;
520
 
520
 
521
				if ( entries == -1 )
521
				if ( entries == -1 )
522
				{
522
				{
523
					entries = l.GetToken(":", 2, 2).ToInt();
523
					entries = l.token(":", 2).toInt();
524
					if ( id )
524
					if ( id )
525
						(*id) = l.GetToken(":", 1, 1).ToInt();
525
						(*id) = l.token(":", 1).toInt();
526
				}
526
				}
527
				else
527
				else
528
					writeLines->PushBack(l);
528
					writeLines.pushBack(l);
529
			}
529
			}
530
			delete lines;
530
			delete lines;
531
			ret = true;
531
			ret = true;
532
		}
532
		}
533
		File.close();
533
		File.close();