Add optional blob base name to blob IO system.
parent
964778cac1
commit
be85f238f4
|
@ -194,8 +194,14 @@ class BlobIOSystem : public IOSystem {
|
|||
friend class BlobIOStream;
|
||||
typedef std::pair<std::string, aiExportDataBlob *> BlobEntry;
|
||||
|
||||
|
||||
public:
|
||||
BlobIOSystem() {
|
||||
BlobIOSystem() :
|
||||
baseName{} {
|
||||
}
|
||||
|
||||
BlobIOSystem(const std::string &baseName) :
|
||||
baseName(baseName) {
|
||||
}
|
||||
|
||||
virtual ~BlobIOSystem() {
|
||||
|
@ -207,27 +213,32 @@ public:
|
|||
public:
|
||||
// -------------------------------------------------------------------
|
||||
const char *GetMagicFileName() const {
|
||||
return AI_BLOBIO_MAGIC;
|
||||
return baseName.empty() ? AI_BLOBIO_MAGIC : baseName.c_str();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
aiExportDataBlob *GetBlobChain() {
|
||||
const auto magicName = std::string(this->GetMagicFileName());
|
||||
const bool hasBaseName = baseName.empty();
|
||||
|
||||
// one must be the master
|
||||
aiExportDataBlob *master = nullptr, *cur;
|
||||
|
||||
for (const BlobEntry &blobby : blobs) {
|
||||
if (blobby.first == AI_BLOBIO_MAGIC) {
|
||||
if (blobby.first == magicName) {
|
||||
master = blobby.second;
|
||||
master->name.Set(hasBaseName ? blobby.first : "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!master) {
|
||||
ASSIMP_LOG_ERROR("BlobIOSystem: no data written or master file was not closed properly.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
master->name.Set("");
|
||||
|
||||
cur = master;
|
||||
|
||||
for (const BlobEntry &blobby : blobs) {
|
||||
if (blobby.second == master) {
|
||||
continue;
|
||||
|
@ -236,10 +247,15 @@ public:
|
|||
cur->next = blobby.second;
|
||||
cur = cur->next;
|
||||
|
||||
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
|
||||
blobs.clear();
|
||||
|
@ -283,6 +299,7 @@ private:
|
|||
}
|
||||
|
||||
private:
|
||||
std::string baseName;
|
||||
std::set<std::string> created;
|
||||
std::vector<BlobEntry> blobs;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue