Skip to content

Commit

Permalink
Functional implementation of forEachPointfile()
Browse files Browse the repository at this point in the history
Method uses fs::directory_iterator to enumerate files in the directory
containing the map file, and looks for any file with a .lin extension and a
stem which corresponds to the map name (with a possible underscore suffix).
Unit test now passes as a result.
  • Loading branch information
Matthew Mott committed May 12, 2021
1 parent 6c3af51 commit 9fc9017
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions radiantcore/map/Map.cpp
Expand Up @@ -193,9 +193,42 @@ bool Map::isUnnamed() const {
return _mapName == _(MAP_UNNAMED_STRING);
}

namespace
{
bool pointfileNameMatch(const std::string& candidate,
const std::string& mapStem)
{
// A matching point file either has an identical stem to the map file,
// or the map file stem with an underscore suffix (e.g.
// "mapfile_portal_123_456.lin")
if (candidate == mapStem)
return true;
else if (candidate.rfind(mapStem + "_", 0) == 0)
return true;
else
return false;
}
}

void Map::forEachPointfile(PointfileFunctor func) const
{
static const char* LIN_EXT = ".lin";

const fs::path map(getMapName());
const fs::path mapDir = map.parent_path();
const fs::path mapStem = map.stem();

// Iterate over files in the map directory
for (const auto& entry: fs::directory_iterator(mapDir))
{
// Ignore anything which isn't a .lin file
auto entryPath = entry.path();
if (entryPath.extension() == LIN_EXT
&& pointfileNameMatch(entryPath.stem(), mapStem))
{
func(entryPath);
}
}
}

void Map::onSceneNodeErase(const scene::INodePtr& node)
Expand Down

0 comments on commit 9fc9017

Please sign in to comment.