Subversion Repositories spk

Rev

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

Rev 84 Rev 85
Line 20... Line 20...
20
	if ( m_bCatChanged ) {
20
	if ( m_bCatChanged ) {
21
		WriteCatFile ();
21
		WriteCatFile ();
22
		m_fCatFile.close();
22
		m_fCatFile.close();
23
	}
23
	}
24
 
24
 
-
 
25
	_clearFiles();
-
 
26
 
-
 
27
	if ( m_sData ) delete []m_sData;
-
 
28
}
-
 
29
 
-
 
30
void CCatFile::_clearFiles()
-
 
31
{
25
	for ( SInCatFile *c = m_lFiles.First(); c; c = m_lFiles.Next() )
32
	for ( SInCatFile *c = m_lFiles.First(); c; c = m_lFiles.Next() )
26
	{
33
	{
27
		if ( c->sData )
34
		if ( c->sData )
28
			delete []c->sData;
35
			delete []c->sData;
29
		delete c;
36
		delete c;
30
	}
37
	}
31
 
38
 
32
	if ( m_sData ) delete []m_sData;
-
 
33
 
-
 
34
	m_lFiles.clear();
39
	m_lFiles.clear();
35
}
40
}
36
 
41
 
37
bool CCatFile::IsAddonDir(CyString dir)
42
bool CCatFile::IsAddonDir(CyString dir)
38
{
43
{
Line 75... Line 80...
75
	if ( readtype == CATREAD_JUSTCONTENTS ) create = false;
80
	if ( readtype == CATREAD_JUSTCONTENTS ) create = false;
76
 
81
 
77
	// first check if the dat file exists and opens
82
	// first check if the dat file exists and opens
78
	bool created = false;
83
	bool created = false;
79
	if ( readtype != CATREAD_JUSTCONTENTS ) {
84
	if ( readtype != CATREAD_JUSTCONTENTS ) {
80
		std::ifstream file(datfile);
-
 
81
		if ( !file.good() ) {
85
		if ( !CFileIO::Exists(datfile) ) {
82
			if ( create ) created = true;
86
			if ( create ) created = true;
83
			else		  return CATERR_NODATFILE;
87
			else		  return CATERR_NODATFILE;
84
		}
88
		}
85
 
-
 
86
		if ( file.is_open() ) file.close();
-
 
87
	}
89
	}
88
 
90
 
89
	// now open the cat file to read
91
	// now open the cat file to read
90
	CFileIO File(catfile);
92
	CFileIO File(catfile);
91
	if ( !File.startRead() ) {
93
	if ( !File.startRead() ) {
Line 134... Line 136...
134
	File.close();
136
	File.close();
135
 
137
 
136
	if ( readtype != CATREAD_CAT ) {
138
	if ( readtype != CATREAD_CAT ) {
137
		if ( !DecryptData () ) return CATERR_DECRYPT;
139
		if ( !DecryptData () ) return CATERR_DECRYPT;
138
		m_sData[File.fileSize()] = 0;
140
		m_sData[File.fileSize()] = 0;
139
		ReadFiles ();
141
		readFiles ();
140
	}
142
	}
141
 
143
 
142
	m_sAddonDir = addon;
144
	m_sAddonDir = addon;
143
 
145
 
144
	m_fCatFile.Open ( catfile );
146
	m_fCatFile.Open ( catfile );
Line 151... Line 153...
151
		if ( m_fDatFile.startRead() ) {
153
		if ( m_fDatFile.startRead() ) {
152
			compare = m_fDatFile.fileSize();
154
			compare = m_fDatFile.fileSize();
153
			m_fDatFile.close();
155
			m_fDatFile.close();
154
		}
156
		}
155
		SInCatFile *c = m_lFiles.Back ()->Data();
157
		SInCatFile *c = m_lFiles.Back ()->Data();
156
		//if ( (c->lSize + c->lOffset) != compare ) return CATERR_MISMATCH;
158
		if ( (c->lSize + c->lOffset) != compare ) {
-
 
159
//			return CATERR_MISMATCH;
-
 
160
		}
157
	}
161
	}
158
 
162
 
159
	if ( readtype >= CATREAD_DAT ) LoadDatFile ();
163
	if ( readtype >= CATREAD_DAT ) LoadDatFile ();
160
 
164
 
161
	return CATERR_NONE;
165
	return CATERR_NONE;
Line 214... Line 218...
214
		}
218
		}
215
		m_fDatFile.close();
219
		m_fDatFile.close();
216
	}
220
	}
217
}
221
}
218
 
222
 
