Subversion Repositories spk

Rev

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

Rev 41 Rev 43
Line 267... Line 267...
267
	if ( filename.IsIn("-L") || filename.IsIn("-l") )
267
	if ( filename.IsIn("-L") || filename.IsIn("-l") )
268
		textid = filename.GetToken("-", 1, 1);
268
		textid = filename.GetToken("-", 1, 1);
269
	else
269
	else
270
		textid = filename.GetToken(".", -1).Right(4);
270
		textid = filename.GetToken(".", -1).Right(4);
271
 
271
 
272
	return textid.ToInt();
272
	if ( textid.IsNumber() ) return textid.ToInt();
-
 
273
	return -1;
273
}
274
}
274
bool C_File::IsAutoTextFile ()
275
bool C_File::IsAutoTextFile ()
275
{
276
{
276
	int textid = GetTextFileID();
277
	int textid = GetTextFileID();
277
	if ( textid == -1 ) return false;
278
	if ( textid == -1 ) return false;
278
 
279
 
279
	if ( textid <= 3 )
280
	if ( textid <= 3 )
280
		return true;
281
		return true;
281
 
282
 
282
	// check for original name
283
	// check for original name
283
	if ( !m_sOriginalName.Empty() )
284
	if ( !m_sOriginalName.Empty() )
284
	{
285
	{
285
		textid = GetTextFileID(m_sOriginalName);
286
		textid = GetTextFileID(m_sOriginalName);
286
		if ( textid >= 0 && textid <= 3 )
287
		if ( textid >= 0 && textid <= 3 )
287
			return true;
288
			return true;
288
	}
289
	}
289
 
290
 
290
	return false;
291
	return false;
291
}
292
}
292
 
293
 
293
bool C_File::IsFakePatch ()
294
bool C_File::IsFakePatch ()
294
{
295
{
295
	if ( m_iFileType != FILETYPE_MOD )
296
	if ( m_iFileType != FILETYPE_MOD )
296
		return false;
297
		return false;
297
 
298
 
298
	if ( m_sName.GetToken ( 1, '.' ).ToInt() )
299
	if ( m_sName.GetToken ( 1, '.' ).ToInt() )
299
		return true;
300
		return true;
Line 373... Line 374...
373
	{
374
	{
374
		m_iLastError = SPKERR_FILEREAD;
375
		m_iLastError = SPKERR_FILEREAD;
375
		DeleteData ();
376
		DeleteData ();
376
		m_lDataSize = 0;
377
		m_lDataSize = 0;
377
		fclose ( id );
378
		fclose ( id );
378
		return false;
379
		return false;
379
	}
380
	}
380
 
381
 
381
	m_iLastError = SPKERR_NONE;
382
	m_iLastError = SPKERR_NONE;
382
 
383
 
383
	struct stat fileStat;
384
	struct stat fileStat;
384
	if ( !stat(GetFilePointer().c_str(), &fileStat) )
385
	if ( !stat(GetFilePointer().c_str(), &fileStat) )
385
		m_tTime = fileStat.st_atime;
386
		m_tTime = fileStat.st_atime;
386
 
387
 
387
	m_bLoaded = true;
388
	m_bLoaded = true;
Line 443... Line 444...
443
	}
444
	}
444
 
445
 
445
	return true;
446
	return true;
446
}
447
}
447
 
448
 
-
 
449
 
-
 
450
void C_File::copyData(const unsigned char *data, size_t size)
-
 
451
{
-
 
452
	m_lDataSize = (long)size;
-
 
453
	delete m_sData;
-
 
454
	m_sData = new unsigned char[size];
-
 
455
	memcpy(m_sData, data, size);
-
 
456
}
448
 
457
 
449
 
458
 
