Subversion Repositories spk

Rev

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

Rev 160 Rev 173
Line 79... Line 79...
79
	// need to read TCockpits
79
	// need to read TCockpits
80
	Utils::String sTo = this->_extractFile("types/TCockpits.pck", "TCockpits.xml");
80
	Utils::String sTo = this->_extractFile("types/TCockpits.pck", "TCockpits.xml");
81
	if ( sTo.empty() ) return false;
81
	if ( sTo.empty() ) return false;
82
	CFileIO TCockpits("TCockpits.xml");
82
	CFileIO TCockpits("TCockpits.xml");
83
	if ( !TCockpits.exists() ) return false;
83
	if ( !TCockpits.exists() ) return false;
-
 
84
	std::vector<Utils::String> lines;
84
	CyStringList *pFiles = TCockpits.ReadLinesStr();
85
	if (!TCockpits.readLines(lines))
85
	if ( !pFiles ) return false;
86
		return false;
86
 
87
 
87
	// remove all the comments
88
	// remove all the comments
-
 
89
	auto itr = lines.begin();
88
	for ( SStringList *str = pFiles->Head(); str; str = str->next ) {
90
	while(itr != lines.end())
-
 
91
	{
89
		if ( str->str[0] == '/&apos; ) str->remove = true;
92
		if ((*itr)[0] == '/&apos;)
-
 
93
			itr = lines.erase(itr);
-
 
94
		else
-
 
95
			itr++;
90
	}
96
	}
91
	pFiles->RemoveMarked();
97
	lines.erase(lines.begin());
92
	pFiles->PopFront();
-
 
93
 
98
 
94
	std::map<Utils::String, int> fileSet;
99
	std::map<Utils::String, int> fileSet;
95
	int iPos = 0;
100
	int iPos = 0;
96
	for ( SStringList *str = pFiles->Head(); str; str = str->next ) fileSet[Utils::String(str->str.ToString()).token(";;", -2)] = iPos++;
101
	for(itr = lines.begin(); itr != lines.end(); itr++)
-
 
102
		fileSet[itr->token(";", -2)] = iPos++;
97
 
103
 
98
	// now cycle through ships and adjust the cockpits
104
	// now cycle through ships and adjust the cockpits
99
	int iCount = -1;
105
	int iCount = -1;
100
	for ( SDiffEntry *pEntry = pDiff->m_lEntries.First(); pEntry; pEntry = pDiff->m_lEntries.Next() ) {
106
	for ( SDiffEntry *pEntry = pDiff->m_lEntries.First(); pEntry; pEntry = pDiff->m_lEntries.Next() ) {
101
		switch (pEntry->iType) {
107
		switch (pEntry->iType) {
Line 103... Line 109...
103
				{
109
				{
104
					SDiffEntryAddition *pAddition = static_cast<SDiffEntryAddition *>(pEntry);
110
					SDiffEntryAddition *pAddition = static_cast<SDiffEntryAddition *>(pEntry);
105
					if ( pAddition ) {
111
					if ( pAddition ) {
106
						for ( int t = 0; t < 6; t++ ) {
112
						for ( int t = 0; t < 6; t++ ) {
107
							Utils::String sE = pAddition->sEntry.token(";", 32 + (t * 2));
113
							Utils::String sE = pAddition->sEntry.token(";", 32 + (t * 2));
108
							if ( !bReverse && sE.isNumber() ) {
114
							if ( !bReverse && sE.isNumber() )
-
 
115
							{
109
								int iTurret = sE;
116
								int iTurret = sE;
110
								if ( iTurret && iTurret < pFiles->Count() ) {
117
								if ( iTurret && static_cast<size_t>(iTurret) < lines.size()) 
-
 
118
								{
111
									Utils::String sCockpit = pFiles->GetAt(iTurret)->str.ToString();
119
									Utils::String sCockpit = lines[iTurret];
112
									pAddition->sEntry = pAddition->sEntry.replaceToken(";", 32 + (t * 2), sCockpit.token(";", -2) + ":" + static_cast<long>(iTurret));
120
									pAddition->sEntry = pAddition->sEntry.replaceToken(";", 32 + (t * 2), sCockpit.token(";", -2) + ":" + static_cast<long>(iTurret));
113
								}
121
								}
114
							}
122
							}
115
							else if ( bReverse && !sE.isNumber() ) {
123
							else if ( bReverse && !sE.isNumber() ) {
116
								int iUnfound = 0;
124
								int iUnfound = 0;
Line 127... Line 135...
127
				break;
135
				break;
128
			case DIFFTYPE_CHANGE:
136
			case DIFFTYPE_CHANGE:
129
				{
137
				{
130
					SDiffEntryChange *pChange = static_cast<SDiffEntryChange *>(pEntry);
138
					SDiffEntryChange *pChange = static_cast<SDiffEntryChange *>(pEntry);
131
					if ( pChange->iPos >= 32 && pChange->iPos <= 42 && (pChange->iPos % 2) && pChange->sEntry.isNumber() ) {
139
					if ( pChange->iPos >= 32 && pChange->iPos <= 42 && (pChange->iPos % 2) && pChange->sEntry.isNumber() ) {
132
						Utils::String sCockpit = pFiles->GetAt(pChange->sEntry)->str.ToString();
140
						Utils::String sCockpit = lines[pChange->sEntry.toInt()];
133
						pChange->sEntry = sCockpit.token(";", -2) + ":" + pChange->sEntry;
141
						pChange->sEntry = sCockpit.token(";", -2) + ":" + pChange->sEntry;
134
					}
142
					}
135
				}
143
				}
136
				break;
144
				break;
137
		}
145
		}
138
	}
146
	}
139
 
-
 
140
	delete pFiles;
-
 
141
 
147
 
142
	return true;
148
	return true;
143
}
149
}
144
 
150
 
145
int CModDiff::_specialType(const Utils::String &sFile)
151
int CModDiff::_specialType(const Utils::String &sFile)
Line 194... Line 200...
194
					diffFile(toFile + ".compare", toFile, f->sFile);
200
					diffFile(toFile + ".compare", toFile, f->sFile);
195
					CFileIO::Remove(toFile + ".compare");
201
					CFileIO::Remove(toFile + ".compare");
196
				}
202
				}
197
				// make sure we clear up afterwards
203
				// make sure we clear up afterwards
198
				CFileIO::Remove(toFile);
204
				CFileIO::Remove(toFile);
199
			}
205
			}
200
		}
206
		}
201
	}
207
	}
