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