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.
This commit is contained in:
Ignacio R. Morelle 2015-07-13 20:52:38 -03:00
parent 941e983d61
commit 51c026dc91
5 changed files with 125 additions and 0 deletions

View File

@ -249,6 +249,8 @@
<Unit filename="../../src/desktop/notifications.hpp" />
<Unit filename="../../src/desktop/open.cpp" />
<Unit filename="../../src/desktop/open.hpp" />
<Unit filename="../../src/desktop/version.cpp" />
<Unit filename="../../src/desktop/version.hpp" />
<Unit filename="../../src/desktop/windows_console.cpp" />
<Unit filename="../../src/desktop/windows_console.hpp" />
<Unit filename="../../src/desktop/windows_tray_notification.cpp" />

View File

@ -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

View File

@ -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

79
src/desktop/version.cpp Normal file
View File

@ -0,0 +1,79 @@
/*
Copyright (C) 2015 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
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 <cerrno>
#include <cstring>
#include <sys/utsname.h>
#endif
#ifdef _WIN32
#ifndef UNICODE
#define UNICODE
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#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^<unknown>");
#endif
}
} // end namespace desktop

42
src/desktop/version.hpp Normal file
View File

@ -0,0 +1,42 @@
/*
Copyright (C) 2015 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
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 <string>
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