diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index 22f3761dee..b5688260ce 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -469,7 +469,7 @@ void __UmdReplace(std::string filepath) { if (!currentUMD) return; - FileLoader *loadedFile = new LocalFileLoader(filepath); + FileLoader *loadedFile = ConstructFileLoader(filepath); IFileSystem* umd2; FileInfo info; diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index 381d3ee4c9..f64c57279a 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -31,6 +31,34 @@ #include "Core/ELF/PBPReader.h" #include "Core/ELF/ParamSFO.h" +class LocalFileLoader : public FileLoader { +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; + virtual std::string Path() const override; + + virtual void Seek(s64 absolutePos) override; + virtual size_t Read(size_t bytes, size_t count, void *data) override; + virtual size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data) override; + +private: + // First only used by Android, but we can keep it here for everyone. + int fd_; + FILE *f_; + u64 filesize_; + std::string filename_; +}; + +FileLoader *ConstructFileLoader(const std::string &filename) { + return new LocalFileLoader(filename); +} + LocalFileLoader::LocalFileLoader(const std::string &filename) { Reopen(filename); } diff --git a/Core/Loaders.h b/Core/Loaders.h index c39fc471d6..86069914f3 100644 --- a/Core/Loaders.h +++ b/Core/Loaders.h @@ -78,29 +78,7 @@ public: } }; -class LocalFileLoader : public FileLoader { -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; - virtual std::string Path() const override; - - virtual void Seek(s64 absolutePos) override; - virtual size_t Read(size_t bytes, size_t count, void *data) override; - virtual size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data) override; - -private: - // First only used by Android, but we can keep it here for everyone. - int fd_; - FILE *f_; - u64 filesize_; - std::string filename_; -}; +FileLoader *ConstructFileLoader(const std::string &filename); // This can modify the string, for example for stripping off the "/EBOOT.PBP" // for a FILETYPE_PSP_PBP_DIRECTORY. diff --git a/Core/System.cpp b/Core/System.cpp index d60a42e44f..da52d185a1 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -182,12 +182,12 @@ void CPU_Init() { Memory::g_PSPModel = g_Config.iPSPModel; std::string filename = coreParameter.fileToStart; - loadedFile = new LocalFileLoader(filename); + loadedFile = ConstructFileLoader(filename); IdentifiedFileType type = Identify_File(loadedFile); // TODO: Put this somewhere better? if (coreParameter.mountIso != "") { - coreParameter.mountIsoLoader = new LocalFileLoader(coreParameter.mountIso); + coreParameter.mountIsoLoader = ConstructFileLoader(coreParameter.mountIso); } MIPSAnalyst::Reset(); diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 81734392ac..a8d18e5cc4 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -247,7 +247,7 @@ public: return; std::string filename = gamePath_; - std::unique_ptr fileLoader(new LocalFileLoader(filename)); + std::unique_ptr fileLoader(ConstructFileLoader(filename)); info_->path = gamePath_; info_->fileType = Identify_File(fileLoader.get()); // Fallback title