Subversion Repositories spk

Rev

Rev 85 | Rev 102 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed


#include "VirtualFileSystem.h"
#include "File_IO.h"
#include "CatFile.h"
#include "XspFile.h"
#include "TextDB.h"

#include "Packages.h"
#include "Utils/StringList.h"

#define DELETELIST(list) if ( list ) { list->MemoryClear(); delete list; }

namespace SPK {

CVirtualFileSystem::CVirtualFileSystem() : _lShields(NULL),
        _lLasers(NULL),
        _lMissiles(NULL),
        _lCockpits(NULL),
        _lComponentSections(NULL),
        _lDummySections(NULL),
        _lBodiesSections(NULL)
{
        m_bLoaded = false;
        m_pMap = new FileList;
        m_pModMap = new FileList;

        m_pTexts = new CTextDB();
        m_pModTexts = new CTextDB();

        m_sAddon = "";

        m_iLang = 0;
}

CVirtualFileSystem::~CVirtualFileSystem(void)
{
        if ( m_pMap )           delete m_pMap;
        if ( m_pModMap )        delete m_pModMap;

        if ( m_pTexts )         delete m_pTexts;
        if ( m_pModTexts )  delete m_pModTexts;

        DELETELIST(_lShields);
        DELETELIST(_lLasers);
        DELETELIST(_lMissiles);
        DELETELIST(_lCockpits);
        DELETELIST(_lComponentSections);
        DELETELIST(_lDummySections);
        DELETELIST(_lBodiesSections);
}

void CVirtualFileSystem::setLanguage(int iLang)
{
        m_iLang = iLang;
}

Utils::String CVirtualFileSystem::firstShield()
{
        if ( !_lShields || _lShields->empty() ) _updateShields();
        return _returnText(_lShields->First());
}

Utils::String CVirtualFileSystem::nextShield()
{
        return _returnText(_lShields->Next());
}

Utils::String CVirtualFileSystem::firstComponentSection()
{
        if ( !_lComponentSections || _lComponentSections->empty() ) _updateComponentSections();
        return _returnLine(_lComponentSections->First());
}

Utils::String CVirtualFileSystem::nextComponentSection()
{
        return _returnLine(_lComponentSections->Next());
}

Utils::String CVirtualFileSystem::firstDummySection()
{
        if ( !_lDummySections || _lDummySections->empty() ) _updateDummySections();
        return _returnLine(_lDummySections->First());
}

Utils::String CVirtualFileSystem::nextDummySection()
{
        return _returnLine(_lDummySections->Next());
}

Utils::String CVirtualFileSystem::firstBodiesSection()
{
        if ( !_lBodiesSections || _lBodiesSections->empty() ) _updateBodiesSections();
        return _returnLine(_lBodiesSections->First());
}

Utils::String CVirtualFileSystem::nextBodiesSection()
{
        return _returnLine(_lBodiesSections->Next());
}

std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextLaser()
{
        return _returnPair(_lLasers->Next());
}

std::pair<Utils::String, Utils::String>  CVirtualFileSystem::firstLaser()
{
        if ( !_lLasers || _lLasers->empty() ) _updateLasers();
        return _returnPair(_lLasers->First());
}

std::pair<Utils::String, Utils::String>  CVirtualFileSystem::firstMissile()
{
        if ( !_lMissiles || _lMissiles->empty() ) _updateMissiles();
        return _returnPair(_lMissiles->First());
}

std::pair<Utils::String, Utils::String> CVirtualFileSystem::nextMissile()
{
        return _returnPair(_lMissiles->Next());
}

Utils::String CVirtualFileSystem::firstCockpit()
{
        if ( !_lCockpits || _lCockpits->empty() ) _updateCockpits();
        return _returnID(_lCockpits->First());
}

Utils::String CVirtualFileSystem::nextCockpit()
{
        return _returnID(_lCockpits->Next());
}

std::pair<Utils::String, Utils::String> CVirtualFileSystem::_returnPair(Utils::SStringList *s)
{
        if ( s && !s->data.empty() && !s->data.left(8).Compare("ReadText") ) return std::make_pair<Utils::String, Utils::String>(s->str, s->data);
        if ( s ) return std::make_pair<Utils::String, Utils::String>(s->str, s->str.token(";", -2));
        return std::make_pair<Utils::String, Utils::String>(Utils::String::Null(), Utils::String::Null());
}

Utils::String CVirtualFileSystem::_returnText(Utils::SStringList *s)
{
        if ( s && !s->data.empty() && !s->data.left(8).Compare("ReadText") ) return s->data;
        if ( s ) return s->str.token(";", -2);
        return Utils::String::Null();
}

Utils::String CVirtualFileSystem::_returnID(Utils::SStringList *s)
{
        if ( s ) return s->str.token(";", -2);
        return Utils::String::Null();
}

Utils::String CVirtualFileSystem::_returnLine(Utils::SStringList *s)
{
        if ( s ) return s->str;
        return Utils::String::Null();
}


bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, int maxPatch)
{
        return this->LoadFilesystem(dir, "", maxPatch);
}

bool CVirtualFileSystem::LoadFilesystem(const Utils::String &dir, const Utils::String &mod, int maxPatch)
{
        m_sDir = dir;

        this->_clear();

        int number = 1;
        while ( CFileIO(CyString(dir) + "/" + CyString::Number(number).PadNumber(2) + ".cat").ExistsOld() )
        {
                if ( maxPatch && maxPatch < number ) break;
                CyString file = CyString(dir) + "/" + CyString::Number(number).PadNumber(2);
                if ( !CFileIO(file + ".dat").ExistsOld() )
                        break;

                CCatFile cat;
                if ( cat.Open(file + ".cat", m_sAddon, CATREAD_JUSTCONTENTS, false) == CATERR_NONE )
                {
                        for ( CListNode<SInCatFile> *c = cat.GetFiles()->Front(); c; c = c->next() ) {
                                this->_addModFile(CFileIO(c->Data()->sFile).GetFullFilename().ToString(), CyString(file + ".cat").ToString(), m_pMap);
                                m_bLoaded = true;
                        }
                }
                ++number;
        }

        // add all the files from the mod
        if ( !mod.empty() )
                this->addMod(mod);

        // now add all the extracted data
        this->_addDir(m_sDir, "");

        return m_bLoaded;
}


void CVirtualFileSystem::_addDir(const Utils::String &sStart, const Utils::String &sDir)
{
        CDirIO Dir(sStart + "/" + sDir);
        CyStringList *list = Dir.DirList();
        if ( list ) {
                for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->next ) {
                        if ( CDirIO(Dir.Dir(strNode->str)).IsDir() ) _addDir(sStart, sDir + "/" + strNode->str.ToString());
                        else if ( CFileIO(strNode->str).CheckFileExtension("cat") ) continue;
                        else if ( CFileIO(strNode->str).CheckFileExtension("dat") ) continue;
                        else this->_addFile(sDir + "/" + strNode->str.ToString(), Dir.File(strNode->str).ToString(), m_pMap);
                }
        }
}

void CVirtualFileSystem::_addFile(const Utils::String &sFile, const Utils::String &sDest, FileList *pList)
{
        (*pList)[sFile.asFilename().removeIf(0, '/').lower()] = sDest.findReplace("//", "/");
}
void CVirtualFileSystem::_addModFile(const Utils::String &sFile, const Utils::String &sMod, FileList *pList)
{
        this->_addFile(sFile, sMod + "::" + sFile, pList);
}

