Subversion Repositories spk

Rev

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

Rev 181 Rev 196
Line 51... Line 51...
51
{
51
{
52
	// find the file in the loaded cat
52
	// find the file in the loaded cat
53
	SInCatFile *c = m_pCatFile->findData(sModFile);
53
	SInCatFile *c = m_pCatFile->findData(sModFile);
54
	if ( !c ) c = m_pCatFile->findData(m_sAddon + "/" + sModFile);
54
	if ( !c ) c = m_pCatFile->findData(m_sAddon + "/" + sModFile);
55
	if ( !c ) return false;
55
	if ( !c ) return false;
-
 
56
 
-
 
57
	Utils::WString temp = m_sTempDir.toWString();
56
 
58
 
57
	// extract the matching file
59
	// extract the matching file
58
	Utils::String sToFile = CFileIO(m_sTempDir + "/" + CFileIO(c->sFile).filename()).fullFilename();
60
	Utils::String sToFile = CFileIO(temp + L"/" + CFileIO(c->sFile).filename()).fullFilenameStr();
59
	if ( !m_pCatFile->extractFile(sModFile, sToFile) ) return false;
61
	if ( !m_pCatFile->extractFile(sModFile, sToFile) ) return false;
60
 
62
 
61
	// create a diff
63
	// create a diff
62
	Utils::String to = m_fileSystem.ExtractGameFile(c->sFile, sToFile + ".compare");
64
	Utils::String to = m_fileSystem.ExtractGameFile(c->sFile, sToFile + ".compare");
63
	if ( !to.empty() ) {
65
	if ( !to.empty() ) {
64
		SDiffFile *diff = diffFile(to, sToFile, c->sFile);
66
		SDiffFile *diff = diffFile(to, sToFile, c->sFile);
65
		if ( diff ) { 
67
		if ( diff ) { 
66
			this->_adjustFile(sModFile, diff, false);
68
			this->_adjustFile(sModFile, diff, false);
67
		}
69
		}
68
		CFileIO::Remove(to);
70
		CFileIO::Remove(to);
69
	}
71
	}
70
 
72
 
71
	CFileIO::Remove(sToFile);
73
	CFileIO::Remove(sToFile);
72
 
74
 
73
	return true;
75
	return true;
74
}
76
}
75
 
77
 
76
 
78
 
77
bool CModDiff::_adjustTShips(SDiffFile *pDiff, bool bReverse)
79
bool CModDiff::_adjustTShips(SDiffFile *pDiff, bool bReverse)
78
{
80
{
Line 144... Line 146...
144
				break;
146
				break;
145
		}
147
		}
146
	}
148
	}
147
 
149
 
148
	return true;
150
	return true;
149
}
151
}
150
 
152
 
151
int CModDiff::_specialType(const Utils::String &sFile)
153
int CModDiff::_specialType(const Utils::WString &sFile) const
152
{
154
{
153
	if ( sFile.Compare("TShips") ) return MERGETYPE_TSHIPS;
155
	if ( sFile.Compare(L"TShips") ) return MERGETYPE_TSHIPS;
154
	return MERGETYPE_NONE;
156
	return MERGETYPE_NONE;
155
}
157
}
156
 
158
 
