Subversion Repositories spk

Rev

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

Rev 129 Rev 130
Line 135... Line 135...
135
{
135
{
136
	m_bDontDeleteData = false;
136
	m_bDontDeleteData = false;
137
	m_bUsedMalloc = false;
137
	m_bUsedMalloc = false;
138
	m_sData = NULL;
138
	m_sData = NULL;
139
	Reset ();
139
	Reset ();
140
	SetFilename(filename);
140
	setFilename(filename);
141
}
141
}
142
 
142
 
143
C_File::~C_File()
143
C_File::~C_File()
144
{
144
{
145
	DeleteData ();
145
	DeleteData ();
Line 153... Line 153...
153
	Return: Directory String
153
	Return: Directory String
154
	Desc:	Returns the directory the file goes into, based on m_sDir and Filetype
154
	Desc:	Returns the directory the file goes into, based on m_sDir and Filetype
155
*/
155
*/
156
CyString C_File::GetDirectory ( CBaseFile *file )
156
CyString C_File::GetDirectory ( CBaseFile *file )
157
{
157
{
158
	if ( IsFakePatch() )
-
 
159
		return "";
-
 
160
 
-
 
161
	if ( (m_iFileType == FILETYPE_MOD) && (m_sDir == "Patch") )
-
 
162
		return "PluginManager/Patch";
-
 
163
 
-
 
164
	if ( (!m_sDir.Empty()) && (m_iFileType != FILETYPE_README) && m_sDir != "." )
-
 
165
	{
-
 
166
		CyString dir = m_sDir.FindReplace ( "\\", "/" );
-
 
167
		if ( file )
-
 
168
		{
-
 
169
			dir = dir.FindReplace ( "$scriptname", file->GetNameValidFile() );
-
 
170
			dir = dir.FindReplace ( "$scriptauthor", CyString(file->author()) );
-
 
171
		}
-
 
172
		return dir;
-
 
173
	}
-
 
174
 
-
 
175
	switch ( m_iFileType )
-
 
176
	{
-
 
177
		case FILETYPE_SCRIPT:
-
 
178
			return "Scripts";
-
 
179
		case FILETYPE_TEXT:
-
 
180
			return "T";
-
 
181
		case FILETYPE_README:
-
 
182
		{
-
 
183
			if ( file )
-
 
184
				return CyString("PluginManager/Readme/") + file->GetNameValidFile();
-
 
185
			return "PluginManager/Readme";
-
 
186
		}
-
 
187
		case FILETYPE_MAP:
-
 
188
			return "Maps";
-
 
189
		case FILETYPE_MOD:
-
 
190
//			if ( (file) && (file->IsPatch()) )
-
 
191
//				return "Mods/Patch";
-
 
192
			return "Mods";
-
 
193
		case FILETYPE_UNINSTALL:
-
 
194
			return "PluginManager/Uninstall";
-
 
195
		case FILETYPE_SOUND:
-
 
196
			if ( CFileIO(m_sName).CheckFileExtension("wav") )
-
 
197
				return "s";
-
 
198
			return "Soundtrack";
-
 
199
		case FILETYPE_EXTRA:
-
 
200
			return "PluginManager/Extras";
-
 
201
		case FILETYPE_SCREEN:
-
 
202
			return "loadscr";
-
 
203
		case FILETYPE_ADVERT:
-
 
204
			return "PluginManager/Graphics";
-
 
205
		case FILETYPE_MISSION:
-
 
206
			return "Director";
158
	return getDirectory(file);
207
	}
-
 
208
	return NullString;
-
 
209
}
159
}
210
 
160
 
211
Utils::String C_File::getDirectory(CBaseFile *file) const
161
Utils::String C_File::getDirectory(CBaseFile *file) const
212
{
162
{
213
	if (IsFakePatch())
163
	if (IsFakePatch())
Line 227... Line 177...
227
			dir = dir.findReplace("$scriptauthor", file->author());
177
			dir = dir.findReplace("$scriptauthor", file->author());
228
		}
178
		}
229
		return dir;
179
		return dir;
230
	}
180
	}
231
 
181
 
232
	return GetDirectory(m_iFileType, m_sName.ToString(), file);
182
	return C_File::GetDirectory(m_iFileType, _sName, file);
233
}
183
}
234
 
184
 
235
CyString C_File::GetNameDirectory(CBaseFile *file)
185
CyString C_File::GetNameDirectory(CBaseFile *file)
236
{
186
{
237
	CyString dir = GetDirectory(file);
187
	return getNameDirectory(file);
238
	if (!dir.Empty())
-
 
239
		dir += "/";
-
 
240
	return CyString(dir + m_sName).FindReplace("\\", "/").FindReplace("//", "/");
-
 
241
}
188
}
242
 
189
 
