mirror of
https://github.com/1dot13/source.git
synced 2026-08-26 14:30:26 +02:00
**********************************************************
** 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
This commit is contained in:
+64
-55
@@ -1,11 +1,14 @@
|
||||
#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& sFileName,
|
||||
vfs::IVFSLocation<vfs::IReadable,vfs::IWriteType> *pLocation,
|
||||
ILibrary *pLibrary,
|
||||
vfs::CLibFile* vfs::CLibFile::create(vfs::Path const& filename,
|
||||
tLocation *location,
|
||||
ILibrary *library,
|
||||
ObjBlockAllocator<vfs::CLibFile>* allocator)
|
||||
{
|
||||
#if 0
|
||||
@@ -21,22 +24,22 @@ vfs::CLibFile* vfs::CLibFile::Create(vfs::Path const& sFileName,
|
||||
if(!_lfile_pool)
|
||||
{
|
||||
_lfile_pool = new ObjBlockAllocator<vfs::CLibFile>();
|
||||
CFileAllocator::RegisterAllocator(_lfile_pool);
|
||||
CFileAllocator::registerAllocator(_lfile_pool);
|
||||
}
|
||||
pFile = _lfile_pool->New();
|
||||
}
|
||||
#endif
|
||||
pFile->m_sFileName = sFileName;
|
||||
pFile->_pLoc_ = pLocation;
|
||||
pFile->m_pLibrary = pLibrary;
|
||||
pFile->m_filename = filename;
|
||||
pFile->m_location = location;
|
||||
pFile->m_library = library;
|
||||
return pFile;
|
||||
}
|
||||
|
||||
vfs::CLibFile::CLibFile()
|
||||
: vfs::IFileTemplate<IReadable,IWriteType>(L""),
|
||||
vfs::ILocationAware<vfs::IReadable,vfs::IWriteType>(NULL),
|
||||
m_bIsOpen_read(false),
|
||||
m_pLibrary(NULL)
|
||||
: tBaseClass(L""),
|
||||
m_isOpen_read(false),
|
||||
m_library(NULL),
|
||||
m_location(NULL)
|
||||
{
|
||||
};
|
||||
|
||||
@@ -44,88 +47,94 @@ vfs::CLibFile::~CLibFile()
|
||||
{
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::Close()
|
||||
void vfs::CLibFile::close()
|
||||
{
|
||||
if(m_bIsOpen_read)
|
||||
if(m_isOpen_read)
|
||||
{
|
||||
m_bIsOpen_read = !m_pLibrary->Close(this);
|
||||
return m_bIsOpen_read;
|
||||
m_library->close(this);
|
||||
m_isOpen_read = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::Path vfs::CLibFile::GetFullPath()
|
||||
vfs::FileAttributes vfs::CLibFile::getAttributes()
|
||||
{
|
||||
if(_pLoc_)
|
||||
return vfs::FileAttributes(vfs::FileAttributes::ATTRIB_NORMAL | vfs::FileAttributes::ATTRIB_READONLY,
|
||||
vfs::FileAttributes::LT_LIBRARY);
|
||||
}
|
||||
|
||||
vfs::Path vfs::CLibFile::getPath()
|
||||
{
|
||||
if(m_location)
|
||||
{
|
||||
return _pLoc_->GetFullPath() + m_sFileName;
|
||||
return m_location->getPath() + m_filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_sFileName;
|
||||
return m_filename;
|
||||
}
|
||||
}
|
||||
bool vfs::CLibFile::IsOpenRead()
|
||||
bool vfs::CLibFile::isOpenRead()
|
||||
{
|
||||
return m_bIsOpen_read;
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::OpenRead()
|
||||
bool vfs::CLibFile::openRead()
|
||||
{
|
||||
if(!m_bIsOpen_read)
|
||||
if(!m_isOpen_read)
|
||||
{
|
||||
if(!(m_bIsOpen_read = m_pLibrary->OpenRead(this)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TRYCATCH_RETHROW(m_isOpen_read = m_library->openRead(this), ERROR_FILE(L"read open error"));
|
||||
}
|
||||
return true;
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::Read(Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead)
|
||||
vfs::size_t vfs::CLibFile::read(vfs::Byte* data, vfs::size_t bytesToRead)
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
try
|
||||
{
|
||||
return false;
|
||||
return m_library->read(this, data, bytesToRead);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L"read error"), &ex);
|
||||
}
|
||||
bool success = m_pLibrary->Read(this,pData,uiBytesToRead,uiBytesRead);
|
||||
return success;
|
||||
}
|
||||
|
||||
vfs::UInt32 vfs::CLibFile::GetReadLocation()
|
||||
vfs::size_t vfs::CLibFile::getReadPosition()
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
try
|
||||
{
|
||||
return -1;
|
||||
return m_library->getReadPosition(this);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L"library error"), &ex);
|
||||
}
|
||||
return m_pLibrary->GetReadLocation(this);
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CLibFile::SetReadLocation(vfs::UInt32 uiPositionInBytes)
|
||||
void vfs::CLibFile::setReadPosition(vfs::size_t uiPositionInBytes)
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool success = m_pLibrary->SetReadLocation(this,uiPositionInBytes);
|
||||
return success;
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
TRYCATCH_RETHROW(m_library->setReadPosition(this,uiPositionInBytes), ERROR_FILE(L"library error") );
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::SetReadLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir)
|
||||
void vfs::CLibFile::setReadPosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_pLibrary->SetReadLocation(this,uiOffsetInBytes,eSeekDir);
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
TRYCATCH_RETHROW(m_library->setReadPosition(this, offsetInBytes, seekDir), ERROR_FILE(L"library error"));
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::GetFileSize(vfs::UInt32& uiFileSize)
|
||||
vfs::size_t vfs::CLibFile::getSize()
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"could not open file") );
|
||||
try
|
||||
{
|
||||
return false;
|
||||
return m_library->getSize(this);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L"library error"), &ex);
|
||||
}
|
||||
return m_pLibrary->GetFileSize(this,uiFileSize);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user