From ade784b112629c27c2ddd8c2cac3d56ffc6bb349 Mon Sep 17 00:00:00 2001 From: codereader Date: Thu, 26 Nov 2020 12:18:54 +0100 Subject: [PATCH] #5108: Remove static info file extension member, replace with static method --- radiantcore/map/MapResource.cpp | 28 ++++++++++++++-------------- radiantcore/map/MapResource.h | 5 +++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/radiantcore/map/MapResource.cpp b/radiantcore/map/MapResource.cpp index 4688e9fdf1..0bfd9380f4 100644 --- a/radiantcore/map/MapResource.cpp +++ b/radiantcore/map/MapResource.cpp @@ -53,8 +53,6 @@ namespace } } -std::string MapResource::_infoFileExt; - // Constructor MapResource::MapResource(const std::string& name) : _originalName(name), @@ -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(GKEY_INFO_FILE_EXTENSION); - } - - if (!_infoFileExt.empty() && _infoFileExt[0] != '.') - { - _infoFileExt = "." + _infoFileExt; - } } void MapResource::rename(const std::string& fullPath) @@ -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"); @@ -425,6 +413,18 @@ void MapResource::openFileStream(const std::string& path, const std::function(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 @@ -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); diff --git a/radiantcore/map/MapResource.h b/radiantcore/map/MapResource.h index c349b3c2de..35c6782bfa 100644 --- a/radiantcore/map/MapResource.h +++ b/radiantcore/map/MapResource.h @@ -25,8 +25,6 @@ class MapResource : std::string _path; std::string _name; - static std::string _infoFileExt; - // File extension of this resource std::string _extension; @@ -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& 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); };