Subversion Repositories spk

Rev

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

Rev 51 Rev 52
Line 345... Line 345...
345
	return this->ReadFromFile(GetFilePointer().c_str());
345
	return this->ReadFromFile(GetFilePointer().c_str());
346
}
346
}
347
 
347
 
348
bool C_File::ReadFromFile (CyString filename)
348
bool C_File::ReadFromFile (CyString filename)
349
{
349
{
350
	FILE *id = fopen ( filename.c_str(), "rb" );
350
	CFileIO File(filename);
351
	if ( !id )
351
	if ( !File.startRead() ) {
352
	{
-
 
353
		m_iLastError = SPKERR_FILEOPEN;
352
		m_iLastError = SPKERR_FILEOPEN;
354
		return false;
353
		return false;
355
	}
354
	}
356
 
355
 
357
	if ( !m_lSize )
-
 
358
	{
-
 
359
		fseek ( id, 0, SEEK_END );
-
 
360
		m_lSize = ftell ( id );
-
 
361
		rewind ( id );
-
 
362
	}
-
 
363
 
-
 
364
	m_iDataCompression = SPKCOMPRESS_NONE;
356
	m_iDataCompression = SPKCOMPRESS_NONE;
365
	m_lDataSize = m_lUncomprDataSize = m_lSize;
357
	m_lDataSize = m_lUncomprDataSize = m_lSize;
366
 
358
 
367
	DeleteData ();
359
	DeleteData ();
368
 
360
 
369
	m_sData = new unsigned char[m_lSize];
361
	m_sData = File.readAll((size_t *)&m_lSize);
370
	if ( !m_sData ) { fclose ( id ); m_iLastError = SPKERR_MALLOC; return false; }
-
 
371
 
-
 
372
	fread ( m_sData, sizeof(unsigned char), m_lSize, id );
-
 
373
	if ( ferror(id) )
362
	if ( !m_sData ) { 
374
	{
-
 
375
		m_iLastError = SPKERR_FILEREAD;
363
		m_iLastError = SPKERR_MALLOC; 
376
		DeleteData ();
-
 
377
		m_lDataSize = 0;
364
		m_lDataSize = 0;
378
		fclose ( id );
-
 
379
		return false;
365
		return false; 
380
	}
366
	}
381
 
367
 
382
	m_iLastError = SPKERR_NONE;
368
	m_lDataSize = m_lSize;
-
 
369
	m_tTime = File.modifiedTime();
383
 
370
 
384
	struct stat fileStat;
-
 
385
	if ( !stat(GetFilePointer().c_str(), &fileStat) )
-
 
386
		m_tTime = fileStat.st_atime;
371
	m_iLastError = SPKERR_NONE;
387
 
372
 
388
	m_bLoaded = true;
373
	m_bLoaded = true;
389
 
374
 
390
	fclose ( id );
375
	File.close();
391
 
-
 
392
	return true;
376
	return true;
393
}
377
}
394
 
378
 
395
/*
379
/*
396
	Func:	ReadFromData
380
	Func:	ReadFromData
Line 411... Line 395...
411
 
395
 
412
	return true;
396
	return true;
413
}
397
}
414
 
398
 
415
 
399
 
-
 
400
bool C_File::readFromFile(CFileIO &File, long lSize, bool bDoSize)
-
 
401
{
-
 
402
	return this->readFromFile(File.stream(), lSize, bDoSize);
-
 
403
}
416
bool C_File::readFromFile(std::fstream &stream, long lSize, bool bDoSize)
404
bool C_File::readFromFile(std::fstream &stream, long lSize, bool bDoSize)
417
{
405
{
418
	m_lDataSize = lSize;
406
	m_lDataSize = lSize;
419
	try {
407
	try {
420
		m_sData = new unsigned char[m_lDataSize];
408
		m_sData = new unsigned char[m_lDataSize];
Line 552... Line 540...
552
	Return:	Returns the file size read
540
	Return:	Returns the file size read
553
	Desc:	Opens the file and seeks to the end
541
	Desc:	Opens the file and seeks to the end
554
*/
542
*/
555
long C_File::ReadFileSize ()
543
long C_File::ReadFileSize ()
556
{
544
{
557
 
-
 
558
	FILE *id = fopen ( GetFilePointer().c_str(), "rb" );
545
	CFileIO File(GetFilePointer());
559
	if ( id )
-
 
560
	{
-
 
561
		fseek ( id, 0, SEEK_END );
-
 
562
		m_lSize = ftell ( id );
546
	if ( File.exists() ) m_lSize = File.fileSize();
563
		fclose ( id );
-
 
564
	}
-
 
565
 
547
 
566
	m_lUncomprDataSize = m_lSize;
548
	m_lUncomprDataSize = m_lSize;
567
 
549
 
568
	return m_lSize;
550
	return m_lSize;
569
}
551
}
Line 589... Line 571...
589
	return m_tTime;
571
	return m_tTime;
590
}
572
}
591
 
573
 
592
bool C_File::CheckValidFilePointer ()
574
bool C_File::CheckValidFilePointer ()
593
{
575
{
594
	CyString filename = GetFilePointer();
576
	return CFileIO::Exists(GetFilePointer().ToString());
595
	if ( filename.Empty() )
-
 
596
		return false;
-
 
597
 
-
 
598
	FILE *id = fopen ( filename.c_str(), "rb+" );
-
 
599
	if ( !id )
-
 
600
		return false;
-
 
601
 
-
 
602
	fclose ( id );
-
 
603
	return true;
-
 
604
}
577
}
605
 
578
 
606
bool C_File::ReadSignedFile()
579
bool C_File::ReadSignedFile()
607
{
580
{
608
	if ( (m_iFileType != FILETYPE_SCRIPT) && (m_iFileType != FILETYPE_UNINSTALL) )
581
	if ( (m_iFileType != FILETYPE_SCRIPT) && (m_iFileType != FILETYPE_UNINSTALL) )
Line 749... Line 722...
749
*/
722
*/
750
 
723
 
751
bool C_File::CompressFile ( CProgressInfo *progress )
724
bool C_File::CompressFile ( CProgressInfo *progress )
752
{
725
{
753
	CyString file = this->GetFilePointer();
726
	CyString file = this->GetFilePointer();
754
	if ( !CFileIO(this->GetFilePointer()).Exists() )
727
	if ( !CFileIO(this->GetFilePointer()).exists() )
755
	{
728
	{
756
		if ( !this->WriteToFile("tempuncompr.dat", m_sData, m_lDataSize) )
729
		if ( !this->WriteToFile("tempuncompr.dat", m_sData, m_lDataSize) )
757
			return false;
730
			return false;
758
		file = "tempuncompr.dat";
731
		file = "tempuncompr.dat";
759
	}
732
	}
Line 804... Line 777...
804
 
777
 
805
					fclose(id);
778
					fclose(id);
806
				}
779
				}
807
			}
780
			}
808
		}
781
		}
809
		CFileIO("tempcompr.dat").Remove();
782
		CFileIO::Remove("tempcompr.dat");
810
 
783
 
811
		fclose(fIn);
784
		fclose(fIn);
812
	}
785
	}
813
 
786
 
814
	CFileIO("tempuncompr.dat").Remove();
787
	CFileIO::Remove("tempuncompr.dat");
815
 
788
 
816
	return ret;
789
	return ret;
817
}
790
}
818
 
791
 
819
bool C_File::ChangeCompression ( int compressionType, CProgressInfo *progress )
792
bool C_File::ChangeCompression ( int compressionType, CProgressInfo *progress )