summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorshuax <[email protected]>2022-03-30 07:55:49 +0800
committershuax <[email protected]>2022-03-30 07:55:49 +0800
commit83bb549e7d7c73ce02d6b904452bbf6c8d7af377 (patch)
tree688cac0d9aa173b2a0016c460fb713ee0086bdc1 /core/src
parent8b12860707afe1c56d977d736caec981d92638b9 (diff)
improve registry
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/winos/registry_keys.c4
-rw-r--r--core/src/xmake/winos/registry_query.c62
-rw-r--r--core/src/xmake/winos/registry_values.c4
3 files changed, 57 insertions, 13 deletions
diff --git a/core/src/xmake/winos/registry_keys.c b/core/src/xmake/winos/registry_keys.c
index 9c3467210..d2a1c2bb5 100644
--- a/core/src/xmake/winos/registry_keys.c
+++ b/core/src/xmake/winos/registry_keys.c
@@ -184,9 +184,13 @@ tb_int_t xm_winos_registry_keys(lua_State* lua)
{
// get registry rootkey
if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) key = HKEY_CLASSES_ROOT;
+ else if (!tb_strcmp(rootkey, "HKCR")) key = HKEY_CLASSES_ROOT;
else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) key = HKEY_CURRENT_CONFIG;
+ else if (!tb_strcmp(rootkey, "HKCC")) key = HKEY_CURRENT_CONFIG;
else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) key = HKEY_CURRENT_USER;
+ else if (!tb_strcmp(rootkey, "HKCU")) key = HKEY_CURRENT_USER;
else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) key = HKEY_LOCAL_MACHINE;
+ else if (!tb_strcmp(rootkey, "HKLM")) key = HKEY_LOCAL_MACHINE;
else if (!tb_strcmp(rootkey, "HKEY_USERS")) key = HKEY_USERS;
else
{
diff --git a/core/src/xmake/winos/registry_query.c b/core/src/xmake/winos/registry_query.c
index aadb65b2e..efff036a0 100644
--- a/core/src/xmake/winos/registry_query.c
+++ b/core/src/xmake/winos/registry_query.c
@@ -33,8 +33,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* types
*/
-// the RegGetValueA func type
-typedef BOOL (WINAPI* xm_RegGetValueA_t)(HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
+// the RegGetValueW func type
+typedef BOOL (WINAPI* xm_RegGetValueW_t)(HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
@@ -60,13 +60,18 @@ tb_int_t xm_winos_registry_query(lua_State* lua)
HKEY key = tb_null;
HKEY keynew = tb_null;
tb_char_t* value = tb_null;
+ tb_wchar_t* value_w = tb_null;
do
{
// get registry rootkey
if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) key = HKEY_CLASSES_ROOT;
+ else if (!tb_strcmp(rootkey, "HKCR")) key = HKEY_CLASSES_ROOT;
else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) key = HKEY_CURRENT_CONFIG;
+ else if (!tb_strcmp(rootkey, "HKCC")) key = HKEY_CURRENT_CONFIG;
else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) key = HKEY_CURRENT_USER;
+ else if (!tb_strcmp(rootkey, "HKCU")) key = HKEY_CURRENT_USER;
else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) key = HKEY_LOCAL_MACHINE;
+ else if (!tb_strcmp(rootkey, "HKLM")) key = HKEY_LOCAL_MACHINE;
else if (!tb_strcmp(rootkey, "HKEY_USERS")) key = HKEY_USERS;
else
{
@@ -75,23 +80,41 @@ tb_int_t xm_winos_registry_query(lua_State* lua)
break;
}
- // attempt to load RegGetValueA
- static xm_RegGetValueA_t s_RegGetValueA = tb_null;
- if (!s_RegGetValueA)
+ // convert rootdir to wide characters
+ tb_wchar_t rootdir_w[TB_PATH_MAXN];
+ if (tb_atow(rootdir_w, rootdir, TB_PATH_MAXN) == (tb_size_t)-1)
+ {
+ lua_pushnil(lua);
+ lua_pushfstring(lua, "invalid registry rootkey:: %s", rootdir);
+ break;
+ }
+
+ // convert valuename to wide characters
+ tb_wchar_t valuename_w[TB_PATH_MAXN];
+ if (tb_atow(valuename_w, valuename, TB_PATH_MAXN) == (tb_size_t)-1)
+ {
+ lua_pushnil(lua);
+ lua_pushfstring(lua, "invalid registry valuename: %s", valuename);
+ break;
+ }
+
+ // attempt to load RegGetValueW
+ static xm_RegGetValueW_t s_RegGetValueW = tb_null;
+ if (!s_RegGetValueW)
{
// load the advapi32 module
tb_dynamic_ref_t module = (tb_dynamic_ref_t)GetModuleHandleA("advapi32.dll");
if (!module) module = tb_dynamic_init("advapi32.dll");
- if (module) s_RegGetValueA = (xm_RegGetValueA_t)tb_dynamic_func(module, "RegGetValueA");
+ if (module) s_RegGetValueW = (xm_RegGetValueW_t)tb_dynamic_func(module, "RegGetValueW");
}
// get registry value
DWORD type = 0;
- if (s_RegGetValueA)
+ if (s_RegGetValueW)
{
// get registry value size
DWORD valuesize = 0;
- if (s_RegGetValueA(key, rootdir, valuename, RRF_RT_ANY, 0, tb_null, &valuesize) != ERROR_SUCCESS)
+ if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, 0, tb_null, &valuesize) != ERROR_SUCCESS)
{
lua_pushnil(lua);
lua_pushfstring(lua, "get registry value size failed: %s\\%s;%s", rootkey, rootdir, valuename);
@@ -101,11 +124,13 @@ tb_int_t xm_winos_registry_query(lua_State* lua)
// make value buffer
value = (tb_char_t*)tb_malloc0(valuesize + 1);
tb_assert_and_check_break(value);
+ value_w = (tb_wchar_t*)tb_malloc0(sizeof(tb_wchar_t) * (valuesize + 1));
+ tb_assert_and_check_break(value_w);
// get value result, we attempt to do not expand value if get failed
type = 0;
- if (s_RegGetValueA(key, rootdir, valuename, RRF_RT_ANY, &type, (PVOID)value, &valuesize) != ERROR_SUCCESS &&
- s_RegGetValueA(key, rootdir, valuename, RRF_RT_ANY | RRF_NOEXPAND, &type, (PVOID)value, &valuesize) != ERROR_SUCCESS)
+ if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, &type, (PVOID)value_w, &valuesize) != ERROR_SUCCESS &&
+ s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY | RRF_NOEXPAND, &type, (PVOID)value_w, &valuesize) != ERROR_SUCCESS)
{
lua_pushnil(lua);
lua_pushfstring(lua, "get registry value failed: %s\\%s;%s", rootkey, rootdir, valuename);
@@ -115,7 +140,7 @@ tb_int_t xm_winos_registry_query(lua_State* lua)
else
{
// open registry key
- if (RegOpenKeyExA(key, rootdir, 0, KEY_QUERY_VALUE, &keynew) != ERROR_SUCCESS && keynew)
+ if (RegOpenKeyExW(key, rootdir_w, 0, KEY_QUERY_VALUE, &keynew) != ERROR_SUCCESS && keynew)
{
lua_pushnil(lua);
lua_pushfstring(lua, "open registry key failed: %s\\%s", rootkey, rootdir);
@@ -124,7 +149,7 @@ tb_int_t xm_winos_registry_query(lua_State* lua)
// get registry value size
DWORD valuesize = 0;
- if (RegQueryValueExA(keynew, valuename, tb_null, tb_null, tb_null, &valuesize) != ERROR_SUCCESS)
+ if (RegQueryValueExW(keynew, valuename_w, tb_null, tb_null, tb_null, &valuesize) != ERROR_SUCCESS)
{
lua_pushnil(lua);
lua_pushfstring(lua, "get registry value size failed: %s\\%s;%s", rootkey, rootdir, valuename);
@@ -134,10 +159,12 @@ tb_int_t xm_winos_registry_query(lua_State* lua)
// make value buffer
value = (tb_char_t*)tb_malloc0(valuesize + 1);
tb_assert_and_check_break(value);
+ value_w = (tb_wchar_t*)tb_malloc0(sizeof() * (valuesize + 1));
+ tb_assert_and_check_break(value_w);
// get value result
type = 0;
- if (RegQueryValueExA(keynew, valuename, tb_null, &type, (LPBYTE)value, &valuesize) != ERROR_SUCCESS)
+ if (RegQueryValueExW(keynew, valuename_w, tb_null, &type, (LPBYTE)value_w, &valuesize) != ERROR_SUCCESS)
{
lua_pushnil(lua);
lua_pushfstring(lua, "get registry value failed: %s\\%s;%s", rootkey, rootdir, valuename);
@@ -145,6 +172,13 @@ tb_int_t xm_winos_registry_query(lua_State* lua)
}
}
+ if (tb_wtoa(valuename_w, value, valuesize + 1) == (tb_size_t)-1)
+ {
+ lua_pushnil(lua);
+ lua_pushfstring(lua, "get registry value failed: %s\\%s;%s", rootkey, rootdir, valuename);
+ break;
+ }
+
// save result
switch (type)
{
@@ -177,6 +211,8 @@ tb_int_t xm_winos_registry_query(lua_State* lua)
// exit value
if (value) tb_free(value);
value = tb_null;
+ if (value_w) tb_free(value_w);
+ value_w = tb_null;
// ok?
return ok? 1 : 2;
diff --git a/core/src/xmake/winos/registry_values.c b/core/src/xmake/winos/registry_values.c
index 17aefef6e..ecddabdf5 100644
--- a/core/src/xmake/winos/registry_values.c
+++ b/core/src/xmake/winos/registry_values.c
@@ -62,9 +62,13 @@ tb_int_t xm_winos_registry_values(lua_State* lua)
{
// get registry rootkey
if (!tb_strcmp(rootkey, "HKEY_CLASSES_ROOT")) key = HKEY_CLASSES_ROOT;
+ else if (!tb_strcmp(rootkey, "HKCR")) key = HKEY_CLASSES_ROOT;
else if (!tb_strcmp(rootkey, "HKEY_CURRENT_CONFIG")) key = HKEY_CURRENT_CONFIG;
+ else if (!tb_strcmp(rootkey, "HKCC")) key = HKEY_CURRENT_CONFIG;
else if (!tb_strcmp(rootkey, "HKEY_CURRENT_USER")) key = HKEY_CURRENT_USER;
+ else if (!tb_strcmp(rootkey, "HKCU")) key = HKEY_CURRENT_USER;
else if (!tb_strcmp(rootkey, "HKEY_LOCAL_MACHINE")) key = HKEY_LOCAL_MACHINE;
+ else if (!tb_strcmp(rootkey, "HKLM")) key = HKEY_LOCAL_MACHINE;
else if (!tb_strcmp(rootkey, "HKEY_USERS")) key = HKEY_USERS;
else
{