From b620070fa6a10ce09af8d64c9a10486b461dabdb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 23 Nov 2014 14:08:14 -0800 Subject: [PATCH] Kill FileLoader::Reopen()... Was a bad idea. --- Core/Loaders.cpp | 24 +++++++----------------- Core/Loaders.h | 5 +---- Core/System.cpp | 2 +- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index f64c57279a..c3f8869fdb 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -36,8 +36,6 @@ public: LocalFileLoader(const std::string &filename); virtual ~LocalFileLoader(); - virtual bool Reopen(const std::string &filename); - virtual bool Exists() override; virtual bool IsDirectory() override; virtual s64 FileSize() override; @@ -59,19 +57,11 @@ FileLoader *ConstructFileLoader(const std::string &filename) { return new LocalFileLoader(filename); } -LocalFileLoader::LocalFileLoader(const std::string &filename) { - Reopen(filename); -} - -bool LocalFileLoader::Reopen(const std::string &filename) { - fd_ = 0; - f_ = nullptr; - filesize_ = 0; - filename_ = filename; - +LocalFileLoader::LocalFileLoader(const std::string &filename) + : fd_(0), f_(nullptr), filesize_(0), filename_(filename) { f_ = File::OpenCFile(filename, "rb"); if (!f_) { - return false; + return; } #ifdef ANDROID @@ -87,8 +77,6 @@ bool LocalFileLoader::Reopen(const std::string &filename) { filesize_ = ftello(f_); fseek(f_, 0, SEEK_SET); #endif - - return true; } LocalFileLoader::~LocalFileLoader() { @@ -295,7 +283,8 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader) return FILETYPE_UNKNOWN; } -bool LoadFile(FileLoader *fileLoader, std::string *error_string) { +bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string) { + FileLoader *&fileLoader = *fileLoaderPtr; // Note that this can modify filename! switch (Identify_File(fileLoader)) { case FILETYPE_PSP_PBP_DIRECTORY: @@ -304,7 +293,8 @@ bool LoadFile(FileLoader *fileLoader, std::string *error_string) { std::string ebootFilename = filename + "/EBOOT.PBP"; // Switch fileLoader to the EBOOT. - fileLoader->Reopen(ebootFilename); + delete fileLoader; + fileLoader = ConstructFileLoader(ebootFilename); if (fileLoader->Exists()) { INFO_LOG(LOADER, "File is a PBP in a directory!"); diff --git a/Core/Loaders.h b/Core/Loaders.h index 86069914f3..f3b56668f3 100644 --- a/Core/Loaders.h +++ b/Core/Loaders.h @@ -50,9 +50,6 @@ class FileLoader { public: virtual ~FileLoader() {} - // Needed when we switch from a directory to a PBP, etc. - virtual bool Reopen(const std::string &filename) = 0; - virtual bool Exists() = 0; virtual bool IsDirectory() = 0; virtual s64 FileSize() = 0; @@ -85,4 +82,4 @@ FileLoader *ConstructFileLoader(const std::string &filename); IdentifiedFileType Identify_File(FileLoader *fileLoader); // Can modify the string filename, as it calls IdentifyFile above. -bool LoadFile(FileLoader *fileLoader, std::string *error_string); +bool LoadFile(FileLoader **fileLoaderPtr, std::string *error_string); diff --git a/Core/System.cpp b/Core/System.cpp index da52d185a1..ece502bad4 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -220,7 +220,7 @@ void CPU_Init() { // TODO: Check Game INI here for settings, patches and cheats, and modify coreParameter accordingly // Why did we check for CORE_POWERDOWN here? - if (!LoadFile(loadedFile, &coreParameter.errorString)) { + if (!LoadFile(&loadedFile, &coreParameter.errorString)) { CPU_Shutdown(); coreParameter.fileToStart = ""; CPU_SetState(CPU_THREAD_NOT_RUNNING);