Example #1
0
		game_config_manager()
			: cfg_()
			, paths_manager_()
			, hotkey_manager_()
			, font_manager_()
		{
#ifdef _WIN32
			std::setlocale(LC_ALL, "English");
#else
			std::setlocale(LC_ALL, "C");
			std::setlocale(LC_MESSAGES, "");
#endif
			const std::string& intl_dir = get_intl_dir();
			bindtextdomain ("wesnoth", intl_dir.c_str());
			bind_textdomain_codeset ("wesnoth", "UTF-8");
			bindtextdomain ("wesnoth-lib", intl_dir.c_str());
			bind_textdomain_codeset ("wesnoth-lib", "UTF-8");
			textdomain ("wesnoth");


			font::load_font_config();
			gui2::init();
			load_language_list();
			game_config::config_cache::instance().add_define("TEST");
			game_config::config_cache::instance().get_config(game_config::path + "/data/test/", cfg_);
			::init_textdomains(cfg_);
			const std::vector<language_def>& languages = get_languages();
			std::vector<language_def>::const_iterator English = std::find_if(languages.begin(),
					languages.end(),
					match_english); // Using German because the most active translation
			::set_language(*English);

			cfg_.merge_children("units");

			const config* const units = cfg_.child("units");
			if(units != NULL) {
				unit_type_data::types().set_config(*units);
			}

			game_config::load_config(cfg_.child("game_config"));
			hotkey::deactivate_all_scopes();
			hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
			hotkey::set_scope_active(hotkey::SCOPE_GAME);

			hotkey::load_hotkeys(cfg_);
			paths_manager_.set_paths(cfg_);
			font::load_font_config();

		}
void init_textdomains(const config& cfg)
{
	foreach (const config &t, cfg.child_range("textdomain"))
	{
		const std::string &name = t["name"];
		const std::string &path = t["path"];

		if(path.empty()) {
			t_string::add_textdomain(name, get_intl_dir());
		} else {
			std::string location = get_binary_dir_location("", path);

			if (location.empty()) {
				//if location is empty, this causes a crash on Windows, so we
				//disallow adding empty domains
				ERR_G << "no location found for '" << path << "', skipping textdomain\n";
			} else {
				t_string::add_textdomain(name, location);
			}
		}
	}
}
Example #3
0
void wml_config_from_file(const std::string &fname, config &cfg, uint32_t* nfiles, uint32_t* sum_size, uint32_t* modified)
{
	posix_file_t						fp = INVALID_FILE;
	uint32_t							datalen, fsizelow, fsizehigh, max_str_len, bytertd, tdcnt, idx, len;
	uint8_t								*data = NULL, *namebuf = NULL, *valbuf = NULL;
	char								tdname[MAXLEN_TEXTDOMAIN + 1];

	std::vector<std::string>			tdomain;

	posix_print("<xwml.cpp>::wml_config_from_file------fname: %s\n", fname.c_str());

	cfg.clear();	// 首先清空,以下是增加方式

	posix_fopen(fname.c_str(), GENERIC_READ, OPEN_EXISTING, fp);
	if (fp == INVALID_FILE) {
		posix_print("------<xwml.cpp>::wml_config_from_file, cannot create %s for read\n", fname.c_str());
		goto exit;
	}
	posix_fsize(fp, fsizelow, fsizehigh);
	if (fsizelow <= 16) {
		goto exit;
	}
	posix_fseek(fp, 0, 0);
	posix_fread(fp, &len, 4, bytertd);
	// 判断是不是XWML
	if (len != mmioFOURCC('X', 'W', 'M', 'L')) {
		goto exit;
	}
	posix_fread(fp, &len, 4, bytertd);
	if (nfiles) {
		*nfiles = len;
	}
	posix_fread(fp, &len, 4, bytertd);
	if (sum_size) {
		*sum_size = len;
	}
	posix_fread(fp, &len, 4, bytertd);
	if (modified) {
		*modified = len;
	}
	posix_fread(fp, &max_str_len, sizeof(max_str_len), bytertd);
			
	// 读出po
	posix_fread(fp, &tdcnt, sizeof(tdcnt), bytertd);
	datalen = fsizelow - 16 - sizeof(max_str_len) - sizeof(tdcnt);
	for (idx = 0; idx < tdcnt; idx ++) {
		posix_fread(fp, &len, sizeof(uint32_t), bytertd);
		posix_fread(fp, tdname, len, bytertd);
		tdname[len] = 0;
		tdomain.push_back(tdname);

		datalen -= sizeof(uint32_t) + len;

		t_string::add_textdomain(tdomain.back(), get_intl_dir());
	}
		
	data = (uint8_t *)malloc(datalen);
	namebuf = (uint8_t *)malloc(max_str_len + 1 + 1024);
	valbuf = (uint8_t *)malloc(max_str_len + 1 + 1024);

	// 剩下数据读出sram
	posix_fread(fp, data, datalen, bytertd);

	wml_config_from_data(data, datalen, namebuf, valbuf, tdomain, cfg);

exit:
	if (fp != INVALID_FILE) {
		posix_fclose(fp);
	}
	if (data) {
		free(data);
	}
	if (namebuf) {
		free(namebuf);
	}
	if (valbuf) {
		free(valbuf);
	}
	return;
}