addon/mg: Turn _info.cfg writer into a public API
This reduces code duplication in the client proper resulting from the addition of delta pack support, plus makes the overall procedure less complicated since we don't have to inject a file into the pack before unpacking it to disk.
This commit is contained in:
parent
3ddff73675
commit
d8f943664f
3 changed files with 30 additions and 48 deletions
|
@ -325,25 +325,6 @@ bool addons_client::download_addon(config& archive_cfg, const std::string& id, c
|
|||
return !update_last_error(archive_cfg);
|
||||
}
|
||||
|
||||
static std::string write_info_contents(const addon_info& info)
|
||||
{
|
||||
LOG_ADDONS << "generating version info for add-on '" << info.id << "'\n";
|
||||
|
||||
std::ostringstream info_contents;
|
||||
config wml;
|
||||
|
||||
info_contents <<
|
||||
"#\n"
|
||||
"# File automatically generated by Wesnoth to keep track\n"
|
||||
"# of version information on installed add-ons. DO NOT EDIT!\n"
|
||||
"#\n";
|
||||
|
||||
info.write_minimal(wml.add_child("info"));
|
||||
write(info_contents, wml);
|
||||
|
||||
return info_contents.str();
|
||||
}
|
||||
|
||||
bool addons_client::install_addon(config& archive_cfg, const addon_info& info)
|
||||
{
|
||||
const cursor::setter cursor_setter(cursor::WAIT);
|
||||
|
@ -354,20 +335,6 @@ bool addons_client::install_addon(config& archive_cfg, const addon_info& info)
|
|||
if(archive_cfg.has_child("removelist") || archive_cfg.has_child("addlist")) {
|
||||
LOG_ADDONS << "Received an updatepack for the addon '" << info.id << "'\n";
|
||||
|
||||
// Update the version tracking file
|
||||
config& info_remove = archive_cfg.add_child("removelist");
|
||||
config& remove_maindir = info_remove.add_child("dir");
|
||||
remove_maindir["name"] = info.id;
|
||||
config file;
|
||||
file["name"] = "_info.cfg";
|
||||
remove_maindir.add_child("file", file);
|
||||
|
||||
config& info_add = archive_cfg.add_child("addlist");
|
||||
config& add_maindir = info_add.add_child("dir");
|
||||
add_maindir["name"] = info.id;
|
||||
file["contents"] = write_info_contents(info);
|
||||
add_maindir.add_child("file", file);
|
||||
|
||||
// A consistency check
|
||||
for(const config::any_child entry : archive_cfg.all_children_range()) {
|
||||
if(entry.key == "removelist" || entry.key == "addlist") {
|
||||
|
@ -407,21 +374,6 @@ bool addons_client::install_addon(config& archive_cfg, const addon_info& info)
|
|||
"with case conflicts. This may cause problems.", i18n_symbols));
|
||||
}
|
||||
|
||||
// Add local version information before unpacking
|
||||
config* maindir = &archive_cfg.find_child("dir", "name", info.id);
|
||||
if(!*maindir) {
|
||||
LOG_ADDONS << "downloaded add-on '" << info.id
|
||||
<< "' is missing its directory in the archive; creating it\n";
|
||||
maindir = &archive_cfg.add_child("dir");
|
||||
(*maindir)["name"] = info.id;
|
||||
}
|
||||
|
||||
config file;
|
||||
file["name"] = "_info.cfg";
|
||||
file["contents"] = write_info_contents(info);
|
||||
|
||||
maindir->add_child("file", file);
|
||||
|
||||
LOG_ADDONS << "unpacking " << info.id << '\n';
|
||||
|
||||
// Remove any previously installed versions
|
||||
|
@ -433,6 +385,10 @@ bool addons_client::install_addon(config& archive_cfg, const addon_info& info)
|
|||
LOG_ADDONS << "unpacking finished\n";
|
||||
}
|
||||
|
||||
config info_cfg;
|
||||
info.write_minimal(info_cfg);
|
||||
write_addon_install_info(info.id, info_cfg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,23 @@ void get_addon_install_info(const std::string& addon_name, config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void write_addon_install_info(const std::string& addon_name, const config& cfg)
|
||||
{
|
||||
LOG_CFG << "Writing version info for add-on '" << addon_name << "'\n";
|
||||
|
||||
const auto& info_path = get_info_file_path(addon_name);
|
||||
auto out = filesystem::ostream_file(info_path);
|
||||
|
||||
*out << "#\n"
|
||||
<< "# File automatically generated by Wesnoth to keep track\n"
|
||||
<< "# of version information on installed add-ons. DO NOT EDIT!\n"
|
||||
<< "#\n";
|
||||
|
||||
config envelope;
|
||||
envelope.add_child("info", cfg);
|
||||
write(*out, envelope);
|
||||
}
|
||||
|
||||
bool remove_local_addon(const std::string& addon)
|
||||
{
|
||||
const std::string addon_dir = filesystem::get_addons_dir() + "/" + addon;
|
||||
|
|
|
@ -108,6 +108,15 @@ bool have_addon_install_info(const std::string& addon_name);
|
|||
*/
|
||||
void get_addon_install_info(const std::string& addon_name, class config& cfg);
|
||||
|
||||
/**
|
||||
* Writes the installation info (_info.cfg) for an add-on to disk.
|
||||
*
|
||||
* @param addon_name The add-on's main directory/file name.
|
||||
* @param cfg A config object containing the add-on's
|
||||
* properties.
|
||||
*/
|
||||
void write_addon_install_info(const std::string& addon_name, const class config& cfg);
|
||||
|
||||
/** Returns a list of local add-ons that can be published. */
|
||||
std::vector<std::string> available_addons();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue