Fix for bug #18665, bug load index not being rebuilt.

Restored correct behavior of inserting configs for saves that are
missing index enties.
This commit is contained in:
Thonsew 2011-09-24 19:03:28 +00:00
parent 6711f50f1a
commit 786d6c0d67
3 changed files with 39 additions and 12 deletions

View file

@ -597,17 +597,11 @@ std::string load_game_dialog(display& disp, const config& game_config, bool* sho
std::map<std::string,std::string> parent_to_child;
std::vector<savegame::save_info>::const_iterator i;
for(i = games.begin(); i != games.end(); ++i) {
std::string sname(i->name);
if(sname.length() < 3 || sname.substr(sname.length() - 3) != ".gz") {
sname += ".gz"; }
config::t_token iname(sname);
config::t_child_range_index::iterator xcfgi = index.find( iname);
config* cfg;
if(xcfgi != index.end()){
cfg = &*xcfgi->second;
parent_to_child[(*cfg)["parent"]] = iname;
saves_and_summaries.push_back(save_with_summary(*i, cfg));
}
n_token::t_token tname(i->name);
config * cfg = &savegame::save_index::find_or_create_summary(index, tname);
n_token::t_token gname = savegame::save_index::gz_corrected_filename(tname);
parent_to_child[(*cfg)["parent"]] = gname;
saves_and_summaries.push_back(save_with_summary(*i, cfg));
}
const events::event_context context;

View file

@ -351,13 +351,14 @@ config& save_index::load() {
try {
scoped_istream stream = istream_file(get_save_index_file());
read(*save_index_cfg, *stream);
save_index_loaded = true;
} catch(io_exception& e) {
ERR_SAVE << "error reading save index: '" << e.what() << "'\n";
} catch(config::error&) {
ERR_SAVE << "error parsing save index config file\n";
save_index_cfg->clear();
}
//Only try once
save_index_loaded = true;
}
return *save_index_cfg;
@ -390,6 +391,34 @@ config::t_child_range_index const save_index::indexed_summaries(){
return load().child_range_index(z_save, z_save);
}
n_token::t_token save_index::gz_corrected_filename(n_token::t_token const & name) {
/*
* All saves are .gz files now so make sure we use that name when opening
* a file. If not some parts of the code use the name with and some parts
* without the .gz suffix.
*/
std::string sname(name);
if(sname.length() < 3 || sname.substr(sname.length() - 3) != ".gz") {
sname += ".gz"; }
return config::t_token(sname);
}
config & save_index::find_or_create_summary(config::t_child_range_index & index, n_token::t_token const & name) {
static const config::t_token & z_save( generate_safe_static_const_t_interned(n_token::t_token("save")) );
config::t_token iname(gz_corrected_filename(name));
config::t_child_range_index::iterator xcfgi = index.find( iname);
if(xcfgi != index.end()){
return *xcfgi->second; }
//Fallback create an empty summary
config & cfg = load();
config &res = cfg.add_child(z_save);
res[z_save] = iname;
return res;
}
void save_index::write_save_index()
{
log_scope("write_save_index()");

View file

@ -80,8 +80,12 @@ public:
static config& save_summary(std::string save);
/** Update the save_index file with changed savegame information. */
static void write_save_index();
/** Correct the filename to include the .gz suffix */
static n_token::t_token gz_corrected_filename(n_token::t_token const & name);
/** Create an index to the save summaries. */
static config::t_child_range_index const indexed_summaries();
/** Use the index to find an existing or create a new save summary and a corrected filename. */
static config & find_or_create_summary(config::t_child_range_index & index, n_token::t_token const &name);
private:
/** Default-Constructor (don't instantiate this class) */