From 18bcf63ee9b8e2b3c7583157c8c3aedaaf75bc3f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 8 Dec 2013 11:05:36 -0800 Subject: [PATCH] Add a convenience helper to load a file oneshot. --- Core/FileSystems/MetaFileSystem.cpp | 17 +++++++++++++++++ Core/FileSystems/MetaFileSystem.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/Core/FileSystems/MetaFileSystem.cpp b/Core/FileSystems/MetaFileSystem.cpp index b0417ab6d8..937b1c7d72 100644 --- a/Core/FileSystems/MetaFileSystem.cpp +++ b/Core/FileSystems/MetaFileSystem.cpp @@ -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); diff --git a/Core/FileSystems/MetaFileSystem.h b/Core/FileSystems/MetaFileSystem.h index 130644e58f..e64b47fe5b 100644 --- a/Core/FileSystems/MetaFileSystem.h +++ b/Core/FileSystems/MetaFileSystem.h @@ -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;