16 #define GETTEXT_DOMAIN "wesnoth-lib" 30 #include "addon/manager.hpp" 40 #include <SDL2/SDL_image.h> 41 #include <SDL2/SDL_mixer.h> 43 #include <boost/algorithm/string.hpp> 44 #include <boost/predef.h> 45 #include <boost/version.hpp> 48 #include <openssl/crypto.h> 49 #include <openssl/opensslv.h> 52 #include <pango/pangocairo.h> 57 #include <CoreFoundation/CoreFoundation.h> 65 struct version_table_manager
70 version_table_manager();
73 const version_table_manager versions;
76 std::string format_version(
unsigned a,
unsigned b,
unsigned c)
78 return formatter() << a <<
'.' << b <<
'.' <<
c;
82 std::string format_version(
const SDL_version& v)
84 return formatter() <<
static_cast<unsigned>(v.major) <<
'.' 85 << static_cast<unsigned>(v.minor) <<
'.' 86 <<
static_cast<unsigned>(v.patch);
91 std::string format_openssl_patch_level(uint8_t
p)
94 ? std::string(1,
'a' + static_cast<char>(p) - 1)
95 :
"patch" +
std::to_string(p);
98 std::string format_openssl_version(
long v)
100 int major, minor, fix, patch, status;
101 std::ostringstream fmt;
111 minor = v & 0x0F00L >> 8;
112 fix = v & 0x00F0L >> 4;
115 fmt <<
"0." << minor <<
'.' << fix;
117 fmt << format_openssl_patch_level(patch);
126 major = (v & 0xF0000000L) >> 28;
127 minor = (v & 0x0FF00000L) >> 20;
128 fix = (v & 0x000FF000L) >> 12;
129 patch = (v & 0x00000FF0L) >> 4;
130 status = (v & 0x0000000FL);
132 if(v < 0x00905100L) {
144 const uint8_t is_final = (v & 0xF00L) >> 8;
145 status = is_final ? 0xF : 0;
147 }
else if(v < 0x00906000L) {
160 fmt << major <<
'.' << minor <<
'.' << fix;
163 fmt << format_openssl_patch_level(patch);
168 }
else if(status < 0xF) {
169 fmt <<
"-beta" << status;
179 version_table_manager::version_table_manager()
185 SDL_version sdl_version;
192 SDL_VERSION(&sdl_version);
195 SDL_GetVersion(&sdl_version);
204 SDL_IMAGE_VERSION(&sdl_version);
207 const SDL_version* sdl_rt_version = IMG_Linked_Version();
218 SDL_MIXER_VERSION(&sdl_version);
221 sdl_rt_version = Mix_Linked_Version();
240 compiled[
LIB_LUA] = LUA_VERSION_MAJOR
"." LUA_VERSION_MINOR
"." LUA_VERSION_RELEASE;
273 features.emplace_back(
N_(
"feature^Lua console completion"));
280 features.emplace_back(
N_(
"feature^D-Bus notifications back end"));
289 features.emplace_back(
N_(
"feature^Win32 notifications back end"));
295 features.emplace_back(
N_(
"feature^Cocoa notifications back end"));
300 const std::string empty_version =
"";
306 #if BOOST_ARCH_X86_64 308 #elif BOOST_ARCH_X86_32 310 #elif BOOST_ARCH_ARM && (defined(__arm64) || defined(_M_ARM64)) 314 #elif BOOST_ARCH_IA64 318 #elif BOOST_ARCH_ALPHA 320 #elif BOOST_ARCH_MIPS 322 #elif BOOST_ARCH_SPARC 333 return _(
"cpu_architecture^<unknown>");
339 std::vector<optional_feature> res = versions.features;
341 for(std::size_t k = 0; k < res.size(); ++k) {
343 res[k].name =
_(res[k].name.c_str());
347 const auto caret_pos = res[k].name.find(
'^');
348 if(caret_pos != std::string::npos) {
349 res[k].name.erase(0, caret_pos + 1);
359 return empty_version;
362 return versions.compiled[lib];
368 return empty_version;
371 return versions.linked[lib];
377 return empty_version;
380 return versions.names[lib];
387 if(infofile.is_open()) {
388 std::getline(infofile, info);
408 using list_entry = std::pair<std::string, std::string>;
409 using contents_list = std::vector<list_entry>;
411 list_formatter(
const std::string& heading,
const contents_list& contents = {},
const std::string& empty_placeholder =
"")
418 void insert(
const std::string&
label,
const std::string& value)
423 void set_placeholder(
const std::string& placeholder)
428 void stream_put(std::ostream& os)
const;
443 void list_formatter::stream_put(std::ostream& os)
const 452 auto label_length_comparator = [](
const list_entry&
a,
const list_entry&
b)
457 const auto longest_entry_label = std::max_element(
contents_.begin(),
contents_.end(), label_length_comparator);
458 const std::size_t min_length = longest_entry_label !=
contents_.end()
463 const std::size_t prev_width = os.width();
464 const std::ostream::fmtflags prev_flags = os.flags();
469 os << std::setw(min_length) << entry.first +
label_delimiter << entry.second <<
'\n';
472 os.width(prev_width);
473 os.flags(prev_flags);
479 std::ostream&
operator<<(std::ostream& os,
const list_formatter& fmt)
485 list_formatter library_versions_report_internal(
const std::string& heading =
"")
487 list_formatter fmt{heading};
491 if(versions.names[
n].empty()) {
495 std::string text = versions.compiled[
n];
496 if(!versions.linked[
n].empty()) {
497 text +=
" (runtime " + versions.linked[
n] +
")";
500 fmt.insert(versions.names[
n], text);
506 list_formatter optional_features_report_internal(
const std::string& heading =
"")
508 list_formatter fmt{heading};
512 for(
const auto& feature : features) {
513 fmt.insert(feature.name, feature.enabled ?
"yes" :
"no");
520 inline std::string geometry_to_string(T horizontal, T vertical)
522 return std::to_string(horizontal) +
'x' + std::to_string(vertical);
525 std::string format_sdl_driver_list(std::vector<std::string> drivers,
const std::string&
current_driver)
527 bool found_current_driver =
false;
529 for(
auto& drvname : drivers) {
530 if(current_driver == drvname) {
531 found_current_driver =
true;
532 drvname =
"[" + current_driver +
"]";
536 if(drivers.empty() || !found_current_driver) {
538 drivers.emplace_back(
"[" + current_driver +
"]");
544 list_formatter video_settings_report_internal(
const std::string& heading =
"")
546 list_formatter fmt{heading};
549 fmt.set_placeholder(
"Graphics not initialized.");
555 std::string placeholder;
558 placeholder =
"Running in non-interactive mode.";
560 placeholder =
"Running without a game window.";
563 if(!placeholder.empty()) {
564 fmt.set_placeholder(placeholder);
571 fmt.insert(
"SDL video drivers", format_sdl_driver_list(drivers, current_driver));
572 fmt.insert(
"Window size", geometry_to_string(
574 fmt.insert(
"Game canvas size", geometry_to_string(
576 fmt.insert(
"Final render target size", geometry_to_string(
583 list_formatter sound_settings_report_internal(
const std::string& heading =
"")
585 list_formatter fmt{heading};
589 if(!driver_status.initialized) {
590 fmt.set_placeholder(
"Audio not initialized.");
597 static std::map<uint16_t, std::string> audio_format_names = {
599 { AUDIO_U8,
"unsigned 8 bit" },
600 { AUDIO_S8,
"signed 8 bit" },
602 { AUDIO_U16LSB,
"unsigned 16 bit little-endian" },
603 { AUDIO_U16MSB,
"unsigned 16 bit big-endian" },
604 { AUDIO_S16LSB,
"signed 16 bit little-endian" },
605 { AUDIO_S16MSB,
"signed 16 bit big-endian" },
607 { AUDIO_S32LSB,
"signed 32 bit little-endian" },
608 { AUDIO_S32MSB,
"signed 32 bit big-endian" },
609 { AUDIO_F32LSB,
"signed 32 bit floating point little-endian" },
610 { AUDIO_F32MSB,
"signed 32 bit floating point big-endian" },
613 auto fmt_names_it = audio_format_names.find(driver_status.format);
615 const std::string fmt_name = fmt_names_it != audio_format_names.end()
616 ? fmt_names_it->second
617 :
formatter() <<
"0x" << std::setfill(
'0') << std::setw(2*
sizeof(driver_status.format)) << std::hex << std::uppercase << driver_status.format;
619 fmt.insert(
"SDL audio drivers", format_sdl_driver_list(drivers, current_driver));
620 fmt.insert(
"Number of channels", std::to_string(driver_status.channels));
621 fmt.insert(
"Output rate", std::to_string(driver_status.frequency) +
" Hz");
622 fmt.insert(
"Sample format", fmt_name);
623 fmt.insert(
"Sample size", std::to_string(driver_status.chunk_size) +
" bytes");
632 return formatter{} << library_versions_report_internal();
637 return formatter{} << optional_features_report_internal();
642 list_formatter::contents_list paths{
652 for(
auto& entry : paths) {
656 list_formatter::contents_list addons;
662 std::ostringstream o;
668 << list_formatter{
"Game paths", paths}
669 << library_versions_report_internal(
"Libraries")
670 << optional_features_report_internal(
"Features")
671 << video_settings_report_internal(
"Current video settings")
672 << sound_settings_report_internal(
"Current audio settings")
673 << list_formatter(
"Installed add-ons", addons,
"No add-ons installed.");
point current_resolution()
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.
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.
std::vector< optional_feature > optional_features_table(bool localize)
Retrieve the features table.
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.
std::string label
What to show in the filter's drop-down list.
std::vector< optional_feature > features
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 build_arch()
Obtain the processor architecture for this build.
std::string sanitize_path(const std::string &path)
Sanitizes a path to remove references to the user's name.
rect draw_area() const
Returns the size and location of the current drawing area in pixels.
std::ostream & operator<<(std::ostream &s, const ai::attack_result &r)
SDL_Point output_size() const
Returns the size of the final render target.
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.
std::string get_user_config_dir()
std::string get_addons_dir()
void trim(std::string_view &s)
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::map< std::string, std::string > installed_addons_and_versions()
Retrieves the ids and versions of all installed add-ons.