forked from 0ad/0ad
janwas
e2eb5b2610
mostly straightforward except for CVSFile / Filesystem. moved the former into the newly created latter component. removed VFSUtil entirely (that functionality is available from lib/file/file_system_util.h) Xeromyces.cpp: simplify buffer handling since smart pointers are now in play. also use WriteBuffer instead of membuffer. This was SVN commit r5519.
66 lines
1.2 KiB
C++
66 lines
1.2 KiB
C++
#include "precompiled.h"
|
|
#include "Filesystem.h"
|
|
|
|
#include "ps/CLogger.h"
|
|
|
|
#define LOG_CATEGORY "file"
|
|
|
|
|
|
PIVFS g_VFS;
|
|
|
|
bool FileExists(const char* pathname)
|
|
{
|
|
return g_VFS->GetFileInfo(pathname, 0) == INFO::OK;
|
|
}
|
|
|
|
|
|
CVFSFile::CVFSFile()
|
|
{
|
|
}
|
|
|
|
CVFSFile::~CVFSFile()
|
|
{
|
|
}
|
|
|
|
PSRETURN CVFSFile::Load(const char* filename)
|
|
{
|
|
// Load should never be called more than once, so complain
|
|
if (m_Buffer)
|
|
{
|
|
debug_assert(0);
|
|
return PSRETURN_CVFSFile_AlreadyLoaded;
|
|
}
|
|
|
|
LibError ret = g_VFS->LoadFile(filename, m_Buffer, m_BufferSize);
|
|
if (ret != INFO::OK)
|
|
{
|
|
LOG(ERROR, LOG_CATEGORY, "CVFSFile: file %s couldn't be opened (vfs_load: %d)", filename, ret);
|
|
return PSRETURN_CVFSFile_LoadFailed;
|
|
}
|
|
|
|
return PSRETURN_OK;
|
|
}
|
|
|
|
const u8* CVFSFile::GetBuffer() const
|
|
{
|
|
// Die in a very obvious way, to avoid subtle problems caused by
|
|
// accidentally forgetting to check that the open succeeded
|
|
if (!m_Buffer)
|
|
{
|
|
debug_warn("GetBuffer() called with no file loaded");
|
|
throw PSERROR_CVFSFile_InvalidBufferAccess();
|
|
}
|
|
|
|
return m_Buffer.get();
|
|
}
|
|
|
|
size_t CVFSFile::GetBufferSize() const
|
|
{
|
|
return m_BufferSize;
|
|
}
|
|
|
|
CStr CVFSFile::GetAsString() const
|
|
{
|
|
return std::string((char*)GetBuffer(), GetBufferSize());
|
|
}
|