Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use /**/ in Windows registry string? #1032

Closed
xq114 opened this issue Nov 13, 2020 · 11 comments
Closed

Can I use /**/ in Windows registry string? #1032

xq114 opened this issue Nov 13, 2020 · 11 comments

Comments

@xq114
Copy link
Contributor

xq114 commented Nov 13, 2020

描述讨论详情

目前在Windows下找注册表项只能是用"$(reg PATH;NAME)"的形式,能否在PATH或者NAME中加通配符("%.","**|d"这样的)?

使用场景:自定义find_package时需要找已安装的软件,然而这个软件在注册表中的形式是"XXX 18.x.x.x"这样的,导致无法使用完整路径匹配。在path中加通配符后发现find_path找不到目录了。

@waruqi
Copy link
Member

waruqi commented Nov 13, 2020

这块是可以改进,但是需要花时间改造现有 https://github.com/xmake-io/xmake/blob/master/core/src/xmake/winos/registry_query.c 的实现,加上 lua 的 模式匹配,我暂时没时间去看这块,即使要支持,也要等 2.3.9 之后的下一个版本了

当前 2.3.9 版本,我快要发版了,目前不考虑加新特性和改进了,只解决稳定性问题

@waruqi waruqi added this to the v2.5.1 milestone Nov 13, 2020
@waruqi
Copy link
Member

waruqi commented Dec 26, 2020

我支持上了,你可以看下这个:#1162

通过 winos.registry_keys 模式匹配获取需要的 key path 列表,如果 keypath 固定,仅仅想模式匹配 value 名,可以用 winos.registry_values 获取匹配的值路径

获取到对应 keypath 和 value name 后,就可以用 winos.registry_query 获取实际的 value 值

local keypaths = winos.registry_keys("HKEY_LOCAL_MACHINE\\SOFTWARE\\*\\Windows NT\\*\\CurrentVersion\\AeDebug")
for _, keypath in ipairs(keypaths) do
    print(winos.registry_query(keypath .. ";Debugger"))
end

local valuepaths = winos.registry_values("HKEY_LOCAL_MACHINE\\SOFTWARE\\xx\\AeDebug;Debug*")
for _, valuepath in ipairs(valuepaths) do
    print(winos.registry_query(valuepath))
end

winos.registry_values主要用于匹配 ;xxx* 的值名,获取全路径列表,winos.registry_keys 可以用于匹配前面的 key 路径,支持 ** 递归匹配,但通常建议只做 *\\xx\\*\\xxx 单级匹配,递归层级太多,会影响效率

@waruqi waruqi closed this as completed Dec 26, 2020
@xq114
Copy link
Contributor Author

xq114 commented Jan 4, 2021

我发现这个方法可以成功访问到REG_SZ类型和REG_DWORD类型,但对REG_EXPAND_SZ类型无效,报错

get registry value failed: HKEY_LOCAL_MACHINE\SOFTWARE\LunarG\VulkanSDK;VK_SDK_PATHs

@waruqi waruqi reopened this Jan 6, 2021
@waruqi
Copy link
Member

waruqi commented Jan 6, 2021

我回头看下

@waruqi
Copy link
Member

waruqi commented Jan 6, 2021

你是指哪个接口? 我 query/values试了下,都可以的么,没啥问题

Snip20210106_16

@xq114
Copy link
Contributor Author

xq114 commented Jan 7, 2021

image

好像REG_EXPAND_SZ也不一定出错

@waruqi
Copy link
Member

waruqi commented Jan 7, 2021

那就不知道了,看了下,REG_EXPAND_SZ 的值里面带有 %xx% 的,可以正常查到,如果没带 %xx%,纯文本,就会失败,具体为啥我也不清楚

https://github.com/xmake-io/xmake/blob/master/core/src/xmake/winos/registry_query.c

@waruqi
Copy link
Member

waruqi commented Jan 7, 2021

我改了下 你再试试

@xq114
Copy link
Contributor Author

xq114 commented Jan 7, 2021

https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-reggetvaluea

type = 0;
if (s_RegGetValueA(key, rootdir, valuename, RRF_RT_ANY, &type, (PVOID)value, &valuesize) != ERROR_SUCCESS)
{
lua_pushnil(lua);
lua_pushfstring(lua, "get registry value failed: %s\\%s;%s", rootkey, rootdir, valuename);
break;
}

我觉得这里应该是expand的时候失败了,失败之后再试一次

s_RegGetValueA(key, rootdir, valuename, RRF_RT_ANY | RRF_NO_EXPAND, &type, (PVOID)value, &valuesize)

可能就好了

@waruqi
Copy link
Member

waruqi commented Jan 7, 2021

https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-reggetvaluea

type = 0;
if (s_RegGetValueA(key, rootdir, valuename, RRF_RT_ANY, &type, (PVOID)value, &valuesize) != ERROR_SUCCESS)
{
lua_pushnil(lua);
lua_pushfstring(lua, "get registry value failed: %s\\%s;%s", rootkey, rootdir, valuename);
break;
}

我觉得这里应该是expand的时候失败了,失败之后再试一次

s_RegGetValueA(key, rootdir, valuename, RRF_RT_ANY | RRF_NO_EXPAND, &type, (PVOID)value, &valuesize)

可能就好了

已经改了

@xq114
Copy link
Contributor Author

xq114 commented Jan 7, 2021

现在可以了

@xq114 xq114 closed this as completed Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants