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:
Krishty
2021-04-24 00:17:50 +02:00
parent 9dc66b0003
commit b00de10eb3
51 changed files with 246 additions and 659 deletions

View File

@@ -170,7 +170,7 @@ void BaseImporter::GetExtensionList(std::set<std::string> &extensions) {
/*static*/ bool BaseImporter::SearchFileHeaderForToken(IOSystem *pIOHandler,
const std::string &pFile,
const char **tokens,
unsigned int numTokens,
std::size_t numTokens,
unsigned int searchBytes /* = 200 */,
bool tokensSol /* false */,
bool noAlphaBeforeTokens /* false */) {
@@ -238,32 +238,6 @@ void BaseImporter::GetExtensionList(std::set<std::string> &extensions) {
return false;
}
// ------------------------------------------------------------------------------------------------
// Simple check for file extension
/*static*/ bool BaseImporter::SimpleExtensionCheck(const std::string &pFile,
const char *ext0,
const char *ext1,
const char *ext2) {
std::string::size_type pos = pFile.find_last_of('.');
// no file extension - can't read
if (pos == std::string::npos)
return false;
const char *ext_real = &pFile[pos + 1];
if (!ASSIMP_stricmp(ext_real, ext0))
return true;
// check for other, optional, file extensions
if (ext1 && !ASSIMP_stricmp(ext_real, ext1))
return true;
if (ext2 && !ASSIMP_stricmp(ext_real, ext2))
return true;
return false;
}
// ------------------------------------------------------------------------------------------------
// Get file extension from path
std::string BaseImporter::GetExtension(const std::string &file) {
@@ -284,7 +258,7 @@ std::string BaseImporter::GetExtension(const std::string &file) {
// ------------------------------------------------------------------------------------------------
// Check for magic bytes at the beginning of the file.
/* static */ bool BaseImporter::CheckMagicToken(IOSystem *pIOHandler, const std::string &pFile,
const void *_magic, unsigned int num, unsigned int offset, unsigned int size) {
const void *_magic, std::size_t num, unsigned int offset, unsigned int size) {
ai_assert(size <= 16);
ai_assert(_magic);