Fix up leader image paths for existing saves

As a bonus, this also makes the images show up when a save from Windows
is loaded on GNU/Linux or macOS.
It would be particularly useful if Steam Cloud was supported.
This commit is contained in:
Jyrki Vesterinen 2017-10-28 20:05:29 +03:00
parent a6df1750d1
commit 32621bddf6
2 changed files with 12 additions and 0 deletions

View file

@ -31,6 +31,8 @@
#include "filesystem.hpp"
#include "config.hpp"
#include <boost/algorithm/string/replace.hpp>
static lg::log_domain log_engine("engine");
#define LOG_SAVE LOG_STREAM(info, log_engine)
#define ERR_SAVE LOG_STREAM(err, log_engine)
@ -116,6 +118,7 @@ save_index_class::save_index_class()
config& save_index_class::data(const std::string& name) {
config& cfg = data();
if (config& sv = cfg.find_child("save", "save", name)) {
fix_leader_image_path(sv);
return sv;
}
config& res = cfg.add_child("save");
@ -144,6 +147,14 @@ config& save_index_class::data() {
return data_;
}
void save_index_class::fix_leader_image_path(config& data) {
for(config& leader : data.child_range("leader")) {
std::string leader_image = leader["leader_image"];
boost::algorithm::replace_all(leader_image, "\\", "/");
leader["leader_image"] = leader_image;
}
}
save_index_class save_index_manager;
class filename_filter {

View file

@ -89,6 +89,7 @@ public:
private:
config& data(const std::string& name) ;
config& data() ;
static void fix_leader_image_path(config& data);
private:
bool loaded_;
config data_;