Kelsidavis-WoWee/src/pipeline/loose_file_reader.cpp
Kelsi aa16a687c2 Replace MPQ runtime with loose file asset system
Extract assets from MPQ archives into organized loose files indexed by
manifest.json, enabling fully parallel reads without StormLib serialization.
Add asset_extract and blp_convert tools, PNG texture override support.
2026-02-12 20:32:14 -08:00

47 lines
1.2 KiB
C++

#include "pipeline/loose_file_reader.hpp"
#include "core/logger.hpp"
#include <fstream>
#include <filesystem>
namespace wowee {
namespace pipeline {
std::vector<uint8_t> LooseFileReader::readFile(const std::string& filesystemPath) {
std::ifstream file(filesystemPath, std::ios::binary | std::ios::ate);
if (!file.is_open()) {
return {};
}
auto size = file.tellg();
if (size <= 0) {
return {};
}
std::vector<uint8_t> data(static_cast<size_t>(size));
file.seekg(0, std::ios::beg);
file.read(reinterpret_cast<char*>(data.data()), size);
if (!file.good()) {
LOG_WARNING("Incomplete read of: ", filesystemPath);
data.resize(static_cast<size_t>(file.gcount()));
}
return data;
}
bool LooseFileReader::fileExists(const std::string& filesystemPath) {
std::error_code ec;
return std::filesystem::exists(filesystemPath, ec);
}
uint64_t LooseFileReader::getFileSize(const std::string& filesystemPath) {
std::error_code ec;
auto size = std::filesystem::file_size(filesystemPath, ec);
if (ec) {
return 0;
}
return static_cast<uint64_t>(size);
}
} // namespace pipeline
} // namespace wowee