Skip to content

Commit 0ee90ab

Browse files
authored
Fix wmic (#642)
1 parent a990da0 commit 0ee90ab

File tree

3 files changed

+154
-8
lines changed

3 files changed

+154
-8
lines changed

source/funkin/backend/system/framerate/SystemInfo.hx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ class SystemInfo extends FramerateCategory {
4949
if (osName != "")
5050
osInfo = '${osName} ${osVersion}'.trim();
5151
}
52+
#elseif windows
53+
var windowsCurrentVersionPath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
54+
var buildNumber = Std.parseInt(RegistryUtil.get(HKEY_LOCAL_MACHINE, windowsCurrentVersionPath, "CurrentBuildNumber"));
55+
var edition = RegistryUtil.get(HKEY_LOCAL_MACHINE, windowsCurrentVersionPath, "ProductName");
56+
57+
var lcuKey = "WinREVersion"; // Last Cumulative Update Key On Older Windows Versions
58+
if (buildNumber >= 22000) { // Windows 11 Initial Release Build Number
59+
edition = edition.replace("Windows 10", "Windows 11");
60+
lcuKey = "LCUVer"; // Last Cumulative Update Key On Windows 11
61+
}
62+
63+
var lcuVersion = RegistryUtil.get(HKEY_LOCAL_MACHINE, windowsCurrentVersionPath, lcuKey);
64+
65+
osInfo = edition;
66+
67+
if (lcuVersion != null && lcuVersion != "")
68+
osInfo += ' ${lcuVersion}';
69+
else if (lime.system.System.platformVersion != null && lime.system.System.platformVersion != "")
70+
osInfo += ' ${lime.system.System.platformVersion}';
5271
#else
5372
if (lime.system.System.platformLabel != null && lime.system.System.platformLabel != "" && lime.system.System.platformVersion != null && lime.system.System.platformVersion != "")
5473
osInfo = '${lime.system.System.platformLabel.replace(lime.system.System.platformVersion, "").trim()} ${lime.system.System.platformVersion}';
@@ -58,10 +77,7 @@ class SystemInfo extends FramerateCategory {
5877

5978
try {
6079
#if windows
61-
var process = new HiddenProcess("wmic", ["cpu", "get", "name"]);
62-
if (process.exitCode() != 0) throw 'Could not fetch CPU information';
63-
64-
cpuName = process.stdout.readAll().toString().trim().split("\n")[1].trim();
80+
cpuName = RegistryUtil.get(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "ProcessorNameString");
6581
#elseif mac
6682
var process = new HiddenProcess("sysctl -a | grep brand_string"); // Somehow this isnt able to use the args but it still works
6783
if (process.exitCode() != 0) throw 'Could not fetch CPU information';

source/funkin/backend/utils/MemoryUtil.hx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class MemoryUtil {
9292
public static function getMemType():String {
9393
#if windows
9494
var memoryMap:Map<Int, String> = [
95-
0 => "Unknown",
95+
0 => null,
9696
1 => "Other",
9797
2 => "DRAM",
9898
3 => "Synchronous DRAM",
@@ -117,13 +117,23 @@ class MemoryUtil {
117117
22 => "DDR2 FB-DIMM",
118118
24 => "DDR3",
119119
25 => "FBD2",
120-
26 => "DDR4"
120+
26 => "DDR4",
121+
27 => "LPDDR",
122+
28 => "LPDDR2",
123+
29 => "LPDDR3",
124+
30 => "LPDDR4",
125+
31 => "Logical Non-volatile device",
126+
32 => "HBM",
127+
33 => "HBM2",
128+
34 => "DDR5",
129+
35 => "LPDDR5",
130+
36 => "HBM3",
121131
];
122132
var memoryOutput:Int = -1;
123133

124-
var process = new HiddenProcess("wmic", ["memorychip", "get", "SMBIOSMemoryType"]);
134+
var process = new HiddenProcess("powershell", ["-Command", "Get-CimInstance Win32_PhysicalMemory | Select-Object -ExpandProperty SMBIOSMemoryType" ]);
125135
if (process.exitCode() == 0) memoryOutput = Std.int(Std.parseFloat(process.stdout.readAll().toString().trim().split("\n")[1]));
126-
if (memoryOutput != -1) return memoryMap[memoryOutput];
136+
if (memoryOutput != -1) return memoryMap[memoryOutput] == null ? 'Unknown ($memoryOutput)' : memoryMap[memoryOutput];
127137
#elseif mac
128138
var process = new HiddenProcess("system_profiler", ["SPMemoryDataType"]);
129139
var reg = ~/Type: (.+)/;
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package funkin.backend.utils;
2+
3+
enum abstract RegistryHive(Int) {
4+
var HKEY_CLASSES_ROOT = 0x80000000;
5+
var HKEY_CURRENT_USER = 0x80000001;
6+
var HKEY_LOCAL_MACHINE = 0x80000002;
7+
var HKEY_USERS = 0x80000003;
8+
var HKEY_CURRENT_CONFIG = 0x80000005;
9+
}
10+
#if windows
11+
@:cppFileCode('
12+
#include <windows.h>
13+
#include <tchar.h>
14+
#include <string>
15+
#include <vector>
16+
')
17+
#end
18+
class RegistryUtil {
19+
#if windows
20+
@:functionCode('
21+
HKEY hKey;
22+
LONG result;
23+
DWORD dataSize = 0;
24+
DWORD dataType = 0;
25+
26+
std::wstring subkey = std::wstring(key.wchar_str());
27+
std::wstring valname = std::wstring(string.wchar_str());
28+
29+
result = RegOpenKeyExW((HKEY)reinterpret_cast<HKEY>(static_cast<uintptr_t>(hive)), subkey.c_str(), 0, KEY_READ, &hKey);
30+
if (result != ERROR_SUCCESS) return null();
31+
32+
result = RegQueryValueExW(hKey, valname.c_str(), NULL, &dataType, NULL, &dataSize);
33+
if (result != ERROR_SUCCESS || dataSize == 0) {
34+
RegCloseKey(hKey);
35+
return null();
36+
}
37+
38+
std::vector<wchar_t> buffer(dataSize / sizeof(wchar_t));
39+
result = RegQueryValueExW(hKey, valname.c_str(), NULL, NULL, (LPBYTE)buffer.data(), &dataSize);
40+
RegCloseKey(hKey);
41+
42+
if (result == ERROR_SUCCESS) {
43+
return ::String(buffer.data());
44+
}
45+
return null();
46+
')
47+
#end
48+
public static function get(hive:RegistryHive, key:String, string:String):Null<String>
49+
{
50+
return null;
51+
}
52+
53+
#if windows
54+
@:functionCode('
55+
HKEY hKey;
56+
LONG result;
57+
58+
std::wstring subkey = std::wstring(key.wchar_str());
59+
std::wstring valname = std::wstring(string.wchar_str());
60+
std::wstring data = std::wstring(value.wchar_str());
61+
62+
result = RegCreateKeyExW((HKEY)reinterpret_cast<HKEY>(static_cast<uintptr_t>(hive)), subkey.c_str(), 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL);
63+
if (result != ERROR_SUCCESS) return false;
64+
65+
result = RegSetValueExW(hKey, valname.c_str(), 0, REG_SZ, (const BYTE*)data.c_str(), (DWORD)((data.length() + 1) * sizeof(wchar_t)));
66+
RegCloseKey(hKey);
67+
68+
return result == ERROR_SUCCESS;
69+
')
70+
#end
71+
public static function set(hive:RegistryHive, key:String, string:String, value:String):Bool
72+
{
73+
return false;
74+
}
75+
76+
#if windows
77+
@:functionCode('
78+
HKEY hKey;
79+
LONG result;
80+
81+
std::wstring subkey = std::wstring(key.wchar_str());
82+
std::wstring valname = std::wstring(string.wchar_str());
83+
84+
result = RegOpenKeyExW((HKEY)reinterpret_cast<HKEY>(static_cast<uintptr_t>(hive)), subkey.c_str(), 0, KEY_READ, &hKey);
85+
if (result != ERROR_SUCCESS) return false;
86+
87+
DWORD dataType = 0;
88+
result = RegQueryValueExW(hKey, valname.c_str(), NULL, &dataType, NULL, NULL);
89+
90+
RegCloseKey(hKey);
91+
92+
return result == ERROR_SUCCESS;
93+
')
94+
#end
95+
public static function exists(hive:RegistryHive, key:String, string:String):Bool
96+
{
97+
return false;
98+
}
99+
100+
#if windows
101+
@:functionCode('
102+
HKEY hKey;
103+
LONG result;
104+
105+
std::wstring subkey = std::wstring(key.wchar_str());
106+
std::wstring valname = std::wstring(string.wchar_str());
107+
108+
result = RegOpenKeyExW((HKEY)reinterpret_cast<HKEY>(static_cast<uintptr_t>(hive)), subkey.c_str(), 0, KEY_SET_VALUE, &hKey);
109+
if (result != ERROR_SUCCESS) return false;
110+
111+
result = RegDeleteValueW(hKey, valname.c_str());
112+
RegCloseKey(hKey);
113+
114+
return result == ERROR_SUCCESS;
115+
')
116+
#end
117+
public static function delete(hive:RegistryHive, key:String, string:String):Bool {
118+
return false;
119+
}
120+
}

0 commit comments

Comments
 (0)