202
 
208
 
203
	return true;
209
	return true;
204
}
210
}
205
 
211
 
206
SDiffFile *CModDiff::diffFile(const Utils::String &baseFile, const Utils::String &modFile, const Utils::String &fileType)
212
SDiffFile *CModDiff::diffFile(const Utils::String &baseFile, const Utils::String &modFile, const Utils::String &fileType)
207
{
213
{
208
	int type = 0;
214
	int type = 0;
209
 
215
 
210
	SDiffFile *diffFile = new SDiffFile;
216
	SDiffFile *diffFile = new SDiffFile;
211
	diffFile->sFile = fileType;
217
	diffFile->sFile = fileType;
212
 
218
 
213
	// read both files and compare them
219
	// read both files and compare them
214
	CFileIO Base(baseFile);
220
	CFileIO Base(baseFile);
215
	CyStringList *baseLines = Base.ReadLinesStr();
221
	std::vector<Utils::String> baseLines;
216
	if ( baseLines )
222
	if(Base.readLines(baseLines))
217
	{
223
	{
218
		CFileIO Mod(modFile);
224
		CFileIO Mod(modFile);
219
		CyStringList *lines = Mod.ReadLinesStr();
225
		std::vector<Utils::String> lines;
220
		if ( lines )
226
		if(Mod.readLines(lines))
221
		{
227
		{
222
			int id = -1;
228
			int id = -1;
223
			SStringList *node[2];
229
			std::vector<Utils::String>::iterator node[2];
224
			node[0] = baseLines->Head();
230
			node[0] = baseLines.begin();
225
			node[1] = lines->Head();
231
			node[1] = lines.begin();
-
 
232
			std::vector<Utils::String>::iterator endNode[2];
-
 
233
			endNode[0] = baseLines.end();
-
 
234
			endNode[1] = lines.end();
226
 
235
 
227
			Utils::String prev[2];
236
			Utils::String prev[2];
228
 
237
 
229
			while ( node[0] || node[1] )
238
			while (node[0] != endNode[0] || node[1] != endNode[1])
230
			{
239
			{
231
				Utils::String str[2];
240
				Utils::String str[2];
232
 
241
 
233
				for ( int i = 0; i < 2; i++ )
242
				for ( int i = 0; i < 2; i++ )
234
				{
243
				{
235
					while (node[i])
244
					while (node[i] != endNode[i])
236
					{
245
					{
237
						Utils::String l = node[i]->str.ToString();
246
						Utils::String l = *node[i];
238
						node[i] = node[i]->next;
247
						node[i]++;
239
 
248
 
240
						l.removeFirstSpace();
249
						l.removeFirstSpace();
241
						l.removeChar('\r');
250
						l.removeChar('\r');
242
						if ( !l.empty() && l.left(1) != "/") {
251
						if ( !l.empty() && l.left(1) != "/") {
243
							str[i] += l;
252
							str[i] += l;
Line 248... Line 257...
248
				}
257
				}
249
 
258
 
250
				if ( id == -1 )
259
				if ( id == -1 )
251
					id = 0;
260
					id = 0;
252
				else
261
				else
253
				{
262
				{
254
					// first check for mismatch amount, one of the nodes will be empty
263
					// first check for mismatch amount, one of the nodes will be empty
255
					if ( str[0].empty() && !str[1].empty() ) // mod file has more entries (these must be additions)
264
					if ( str[0].empty() && !str[1].empty() ) // mod file has more entries (these must be additions)
256
					{
265
					{
257
						SDiffEntryAddition *entry = new SDiffEntryAddition;
266
						SDiffEntryAddition *entry = new SDiffEntryAddition;
258
						entry->iID = id;
267
						entry->iID = id;
259
						entry->sEntry = str[1];
268
						entry->sEntry = str[1];
260
						diffFile->m_lEntries.push_back(entry);
269
						diffFile->m_lEntries.push_back(entry);
261
					}
270
					}
262
					else if ( str[1].empty() && !str[0].empty() ) // mod file has less entries (must have removed some)
271
					else if ( str[1].empty() && !str[0].empty() ) // mod file has less entries (must have removed some)
263
					{
272
					{
264
						SDiffEntry *entry = new SDiffEntryRemoval;
273
						SDiffEntry *entry = new SDiffEntryRemoval;
265
						entry->iID = id;
274
						entry->iID = id;
266
						diffFile->m_lEntries.push_back(entry);
275
						diffFile->m_lEntries.push_back(entry);
Line 273... Line 282...
273
					}
282
					}
274
 
283
 
275
					++id;
284
					++id;
276
				}
285
				}
277
			}
286
			}
278
 
-
 
279
			delete lines;
-
 
280
		}
287
		}
281
		delete baseLines;
-
 
282
	}
288
	}
283
 
289
 
284
	if ( diffFile->m_lEntries.empty() ) {
290
	if ( diffFile->m_lEntries.empty() ) {
285
		delete diffFile;
291
		delete diffFile;
286
		return NULL;
292
		return NULL;
287
	}
293
	}
288
	else {
294
	else {
289
		m_lFiles.push_back(diffFile);
295
		m_lFiles.push_back(diffFile);
290
		return diffFile;
296
		return diffFile;
291
	}
297
	}
292
}
298
}
293
 
299
 
294
int CModDiff::_amountPosition(const Utils::String &fileType)
300
int CModDiff::_amountPosition(const Utils::String &fileType)
295
{
301
{
296
	return 2;
302
	return 2;
297
}
303
}
298
 
304
 
Line 361... Line 367...
361
					lines.pushBack("---:" + Utils::String::Number((long)node2->Data()->iID));
367
					lines.pushBack("---:" + Utils::String::Number((long)node2->Data()->iID));
362
					break;
368
					break;
363
				case DIFFTYPE_CHANGE:
369
				case DIFFTYPE_CHANGE:
364
					lines.pushBack("///:" + Utils::String::Number((long)node2->Data()->iID) + ":" + Utils::String::Number((long)((SDiffEntryChange *)node2->Data())->iPos) + ":" + ((SDiffEntryChange *)node2->Data())->sEntry);
370
					lines.pushBack("///:" + Utils::String::Number((long)node2->Data()->iID) + ":" + Utils::String::Number((long)((SDiffEntryChange *)node2->Data())->iPos) + ":" + ((SDiffEntryChange *)node2->Data())->sEntry);
365
					break;
371
					break;
366
			}
372
			}
367
		}
373
		}
