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