Skip to content

Commit

Permalink
libdoomsday: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jun 2, 2016
1 parent 94c12c8 commit 8bf5a2c
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions doomsday/apps/libdoomsday/src/resource/databundle.cpp
Expand Up @@ -88,6 +88,7 @@ DENG2_PIMPL(DataBundle)
": WAD file lump directory not found");
}

// Determine the WAD type, if unspecified.
format = (lumpDir->type() == res::LumpDirectory::Pwad? Pwad : Iwad);

/*qDebug() << "format:" << (lumpDir->type()==res::LumpDirectory::Pwad? "PWAD" : "IWAD")
Expand All @@ -104,10 +105,28 @@ DENG2_PIMPL(DataBundle)

// Search for known data files in the bundle registry.
res::Bundles::MatchResult matched = DoomsdayApp::bundles().match(self);
File &dataFile = self.asFile();

// Metadata for the package will be collected into this record.
Record meta;
meta.set("path", dataFile.path());
meta.set("bundleScore", matched.bestScore);

if (matched)
{
// Package metadata has been defined for this file (databundles.dei).
packageId = matched.packageId;

if (lumpDir)
{
meta.set("lumpDirCRC32", lumpDir->crc32())
.value().as<NumberValue>().setSemanticHints(NumberValue::Hex);
}

meta.set("title", matched.bestMatch->keyValue("info:title"));
meta.set("author", matched.bestMatch->keyValue("info:author"));
meta.set("license", matched.bestMatch->keyValue("info:license", "Unknown"));
meta.set("tags", matched.bestMatch->keyValue("info:tags"));
}
else
{
Expand All @@ -116,6 +135,11 @@ DENG2_PIMPL(DataBundle)
// - .manifest companion


meta.set("title", dataFile.name());
meta.set("author", "Unknown");
meta.set("license", "Unknown");
meta.set("tags", "generated");

// Generate an identifier based on the information we have.
static String const formatDomains[] = {
"file.local",
Expand All @@ -142,7 +166,6 @@ DENG2_PIMPL(DataBundle)
* Set up the package metadata according to the best matched known
* information or autogenerated entries.
*/
File &dataFile = self.asFile();

// Finally, make a link that represents the package.
if (auto chosen = chooseUniqueLinkPathAndVersion(dataFile, packageId,
Expand All @@ -155,33 +178,8 @@ DENG2_PIMPL(DataBundle)

// Set up package metadata in the link.
Record &metadata = Package::initializeMetadata(*pkgLink, packageId);
metadata.set("path", dataFile.path());
metadata.copyMembersFrom(meta);
metadata.set("version", !chosen.version.isEmpty()? chosen.version : "0.0");
if (lumpDir)
{
metadata.set("lumpDirCRC32", lumpDir->crc32())
.value().as<NumberValue>().setSemanticHints(NumberValue::Hex);
}
metadata.set("bundleScore", matched.bestScore);

// Get the rest of the metadata.
if (matched)
{
metadata.set("title", matched.bestMatch->keyValue("info:title"));
metadata.set("tags", matched.bestMatch->keyValue("info:tags"));
metadata.set("author", matched.bestMatch->keyValue("info:author"));

String license = matched.bestMatch->keyValue("info:license");
if (license.isEmpty()) license = "Unknown";
metadata.set("license", license);
}
else
{
metadata.set("title", dataFile.name());
metadata.set("author", "Unknown");
metadata.set("license", "Unknown");
metadata.set("tags", "generated");
}

LOG_RES_VERBOSE("Generated package:\n%s") << metadata.asText();

Expand Down Expand Up @@ -330,13 +328,13 @@ void DataBundle::set(Offset, Byte const *, Size)
Record &DataBundle::objectNamespace()
{
DENG2_ASSERT(dynamic_cast<File *>(this) != nullptr);
return dynamic_cast<File *>(this)->objectNamespace().subrecord(QStringLiteral("package"));
return asFile().objectNamespace().subrecord(QStringLiteral("package"));
}

Record const &DataBundle::objectNamespace() const
{
DENG2_ASSERT(dynamic_cast<File const *>(this) != nullptr);
return dynamic_cast<File const *>(this)->objectNamespace().subrecord(QStringLiteral("package"));
return asFile().objectNamespace().subrecord(QStringLiteral("package"));
}

void DataBundle::setFormat(Format format)
Expand Down

0 comments on commit 8bf5a2c

Please sign in to comment.