From 32fb5eb409d920b709d41bee42b4ce28c08444d8 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 2 Nov 2017 05:01:00 +0100 Subject: [PATCH] rwlib: LoaderIMG accepts rwfs::path --- rwengine/src/engine/GameData.cpp | 2 +- rwlib/source/loaders/LoaderIMG.cpp | 21 +++++++++------------ rwlib/source/loaders/LoaderIMG.hpp | 6 ++++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/rwengine/src/engine/GameData.cpp b/rwengine/src/engine/GameData.cpp index 61e3c43d..cbaa930b 100644 --- a/rwengine/src/engine/GameData.cpp +++ b/rwengine/src/engine/GameData.cpp @@ -704,5 +704,5 @@ bool GameData::isValidGameDirectory(const rwfs::path& path) { } LoaderIMG i; - return i.load((path / "models/gta3.img").string()); //FIXME: to path + return i.load(path / "models/gta3.img"); } diff --git a/rwlib/source/loaders/LoaderIMG.cpp b/rwlib/source/loaders/LoaderIMG.cpp index 5d3a3b59..5be0c9f1 100644 --- a/rwlib/source/loaders/LoaderIMG.cpp +++ b/rwlib/source/loaders/LoaderIMG.cpp @@ -5,16 +5,11 @@ LoaderIMG::LoaderIMG() : m_version(GTAIIIVC), m_assetCount(0) { } -bool LoaderIMG::load(const std::string& filename) { - auto baseName = filename; - auto extpos = filename.find(".img"); - if (extpos != std::string::npos) { - baseName.erase(extpos); - } - auto dirName = baseName + ".dir"; - auto imgName = baseName + ".img"; +bool LoaderIMG::load(const rwfs::path& filepath) { + auto dirPath = filepath; + dirPath.replace_extension(".dir"); - FILE* fp = fopen(dirName.c_str(), "rb"); + FILE* fp = fopen(dirPath.string().c_str(), "rb"); if (fp) { fseek(fp, 0, SEEK_END); unsigned long fileSize = ftell(fp); @@ -30,7 +25,9 @@ bool LoaderIMG::load(const std::string& filename) { } fclose(fp); - m_archive = imgName; + auto imgPath = filepath; + imgPath.replace_extension(".img"); + m_archive = imgPath; return true; } else { return false; @@ -58,9 +55,9 @@ char* LoaderIMG::loadToMemory(const std::string& assetname) { return nullptr; } - std::string imgName = m_archive; + auto imgName = m_archive; - FILE* fp = fopen(imgName.c_str(), "rb"); + FILE* fp = fopen(imgName.string().c_str(), "rb"); if (fp) { char* raw_data = new char[assetInfo.size * 2048]; diff --git a/rwlib/source/loaders/LoaderIMG.hpp b/rwlib/source/loaders/LoaderIMG.hpp index 42f7000b..187d5ee3 100644 --- a/rwlib/source/loaders/LoaderIMG.hpp +++ b/rwlib/source/loaders/LoaderIMG.hpp @@ -6,6 +6,8 @@ #include #include +#include + /// \brief Points to one file within the archive class LoaderIMGFile { public: @@ -34,7 +36,7 @@ public: /// Load the structure of the archive /// Omit the extension in filename so both .dir and .img are loaded when /// appropriate - bool load(const std::string& filename); + bool load(const rwfs::path& filename); /// Load a file from the archive to memory and pass a pointer to it /// Warning: Please delete[] the memory in the end. @@ -56,7 +58,7 @@ public: private: Versions m_version; ///< Version of this IMG archive uint32_t m_assetCount; ///< Number of assets in the current archive - std::string m_archive; ///< Path to the archive being used (no extension) + rwfs::path m_archive; ///< Path to the archive being used (no extension) std::vector m_assets; ///< Asset info of the archive };