bool CVirtualFileSystem::loadMod(const Utils::String &mod)
{
        bool loaded = false;

        if ( !m_pModMap ) m_pModMap = new FileList;

        CCatFile cat;
        if ( CCatFile::Opened(cat.Open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
        {
                for ( CListNode<SInCatFile> *c = cat.GetFiles()->Front(); c; c = c->next() ) {
                        this->_addModFile(CFileIO(c->Data()->sFile).GetFullFilename().ToString(), mod, m_pModMap);
                        loaded = true;
                }
        }

        return loaded;
}

bool CVirtualFileSystem::addMod(const Utils::String &mod)
{
        bool loaded = false;

        if ( !m_pMap ) m_pMap = new FileList;

        CCatFile cat;
        if ( CCatFile::Opened(cat.Open(mod, m_sAddon, CATREAD_JUSTCONTENTS, false), false) )
        {
                for ( CListNode<SInCatFile> *c = cat.GetFiles()->Front(); c; c = c->next() )
                {
                        this->_addModFile(CFileIO(c->Data()->sFile).GetFullFilename().ToString(), mod, m_pMap);
                        loaded = true;
                }
        }

        return loaded;
}

bool CVirtualFileSystem::textExists(int iLang, int iPage, int iID) const
{
        if ( iLang <= 0 ) iLang = m_iLang;

        if ( m_pTexts ) {
                if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->exists(iLang, iPage, iID);
        }
        if ( m_pModTexts ) {
                if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->exists(iLang, iPage, iID);
        }

        return false;
}

Utils::String CVirtualFileSystem::findText(int iLang, int iPage, int iID) const
{
        if ( iLang <= 0 ) iLang = m_iLang;

        if ( m_pTexts ) {
                if ( m_pTexts->exists(iLang, iPage, iID) ) return m_pTexts->get(iLang, iPage, iID);
        }
        if ( m_pModTexts ) {
                if ( m_pModTexts->exists(iLang, iPage, iID) ) return m_pModTexts->get(iLang, iPage, iID);
        }

        return Utils::String("ReadText") + (long)iPage + "-" + (long)iID;
}

bool CVirtualFileSystem::isFileAvailable(const Utils::String &file)
{
        return !this->_findFile(file).empty();
}

Utils::String CVirtualFileSystem::_findFile(const Utils::String &file)
{
        Utils::String toFile = file.findReplace("\\", "/").lower();

        if ( m_pModMap && !m_pModMap->empty() ) {
                if ( !m_sAddon.empty() ) {
                        FileListItr aitr = m_pModMap->find(CFileIO(m_sAddon + "/" + toFile).GetFullFilename().ToLower().c_str());
                        if ( aitr == m_pModMap->end() ) aitr = m_pModMap->find(CFileIO(_convertExtension(m_sAddon + "/" + toFile)).GetFullFilename().ToLower().c_str());
                        if ( aitr != m_pModMap->end() ) return aitr->second;
                }
                FileListItr itr = m_pModMap->find(CFileIO(toFile).GetFullFilename().ToLower().c_str());
                if ( itr == m_pModMap->end() ) itr = m_pModMap->find(CFileIO(_convertExtension(toFile)).GetFullFilename().ToLower().c_str());
                if ( itr != m_pModMap->end() ) return itr->second;
        }
        else if ( m_pMap && !m_pMap->empty() ) {
                if ( !m_sAddon.empty() ) {
                        FileListItr aitr = m_pMap->find(CFileIO(m_sAddon + "/" + toFile).fullFilename().lower().c_str());
                        if ( aitr == m_pMap->end() ) aitr = m_pMap->find(CFileIO(_convertExtension(m_sAddon + "/" + file)).fullFilename().lower().c_str());
                        if ( aitr != m_pMap->end() ) return aitr->second;
                }
                FileListItr itr = m_pMap->find(CFileIO(file).GetFullFilename().ToLower().c_str());
                if ( itr == m_pMap->end() ) itr = m_pMap->find(CFileIO(_convertExtension(file)).GetFullFilename().ToLower().c_str());
                if ( itr != m_pMap->end() ) return itr->second;
        }
        return "";
}

Utils::String CVirtualFileSystem::_extractFromCat(const Utils::String &sCat, const Utils::String &sFile, const Utils::String &sTo)
{
        CCatFile catFile;
        if ( catFile.Open(sCat, m_sAddon, CATREAD_CATDECRYPT, false) == CATERR_NONE )
        {
                // check for the file
                if ( catFile.ExtractFile(sFile, sTo) ) return sTo;
                if ( catFile.Error() == CATERR_INVALIDDEST || catFile.Error() == CATERR_CANTCREATEDIR ) {
                        if ( catFile.ExtractFile(sFile) ) return sFile;
                }
        }

        return "";
}

Utils::String CVirtualFileSystem::_extract(const Utils::String &sFile, const Utils::String &sTo)
{
        // check if we need to unpack the file
        if ( CCatFile::CheckPackedExtension(sFile) ) {
                CFileIO File(sFile);
                C_File f(CyString(File.fullFilename()));
                if ( !f.readFromFile(File) ) return "";
                if ( !f.UnPCKFile() ) return "";
                if ( !f.WriteToFile(sTo) ) return "";
                return sTo;
        }
        return sFile;
}

Utils::String CVirtualFileSystem::ExtractGameFile(const Utils::String &file, const Utils::String &to)
{
        Utils::String sIn = _findFile(file);
        Utils::String sFile = file;

        if ( sIn.empty() ) return "";

        if ( sIn.isin("::") ) {
                sFile = sIn.token("::", 2);
                sIn = sIn.token("::", 1);
                return _extractFromCat(sIn, sFile, to);
        }
        
        return _extract(sIn, to);
}

Utils::String CVirtualFileSystem::_convertExtension(const Utils::String &sFile)
{
        CFileIO File(sFile);
        if ( File.CheckFileExtension("pck") ) {
                return File.ChangeFileExtension("xml").ToString();
        }
        else if ( File.CheckFileExtension("xml") ) {
                return File.ChangeFileExtension("pck").ToString();
        }
        else if ( File.CheckFileExtension("pbb") ) {
                return File.ChangeFileExtension("bob").ToString();
        }
        else if ( File.CheckFileExtension("bob") ) {
                return File.ChangeFileExtension("pbb").ToString();
        }
        else if ( File.CheckFileExtension("pbd") ) {
                return File.ChangeFileExtension("bod").ToString();
        }
        else if ( File.CheckFileExtension("bod") ) {
                return File.ChangeFileExtension("pbd").ToString();
        }

        return sFile;
}

CyStringList *CVirtualFileSystem::GetTShipsEntries()
{
        Utils::String sTo = this->ExtractGameFile("types/tships.pck", CPackages::tempDirectory() + "/tships.txt");
        if ( !sTo.empty() ) {
                CFileIO TShips(sTo);
                if ( TShips.exists() )
                {
                        CyStringList *lines = TShips.ReadLinesStr();
                        if ( lines )
                        {
                                // remove any commands, blank lines, and start
                                // and put the id as the data
                                int entries = -1;
                                for ( SStringList *str = lines->Head(); str; str = str->next )
                                {
                                        str->str.RemoveFirstSpace();
                                        str->str.RemoveChar(9);
                                        str->str.RemoveChar('\r');
                                        str->str.RemoveChar('\n');
                                        if ( str->str.Empty() )
                                        {
                                                str->remove = true;
                                                continue;
                                        }

                                        if ( str->str[0] == '/' )
                                        {
                                                str->remove = true;
                                                continue;
                                        }

                                        if ( entries == -1 )
                                        {
                                                entries = str->str.GetToken(";", 2, 2).ToInt();
                                                str->remove = true;
                                                continue;
                                        }

                                        // hopefully we now have a valid tships line
                                        int num = -1;
                                        while ( str->data.Empty() )
                                                str->data = str->str.GetToken(";", num--, (num + 2));
                                }
                        }
                        // remove the tmp file
                        TShips.remove();

                        if ( lines )
                                lines->RemoveMarked();
                        return lines;
                }
        }

        return NULL;
}

C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType)
{
        return this->extractGameFileToPackage(pPackage, sFile, iFileType, sFile);
}

C_File *CVirtualFileSystem::extractGameFileToPackage(CBaseFile *pPackage, const Utils::String &sFile, FileType iFileType, const Utils::String &sTo)
{
        Utils::String to = this->ExtractGameFile(sFile, CPackages::tempDirectory() + "tmp.dat");
        if ( !to.empty() ) {
                CFileIO File(to);

                C_File *f = pPackage->AddFile(CFileIO(sTo).GetFilename(), CFileIO(sTo).GetDir(), iFileType);
                if ( f ) {
                        if ( f->ReadFromFile(CPackages::GetTempDirectory() + "tmp.dat") ) {
                                File.remove();
                                return f;
                        }
                }

                File.remove();
        }

        return NULL;
}

Utils::String CVirtualFileSystem::getTShipsEntry(const Utils::String &sId)
{
        CyStringList *ships = this->GetTShipsEntries();
        if ( ships )
        {
                SStringList *node = ships->FindData(CyString(sId).upper());
                if ( node )
                        return node->str.ToString();
        }
        return "";
}

void CVirtualFileSystem::extractTexts(CXspFile *pPackage, int textId)
{
        //TODO: check for better finding of files in map
        for ( FileListItr itr = m_pMap->begin(); itr != m_pMap->end(); ++itr ) {
                Utils::String str = itr->first;

                if ( !m_sAddon.empty() ) {
                        if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "/t/") && !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "\\t\\") )
                                continue;
                }
                else {
                        if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") && !str.left(8).Compare("addon\t\\") && !str.left(8).Compare("addon/t/") )
                                continue;
                }

                Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
                if ( !sTo.empty() ) {
                        pPackage->AddTextFromFile(sTo, textId);
                        CFileIO::Remove(sTo);
                }
        }
}

