15 #define GETTEXT_DOMAIN "wesnoth-lib" 29 #include "addon/manager.hpp" 36 #include <SDL2/SDL_image.h> 37 #include <SDL2/SDL_mixer.h> 38 #include <SDL2/SDL_ttf.h> 40 #include <boost/algorithm/string.hpp> 41 #include <boost/version.hpp> 44 #include <openssl/crypto.h> 45 #include <openssl/opensslv.h> 48 #include <pango/pangocairo.h> 53 #include <CoreFoundation/CoreFoundation.h> 61 struct version_table_manager
66 version_table_manager();
69 const version_table_manager versions;
72 std::string format_version(
unsigned a,
unsigned b,
unsigned c)
74 return formatter() << a <<
'.' << b <<
'.' <<
c;
78 std::string format_version(
const SDL_version& v)
80 return formatter() <<
static_cast<unsigned>(v.major) <<
'.' 81 << static_cast<unsigned>(v.minor) <<
'.' 82 <<
static_cast<unsigned>(v.patch);
87 std::string format_openssl_patch_level(uint8_t
p)
90 ? std::string(1,
'a' + static_cast<char>(p) - 1)
91 :
"patch" +
std::to_string(p);
94 std::string format_openssl_version(
long v)
96 int major, minor, fix, patch, status;
97 std::ostringstream fmt;
107 minor = v & 0x0F00L >> 8;
108 fix = v & 0x00F0L >> 4;
111 fmt <<
"0." << minor <<
'.' << fix;
113 fmt << format_openssl_patch_level(patch);
122 major = (v & 0xF0000000L) >> 28;
123 minor = (v & 0x0FF00000L) >> 20;
124 fix = (v & 0x000FF000L) >> 12;
125 patch = (v & 0x00000FF0L) >> 4;
126 status = (v & 0x0000000FL);
128 if(v < 0x00905100L) {
140 const uint8_t is_final = (v & 0xF00L) >> 8;
141 status = is_final ? 0xF : 0;
143 }
else if(v < 0x00906000L) {
156 fmt << major <<
'.' << minor <<
'.' << fix;
159 fmt << format_openssl_patch_level(patch);
164 }
else if(status < 0xF) {
165 fmt <<
"-beta" << status;
175 version_table_manager::version_table_manager()
181 SDL_version sdl_version;
188 SDL_VERSION(&sdl_version);
191 SDL_GetVersion(&sdl_version);
200 SDL_IMAGE_VERSION(&sdl_version);
203 const SDL_version* sdl_rt_version = IMG_Linked_Version();
214 SDL_MIXER_VERSION(&sdl_version);
217 sdl_rt_version = Mix_Linked_Version();
228 SDL_TTF_VERSION(&sdl_version);
231 sdl_rt_version = TTF_Linked_Version();
276 features.emplace_back(
N_(
"feature^Lua console completion"));
281 features.emplace_back(
N_(
"feature^Legacy bidirectional rendering"));
288 features.emplace_back(
N_(
"feature^D-Bus notifications back end"));
297 features.emplace_back(
N_(
"feature^Win32 notifications back end"));
303 features.emplace_back(
N_(
"feature^Cocoa notifications back end"));
308 const std::string empty_version =
"";
314 std::vector<optional_feature> res = versions.features;
316 for(std::size_t k = 0; k < res.size(); ++k) {
317 res[k].name =
_(res[k].
name.c_str());
325 return empty_version;
328 return versions.compiled[lib];
334 return empty_version;
337 return versions.linked[lib];
343 return empty_version;
346 return versions.names[lib];
353 if(infofile.is_open()) {
354 std::getline(infofile, info);
374 using list_entry = std::pair<std::string, std::string>;
375 using contents_list = std::vector<list_entry>;
377 list_formatter(
const std::string& heading,
const contents_list& contents = {},
const std::string& empty_placeholder =
"")
384 void insert(
const std::string& label,
const std::string& value)
389 void set_placeholder(
const std::string& placeholder)
394 void stream_put(std::ostream& os)
const;
409 void list_formatter::stream_put(std::ostream& os)
const 418 auto label_length_comparator = [](
const list_entry&
a,
const list_entry&
b)
423 const auto longest_entry_label = std::max_element(
contents_.begin(),
contents_.end(), label_length_comparator);
424 const std::size_t min_length = longest_entry_label !=
contents_.end()
429 const std::size_t prev_width = os.width();
430 const std::ostream::fmtflags prev_flags = os.flags();
435 os << std::setw(min_length) << entry.first +
label_delimiter << entry.second <<
'\n';
438 os.width(prev_width);
439 os.flags(prev_flags);
445 std::ostream&
operator<<(std::ostream& os,
const list_formatter& fmt)
451 list_formatter library_versions_report_internal(
const std::string& heading =
"")
453 list_formatter fmt{heading};
457 if(versions.names[
n].empty()) {
461 std::string text = versions.compiled[
n];
462 if(!versions.linked[
n].empty()) {
463 text +=
" (runtime " + versions.linked[
n] +
")";
466 fmt.insert(versions.names[
n], text);
472 list_formatter optional_features_report_internal(
const std::string& heading =
"")
474 list_formatter fmt{heading};
480 for(
const auto& feature : features) {
481 fmt.insert(feature.name, feature.enabled ?
"yes" :
"no");
488 inline std::string geometry_to_string(T horizontal, T vertical)
490 return std::to_string(horizontal) +
'x' + std::to_string(vertical);
493 std::string format_sdl_driver_list(std::vector<std::string> drivers,
const std::string&
current_driver)
495 bool found_current_driver =
false;
497 for(
auto& drvname : drivers) {
498 if(current_driver == drvname) {
499 found_current_driver =
true;
500 drvname =
"[" + current_driver +
"]";
504 if(drivers.empty() || !found_current_driver) {
506 drivers.emplace_back(
"[" + current_driver +
"]");
512 list_formatter video_settings_report_internal(
const std::string& heading =
"")
514 list_formatter fmt{heading};
517 fmt.set_placeholder(
"Graphics not initialized.");
523 std::string placeholder;
526 placeholder =
"Running in non-interactive mode.";
528 placeholder =
"Running without a game window.";
531 if(!placeholder.empty()) {
532 fmt.set_placeholder(placeholder);
539 const auto& dpi = video.
get_dpi();
541 std::string dpi_report, scale_report;
543 if(dpi.first == 0.0f || dpi.second == 0.0f) {
544 scale_report = dpi_report =
"<unknown>";
546 dpi_report = geometry_to_string(dpi.first, dpi.second);
547 scale_report = geometry_to_string(
scale.first,
scale.second);
550 fmt.insert(
"SDL video drivers", format_sdl_driver_list(drivers, current_driver));
553 fmt.insert(
"Screen dots per inch", dpi_report);
554 fmt.insert(
"Screen dpi scale factor", scale_report);
559 list_formatter sound_settings_report_internal(
const std::string& heading =
"")
561 list_formatter fmt{heading};
565 if(!driver_status.initialized) {
566 fmt.set_placeholder(
"Audio not initialized.");
573 static std::map<uint16_t, std::string> audio_format_names = {
575 { AUDIO_U8,
"unsigned 8 bit" },
576 { AUDIO_S8,
"signed 8 bit" },
578 { AUDIO_U16LSB,
"unsigned 16 bit little-endian" },
579 { AUDIO_U16MSB,
"unsigned 16 bit big-endian" },
580 { AUDIO_S16LSB,
"signed 16 bit little-endian" },
581 { AUDIO_S16MSB,
"signed 16 bit big-endian" },
583 { AUDIO_S32LSB,
"signed 32 bit little-endian" },
584 { AUDIO_S32MSB,
"signed 32 bit big-endian" },
585 { AUDIO_F32LSB,
"signed 32 bit floating point little-endian" },
586 { AUDIO_F32MSB,
"signed 32 bit floating point big-endian" },
589 auto fmt_names_it = audio_format_names.find(driver_status.format);
591 const std::string fmt_name = fmt_names_it != audio_format_names.end()
592 ? fmt_names_it->second
593 :
formatter() <<
"0x" << std::setfill(
'0') << std::setw(2*
sizeof(driver_status.format)) << std::hex << std::uppercase << driver_status.format;
595 fmt.insert(
"SDL audio drivers", format_sdl_driver_list(drivers, current_driver));
596 fmt.insert(
"Number of channels", std::to_string(driver_status.channels));
597 fmt.insert(
"Output rate", std::to_string(driver_status.frequency) +
" Hz");
598 fmt.insert(
"Sample format", fmt_name);
599 fmt.insert(
"Sample size", std::to_string(driver_status.chunk_size) +
" bytes");
608 return formatter{} << library_versions_report_internal();
613 return formatter{} << optional_features_report_internal();
618 list_formatter::contents_list paths{
628 for(
auto& entry : paths) {
632 list_formatter::contents_list addons;
638 std::ostringstream o;
644 << list_formatter{
"Game paths", paths}
645 << library_versions_report_internal(
"Libraries")
646 << optional_features_report_internal(
"Features")
647 << video_settings_report_internal(
"Current video settings")
648 << sound_settings_report_internal(
"Current audio settings")
649 << list_formatter(
"Installed add-ons", addons,
"No add-ons installed.");
static const char heading_delimiter
std::string library_versions_report()
Produce a plain-text report of library versions suitable for stdout/stderr.
Interfaces for manipulating version numbers of engine, add-ons, etc.
std::string current_driver()
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::pair< float, float > get_dpi_scale_factor() const
The current scale factor on High-DPI screens.
static const std::string label_delimiter
std::string optional_features_report()
Produce a plain-text report of features suitable for stdout/stderr.
static CVideo & get_singleton()
bool non_interactive() const
const std::string & library_build_version(LIBRARY_ID lib)
Retrieve the build-time version number of the given library.
static std::string _(const char *str)
std::string get_saves_dir()
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
const std::string & library_name(LIBRARY_ID lib)
Retrieve the user-visible name for the given library.
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
std::vector< optional_feature > optional_features_table()
Return a localized features table.
std::vector< optional_feature > features
void trim(string_view &s)
std::string get_user_data_dir()
static std::vector< std::string > enumerate_drivers()
std::string dist_channel_id()
Return the distribution channel identifier, or "Default" if missing.
std::string sanitize_path(const std::string &path)
Sanitizes a path to remove references to the user's name.
int get_width(bool as_pixels=true) const
Returns the window renderer width in pixels or screen coordinates.
std::ostream & operator<<(std::ostream &s, const ai::attack_result &r)
Platform identification and version information functions.
std::string get_cache_dir()
int current_refresh_rate() const
std::vector< std::string > linked
const std::string revision
Game configuration data as global variables.
std::string os_version()
Returns a string with the running OS name and version information.
std::vector< std::string > names
const std::string & library_runtime_version(LIBRARY_ID lib)
Retrieve the runtime version number of the given library.
static std::string current_driver()
std::string & insert(std::string &str, const std::size_t pos, const std::string &insert)
Insert a UTF-8 string at the specified position.
Declarations for File-IO.
int get_height(bool as_pixels=true) const
Returns the window renderer height in pixels or in screen coordinates.
std::string get_user_config_dir()
std::string get_addons_dir()
static driver_status query()
std::vector< std::string > enumerate_drivers()
static map_location::DIRECTION n
std::vector< std::string > compiled
static bool setup_completed()
std::string full_build_report()
Produce a bug report-style info dump.
std::pair< float, float > get_dpi() const
The current game screen dpi.
std::map< std::string, std::string > installed_addons_and_versions()
Retrieves the ids and versions of all installed add-ons.