243
Utils::String C_File::getNameDirectory(CBaseFile *file) const
190
Utils::String C_File::getNameDirectory(CBaseFile *file) const
244
{
191
{
245
	Utils::String dir = getDirectory(file);
192
	Utils::String dir = getDirectory(file);
246
	if (!dir.empty())
193
	if (!dir.empty())
247
		dir += "/";
194
		dir += "/";
248
	return (dir + m_sName.ToString()).findReplace("\\", "/").findReplace("//", "/");
195
	return (dir + _sName).findReplace("\\", "/").findReplace("//", "/");
249
}
196
}
250
 
197
 
251
/*
198
/*
252
	Func:	Reset()
199
	Func:	Reset()
253
	Desc:	Resets the file data, clears all data inside
200
	Desc:	Resets the file data, clears all data inside
Line 285... Line 232...
285
		case FILETYPE_SCREEN:
232
		case FILETYPE_SCREEN:
286
		case FILETYPE_ADVERT:
233
		case FILETYPE_ADVERT:
287
		case FILETYPE_SOUND:
234
		case FILETYPE_SOUND:
288
		case FILETYPE_BACKUP:
235
		case FILETYPE_BACKUP:
289
			m_bSigned = true;
236
			m_bSigned = true;
290
			break;
237
			break;
291
 
238
 
292
		// mods, maps are always not signed
239
		// mods, maps are always not signed
293
		case FILETYPE_MOD:
240
		case FILETYPE_MOD:
294
		case FILETYPE_MAP:
241
		case FILETYPE_MAP:
295
		case FILETYPE_SHIPOTHER:
242
		case FILETYPE_SHIPOTHER:
296
		case FILETYPE_SHIPMODEL:
243
		case FILETYPE_SHIPMODEL:
297
		case FILETYPE_SHIPSCENE:
244
		case FILETYPE_SHIPSCENE:
298
		case FILETYPE_COCKPITSCENE:
245
		case FILETYPE_COCKPITSCENE:
299
			m_bSigned = false;
246
			m_bSigned = false;
300
			break;
247
			break;
301
 
248
 
302
		// extra files are a special case
249
		// extra files are a special case
303
		case FILETYPE_EXTRA:
250
		case FILETYPE_EXTRA:
304
			if ( this->GetDir().Left(6).Compare("extras") )
251
			if ( this->GetDir().Left(6).Compare("extras") )
305
				m_bSigned = true;
252
				m_bSigned = true;
306
			else
253
			else
Line 309... Line 256...
309
 
256
 
310
		// script files need to check
257
		// script files need to check
311
		case FILETYPE_SCRIPT:
258
		case FILETYPE_SCRIPT:
312
		case FILETYPE_UNINSTALL:
259
		case FILETYPE_UNINSTALL:
313
			m_bSigned = this->ReadSignedFile();
260
			m_bSigned = this->ReadSignedFile();
314
			break;
261
			break;
315
 
262
 
316
		// mission files
263
		// mission files
317
		case FILETYPE_MISSION:
264
		case FILETYPE_MISSION:
318
			m_bSigned = false;
265
			m_bSigned = false;
319
			break;
266
			break;
320
	}
267
	}
Line 347... Line 294...
347
{
294
{
348
	if ( m_iFileType != FILETYPE_TEXT )
295
	if ( m_iFileType != FILETYPE_TEXT )
349
		return -1;
296
		return -1;
350
 
297
 
351
	if ( filename.Empty() )
298
	if ( filename.Empty() )
352
		filename = m_sName;
299
		filename = _sName;
353
 
300
 
354
	CyString textid;
301
	CyString textid;
355
	if ( filename.IsIn("-L") || filename.IsIn("-l") )
302
	if ( filename.IsIn("-L") || filename.IsIn("-l") )
356
		textid = filename.GetToken("-", 1, 1);
303
		textid = filename.GetToken("-", 1, 1);
357
	else
304
	else
358
		textid = filename.GetToken(".", -1).Right(4);
305
		textid = filename.GetToken(".", -1).Right(4);
359
 
306
 
360
	if ( textid.IsNumber() ) return textid.ToInt();
307
	if ( textid.IsNumber() ) return textid.ToInt();
361
	return -1;
308
	return -1;
362
}
309
}
363
bool C_File::IsAutoTextFile ()
310
bool C_File::isAutoTextFile ()
364
{
311
{
365
	int textid = GetTextFileID();
312
	int textid = GetTextFileID();
366
	if ( textid == -1 ) return false;
313
	if ( textid == -1 ) return false;
367
 
314
 
368
	if ( textid <= 3 )
315
	if ( textid <= 3 )
369
		return true;
316
		return true;
370
 
317
 
371
	// check for original name
318
	// check for original name
372
	if ( !_sOriginalName.empty() )
319
	if ( !_sOriginalName.empty() )
Line 397... Line 344...
397
bool C_File::IsFakePatch() const
344
bool C_File::IsFakePatch() const
398
{
345
{
399
	if (m_iFileType != FILETYPE_MOD)
346
	if (m_iFileType != FILETYPE_MOD)
400
		return false;
347
		return false;
401
 
348
 
402
	Utils::String name = m_sName.ToString();
349
	Utils::String name = _sName;
403
 
350
 
404
	if (name.token(".", 1).toLong())
351
	if (name.token(".", 1).toLong())
405
		return true;
352
		return true;
406
 
353
 
407
	if (name.left(10) == "FakePatch_")
354
	if (name.left(10) == "FakePatch_")
408
		return true;
355
		return true;
409
 
356
 
410
	return false;
357
	return false;
411
}
358
}
412
 
359
 
413
/*
360
/*
414
########################################################################################################################
361
########################################################################################################################
415
####################################             File Pointer Functions             ####################################
362
####################################             File Pointer Functions             ####################################
416
########################################################################################################################
363
########################################################################################################################
417
*/
364
*/
418
 
