mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +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
122 lines
2.9 KiB
C++
122 lines
2.9 KiB
C++
#include "vfs_file_raii.h"
|
|
#include "vfs.h"
|
|
|
|
#include <sstream>
|
|
/********************************************************************************************/
|
|
/********************************************************************************************/
|
|
|
|
vfs::COpenReadFile::COpenReadFile(vfs::Path const& sPath, vfs::CVirtualFile::ESearchFile eSF)
|
|
{
|
|
vfs::IBaseFile *pFile = getVFS()->getFile(sPath,eSF);
|
|
THROWIFFALSE(pFile,
|
|
BuildString().add(L"file \"").add(sPath).add(L"\" does not exist").get());
|
|
|
|
m_pFile = vfs::tReadableFile::cast(pFile);
|
|
|
|
THROWIFFALSE(m_pFile,
|
|
BuildString().add(L"File \"").add(sPath).add(L"\" is not readable").get());
|
|
|
|
THROWIFFALSE(m_pFile->openRead(),
|
|
BuildString().add(L"Could not open file : ").add(m_pFile->getPath()).get());
|
|
}
|
|
|
|
vfs::COpenReadFile::COpenReadFile(vfs::tReadableFile *pFile)
|
|
{
|
|
try
|
|
{
|
|
m_pFile = pFile;
|
|
THROWIFFALSE(m_pFile,
|
|
BuildString().add(L"Invalid file object").get());
|
|
|
|
THROWIFFALSE(m_pFile->openRead(),
|
|
BuildString().add(L"Could not open file : ").add(pFile->getPath()).get());
|
|
}
|
|
catch(CBasicException &ex)
|
|
{
|
|
RETHROWEXCEPTION(L"",&ex);
|
|
}
|
|
}
|
|
vfs::COpenReadFile::~COpenReadFile()
|
|
{
|
|
if(m_pFile)
|
|
{
|
|
m_pFile->close();
|
|
m_pFile = NULL;
|
|
}
|
|
}
|
|
|
|
vfs::tReadableFile& vfs::COpenReadFile::file()
|
|
{
|
|
return *m_pFile;
|
|
}
|
|
|
|
void vfs::COpenReadFile::release()
|
|
{
|
|
m_pFile = NULL;
|
|
}
|
|
|
|
/**************************************************************************/
|
|
|
|
vfs::COpenWriteFile::COpenWriteFile(vfs::Path const& sPath,
|
|
bool bCreate,
|
|
bool bTruncate,
|
|
vfs::CVirtualFile::ESearchFile eSF)
|
|
{
|
|
vfs::IBaseFile *pFile = getVFS()->getFile(sPath,eSF);
|
|
if(!pFile && bCreate)
|
|
{
|
|
if(getVFS()->createNewFile(sPath))
|
|
{
|
|
pFile = getVFS()->getFile(sPath,eSF);
|
|
}
|
|
else
|
|
{
|
|
THROWEXCEPTION(BuildString().add(L"Could not create VFS file \"").add(sPath).add(L"\"").get());
|
|
}
|
|
}
|
|
THROWIFFALSE(pFile,
|
|
BuildString().add(L"File \"").add(sPath).add(L"\" not found").get());
|
|
|
|
m_pFile = vfs::tWritableFile::cast(pFile);
|
|
|
|
THROWIFFALSE(m_pFile,
|
|
BuildString().add(L"File \"").add(sPath).add(L"\" exists, but is not writable").get());
|
|
|
|
THROWIFFALSE(m_pFile->openWrite(bCreate,bTruncate),
|
|
BuildString().add(L"File \"").add(sPath).add(L"\" could not be opened for writing").get());
|
|
}
|
|
vfs::COpenWriteFile::COpenWriteFile(vfs::tWritableFile *pFile)
|
|
{
|
|
try
|
|
{
|
|
m_pFile = pFile;
|
|
THROWIFFALSE(m_pFile,
|
|
BuildString().add(L"Invalid file object").get());
|
|
THROWIFFALSE(m_pFile->openWrite(true,false),
|
|
BuildString().add(L"Could not open file : ").add(m_pFile->getPath()).get());
|
|
}
|
|
catch(CBasicException& ex)
|
|
{
|
|
RETHROWEXCEPTION(L"",&ex);
|
|
};
|
|
}
|
|
vfs::COpenWriteFile::~COpenWriteFile()
|
|
{
|
|
if(m_pFile)
|
|
{
|
|
m_pFile->close();
|
|
m_pFile = NULL;
|
|
}
|
|
}
|
|
|
|
vfs::tWritableFile& vfs::COpenWriteFile::file()
|
|
{
|
|
return *m_pFile;
|
|
}
|
|
|
|
void vfs::COpenWriteFile::release()
|
|
{
|
|
m_pFile = NULL;
|
|
}
|
|
|