Skip to content

Commit

Permalink
Refactor|FS: Added a method for getting file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jun 2, 2016
1 parent 8bf5a2c commit 2b25aca
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/src/resource/bundles.cpp
Expand Up @@ -193,7 +193,7 @@ Bundles::MatchResult Bundles::match(DataBundle const &bundle) const

// Additional criteria for recognizing WADs.
if (bundle.format() == DataBundle::Iwad ||
bundle.format() == DataBundle::Pwad)
bundle.format() == DataBundle::Pwad)
{
String lumpDirCRC32 = def->keyValue(QStringLiteral("lumpDirCRC32"));
if (!lumpDirCRC32.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/libdoomsday/src/savedsession.cpp
Expand Up @@ -392,7 +392,7 @@ File *SavedSession::Interpreter::interpretFile(File *sourceData) const
if (ZipArchive::recognize(*sourceData))
{
// It is a ZIP archive: we will represent it as a folder.
if (sourceData->name().fileNameExtension() == ".save")
if (sourceData->extension() == ".save")
{
/// @todo fixme: Don't assume this is a save package.
LOG_RES_VERBOSE("Interpreted %s as a SavedSession") << sourceData->description();
Expand Down
3 changes: 3 additions & 0 deletions doomsday/sdk/libcore/include/de/filesys/node.h
Expand Up @@ -46,6 +46,9 @@ class DENG2_PUBLIC Node : public Lockable, public Deletable
/// Returns the name of the file.
String name() const;

/// Returns the file name extension, including the preceding dot (".zip").
String extension() const;

/**
* Sets the parent node of this file.
*/
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libcore/src/data/info.cpp
Expand Up @@ -374,7 +374,7 @@ DENG2_PIMPL(Info)
}

// Continue parsing normally from here.
int endPos = startPos + lex.pos();
int endPos = startPos + int(lex.pos());
do { nextChar(); } while (cursor < endPos); // fast-forward

// Update the current token.
Expand All @@ -391,7 +391,7 @@ DENG2_PIMPL(Info)
//qDebug() << "now at" << content.substr(endPos - 15, endPos) << "^" << content.substr(endPos);

// Whitespace is removed from beginning and end.
return InfoValue(content.substr(startPos, lex.pos() - 1).trimmed(), InfoValue::Script);
return InfoValue(content.substr(startPos, int(lex.pos()) - 1).trimmed(), InfoValue::Script);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/data/ziparchive.cpp
Expand Up @@ -620,7 +620,7 @@ bool ZipArchive::recognize(File const &file)
if (file.status().type() == File::Status::FILE)
{
// For now, just check the name.
return recognizeZipExtension(file.name().fileNameExtension().lower());
return recognizeZipExtension(file.extension().lower());
}
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libcore/src/filesys/node.cpp
Expand Up @@ -43,6 +43,11 @@ String Node::name() const
return d->name;
}

String Node::extension() const
{
return d->name.fileNameExtension();
}

void Node::setParent(Node *parent)
{
DENG2_GUARD(this);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libcore/src/filesys/package.cpp
Expand Up @@ -384,7 +384,7 @@ String Package::identifierForFile(File const &file)
// Form the prefix if there are enclosing packs as parents.
String prefix;
Folder const *parent = file.parent();
while (parent && parent->name().fileNameExtension() == ".pack")
while (parent && parent->extension() == ".pack")
{
prefix = extractIdentifier(parent->name()) + "." + prefix;
parent = parent->parent();
Expand All @@ -396,7 +396,7 @@ File const *Package::containerOfFile(File const &file)
{
// Find the containing package.
File const *i = file.parent();
while (i && i->name().fileNameExtension() != ".pack")
while (i && i->extension() != ".pack")
{
i = i->parent();
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libgui/src/audio/waveform.cpp
Expand Up @@ -112,7 +112,7 @@ DENG2_PIMPL(Waveform)

void load(File const &src)
{
if (!src.name().fileNameExtension().compareWithoutCase(".wav"))
if (!src.extension().compareWithoutCase(".wav"))
{
// We know how to read WAV files.
loadWAV(Block(src));
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libgui/src/graphics/image.cpp
Expand Up @@ -896,7 +896,7 @@ Image Image::fromMaskedIndexedData(Size const &size, IByteArray const &imageAndM

bool Image::recognize(File const &file)
{
String const ext = file.name().fileNameExtension().toLower();
String const ext = file.extension().toLower();
return (ext == ".tga" || ext == ".pcx" || ext == ".png" || ext == ".jpg" ||
ext == ".jpeg" || ext == ".gif" || ext == ".tiff" || ext == ".ico");
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libgui/src/graphics/imagefile.cpp
Expand Up @@ -155,7 +155,7 @@ Image ImageFile::image() const
}
else
{
return Image::fromData(*source(), name().fileNameExtension());
return Image::fromData(*source(), extension());
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libgui/src/graphics/modeldrawable.cpp
Expand Up @@ -651,7 +651,7 @@ DENG2_PIMPL(ModelDrawable)
* Autodetect if these exist and make a list of their names.
*/
String anims;
if (file.name().fileNameExtension() == ".md5mesh")
if (file.extension() == ".md5mesh")
{
String const baseName = file.name().fileNameWithoutExtension() + "_";
for (auto const i : file.parent()->contents())
Expand Down

0 comments on commit 2b25aca

Please sign in to comment.