void CVirtualFileSystem::updateTexts(int iFromPage, int iToPage)
{
        this->_updateTexts(iFromPage, iToPage, m_pMap, m_pTexts);
}
void CVirtualFileSystem::updateTexts(int iPage)
{
        this->_updateTexts(iPage, iPage, m_pMap, m_pTexts);
}
void CVirtualFileSystem::updateModTexts(int iFromPage, int iToPage)
{
        this->_updateTexts(iFromPage, iToPage, m_pModMap, m_pModTexts);
}
void CVirtualFileSystem::updateModTexts(int iPage)
{
        this->_updateTexts(iPage, iPage, m_pModMap, m_pModTexts);
}

void CVirtualFileSystem::_clear()
{
        m_bLoaded = false;

        if ( m_pMap ) delete m_pMap;
        m_pMap = new FileList;
        if ( m_pModMap ) delete m_pModMap;
        m_pModMap = new FileList;
}

void CVirtualFileSystem::_updateTexts(int iFromPage, int iToPage, FileList *pFileList, CTextDB *pTextList)
{
        // read all text files
        for ( FileListItr itr = pFileList->begin(); itr != pFileList->end(); ++itr ) {
                Utils::String str = itr->first;

                if ( !m_sAddon.empty() ) {
                        if ( !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "/t/") && !str.left(m_sAddon.length() + 3).Compare(m_sAddon + "\\t\\") )
                                continue;
                }
                else {
                        if ( !str.left(2).Compare("t\\") && !str.left(2).Compare("t/") )
                                continue;
                }

                Utils::String sTo = this->ExtractGameFile(str, CPackages::tempDirectory() + "tmp.dat");
                if ( !sTo.empty() ) {
                        // add all texts into the map, id=(pageid, tid) data=text
                        Utils::String baseFile = CFileIO(str).baseName();
                        int lang = (baseFile.isin("-L")) ? baseFile.right(3) : baseFile.truncate(-4);

                        if ( m_iLang && lang != m_iLang ) continue;
                        // open the text file to add
                        pTextList->parseTextFile(iFromPage, iToPage, sTo, lang);
                }
        }
}

