From 51c026dc91c23f1a8765a55f991b73d737e70925 Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Mon, 13 Jul 2015 20:52:38 -0300 Subject: [PATCH] desktop: Add function to obtain OS version string Highly unreliable and generally useless, see the Doxygen documentation. Also missing the actual Windows implementation for the moment. Also, since uname() is highly useless on most platforms, I'll need to think up a better OS X implementation later down the road. --- projectfiles/CodeBlocks/wesnoth.cbp | 2 + src/CMakeLists.txt | 1 + src/SConscript | 1 + src/desktop/version.cpp | 79 +++++++++++++++++++++++++++++ src/desktop/version.hpp | 42 +++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 src/desktop/version.cpp create mode 100644 src/desktop/version.hpp diff --git a/projectfiles/CodeBlocks/wesnoth.cbp b/projectfiles/CodeBlocks/wesnoth.cbp index e04cd2d7607..02790bca21c 100644 --- a/projectfiles/CodeBlocks/wesnoth.cbp +++ b/projectfiles/CodeBlocks/wesnoth.cbp @@ -249,6 +249,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 74b34a550ec..5919df92d6b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -775,6 +775,7 @@ set(wesnoth-main_SRC game_initialization/depcheck.cpp desktop/notifications.cpp desktop/open.cpp + desktop/version.cpp dialogs.cpp display_chat_manager.cpp editor/action/action.cpp diff --git a/src/SConscript b/src/SConscript index a624a0e2f95..b40a695f8fa 100644 --- a/src/SConscript +++ b/src/SConscript @@ -261,6 +261,7 @@ wesnoth_sources = Split(""" game_initialization/create_engine.cpp desktop/notifications.cpp desktop/open.cpp + desktop/version.cpp game_initialization/depcheck.cpp dialogs.cpp display_chat_manager.cpp diff --git a/src/desktop/version.cpp b/src/desktop/version.cpp new file mode 100644 index 00000000000..b6d80558d5a --- /dev/null +++ b/src/desktop/version.cpp @@ -0,0 +1,79 @@ +/* + Copyright (C) 2015 by Ignacio Riquelme Morelle + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +#define GETTEXT_DOMAIN "wesnoth-lib" + +#include "desktop/version.hpp" + +#include "formatter.hpp" +#include "gettext.hpp" +#include "log.hpp" + +#if defined(_X11) || defined(__APPLE__) + +#include +#include + +#include + +#endif + +#ifdef _WIN32 + +#ifndef UNICODE +#define UNICODE +#endif +#define WIN32_LEAN_AND_MEAN + +#include + +#endif + +static lg::log_domain log_desktop("desktop"); +#define ERR_DU LOG_STREAM(err, log_desktop) +#define LOG_DU LOG_STREAM(info, log_desktop) + +namespace desktop +{ + +std::string os_version() +{ +#if defined(_X11) || defined(__APPLE__) + + utsname u; + + if(uname(&u) != 0) { + ERR_DU << "os_version: uname error (" << strerror(errno) << ")\n"; + } + + return (formatter() << u.sysname << ' ' + << u.release << ' ' + << u.version << ' ' + << u.machine).str(); + +#elif defined(_WIN32) + + ERR_DU << "os_version: STUB!\n"; + return "Microsoft Windows"; + +#else + + ERR_DU << "os_version(): unsupported platform\n"; + return _("operating_system^"); + +#endif +} + +} // end namespace desktop + diff --git a/src/desktop/version.hpp b/src/desktop/version.hpp new file mode 100644 index 00000000000..10cc7e1bade --- /dev/null +++ b/src/desktop/version.hpp @@ -0,0 +1,42 @@ +/* + Copyright (C) 2015 by Ignacio Riquelme Morelle + Part of the Battle for Wesnoth Project http://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. +*/ + +/** + * @file + * Platform identification and version information functions. + */ + +#ifndef DESKTOP_VERSION_HPP_INCLUDED +#define DESKTOP_VERSION_HPP_INCLUDED + +#include + +namespace desktop +{ + +/** + * Returns a string with the running OS name and version information. + * + * On Unix-type platforms, this will be the uname information (which is rarely + * useful). On Windows, this is a string we generate ourselves by processing + * GetVersionEx's output data. + * + * Needless to say, this is a highly experimental and unreliable function and + * odds are its output is not particularly useful most of the time. + */ +std::string os_version(); + +} + +#endif