diff options
| author | ruki <[email protected]> | 2025-11-09 19:11:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-09 19:44:18 +0800 |
| commit | c89c94bf89e98c8e42e786aacc0b334a57474179 (patch) | |
| tree | 60b4964d58a5289e1444b2375ec5db1a93eccdd6 /core/src/xmake/winos | |
| parent | 3f9c6f27ee8f99d5c4393433e8863fec93da43e7 (diff) | |
format code
Diffstat (limited to 'core/src/xmake/winos')
| -rw-r--r-- | core/src/xmake/winos/ansi.c | 50 | ||||
| -rw-r--r-- | core/src/xmake/winos/logical_drives.c | 24 | ||||
| -rw-r--r-- | core/src/xmake/winos/prefix.h | 5 | ||||
| -rw-r--r-- | core/src/xmake/winos/registry_keys.c | 161 | ||||
| -rw-r--r-- | core/src/xmake/winos/registry_query.c | 132 | ||||
| -rw-r--r-- | core/src/xmake/winos/registry_values.c | 100 | ||||
| -rw-r--r-- | core/src/xmake/winos/short_path.c | 20 |
7 files changed, 243 insertions, 249 deletions
diff --git a/core/src/xmake/winos/ansi.c b/core/src/xmake/winos/ansi.c index e4780d134..137f18742 100644 --- a/core/src/xmake/winos/ansi.c +++ b/core/src/xmake/winos/ansi.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "ansi" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "ansi" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,64 +35,56 @@ * implementation */ -static tb_int_t xm_expand_cp(tb_int_t cp) -{ +static tb_int_t xm_expand_cp(tb_int_t cp) { // check tb_assert_and_check_return_val(cp >= 0 && cp <= 65535, 0); - if (cp == CP_OEMCP) return GetOEMCP(); - if (cp == CP_ACP) return GetACP(); + if (cp == CP_OEMCP) + return GetOEMCP(); + if (cp == CP_ACP) + return GetACP(); return cp; } -tb_int_t xm_winos_console_cp(lua_State* lua) -{ +tb_int_t xm_winos_console_cp(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); tb_int_t n = lua_gettop(lua); - if (n >= 1) - { + if (n >= 1) { lua_Integer cp = luaL_checkinteger(lua, 1); luaL_argcheck(lua, cp >= 0 && cp < 65536, 1, "invalid code page"); cp = xm_expand_cp((tb_uint_t)cp); luaL_argcheck(lua, SetConsoleCP((tb_uint_t)cp), 1, "failed to set code page"); lua_pushinteger(lua, cp); return 1; - } - else - { + } else { tb_uint_t cp = GetConsoleCP(); lua_pushinteger(lua, (lua_Integer)cp); return 1; } } -tb_int_t xm_winos_console_output_cp(lua_State* lua) -{ +tb_int_t xm_winos_console_output_cp(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); tb_int_t n = lua_gettop(lua); - if (n >= 1) - { + if (n >= 1) { lua_Integer cp = luaL_checkinteger(lua, 1); luaL_argcheck(lua, cp >= 0 && cp < 65536, 1, "invalid code page"); cp = xm_expand_cp((tb_uint_t)cp); luaL_argcheck(lua, SetConsoleOutputCP((tb_uint_t)cp), 1, "failed to set code page"); lua_pushinteger(lua, cp); return 1; - } - else - { + } else { tb_uint_t cp = GetConsoleOutputCP(); lua_pushinteger(lua, (lua_Integer)cp); return 1; } } -tb_int_t xm_winos_cp_info(lua_State* lua) -{ +tb_int_t xm_winos_cp_info(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -104,7 +96,7 @@ tb_int_t xm_winos_cp_info(lua_State* lua) lua_newtable(lua); lua_pushliteral(lua, "name"); - tb_char_t* namebuf = tb_malloc_cstr(sizeof(cp_info.CodePageName) * 2); + tb_char_t *namebuf = tb_malloc_cstr(sizeof(cp_info.CodePageName) * 2); tb_assert_and_check_return_val(namebuf, 0); tb_size_t namelen = tb_wtoa(namebuf, (const tb_wchar_t *)cp_info.CodePageName, sizeof(cp_info.CodePageName) * 2); tb_assert_and_check_return_val(namelen < sizeof(cp_info.CodePageName) * 2, 0); @@ -121,13 +113,12 @@ tb_int_t xm_winos_cp_info(lua_State* lua) lua_settable(lua, -3); lua_pushliteral(lua, "default_char"); - lua_pushstring(lua, (tb_char_t const*)cp_info.DefaultChar); + lua_pushstring(lua, (tb_char_t const *)cp_info.DefaultChar); lua_settable(lua, -3); lua_pushliteral(lua, "lead_byte"); lua_createtable(lua, MAX_LEADBYTES / 2, 0); - for (tb_size_t i = 0; i < MAX_LEADBYTES && cp_info.LeadByte[i] != 0 && cp_info.LeadByte[i + 1] != 0; i += 2) - { + for (tb_size_t i = 0; i < MAX_LEADBYTES && cp_info.LeadByte[i] != 0 && cp_info.LeadByte[i + 1] != 0; i += 2) { lua_pushinteger(lua, (i / 2) + 1); lua_createtable(lua, 0, 2); @@ -146,8 +137,7 @@ tb_int_t xm_winos_cp_info(lua_State* lua) return 1; } -tb_int_t xm_winos_ansi_cp(lua_State* lua) -{ +tb_int_t xm_winos_ansi_cp(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -156,8 +146,7 @@ tb_int_t xm_winos_ansi_cp(lua_State* lua) return 1; } -tb_int_t xm_winos_oem_cp(lua_State* lua) -{ +tb_int_t xm_winos_oem_cp(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); @@ -165,4 +154,3 @@ tb_int_t xm_winos_oem_cp(lua_State* lua) lua_pushinteger(lua, (lua_Integer)cp); return 1; } - diff --git a/core/src/xmake/winos/logical_drives.c b/core/src/xmake/winos/logical_drives.c index f10e4e09b..48b05886e 100644 --- a/core/src/xmake/winos/logical_drives.c +++ b/core/src/xmake/winos/logical_drives.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "logical_drives" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "logical_drives" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,21 +35,19 @@ */ // get the logical drives -tb_int_t xm_winos_logical_drives(lua_State* lua) -{ +tb_int_t xm_winos_logical_drives(lua_State *lua) { // init table lua_newtable(lua); // get logical drives - tb_char_t* data = tb_null; - do - { + tb_char_t *data = tb_null; + do { // get buffer size DWORD size = GetLogicalDriveStringsA(0, tb_null); tb_assert_and_check_break(size); // make data buffer - data = (tb_char_t*)tb_malloc0(size + 1); + data = (tb_char_t *)tb_malloc0(size + 1); tb_assert_and_check_break(data); // get logical drives @@ -57,10 +55,9 @@ tb_int_t xm_winos_logical_drives(lua_State* lua) tb_assert_and_check_break(size); // parse logical drives - tb_size_t i = 1; - tb_char_t const* p = data; - while (*p) - { + tb_size_t i = 1; + tb_char_t const *p = data; + while (*p) { // save drive lua_pushinteger(lua, i++); lua_pushstring(lua, p); @@ -72,7 +69,8 @@ tb_int_t xm_winos_logical_drives(lua_State* lua) } while (0); // exit data - if (data) tb_free(data); + if (data) + tb_free(data); data = tb_null; // ok diff --git a/core/src/xmake/winos/prefix.h b/core/src/xmake/winos/prefix.h index 3c7e103dc..6543b112d 100644 --- a/core/src/xmake/winos/prefix.h +++ b/core/src/xmake/winos/prefix.h @@ -26,10 +26,7 @@ */ #include "../prefix.h" #ifdef TB_CONFIG_OS_WINDOWS -# include <windows.h> +#include <windows.h> #endif - #endif - - diff --git a/core/src/xmake/winos/registry_keys.c b/core/src/xmake/winos/registry_keys.c index 807a094a1..42a37e33d 100644 --- a/core/src/xmake/winos/registry_keys.c +++ b/core/src/xmake/winos/registry_keys.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "registry_keys" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "registry_keys" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -35,75 +35,79 @@ */ // the enum info type -typedef struct __xm_winos_registry_enum_info_t -{ - lua_State* lua; - HKEY key; - tb_int_t ok; - tb_char_t const* error; - tb_int_t count; - tb_wchar_t key_name[1024]; - tb_char_t key_path_a[TB_PATH_MAXN]; - -}xm_winos_registry_enum_info_t; +typedef struct __xm_winos_registry_enum_info_t { + lua_State *lua; + HKEY key; + tb_int_t ok; + tb_char_t const *error; + tb_int_t count; + tb_wchar_t key_name[1024]; + tb_char_t key_path_a[TB_PATH_MAXN]; +} xm_winos_registry_enum_info_t; /* ////////////////////////////////////////////////////////////////////////////////////// * private implementation */ -static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info, tb_wchar_t const* rootdir, tb_long_t recursion) -{ +static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t *info, + tb_wchar_t const *rootdir, + tb_long_t recursion) { // enum keys - HKEY keynew = tb_null; - lua_State* lua = info->lua; - tb_wchar_t* key_path = tb_null; + HKEY keynew = tb_null; + lua_State *lua = info->lua; + tb_wchar_t *key_path = tb_null; tb_size_t key_path_maxn = TB_PATH_MAXN; - do - { + do { // open registry key - if (RegOpenKeyExW(info->key, rootdir, 0, KEY_READ, &keynew) != ERROR_SUCCESS && keynew) - { - info->ok = -1; + if (RegOpenKeyExW(info->key, rootdir, 0, KEY_READ, &keynew) != ERROR_SUCCESS && keynew) { + info->ok = -1; info->error = "open registry key failed"; break; } // query keys - DWORD key_name_num = 0; + DWORD key_name_num = 0; DWORD key_name_maxn = 0; - if (RegQueryInfoKeyW(keynew, tb_null, tb_null, tb_null, &key_name_num, &key_name_maxn, tb_null, tb_null, tb_null, tb_null, tb_null, tb_null) != ERROR_SUCCESS) - { + if (RegQueryInfoKeyW(keynew, + tb_null, + tb_null, + tb_null, + &key_name_num, + &key_name_maxn, + tb_null, + tb_null, + tb_null, + tb_null, + tb_null, + tb_null) != ERROR_SUCCESS) { // cannot query this key, we ignore it break; } key_name_maxn++; // add `\0` // ensure enough key path buffer - if (key_name_maxn > tb_arrayn(info->key_name)) - { - info->ok = -1; + if (key_name_maxn > tb_arrayn(info->key_name)) { + info->ok = -1; info->error = "no enough key path buffer"; break; } // init key path - key_path = (tb_wchar_t*)tb_malloc(key_path_maxn * sizeof(tb_wchar_t)); - if (!key_path) - { - info->ok = -1; + key_path = (tb_wchar_t *)tb_malloc(key_path_maxn * sizeof(tb_wchar_t)); + if (!key_path) { + info->ok = -1; info->error = "no enough key path buffer"; break; } // get all keys DWORD i = 0; - for (i = 0; i < key_name_num && info->ok > 0; i++) - { + for (i = 0; i < key_name_num && info->ok > 0; i++) { // get key name - info->key_name[0] = L'\0'; + info->key_name[0] = L'\0'; DWORD key_name_size = tb_arrayn(info->key_name); - if (RegEnumKeyExW(keynew, i, info->key_name, &key_name_size, tb_null, tb_null, tb_null, tb_null) != ERROR_SUCCESS) - { - info->ok = -1; + if (RegEnumKeyExW(keynew, i, info->key_name, &key_name_size, tb_null, tb_null, tb_null, tb_null) != + ERROR_SUCCESS) { + info->ok = -1; info->error = "get registry key failed"; break; } @@ -113,9 +117,8 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info // get key path (mbs) tb_size_t key_path_a_size = tb_wtoa(info->key_path_a, key_path, sizeof(info->key_path_a)); - if (key_path_a_size == -1) - { - info->ok = -1; + if (key_path_a_size == -1) { + info->ok = -1; info->error = "convert registry key path failed"; break; } @@ -129,15 +132,14 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info // is continue? tb_bool_t is_continue = lua_toboolean(lua, -1); lua_pop(lua, 1); - if (!is_continue) - { + if (!is_continue) { info->ok = 0; break; } // enum all subkeys if (recursion > 0 || recursion < 0) - xm_winos_registry_enum_keys(info, key_path, recursion > 0? recursion - 1 : recursion); + xm_winos_registry_enum_keys(info, key_path, recursion > 0 ? recursion - 1 : recursion); } } while (0); @@ -148,7 +150,8 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info keynew = tb_null; // free key path - if (key_path) tb_free(key_path); + if (key_path) + tb_free(key_path); key_path = tb_null; } @@ -164,36 +167,42 @@ static tb_void_t xm_winos_registry_enum_keys(xm_winos_registry_enum_info_t* info * return true -- continue or break * end) */ -tb_int_t xm_winos_registry_keys(lua_State* lua) -{ +tb_int_t xm_winos_registry_keys(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the arguments - tb_char_t const* rootkey = luaL_checkstring(lua, 1); - tb_char_t const* rootdir = luaL_checkstring(lua, 2); - tb_long_t recursion = (tb_long_t)lua_tointeger(lua, 3); - tb_bool_t is_function = lua_isfunction(lua, 4); + tb_char_t const *rootkey = luaL_checkstring(lua, 1); + tb_char_t const *rootdir = luaL_checkstring(lua, 2); + tb_long_t recursion = (tb_long_t)lua_tointeger(lua, 3); + tb_bool_t is_function = lua_isfunction(lua, 4); tb_check_return_val(rootkey && rootdir && is_function, 0); // enum keys - tb_bool_t ok = tb_false; - tb_int_t count = 0; - HKEY key = tb_null; - do - { + tb_bool_t ok = tb_false; + tb_int_t count = 0; + HKEY key = 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 - { + 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 { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey: %s", rootkey); break; @@ -201,8 +210,7 @@ tb_int_t xm_winos_registry_keys(lua_State* lua) // do enum tb_wchar_t rootdir_w[TB_PATH_MAXN]; - if (tb_atow(rootdir_w, rootdir, TB_PATH_MAXN) == -1) - { + if (tb_atow(rootdir_w, rootdir, TB_PATH_MAXN) == -1) { lua_pushnil(lua); lua_pushfstring(lua, "rootdir is too long: %s", rootdir); break; @@ -216,20 +224,17 @@ tb_int_t xm_winos_registry_keys(lua_State* lua) xm_winos_registry_enum_keys(&info, rootdir_w, recursion); count = info.count; ok = info.ok >= 0; - if (!ok) - { + if (!ok) { lua_pushnil(lua); - lua_pushfstring(lua, "%s: %s\\%s", info.error? info.error : "enum registry keys failed", rootkey, rootdir); + lua_pushfstring(lua, "%s: %s\\%s", info.error ? info.error : "enum registry keys failed", rootkey, rootdir); } } while (0); // ok? - if (ok) - { + if (ok) { lua_pushinteger(lua, count); return 1; - } - else return 2; + } else + return 2; } - diff --git a/core/src/xmake/winos/registry_query.c b/core/src/xmake/winos/registry_query.c index d494a6db9..23fda76ff 100644 --- a/core/src/xmake/winos/registry_query.c +++ b/core/src/xmake/winos/registry_query.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "registry_query" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "registry_query" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -34,7 +34,8 @@ * types */ // the RegGetValueW func type -typedef BOOL (WINAPI* xm_RegGetValueW_t)(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData); +typedef BOOL(WINAPI *xm_RegGetValueW_t)( + HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData); /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -44,38 +45,44 @@ typedef BOOL (WINAPI* xm_RegGetValueW_t)(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lp * * local value, errors = winos.registry_query("HKEY_LOCAL_MACHINE", "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", "Debugger") */ -tb_int_t xm_winos_registry_query(lua_State* lua) -{ +tb_int_t xm_winos_registry_query(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the arguments - tb_char_t const* rootkey = luaL_checkstring(lua, 1); - tb_char_t const* rootdir = luaL_checkstring(lua, 2); - tb_char_t const* valuename = luaL_checkstring(lua, 3); + tb_char_t const *rootkey = luaL_checkstring(lua, 1); + tb_char_t const *rootdir = luaL_checkstring(lua, 2); + tb_char_t const *valuename = luaL_checkstring(lua, 3); tb_check_return_val(rootkey && rootdir && valuename, 0); // query key-value - tb_bool_t ok = tb_false; - HKEY key = tb_null; - HKEY keynew = tb_null; - tb_char_t* value = tb_null; - tb_wchar_t* value_w = tb_null; + tb_bool_t ok = tb_false; + HKEY key = tb_null; + HKEY keynew = tb_null; + tb_char_t *value = tb_null; + tb_wchar_t *value_w = tb_null; tb_size_t value_n = (tb_size_t)-1; - do - { + 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 - { + 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 { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey: %s", rootkey); break; @@ -83,8 +90,7 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // 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) - { + 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; @@ -92,8 +98,7 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // 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) - { + 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; @@ -101,22 +106,21 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // attempt to load RegGetValueW static xm_RegGetValueW_t s_RegGetValueW = tb_null; - if (!s_RegGetValueW) - { + 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_RegGetValueW = (xm_RegGetValueW_t)tb_dynamic_func(module, "RegGetValueW"); + if (!module) + module = tb_dynamic_init("advapi32.dll"); + if (module) + s_RegGetValueW = (xm_RegGetValueW_t)tb_dynamic_func(module, "RegGetValueW"); } // get registry value DWORD type = 0; - if (s_RegGetValueW) - { + if (s_RegGetValueW) { // get registry value size DWORD valuesize_w = 0; - if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, 0, tb_null, &valuesize_w) != ERROR_SUCCESS) - { + if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, 0, tb_null, &valuesize_w) != ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value size failed: %s\\%s;%s", rootkey, rootdir, valuename); break; @@ -124,34 +128,32 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // make value buffer DWORD valuesize = valuesize_w * 2; - value = (tb_char_t*)tb_malloc0(valuesize); + value = (tb_char_t *)tb_malloc0(valuesize); tb_assert_and_check_break(value); - value_w = (tb_wchar_t*)tb_malloc0(valuesize_w); + value_w = (tb_wchar_t *)tb_malloc0(valuesize_w); tb_assert_and_check_break(value_w); // get value result, we attempt to do not expand value if get failed type = 0; - if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, &type, (PVOID)value_w, &valuesize_w) != ERROR_SUCCESS && - s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY | RRF_NOEXPAND, &type, (PVOID)value_w, &valuesize_w) != ERROR_SUCCESS) - { + if (s_RegGetValueW(key, rootdir_w, valuename_w, RRF_RT_ANY, &type, (PVOID)value_w, &valuesize_w) != + ERROR_SUCCESS && + s_RegGetValueW( + key, rootdir_w, valuename_w, RRF_RT_ANY | RRF_NOEXPAND, &type, (PVOID)value_w, &valuesize_w) != + ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value failed: %s\\%s;%s", rootkey, rootdir, valuename); break; } - + value_n = tb_wtoa(value, value_w, valuesize); - if (value_n == (tb_size_t)-1) - { + if (value_n == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "wtoa registry value failed: %s\\%s;%s", rootkey, rootdir, valuename); break; } - } - else - { + } else { // open registry key - if (RegOpenKeyExW(key, rootdir_w, 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); break; @@ -159,8 +161,7 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // get registry value size DWORD valuesize_w = 0; - if (RegQueryValueExW(keynew, valuename_w, tb_null, tb_null, tb_null, &valuesize_w) != ERROR_SUCCESS) - { + if (RegQueryValueExW(keynew, valuename_w, tb_null, tb_null, tb_null, &valuesize_w) != ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value size failed: %s\\%s;%s", rootkey, rootdir, valuename); break; @@ -168,23 +169,21 @@ tb_int_t xm_winos_registry_query(lua_State* lua) // make value buffer DWORD valuesize = valuesize_w * 2; - value = (tb_char_t*)tb_malloc0(valuesize); + value = (tb_char_t *)tb_malloc0(valuesize); tb_assert_and_check_break(value); - value_w = (tb_wchar_t*)tb_malloc0(valuesize_w); + value_w = (tb_wchar_t *)tb_malloc0(valuesize_w); tb_assert_and_check_break(value_w); // get value result type = 0; - if (RegQueryValueExW(keynew, valuename_w, tb_null, &type, (LPBYTE)value_w, &valuesize_w) != ERROR_SUCCESS) - { + if (RegQueryValueExW(keynew, valuename_w, tb_null, &type, (LPBYTE)value_w, &valuesize_w) != ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value failed: %s\\%s;%s", rootkey, rootdir, valuename); break; } value_n = tb_wtoa(value, value_w, valuesize); - if (value_n == (tb_size_t)-1) - { + if (value_n == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "wtoa registry value failed: %s\\%s;%s", rootkey, rootdir, valuename); break; @@ -192,19 +191,18 @@ tb_int_t xm_winos_registry_query(lua_State* lua) } // save result - switch (type) - { + switch (type) { case REG_SZ: case REG_EXPAND_SZ: lua_pushlstring(lua, value, value_n); ok = tb_true; break; case REG_DWORD: - lua_pushfstring(lua, "%d", *((tb_int_t*)value)); + lua_pushfstring(lua, "%d", *((tb_int_t *)value)); ok = tb_true; break; case REG_QWORD: - lua_pushfstring(lua, "%lld", *((tb_int64_t*)value)); + lua_pushfstring(lua, "%lld", *((tb_int64_t *)value)); ok = tb_true; break; default: @@ -221,11 +219,13 @@ tb_int_t xm_winos_registry_query(lua_State* lua) keynew = tb_null; // exit value - if (value) tb_free(value); + if (value) + tb_free(value); value = tb_null; - if (value_w) tb_free(value_w); + if (value_w) + tb_free(value_w); value_w = tb_null; // ok? - return ok? 1 : 2; + return ok ? 1 : 2; } diff --git a/core/src/xmake/winos/registry_values.c b/core/src/xmake/winos/registry_values.c index 7ce8ada10..1f72d978b 100644 --- a/core/src/xmake/winos/registry_values.c +++ b/core/src/xmake/winos/registry_values.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "registry_values" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "registry_values" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -42,54 +42,69 @@ * return true -- continue or break * end) */ -tb_int_t xm_winos_registry_values(lua_State* lua) -{ +tb_int_t xm_winos_registry_values(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the arguments - tb_char_t const* rootkey = luaL_checkstring(lua, 1); - tb_char_t const* rootdir = luaL_checkstring(lua, 2); - tb_bool_t is_function = lua_isfunction(lua, 3); + tb_char_t const *rootkey = luaL_checkstring(lua, 1); + tb_char_t const *rootdir = luaL_checkstring(lua, 2); + tb_bool_t is_function = lua_isfunction(lua, 3); tb_check_return_val(rootkey && rootdir && is_function, 0); // enum values - tb_bool_t ok = tb_false; - tb_int_t count = 0; - HKEY key = tb_null; - HKEY keynew = tb_null; - do - { + tb_bool_t ok = tb_false; + tb_int_t count = 0; + HKEY key = tb_null; + HKEY keynew = 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 - { + 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 { lua_pushnil(lua); lua_pushfstring(lua, "invalid registry rootkey: %s", rootkey); break; } // open registry key - if (RegOpenKeyExA(key, rootdir, 0, KEY_QUERY_VALUE, &keynew) != ERROR_SUCCESS && keynew) - { + if (RegOpenKeyExA(key, rootdir, 0, KEY_QUERY_VALUE, &keynew) != ERROR_SUCCESS && keynew) { lua_pushnil(lua); lua_pushfstring(lua, "open registry key failed: %s\\%s", rootkey, rootdir); break; } // query values - DWORD value_name_num = 0; + DWORD value_name_num = 0; DWORD value_name_maxn = 0; - if (RegQueryInfoKeyW(keynew, tb_null, tb_null, tb_null, tb_null, tb_null, tb_null, &value_name_num, &value_name_maxn, tb_null, tb_null, tb_null) != ERROR_SUCCESS) - { + if (RegQueryInfoKeyW(keynew, + tb_null, + tb_null, + tb_null, + tb_null, + tb_null, + tb_null, + &value_name_num, + &value_name_maxn, + tb_null, + tb_null, + tb_null) != ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "query registry info failed: %s\\%s", rootkey, rootdir); break; @@ -98,23 +113,21 @@ tb_int_t xm_winos_registry_values(lua_State* lua) // ensure enough value name buffer tb_wchar_t value_name[1024]; - if (value_name_maxn > tb_arrayn(value_name)) - { + if (value_name_maxn > tb_arrayn(value_name)) { lua_pushnil(lua); lua_pushfstring(lua, "no enough value name buffer: %s\\%s", rootkey, rootdir); break; } // get all values - DWORD i = 0; + DWORD i = 0; tb_char_t value_name_a[1024]; - for (i = 0; i < value_name_num; i++) - { + for (i = 0; i < value_name_num; i++) { // get value name - value_name[0] = L'\0'; + value_name[0] = L'\0'; DWORD value_name_size = tb_arrayn(value_name); - if (RegEnumValueW(keynew, i, value_name, &value_name_size, tb_null, tb_null, tb_null, tb_null) != ERROR_SUCCESS) - { + if (RegEnumValueW(keynew, i, value_name, &value_name_size, tb_null, tb_null, tb_null, tb_null) != + ERROR_SUCCESS) { lua_pushnil(lua); lua_pushfstring(lua, "get registry value name(%d) failed: %s\\%s", i, rootkey, rootdir); break; @@ -122,8 +135,7 @@ tb_int_t xm_winos_registry_values(lua_State* lua) // get value name (mbs) tb_size_t value_name_a_size = tb_wtoa(value_name_a, value_name, sizeof(value_name_a)); - if (value_name_a_size == -1) - { + if (value_name_a_size == -1) { lua_pushnil(lua); lua_pushfstring(lua, "convert registry value name(%d) failed: %s\\%s", i, rootkey, rootdir); break; @@ -138,8 +150,7 @@ tb_int_t xm_winos_registry_values(lua_State* lua) // is continue? tb_bool_t is_continue = lua_toboolean(lua, -1); lua_pop(lua, 1); - if (!is_continue) - { + if (!is_continue) { ok = tb_true; break; } @@ -157,10 +168,9 @@ tb_int_t xm_winos_registry_values(lua_State* lua) keynew = tb_null; // ok? - if (ok) - { + if (ok) { lua_pushinteger(lua, count); return 1; - } - else return 2; + } else + return 2; } diff --git a/core/src/xmake/winos/short_path.c b/core/src/xmake/winos/short_path.c index 5812a20da..5c6e20b30 100644 --- a/core/src/xmake/winos/short_path.c +++ b/core/src/xmake/winos/short_path.c @@ -22,8 +22,8 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * trace */ -#define TB_TRACE_MODULE_NAME "short_path" -#define TB_TRACE_MODULE_DEBUG (0) +#define TB_TRACE_MODULE_NAME "short_path" +#define TB_TRACE_MODULE_DEBUG (0) /* ////////////////////////////////////////////////////////////////////////////////////// * includes @@ -38,19 +38,17 @@ * * local short_path, errors = winos.short_path(long_path) */ -tb_int_t xm_winos_short_path(lua_State* lua) -{ +tb_int_t xm_winos_short_path(lua_State *lua) { // check tb_assert_and_check_return_val(lua, 0); // get the arguments - tb_char_t const* long_path = luaL_checkstring(lua, 1); + tb_char_t const *long_path = luaL_checkstring(lua, 1); tb_check_return_val(long_path, 0); // convert long path to wide characters tb_wchar_t long_path_w[TB_PATH_MAXN]; - if (tb_atow(long_path_w, long_path, TB_PATH_MAXN) == (tb_size_t)-1) - { + if (tb_atow(long_path_w, long_path, TB_PATH_MAXN) == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "invalid long path: %s", long_path); return 2; @@ -58,18 +56,16 @@ tb_int_t xm_winos_short_path(lua_State* lua) // get short path tb_wchar_t short_path_w[TB_PATH_MAXN]; - if (GetShortPathNameW(long_path_w, short_path_w, TB_PATH_MAXN) == 0) - { + if (GetShortPathNameW(long_path_w, short_path_w, TB_PATH_MAXN) == 0) { lua_pushnil(lua); lua_pushfstring(lua, "cannot get short path from: %s", long_path); return 2; } // return result - tb_char_t* short_path_a = (tb_char_t*)long_path_w; + tb_char_t *short_path_a = (tb_char_t *)long_path_w; tb_size_t short_path_n = tb_wtoa(short_path_a, short_path_w, TB_PATH_MAXN); - if (short_path_n == (tb_size_t)-1) - { + if (short_path_n == (tb_size_t)-1) { lua_pushnil(lua); lua_pushfstring(lua, "invalid short path from %s!", long_path); return 2; |
