Browse Source

Add missing SImpleExtensionCheck

Kim Kulling 3 years ago
parent
commit
17d5633a5b

+ 0 - 6
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;
     }

+ 27 - 0
code/Common/BaseImporter.cpp

@@ -225,6 +225,32 @@ 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) {
@@ -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,

+ 14 - 0
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