365
 
419
/*
366
/*
420
	Func:	SetFilename
367
	Func:	SetFilename
421
	Accept:	filename - String for the filename of disk
368
	Accept:	filename - String for the filename of disk
422
	Desc:	Sets the file pointer
369
	Desc:	Sets the file pointer
423
			Reads the file size and last modifed time to store in the class
370
			Reads the file size and last modifed time to store in the class
Line 430... Line 377...
430
void C_File::setFilename(const Utils::String &filename)
377
void C_File::setFilename(const Utils::String &filename)
431
{
378
{
432
	Utils::String file = filename.findReplace ( "\\", "/" ).findReplace ( "//", "/" );
379
	Utils::String file = filename.findReplace ( "\\", "/" ).findReplace ( "//", "/" );
433
 
380
 
434
	_sFullDir = file.tokens("/", 1, -2);
381
	_sFullDir = file.tokens("/", 1, -2);
435
	m_sName = file.token("/", -1);
382
	_sName = file.token("/", -1);
436
	if ( _sFullDir.right(2) == "/." )
383
	if ( _sFullDir.right(2) == "/." )
437
		_sFullDir = _sFullDir.left(-2);
384
		_sFullDir = _sFullDir.left(-2);
438
 
385
 
439
	ReadFileSize ();
386
	ReadFileSize ();
440
 
387
 
441
	ReadLastModified ();
388
	ReadLastModified ();
442
}
389
}
443
 
390
 
444
 
391
 
445
/*
392
/*
446
	Func:	ReadFromFile
393
	Func:	ReadFromFile
447
	Return:	Boolean - Returns true if read was successfull
394
	Return:	Boolean - Returns true if read was successfull
448
	Desc:	Reads data from file pointer into data stream
395
	Desc:	Reads data from file pointer into data stream
449
			As its read from a file, there will be no compression, so its set to None
396
			As its read from a file, there will be no compression, so its set to None
450
*/
397
*/
451
bool C_File::ReadFromFile ()
398
bool C_File::ReadFromFile ()
452
{
399
{
453
	return this->readFromFile(filePointer());
400
	return this->readFromFile(filePointer());
454
}
401
}
455
 
402
 
456
bool C_File::ReadFromFile(CyString filename)
403
bool C_File::ReadFromFile(CyString filename)
457
{
404
{
458
	return readFromFile(filename.ToString());
405
	return readFromFile(filename.ToString());
459
}
406
}
460
bool C_File::readFromFile(const Utils::String filename)
407
bool C_File::readFromFile(const Utils::String filename)
Line 464... Line 411...
464
		m_iLastError = SPKERR_FILEOPEN;
411
		m_iLastError = SPKERR_FILEOPEN;
465
		return false;
412
		return false;
466
	}
413
	}
467
 
414
 
468
	m_iDataCompression = SPKCOMPRESS_NONE;
415
	m_iDataCompression = SPKCOMPRESS_NONE;
469
	m_lDataSize = m_lUncomprDataSize = m_lSize;
416
	m_lDataSize = m_lUncomprDataSize = m_lSize;
470
 
417
 
471
	DeleteData ();
418
	DeleteData ();
472
 
419
 
473
	m_sData = File.readAll((size_t *)&m_lSize);
420
	m_sData = File.readAll((size_t *)&m_lSize);
474
	if ( !m_sData ) { 
421
	if ( !m_sData ) { 
475
		m_iLastError = SPKERR_MALLOC; 
422
		m_iLastError = SPKERR_MALLOC; 
Line 555... Line 502...
555
{
502
{
556
	Utils::String fullfile = _sFullDir;
503
	Utils::String fullfile = _sFullDir;
557
	if ( !fullfile.empty() )
504
	if ( !fullfile.empty() )
558
		fullfile += "/";
505
		fullfile += "/";
559
 
506
 
560
	if ( !m_sName.Empty() )
507
	if ( !_sName.empty() )
561
		fullfile += m_sName.ToString();
508
		fullfile += _sName;
562
 
509
 
563
	return fullfile;
510
	return fullfile;
564
}
511
}
565
 
512
 
566
bool C_File::isExternalFile() const
513
bool C_File::isExternalFile() const
Line 617... Line 564...
617
	{
564
	{
618
		sData = sData.Right(sData.Length() - pos);
565
		sData = sData.Right(sData.Length() - pos);
619
		pos = sData.FindPos("<signature>", 0);
566
		pos = sData.FindPos("<signature>", 0);
620
		int endpos = sData.FindPos("</signature>", 0);
567
		int endpos = sData.FindPos("</signature>", 0);
621
		if ( pos != -1 && endpos != -1 )
568
		if ( pos != -1 && endpos != -1 )
622
		{
569
		{
623
			m_sSignature = sData.Mid(pos + 12, endpos - (pos + 12) + 1);
570
			m_sSignature = sData.Mid(pos + 12, endpos - (pos + 12) + 1);
624
			m_sSignature = m_sSignature.Remove('\n').Remove('\r');
571
			m_sSignature = m_sSignature.Remove('\n').Remove('\r');
625
		}
572
		}
626
	}
573
	}
627
 
574
 
628
	if ( deleteData )
575
	if ( deleteData )
629
		DeleteData();
576
		DeleteData();
630
}
577
}
631
 