void CVirtualFileSystem::clearMods(bool bIncludeStandard)
{
        if ( bIncludeStandard ) {
                if ( m_pTexts ) delete m_pTexts;
                m_pTexts = new CTextDB();
        }

        if ( m_pModTexts ) delete m_pModTexts;
        m_pModTexts = new CTextDB();
}

bool CVirtualFileSystem::loadShipData(CyStringList *list)
{
        bool ret = false;

        Utils::String sTo = this->ExtractGameFile("types/TShips.pck", CPackages::tempDirectory() + "tmp.dat");
        if ( !sTo.empty() ) {
                CFileIO File(sTo);
                CyStringList *lines = File.ReadLinesStr();
                if ( lines )
                {
                        bool readFirst = false;
                        for ( SStringList *str = lines->Head(); str; str = str->next )
                        {
                                if ( str->str.Empty() )
                                        continue;
                                str->str.RemoveChar('\r');
                                str->str.RemoveChar(9);
                                str->str.RemoveFirstSpace();
                                if ( str->str.Empty() )
                                        continue;
                                if ( str->str[0] == '/' || str->str[0] == '#' )
                                        continue;

                                if ( !readFirst )
                                        readFirst = true;
                                else
                                {
                                        CyString t = str->str.GetToken(";", -2);
                                        while ( t.Right(1) == ";" )
                                                t.Truncate((int)t.Length() - 1);
                                        list->PushBack(t, str->str);
                                }
                        }

                        delete lines;
                        ret = true;
                }

                File.remove();
        }

        return ret;
}

