port from perforce
This commit is contained in:
89
aiwaz/Aiwaz/FileSystem/CFileLoader/CFileLoader.cpp
Normal file
89
aiwaz/Aiwaz/FileSystem/CFileLoader/CFileLoader.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "stdafx.h"
|
||||
#include "CFileLoader.h"
|
||||
|
||||
#include "IFileSystem.h"
|
||||
|
||||
|
||||
CFileLoader::~CFileLoader()
|
||||
{
|
||||
this->FreeFile();
|
||||
}
|
||||
|
||||
|
||||
bool CFileLoader::LoadFile(string16 argFilename)
|
||||
{
|
||||
m_File = m_Engine->get_FileSystem().Open(argFilename);
|
||||
if (m_File != NULL)
|
||||
{
|
||||
std::stringstream dataStream;
|
||||
dataStream.write(m_File->get_Buffer(), m_File->get_BufferLength());
|
||||
|
||||
while (!dataStream.eof())
|
||||
{
|
||||
m_CurrentLineOfCode++;
|
||||
|
||||
std::string currentReadLine;
|
||||
std::getline(dataStream, currentReadLine);
|
||||
if (currentReadLine.empty())
|
||||
continue;
|
||||
|
||||
std::vector<std::string> token = this->SplitString(currentReadLine);
|
||||
if (token.empty())
|
||||
continue;
|
||||
|
||||
m_CurrentSection = token[0];
|
||||
if (!this->OnSectionBegin(m_CurrentSection, token))
|
||||
{
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (token[token.size() - 1] == "{{")
|
||||
m_EndSectionMarker = "}}";
|
||||
else
|
||||
m_EndSectionMarker = "}";
|
||||
|
||||
while (!dataStream.eof())
|
||||
{
|
||||
m_CurrentLineOfCode++;
|
||||
std::getline(dataStream, currentReadLine);
|
||||
if (currentReadLine.empty())
|
||||
continue;
|
||||
|
||||
std::vector<std::string> token = this->SplitString(currentReadLine, ", \t()\r");
|
||||
if (token.empty())
|
||||
continue;
|
||||
|
||||
if (token[0] == m_EndSectionMarker)
|
||||
{
|
||||
if (!this->OnSectionEnd(m_CurrentSection))
|
||||
{
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
m_CurrentSection = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this->OnContentReceived(token, currentReadLine))
|
||||
{
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->FreeFile();
|
||||
return true;
|
||||
}
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CFileLoader::FreeFile()
|
||||
{
|
||||
if (m_File != NULL)
|
||||
delete m_File;
|
||||
m_File = NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user