Subversion Repositories spk

Rev

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

Rev 181 Rev 196
Line 488... Line 488...
488
 
488
 
489
bool CCatFile::WriteCatFile ()
489
bool CCatFile::WriteCatFile ()
490
{
490
{
491
	if ( (m_bCreate) && (_lFiles->empty()) ) return false;
491
	if ( (m_bCreate) && (_lFiles->empty()) ) return false;
492
 
492
 
493
	Utils::String cat = m_fDatFile.filename() + "\n";
493
	Utils::String cat = m_fDatFile.filename().toString() + "\n";
494
	for (auto itr = _lFiles->cbegin(); itr != _lFiles->cend(); ++itr)
494
	for (auto itr = _lFiles->cbegin(); itr != _lFiles->cend(); ++itr)
495
	{
495
	{
496
		SInCatFile *c = *itr;
496
		SInCatFile *c = *itr;
497
		if ( !c ) continue;
497
		if ( !c ) continue;
498
		if ( c->sFile.empty() ) continue;
498
		if ( c->sFile.empty() ) continue;
Line 530... Line 530...
530
	return _lFiles;
530
	return _lFiles;
531
}
531
}
532
 
532
 
533
bool CCatFile::checkExtensionPck(const Utils::String &filename) const
533
bool CCatFile::checkExtensionPck(const Utils::String &filename) const
534
{	
534
{	
535
	Utils::String ext = CFileIO(filename).extension().lower();
535
	Utils::WString ext = CFileIO(filename).extension().lower();
536
	if ( ext == "xml" )
536
	if ( ext == L"xml" )
537
		return true;
537
		return true;
538
	else if ( ext == "txt" )
538
	else if ( ext == L"txt" )
539
		return true;
539
		return true;
540
	else if ( ext == "bob" )
540
	else if ( ext == L"bob" )
541
		return true;
541
		return true;
542
	else if ( ext == "bod" )
542
	else if ( ext == L"bod" )
543
		return true;
543
		return true;
544
 
544
 
545
	return false;
545
	return false;
546
}
546
}
547
 
547
 
548
bool CCatFile::CheckPackedExtension(const Utils::String &sFilename)
548
bool CCatFile::CheckPackedExtension(const Utils::String &sFilename)
549
{
549
{
550
	Utils::String ext = CFileIO(sFilename).extension().lower();
550
	Utils::WString ext = CFileIO(sFilename).extension().lower();
551
 
551
 
552
	if ( ext == "pck" )
552
	if ( ext == L"pck" )
-
 
553
		return true;
-
 
554
	else if ( ext == L"pbb" )
553
		return true;
555
		return true;
554
	else if ( ext == "pbb" )
-
 
555
		return true;
-
 
556
	else if ( ext == "pbd" )
556
	else if ( ext == L"pbd" )
557
		return true;
557
		return true;
558
 
558
 
559
	return false;
559
	return false;
560
}
560
}
561
 
561
 
562
Utils::String CCatFile::PckChangeExtension(const Utils::String &f)
562
Utils::String CCatFile::PckChangeExtension(const Utils::String &f)
563
{
563
{
564
	CFileIO fo ( f );
564
	CFileIO fo ( f );
565
	Utils::String ext = fo.extension ().lower();
565
	Utils::WString ext = fo.extension ().lower();
566
	if ( ext == "txt" )
566
	if ( ext == L"txt" )
567
		return fo.changeFileExtension("pck");
567
		return fo.changeFileExtension(L"pck").toString();
568
	else if ( ext == "xml" )
568
	else if ( ext == L"xml" )
569
		return fo.changeFileExtension("pck");
569
		return fo.changeFileExtension(L"pck").toString();
570
	else if ( ext == "bob" )
570
	else if ( ext == L"bob" )
571
		return fo.changeFileExtension("pbb");
571
		return fo.changeFileExtension(L"pbb").toString();
572
	else if ( ext == "bod" )
572
	else if ( ext == L"bod" )
573
		return fo.changeFileExtension("pbd");
573
		return fo.changeFileExtension(L"pbd").toString();
574
 
574
 
575
	return f;
575
	return f;
576
}
576
}
577
 
577
 
578
bool CCatFile::appendFile(const Utils::String &filename, const Utils::String &sTo, bool pck, bool bXor, Utils::String *sChangeTo)
578
bool CCatFile::appendFile(const Utils::String &filename, const Utils::String &sTo, bool pck, bool bXor, Utils::String *sChangeTo)
Line 784... Line 784...
784
}
784
}
785
 
785
 
786
Utils::String CCatFile::RenameFileExtension(SInCatFile *f)
786
Utils::String CCatFile::RenameFileExtension(SInCatFile *f)
787
{
787
{
788
	CFileIO fo(f->sFile);
788
	CFileIO fo(f->sFile);
789
	Utils::String ext = fo.extension().lower();
789
	Utils::WString ext = fo.extension().lower();
790
	if ( ext == "pck" )
790
	if ( ext == "pck" )
791
	{
791
	{
792
		Utils::String firstDir = f->sFile.findReplace("/", "\\").token("\\", 1).lower();
792
		Utils::String firstDir = f->sFile.findReplace("/", "\\").token("\\", 1).lower();
793
 
793
 
794
		if ( firstDir == "t" )
794
		if ( firstDir == "t" )
795
			return fo.changeFileExtension ( "xml" );
795
			return fo.changeFileExtension(L"xml").toString();
796
		else if ( firstDir == "director" )
796
		else if ( firstDir == "director" )
797
			return fo.changeFileExtension ( "xml" );
797
			return fo.changeFileExtension(L"xml").toString();
798
		return fo.changeFileExtension ( "txt" );
798
		return fo.changeFileExtension(L"txt").toString();
799
	}
799
	}
800
	else if ( ext == "pbb" )
800
	else if ( ext == "pbb" )
801
		return fo.changeFileExtension ( "bob" );
801
		return fo.changeFileExtension(L"bob").toString();
802
	else if ( ext == "pbd" )
802
	else if ( ext == "pbd" )
803
		return fo.changeFileExtension ( "bod" );
803
		return fo.changeFileExtension(L"bod").toString();
804
	return f->sFile;
804
	return f->sFile;
805
}
805
}
806
 
806
 
807
void CCatFile::findFiles(Utils::CStringList &files, const Utils::String &filemask) const
807
void CCatFile::findFiles(Utils::CStringList &files, const Utils::String &filemask) const
808
{
808
{
Line 896... Line 896...
896
		checkFile = checkFile.findReplace ( "//", "/" );
896
		checkFile = checkFile.findReplace ( "//", "/" );
897
		tofile = checkFile.token("/", checkFile.countToken("/"));
897
		tofile = checkFile.token("/", checkFile.countToken("/"));
898
 
898
 
899
		if ( !checkFile.contains(".") || preserve )
899
		if ( !checkFile.contains(".") || preserve )
900
		{
900
		{
901
			tofile = fo.filename();
901
			tofile = fo.filenameStr();
902
			todir = checkFile;
902
			todir = checkFile;
903
		}
903
		}
904
		else
904
		else
905
		{
905
		{
906
			todir = CFileIO(checkFile).dir();
906
			todir = CFileIO(checkFile).dirStr();
907
			tofile = CFileIO(checkFile).filename();
907
			tofile = CFileIO(checkFile).filenameStr();
908
		}
908
		}
909
	}
909
	}
910
 
910
 
911
	if ( tofile.empty() )
911
	if ( tofile.empty() )
912
	{
912
	{
913
		if ( !tofile.empty() )
913
		if ( !tofile.empty() )
914
			tofile += "/";
914
			tofile += "/";
915
		tofile += fo.filename();
915
		tofile += fo.filenameStr();
916
		todir = CFileIO(tofile).dir();
916
		todir = CFileIO(tofile).dirStr();
917
		tofile = CFileIO(tofile).filename();
917
		tofile = CFileIO(tofile).filenameStr();
918
	}
918
	}
919
	
919
	
920
	if ( preserve )
920
	if ( preserve )
921
	{
921
	{
922
		if ( !fo.dir().Compare(todir.right(- (int)fo.dir().length())) )
922
		if ( !fo.dir().Compare(todir.right(- (int)fo.dir().length())) )
923
		{
923
		{
924
			if ( !todir.empty() && todir.right(1) != "/" )
924
			if ( !todir.empty() && todir.right(1) != "/" )
925
				todir += "/";
925
				todir += "/";
926
			todir += fo.dir();
926
			todir += fo.dirStr();
927
		}
927
		}
928
	}
928
	}
929
 
929
 
930
	if ( tofile.empty() )
930
	if ( tofile.empty() )
931
		tofile = fo.filename();
931
		tofile = fo.filenameStr();
932
 
932
 
933
	bool bWritten = false;
933
	bool bWritten = false;
934
 
934
 
935
	// create the directory to extract to
935
	// create the directory to extract to
936
	if ( !todir.empty() && !CDirIO(todir).create() )
936
	if ( !todir.empty() && !CDirIO(todir).create() )
937
		m_iError = CATERR_CANTCREATEDIR;
937
		m_iError = CATERR_CANTCREATEDIR;
938
	else
938
	else
939
	{
939
	{
940
		Utils::String file = todir;
940
		Utils::WString file = todir;
941
		if ( !file.empty() )
941
		if ( !file.empty() )
942
			file += "/";
942
			file += L"/";
943
		file += tofile;
943
		file += tofile.toWString();
944
		file = file.findReplace("/", "\\");
944
		file = file.findReplace(L"/", L"\\");
945
		file = file.findReplace("\\\\", "\\");
945
		file = file.findReplace(L"\\\\", L"\\");
946
 
946
 
947
		CFileIO File(file.c_str());
947
		CFileIO File(file);
948
		if ( !File.startWrite() ) m_iError = CATERR_INVALIDDEST;
948
		if ( !File.startWrite() ) m_iError = CATERR_INVALIDDEST;
949
		else bWritten = File.write(data, size);
949
		else bWritten = File.write(data, size);
950
	}
950
	}
951
 
951
 
952
	delete data;
952
	delete data;