578
 
632
 
579
 
633
/*
580
/*
634
	Func:	ReadFileSize()
581
	Func:	ReadFileSize()
635
	Return:	Returns the file size read
582
	Return:	Returns the file size read
636
	Desc:	Opens the file and seeks to the end
583
	Desc:	Opens the file and seeks to the end
Line 641... Line 588...
641
	if ( File.exists() ) m_lSize = File.fileSize();
588
	if ( File.exists() ) m_lSize = File.fileSize();
642
 
589
 
643
	m_lUncomprDataSize = m_lSize;
590
	m_lUncomprDataSize = m_lSize;
644
 
591
 
645
	return m_lSize;
592
	return m_lSize;
646
}
593
}
647
 
594
 
648
/*
595
/*
649
	Func:	ReadLastModifed()
596
	Func:	ReadLastModifed()
650
	Desc:	Reads the last modified time of the file and returns
597
	Desc:	Reads the last modified time of the file and returns
651
			Uses seperate rountines for Windows and Linux
598
			Uses seperate rountines for Windows and Linux
Line 714... Line 661...
714
 
661
 
715
	return false;
662
	return false;
716
}
663
}
717
 
664
 
718
int C_File::ReadScriptVersion ()
665
int C_File::ReadScriptVersion ()
719
{
666
{
720
	if ( (m_iFileType != FILETYPE_SCRIPT) && (m_iFileType != FILETYPE_UNINSTALL) ) return 0;
667
	if ( (m_iFileType != FILETYPE_SCRIPT) && (m_iFileType != FILETYPE_UNINSTALL) ) return 0;
721
 
668
 
722
	if ( (m_sData) && (m_iDataCompression == SPKCOMPRESS_NONE) )
669
	if ( (m_sData) && (m_iDataCompression == SPKCOMPRESS_NONE) )
723
		m_iVersion = ::ReadScriptVersionFromData ( m_sData, m_lDataSize );
670
		m_iVersion = ::ReadScriptVersionFromData ( m_sData, m_lDataSize );
724
	else {
671
	else {
725
		CFileIO File(filePointer());
672
		CFileIO File(filePointer());
726
		if ( File.startRead() ) {
673
		if ( File.startRead() ) {
Line 740... Line 687...
740
{
687
{
741
	if ( file->GetFileType() != m_iFileType )
688
	if ( file->GetFileType() != m_iFileType )
742
		return false;
689
		return false;
743
 
690
 
744
	if ( file->GetDir() != m_sDir )
691
	if ( file->GetDir() != m_sDir )
745
		return false;
692
		return false;
746
 
693
 
747
	if ( file->GetName() != m_sName )
694
	if ( file->name() != _sName )
748
	{
695
	{
749
		// check if the base name matches, but only for certain file extensions
696
		// check if the base name matches, but only for certain file extensions
750
		if (file->shouldCheckBaseName())
697
		if (file->shouldCheckBaseName())
751
		{
698
		{
752
			Utils::String baseName = CFileIO(file->GetName()).dir() + "/" + CFileIO(file->GetName()).baseName();
699
			Utils::String baseName = CFileIO(file->GetName()).dir() + "/" + CFileIO(file->GetName()).baseName();
753
			Utils::String compareBaseName = CFileIO(m_sName).dir() + "/" + CFileIO(m_sName).baseName();
700
			Utils::String compareBaseName = CFileIO(_sName).dir() + "/" + CFileIO(_sName).baseName();
754
			if (baseName.Compare(compareBaseName))
701
			if (baseName.Compare(compareBaseName))
755
				return true;
702
				return true;
756
		}
703
		}
757
		return false;
704
		return false;
758
	}
705
	}
759
 
706
 
760
	return true;
707
	return true;
761
}
708
}
762
 
709
 
763
/*
710
/*
764
########################################################################################################################
711
########################################################################################################################
765
####################################              Compression Functions             ####################################
712
####################################              Compression Functions             ####################################
766
########################################################################################################################
713
########################################################################################################################
767
*/
714
*/
768
 
