From 17d5633a5b2688681fb9b83fbf47e228264b6924 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 19 Jan 2022 21:42:14 +0100 Subject: [PATCH] Add missing SImpleExtensionCheck --- code/AssetLib/glTF2/glTF2Importer.cpp | 6 ------ code/Common/BaseImporter.cpp | 27 +++++++++++++++++++++++++++ include/assimp/BaseImporter.h | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Importer.cpp b/code/AssetLib/glTF2/glTF2Importer.cpp index 4e78d0e17..1f4cafdda 100644 --- a/code/AssetLib/glTF2/glTF2Importer.cpp +++ b/code/AssetLib/glTF2/glTF2Importer.cpp @@ -1521,12 +1521,6 @@ static unsigned int countEmbeddedTextures(glTF2::Asset &r) { void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) { mEmbeddedTexIdxs.resize(r.images.Size(), -1); const unsigned int numEmbeddedTexs = countEmbeddedTextures(r); - /* for (size_t i = 0; i < r.images.Size(); ++i) { - if (r.images[i].HasData()) { - numEmbeddedTexs += 1; - } - }*/ - if (numEmbeddedTexs == 0) { return; } diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index e400f5c29..383300ef1 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -225,6 +225,32 @@ void BaseImporter::GetExtensionList(std::set &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) { @@ -242,6 +268,7 @@ std::string BaseImporter::GetExtension(const std::string &file) { return ret; } + // ------------------------------------------------------------------------------------------------ // Check for magic bytes at the beginning of the file. /* static */ bool BaseImporter::CheckMagicToken(IOSystem *pIOHandler, const std::string &pFile, diff --git a/include/assimp/BaseImporter.h b/include/assimp/BaseImporter.h index e7aafef23..5a3c764d4 100644 --- a/include/assimp/BaseImporter.h +++ b/include/assimp/BaseImporter.h @@ -260,6 +260,20 @@ public: // static utilities bool tokensSol = false, bool noAlphaBeforeTokens = false); + // ------------------------------------------------------------------- + /** @brief Check whether a file has a specific file extension + * @param pFile Input file + * @param ext0 Extension to check for. Lowercase characters only, no dot! + * @param ext1 Optional second extension + * @param ext2 Optional third extension + * @note Case-insensitive + */ + static bool SimpleExtensionCheck( + const std::string &pFile, + const char *ext0, + const char *ext1 = nullptr, + const char *ext2 = nullptr); + // ------------------------------------------------------------------- /** @brief Extract file extension from a string * @param pFile Input file