コード例 #1
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";
		}
	}
}
コード例 #2
0
ファイル: state.cpp プロジェクト: Martin9295/wesnoth
addon_tracking_info get_addon_tracking_info(const addon_info& addon)
{
	const std::string& id = addon.id;
	addon_tracking_info t;

	t.can_publish = have_addon_pbl_info(id);
	t.in_version_control = have_addon_in_vcs_tree(id);
	t.installed_version = version_info(0, 0, 0, false);

	if(is_addon_installed(id)) {
		if(t.can_publish) {
			// Try to obtain the version number from the .pbl first.
			config pbl;
			get_addon_pbl_info(id, pbl);

			if(pbl.has_attribute("version")) {
				t.installed_version = pbl["version"].str();
			}
		} else {
			// We normally use the _info.cfg version instead.
			t.installed_version = get_addon_version_info(id);
		}

		const version_info& remote_version = addon.version;

		if(remote_version == t.installed_version) {
			t.state = ADDON_INSTALLED;
		} else if(remote_version > t.installed_version) {
			t.state = ADDON_INSTALLED_UPGRADABLE;
		} else /* if(remote_version < t.installed_version) */ {
			t.state = ADDON_INSTALLED_OUTDATED;
		}
	} else {
		t.state = ADDON_NONE;
	}

	return t;
}