15 #define GETTEXT_DOMAIN "wesnoth-lib" 29 #include "addon/manager.hpp" 38 #include <SDL2/SDL_image.h> 39 #include <SDL2/SDL_mixer.h> 41 #include <boost/algorithm/string.hpp> 42 #include <boost/predef.h> 43 #include <boost/version.hpp> 46 #include <openssl/crypto.h> 47 #include <openssl/opensslv.h> 50 #include <pango/pangocairo.h> 55 #include <CoreFoundation/CoreFoundation.h> 63 struct version_table_manager
68 version_table_manager();
71 const version_table_manager versions;
74 std::string format_version(
unsigned a,
unsigned b,
unsigned c)
76 return formatter() << a <<
'.' << b <<
'.' <<
c;
80 std::string format_version(
const SDL_version& v)
82 return formatter() <<
static_cast<unsigned>(v.major) <<
'.' 83 << static_cast<unsigned>(v.minor) <<
'.' 84 <<
static_cast<unsigned>(v.patch);
89 std::string format_openssl_patch_level(uint8_t
p)
92 ? std::string(1,
'a' + static_cast<char>(p) - 1)
93 :
"patch" +
std::to_string(p);
96 std::string format_openssl_version(
long v)
98 int major, minor, fix, patch, status;
99 std::ostringstream fmt;
109 minor = v & 0x0F00L >> 8;
110 fix = v & 0x00F0L >> 4;
113 fmt <<
"0." << minor <<
'.' << fix;
115 fmt << format_openssl_patch_level(patch);
124 major = (v & 0xF0000000L) >> 28;
125 minor = (v & 0x0FF00000L) >> 20;
126 fix = (v & 0x000FF000L) >> 12;
127 patch = (v & 0x00000FF0L) >> 4;
128 status = (v & 0x0000000FL);
130 if(v < 0x00905100L) {
142 const uint8_t is_final = (v & 0xF00L) >> 8;
143 status = is_final ? 0xF : 0;
145 }
else if(v < 0x00906000L) {
158 fmt << major <<
'.' << minor <<
'.' << fix;
161 fmt << format_openssl_patch_level(patch);
166 }
else if(status < 0xF) {
167 fmt <<
"-beta" << status;
177 version_table_manager::version_table_manager()
183 SDL_version sdl_version;
190 SDL_VERSION(&sdl_version);
193 SDL_GetVersion(&sdl_version);
202 SDL_IMAGE_VERSION(&sdl_version);
205 const SDL_version* sdl_rt_version = IMG_Linked_Version();
216 SDL_MIXER_VERSION(&sdl_version);
219 sdl_rt_version = Mix_Linked_Version();
271 features.emplace_back(
N_(
"feature^Lua console completion"));
278 features.emplace_back(
N_(
"feature^D-Bus notifications back end"));
287 features.emplace_back(
N_(
"feature^Win32 notifications back end"));
293 features.emplace_back(
N_(
"feature^Cocoa notifications back end"));
298 const std::string empty_version =
"";
304 #if BOOST_ARCH_X86_64 306 #elif BOOST_ARCH_X86_32 308 #elif BOOST_ARCH_ARM && (defined(__arm64) || defined(_M_ARM64)) 312 #elif BOOST_ARCH_IA64 316 #elif BOOST_ARCH_ALPHA 318 #elif BOOST_ARCH_MIPS 320 #elif BOOST_ARCH_SPARC 331 return _(
"cpu_architecture^<unknown>");
337 std::vector<optional_feature> res = versions.features;
339 for(std::size_t k = 0; k < res.size(); ++k) {
341 res[k].name =
_(res[k].name.c_str());
345 const auto caret_pos = res[k].name.find(
'^');
346 if(caret_pos != std::string::npos) {
347 res[k].name.erase(0, caret_pos + 1);
357 return empty_version;
360 return versions.compiled[lib];
366 return empty_version;
369 return versions.linked[lib];
375 return empty_version;
378 return versions.names[lib];
385 if(infofile.is_open()) {
386 std::getline(infofile, info);
406 using list_entry = std::pair<std::string, std::string>;
407 using contents_list = std::vector<list_entry>;
409 list_formatter(
const std::string& heading,
const contents_list& contents = {},
const std::string& empty_placeholder =
"")
416 void insert(
const std::string& label,
const std::string& value)
421 void set_placeholder(
const std::string& placeholder)
426 void stream_put(std::ostream& os)
const;
441 void list_formatter::stream_put(std::ostream& os)
const 450 auto label_length_comparator = [](
const list_entry&
a,
const list_entry&
b)
455 const auto longest_entry_label = std::max_element(
contents_.begin(),
contents_.end(), label_length_comparator);
456 const std::size_t min_length = longest_entry_label !=
contents_.end()
461 const std::size_t prev_width = os.width();
462 const std::ostream::fmtflags prev_flags = os.flags();
467 os << std::setw(min_length) << entry.first +
label_delimiter << entry.second <<
'\n';
470 os.width(prev_width);
471 os.flags(prev_flags);
477 std::ostream&
operator<<(std::ostream& os,
const list_formatter& fmt)
483 list_formatter library_versions_report_internal(
const std::string& heading =
"")
485 list_formatter fmt{heading};
489 if(versions.names[
n].empty()) {
493 std::string text = versions.compiled[
n];
494 if(!versions.linked[
n].empty()) {
495 text +=
" (runtime " + versions.linked[
n] +
")";
498 fmt.insert(versions.names[
n], text);
504 list_formatter optional_features_report_internal(
const std::string& heading =
"")
506 list_formatter fmt{heading};
510 for(
const auto& feature : features) {
511 fmt.insert(feature.name, feature.enabled ?
"yes" :
"no");
518 inline std::string geometry_to_string(T horizontal, T vertical)
520 return std::to_string(horizontal) +
'x' + std::to_string(vertical);
523 std::string format_sdl_driver_list(std::vector<std::string> drivers,
const std::string&
current_driver)
525 bool found_current_driver =
false;
527 for(
auto& drvname : drivers) {
528 if(current_driver == drvname) {
529 found_current_driver =
true;
530 drvname =
"[" + current_driver +
"]";
534 if(drivers.empty() || !found_current_driver) {
536 drivers.emplace_back(
"[" + current_driver +
"]");
542 list_formatter video_settings_report_internal(
const std::string& heading =
"")
544 list_formatter fmt{heading};
547 fmt.set_placeholder(
"Graphics not initialized.");
553 std::string placeholder;
556 placeholder =
"Running in non-interactive mode.";
558 placeholder =
"Running without a game window.";
561 if(!placeholder.empty()) {
562 fmt.set_placeholder(placeholder);
569 const auto& dpi = video.
get_dpi();
571 std::string dpi_report, scale_report;
573 if(dpi.first == 0.0f || dpi.second == 0.0f) {
574 scale_report = dpi_report =
"<unknown>";
576 dpi_report = geometry_to_string(dpi.first, dpi.second);
577 scale_report = geometry_to_string(
scale.first,
scale.second);
580 fmt.insert(
"SDL video drivers", format_sdl_driver_list(drivers, current_driver));
583 fmt.insert(
"Screen dots per inch", dpi_report);
584 fmt.insert(
"Screen dpi scale factor", scale_report);
589 list_formatter sound_settings_report_internal(
const std::string& heading =
"")
591 list_formatter fmt{heading};
595 if(!driver_status.initialized) {
596 fmt.set_placeholder(
"Audio not initialized.");
603 static std::map<uint16_t, std::string> audio_format_names = {
605 { AUDIO_U8,
"unsigned 8 bit" },
606 { AUDIO_S8,
"signed 8 bit" },
608 { AUDIO_U16LSB,
"unsigned 16 bit little-endian" },
609 { AUDIO_U16MSB,
"unsigned 16 bit big-endian" },
610 { AUDIO_S16LSB,
"signed 16 bit little-endian" },
611 { AUDIO_S16MSB,
"signed 16 bit big-endian" },
613 { AUDIO_S32LSB,
"signed 32 bit little-endian" },
614 { AUDIO_S32MSB,
"signed 32 bit big-endian" },
615 { AUDIO_F32LSB,
"signed 32 bit floating point little-endian" },
616 { AUDIO_F32MSB,
"signed 32 bit floating point big-endian" },
619 auto fmt_names_it = audio_format_names.find(driver_status.format);
621 const std::string fmt_name = fmt_names_it != audio_format_names.end()
622 ? fmt_names_it->second
623 :
formatter() <<
"0x" << std::setfill(
'0') << std::setw(2*
sizeof(driver_status.format)) << std::hex << std::uppercase << driver_status.format;
625 fmt.insert(
"SDL audio drivers", format_sdl_driver_list(drivers, current_driver));
626 fmt.insert(
"Number of channels", std::to_string(driver_status.channels));
627 fmt.insert(
"Output rate", std::to_string(driver_status.frequency) +
" Hz");
628 fmt.insert(
"Sample format", fmt_name);
629 fmt.insert(
"Sample size", std::to_string(driver_status.chunk_size) +
" bytes");
638 return formatter{} << library_versions_report_internal();
643 return formatter{} << optional_features_report_internal();
648 list_formatter::contents_list paths{
658 for(
auto& entry : paths) {
662 list_formatter::contents_list addons;
668 std::ostringstream o;
674 << list_formatter{
"Game paths", paths}
675 << library_versions_report_internal(
"Libraries")
676 << optional_features_report_internal(
"Features")
677 << video_settings_report_internal(
"Current video settings")
678 << sound_settings_report_internal(
"Current audio settings")
679 << 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.
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.
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 > 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.
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)
#define LUA_VERSION_MINOR
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.
#define LUA_VERSION_RELEASE
std::string os_version()
Returns a string with the running OS name and version information.
#define LUA_VERSION_MAJOR
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()
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::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.