From fd57a4df6fc1f2016f590e0865bfb64a615fbdf2 Mon Sep 17 00:00:00 2001 From: Dave White Date: Mon, 6 Oct 2003 04:16:16 +0000 Subject: [PATCH] got rid of use of spaces in saved game names --- src/gamestatus.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/gamestatus.cpp b/src/gamestatus.cpp index 4c96a7b49a7..340f8f649f2 100644 --- a/src/gamestatus.cpp +++ b/src/gamestatus.cpp @@ -15,6 +15,7 @@ #include "gamestatus.hpp" #include "language.hpp" +#include #include #include @@ -154,18 +155,30 @@ std::vector get_saves_list() { std::vector res; get_files_in_dir(get_saves_dir(),&res); + for(std::vector::iterator i = res.begin(); i != res.end(); ++i) + std::replace(i->begin(),i->end(),'_',' '); return res; } void load_game(game_data& data, const std::string& name, game_state& state) { - config cfg(read_file(get_saves_dir() + "/" + name)); + std::string modified_name = name; + std::replace(modified_name.begin(),modified_name.end(),' ','_'); + + //try reading the file both with and without underscores + std::string file_data = read_file(get_saves_dir() + "/" + modified_name); + if(file_data.empty()) { + file_data = read_file(get_saves_dir() + "/" + name); + } + + config cfg(file_data); state = read_game(data,&cfg); } void save_game(const game_state& state) { - const std::string& name = state.label; + std::string name = state.label; + std::replace(name.begin(),name.end(),' ','_'); config cfg; write_game(state,cfg);