Forráskód Böngészése

GetOSVersion() returns the version of the OS.

Florastamine 8 éve
szülő
commit
4c7647aa29

+ 1 - 0
Docs/AngelScriptAPI.h

@@ -15947,6 +15947,7 @@ String GetPlatform();
 uint64 GetTotalMemory();
 uint64 GetTotalMemory();
 String GetLoginName(); 
 String GetLoginName(); 
 String GetHostName();
 String GetHostName();
+String GetOSVersion(); 
 uint GetRG16Format();
 uint GetRG16Format();
 uint GetRGBA16Format();
 uint GetRGBA16Format();
 uint GetRGBAFloat16Format();
 uint GetRGBAFloat16Format();

+ 1 - 0
Docs/LuaScriptAPI.dox

@@ -8657,6 +8657,7 @@ Properties:
 - unsigned long long GetTotalMemory()
 - unsigned long long GetTotalMemory()
 - String GetLoginName()
 - String GetLoginName()
 - String GetHostName() 
 - String GetHostName() 
+- String GetOSVersion() 
 - unsigned GetRandomSeed()
 - unsigned GetRandomSeed()
 - Renderer* GetRenderer()
 - Renderer* GetRenderer()
 - Time* GetTime()
 - Time* GetTime()

+ 1 - 0
Docs/ScriptAPI.dox

@@ -16524,6 +16524,7 @@ Properties:
 - uint64 GetTotalMemory() 
 - uint64 GetTotalMemory() 
 - String GetLoginName() 
 - String GetLoginName() 
 - String GetHostName()
 - String GetHostName()
+- String GetOSVersion() 
 - uint GetRG16Format()
 - uint GetRG16Format()
 - uint GetRGBA16Format()
 - uint GetRGBA16Format()
 - uint GetRGBAFloat16Format()
 - uint GetRGBAFloat16Format()

+ 1 - 0
Source/Urho3D/AngelScript/CoreAPI.cpp

@@ -832,6 +832,7 @@ static void RegisterProcessUtils(asIScriptEngine* engine)
     engine->RegisterGlobalFunction("uint64 GetTotalMemory()", asFUNCTION(GetTotalMemory), asCALL_CDECL);
     engine->RegisterGlobalFunction("uint64 GetTotalMemory()", asFUNCTION(GetTotalMemory), asCALL_CDECL);
     engine->RegisterGlobalFunction("String GetLoginName()", asFUNCTION(GetLoginName), asCALL_CDECL);
     engine->RegisterGlobalFunction("String GetLoginName()", asFUNCTION(GetLoginName), asCALL_CDECL);
     engine->RegisterGlobalFunction("String GetHostName()", asFUNCTION(GetHostName), asCALL_CDECL);
     engine->RegisterGlobalFunction("String GetHostName()", asFUNCTION(GetHostName), asCALL_CDECL);
+    engine->RegisterGlobalFunction("String GetOSVersion()", asFUNCTION(GetOSVersion), asCALL_CDECL);
 }
 }
 
 
 static void ConstructAttributeInfo(AttributeInfo* ptr)
 static void ConstructAttributeInfo(AttributeInfo* ptr)

+ 49 - 0
Source/Urho3D/Core/ProcessUtils.cpp

@@ -539,4 +539,53 @@ String GetHostName()
     return String::EMPTY; 
     return String::EMPTY; 
 }
 }
 
 
+#if defined(_WIN32)
+#define STATUS_SUCCESS (0x00000000)
+typedef NTSTATUS       (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
+
+static void GetOS(RTL_OSVERSIONINFOW *r)
+{
+    HMODULE m = GetModuleHandle("ntdll.dll");
+    if (m)
+    {
+        RtlGetVersionPtr fPtr = (RtlGetVersionPtr) GetProcAddress(m, "RtlGetVersion");
+        if (r && fPtr && fPtr(r) == STATUS_SUCCESS)
+            r->dwOSVersionInfoSize = sizeof *r; 
+    }
+}
+#endif 
+
+String GetOSVersion() 
+{
+#if defined(__linux__)
+    struct utsname u; 
+    if(uname(&u) == 0)
+        return String(u.sysname) + " " + u.release; 
+#elif defined(_WIN32)
+    RTL_OSVERSIONINFOW r;
+    GetOS(&r); 
+    // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
+    if(r.dwMajorVersion == 5 && r.dwMinorVersion == 0) 
+        return "Windows 2000"; 
+    else if(r.dwMajorVersion == 5 && r.dwMinorVersion == 1) 
+        return "Windows XP"; 
+    else if(r.dwMajorVersion == 5 && r.dwMinorVersion == 2) 
+        return "Windows XP 64-Bit Edition/Windows Server 2003/Windows Server 2003 R2"; 
+    else if(r.dwMajorVersion == 6 && r.dwMinorVersion == 0) 
+        return "Windows Vista/Windows Server 2008"; 
+    else if(r.dwMajorVersion == 6 && r.dwMinorVersion == 1) 
+        return "Windows 7/Windows Server 2008 R2"; 
+    else if(r.dwMajorVersion == 6 && r.dwMinorVersion == 2) 
+        return "Windows 8/Windows Server 2012";
+    else if(r.dwMajorVersion == 6 && r.dwMinorVersion == 3) 
+        return "Windows 8.1/Windows Server 2012 R2"; 
+    else if(r.dwMajorVersion == 10 && r.dwMinorVersion == 0) 
+        return "Windows 10/Windows Server 2016"; 
+    else 
+        return "Windows Unidentified"; 
+#else 
+#endif 
+    return String::EMPTY; 
+}
+
 }
 }

+ 2 - 0
Source/Urho3D/Core/ProcessUtils.h

@@ -75,4 +75,6 @@ URHO3D_API unsigned long long GetTotalMemory();
 URHO3D_API String GetLoginName(); 
 URHO3D_API String GetLoginName(); 
 /// Return the name of the running machine. 
 /// Return the name of the running machine. 
 URHO3D_API String GetHostName();
 URHO3D_API String GetHostName();
+/// Return the version of the currently running OS. 
+URHO3D_API String GetOSVersion(); 
 }
 }

+ 1 - 0
Source/Urho3D/LuaScript/pkgs/Core/ProcessUtils.pkg

@@ -19,3 +19,4 @@ String GetMiniDumpDir();
 unsigned long long GetTotalMemory(); 
 unsigned long long GetTotalMemory(); 
 String GetLoginName(); 
 String GetLoginName(); 
 String GetHostName();
 String GetHostName();
+String GetOSVersion();