Subversion Repositories spk

Rev

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

Rev 83 Rev 84
Line 259... Line 259...
259
	File.setAutoDelete(false);
259
	File.setAutoDelete(false);
260
 
260
 
261
	// now copy to original file
261
	// now copy to original file
262
	if ( std::remove(m_sFilename.c_str()) == 0 ) {
262
	if ( std::remove(m_sFilename.c_str()) == 0 ) {
263
		std::rename(CPackages::tempDirectory() + "/temp.tmp", m_sFilename.c_str());
263
		std::rename(CPackages::tempDirectory() + "/temp.tmp", m_sFilename.c_str());
-
 
264
		size_t checkFileSize = m_lSize - datasize;
-
 
265
		this->_readFileSize();
-
 
266
		if ( checkFileSize != m_lSize ) {
-
 
267
			CLog::log(CLog::Log_IO, 3, Utils::String("WARNING: CFileIO::TruncateFile, file size mismatch, ") + (long)checkFileSize + " => " + (long)m_lSize);
-
 
268
		}
264
		return FILEERR_NONE;
269
		return FILEERR_NONE;
265
	}
270
	}
266
 
271
 
267
	return FILEERR_NOWRITE;
272
	return FILEERR_NOWRITE;
268
}
273
}
Line 409... Line 414...
409
std::vector<Utils::String> *CFileIO::readLines()
414
std::vector<Utils::String> *CFileIO::readLines()
410
{
415
{
411
	if ( m_sFilename.empty() ) return 0;
416
	if ( m_sFilename.empty() ) return 0;
412
 
417
 
413
	std::vector<Utils::String> *file = new std::vector<Utils::String>;
418
	std::vector<Utils::String> *file = new std::vector<Utils::String>;
414
	std::string line;
419
	Utils::String line;
415
	file->clear();
420
	file->clear();
416
	std::ifstream infile (m_sFilename.c_str(), std::ios_base::in);
421
	std::ifstream infile (m_sFilename.c_str(), std::ios_base::in);
417
	while (getline(infile, line, '\n')) {
422
	while (getline(infile, line, '\n')) {
418
		file->push_back(Utils::String(line).removeChar((char)0));
423
		file->push_back(Utils::String(line).removeChar((char)0));
419
	}
424
	}
Line 426... Line 431...
426
std::vector<CyString> *CFileIO::ReadLines()
431
std::vector<CyString> *CFileIO::ReadLines()
427
{
432
{
428
	if ( m_sFilename.empty() ) return 0;
433
	if ( m_sFilename.empty() ) return 0;
429
 
434
 
430
	std::vector<CyString> *file = new std::vector<CyString>;
435
	std::vector<CyString> *file = new std::vector<CyString>;
431
	std::string line;
436
	Utils::String line;
432
	file->clear();
437
	file->clear();
433
	std::ifstream infile (m_sFilename.c_str(), std::ios_base::in);
438
	std::ifstream infile (m_sFilename.c_str(), std::ios_base::in);
434
	while (getline(infile, line, '\n'))
439
	while (getline(infile, line, '\n'))
435
	{
440
	{
436
		CyString l = line;
441
		CyString l = line;
Line 446... Line 451...
446
CyStringList *CFileIO::ReadLinesStr()
451
CyStringList *CFileIO::ReadLinesStr()
447
{
452
{
448
	if ( m_sFilename.empty() ) return 0;
453
	if ( m_sFilename.empty() ) return 0;
449
 
454
 
450
	CyStringList *file = new CyStringList;
455
	CyStringList *file = new CyStringList;
451
	std::string line;
456
	Utils::String line;
452
	std::ifstream infile (m_sFilename.c_str(), std::ios_base::in);
457
	std::ifstream infile (m_sFilename.c_str(), std::ios_base::in);
453
	while (getline(infile, line, '\n'))
458
	while (getline(infile, line, '\n'))
454
	{
459
	{
455
		CyString l = line;
-
 
456
		l.RemoveChar((char)0);
460
		file->PushBack(CyString(line.removeChar((char)0)));
457
		file->PushBack(l);
-
 
458
	}
461
	}
459
 
462
 
460
	infile.close();
463
	infile.close();
461
 
464
 
462
	return file;
465
	return file;
463
}
466
}
464
 
467
 
465
bool CFileIO::put(const unsigned char c)
468
bool CFileIO::put(const unsigned char c)
466
{
469
{
467
	if ( !this->isOpened() ) return false;
470
	if ( !this->isOpened() ) return false;
468
 
471
 
469
	m_fId.put(c);
472
	m_fId.put(c);
470
	return !m_fId.bad();
473
	return !m_fId.bad();
471
}
474
}
472
 
475
 
473
bool CFileIO::writeSize(unsigned int iSize)
476
bool CFileIO::writeSize(unsigned int iSize)
474
{
477
{
475
	if ( !this->isOpened() ) return false;
478
	if ( !this->isOpened() ) return false;
476
	if ( !this->put(static_cast<unsigned char>(iSize >> 24)) ) return false;
479
	if ( !this->put(static_cast<unsigned char>(iSize >> 24)) ) return false;
Line 493... Line 496...
493
		data = new unsigned char[iMaxSize + 1];
496
		data = new unsigned char[iMaxSize + 1];
494
	}
497
	}
495
	catch (std::exception &e) {
498
	catch (std::exception &e) {
496
		CLog::logf(CLog::Log_IO, 2, "ERROR: CFileIO::write(CFileIO, size_t) unable to malloc data, %d (%s)", iMaxSize + 1, e.what());
499
		CLog::logf(CLog::Log_IO, 2, "ERROR: CFileIO::write(CFileIO, size_t) unable to malloc data, %d (%s)", iMaxSize + 1, e.what());
497
		return false;
500
		return false;
498
	}
501
	}
499
 
502
 
500
	int iSizeLeft = iSize;
503
	int iSizeLeft = iSize;
501
	bool bSuccess = true;
504
	bool bSuccess = true;
502
	while ( iSizeLeft > 0 ) {
505
	while ( iSizeLeft > 0 ) {
503
		int iDoSize = iMaxSize;
506
		int iDoSize = iMaxSize;
504
		if ( iDoSize > iSizeLeft ) iDoSize = iSizeLeft;
507
		if ( iDoSize > iSizeLeft ) iDoSize = iSizeLeft;
Line 509... Line 512...
509
		m_lSize += iDoSize;		
512
		m_lSize += iDoSize;		
510
		iSizeLeft -= iDoSize;
513
		iSizeLeft -= iDoSize;
511
	}
514
	}
512
 
515
 
513
	delete data;
516
	delete data;
514
 
-
 
515
 
517
 
516
	return bSuccess;
518
	return bSuccess;
517
}
519
}
518
 
520
 
519
bool CFileIO::write(const char *buf, unsigned int iSize)
521
bool CFileIO::write(const char *buf, unsigned int iSize)
Line 608... Line 610...
608
}
610
}
609
 
611
 
610
void CFileIO::close()
612
void CFileIO::close()
611
{
613
{
612
	if ( this->isOpened() ) m_fId.close();
614
	if ( this->isOpened() ) m_fId.close();
-
 
615
	this->_readFileSize();
613
}
616
}
614
 
617
 
615
int CFileIO::readSize()
618
int CFileIO::readSize()
616
{
619
{
617
	unsigned char size[4];
620
	unsigned char size[4];