Utils::CStringList *CVirtualFileSystem::_updateList(const Utils::String &typesFile, int iTextPos)
{
        Utils::CStringList *list = new Utils::CStringList();

        Utils::String file = this->ExtractGameFile("types\\" + typesFile + ".pck", CPackages::tempDirectory() + "/" + typesFile + ".txt");

        CFileIO f(file);

        if ( f.exists() && f.startRead() ) {
                int itemsLeft = -1;

                while(!f.atEnd()) {
                        // read the next line
                        Utils::String line = f.readEndOfLine();

                        // remove the unneeded characters
                        line.removeChar('\r');
                        line.removeChar(9);
                        line.removeFirstSpace();

                        // blank line ? skip it
                        if ( line.empty() ) continue;
                        // skip anything starting with / as its a comment
                        if ( line[0] == '/' ) continue;

                        // first line is the count
                        if ( itemsLeft == -1 )
                                itemsLeft = line.token(";", 2);
                        else {
                                if ( iTextPos == 0 )
                                        list->pushBack(line, line);
                                else if ( iTextPos == -1 ) 
                                        list->pushBack(line, line.token(";", -2));
                                else
                                        list->pushBack(line, this->findText(m_iLang, TEXTPAGE_OBJECTS, line.token(";", iTextPos).toLong()));
                                --itemsLeft;
                        }
                }
                
                f.close();
                f.remove();
        }

        return list;
}

void CVirtualFileSystem::_updateShields()
{
        DELETELIST(_lShields);
        _lShields = _updateList("TShields", 7);
}

void CVirtualFileSystem::_updateLasers()
{
        DELETELIST(_lLasers);
        _lLasers = _updateList("TLaser", 7);
}

void CVirtualFileSystem::_updateMissiles()
{
        DELETELIST(_lMissiles);
        _lMissiles = _updateList("TMissiles", 7);
}

void CVirtualFileSystem::_updateCockpits()
{
        DELETELIST(_lCockpits);
        _lCockpits = _updateList("TCockpits", -1);
}

void CVirtualFileSystem::_updateComponentSections()
{
        DELETELIST(_lComponentSections);

        _lComponentSections = new Utils::CStringList();

        Utils::String file = this->ExtractGameFile("types\\Components.pck", CPackages::tempDirectory() + "/Components.txt");

        CFileIO f(file);

        if ( f.exists() && f.startRead() ) {
                int sectionRemaining = 0;
                int itemsRemaining = 0;

                while(!f.atEnd()) {
                        // read the next line
                        Utils::String line = f.readEndOfLine();

                        // remove the unneeded characters
                        line.removeChar('\r');
                        line.removeChar(9);
                        line.removeFirstSpace();

                        // blank line ? skip it
                        if ( line.empty() ) continue;
                        // skip anything starting with / as its a comment
                        if ( line[0] == '/' ) continue;

                        if ( itemsRemaining )
                                --itemsRemaining;
                        else if ( !sectionRemaining )
                        {
                                sectionRemaining = line.token(";", 2).toLong();
                                Utils::String section = line.token(";", 1);
                                if ( !section.empty() )
                                        _lComponentSections->pushBack(section, section);
                        }
                        else if ( !itemsRemaining )
                        {
                                itemsRemaining = line.token(";", 2).toLong();
                                --sectionRemaining;
                        }
                }
                
                f.close();
                f.remove();
        }

        if ( _lComponentSections->empty() )
        {
                _lComponentSections->pushBack("SCTYPE_LASER", "SCTYPE_LASER");
                _lComponentSections->pushBack("SCTYPE_COCKPIT", "SCTYPE_COCKPIT");
                _lComponentSections->pushBack("SCTYPE_DOCKING", "SCTYPE_DOCKING");
        }
}