450
/*
459
/*
451
	Func:	GetFilePointer
460
	Func:	GetFilePointer
452
	Desc:	Returns the file pointer name
461
	Desc:	Returns the file pointer name
Line 600... Line 609...
600
 
609
 
601
			fseek(id, 0, SEEK_END);
610
			fseek(id, 0, SEEK_END);
602
			int endPos = ftell(id);
611
			int endPos = ftell(id);
603
 
612
 
604
			int pos = endPos;
613
			int pos = endPos;
-
 
614
			int attempts = 100;
605
			// move to end of the file
615
			// move to end of the file
606
			while ( true )
616
			while ( true )
607
			{
617
			{
608
				// read blocks of 20 backwards
618
				// read blocks of 20 backwards
609
				pos -= 20;
619
				pos -= 20;
Line 617... Line 627...
617
				// find code array
627
				// find code array
618
				if ( sRead.FindPos("codearray") != -1 )
628
				if ( sRead.FindPos("codearray") != -1 )
619
					break;
629
					break;
620
				if ( pos <= 2 )
630
				if ( pos <= 2 )
621
					break;
631
					break;
-
 
632
				--attempts;
-
 
633
				if ( attempts <= 0 ) break;
622
			}
634
			}
623
 
635
 
624
			fclose(id);
636
			fclose(id);
625
 
637
 
626
			// now check the find read
638
			// now check the find read
Line 631... Line 643...
631
 
643
 
632
	return false;
644
	return false;
633
}
645
}
634
 
646
 
635
int C_File::ReadScriptVersion ()
647
int C_File::ReadScriptVersion ()
636
{
648
{
637
	if ( (m_iFileType != FILETYPE_SCRIPT) && (m_iFileType != FILETYPE_UNINSTALL) )
649
	if ( (m_iFileType != FILETYPE_SCRIPT) && (m_iFileType != FILETYPE_UNINSTALL) )
638
		return 0;
650
		return 0;
639
 
651
 
640
	// check file pointer
652
	// check file pointer
641
	CyString file = GetFilePointer();
653
	CyString file = GetFilePointer();
Line 1177... Line 1189...
1177
			ret = false;
1189
			ret = false;
1178
 
1190
 
1179
		fclose ( id );
1191
		fclose ( id );
1180
 
1192
 
1181
		return ret;
1193
		return ret;
1182
	}
1194
	}
1183
 
1195
 
1184
	return false;
1196
	return false;
1185
}
1197
}
1186
 
1198
 
1187
CyString C_File::GetFullFileToDir ( CyString dir, bool includedir, CBaseFile *file )
1199
CyString C_File::GetFullFileToDir ( CyString dir, bool includedir, CBaseFile *file )
1188
{
1200
{
1189
	CyString fullfile = dir;
1201
	CyString fullfile = dir;
1190
	if ( includedir )
1202
	if ( includedir )
1191
	{
1203
	{
1192
		CyString d = GetDirectory ( file );
1204
		CyString d = GetDirectory ( file );
1193
		if ( !d.Empty() )
1205
		if ( !d.Empty() )
1194
		{
1206
		{
1195
			if ( !fullfile.Empty() )
1207
			if ( !fullfile.Empty() )
1196
				fullfile += "/";
1208
				fullfile += "/";
Line 1200... Line 1212...
1200
	if ( !m_sName.Empty() )
1212
	if ( !m_sName.Empty() )
1201
	{
1213
	{
1202
		if ( !fullfile.Empty() )
1214
		if ( !fullfile.Empty() )
1203
			fullfile += "/";
1215
			fullfile += "/";
1204
		fullfile += m_sName;
1216
		fullfile += m_sName;
1205
	}
1217
	}
1206
 
1218
 
1207
	fullfile = fullfile.FindReplace ( "\\", "/" );
1219
	fullfile = fullfile.FindReplace ( "\\", "/" );
1208
	return fullfile;
1220
	return fullfile;
1209
}
1221
}
1210
 
1222
 
1211
bool C_File::WriteToDir ( CyString &dir, CBaseFile *spkfile, bool includedir, CyString appendDir, unsigned char *data, long len )
1223
bool C_File::WriteToDir ( CyString &dir, CBaseFile *spkfile, bool includedir, CyString appendDir, unsigned char *data, long len )
1212
{
1224
{
1213
	CyString fullfile = GetFullFileToDir ( dir, includedir, spkfile );
1225
	CyString fullfile = GetFullFileToDir ( dir, includedir, spkfile );
1214
 
1226
 
1215
	if ( !appendDir.Empty() )
1227
	if ( !appendDir.Empty() )
1216
	{
1228
	{
1217
		if ( !fullfile.Empty() )
1229
		if ( !fullfile.Empty() )
1218
			fullfile += "/";
1230
			fullfile += "/";
1219
		fullfile += appendDir;
1231
		fullfile += appendDir;
1220
	}
1232
	}
1221
 
1233
 
1222
	CyString fulldir = fullfile.GetToken ( 1, fullfile.NumToken('/') - 2, '/' );
1234
	CyString fulldir = fullfile.GetToken ( 1, fullfile.NumToken('/') - 2, '/' );
1223
	if ( !fulldir.Empty() )
1235
	if ( !fulldir.Empty() )
1224
	{
1236
	{
1225
		if ( !CDirIO(fulldir).Create() )
1237
		if ( !CDirIO(fulldir).Create() )
1226
			return false;
1238
			return false;
1227
	}
1239
	}
1228
 
1240
 
1229
	return WriteToFile ( fullfile, data, len );
1241
	return WriteToFile ( fullfile, data, len );
1230
}
1242
}
1231
 
1243
 
1232
CyString C_File::GetDataSizeString ()
1244
CyString C_File::GetDataSizeString ()
1233
{
1245
{
Line 1268... Line 1280...
1268
			return false;
1280
			return false;
1269
	}
1281
	}
1270
 
1282
 
1271
	// now check for last modified time
1283
	// now check for last modified time
1272
	if ( (m_tTime) && (file->GetLastModified()) )
1284
	if ( (m_tTime) && (file->GetLastModified()) )
1273
	{
1285
	{
1274
		if ( m_tTime > file->GetLastModified() )
1286
		if ( m_tTime > file->GetLastModified() )
1275
			return false;
1287
			return false;
1276
	}
1288
	}
1277
 
1289
 
1278
	// assume same or newer
1290
	// assume same or newer
Line 1314... Line 1326...
1314
		case FILETYPE_SHIPSCENE:
1326
		case FILETYPE_SHIPSCENE:
1315
			return "ShipScene";
1327
			return "ShipScene";
1316
		case FILETYPE_COCKPITSCENE:
1328
		case FILETYPE_COCKPITSCENE:
1317
			return "CockpitScene";
1329
			return "CockpitScene";
1318
	}
1330
	}
1319
 
1331
 
1320
	return NullString;
1332
	return NullString;
1321
}
1333
}
1322
 
1334
 
1323
int GetFileTypeFromString ( CyString type )
1335
int GetFileTypeFromString ( CyString type )
1324
{
1336
{
Line 1359... Line 1371...
1359
	return -1;
1371
	return -1;
1360
}
1372
}
1361
 
1373
 
1362
 
1374
 
1363
CyString FormatErrorString(int error, CyString rest)
1375
CyString FormatErrorString(int error, CyString rest)
1364
{
1376
{
1365
	int max = 0;
1377
	int max = 0;
1366
	CyString *args = 0;
1378
	CyString *args = 0;
1367
 
1379
 
1368
	if ( !rest.Empty() )
1380
	if ( !rest.Empty() )
1369
		args = rest.SplitToken('~', &max);
1381
		args = rest.SplitToken('~', &max);
Line 1722... Line 1734...
1722
		return false;
1734
		return false;
1723
	}
1735
	}
1724
 
1736
 
1725
	// work backwards
1737
	// work backwards
1726
	int pos = size - 1;
1738
	int pos = size - 1;
1727
 
-
 
-
 
1739
	int max = size - 5000;
-
 
1740
	if ( max < 0 ) max = 0;
1728
	// find the first tage
1741
	// find the first tage
1729
	while ( pos > 0 )
1742
	while ( pos > max )
1730
	{
1743
	{
1731
		while ( data[pos] != '>' && pos > 0 )
1744
		while ( data[pos] != '>' && pos > 0 )
1732
			pos--;
1745
			pos--;
1733
 
1746
 
1734
		char tag[100];
1747
		char tag[10000];
1735
		bool checked = false;
1748
		bool checked = false;
1736
		if ( data[pos] == '>' )
1749
		if ( data[pos] == '>' )
1737
		{
1750
		{
1738
			int pos2 = pos - 1;
1751
			int pos2 = pos - 1;
1739
			// now find the front
1752
			// now find the front
1740
			while ( data[pos2] != '<' && pos2 > 0 )
1753
			while ( data[pos2] != '<' && pos2 > max )
1741
				pos2--;
1754
				pos2--;
1742
 
1755
 
1743
			// now get the tag
1756
			// now get the tag
1744
			if ( data[pos2] == '<' )
1757
			if ( data[pos2] == '<' )
1745
			{
1758
			{