Пример #1
0
void manager::delete_game(const std::string& name)
{
	std::string modified_name = name;
	replace_space2underbar(modified_name);

	remove((get_saves_dir() + "/" + name).c_str());
	remove((get_saves_dir() + "/" + modified_name).c_str());
}
Пример #2
0
// Throws game::save_game_failed
filesystem::scoped_ostream savegame::open_save_game(const std::string &label)
{
	std::string name = label;
	replace_space2underbar(name);

	try {
		return filesystem::scoped_ostream(filesystem::ostream_file(filesystem::get_saves_dir() + "/" + name));
	} catch(filesystem::io_exception& e) {
		throw game::save_game_failed(e.what());
	}
}
Пример #3
0
bool manager::save_game_exists(const std::string& name, const bool compress_saves)
{
	std::string fname = name;
	replace_space2underbar(fname);

	if(compress_saves) {
		fname += ".gz";
	}

	return file_exists(get_saves_dir() + "/" + fname);
}
Пример #4
0
void savegame::finish_save_game(const config_writer &out)
{
	std::string name = gamestate_.classification().label;
	replace_space2underbar(name);
	std::string fname(get_saves_dir() + "/" + name);

	try {
		if(!out.good()) {
			throw game::save_game_failed(_("Could not write to file"));
		}

		config& summary = save_index::save_summary(gamestate_.classification().label);
		extract_summary_data_from_save(summary);
		const int mod_time = static_cast<int>(file_create_time(fname));
		summary["mod_time"] = str_cast(mod_time);
		save_index::write_save_index();
	} catch(io_exception& e) {
		throw game::save_game_failed(e.what());
	}
}
Пример #5
0
void manager::read_save_file(const std::string& name, config& cfg, std::string* error_log)
{
	std::string modified_name = name;
	replace_space2underbar(modified_name);

	// Try reading the file both with and without underscores, if needed append .gz as well
	scoped_istream file_stream = istream_file(get_saves_dir() + "/" + modified_name);
	if (file_stream->fail()) {
		file_stream = istream_file(get_saves_dir() + "/" + name);
	}
	if(file_stream->fail() && !is_gzip_file(modified_name)) {
		file_stream = istream_file(get_saves_dir() + "/" + modified_name + ".gz");
		if (file_stream->fail()) {
			file_stream = istream_file(get_saves_dir() + "/" + name + ".gz");
		}
		modified_name += ".gz";
	}

	cfg.clear();
	try{
		/*
		 * Test the modified name, since it might use a .gz
		 * file even when not requested.
		 */
		if(is_gzip_file(modified_name)) {
			read_gz(cfg, *file_stream);
		} else {
			read(cfg, *file_stream);
		}
	} catch (config::error &err)
	{
		LOG_SAVE << err.message;
		if (error_log) *error_log += err.message;
		throw game::load_game_failed();
	}

	if(cfg.empty()) {
		LOG_SAVE << "Could not parse file data into config\n";
		throw game::load_game_failed();
	}
}