715
 
769
bool C_File::CompressFile ( CProgressInfo *progress )
716
bool C_File::CompressFile ( CProgressInfo *progress )
770
{
717
{
771
	Utils::String file = this->filePointer();
718
	Utils::String file = this->filePointer();
772
	if ( !CFileIO(this->filePointer()).exists() )
719
	if ( !CFileIO(this->filePointer()).exists() )
773
	{
720
	{
774
		if ( !this->writeToFile("tempuncompr.dat", m_sData, m_lDataSize) )
721
		if ( !this->writeToFile("tempuncompr.dat", m_sData, m_lDataSize) )
775
			return false;
722
			return false;
776
		file = "tempuncompr.dat";
723
		file = "tempuncompr.dat";
777
	}
724
	}
778
 
725
 
Line 819... Line 766...
819
 
766
 
820
	return ret;
767
	return ret;
821
}
768
}
822
 
769
 
823
bool C_File::ChangeCompression ( int compressionType, CProgressInfo *progress )
770
bool C_File::ChangeCompression ( int compressionType, CProgressInfo *progress )
824
{
771
{
825
	// no data to try to compress
772
	// no data to try to compress
826
	if ( (!m_sData) || (!m_lDataSize) )
773
	if ( (!m_sData) || (!m_lDataSize) )
827
		return false;
774
		return false;
828
 
775
 
829
	// laready compressed to correct type
776
	// laready compressed to correct type
Line 1007... Line 954...
1007
	if ( (!m_sData) || (!m_lDataSize) ) {
954
	if ( (!m_sData) || (!m_lDataSize) ) {
1008
		return (m_lSize) ? false : true;
955
		return (m_lSize) ? false : true;
1009
	}
956
	}
1010
 
957
 
1011
	if ( m_bCompressedToFile )
958
	if ( m_bCompressedToFile )
1012
		return false;
959
		return false;
1013
 
960
 
1014
	// if comopression is set to none, dont bother
961
	// if comopression is set to none, dont bother
1015
	if ( m_iDataCompression == SPKCOMPRESS_NONE )
962
	if ( m_iDataCompression == SPKCOMPRESS_NONE )
1016
		return true;
963
		return true;
1017
 
964
 
1018
	if ( m_iDataCompression == SPKCOMPRESS_ZLIB )
965
	if ( m_iDataCompression == SPKCOMPRESS_ZLIB )
1019
	{
966
	{
1020
		unsigned long uncomprLen = m_lUncomprDataSize;
967
		unsigned long uncomprLen = m_lUncomprDataSize;
1021
		unsigned char *uncompr = new unsigned char[m_lUncomprDataSize];
968
		unsigned char *uncompr = new unsigned char[m_lUncomprDataSize];
1022
		int err = uncompress ( uncompr, &uncomprLen, (const unsigned char *)m_sData, m_lDataSize );
969
		int err = uncompress ( uncompr, &uncomprLen, (const unsigned char *)m_sData, m_lDataSize );
1023
		if ( err == Z_OK )
970
		if ( err == Z_OK )
1024
		{
971
		{
1025
			DeleteData ();
972
			DeleteData ();
1026
			m_iDataCompression = SPKCOMPRESS_NONE;
973
			m_iDataCompression = SPKCOMPRESS_NONE;
1027
			m_lDataSize = uncomprLen;
974
			m_lDataSize = uncomprLen;
1028
			m_sData = uncompr;
975
			m_sData = uncompr;
1029
			return true;
976
			return true;
1030
		}
977
		}
Line 1043... Line 990...
1043
			m_iDataCompression = SPKCOMPRESS_NONE;
990
			m_iDataCompression = SPKCOMPRESS_NONE;
1044
			m_lDataSize = (long)uncomprLen;
991
			m_lDataSize = (long)uncomprLen;
1045
			m_sData = new unsigned char[m_lDataSize];
992
			m_sData = new unsigned char[m_lDataSize];
1046
			memcpy(m_sData, uncompr, m_lDataSize);
993
			memcpy(m_sData, uncompr, m_lDataSize);
1047
			delete uncompr;
994
			delete uncompr;
1048
			return true;
995
			return true;
1049
		}
996
		}
1050
 
997
 
1051
		if ( uncompr )
998
		if ( uncompr )
1052
			delete [] uncompr;
999
			delete [] uncompr;
1053
	}
1000
	}
1054
	else if ( m_iDataCompression == SPKCOMPRESS_7ZIP )
1001
	else if ( m_iDataCompression == SPKCOMPRESS_7ZIP )
1055
	{
1002
	{
1056
		long len = m_lUncomprDataSize;
1003
		long len = m_lUncomprDataSize;
Line 1062... Line 1009...
1062
			m_lDataSize = len;
1009
			m_lDataSize = len;
1063
			m_iDataCompression = SPKCOMPRESS_NONE;
1010
			m_iDataCompression = SPKCOMPRESS_NONE;
1064
			return true;
1011
			return true;
1065
		}
1012
		}