157
void CModDiff::_adjustFile(const Utils::String &sFile, SDiffFile *pDiff, bool bReverse)
159
void CModDiff::_adjustFile(const Utils::String &sFile, SDiffFile *pDiff, bool bReverse)
158
{
160
{
Line 180... Line 182...
180
	int addonSize = addonDir.length() + 1;
182
	int addonSize = addonDir.length() + 1;
181
 
183
 
182
	// try and open the mod file
184
	// try and open the mod file
183
	CCatFile cat;
185
	CCatFile cat;
184
	if ( cat.open(modfile, addonDir, CATREAD_DAT, false) != CATERR_NONE ) { m_iError = MDERR_CANTOPENMOD; return false; }
186
	if ( cat.open(modfile, addonDir, CATREAD_DAT, false) != CATERR_NONE ) { m_iError = MDERR_CANTOPENMOD; return false; }
-
 
187
 
-
 
188
	Utils::WString temp = m_sTempDir.toWString();
185
 
189
 
186
	// we'll need to read in all the types/text files
190
	// we'll need to read in all the types/text files
187
	for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
191
	for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
188
	{
192
	{
189
		SInCatFile *f = cat.GetFile(i);
193
		SInCatFile *f = cat.GetFile(i);
190
		Utils::String checkFile = f->sFile.findReplace("\\", "/");
194
		Utils::String checkFile = f->sFile.findReplace("\\", "/");
191
		if ( (checkFile.left(6).Compare("types/") || checkFile.left(2).Compare("t/") || checkFile.left(6 + addonSize).Compare(addonDir + "/types/") || checkFile.left(2 + addonSize).Compare(addonDir + "/t/")) && _validFile(checkFile) )
195
		if ( (checkFile.left(6).Compare("types/") || checkFile.left(2).Compare("t/") || checkFile.left(6 + addonSize).Compare(addonDir + "/types/") || checkFile.left(2 + addonSize).Compare(addonDir + "/t/")) && _validFile(checkFile) )
192
		{
196
		{
193
			// extract the file to the temp dir
197
			// extract the file to the temp dir
194
			Utils::String toFile = CFileIO(m_sTempDir + "/" + CFileIO(f->sFile).filename()).fullFilename();
198
			Utils::String toFile = CFileIO(temp + L"/" + CFileIO(f->sFile).filename()).fullFilenameStr();
195
			if (cat.extractFile(f, toFile ))
199
			if (cat.extractFile(f, toFile ))
196
			{
200
			{
197
				// now extract the matching file from the game dir
201
				// now extract the matching file from the game dir
198
				if ( m_fileSystem.ExtractGameFile(f->sFile, toFile + ".compare") )
202
				if ( m_fileSystem.ExtractGameFile(f->sFile, toFile + ".compare") )
199
				{
203
				{
Line 440... Line 444...
440
 
444
 
441
	this->ApplyMod(mod);
445
	this->ApplyMod(mod);
442
 
446
 
443
	bool ret = false;
447
	bool ret = false;
444
 
448
 
-
 
449
	Utils::WString temp = m_sTempDir.toWString();
445
	Utils::String addonDir = "";
450
	Utils::String addonDir = "";
446
 
451
 
447
	CCatFile cat;
452
	CCatFile cat;
448
	if ( !CCatFile::Opened(cat.open(mod, addonDir, CATREAD_CATDECRYPT, true)) )
453
	if ( !CCatFile::Opened(cat.open(mod, addonDir, CATREAD_CATDECRYPT, true)) )
449
		return false;
454
		return false;
Line 482... Line 487...
482
			// add our comments and info
487
			// add our comments and info
483
			writeLines.pushFront(Utils::String((long)id) + ";" + (long)writeLines.size() + ";");
488
			writeLines.pushFront(Utils::String((long)id) + ";" + (long)writeLines.size() + ";");
484
			writeLines.pushFront("// Generated by ModDiff (SPK Version: " + Utils::String::FromFloat(GetLibraryVersion(), 2) + ")");
489
			writeLines.pushFront("// Generated by ModDiff (SPK Version: " + Utils::String::FromFloat(GetLibraryVersion(), 2) + ")");
485
 
490
 
486
			// now write the file
491
			// now write the file
487
			CFileIO WriteFile(m_sTempDir + "/" + CFileIO(f->sFile).filename());
492
			CFileIO WriteFile(temp + L"/" + CFileIO(f->sFile).filename());
488
			if ( WriteFile.writeFile(&writeLines) )
493
			if ( WriteFile.writeFile(&writeLines) )
489
			{
494
			{
490
				if ( cat.appendFile(m_sTempDir + "/" + CFileIO(f->sFile).filename(), f->sFile) )
495
				if ( cat.appendFile(m_sTempDir + "/" + CFileIO(f->sFile).filenameStr(), f->sFile) )
491
					ret = true;
496
					ret = true;
492
				WriteFile.remove();
497
				WriteFile.remove();
493
			}
498
			}
494
		}
499
		}
495
	}
500
	}
Line 502... Line 507...
502
 
507
 
503
bool CModDiff::_readGameFile(const Utils::String &file, Utils::CStringList &writeLines, int *id)
508
bool CModDiff::_readGameFile(const Utils::String &file, Utils::CStringList &writeLines, int *id)
504
{
509
{
505
	bool ret = false;
510
	bool ret = false;
506
 
511
 
507
	Utils::String sTo = m_fileSystem.ExtractGameFile(file, m_sTempDir + "/" + CFileIO(file).filename());
512
	Utils::String sTo = m_fileSystem.ExtractGameFile(file, m_sTempDir + "/" + CFileIO(file).filenameStr());
508
	if ( !sTo.empty() ) {
513
	if ( !sTo.empty() ) {
509
		CFileIO File(sTo);
514
		CFileIO File(sTo);
510
 
515
 
511
		Utils::CStringList *lines = File.readLinesStr();
516
		Utils::CStringList *lines = File.readLinesStr();
512
		if ( lines )
517
		if ( lines )
Line 544... Line 549...
544
	return CModDiff::CanBeDiffed(file);
549
	return CModDiff::CanBeDiffed(file);
545
}
550
}
546
 
551
 
547
bool CModDiff::CanBeDiffed(const Utils::String &file)
552
bool CModDiff::CanBeDiffed(const Utils::String &file)
548
{
553
{
549
	Utils::String checkFile = file;
554
	Utils::WString checkFile = file.toWString();
550
	checkFile = CFileIO(file).dir() + "/" + CFileIO(file).baseName();
555
	checkFile = CFileIO(file).dir() + L"/" + CFileIO(file).baseName();
551
 
556
 
552
	// all t files are the same format
557
	// all t files are the same format
553
	if ( checkFile.left(7).Compare("types/T") )
558
	if ( checkFile.left(7).Compare(L"types/T") )
554
		return true;
559
		return true;
555
 
560
 
556
	return false;
561
	return false;
557
}
562
}