From 1c7d6895bdc00bbdcd77b963cc21db684ed1f540 Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Tue, 28 Apr 2015 12:34:33 +0200 Subject: [PATCH] Add Windows version string to --version fixes #8888 --- lib/base/application.cpp | 119 ++++++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 44 deletions(-) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 2aee26ee9..81c8efaa8 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -42,6 +42,9 @@ #ifdef __linux__ #include #endif /* __linux__ */ +#ifdef _WIN32 +#include +#endif /*_WIN32*/ using namespace icinga; @@ -488,54 +491,77 @@ static String UnameHelper(char type) int ReleaseHelper(std::string &result) { - /* You are useing *some* distribution */ - FILE *fp = popen("lsb_release -s -d 2>&1", "r"); - std::ostringstream msgbuf; - - if (fp != NULL) { - char line[1024]; - while (fgets(line, sizeof(line), fp) != NULL) - msgbuf << line; - int status = pclose(fp); - if (WEXITSTATUS(status) == 0) { - result = msgbuf.str(); + /* You are useing *some* distribution */ + FILE *fp = popen("lsb_release -s -d 2>&1", "r"); + std::ostringstream msgbuf; + + if (fp != NULL) { + char line[1024]; + while (fgets(line, sizeof(line), fp) != NULL) + msgbuf << line; + int status = pclose(fp); + if (WEXITSTATUS(status) == 0) { + result = msgbuf.str(); boost::trim(result); - return result.length(); - } - } - - /* You have systemd or Ubuntu etc. */ - std::ifstream release("/etc/os-release"); - std::string release_line; - if (release.is_open()) { - while (getline(release, release_line)) { - if (release_line.find("PRETTY_NAME") != std::string::npos) { - result = release_line.substr(13, release_line.length() - 14); - return result.length(); - } - } - } - - /* Centos < 7 */ - release.close(); - release.open("/etc/redhat-release"); - if (release.is_open()) { - getline(release, release_line); + return result.length(); + } + } + + /* You have systemd or Ubuntu etc. */ + std::ifstream release("/etc/os-release"); + std::string release_line; + if (release.is_open()) { + while (getline(release, release_line)) { + if (release_line.find("PRETTY_NAME") != std::string::npos) { + result = release_line.substr(13, release_line.length() - 14); + return result.length(); + } + } + } + + /* Centos < 7 */ + release.close(); + release.open("/etc/redhat-release"); + if (release.is_open()) { + getline(release, release_line); result = release_line; - return result.length(); - } + return result.length(); + } - /* sles 11 sp3, opensuse w/e */ - release.close(); - release.open("etc/SuSE-release"); - if (release.is_open()) { - getline(release, release_line); - result = release_line; - return result.length(); - } + /* sles 11 sp3, opensuse w/e */ + release.close(); + release.open("etc/SuSE-release"); + if (release.is_open()) { + getline(release, release_line); + result = release_line; + return result.length(); + } - /* Just give up */ - return 0; + /* Just give up */ + return 0; +} + +#else +static String WindowsVersionHelper() +{ + //Minimum required Version, the installer/user is in the responsibility to take care of that + String winver = "Windows Vista"; + if (IsWindowsVistaSP1OrGreater()) + winver = "Windows Vista SP1"; + if (IsWindowsVistaSP2OrGreater()) + winver = "Windows Vista SP2"; + if (IsWindows7OrGreater()) + winver = "Windows 7"; + if (IsWindows7SP1OrGreater()) + winver = "Windows 7 SP1"; + if (IsWindows8OrGreater()) + winver = "Windows 8"; + if (IsWindows8Point1OrGreater()) + winver = "Windows 8.1 or greater"; + if (IsWindowsServer()) + winver += " (Server)"; + + return winver; } #endif /* _WIN32 */ @@ -567,6 +593,11 @@ void Application::DisplayInfoMessage(std::ostream& os, bool skipVersion) << " Operating system: " << UnameHelper('s') << "\n" << " Operating system version: " << UnameHelper('r') << "\n" << " Architecture: " << UnameHelper('m') << "\n"; +#else + os << "\n" + << "System information:\n" + << " Operating system: Windows\n" + << " Operating system version: " << WindowsVersionHelper() << "\n"; #endif /* _WIN32 */ #ifdef __linux__ -- 2.40.0