1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 16:15:33 +00:00

Avoid seek for detecting BSA type

Seek is pretty expensive operation. Try to read first 12 bytes instead.
This commit is contained in:
elsid 2024-01-30 01:47:49 +01:00
parent cc9f9b53ba
commit 8c6e0866e0
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625

View file

@ -325,25 +325,15 @@ BsaVersion Bsa::BSAFile::detectVersion(const std::filesystem::path& filePath)
{ {
std::ifstream input(filePath, std::ios_base::binary); std::ifstream input(filePath, std::ios_base::binary);
// Total archive size
std::streamoff fsize = 0;
if (input.seekg(0, std::ios_base::end))
{
fsize = input.tellg();
input.seekg(0);
}
if (fsize < 12)
{
return BsaVersion::Unknown;
}
// Get essential header numbers // Get essential header numbers
// First 12 bytes // First 12 bytes
uint32_t head[3]; uint32_t head[3];
input.read(reinterpret_cast<char*>(head), 12); input.read(reinterpret_cast<char*>(head), sizeof(head));
if (input.gcount() != sizeof(head))
return BsaVersion::Unknown;
if (head[0] == static_cast<uint32_t>(BsaVersion::Uncompressed)) if (head[0] == static_cast<uint32_t>(BsaVersion::Uncompressed))
{ {