diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-11-12 09:27:52 -0600 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-11-12 09:27:52 -0600 |
commit | cb286da1dd4a7cadc2b533219ef9185fa45fb701 (patch) | |
tree | 6a090600564976a49236a1aecf3ba03433910a76 | |
parent | 658b5d4cf822b9f796058272e37ffd6bcb9b8559 (diff) | |
parent | a6dfd1cf6ef90f4e732727649ebc0c3234ec90b6 (diff) | |
download | redot-engine-cb286da1dd4a7cadc2b533219ef9185fa45fb701.tar.gz |
Merge pull request #99112 from bruvzg/get_model_name
Implement `get_model_name` on macOS and Windows.
-rw-r--r-- | doc/classes/OS.xml | 2 | ||||
-rw-r--r-- | platform/macos/os_macos.h | 2 | ||||
-rw-r--r-- | platform/macos/os_macos.mm | 9 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 28 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 2 |
5 files changed, 42 insertions, 1 deletions
diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index 777950c075..1a2f0e653d 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -356,7 +356,7 @@ <return type="String" /> <description> Returns the model name of the current device. - [b]Note:[/b] This method is implemented on Android and iOS. Returns [code]"GenericDevice"[/code] on unsupported platforms. + [b]Note:[/b] This method is implemented on Android, iOS, macOS, and Windows. Returns [code]"GenericDevice"[/code] on unsupported platforms. </description> </method> <method name="get_name" qualifiers="const"> diff --git a/platform/macos/os_macos.h b/platform/macos/os_macos.h index 303fc112bf..4fb4507837 100644 --- a/platform/macos/os_macos.h +++ b/platform/macos/os_macos.h @@ -114,6 +114,8 @@ public: virtual String get_unique_id() const override; virtual String get_processor_name() const override; + virtual String get_model_name() const override; + virtual bool is_sandboxed() const override; virtual Vector<String> get_granted_permissions() const override; virtual void revoke_granted_permissions() override; diff --git a/platform/macos/os_macos.mm b/platform/macos/os_macos.mm index d9086b8c38..08ff391aab 100644 --- a/platform/macos/os_macos.mm +++ b/platform/macos/os_macos.mm @@ -67,6 +67,15 @@ void OS_MacOS::initialize() { initialize_core(); } +String OS_MacOS::get_model_name() const { + char buffer[256]; + size_t buffer_len = 256; + if (sysctlbyname("hw.model", &buffer, &buffer_len, nullptr, 0) == 0 && buffer_len != 0) { + return String::utf8(buffer, buffer_len); + } + return OS_Unix::get_model_name(); +} + String OS_MacOS::get_processor_name() const { char buffer[256]; size_t buffer_len = 256; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 50fc4e3653..0d151668ba 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1740,6 +1740,34 @@ String OS_Windows::get_locale() const { return "en"; } +String OS_Windows::get_model_name() const { + HKEY hkey; + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) { + return OS::get_model_name(); + } + + String sys_name; + String board_name; + WCHAR buffer[256]; + DWORD buffer_len = 256; + DWORD vtype = REG_SZ; + if (RegQueryValueExW(hkey, L"SystemProductName", nullptr, &vtype, (LPBYTE)buffer, &buffer_len) == ERROR_SUCCESS && buffer_len != 0) { + sys_name = String::utf16((const char16_t *)buffer, buffer_len).strip_edges(); + } + buffer_len = 256; + if (RegQueryValueExW(hkey, L"BaseBoardProduct", nullptr, &vtype, (LPBYTE)buffer, &buffer_len) == ERROR_SUCCESS && buffer_len != 0) { + board_name = String::utf16((const char16_t *)buffer, buffer_len).strip_edges(); + } + RegCloseKey(hkey); + if (!sys_name.is_empty() && sys_name.to_lower() != "system product name") { + return sys_name; + } + if (!board_name.is_empty() && board_name.to_lower() != "base board product") { + return board_name; + } + return OS::get_model_name(); +} + String OS_Windows::get_processor_name() const { const String id = "Hardware\\Description\\System\\CentralProcessor\\0"; diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 4f9bc049ee..34af004822 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -210,6 +210,8 @@ public: virtual String get_processor_name() const override; + virtual String get_model_name() const override; + virtual uint64_t get_embedded_pck_offset() const override; virtual String get_config_path() const override; |