1066
	}
1013
	}
1067
 
1014
 
1068
	return false;
1015
	return false;
1069
}
1016
}
1070
 
1017
 
1071
unsigned char *C_File::UncompressData ( long *size, CProgressInfo *progress )
1018
unsigned char *C_File::UncompressData ( long *size, CProgressInfo *progress )
1072
{
1019
{
1073
	// no data to try to uncompress
1020
	// no data to try to uncompress
1074
	if ( (!m_sData) || (!m_lDataSize) )
1021
	if ( (!m_sData) || (!m_lDataSize) )
1075
		return NULL;
1022
		return NULL;
1076
 
1023
 
1077
	//if ( m_bCompressedToFile )
1024
	//if ( m_bCompressedToFile )
1078
	//	return NULL;
1025
	//	return NULL;
1079
 
1026
 
1080
	// if comopression is set to none, dont bother
1027
	// if comopression is set to none, dont bother
1081
	if ( m_iDataCompression == SPKCOMPRESS_NONE )
1028
	if ( m_iDataCompression == SPKCOMPRESS_NONE )
1082
	{
1029
	{
1083
		*size = m_lDataSize;
1030
		*size = m_lDataSize;
1084
		return m_sData;
1031
		return m_sData;
1085
	}
1032
	}
1086
 
1033
 
1087
	if ( m_iDataCompression == SPKCOMPRESS_ZLIB )
1034
	if ( m_iDataCompression == SPKCOMPRESS_ZLIB )
1088
	{
1035
	{
1089
		unsigned long uncomprLen = m_lUncomprDataSize;
1036
		unsigned long uncomprLen = m_lUncomprDataSize;
1090
		unsigned char *uncompr = new unsigned char[m_lUncomprDataSize];
1037
		unsigned char *uncompr = new unsigned char[m_lUncomprDataSize];
1091
		int err = uncompress ( uncompr, &uncomprLen, (const unsigned char *)m_sData, m_lDataSize );
1038
		int err = uncompress ( uncompr, &uncomprLen, (const unsigned char *)m_sData, m_lDataSize );
1092
		if ( err == Z_OK )
1039
		if ( err == Z_OK )
1093
		{
1040
		{
Line 1096... Line 1043...
1096
		}
1043
		}
1097
		if ( uncompr )
1044
		if ( uncompr )
1098
			delete [] uncompr;
1045
			delete [] uncompr;
1099
	}
1046
	}
1100
	if ( m_iDataCompression == SPKCOMPRESS_7ZIP )
1047
	if ( m_iDataCompression == SPKCOMPRESS_7ZIP )
1101
	{
1048
	{
1102
		long len = m_lUncomprDataSize;
1049
		long len = m_lUncomprDataSize;
1103
		unsigned char *compr = LZMADecode_C ( m_sData, m_lDataSize, (size_t *)&len, NULL );
1050
		unsigned char *compr = LZMADecode_C ( m_sData, m_lDataSize, (size_t *)&len, NULL );
1104
		if ( compr )
1051
		if ( compr )
1105
		{
1052
		{
1106
			*size = len;
1053
			*size = len;
Line 1171... Line 1118...
1171
bool C_File::writeFilePointer(unsigned char *cData, long len)
1118
bool C_File::writeFilePointer(unsigned char *cData, long len)
1172
{
1119
{
1173
	return writeToFile(filePointer(), cData, len);
1120
	return writeToFile(filePointer(), cData, len);
1174
}
1121
}
1175
bool C_File::writeToFile(const Utils::String &filename, unsigned char *cData, long len)
1122
bool C_File::writeToFile(const Utils::String &filename, unsigned char *cData, long len)
1176
{
1123
{
1177
	unsigned char *data = cData;
1124
	unsigned char *data = cData;
1178
	if ( (!len) || (!data) ) {
1125
	if ( (!len) || (!data) ) {
1179
		len = m_lDataSize;
1126
		len = m_lDataSize;
1180
		data = m_sData;
1127
		data = m_sData;
1181
	}
1128
	}
Line 1220... Line 1167...
1220
 
1167
 
1221
	Utils::String fulldir = fullfile.tokens("/", 1, -2);
1168
	Utils::String fulldir = fullfile.tokens("/", 1, -2);
1222
	if (!fulldir.empty())
1169
	if (!fulldir.empty())
1223
	{
1170
	{
1224
		if (!CDirIO(fulldir).Create())
1171
		if (!CDirIO(fulldir).Create())
1225
			return false;
1172
			return false;
1226
	}
1173
	}
1227
 
1174
 
1228
	return writeToFile(fullfile, data, len);
1175
	return writeToFile(fullfile, data, len);
1229
}
1176
}
1230
 
1177
 
1231
CyString C_File::GetDataSizeString ()
1178
CyString C_File::GetDataSizeString ()
Line 1357... Line 1304...
1357
 
1304
 
1358
	return FILETYPE_UNKNOWN;
1305
	return FILETYPE_UNKNOWN;
1359
}
1306
}
1360
 
1307
 
1361
 
1308
 
1362
CyString FormatErrorString(int error, CyString rest)
1309
Utils::String FormatErrorString(int error, const Utils::String &rest)
1363
{
1310
{
1364
	int max = 0;
1311
	int max = 0;
1365
	CyString *args = 0;
1312
	Utils::String *args = 0;
1366
 
1313
 
1367
	if ( !rest.Empty() )
1314
	if ( !rest.empty() )
1368
		args = rest.SplitToken(&apos;~&apos;, &max);
1315
		args = rest.tokenise(&quot;~&quot;, &max);
1369
 
1316
 
1370
	CyString errorStr;
1317
	Utils::String errorStr;
1371
	switch ( error )
1318
	switch ( error )
1372
	{
1319
	{
1373
		case SPKINSTALL_CREATEDIRECTORY:
1320
		case SPKINSTALL_CREATEDIRECTORY:
1374
			errorStr = "Creating Directory: %1";
1321
			errorStr = "Creating Directory: %1";
1375
			break;
1322
			break;
Line 1463... Line 1410...
1463
		case SPKINSTALL_ORPHANED_FAIL:
1410
		case SPKINSTALL_ORPHANED_FAIL:
1464
			errorStr = "Unable to remove Orphaned File: %1";
1411
			errorStr = "Unable to remove Orphaned File: %1";
1465
			break;
1412
			break;
1466
	}
1413
	}
1467
 
1414
 
1468
	CyString ret = errorStr.Args(args, max);
1415
	Utils::String ret = errorStr.args(args, max);
1469
	CLEANSPLIT(args, max)
1416
	CLEANSPLIT(args, max)
1470
	return ret;
1417
	return ret;
1471
}
1418
}
1472
 
1419
 
1473
 
1420
 
Line 1624... Line 1571...
1624
 
1571
 
1625
	// create data buffer
1572
	// create data buffer
1626
	size_t *uncomprLenSize = (size_t*)(newData + (datasize - 4));
1573
	size_t *uncomprLenSize = (size_t*)(newData + (datasize - 4));
1627
	unsigned long uncomprLen = (unsigned long)*uncomprLenSize;
1574
	unsigned long uncomprLen = (unsigned long)*uncomprLenSize;
1628
	if ( uncomprLen > (datasize * 100) )
1575
	if ( uncomprLen > (datasize * 100) )
1629
	{
1576
	{
1630
		if ( tempData ) delete []tempData;
1577
		if ( tempData ) delete []tempData;
1631
		*len = 0;
1578
		*len = 0;
1632
		return NULL;
1579
		return NULL;
1633
	}
1580
	}
1634
	unsigned char *uncompr = new unsigned char[uncomprLen + 1];
1581
	unsigned char *uncompr = new unsigned char[uncomprLen + 1];
1635
	if ( !uncompr ) {
1582
	if ( !uncompr ) {
1636
		if ( tempData ) delete []tempData;
1583
		if ( tempData ) delete []tempData;
1637
		return NULL;
1584
		return NULL;
1638
	}
1585
	}
1639
	memset ( uncompr, 0, sizeof(uncompr) );
1586
	memset ( uncompr, 0, sizeof(uncompr) );
1640
 
1587
 
1641
 
1588
 
1642
	// find header size
1589
	// find header size
1643
	unsigned char *buf = newData + PCKHEADERSIZE;
1590
	unsigned char *buf = newData + PCKHEADERSIZE;
1644
 
1591
 
1645
//	buf = data + (6 + sizeof(time_t));
1592
//	buf = data + (6 + sizeof(time_t));
1646
	char flag = newData[3];
1593
	char flag = newData[3];
1647
 
1594
 
1648
	if ( flag & GZ_FLAG_EXTRA )
1595
	if ( flag & GZ_FLAG_EXTRA )
1649
	{
1596
	{
1650
		size_t xlen = *((short int*)(buf));
1597
		size_t xlen = *((short int*)(buf));
1651
		buf += xlen;
1598
		buf += xlen;
1652
	}
1599
	}
1653
 
1600
 
1654
	if ( flag & GZ_FLAG_FILENAME )
1601
	if ( flag & GZ_FLAG_FILENAME )
1655
	{
1602
	{
1656
		char *origname = (char*)(buf);
1603
		char *origname = (char*)(buf);
1657
		buf += strlen (origname) + 1;
1604
		buf += strlen (origname) + 1;
1658
	}
1605
	}
Line 1722... Line 1669...
1722
		while ( data[pos2] != '<' && pos2 > max ) pos2--;
1669
		while ( data[pos2] != '<' && pos2 > max ) pos2--;
1723
		if ( data[pos2] != '<' ) break;
1670
		if ( data[pos2] != '<' ) break;
1724
 
1671
 
1725
		memcpy(tag, data + pos2, pos - pos2);
1672
		memcpy(tag, data + pos2, pos - pos2);
1726
		tag[pos - pos2] = '\0';
1673
		tag[pos - pos2] = '\0';
1727
 
1674
 
1728
		Utils::String sTag(tag);
1675
		Utils::String sTag(tag);
1729
		if ( sTag.Compare("</signature") || sTag.Compare("<signature") ) return true;
1676
		if ( sTag.Compare("</signature") || sTag.Compare("<signature") ) return true;
1730
		if ( sTag.Compare("</codearray") || sTag.Compare("<codearray") ) return false;
1677
		if ( sTag.Compare("</codearray") || sTag.Compare("<codearray") ) return false;
1731
		pos = pos2 - 1;
1678
		pos = pos2 - 1;
1732
	}
1679
	}
1733
 
1680
 
Line 1789... Line 1736...
1789
}
1736
}
1790
 
