Skip to content

Commit

Permalink
Add installed addons and addon versions to the build report.
Browse files Browse the repository at this point in the history
This would be useful since often one of the things asked when a user reports issues is if they have any addons installed.

Backport of 177348b
  • Loading branch information
Pentarctagon committed Jun 11, 2020
1 parent 8991509 commit 4b504f2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/addon/manager.cpp
Expand Up @@ -31,6 +31,7 @@
#include "game_version.hpp"
#include "serialization/string_utils.hpp"
#include "addon/client.hpp"
#include "game_config_manager.hpp"

#include <boost/algorithm/string.hpp>

Expand Down Expand Up @@ -160,6 +161,17 @@ std::vector<std::string> installed_addons()
return res;
}

std::vector<std::pair<std::string, std::string>> installed_addons_and_versions()
{
std::vector<std::pair<std::string, std::string>> addons;

for(const std::string& addon_id : installed_addons()) {
addons.push_back(std::pair<std::string, std::string>(addon_id, game_config_manager::get()->get_addon_version(addon_id)));
}

return addons;
}

bool is_addon_installed(const std::string& addon_name)
{
const std::string namestem = filesystem::get_addons_dir() + "/" + addon_name;
Expand Down
3 changes: 3 additions & 0 deletions src/addon/manager.hpp
Expand Up @@ -114,6 +114,9 @@ std::vector<std::string> available_addons();
/** Retrieves the names of all installed add-ons. */
std::vector<std::string> installed_addons();

/** Retrieves the ids and versions of all installed add-ons. */
std::vector<std::pair<std::string, std::string>> installed_addons_and_versions();

/** Check whether the specified add-on is currently installed. */
bool is_addon_installed(const std::string& addon_name);

Expand Down
10 changes: 9 additions & 1 deletion src/build_info.cpp
Expand Up @@ -23,6 +23,7 @@
#include "gettext.hpp"
#include "serialization/unicode.hpp"
#include "video.hpp"
#include "addon/manager.hpp"

#include <algorithm>
#include <fstream>
Expand Down Expand Up @@ -486,7 +487,14 @@ std::string full_build_report()
<< '\n'
<< report_heading("Current video settings")
<< '\n'
<< CVideo::video_settings_report();
<< CVideo::video_settings_report()
<< '\n'
<< report_heading("Installed Add-ons")
<< '\n';
for(const auto& addon_info : installed_addons_and_versions())
{
o << addon_info.first << " : " << addon_info.second << '\n';
}

return o.str();
}
Expand Down
19 changes: 19 additions & 0 deletions src/game_config_manager.cpp
Expand Up @@ -495,6 +495,25 @@ void game_config_manager::load_addons_cfg()
}
}

std::string game_config_manager::get_addon_version(const std::string& addon_id)
{
const std::string info_cfg = filesystem::get_addons_dir() + "/" + addon_id + "/_info.cfg";
if(have_addon_pbl_info(addon_id)) {
// Publishing info needs to be read from disk.
try {
return get_addon_pbl_info(addon_id)["version"].str();
} catch(const invalid_pbl_exception& e) {
return "Invalid pbl file, version unknown";
}
} else if(filesystem::file_exists(info_cfg)) {
// Addon server-generated info can be fetched from cache.
config temp;
cache_.get_config(info_cfg, temp);
return temp.child("info")["version"].str();
}
return "Unknown";
}

void game_config_manager::set_multiplayer_hashes()
{
config& hashes = game_config_.add_child("multiplayer_hashes");
Expand Down
2 changes: 2 additions & 0 deletions src/game_config_manager.hpp
Expand Up @@ -48,6 +48,8 @@ class game_config_manager
void load_game_config_for_game(const game_classification& classification);
void load_game_config_for_create(bool is_mp, bool is_test = false);

std::string get_addon_version(const std::string& addon_id);

static game_config_manager * get();

private:
Expand Down

0 comments on commit 4b504f2

Please sign in to comment.