Browse Source

Add optional blob base name to blob IO system.

Carsten Rudolph 4 years ago
parent
commit
be85f238f4
1 changed files with 25 additions and 8 deletions
  1. 25 8
      include/assimp/BlobIOSystem.h

+ 25 - 8
include/assimp/BlobIOSystem.h

@@ -194,8 +194,14 @@ class BlobIOSystem : public IOSystem {
     friend class BlobIOStream;
     friend class BlobIOStream;
     typedef std::pair<std::string, aiExportDataBlob *> BlobEntry;
     typedef std::pair<std::string, aiExportDataBlob *> BlobEntry;
 
 
+
 public:
 public:
-    BlobIOSystem() {
+    BlobIOSystem() :
+            baseName{} {
+    }
+
+    BlobIOSystem(const std::string &baseName) :
+            baseName(baseName) {
     }
     }
 
 
     virtual ~BlobIOSystem() {
     virtual ~BlobIOSystem() {
@@ -207,27 +213,32 @@ public:
 public:
 public:
     // -------------------------------------------------------------------
     // -------------------------------------------------------------------
     const char *GetMagicFileName() const {
     const char *GetMagicFileName() const {
-        return AI_BLOBIO_MAGIC;
+        return baseName.empty() ? AI_BLOBIO_MAGIC : baseName.c_str();
     }
     }
 
 
     // -------------------------------------------------------------------
     // -------------------------------------------------------------------
     aiExportDataBlob *GetBlobChain() {
     aiExportDataBlob *GetBlobChain() {
+        const auto magicName = std::string(this->GetMagicFileName());
+        const bool hasBaseName = baseName.empty();
+
         // one must be the master
         // one must be the master
         aiExportDataBlob *master = nullptr, *cur;
         aiExportDataBlob *master = nullptr, *cur;
+
         for (const BlobEntry &blobby : blobs) {
         for (const BlobEntry &blobby : blobs) {
-            if (blobby.first == AI_BLOBIO_MAGIC) {
+            if (blobby.first == magicName) {
                 master = blobby.second;
                 master = blobby.second;
+                master->name.Set(hasBaseName ? blobby.first : "");
                 break;
                 break;
             }
             }
         }
         }
+
         if (!master) {
         if (!master) {
             ASSIMP_LOG_ERROR("BlobIOSystem: no data written or master file was not closed properly.");
             ASSIMP_LOG_ERROR("BlobIOSystem: no data written or master file was not closed properly.");
             return nullptr;
             return nullptr;
         }
         }
 
 
-        master->name.Set("");
-
         cur = master;
         cur = master;
+
         for (const BlobEntry &blobby : blobs) {
         for (const BlobEntry &blobby : blobs) {
             if (blobby.second == master) {
             if (blobby.second == master) {
                 continue;
                 continue;
@@ -236,9 +247,14 @@ public:
             cur->next = blobby.second;
             cur->next = blobby.second;
             cur = cur->next;
             cur = cur->next;
 
 
-            // extract the file extension from the file written
-            const std::string::size_type s = blobby.first.find_first_of('.');
-            cur->name.Set(s == std::string::npos ? blobby.first : blobby.first.substr(s + 1));
+            if (hasBaseName) {
+                cur->name.Set(blobby.first);
+            }
+            else {
+                // extract the file extension from the file written
+                const std::string::size_type s = blobby.first.find_first_of('.');
+                cur->name.Set(s == std::string::npos ? blobby.first : blobby.first.substr(s + 1));
+            }
         }
         }
 
 
         // give up blob ownership
         // give up blob ownership
@@ -283,6 +299,7 @@ private:
     }
     }
 
 
 private:
 private:
+    std::string baseName;
     std::set<std::string> created;
     std::set<std::string> created;
     std::vector<BlobEntry> blobs;
     std::vector<BlobEntry> blobs;
 };
 };