added support for wchar_t file paths and more stable windows builds

This commit is contained in:
Jack Andersen
2015-07-22 08:59:40 -10:00
parent 602f6b6e15
commit 5d3dcb57ad
7 changed files with 73 additions and 9 deletions

View File

@@ -24,6 +24,18 @@ FileReader::FileReader(const std::string& filename, atInt32 cacheSize)
setCacheSize(cacheSize);
}
#if _WIN32
FileReader::FileReader(const std::wstring& filename, atInt32 cacheSize)
: m_wfilename(filename),
m_fileHandle(nullptr),
m_cacheData(nullptr),
m_offset(0)
{
open();
setCacheSize(cacheSize);
}
#endif
FileReader::~FileReader()
{
if (isOpen())
@@ -32,7 +44,14 @@ FileReader::~FileReader()
void FileReader::open()
{
#if _WIN32
if (m_wfilename.size())
m_fileHandle = _wfopen(m_wfilename.c_str(), L"rb");
else
m_fileHandle = fopen(m_filename.c_str(), "rb");
#else
m_fileHandle = fopen(m_filename.c_str(), "rb");
#endif
if (!m_fileHandle)
THROW_FILE_NOT_FOUND_EXCEPTION(m_filename);
@@ -80,7 +99,7 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin)
{
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
m_curBlock = block;
m_curBlock = (atInt32)block;
}
}
else if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
@@ -127,7 +146,7 @@ atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
{
fseeko64(m_fileHandle, block * m_blockSize, SEEK_SET);
fread(m_cacheData.get(), 1, m_blockSize, m_fileHandle);
m_curBlock = block;
m_curBlock = (atInt32)block;
}
cacheSize = rem;
@@ -150,7 +169,7 @@ void FileReader::setCacheSize(const atInt32 blockSize)
m_blockSize = blockSize;
if (m_blockSize > length())
m_blockSize = length();
m_blockSize = (atInt32)length();
m_curBlock = -1;
if (m_blockSize > 0)