1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/dl/win32/lib/win32/registry.rb (Win32::Registry.expand_environ):

use suitable encoding for the string.  fixed a test-all error of
  r41838.

* ext/fiddle/win32/lib/win32/registry.rb: same changes of r41838 and
  this revision of dl's win32/registry.rb.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2013-07-09 00:49:44 +00:00
parent 7083cebeae
commit d9726121e5
3 changed files with 46 additions and 27 deletions

View file

@ -1,3 +1,12 @@
Tue Jul 9 09:46:53 2013 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/dl/win32/lib/win32/registry.rb (Win32::Registry.expand_environ):
use suitable encoding for the string. fixed a test-all error of
r41838.
* ext/fiddle/win32/lib/win32/registry.rb: same changes of r41838 and
this revision of dl's win32/registry.rb.
Tue Jul 9 07:39:45 2013 Eric Hodel <drbrain@segment7.net>
* lib/rubygems: Update to RubyGems 2.0.4. See

View file

@ -340,7 +340,7 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
# For detail, see expandEnvironmentStrings[http://msdn.microsoft.com/library/en-us/sysinfo/base/expandenvironmentstrings.asp] \Win32 \API.
#
def self.expand_environ(str)
str.gsub(/%([^%]+)%/) { ENV[$1] || ENV[$1.upcase] || $& }
str.gsub(Regexp.compile("%([^%]+)%".encode(str.encoding))) { ENV[$1] || ENV[$1.upcase] || $& }
end
@@type2name = { }

View file

@ -63,6 +63,10 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
=end rdoc
WCHAR = Encoding::UTF_16LE
WCHAR_SPACE = "\0".encode(WCHAR).freeze
LOCALE = Encoding.find(Encoding.locale_charmap)
class Registry
#
@ -164,12 +168,12 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
extend Fiddle::Importer
dlload "kernel32.dll"
end
FormatMessageA = Kernel32.extern "int FormatMessageA(int, void *, int, int, void *, int, void *)", :stdcall
FormatMessageW = Kernel32.extern "int FormatMessageW(int, void *, int, int, void *, int, void *)", :stdcall
def initialize(code)
@code = code
msg = "\0".force_encoding(Encoding::ASCII_8BIT) * 1024
len = FormatMessageA.call(0x1200, 0, code, 0, msg, 1024, 0)
msg = msg[0, len].force_encoding(Encoding.find(Encoding.locale_charmap))
msg = WCHAR_SPACE * 1024
len = FormatMessageW.call(0x1200, 0, code, 0, msg, 1024, 0)
msg = msg[0, len].encode
super msg.tr("\r", '').chomp
end
attr_reader :code
@ -209,12 +213,12 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
extend Fiddle::Importer
dlload "advapi32.dll"
[
"long RegOpenKeyExA(void *, void *, long, long, void *)",
"long RegCreateKeyExA(void *, void *, long, long, long, long, void *, void *, void *)",
"long RegEnumValueA(void *, long, void *, void *, void *, void *, void *, void *)",
"long RegEnumKeyExA(void *, long, void *, void *, void *, void *, void *, void *)",
"long RegQueryValueExA(void *, void *, void *, void *, void *, void *)",
"long RegSetValueExA(void *, void *, long, long, void *, long)",
"long RegOpenKeyExW(void *, void *, long, long, void *)",
"long RegCreateKeyExW(void *, void *, long, long, long, long, void *, void *, void *)",
"long RegEnumValueW(void *, long, void *, void *, void *, void *, void *, void *)",
"long RegEnumKeyExW(void *, long, void *, void *, void *, void *, void *, void *)",
"long RegQueryValueExW(void *, void *, void *, void *, void *, void *)",
"long RegSetValueExW(void *, void *, long, long, void *, long)",
"long RegDeleteValue(void *, void *)",
"long RegDeleteKey(void *, void *)",
"long RegFlushKey(void *)",
@ -251,52 +255,58 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
def OpenKey(hkey, name, opt, desired)
result = packdw(0)
check RegOpenKeyExA.call(hkey, name, opt, desired, result)
check RegOpenKeyExW.call(hkey, name.encode(WCHAR), opt, desired, result)
unpackdw(result)
end
def CreateKey(hkey, name, opt, desired)
result = packdw(0)
disp = packdw(0)
check RegCreateKeyExA.call(hkey, name, 0, 0, opt, desired,
check RegCreateKeyExW.call(hkey, name.encode(WCHAR), 0, 0, opt, desired,
0, result, disp)
[ unpackdw(result), unpackdw(disp) ]
end
def EnumValue(hkey, index)
name = ' ' * Constants::MAX_KEY_LENGTH
name = WCHAR_SPACE * Constants::MAX_KEY_LENGTH
size = packdw(Constants::MAX_KEY_LENGTH)
check RegEnumValueA.call(hkey, index, name, size, 0, 0, 0, 0)
name[0, unpackdw(size)]
check RegEnumValueW.call(hkey, index, name, size, 0, 0, 0, 0)
name[0, unpackdw(size)].encode
end
def EnumKey(hkey, index)
name = ' ' * Constants::MAX_KEY_LENGTH
name = WCHAR_SPACE * Constants::MAX_KEY_LENGTH
size = packdw(Constants::MAX_KEY_LENGTH)
wtime = ' ' * 8
check RegEnumKeyExA.call(hkey, index, name, size, 0, 0, 0, wtime)
[ name[0, unpackdw(size)], unpackqw(wtime) ]
check RegEnumKeyExW.call(hkey, index, name, size, 0, 0, 0, wtime)
[ name[0, unpackdw(size)].encode, unpackqw(wtime) ]
end
def QueryValue(hkey, name)
type = packdw(0)
size = packdw(0)
check RegQueryValueExA.call(hkey, name, 0, type, 0, size)
data = ' ' * unpackdw(size)
check RegQueryValueExA.call(hkey, name, 0, type, data, size)
[ unpackdw(type), data[0, unpackdw(size)] ]
name = name.encode(WCHAR)
check RegQueryValueExW.call(hkey, name, 0, type, 0, size)
data = WCHAR_SPACE * unpackdw(size)
check RegQueryValueExW.call(hkey, name, 0, type, data, size)
[ unpackdw(type), data[0, unpackdw(size)].encode ]
end
def SetValue(hkey, name, type, data, size)
check RegSetValueExA.call(hkey, name, 0, type, data, size)
case type
when REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ
data = data.encode(WCHAR)
size ||= data.size + 1
end
check RegSetValueExW.call(hkey, name.encode(WCHAR), 0, type, data, size)
end
def DeleteValue(hkey, name)
check RegDeleteValue.call(hkey, name)
check RegDeleteValue.call(hkey, name.encode(WCHAR))
end
def DeleteKey(hkey, name)
check RegDeleteKey.call(hkey, name)
check RegDeleteKey.call(hkey, name.encode(WCHAR))
end
def FlushKey(hkey)
@ -330,7 +340,7 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
# For detail, see expandEnvironmentStrings[http://msdn.microsoft.com/library/en-us/sysinfo/base/expandenvironmentstrings.asp] \Win32 \API.
#
def self.expand_environ(str)
str.gsub(/%([^%]+)%/) { ENV[$1] || ENV[$1.upcase] || $& }
str.gsub(Regexp.compile("%([^%]+)%".encode(str.encoding))) { ENV[$1] || ENV[$1.upcase] || $& }
end
@@type2name = { }