diff --git a/lime/system/System.hx b/lime/system/System.hx index 53b52dddb..79815ab68 100644 --- a/lime/system/System.hx +++ b/lime/system/System.hx @@ -647,7 +647,9 @@ class System { private static function get_manufacturer ():String { - #if android + #if windows + return NativeCFFI.lime_system_get_manufacturer (); + #elseif android var manufacturer:String = JNI.createStaticField ("android/os/Build", "MANUFACTURER", "Ljava/lang/String;").get (); if (manufacturer != null) { return manufacturer.charAt (0).toUpperCase () + manufacturer.substr (1); @@ -664,7 +666,9 @@ class System { private static function get_model ():String { - #if android + #if (windows || ios) + return NativeCFFI.lime_system_get_model (); + #elseif android var manufacturer:String = JNI.createStaticField ("android/os/Build", "MANUFACTURER", "Ljava/lang/String;").get (); var model:String = JNI.createStaticField ("android/os/Build", "MODEL", "Ljava/lang/String;").get (); if (manufacturer != null && model != null) { @@ -676,8 +680,6 @@ class System { } return model; } - #elseif ios - return NativeCFFI.lime_system_get_model (); #elseif mac return __runProcess ("sysctl", [ "-n", "hw.model" ]); #elseif linux @@ -690,7 +692,10 @@ class System { private static function get_version ():String { - #if android + #if windows + var version:String = NativeCFFI.lime_system_get_version (); + if (version != null) return StringTools.trim (version); + #elseif android var release = JNI.createStaticField ("android/os/Build$VERSION", "RELEASE", "Ljava/lang/String;").get (); var api = JNI.createStaticField ("android/os/Build$VERSION", "SDK_INT", "I").get (); if (release != null && api != null) return "Android " + release + " (API " + api + ")"; diff --git a/project/Build.xml b/project/Build.xml index 045ebcf44..f77674868 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -367,6 +367,7 @@ + diff --git a/project/src/system/System.cpp b/project/src/system/System.cpp index 7e4a246f7..059ed0ef3 100644 --- a/project/src/system/System.cpp +++ b/project/src/system/System.cpp @@ -1,4 +1,9 @@ #ifdef HX_WINDOWS +#define _WIN32_DCOM +#include +#include +#include +#pragma comment(lib, "wbemuuid.lib") #include #endif @@ -8,8 +13,107 @@ namespace lime { + #ifdef HX_WINDOWS + std::wstring* GetWMIValue (BSTR query, BSTR field) { + + HRESULT hres = 0; + IWbemLocator *pLoc = NULL; + IWbemServices *pSvc = NULL; + IEnumWbemClassObject* pEnumerator = NULL; + IWbemClassObject *pclsObj = NULL; + ULONG uReturn = 0; + std::wstring* result = NULL; + + // hres = CoInitializeEx (0, COINIT_MULTITHREADED); + + // if (FAILED (hres)) { + + // return NULL; + + // } + + // hres = CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); + + // if (FAILED (hres)) { + + // CoUninitialize (); + // NULL; + + // } + + hres = CoCreateInstance (CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc); + + if (FAILED (hres)) { + + //CoUninitialize (); + return NULL; + + } + + hres = pLoc->ConnectServer (_bstr_t (L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &pSvc); + + if (FAILED (hres)) { + + pLoc->Release (); + // CoUninitialize (); + return NULL; + + } + + hres = CoSetProxyBlanket (pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); + + if (FAILED (hres)) { + + pSvc->Release (); + pLoc->Release (); + // CoUninitialize (); + return NULL; + + } + + hres = pSvc->ExecQuery (bstr_t ("WQL"), query, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); + + if (FAILED (hres)) { + + pSvc->Release (); + pLoc->Release (); + // CoUninitialize (); + return NULL; + + } + + while (pEnumerator) { + + HRESULT hr = pEnumerator->Next (WBEM_INFINITE, 1, &pclsObj, &uReturn); + if (uReturn == 0) break; + + VARIANT vtProp; + + hr = pclsObj->Get (field, 0, &vtProp, 0, 0); + VariantClear (&vtProp); + result = new std::wstring (vtProp.bstrVal, SysStringLen (vtProp.bstrVal)); + + pclsObj->Release (); + + } + + pSvc->Release (); + pLoc->Release (); + pEnumerator->Release (); + // CoUninitialize (); + + return result; + + } + #endif + + std::wstring* System::GetManufacturer () { + #ifdef HX_WINDOWS + return GetWMIValue (bstr_t ("SELECT * FROM Win32_ComputerSystemProduct"), L"Vendor"); + #endif + return NULL; } @@ -17,6 +121,10 @@ namespace lime { std::wstring* System::GetModel () { + #ifdef HX_WINDOWS + return GetWMIValue (bstr_t ("SELECT * FROM Win32_ComputerSystemProduct"), L"Version"); + #endif + return NULL; } @@ -24,6 +132,10 @@ namespace lime { std::wstring* System::GetVersion () { + #ifdef HX_WINDOWS + return GetWMIValue (bstr_t ("SELECT * FROM Win32_OperatingSystem"), L"Caption"); + #endif + return NULL; }