2007-12-20 21:21:45 +01:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
bool FileExists(const VfsPath& pathname)
|
|
|
|
{
|
|
|
|
return g_VFS->GetFileInfo(pathname, 0) == INFO::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-20 21:21:45 +01:00
|
|
|
|
|
|
|
CVFSFile::CVFSFile()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CVFSFile::~CVFSFile()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
PSRETURN CVFSFile::Load(const VfsPath& filename)
|
2007-12-20 21:21:45 +01:00
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
{
|
2008-01-07 21:03:19 +01:00
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, "CVFSFile: file %s couldn't be opened (vfs_load: %d)", filename.string().c_str(), ret);
|
2007-12-20 21:21:45 +01:00
|
|
|
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());
|
|
|
|
}
|