summaryrefslogtreecommitdiff
path: root/src/porting.cpp
diff options
context:
space:
mode:
authorSfan5 <sfan5@live.de>2014-01-19 14:32:03 +0100
committerSfan5 <sfan5@live.de>2014-01-23 22:27:13 +0100
commitcd7e8372f3c83531afe5d5c2460ecb95540f9d0d (patch)
tree394e065a8c1ac8408e735180ffd9ef9bc5675722 /src/porting.cpp
parent1b5b6fe6929404ae416ac33c31df7d795d444614 (diff)
downloadminetest-cd7e8372f3c83531afe5d5c2460ecb95540f9d0d.tar.gz
minetest-cd7e8372f3c83531afe5d5c2460ecb95540f9d0d.tar.bz2
minetest-cd7e8372f3c83531afe5d5c2460ecb95540f9d0d.zip
Include system info in the HTTP user agent on Windows
Diffstat (limited to 'src/porting.cpp')
-rw-r--r--src/porting.cpp53
1 files changed, 44 insertions, 9 deletions
diff --git a/src/porting.cpp b/src/porting.cpp
index a080a44e5..b0a1843eb 100644
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -23,15 +23,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
See comments in porting.h
*/
-#if defined(linux)
- #include <unistd.h>
-#elif defined(__APPLE__)
- #include <unistd.h>
+#if defined(__APPLE__)
#include <mach-o/dyld.h>
+ #include "CoreFoundation/CoreFoundation.h"
#elif defined(__FreeBSD__)
- #include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
+#elif defined(_WIN32)
+ #include <algorithm>
+#endif
+#if !defined(_WIN32)
+ #include <unistd.h>
+ #include <sys/utsname.h>
#endif
#include "porting.h"
@@ -42,10 +45,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/string.h"
#include <list>
-#ifdef __APPLE__
- #include "CoreFoundation/CoreFoundation.h"
-#endif
-
namespace porting
{
@@ -284,6 +283,42 @@ bool detectMSVCBuildDir(char *c_path)
return (removeStringEnd(path, ends) != "");
}
+std::string get_sysinfo()
+{
+#ifdef _WIN32
+ OSVERSIONINFO osvi;
+ std::ostringstream oss;
+ std::string tmp;
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&osvi);
+ tmp = osvi.szCSDVersion;
+ std::replace(tmp.begin(), tmp.end(), ' ', '_');
+
+ oss << "Windows/" << osvi.dwMajorVersion << "."
+ << osvi.dwMinorVersion;
+ if(osvi.szCSDVersion[0])
+ oss << "-" << tmp;
+ oss << " ";
+ #ifdef _WIN64
+ oss << "x86_64";
+ #else
+ BOOL is64 = FALSE;
+ if(IsWow64Process(GetCurrentProcess(), &is64) && is64)
+ oss << "x86_64"; // 32-bit app on 64-bit OS
+ else
+ oss << "x86";
+ #endif
+
+ return oss.str();
+#else
+ struct utsname osinfo;
+ uname(&osinfo);
+ return std::string(osinfo.sysname) + "/"
+ + osinfo.release + " " + osinfo.machine;
+#endif
+}
+
void initializePaths()
{
#if RUN_IN_PLACE