From 4b5bcba2e28b367f851bd21fbcd828f5e21a2f43 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 4 Feb 2025 17:32:51 +0900 Subject: [PATCH] Integrate read_s and read_s_expand with get_item_property for Win32::Registry --- ext/win32/lib/win32/resolv.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/ext/win32/lib/win32/resolv.rb b/ext/win32/lib/win32/resolv.rb index 0ea09ba82e7972..aaa98914561926 100644 --- a/ext/win32/lib/win32/resolv.rb +++ b/ext/win32/lib/win32/resolv.rb @@ -67,15 +67,7 @@ def read_s(key) class << self private def get_hosts_dir - if defined?(Win32::Registry) - Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| - reg.read_s_expand('DataBasePath') - end - else - cmd = "Get-ItemProperty -Path 'HKLM:\\#{TCPIP_NT}' -Name 'DataBasePath' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty DataBasePath" - output, _ = Open3.capture2('powershell', '-Command', cmd) - output.strip - end + get_item_property(TCPIP_NT, 'DataBasePath', expand: true) end def get_info @@ -134,10 +126,10 @@ def get_info [ search.uniq, nameserver.uniq ] end - def get_item_property(path, name) + def get_item_property(path, name, expand: false) if defined?(Win32::Registry) Registry::HKEY_LOCAL_MACHINE.open(path) do |reg| - reg.read_s(key) + expand ? reg.read_s_expand(name) : reg.read_s(name) rescue Registry::Error "" end