Skip to content

Commit

Permalink
#5108: Remove static info file extension member, replace with static …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
codereader committed Nov 26, 2020
1 parent 439f290 commit ade784b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
28 changes: 14 additions & 14 deletions radiantcore/map/MapResource.cpp
Expand Up @@ -53,8 +53,6 @@ namespace
}
}

std::string MapResource::_infoFileExt;

// Constructor
MapResource::MapResource(const std::string& name) :
_originalName(name),
Expand All @@ -63,16 +61,6 @@ MapResource::MapResource(const std::string& name) :
// Initialise the paths, this is all needed for realisation
_path = rootPath(_originalName);
_name = os::getRelativePath(_originalName, _path);

if (_infoFileExt.empty())
{
_infoFileExt = game::current::getValue<std::string>(GKEY_INFO_FILE_EXTENSION);
}

if (!_infoFileExt.empty() && _infoFileExt[0] != '.')
{
_infoFileExt = "." + _infoFileExt;
}
}

void MapResource::rename(const std::string& fullPath)
Expand Down Expand Up @@ -152,7 +140,7 @@ bool MapResource::saveBackup()
}

fs::path auxFile = fullpath;
auxFile.replace_extension(_infoFileExt);
auxFile.replace_extension(getInfoFileExtension());

fs::path backup = fullpath;
backup.replace_extension(".bak");
Expand Down Expand Up @@ -425,6 +413,18 @@ void MapResource::openFileStream(const std::string& path, const std::function<vo
}
}

std::string MapResource::getInfoFileExtension()
{
std::string extension = game::current::getValue<std::string>(GKEY_INFO_FILE_EXTENSION);

if (!extension.empty() && extension[0] != '.')
{
extension = "." + extension;
}

return extension;
}

void MapResource::throwIfNotWriteable(const fs::path& path)
{
// Check writeability of the given file
Expand All @@ -443,7 +443,7 @@ void MapResource::saveFile(const MapFormat& format, const scene::IMapRootNodePtr
// Actual output file paths
fs::path outFile = filename;
fs::path auxFile = outFile;
auxFile.replace_extension(_infoFileExt);
auxFile.replace_extension(getInfoFileExtension());

// Check writeability of the primary output file
throwIfNotWriteable(outFile);
Expand Down
5 changes: 3 additions & 2 deletions radiantcore/map/MapResource.h
Expand Up @@ -25,8 +25,6 @@ class MapResource :
std::string _path;
std::string _name;

static std::string _infoFileExt;

// File extension of this resource
std::string _extension;

Expand Down Expand Up @@ -69,6 +67,9 @@ class MapResource :
// function is then called with the opened stream. Throws std::runtime_error on stream open failure.
void openFileStream(const std::string& path, const std::function<void(std::istream&)>& streamProcessor);

// Returns the extension of the auxiliary info file (including the leading dot character)
static std::string getInfoFileExtension();

// Checks if file can be overwritten (throws on failure)
static void throwIfNotWriteable(const fs::path& path);
};
Expand Down

0 comments on commit ade784b

Please sign in to comment.