Add a convenience helper to load a file oneshot.

This commit is contained in:
Unknown W. Brackets 2013-12-08 11:05:36 -08:00
parent 93d501518a
commit 18bcf63ee9
2 changed files with 20 additions and 0 deletions

View File

@ -517,6 +517,23 @@ size_t MetaFileSystem::SeekFile(u32 handle, s32 position, FileMove type)
return 0;
}
u32 MetaFileSystem::ReadEntireFile(const std::string &filename, std::string &data) {
int error = 0;
u32 handle = pspFileSystem.OpenWithError(error, filename, FILEACCESS_READ);
if (handle == 0)
return error;
size_t dataSize = (size_t)pspFileSystem.GetFileInfo(filename).size;
data.resize(dataSize);
size_t result = pspFileSystem.ReadFile(handle, (u8 *)&data[0], dataSize);
pspFileSystem.CloseFile(handle);
if (result != dataSize)
return SCE_KERNEL_ERROR_ERROR;
return 0;
}
void MetaFileSystem::DoState(PointerWrap &p)
{
lock_guard guard(lock);

View File

@ -105,6 +105,9 @@ public:
// TODO: void IoCtl(...)
// Convenience helper - returns < 0 on failure.
u32 ReadEntireFile(const std::string &filename, std::string &data);
void SetStartingDirectory(const std::string &dir) {
lock_guard guard(lock);
startingDirectory = dir;