Files
source/VFS/File/vfs_lib_file.cpp
T
Wanne 14750c6903 **********************************************************
** Big Maps Projects code (incl. Multiplayer v1.5 **
**********************************************************
- Merged Big Maps Project code from BMP+MP trunk (Revision: 3340)
o Complete SVN Revision history: https://81.169.133.124/source/ja2/branches/Wanne/JA2%201.13%20MP
- Before THIS merge, I made a branch of the existing 1.13 source
o SVN Branch: https://81.169.133.124/source/ja2/branches/JA2_rev.3336/src
- Removed old VS 6.0 and VS 2003 project and solutions files, because compilation is broken long time ago
- I will add VS 2010 projects and solution file in the next few days

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@3341 3b4a5df2-a311-0410-b5c6-a8a6f20db521
2010-02-28 18:38:52 +00:00

141 lines
3.0 KiB
C++

#include "vfs_lib_file.h"
#include "../vfs.h"
#define ERROR_FILE(msg) BuildString().add(L"[").add(this->getPath()).add(L"] - ").add(msg).get()
ObjBlockAllocator<vfs::CLibFile>* vfs::CLibFile::_lfile_pool = NULL;
vfs::CLibFile* vfs::CLibFile::create(vfs::Path const& filename,
tLocation *location,
ILibrary *library,
ObjBlockAllocator<vfs::CLibFile>* allocator)
{
#if 0
vfs::CLibFile* pFile = new vfs::CLibFile();
#else
vfs::CLibFile* pFile;
if(allocator)
{
pFile = allocator->New();
}
else
{
if(!_lfile_pool)
{
_lfile_pool = new ObjBlockAllocator<vfs::CLibFile>();
CFileAllocator::registerAllocator(_lfile_pool);
}
pFile = _lfile_pool->New();
}
#endif
pFile->m_filename = filename;
pFile->m_location = location;
pFile->m_library = library;
return pFile;
}
vfs::CLibFile::CLibFile()
: tBaseClass(L""),
m_isOpen_read(false),
m_library(NULL),
m_location(NULL)
{
};
vfs::CLibFile::~CLibFile()
{
}
void vfs::CLibFile::close()
{
if(m_isOpen_read)
{
m_library->close(this);
m_isOpen_read = false;
}
}
vfs::FileAttributes vfs::CLibFile::getAttributes()
{
return vfs::FileAttributes(vfs::FileAttributes::ATTRIB_NORMAL | vfs::FileAttributes::ATTRIB_READONLY,
vfs::FileAttributes::LT_LIBRARY);
}
vfs::Path vfs::CLibFile::getPath()
{
if(m_location)
{
return m_location->getPath() + m_filename;
}
else
{
return m_filename;
}
}
bool vfs::CLibFile::isOpenRead()
{
return m_isOpen_read;
}
bool vfs::CLibFile::openRead()
{
if(!m_isOpen_read)
{
TRYCATCH_RETHROW(m_isOpen_read = m_library->openRead(this), ERROR_FILE(L"read open error"));
}
return m_isOpen_read;
}
vfs::size_t vfs::CLibFile::read(vfs::Byte* data, vfs::size_t bytesToRead)
{
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
try
{
return m_library->read(this, data, bytesToRead);
}
catch(CBasicException& ex)
{
RETHROWEXCEPTION(ERROR_FILE(L"read error"), &ex);
}
}
vfs::size_t vfs::CLibFile::getReadPosition()
{
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
try
{
return m_library->getReadPosition(this);
}
catch(CBasicException& ex)
{
RETHROWEXCEPTION(ERROR_FILE(L"library error"), &ex);
}
}
void vfs::CLibFile::setReadPosition(vfs::size_t uiPositionInBytes)
{
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
TRYCATCH_RETHROW(m_library->setReadPosition(this,uiPositionInBytes), ERROR_FILE(L"library error") );
}
void vfs::CLibFile::setReadPosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
{
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
TRYCATCH_RETHROW(m_library->setReadPosition(this, offsetInBytes, seekDir), ERROR_FILE(L"library error"));
}
vfs::size_t vfs::CLibFile::getSize()
{
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"could not open file") );
try
{
return m_library->getSize(this);
}
catch(CBasicException& ex)
{
RETHROWEXCEPTION(ERROR_FILE(L"library error"), &ex);
}
}