Пример #1
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();
	}
}
void room_manager::read_rooms()
{
	if (!filename_.empty() && file_exists(filename_)) {
		LOG_LOBBY << "Reading rooms from " <<  filename_ << "\n";
		config cfg;
		scoped_istream file = istream_file(filename_);
		if (compress_stored_rooms_) {
			read_gz(cfg, *file);
		} else {
			detect_format_and_read(cfg, *file);
		}

		foreach (const config &c, cfg.child_range("room")) {
			room* r(new room(c));
			if (room_exists(r->name())) {
				ERR_LOBBY << "Duplicate room ignored in stored rooms: "
					<< r->name() << "\n";
				delete r;
			} else {
				rooms_by_name_.insert(std::make_pair(r->name(), r));
			}
		}
	}
Пример #3
0
void ana_network_manager::read_config( const ana::read_buffer& buffer, config& cfg)
{
    std::istringstream input( buffer->string() );

    read_gz(cfg, input);
}
Пример #4
0
void config_cache::read_file(const std::string& file_path, config& cfg)
{
	filesystem::scoped_istream stream = filesystem::istream_file(file_path);
	read_gz(cfg, *stream);
}