1737
 
1791
CyString C_File::GetBaseName ()
1738
CyString C_File::GetBaseName ()
1792
{
1739
{
1793
	// remove any directory
1740
	// remove any directory
1794
	CyString file = m_sName.GetToken ( "/&quot;, m_sName.NumToken ( '/&apos; ) );
1741
	Utils::String file = _sName.token(&quot;/&quot;, -1);
1795
 
1742
 
1796
	// remove file extension
1743
	// remove file extension
1797
	file = file.GetToken ( ".", 1, file.NumToken ( '.' ) - 1 );
-
 
1798
 
-
 
1799
	return file;
1744
	return file.token(".", -1);
1800
}
1745
}
1801
 
1746
 
1802
void C_File::CopyData(C_File *oldFile, bool includeData)
1747
void C_File::CopyData(C_File *oldFile, bool includeData)
1803
{
1748
{
1804
	SetFilename(oldFile->GetFullFilename());
1749
	SetFilename(oldFile->GetFullFilename());
Line 1828... Line 1773...
1828
float GetLibraryVersion() { return (float)LIBRARYVERSION; }
1773
float GetLibraryVersion() { return (float)LIBRARYVERSION; }
1829
float GetFileFormatVersion() { return (float)FILEVERSION; }
1774
float GetFileFormatVersion() { return (float)FILEVERSION; }
1830
 
1775
 
1831
CyString C_File::ChangeFileExt(CyString ext)
1776
CyString C_File::ChangeFileExt(CyString ext)
1832
{
1777
{
-
 
1778
	_sName = CFileIO(_sName).changeFileExtension(ext.ToString());
-
 
1779
	return _sName;
-
 
1780
}
-
 
1781
 
-
 
1782
Utils::String C_File::fileExt() const 
-
 
1783
{ 
-
 
1784
	return _sName.token(".", -1); 
-
 
1785
}
-
 
1786
 
-
 
1787
const Utils::String &C_File::changeFileExt(const Utils::String &ext)
-
 
1788
{
1833
	m_sName = CFileIO(m_sName).ChangeFileExtension(ext);
1789
	_sName = CFileIO(_sName).changeFileExtension(ext);
1834
	return m_sName;
1790
	return _sName;
1835
}
1791
}
1836
 
1792
 
1837
bool C_File::CheckPackedExtension()
1793
bool C_File::CheckPackedExtension()
1838
{
1794
{
1839
	CyString ext = this->GetFileExt();
1795
	CyString ext = this->GetFileExt();
Line 1847... Line 1803...
1847
	return false;
1803
	return false;
1848
}
1804
}
1849
 
1805
 
1850
bool C_File::shouldCheckBaseName() const
1806
bool C_File::shouldCheckBaseName() const
1851
{
1807
{
1852
	Utils::String ext = CFileIO(m_sName).extension();
1808
	Utils::String ext = CFileIO(_sName).extension();
1853
	if (ext == "xml" || ext == "txt" || ext == "pck")
1809
	if (ext == "xml" || ext == "txt" || ext == "pck")
1854
		return true;
1810
		return true;
1855
	if (ext == "bod" || ext == "bob" || ext == "pbb" || ext == "pbd")
1811
	if (ext == "bod" || ext == "bob" || ext == "pbb" || ext == "pbd")
1856
		return true;
1812
		return true;
1857
	return false;
1813
	return false;
Line 2073... Line 2029...
2073
			if (!fullfile.empty())
2029
			if (!fullfile.empty())
2074
				fullfile += "/";
2030
				fullfile += "/";
2075
			fullfile += d;
2031
			fullfile += d;
2076
		}
2032
		}
2077
	}
2033
	}
2078
	if (!m_sName.Empty())
2034
	if (!_sName.empty())
2079
	{
2035
	{
2080
		if (!fullfile.empty())
2036
		if (!fullfile.empty())
2081
			fullfile += "/";
2037
			fullfile += "/";
2082
		fullfile += m_sName.ToString();
2038
		fullfile += _sName;
2083
	}
2039
	}
2084
 
2040
 
2085
	fullfile = fullfile.findReplace("\\", "/");
2041
	fullfile = fullfile.findReplace("\\", "/");
2086
	return fullfile;
2042
	return fullfile;
2087
}
2043
}