Skip to content

Commit ff97184

Browse files
committed
Integrate read_s and read_s_expand with get_item_property for Win32::Registry
1 parent 720e250 commit ff97184

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

ext/win32/resolv/lib/resolv.rb

+3-11
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@ def read_s(key)
6767
class << self
6868
private
6969
def get_hosts_dir
70-
if defined?(Win32::Registry)
71-
Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg|
72-
reg.read_s_expand('DataBasePath')
73-
end
74-
else
75-
cmd = "Get-ItemProperty -Path 'HKLM:\\#{TCPIP_NT}' -Name 'DataBasePath' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty DataBasePath"
76-
output, _ = Open3.capture2('powershell', '-Command', cmd)
77-
output.strip
78-
end
70+
get_item_property(TCPIP_NT, 'DataBasePath', expand: true)
7971
end
8072

8173
def get_info
@@ -134,10 +126,10 @@ def get_info
134126
[ search.uniq, nameserver.uniq ]
135127
end
136128

137-
def get_item_property(path, name)
129+
def get_item_property(path, name, expand: false)
138130
if defined?(Win32::Registry)
139131
Registry::HKEY_LOCAL_MACHINE.open(path) do |reg|
140-
reg.read_s(key)
132+
expand ? reg.read_s_expand(name) : reg.read_s(name)
141133
rescue Registry::Error
142134
""
143135
end

0 commit comments

Comments
 (0)