16 #define GETTEXT_DOMAIN "wesnoth-lib" 28 #if defined(__APPLE__) || defined(_X11) 29 #include <sys/utsname.h> 32 #if defined(__APPLE__) 38 #include <boost/algorithm/string/trim.hpp> 46 #include <boost/algorithm/string/trim.hpp> 55 #define WIN32_LEAN_AND_MEAN 62 #define ERR_DU LOG_STREAM(err, log_desktop) 63 #define LOG_DU LOG_STREAM(info, log_desktop) 80 HMODULE ntdll = GetModuleHandle(L
"ntdll.dll");
85 return GetProcAddress(ntdll,
"wine_get_version") !=
nullptr;
95 std::string windows_release_id()
98 DWORD
size =
sizeof(buf);
100 auto res = RegGetValueA(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
"DisplayVersion", RRF_RT_REG_SZ,
nullptr, buf, &size);
101 if(res != ERROR_SUCCESS) {
102 res = RegGetValueA(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
"ReleaseId", RRF_RT_REG_SZ,
nullptr, buf, &size);
105 return std::string{res == ERROR_SUCCESS ? buf :
""};
108 std::string windows_runtime_arch()
111 SecureZeroMemory(&si,
sizeof(SYSTEM_INFO));
112 GetNativeSystemInfo(&si);
114 switch(si.wProcessorArchitecture) {
115 case PROCESSOR_ARCHITECTURE_INTEL:
117 case PROCESSOR_ARCHITECTURE_AMD64:
119 case PROCESSOR_ARCHITECTURE_ARM:
121 case PROCESSOR_ARCHITECTURE_ARM64:
123 case PROCESSOR_ARCHITECTURE_IA64:
126 return _(
"cpu_architecture^<unknown>");
136 struct posix_pipe_release_policy
138 void operator()(std::FILE*
f)
const {
if(f !=
nullptr) { pclose(f); } }
147 typedef std::unique_ptr<std::FILE, posix_pipe_release_policy> scoped_posix_pipe;
154 std::string read_pipe_line(scoped_posix_pipe&
p)
166 while((c = std::fgetc(p.get())) && c != EOF && c !=
'\n' && c !=
'\r') {
167 ver.push_back(static_cast<char>(c));
173 std::map<std::string, std::string> parse_fdo_osrelease(
const std::string&
path)
180 std::map<std::string, std::string> res;
185 for(std::string
s; std::getline(*
in,
s);) {
186 if(
s.empty() ||
s.front() ==
'#') {
190 auto eqsign_pos =
s.find(
'=');
191 if(!eqsign_pos || eqsign_pos == std::string::npos) {
195 auto lhs =
s.substr(0, eqsign_pos),
196 rhs = eqsign_pos + 1 <
s.length() ?
utils::unescape(
s.substr(eqsign_pos + 1)) :
"";
202 if(rhs.length() >= 2 && rhs.front() ==
'"' && rhs.back() ==
'"') {
207 res.emplace(std::move(lhs), std::move(rhs));
219 #if defined(__APPLE__) || defined(_X11) 224 ERR_DU <<
"os_version: uname error (" << strerror(errno) <<
")\n";
228 #if defined(__APPLE__) 242 std::map<std::string, std::string> osrel;
244 static const std::string fdo_osrel_etc =
"/etc/os-release";
245 static const std::string fdo_osrel_usr =
"/usr/lib/os-release";
248 osrel = parse_fdo_osrelease(fdo_osrel_etc);
250 osrel = parse_fdo_osrelease(fdo_osrel_usr);
254 auto osrel_distname = osrel[
"PRETTY_NAME"];
255 if(osrel_distname.empty()) {
256 osrel_distname = osrel[
"NAME"];
259 if(!osrel_distname.empty()) {
260 return osrel_distname +
" " + u.machine;
267 static const std::string lsb_release_bin =
"/usr/bin/lsb_release";
270 static const std::string cmdline = lsb_release_bin +
" -s -d";
272 scoped_posix_pipe
p(popen(cmdline.c_str(),
"r"));
273 std::string ver = read_pipe_line(p);
275 if(ver.length() >= 2 && ver[0] ==
'"' && ver[ver.length() - 1] ==
'"') {
276 ver.erase(ver.length() - 1, 1);
282 return ver +
" " + u.machine;
295 #elif defined(_WIN32) 301 static const std::string base
302 = !on_wine() ?
"Microsoft Windows" :
"Wine/Microsoft Windows";
306 SecureZeroMemory(&v,
sizeof(OSVERSIONINFOEX));
307 v.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
313 #pragma warning(push) 314 #pragma warning(disable:4996) 316 if(!GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&v))) {
317 ERR_DU <<
"os_version: GetVersionEx error (" 318 << GetLastError() <<
")\n";
325 const DWORD vnum = v.dwMajorVersion * 100 + v.dwMinorVersion;
338 version =
"Server 2003";
341 if(v.wProductType == VER_NT_WORKSTATION) {
344 version =
"Server 2008";
348 if(v.wProductType == VER_NT_WORKSTATION) {
351 version =
"Server 2008 R2";
355 if(v.wProductType == VER_NT_WORKSTATION) {
358 version =
"Server 2012";
362 if(v.wProductType == VER_NT_WORKSTATION) {
365 version =
"Server 2012 R2";
369 if(v.wProductType == VER_NT_WORKSTATION) {
370 version = v.dwBuildNumber < 22000 ?
"10" :
"11";
371 const auto& release_id = windows_release_id();
372 if(!release_id.empty()) {
374 version += release_id;
380 if(v.wProductType != VER_NT_WORKSTATION) {
385 if(*v.szCSDVersion) {
387 version +=
unicode_cast<std::string>(std::wstring(v.szCSDVersion));
393 << v.dwMajorVersion <<
'.' 394 << v.dwMinorVersion <<
'.' 398 return base +
" " + version +
" " + windows_runtime_arch();
406 ERR_DU <<
"os_version(): unsupported platform\n";
407 return _(
"operating_system^<unknown>");
static bool file_exists(const bfs::path &fpath)
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
filesystem::scoped_istream istream_file(const std::string &fname, bool treat_failure_as_error)
std::string unescape(const std::string &str)
Remove all escape characters (backslash)
static std::string _(const char *str)
unsigned in
If equal to search_counter, the node is off the list.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Platform identification and version information functions.
std::string os_version()
Returns a string with the running OS name and version information.
static map_location::DIRECTION s
std::string os_version()
Returns a string with the running OS name and version information.
Declarations for File-IO.
static lg::log_domain log_desktop("desktop")
Standard logging facilities (interface).
void trim(std::string_view &s)