diff options
| author | ruki <[email protected]> | 2020-12-26 00:47:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-12-26 00:47:01 +0800 |
| commit | 9045f4cd312de04cdfc316ba18094a036702bdfc (patch) | |
| tree | 625644f277e1ccb544afb05f94c5161a957b4503 | |
| parent | 9dd609f518388f7c62e241e7f1d5813df0ada6b1 (diff) | |
parse key path
| -rw-r--r-- | xmake/core/base/winos.lua | 48 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/winos.lua | 8 |
2 files changed, 41 insertions, 15 deletions
diff --git a/xmake/core/base/winos.lua b/xmake/core/base/winos.lua index a6498458a..2492dc76d 100644 --- a/xmake/core/base/winos.lua +++ b/xmake/core/base/winos.lua @@ -217,52 +217,78 @@ end -- get registry key paths -- --- @param pattern the search pattern +-- @param keypath the key path (support key pattern, e.g. \\a\\b;xx*yy) -- uses "*" to match any part of a key path, -- uses "**" to recurse into subkey paths. -- @return the result array and errors -- -- @code --- local keypaths, errors = winos.registry_keys("HKEY_LOCAL_MACHINE\\SOFTWARE\\*\\Windows NT\\*\\CurrentVersion\\AeDebug") --- local keypaths, errors = winos.registry_keys("HKEY_LOCAL_MACHINE\\SOFTWARE\\**") +-- local keys, errors = winos.registry_keys("HKEY_LOCAL_MACHINE\\SOFTWARE\\*\\Windows NT\\*\\CurrentVersion\\AeDebug") +-- local keys, errors = winos.registry_keys("HKEY_LOCAL_MACHINE\\SOFTWARE\\**") -- @endcode -- -function winos.registry_keys(pattern) +function winos.registry_keys(keypath) -- get rootkey, e.g. HKEY_LOCAL_MACHINE local rootkey - local p = pattern:find("\\", 1, true) + local p = keypath:find("\\", 1, true) if p then - rootkey = pattern:sub(1, p - 1) + rootkey = keypath:sub(1, p - 1) end if not rootkey then return end -- get the root directory - local rootdir = pattern:sub(p + 1) + local rootdir = keypath:sub(p + 1) p = rootdir:find("*", 1, true) if p then rootdir = path.directory(rootdir:sub(1, p - 1)) end - -- convert pattern to a lua pattern - pattern = path.pattern(pattern) + -- get key pattern with a lua pattern + local pattern = path.pattern(keypath) - -- find keys + -- get keys return winos._registry_keys(rootkey, rootdir, pattern) end -- get registry values from the given key path -- --- @param keypath the key path +-- @param keypath the key path (support value pattern, e.g. \\a\\b;xx*yy) +-- uses "*" to match value name, -- @return the values array and errors -- -- @code -- local values, errors = winos.registry_values("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug") +-- local values, errors = winos.registry_values("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debug*") -- @endcode -- function winos.registry_values(keypath) + + -- get value pattern + local splitinfo = keypath:split(';', {plain = true}) + local pattern = splitinfo[2] + if pattern then + pattern = path.pattern(pattern) + end + keypath = splitinfo[1] + + -- get rootkey, e.g. HKEY_LOCAL_MACHINE + local rootkey + local p = keypath:find("\\", 1, true) + if p then + rootkey = keypath:sub(1, p - 1) + end + if not rootkey then + return nil, "root key not found!" + end + + -- get the root directory + local rootdir = keypath:sub(p + 1) + + -- get values + return winos._registry_values(rootkey, rootdir, pattern) end -- return module: winos diff --git a/xmake/core/sandbox/modules/winos.lua b/xmake/core/sandbox/modules/winos.lua index 0a8058a75..0a0192470 100644 --- a/xmake/core/sandbox/modules/winos.lua +++ b/xmake/core/sandbox/modules/winos.lua @@ -53,12 +53,12 @@ function sandbox_winos.registry_query(keypath) end -- get registry keys -function sandbox_winos.registry_keys(pattern) - local keypaths, errors = winos.registry_keys(pattern) - if not keypaths then +function sandbox_winos.registry_keys(keypath) + local keys, errors = winos.registry_keys(keypath) + if not keys then raise(errors) end - return keypaths + return keys end -- get registry values |
