16 #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>
45 #if defined(__APPLE__)
46 #include <TargetConditionals.h>
50 #include <openssl/crypto.h>
51 #include <openssl/opensslv.h>
54 #if !(defined(__APPLE__) && TARGET_OS_IPHONE)
55 #include <curl/curl.h>
58 #include <pango/pangocairo.h>
63 #include <CoreFoundation/CoreFoundation.h>
71 struct version_table_manager
76 version_table_manager();
79 const version_table_manager versions;
81 std::string format_version(
unsigned a,
unsigned b,
unsigned c)
86 std::string format_version(
const SDL_version& v)
88 return formatter() <<
static_cast<unsigned>(v.major) <<
'.'
89 <<
static_cast<unsigned>(v.minor) <<
'.'
90 <<
static_cast<unsigned>(v.patch);
95 std::string format_openssl_patch_level(uint8_t
p)
98 ? std::string(1,
'a' +
static_cast<char>(
p) - 1)
99 :
"patch" + std::to_string(
p);
102 std::string format_openssl_version(
long v)
104 int major, minor, fix, patch, status;
105 std::ostringstream fmt;
115 minor = v & 0x0F00L >> 8;
116 fix = v & 0x00F0L >> 4;
119 fmt <<
"0." << minor <<
'.' << fix;
121 fmt << format_openssl_patch_level(patch);
130 major = (v & 0xF0000000L) >> 28;
131 minor = (v & 0x0FF00000L) >> 20;
132 fix = (v & 0x000FF000L) >> 12;
133 patch = (v & 0x00000FF0L) >> 4;
134 status = (v & 0x0000000FL);
136 if(v < 0x00905100L) {
148 const uint8_t is_final = (v & 0xF00L) >> 8;
149 status = is_final ? 0xF : 0;
151 }
else if(v < 0x00906000L) {
164 fmt << major <<
'.' << minor <<
'.' << fix;
167 fmt << format_openssl_patch_level(patch);
172 }
else if(status < 0xF) {
173 fmt <<
"-beta" << status;
182 version_table_manager::version_table_manager()
188 SDL_version sdl_version;
194 SDL_VERSION(&sdl_version);
197 SDL_GetVersion(&sdl_version);
206 SDL_IMAGE_VERSION(&sdl_version);
209 const SDL_version* sdl_rt_version = IMG_Linked_Version();
220 SDL_MIXER_VERSION(&sdl_version);
223 sdl_rt_version = Mix_Linked_Version();
242 compiled[
LIB_LUA] = LUA_VERSION_MAJOR
"." LUA_VERSION_MINOR
"." LUA_VERSION_RELEASE;
259 #if defined(__APPLE__) && TARGET_OS_IPHONE
265 (LIBCURL_VERSION_NUM & 0xFF0000) >> 16,
266 (LIBCURL_VERSION_NUM & 0x00FF00) >> 8,
267 LIBCURL_VERSION_NUM & 0x0000FF);
268 curl_version_info_data *curl_ver = curl_version_info(CURLVERSION_NOW);
269 if(curl_ver && curl_ver->version) {
297 features.emplace_back(
N_(
"feature^Lua console completion"));
304 features.emplace_back(
N_(
"feature^D-Bus notifications back end"));
313 features.emplace_back(
N_(
"feature^Win32 notifications back end"));
319 features.emplace_back(
N_(
"feature^Cocoa notifications back end"));
324 const std::string empty_version =
"";
330 #if BOOST_ARCH_X86_64
332 #elif BOOST_ARCH_X86_32
334 #elif BOOST_ARCH_ARM && (defined(__arm64) || defined(_M_ARM64))
338 #elif BOOST_ARCH_IA64
342 #elif BOOST_ARCH_ALPHA
344 #elif BOOST_ARCH_MIPS
346 #elif BOOST_ARCH_SPARC
349 #warning Unrecognized platform or Boost.Predef broken/unavailable
358 return _(
"cpu_architecture^<unknown>");
364 std::vector<optional_feature> res = versions.features;
366 for(std::size_t k = 0; k < res.size(); ++k) {
368 res[k].name =
_(res[k].name.c_str());
372 const auto caret_pos = res[k].name.find(
'^');
373 if(caret_pos != std::string::npos) {
374 res[k].name.erase(0, caret_pos + 1);
384 return empty_version;
387 return versions.compiled[lib];
393 return empty_version;
396 return versions.linked[lib];
402 return empty_version;
405 return versions.names[lib];
412 if(infofile.is_open()) {
413 std::getline(infofile,
info);
433 using list_entry = std::pair<std::string, std::string>;
434 using contents_list = std::vector<list_entry>;
436 list_formatter(
const std::string& heading,
const contents_list& contents = {},
const std::string& empty_placeholder =
"")
443 void insert(
const std::string&
label,
const std::string& value)
448 void set_placeholder(
const std::string& placeholder)
453 void stream_put(std::ostream& os)
const;
468 void list_formatter::stream_put(std::ostream& os)
const
477 auto label_length_comparator = [](
const list_entry& a,
const list_entry&
b)
482 const auto longest_entry_label = std::max_element(
contents_.begin(),
contents_.end(), label_length_comparator);
483 const std::size_t min_length = longest_entry_label !=
contents_.end()
488 const std::size_t prev_width = os.width();
489 const std::ostream::fmtflags prev_flags = os.flags();
494 os << std::setw(min_length) << entry.first +
label_delimiter << entry.second <<
'\n';
497 os.width(prev_width);
498 os.flags(prev_flags);
504 std::ostream&
operator<<(std::ostream& os,
const list_formatter& fmt)
510 list_formatter library_versions_report_internal(
const std::string& heading =
"")
512 list_formatter fmt{heading};
516 if(versions.names[
n].empty()) {
520 std::string text = versions.compiled[
n];
521 if(!versions.linked[
n].empty()) {
522 text +=
" (runtime " + versions.linked[
n] +
")";
525 fmt.insert(versions.names[
n], text);
531 list_formatter optional_features_report_internal(
const std::string& heading =
"")
533 list_formatter fmt{heading};
537 for(
const auto& feature :
features) {
538 fmt.insert(feature.name, feature.enabled ?
"yes" :
"no");
544 inline std::string geometry_to_string(
point p)
546 return std::to_string(
p.x) +
'x' + std::to_string(
p.y);
549 template<
typename coordinateType>
550 inline std::string geometry_to_string(coordinateType horizontal, coordinateType vertical)
553 return formatter() << std::fixed << std::setprecision(2) << horizontal <<
'x' << vertical;
556 std::string format_sdl_driver_list(std::vector<std::string> drivers,
const std::string&
current_driver)
558 bool found_current_driver =
false;
560 for(
auto& drvname : drivers) {
562 found_current_driver =
true;
567 if(drivers.empty() || !found_current_driver) {
575 list_formatter video_settings_report_internal(
const std::string& heading =
"")
577 list_formatter fmt{heading};
579 std::string placeholder;
582 placeholder =
"Running in non-interactive mode.";
586 placeholder =
"Video not initialized yet.";
589 if(!placeholder.empty()) {
590 fmt.set_placeholder(placeholder);
598 std::string dpi_report;
600 dpi_report = dpi.first == 0.0f || dpi.second == 0.0f ?
602 geometry_to_string(dpi.first, dpi.second);
604 fmt.insert(
"SDL video drivers", format_sdl_driver_list(drivers,
current_driver));
610 fmt.insert(
"Screen dpi", dpi_report);
615 fmt.insert(
info.first,
info.second);
621 list_formatter sound_settings_report_internal(
const std::string& heading =
"")
623 list_formatter fmt{heading};
627 if(!driver_status.initialized) {
628 fmt.set_placeholder(
"Audio not initialized.");
635 static std::map<uint16_t, std::string> audio_format_names = {
637 { AUDIO_U8,
"unsigned 8 bit" },
638 { AUDIO_S8,
"signed 8 bit" },
640 { AUDIO_U16LSB,
"unsigned 16 bit little-endian" },
641 { AUDIO_U16MSB,
"unsigned 16 bit big-endian" },
642 { AUDIO_S16LSB,
"signed 16 bit little-endian" },
643 { AUDIO_S16MSB,
"signed 16 bit big-endian" },
645 { AUDIO_S32LSB,
"signed 32 bit little-endian" },
646 { AUDIO_S32MSB,
"signed 32 bit big-endian" },
647 { AUDIO_F32LSB,
"signed 32 bit floating point little-endian" },
648 { AUDIO_F32MSB,
"signed 32 bit floating point big-endian" },
651 auto fmt_names_it = audio_format_names.find(driver_status.format);
653 const std::string fmt_name = fmt_names_it != audio_format_names.end()
654 ? fmt_names_it->second
655 :
formatter() <<
"0x" << std::setfill(
'0') << std::setw(2*
sizeof(driver_status.format)) << std::hex << std::uppercase << driver_status.format;
657 fmt.insert(
"SDL audio drivers", format_sdl_driver_list(drivers,
current_driver));
658 fmt.insert(
"Number of channels", std::to_string(driver_status.channels));
659 fmt.insert(
"Output rate", std::to_string(driver_status.frequency) +
" Hz");
660 fmt.insert(
"Sample format", fmt_name);
661 fmt.insert(
"Sample size", std::to_string(driver_status.chunk_size) +
" bytes");
670 return formatter{} << library_versions_report_internal();
675 return formatter{} << optional_features_report_internal();
680 list_formatter::contents_list paths{
690 for(
auto& entry : paths) {
694 list_formatter::contents_list addons;
700 std::ostringstream o;
706 << list_formatter{
"Game paths", paths}
707 << library_versions_report_internal(
"Libraries")
708 << optional_features_report_internal(
"Features")
709 << video_settings_report_internal(
"Current video settings")
710 << sound_settings_report_internal(
"Current audio settings")
711 << list_formatter(
"Installed add-ons", addons,
"No add-ons installed.");
std::ostream & operator<<(std::ostream &s, const ai::attack_result &r)
std::map< std::string, std::string > installed_addons_and_versions()
Retrieves the ids and versions of all installed add-ons.
static const char heading_delimiter
std::vector< optional_feature > features
std::vector< std::string > compiled
std::vector< std::string > linked
std::vector< std::string > names
static const std::string label_delimiter
Platform identification and version information functions.
Declarations for File-IO.
Interfaces for manipulating version numbers of engine, add-ons, etc.
static std::string _(const char *str)
std::string label
What to show in the filter's drop-down list.
T end(const std::pair< T, T > &p)
T begin(const std::pair< T, T > &p)
std::string os_version()
Returns a string with the running OS name and version information.
std::string get_cache_dir()
std::string get_user_data_dir()
std::string get_saves_dir()
std::string get_logs_dir()
std::string get_addons_dir()
std::string sanitize_path(const std::string &path)
Sanitizes a path to remove references to the user's name.
Game configuration data as global variables.
const std::string & library_name(LIBRARY_ID lib)
Retrieve the user-visible name for the given library.
std::string full_build_report()
Produce a bug report-style info dump.
std::string library_versions_report()
Produce a plain-text report of library versions suitable for stdout/stderr.
std::vector< optional_feature > optional_features_table(bool localize)
Retrieve the features table.
const std::string & library_runtime_version(LIBRARY_ID lib)
Retrieve the runtime version number of the given library.
const std::string & library_build_version(LIBRARY_ID lib)
Retrieve the build-time version number of the given library.
std::string build_arch()
Obtain the processor architecture for this build.
std::string optional_features_report()
Produce a plain-text report of features suitable for stdout/stderr.
const std::string revision
std::string dist_channel_id()
Return the distribution channel identifier, or "Default" if missing.
std::vector< std::string > enumerate_drivers()
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.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
void trim(std::string_view &s)
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
bool headless()
The game is running headless.
std::vector< std::pair< std::string, std::string > > renderer_report()
Provides diagnostic information about the current renderer for the build_info API.
point output_size()
Returns the size of the final render target.
point game_canvas_size()
The size of the game canvas, in drawing coordinates / game pixels.
bool has_window()
Whether the game has set up a window to render into.
std::vector< std::string > enumerate_drivers()
A list of available video drivers.
std::pair< float, float > get_dpi()
Retrieves the current game screen DPI for the build_info API.
point current_resolution()
The current window size in desktop coordinates.
int native_refresh_rate()
The native refresh rate of display, not taking any user preferences into account.
int current_refresh_rate()
The refresh rate of the screen.
std::string current_driver()
The current video driver in use, or else "<not initialized>".
static driver_status query()
static map_location::direction n