mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
rwlib: LoaderIMG accepts rwfs::path
This commit is contained in:
parent
820c4bd25c
commit
32fb5eb409
@ -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");
|
||||
}
|
||||
|
@ -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];
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <rw/filesystem.hpp>
|
||||
|
||||
/// \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<LoaderIMGFile> m_assets; ///< Asset info of the archive
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user