Subversion Repositories spk

Rev

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

Rev 112 Rev 114
Line 160... Line 160...
160
	return this->LoadFilesystem(dir, "", maxPatch);
160
	return this->LoadFilesystem(dir, "", maxPatch);
161
}
161
}
162
 
162
 
163
bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, const Utils::String &mod, int maxPatch)
163
bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, const Utils::String &mod, int maxPatch)
164
{
164
{
165
	m_sDir = dir;
165
	m_sDir = dir.findReplace("\\", "/");
166
 
166
 
167
	this->_clear();
167
	this->_clear();
-
 
168
 
-
 
169
	// if we are in the addon directory, then also read the previous directory
-
 
170
	Utils::String s = dir.token("/", -1);
-
 
171
	if ( !this->m_sAddon.empty() && dir.token("/", -1).Compare(this->m_sAddon) ) {
-
 
172
		//LoadFilesystem(dir.tokens("/", 1, -2), "", 0);
-
 
173
	}
168
 
174
 
169
	int number = 1;
175
	int number = 1;
170
	while ( CFileIO::Exists(dir + "/" + Utils::String::PadNumber(number, 2) + ".cat") )
176
	while ( CFileIO::Exists(dir + "/" + Utils::String::PadNumber(number, 2) + ".cat") )
171
	{
177
	{
172
		if ( maxPatch && maxPatch < number ) break;
178
		if ( maxPatch && maxPatch < number ) break;
Line 181... Line 187...
181
				this->_addModFile(CFileIO(c->Data()->sFile).fullFilename(), file + ".cat", m_pMap);
187
				this->_addModFile(CFileIO(c->Data()->sFile).fullFilename(), file + ".cat", m_pMap);
182
				m_bLoaded = true;
188
				m_bLoaded = true;
183
			}
189
			}
184
		}
190
		}
185
		++number;
191
		++number;
186
	}
192
	}
187
 
193
 
188
	// add all the files from the mod
194
	// add all the files from the mod
189
	if ( !mod.empty() )
195
	if ( !mod.empty() )
190
		this->addMod(mod);
196
		this->addMod(mod);
191
 
197
 
192
	// now add all the extracted data
198
	// now add all the extracted data
193
	this->_addDir(m_sDir, "");
199
	this->_addDir(m_sDir, "");
194
 
200
 
195
	return m_bLoaded;
201
	return m_bLoaded;
196
}
202
}
197
 
203
 
198
 
204
 
199
void CVirtualFileSystem::_addDir(const Utils::String &sStart, const Utils::String &sDir)
205
void CVirtualFileSystem::_addDir(const Utils::String &sStart, const Utils::String &sDir)
200
{
206
{
201
	CDirIO Dir(sStart + "/" + sDir);
207
	CDirIO Dir(sStart + "/" + sDir);
202
	CyStringList *list = Dir.DirList();
208
	CyStringList *list = Dir.DirList();
Line 204... Line 210...
204
		for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->next ) {
210
		for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->next ) {
205
			if ( CDirIO(Dir.Dir(strNode->str)).IsDir() ) _addDir(sStart, sDir + "/" + strNode->str.ToString());
211
			if ( CDirIO(Dir.Dir(strNode->str)).IsDir() ) _addDir(sStart, sDir + "/" + strNode->str.ToString());
206
			else if ( CFileIO(strNode->str).CheckFileExtension("cat") ) continue;
212
			else if ( CFileIO(strNode->str).CheckFileExtension("cat") ) continue;
207
			else if ( CFileIO(strNode->str).CheckFileExtension("dat") ) continue;
213
			else if ( CFileIO(strNode->str).CheckFileExtension("dat") ) continue;
208
			else this->_addFile(sDir + "/" + strNode->str.ToString(), Dir.File(strNode->str).ToString(), m_pMap);
214
			else this->_addFile(sDir + "/" + strNode->str.ToString(), Dir.File(strNode->str).ToString(), m_pMap);
-
 
215
		}
-
 
216
	}
-
 
217
}
-
 
218
 
-
 
219
 
-
 
220
void CVirtualFileSystem::_removeSameFile(const Utils::String &sFile, const Utils::String &sDest, const Utils::String &ext, FileList *pList)
-
 
221
{
-
 
222
	CFileIO F(sFile);
-
 
223
 
-
 
224
	Utils::String newFile = F.ChangeFileExtension(ext).ToString();
-
 
225
	newFile = newFile.lower();
-
 
226
 
-
 
227
	FileListItr itr = pList->find(newFile);
-
 
228
	if ( itr != pList->end() ) {
-
 
229
		if ( !CFileIO((*pList)[newFile]).dir().Compare(CFileIO(sDest).dir()) ) {
-
 
230
			pList->erase(newFile);
209
		}
231
		}
210
	}
232
	}
211
}
233
}
212
 
234
 
