Add System manufacturer, model and version on Windows
This commit is contained in:
@@ -647,7 +647,9 @@ class System {
|
|||||||
|
|
||||||
private static function get_manufacturer ():String {
|
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 ();
|
var manufacturer:String = JNI.createStaticField ("android/os/Build", "MANUFACTURER", "Ljava/lang/String;").get ();
|
||||||
if (manufacturer != null) {
|
if (manufacturer != null) {
|
||||||
return manufacturer.charAt (0).toUpperCase () + manufacturer.substr (1);
|
return manufacturer.charAt (0).toUpperCase () + manufacturer.substr (1);
|
||||||
@@ -664,7 +666,9 @@ class System {
|
|||||||
|
|
||||||
private static function get_model ():String {
|
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 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 ();
|
var model:String = JNI.createStaticField ("android/os/Build", "MODEL", "Ljava/lang/String;").get ();
|
||||||
if (manufacturer != null && model != null) {
|
if (manufacturer != null && model != null) {
|
||||||
@@ -676,8 +680,6 @@ class System {
|
|||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
#elseif ios
|
|
||||||
return NativeCFFI.lime_system_get_model ();
|
|
||||||
#elseif mac
|
#elseif mac
|
||||||
return __runProcess ("sysctl", [ "-n", "hw.model" ]);
|
return __runProcess ("sysctl", [ "-n", "hw.model" ]);
|
||||||
#elseif linux
|
#elseif linux
|
||||||
@@ -690,7 +692,10 @@ class System {
|
|||||||
|
|
||||||
private static function get_version ():String {
|
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 release = JNI.createStaticField ("android/os/Build$VERSION", "RELEASE", "Ljava/lang/String;").get ();
|
||||||
var api = JNI.createStaticField ("android/os/Build$VERSION", "SDK_INT", "I").get ();
|
var api = JNI.createStaticField ("android/os/Build$VERSION", "SDK_INT", "I").get ();
|
||||||
if (release != null && api != null) return "Android " + release + " (API " + api + ")";
|
if (release != null && api != null) return "Android " + release + " (API " + api + ")";
|
||||||
|
|||||||
@@ -367,6 +367,7 @@
|
|||||||
<lib name="wldap32.lib" />
|
<lib name="wldap32.lib" />
|
||||||
<lib name="shell32.lib" />
|
<lib name="shell32.lib" />
|
||||||
<lib name="comdlg32.lib" />
|
<lib name="comdlg32.lib" />
|
||||||
|
<lib name="comsuppw.lib" />
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
#ifdef HX_WINDOWS
|
#ifdef HX_WINDOWS
|
||||||
|
#define _WIN32_DCOM
|
||||||
|
#include <iostream>
|
||||||
|
#include <wbemidl.h>
|
||||||
|
#include <comutil.h>
|
||||||
|
#pragma comment(lib, "wbemuuid.lib")
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -8,8 +13,107 @@
|
|||||||
namespace lime {
|
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 () {
|
std::wstring* System::GetManufacturer () {
|
||||||
|
|
||||||
|
#ifdef HX_WINDOWS
|
||||||
|
return GetWMIValue (bstr_t ("SELECT * FROM Win32_ComputerSystemProduct"), L"Vendor");
|
||||||
|
#endif
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,6 +121,10 @@ namespace lime {
|
|||||||
|
|
||||||
std::wstring* System::GetModel () {
|
std::wstring* System::GetModel () {
|
||||||
|
|
||||||
|
#ifdef HX_WINDOWS
|
||||||
|
return GetWMIValue (bstr_t ("SELECT * FROM Win32_ComputerSystemProduct"), L"Version");
|
||||||
|
#endif
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,6 +132,10 @@ namespace lime {
|
|||||||
|
|
||||||
std::wstring* System::GetVersion () {
|
std::wstring* System::GetVersion () {
|
||||||
|
|
||||||
|
#ifdef HX_WINDOWS
|
||||||
|
return GetWMIValue (bstr_t ("SELECT * FROM Win32_OperatingSystem"), L"Caption");
|
||||||
|
#endif
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user