Class: Win32::Registry
- Inherits:
-
Object
- Object
- Win32::Registry
- Defined in:
- lib/chef/monkey_patches/win32/registry.rb
Defined Under Namespace
Modules: API
Instance Method Summary collapse
-
#export_string(str, enc = Encoding.default_internal || "utf-8") ⇒ Object
::Win32::Registry#export_string is used when enumerating child keys and values and re encodes a UTF-16LE to the local codepage.
-
#write(name, type, data) ⇒ Object
::Win32::Registry#write does not correctly handle data in Ruby 2.1 This bug is reportedly resolved in Ruby 2.1.7 and 2.2.3 but fails in appveyor on 2.1.8 unless we keep applying this monkeypatch bugs.ruby-lang.org/issues/11439.
Instance Method Details
#export_string(str, enc = Encoding.default_internal || "utf-8") ⇒ Object
::Win32::Registry#export_string is used when enumerating child keys and values and re encodes a UTF-16LE to the local codepage. This can result in encoding incompatibilities if the native codepage does not support the characters in the registry. There is an open bug in ruby at bugs.ruby-lang.org/issues/11410. Rather than converting the UTF-16LE originally returned by the win32 api, we encode to UTF-8 which will likely not result in any conversion error.
32 33 34 |
# File 'lib/chef/monkey_patches/win32/registry.rb', line 32 def export_string(str, enc = Encoding.default_internal || "utf-8") str.encode(enc) end |
#write(name, type, data) ⇒ Object
::Win32::Registry#write does not correctly handle data in Ruby 2.1 This bug is reportedly resolved in Ruby 2.1.7 and 2.2.3 but fails in appveyor on 2.1.8 unless we keep applying this monkeypatch bugs.ruby-lang.org/issues/11439
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chef/monkey_patches/win32/registry.rb', line 65 def write(name, type, data) case type when REG_SZ, REG_EXPAND_SZ data = data.to_s.encode(WCHAR) + WCHAR_NUL when REG_MULTI_SZ data = data.to_a.map { |s| s.encode(WCHAR) }.join(WCHAR_NUL) << WCHAR_NUL << WCHAR_NUL when REG_BINARY data = data.to_s when REG_DWORD data = API.packdw(data.to_i) when REG_DWORD_BIG_ENDIAN data = [data.to_i].pack("N") when REG_QWORD data = API.packqw(data.to_i) else raise TypeError, "Unsupported type #{type}" end API.SetValue(@hkey, name, type, data, data.bytesize) end |