219
bool CCatFile::ReadFiles ()
223
bool CCatFile::readFiles ()
220
{
224
{
221
	int num = 0;
-
 
222
 
-
 
223
	size_t offset = 0;
225
	size_t offset = 0;
-
 
226
	int max = 0;
-
 
227
 
-
 
228
	Utils::String *lines = Utils::String(m_sData).tokenise("\n", &max);
-
 
229
 
-
 
230
	_clearFiles();
-
 
231
 
-
 
232
	if ( lines && max ) {
-
 
233
		int start = 1;
-
 
234
		_sReadFilename = lines[0];
-
 
235
		if ( _sReadFilename.token(" ", -1).isNumber() ) {
-
 
236
			_sReadFilename.clear();
-
 
237
			start = 0;
-
 
238
		}
224
 
239
 
-
 
240
		for(int i = start; i < max; i++) {
-
 
241
			Utils::String l = lines[i];
-
 
242
 
-
 
243
			SInCatFile *catfile = new SInCatFile;
-
 
244
 
-
 
245
			catfile->lSize = static_cast<size_t>(l.token(" ", -1).toLong());
-
 
246
			catfile->sFile = l.tokens(" ", 1, -2);
-
 
247
			catfile->lOffset = offset;
-
 
248
			catfile->sData = 0;
-
 
249
 
-
 
250
			offset += catfile->lSize;
-
 
251
 
-
 
252
			m_lFiles.push_back ( catfile );
-
 
253
		}
-
 
254
	}
-
 
255
 
-
 
256
	CLEANSPLIT(lines, max);
-
 
257
/*
225
	unsigned char *data = m_sData;
258
	unsigned char *data = m_sData;
226
	int spacePos = -1;
259
	int spacePos = -1;
227
	while ( m_sData[num] != '\0' ) {
260
	while ( m_sData[num] != '\0' ) {
228
		if ( m_sData[num] == '\n' ) {
261
		if ( m_sData[num] == '\n' ) {
229
			m_sData[num] = 0;
262
			m_sData[num] = 0;
Line 259... Line 292...
259
		}
292
		}
260
		else if ( m_sData[num] == ' ' )
293
		else if ( m_sData[num] == ' ' )
261
			spacePos = num;
294
			spacePos = num;
262
		++num;
295
		++num;
263
	}
296
	}
264
 
297
*/
265
	return true;
298
	return true;
266
}
299
}
267
 
300
 
268
bool CCatFile::DecryptData ( unsigned char *data, size_t size )
301
bool CCatFile::DecryptData ( unsigned char *data, size_t size )
269
{
302
{
Line 439... Line 472...
439
 
472
 
440
bool CCatFile::WriteCatFile ()
473
bool CCatFile::WriteCatFile ()
441
{
474
{
442
	if ( (m_bCreate) && (m_lFiles.empty()) ) return false;
475
	if ( (m_bCreate) && (m_lFiles.empty()) ) return false;
443
 
476
 
444
	Utils::String cat = m_fCatFile.filename() + "\n";
477
	Utils::String cat = m_fDatFile.filename() + "\n";
445
	for ( CListNode<SInCatFile> *node = m_lFiles.Front(); node; node = node->next() ) {
478
	for ( CListNode<SInCatFile> *node = m_lFiles.Front(); node; node = node->next() ) {
446
		if ( !node->Data() ) continue;
479
		if ( !node->Data() ) continue;
447
		if ( node->Data()->sFile.Empty() ) continue;
480
		if ( node->Data()->sFile.Empty() ) continue;
448
		Utils::String str = node->Data()->sFile.ToString();
481
		Utils::String str = node->Data()->sFile.ToString();
449
		cat += str.findReplace("/", "\\").findReplace("\\\\", "\\") + " " + (long)node->Data()->lSize + "\n";
482
		cat += str.findReplace("/", "\\").findReplace("\\\\", "\\") + " " + (long)node->Data()->lSize + "\n";
Line 556... Line 589...
556
	bool append = false;
589
	bool append = false;
557
 
590
 
558
	SInCatFile *f = new SInCatFile;
591
	SInCatFile *f = new SInCatFile;
559
	f->sData = 0;
592
	f->sData = 0;
560
	f->lOffset = this->GetEndOffset();
593
	f->lOffset = this->GetEndOffset();
561
 
594
	
562
	bool dofile = true;
595
	bool dofile = true;
563
 
596
 
564
	if ( !m_lFiles.size() )	{
597
	if ( !m_lFiles.size() )	{
565
		CLog::logf(CLog::Log_IO, 3, "CCatFile::AppendFile() no existing files found, wipeing the existing dat file");
598
		CLog::logf(CLog::Log_IO, 3, "CCatFile::AppendFile() no existing files found, wipeing the existing dat file");
566
		m_fDatFile.WipeFile();
599
		m_fDatFile.WipeFile();
Line 892... Line 925...
892
	if ( bWritten ) this->ClearError();
925
	if ( bWritten ) this->ClearError();
893
 
926
 
894
	return bWritten;
927
	return bWritten;
895
}
928
}
896
 
929
 
-
 
930
const Utils::String &CCatFile::internalDatFilename() const
-
 
931
{
-
 
932
	return _sReadFilename;
-
 
933
}
-
 
934
 
897
CyString CCatFile::GetErrorString ()
935
CyString CCatFile::GetErrorString ()
898
{
936
{
899
	switch ( m_iError )
937
	switch ( m_iError )
900
	{
938
	{
901
		case CATERR_NONE:
939
		case CATERR_NONE: