simplify path fixing for packed vs unpacked (#816)

fix slashes for hasfile for unpacked client checking
This commit is contained in:
Aaron Kimbrell 2022-11-04 19:45:04 -05:00 committed by GitHub
parent 8880486c8b
commit 162f84e285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,17 +66,15 @@ eAssetBundleType AssetManager::GetAssetBundleType() {
bool AssetManager::HasFile(const char* name) { bool AssetManager::HasFile(const char* name) {
auto fixedName = std::string(name); auto fixedName = std::string(name);
std::transform(fixedName.begin(), fixedName.end(), fixedName.begin(), [](uint8_t c) { return std::tolower(c); }); std::transform(fixedName.begin(), fixedName.end(), fixedName.begin(), [](uint8_t c) { return std::tolower(c); });
std::replace(fixedName.begin(), fixedName.end(), '\\', '/');
if (std::filesystem::exists(m_ResPath / fixedName)) return true;
if (this->m_AssetBundleType == eAssetBundleType::Unpacked) return false;
std::replace(fixedName.begin(), fixedName.end(), '/', '\\'); std::replace(fixedName.begin(), fixedName.end(), '/', '\\');
if (fixedName.rfind("client\\res\\", 0) != 0) fixedName = "client\\res\\" + fixedName;
auto realPathName = fixedName;
if (fixedName.rfind("client\\res\\", 0) != 0) {
fixedName = "client\\res\\" + fixedName;
}
if (std::filesystem::exists(m_ResPath / realPathName)) {
return true;
}
uint32_t crc = crc32b(0xFFFFFFFF, (uint8_t*)fixedName.c_str(), fixedName.size()); uint32_t crc = crc32b(0xFFFFFFFF, (uint8_t*)fixedName.c_str(), fixedName.size());
crc = crc32b(crc, (Bytef*)"\0\0\0\0", 4); crc = crc32b(crc, (Bytef*)"\0\0\0\0", 4);