213
void CVirtualFileSystem::_addFile(const Utils::String &sFile, const Utils::String &sDest, FileList *pList)
235
void CVirtualFileSystem::_addFile(const Utils::String &sFile, const Utils::String &sDest, FileList *pList)
214
{
236
{
-
 
237
	Utils::String file = sFile.asFilename().removeIf(0, '/');
-
 
238
 
-
 
239
	// check file extension, remove any patching files in previous files
-
 
240
	CFileIO F(file);
-
 
241
	if ( F.CheckFileExtension("bob") || F.CheckFileExtension("pbd") || F.CheckFileExtension("bod") ) {
-
 
242
		_removeSameFile(file, sDest, "pbb", pList);
-
 
243
		_removeSameFile(file, sDest, "bob", pList);
-
 
244
		_removeSameFile(file, sDest, "pbd", pList);
-
 
245
	}
-
 
246
 
215
	(*pList)[sFile.asFilename().removeIf(0, '/').lower()] = sDest.findReplace("//", "/");
247
	(*pList)[file.lower()] = sDest.findReplace("//", "/");
216
}
248
}
217
void CVirtualFileSystem::_addModFile(const Utils::String &sFile, const Utils::String &sMod, FileList *pList)
249
void CVirtualFileSystem::_addModFile(const Utils::String &sFile, const Utils::String &sMod, FileList *pList)
218
{
250
{
219
	this->_addFile(sFile, sMod + "::" + sFile, pList);
251
	this->_addFile(sFile, sMod + "::" + sFile, pList);
220
}
252
}
Line 312... Line 344...
312
		}
344
		}
313
		FileListItr itr = m_pModMap->find(CFileIO(toFile).fullFilename().lower().c_str());
345
		FileListItr itr = m_pModMap->find(CFileIO(toFile).fullFilename().lower().c_str());
314
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).fullFilename().lower().c_str());
346
		if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).fullFilename().lower().c_str());
315
		if ( itr != m_pModMap->end() ) return itr->second;
347
		if ( itr != m_pModMap->end() ) return itr->second;
316
	}
348
	}
-
 
349
 
317
	else if ( m_pMap && !m_pMap->empty() ) {
350
	if ( m_pMap && !m_pMap->empty() ) {
318
		if ( !m_sAddon.empty() ) {
351
		if ( !m_sAddon.empty() ) {
319
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilename().lower().c_str());
352
			FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilename().lower().c_str());
320
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + "/" + file)).fullFilename().lower().c_str());
353
			if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + "/" + file)).fullFilename().lower().c_str());
321
			if ( aitr != m_pMap->end() ) return aitr->second;
354
			if ( aitr != m_pMap->end() ) return aitr->second;
322
		}
355
		}
Line 528... Line 561...
528
		m_pTexts = new CTextDB();
561
		m_pTexts = new CTextDB();
529
	}
562
	}
530
 
563
 
531
	if ( m_pModTexts ) delete m_pModTexts;
564
	if ( m_pModTexts ) delete m_pModTexts;
532
	m_pModTexts = new CTextDB();
565
	m_pModTexts = new CTextDB();
533
}
566
}
534
 
567
 
535
Utils::CStringList *CVirtualFileSystem::_updateList(const Utils::String &typesFile, int iTextPos)
568
Utils::CStringList *CVirtualFileSystem::_updateList(const Utils::String &typesFile, int iTextPos)
536
{
569
{
537
	Utils::CStringList *list = new Utils::CStringList();
570
	Utils::CStringList *list = new Utils::CStringList();
538
 
571
 
Line 746... Line 779...
746
		_lBodiesSections->pushBack("SBTYPE_RADAR", "SBTYPE_RADAR");
779
		_lBodiesSections->pushBack("SBTYPE_RADAR", "SBTYPE_RADAR");
747
		_lBodiesSections->pushBack("SBTYPE_CONTAINER", "SBTYPE_CONTAINER");
780
		_lBodiesSections->pushBack("SBTYPE_CONTAINER", "SBTYPE_CONTAINER");
748
		_lBodiesSections->pushBack("SBTYPE_DISPLAY", "SBTYPE_DISPLAY");
781
		_lBodiesSections->pushBack("SBTYPE_DISPLAY", "SBTYPE_DISPLAY");
749
		_lBodiesSections->pushBack("SBTYPE_DOCKPOINT", "SBTYPE_DOCKPOINT");
782
		_lBodiesSections->pushBack("SBTYPE_DOCKPOINT", "SBTYPE_DOCKPOINT");
750
		_lBodiesSections->pushBack("SBTYPE_SMALLJET", "SBTYPE_SMALLJET");
783
		_lBodiesSections->pushBack("SBTYPE_SMALLJET", "SBTYPE_SMALLJET");
-
 
784
	}
-
 
785
}
-
 
786
 
-
 
787
 
-
 
788
/////////////////////////////////////////////////////////////////////////////////////////
-
 
789
//	DEBUG Functions
-
 
790
 
-
 
791
 
-
 
792
void CVirtualFileSystem::DEBUG_LogContents(const Utils::String &sFile)
-
 
793
{
-
 
794
	CFileIO File(sFile);
-
 
795
 
-
 
796
	if ( File.startWrite() ) {
-
 
797
		if ( m_pMap ) {
-
 
798
			for(FileListItr itr = m_pMap->begin(); itr != m_pMap->end(); itr++) {
-
 
799
				Utils::String line = itr->first + " => " + itr->second + "\r\n";
-
 
800
				File.write(line.c_str(), line.length());
-
 
801
			}
-
 
802
		}
-
 
803
 
-
 
804
		File.close();
751
	}
805
	}
752
}
806
}
753
 
807
 
754
} //NAMESPACE
808
} //NAMESPACE