Subversion Repositories spk

Rev

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

Rev 50 Rev 51
Line 806... Line 806...
806
	// no file to read from
806
	// no file to read from
807
	if ( m_sFilename.Empty() )
807
	if ( m_sFilename.Empty() )
808
		return false;
808
		return false;
809
 
809
 
810
	// now open the file
810
	// now open the file
811
	FILE *id = fopen ( m_sFilename.c_str(), "rb" );
811
	std::fstream stream(m_sFilename.ToString().c_str(), std::ios::in | std::ios::binary);
812
	if ( !id )
-
 
813
		return false;
812
	if ( !stream.is_open() ) return false;
814
 
813
 
815
	// read the header
814
	// read the header
816
	CSpkFile::GetEndOfLine ( id, NULL, false );
815
	CBaseFile::readEndOfLine(stream, NULL, false);
817
	// skip past values
816
	// skip past values
818
	fseek ( id, 4, SEEK_CUR );
-
 
819
	fseek ( id, m_SHeader.lComprLen, SEEK_CUR );
817
	stream.seekg(4 + m_SHeader.lComprLen, std::ios::cur);
820
 
818
 
821
	bool ret = false;
819
	bool ret = false;
822
	for ( CListNode<SMultiSpkFile> *node = m_lFiles.Front(); node; node = node->next() )
820
	for ( CListNode<SMultiSpkFile> *node = m_lFiles.Front(); node; node = node->next() ) {
823
	{
-
 
824
		SMultiSpkFile *it = node->Data();
821
		SMultiSpkFile *it = node->Data();
825
		if ( it == ms )
822
		if ( it == ms )
826
		{
823
		{
827
			if ( !ms->pFile )
824
			if ( !ms->pFile )
828
			{
825
			{
829
				if ( ms->iType == TYPE_XSP )
826
				if ( ms->iType == TYPE_XSP )
830
					ms->pFile = new CXspFile;
827
					ms->pFile = new CXspFile;
831
				else
828
				else
832
					ms->pFile = new CSpkFile;
829
					ms->pFile = new CSpkFile;
833
			}
830
			}
834
			ret = it->pFile->ReadFile ( id, type, NULL );
831
			ret = it->pFile->readFile(stream, type, NULL);
835
			break;
832
			break;
836
		}
833
		}
837
		else
834
		else
838
			fseek ( id, it->lSize, SEEK_CUR );
835
			stream.seekg(it->lSize, std::ios::cur);
839
	}
836
	}
840
 
837
 
841
	fclose ( id );
838
	stream.clear();
842
 
-
 
843
	return ret;
839
	return ret;
844
}
840
}
845
 
841
 
846
bool CMultiSpkFile::ReadAllPackages( int type, CLinkList<CBaseFile> *addToList )
842
bool CMultiSpkFile::ReadAllPackages( int type, CLinkList<CBaseFile> *addToList )
847
{
843
{
848
	// no file to read from
844
	// no file to read from
849
	if ( m_sFilename.Empty() )
845
	if ( m_sFilename.Empty() )
850
		return false;
846
		return false;
851
 
847
 
852
	// now open the file
848
	// now open the file
853
	FILE *id = fopen ( m_sFilename.c_str(), "rb" );
849
	std::fstream stream(m_sFilename.ToString().c_str(), std::ios::in | std::ios::binary);
854
	if ( !id )
-
 
855
		return false;
850
	if ( !stream.is_open() ) return false;
856
 
851
 
857
	// read the header
852
	// read the header
858
	CSpkFile::GetEndOfLine ( id, NULL, false );
853
	CBaseFile::readEndOfLine(stream, NULL, false);
859
	// skip past values
854
	// skip past values
860
	fseek ( id, 4, SEEK_CUR );
-
 
861
	fseek ( id, m_SHeader.lComprLen, SEEK_CUR );
855
	stream.seekg(4 + m_SHeader.lComprLen, std::ios::cur);
862
 
856
 
863
	for ( CListNode<SMultiSpkFile> *node = m_lFiles.Front(); node; node = node->next() )
857
	for ( CListNode<SMultiSpkFile> *node = m_lFiles.Front(); node; node = node->next() ) {
864
	{
-
 
865
		SMultiSpkFile *ms = node->Data();
858
		SMultiSpkFile *ms = node->Data();
866
		CBaseFile *package = NULL;
859
		CBaseFile *package = NULL;
867
		if ( ms->iType == TYPE_XSP )
860
		if ( ms->iType == TYPE_XSP )
868
			package = new CXspFile;
861
			package = new CXspFile;
869
		else
862
		else
870
			package = new CSpkFile;
863
			package = new CSpkFile;
871
 
864
 
872
		if ( !addToList )
865
		if ( !addToList ) {
873
		{
-
 
874
			if ( ms->pFile )
866
			if ( ms->pFile ) {
875
			{
-
 
876
				delete package;
867
				delete package;
877
				package = ms->pFile;
868
				package = ms->pFile;
878
			}
869
			}
879
		}
870
		}
880
 
871
 
881
		if ( !package->IsFullyLoaded() )
872
		if ( !package->IsFullyLoaded() ) {
882
		{
-
 
883
			long tell = ftell ( id );
873
			long tell = stream.tellg();
884
			package->ReadFile ( id, type, NULL );
874
			package->readFile(stream, type, NULL);
885
 
875
 
886
			if ( addToList )
876
			if ( addToList ) {
887
			{
-
 
888
				addToList->push_back(package);
877
				addToList->push_back(package);
889
				package->SetEnabled(ms->bOn);
878
				package->SetEnabled(ms->bOn);
890
			}
879
			}
891
			else if ( package )
880
			else if ( package )
892
				ms->pFile = package;
881
				ms->pFile = package;
893
 
882
 
894
			// move to correct position in file for next stream of data
883
			// move to correct position in file for next stream of data
895
			// should be fine, this is more of a failsafe
884
			// should be fine, this is more of a failsafe
896
			rewind ( id );
-
 
897
			fseek ( id, tell, SEEK_CUR );
885
			stream.seekg(tell, std::ios::beg);
898
		}
886
		}
899
		fseek ( id, ms->lSize, SEEK_CUR );
887
		stream.seekg(ms->lSize, std::ios::cur);
900
	}
888
	}
901
 
889
 
902
	fclose ( id );
890
	stream.close();
903
 
-
 
904
	return true;
891
	return true;
905
}
892
}
906
 
893
 
907
 
894
 
908
SMultiSpkFile *CMultiSpkFile::FindFile ( CyString name )
895
SMultiSpkFile *CMultiSpkFile::FindFile ( CyString name )