コード例 #1
0
ファイル: preferences.cpp プロジェクト: hyrio/War-Of-Kingdom
base_manager::base_manager()
{
	scoped_istream stream = istream_file(get_prefs_file(), true);
	read(prefs, *stream);

	if (member().empty()) {
		std::stringstream strstr;
		std::map<int, int> member;
		member.insert(std::make_pair(172, 5));
		member.insert(std::make_pair(176, 6));
		member.insert(std::make_pair(244, 7));
		member.insert(std::make_pair(279, 8));

		member.insert(std::make_pair(103, 8));
		member.insert(std::make_pair(106, 9));
		member.insert(std::make_pair(120, 9));
		member.insert(std::make_pair(381, 9));
		for (std::map<int ,int>::const_iterator it = member.begin(); it != member.end(); ++ it) {
			if (it != member.begin()) {
				strstr << ", ";
			}
			strstr << ((it->second << 16) | it->first);
		}
		set_member(strstr.str());
	}
}
コード例 #2
0
static std::pair<std::vector<std::string>, std::vector<std::string> > read_ignore_patterns(const std::string& addon_name)
{
	const std::string parentd = get_addon_campaigns_dir();
	const std::string exterior = parentd + "/" + addon_name + ".ign";
	const std::string interior = parentd + "/" + addon_name + "/_server.ign";

	std::pair<std::vector<std::string>, std::vector<std::string> > patterns;
	std::string ign_file;
	LOG_CFG << "searching for .ign file for '" << addon_name << "'...\n";
	if (file_exists(interior)) {
		ign_file = interior;
	} else if (file_exists(exterior)) {
		ign_file = exterior;
	} else {
		LOG_CFG << "no .ign file found for '" << addon_name << "'\n"
		        << "inserting default ignore patterns...\n";
		append_default_ignore_patterns(patterns);
		return patterns; // just default patterns
	}
	LOG_CFG << "found .ign file: " << ign_file << '\n';
	std::istream *stream = istream_file(ign_file);
	std::string line;
	while (std::getline(*stream, line)) {
		utils::strip(line);
		const size_t l = line.size();
		if (line[l - 1] == '/') { // directory; we strip the last /
			patterns.second.push_back(line.substr(0, l - 1));
		} else { // file
			patterns.first.push_back(line);
		}
	}
	return patterns;
}
コード例 #3
0
void get_addon_pbl_info(const std::string& addon_name, config& cfg)
{
	const std::string& pbl_path = get_pbl_file_path(addon_name);
	try {
		scoped_istream stream = istream_file(pbl_path);
		read(cfg, *stream);
	} catch(const config::error& e) {
		throw invalid_pbl_exception(pbl_path, e.message);
	}
}
コード例 #4
0
ファイル: preferences.cpp プロジェクト: lyumn/wes-server
base_manager::base_manager()
{
	try{
		scoped_istream stream = istream_file(get_prefs_file());
		read(prefs, *stream);
	} catch(const config::error& e) {
		ERR_CFG << "Error loading preference, message: "
				<< e.what()
				<< '\n';
	}
}
コード例 #5
0
ファイル: savegame.cpp プロジェクト: blackberry/Wesnoth
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();
	}
}
コード例 #6
0
void get_addon_install_info(const std::string& addon_name, config& cfg)
{
	const std::string& info_path = get_info_file_path(addon_name);
	scoped_istream stream = istream_file(info_path);
	try {
		read(cfg, *stream);
	} catch(const config::error& e) {
		ERR_CFG << "Failed to read add-on installation information for '"
				<< addon_name << "' from " << info_path << ":\n"
				<< e.message << std::endl;
	}
}
コード例 #7
0
ファイル: addon_management.cpp プロジェクト: dodikk/iWesnoth
void get_addon_info(const std::string& addon_name, config& cfg)
{
	const std::string parentd = get_addon_campaigns_dir();

	// Cope with old-style or new-style file organization
	const std::string exterior = parentd + "/" + addon_name + ".pbl";
	const std::string interior = parentd + "/" + addon_name + "/_server.pbl";
	const std::string pbl_file = (file_exists(exterior)? exterior : interior);

	scoped_istream stream = istream_file(pbl_file);
	read(cfg, *stream);
}
コード例 #8
0
ファイル: preferences.cpp プロジェクト: Coffee--/wesnoth-old
base_manager::base_manager()
{
	try{
#ifdef DEFAULT_PREFS_PATH
		scoped_istream stream = istream_file(get_default_prefs_file());
		read(prefs, *stream);

		config user_prefs;
		stream = istream_file(get_prefs_file());
		read(user_prefs, *stream);

		prefs.merge_with(user_prefs);
#else
		scoped_istream stream = istream_file(get_prefs_file());
		read(prefs, *stream);
#endif
	} catch(const config::error& e) {
		ERR_CFG << "Error loading preference, message: "
				<< e.what()
				<< '\n';
	}
}
コード例 #9
0
void persist_file_context::load() {
	std::string cfg_dir = get_dir(get_user_data_dir() + "/persist");

	std::string cfg_name = get_persist_cfg_name(namespace_.root_);
	if (file_exists(cfg_name) && !is_directory(cfg_name)) {
		scoped_istream file_stream = istream_file(cfg_name);
		if (!(file_stream->fail())) {
			try {
				read(cfg_,*file_stream);
			} catch (config::error &err) {
				LOG_PERSIST << err.message;
			}
		}
	}
}
コード例 #10
0
ファイル: savegame.cpp プロジェクト: blackberry/Wesnoth
config& save_index::load()
{
	if(save_index_loaded == false) {
		try {
			scoped_istream stream = istream_file(get_save_index_file());
			read(save_index_cfg, *stream);
		} 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();
		}

		save_index_loaded = true;
	}

	return save_index_cfg;
}
コード例 #11
0
ファイル: manager.cpp プロジェクト: piumato/wesnoth-old
void refresh_addon_version_info_cache()
{
	version_info_cache.clear();

	LOG_CFG << "refreshing add-on versions cache\n";

	const std::vector<std::string>& addons = installed_addons();
	if(addons.empty()) {
		return;
	}

	std::vector<std::string> addon_info_files(addons.size());

	std::transform(addons.begin(), addons.end(),
	               addon_info_files.begin(), get_info_file_path);

	for(size_t i = 0; i < addon_info_files.size(); ++i) {
		assert(i < addons.size());

		const std::string& addon = addons[i];
		const std::string& info_file = addon_info_files[i];

		if(file_exists(info_file)) {
			scoped_istream stream = istream_file(info_file);

			config cfg;
			read(cfg, *stream);

			const config& info_cfg = cfg.child("info");
			if(!info_cfg) {
				continue;
			}

			const std::string& version = info_cfg["version"].str();
			LOG_CFG << "cached add-on version: " << addon << " [" << version << "]\n";

			version_info_cache[addon] = version;
		} else if (!have_addon_pbl_info(addon) && !have_addon_in_vcs_tree(addon)) {
			// Don't print the warning if the user is clearly the author
			WRN_CFG << "add-on '" << addon << "' has no _info.cfg; cannot read version info\n";
		}
	}
}
コード例 #12
0
rwops_ptr make_read_RWops(const std::string &path) {
	rwops_ptr rw(SDL_AllocRW(), &SDL_FreeRW);

	rw->size = &ifs_size;
	rw->seek = &ifs_seek;
	rw->read = &ifs_read;
	rw->write = &ifs_write;
	rw->close = &ifs_close;

	rw->type = read_type;

	scoped_istream ifs = istream_file(path);
	if(!ifs) {
		ERR_FS << "make_read_RWops: istream_file returned NULL on " << path << '\n';
		rw.reset();
		return rw;
	}

	rw->hidden.unknown.data1 = ifs.release();

	return rw;
}
コード例 #13
0
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));
			}
		}
	}
コード例 #14
0
ファイル: filesystem.cpp プロジェクト: Duthlet/wesnoth
std::string read_file(const std::string &fname)
{
	scoped_istream s = istream_file(fname);
	return read_stream(*s);
}
コード例 #15
0
std::string read_file(const std::string &fname, bool to_utf16)
{
	scoped_istream s = istream_file(fname, to_utf16);
	return read_stream(*s);
}
コード例 #16
0
ファイル: preferences.cpp プロジェクト: oys0317/opensanguo
base_manager::base_manager()
{
	scoped_istream stream = istream_file(get_prefs_file());
	read(prefs, *stream);
}