Browse Source

fix CanRead-method for the 3MF-Importer.

Kim Kulling 7 years ago
parent
commit
f11d4902c6
3 changed files with 14 additions and 1 deletions
  1. 3 0
      code/D3MFImporter.cpp
  2. 9 0
      code/D3MFOpcPackage.cpp
  3. 2 1
      code/D3MFOpcPackage.h

+ 3 - 0
code/D3MFImporter.cpp

@@ -414,6 +414,9 @@ bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bo
         if ( nullptr == pIOHandler ) {
             return false;
         }
+        if ( !D3MF::D3MFOpcPackage::isZipArchive( pIOHandler, filename ) ) {
+            return false;
+        }
         D3MF::D3MFOpcPackage opcPackage( pIOHandler, filename );
         return opcPackage.validate();
     }

+ 9 - 0
code/D3MFOpcPackage.cpp

@@ -499,6 +499,15 @@ bool D3MFOpcPackage::validate() {
     return mZipArchive->Exists( ModelRef.c_str() );
 }
 
+bool D3MFOpcPackage::isZipArchive( IOSystem* pIOHandler, const std::string& rFile ) {
+    D3MF::D3MFZipArchive ar( pIOHandler, rFile );
+    if ( !ar.isOpen() ) {
+        return false;
+    }
+
+    return true;
+}
+
 std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream* stream) {
     std::unique_ptr<CIrrXML_IOStreamReader> xmlStream(new CIrrXML_IOStreamReader(stream));
     std::unique_ptr<XmlReader> xml(irr::io::createIrrXMLReader(xmlStream.get()));

+ 2 - 1
code/D3MFOpcPackage.h

@@ -64,10 +64,11 @@ class D3MFZipArchive;
 
 class D3MFOpcPackage {
 public:
-    D3MFOpcPackage(IOSystem* pIOHandler, const std::string& rFile);
+    D3MFOpcPackage( IOSystem* pIOHandler, const std::string& rFile );
     ~D3MFOpcPackage();
     IOStream* RootStream() const;
     bool validate();
+    static bool isZipArchive( IOSystem* pIOHandler, const std::string& rFile );
 
 protected:
     std::string ReadPackageRootRelationship(IOStream* stream);