Utils::CStringList *CVirtualFileSystem::_updateSectionList(const Utils::String &sFile, bool singleEntry)
{
        Utils::CStringList *list = new Utils::CStringList();

        Utils::String file = this->ExtractGameFile("types\\" + sFile + ".pck", CPackages::tempDirectory() + "/" + sFile + ".txt");

        CFileIO f(file);

        if ( f.exists() && f.startRead() ) {
                int sectionRemaining = 0;

                while(!f.atEnd()) {
                        // read the next line
                        Utils::String line = f.readEndOfLine();

                        // remove the unneeded characters
                        line.removeChar('\r');
                        line.removeChar(9);
                        line.removeFirstSpace();

                        // blank line ? skip it
                        if ( line.empty() ) continue;
                        // skip anything starting with / as its a comment
                        if ( line[0] == '/' ) continue;

                        if ( !sectionRemaining )
                        {
                                sectionRemaining = line.token(";", 2).toLong();
                                Utils::String section = line.token(";", 1);
                                if ( !section.empty() )
                                        list->pushBack(section, section);
                        }
                        else {
                                if ( singleEntry )
                                        sectionRemaining -= (line.countToken(";") - 1);
                                else 
                                        --sectionRemaining;
                        }
                }
                
                f.close();
                f.remove();
        }

        return list;
}

void CVirtualFileSystem::_updateDummySections()
{
        DELETELIST(_lDummySections);

        _lDummySections = _updateSectionList("Dummies", false);

        if ( _lDummySections->empty() )
        {
                _lDummySections->pushBack("SDTYPE_ANIMATED", "SDTYPE_ANIMATED");
                _lDummySections->pushBack("SDTYPE_DOCK", "SDTYPE_DOCK");
                _lDummySections->pushBack("SDTYPE_DOORWAY", "SDTYPE_DOORWAY");
                _lDummySections->pushBack("SDTYPE_GUN", "SDTYPE_GUN");
                _lDummySections->pushBack("SDTYPE_CONNECTION", "SDTYPE_CONNECTION");
        }
}

void CVirtualFileSystem::_updateBodiesSections()
{
        DELETELIST(_lBodiesSections);

        _lBodiesSections = _updateSectionList("Bodies", true);

        if ( _lBodiesSections->empty() )
        {
                _lBodiesSections->pushBack("SBTYPE_2D", "SBTYPE_2D");
                _lBodiesSections->pushBack("SBTYPE_FACECAMERA", "SBTYPE_FACECAMERA");
                _lBodiesSections->pushBack("SBTYPE_2D2", "SBTYPE_2D2");
                _lBodiesSections->pushBack("SBTYPE_2DY", "SBTYPE_2DY");
                _lBodiesSections->pushBack("SBTYPE_LOGO", "SBTYPE_LOGO");
                _lBodiesSections->pushBack("SBTYPE_FC", "SBTYPE_FC");
                _lBodiesSections->pushBack("SBTYPE_TURRET", "SBTYPE_TURRET");
                _lBodiesSections->pushBack("SBTYPE_JET", "SBTYPE_JET");
                _lBodiesSections->pushBack("SBTYPE_RADAR", "SBTYPE_RADAR");
                _lBodiesSections->pushBack("SBTYPE_CONTAINER", "SBTYPE_CONTAINER");
                _lBodiesSections->pushBack("SBTYPE_DISPLAY", "SBTYPE_DISPLAY");
                _lBodiesSections->pushBack("SBTYPE_DOCKPOINT", "SBTYPE_DOCKPOINT");
                _lBodiesSections->pushBack("SBTYPE_SMALLJET", "SBTYPE_SMALLJET");
        }
}

} //NAMESPACE