Simplified importer search and fixed a few bugs
The search for a matching importer had a few issues, see #3791. There were two different mechanisms to determine whether an importer accepts a specific file extension: 1. `aiImporterDesc::mFileExtensions`, which was forwarded to the UI via `BaseImporter::GetExtensionList()`. 2. `BaseImporter::CanRead()` when called with `checkSig == false`, which determines whether to actually use that importer. Both were redundant and got out of sync repeatedly. I removed 2. completely and replaced it with 1., thereby syncing UI/import and shortening all `BaseImporter::CanRead()` implementations. Further bugfixes: - fixed glTF2 importer throwing exceptions when checking whether it can load a file - removed `BaseImporter::SimpleExtensionCheck()` because it is no longer used and had a bug with case sensitivity Since the `checkSig` parameter in `BaseImporter::CanRead()` is now useless, it can be removed completely. I’m not sure if this would break ABI compatiblity, so I’ll submit it with a later pull request.
This commit is contained in:
@@ -104,23 +104,18 @@ MDLImporter::~MDLImporter() {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool MDLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const {
|
||||
const std::string extension = GetExtension(pFile);
|
||||
|
||||
// if check for extension is not enough, check for the magic tokens
|
||||
if (extension == "mdl" || !extension.length() || checkSig) {
|
||||
uint32_t tokens[8];
|
||||
tokens[0] = AI_MDL_MAGIC_NUMBER_LE_HL2a;
|
||||
tokens[1] = AI_MDL_MAGIC_NUMBER_LE_HL2b;
|
||||
tokens[2] = AI_MDL_MAGIC_NUMBER_LE_GS7;
|
||||
tokens[3] = AI_MDL_MAGIC_NUMBER_LE_GS5b;
|
||||
tokens[4] = AI_MDL_MAGIC_NUMBER_LE_GS5a;
|
||||
tokens[5] = AI_MDL_MAGIC_NUMBER_LE_GS4;
|
||||
tokens[6] = AI_MDL_MAGIC_NUMBER_LE_GS3;
|
||||
tokens[7] = AI_MDL_MAGIC_NUMBER_LE;
|
||||
return CheckMagicToken(pIOHandler, pFile, tokens, 8, 0);
|
||||
}
|
||||
return false;
|
||||
bool MDLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
|
||||
static const uint32_t tokens[] = {
|
||||
AI_MDL_MAGIC_NUMBER_LE_HL2a,
|
||||
AI_MDL_MAGIC_NUMBER_LE_HL2b,
|
||||
AI_MDL_MAGIC_NUMBER_LE_GS7,
|
||||
AI_MDL_MAGIC_NUMBER_LE_GS5b,
|
||||
AI_MDL_MAGIC_NUMBER_LE_GS5a,
|
||||
AI_MDL_MAGIC_NUMBER_LE_GS4,
|
||||
AI_MDL_MAGIC_NUMBER_LE_GS3,
|
||||
AI_MDL_MAGIC_NUMBER_LE
|
||||
};
|
||||
return CheckMagicToken(pIOHandler, pFile, tokens, std::size(tokens));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user