368
	}
374
	}
369
	
375
	
370
 
376
 
371
	CFileIO File(file);
377
	CFileIO File(file);
372
	return File.writeFile(&lines);
378
	return File.writeFile(&lines);
Line 376... Line 382...
376
{
382
{
377
	Clean();
383
	Clean();
378
 
384
 
379
	CFileIO File(file);
385
	CFileIO File(file);
380
	if ( !File.exists() ) return false;
386
	if ( !File.exists() ) return false;
381
 
387
 
382
	CyStringList *lines = File.ReadLinesStr();
388
	std::vector<Utils::String> lines;
383
 
-
 
384
	if ( lines )
389
	if(File.readLines(lines))
385
	{
390
	{
386
		SDiffFile *diffFile = NULL;
391
		SDiffFile *diffFile = NULL;
387
		for ( SStringList *str = lines->Head(); str; str = str->;next )
392
		for(auto itr = lines.begin(); itr != lines.end(); itr++)
388
		{
393
		{
389
			if ( str->str.Left(2).Compare("$$") )
394
			if (itr->left(2).Compare("$$") )
390
			{
395
			{
391
				diffFile = new SDiffFile;
396
				diffFile = new SDiffFile;
392
				m_lFiles.push_back(diffFile);
397
				m_lFiles.push_back(diffFile);
393
				diffFile->sFile = str->str.Right(-2).ToString();
398
				diffFile->sFile = itr->right(-2);
394
			}
399
			}
395
			else if ( diffFile )
400
			else if ( diffFile )
396
			{
401
			{
397
				if ( str->str.Left(4).Compare("+++:") )
402
				if ( itr->left(4).Compare("+++:") )
398
				{
403
				{
399
					SDiffEntryAddition *addition = new SDiffEntryAddition;
404
					SDiffEntryAddition *addition = new SDiffEntryAddition;
400
					addition->iID = str->str.GetToken(":", 2, 2).ToInt();
405
					addition->iID = itr->token(":", 2).toInt();
401
					addition->sEntry = str->str.GetToken(":", 3).ToString();
406
					addition->sEntry = itr->tokens(":", 3);
402
					diffFile->m_lEntries.push_back(addition);
407
					diffFile->m_lEntries.push_back(addition);
403
				}
408
				}
404
				else if ( str->str.Left(4).Compare("---:") )
409
				else if ( itr->left(4).Compare("---:") )
405
				{
410
				{
406
					SDiffEntryRemoval *entry = new SDiffEntryRemoval;
411
					SDiffEntryRemoval *entry = new SDiffEntryRemoval;
407
					entry->iID = str->str.GetToken(":", 2, 2).ToInt();
412
					entry->iID = itr->token(":", 2).toInt();
408
					diffFile->m_lEntries.push_back(entry);
413
					diffFile->m_lEntries.push_back(entry);
409
				}
414
				}
410
				else if ( str->str.Left(4).Compare("///:") )
415
				else if (itr->left(4).Compare("///:") )
411
				{
416
				{
412
					SDiffEntryChange *entry = new SDiffEntryChange;
417
					SDiffEntryChange *entry = new SDiffEntryChange;
413
					entry->iID = str->str.GetToken(":", 2, 2).ToInt();
418
					entry->iID = itr->token(":", 2).toInt();
414
					entry->iPos = str->str.GetToken(":", 3, 3).ToInt();
419
					entry->iPos = itr->token(":", 3).toInt();
415
					entry->sEntry = str->str.GetToken(":", 4).ToString();
420
					entry->sEntry = itr->tokens(":", 4);
416
					diffFile->m_lEntries.push_back(entry);
421
					diffFile->m_lEntries.push_back(entry);
417
				}
422
				}
418
			}
423
			}
419
		}
424
		}
420
 
-
 
421
		delete lines;
-
 
422
 
425
 
423
		return true;
426
		return true;
424
	}
427
	}
425
 
428
 
426
	return false;
429
	return false;