Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread
Message: 95609
BY: Clifford Caoile (piyo)
DATE: 2010-12-28 14:30
SUBJECT: win32-dir fails on Japanese (resolution?)

 

Hi, I use win32 stuff and it's great.

I'd like to make a suggestion for win32-dir. 0.3.7 seems to able to not finish "require" when using with Ruby 1.9.x on Windows XP Japanese. I suspect the SHGetFileInfo is returning a string in ANSI (MS-Windows31J, in my case), and the following string manipulation fails because the encoding is unexpected.

I fix it by forcing the string to be reinterpreted as a ANSI string.

--- a/lib/win32/dir.rb
+++ b/lib/win32/dir.rb
@@ -51,7 +51,17 @@ class Dir
info = 0.chr * 692 # sizeof(SHFILEINFO)
flags = SHGFI_DISPLAYNAME | SHGFI_PIDL
SHGetFileInfo(ppidl.unpack('L')[0], 0, info, 692, flags)
- path = info[12..-1].strip
+ newpath = info[12..-1]
+ if !newpath.ascii_only?
+ newpath.force_encoding($>.external_encoding || Encoding.default_external)
+ end
+ path = newpath.strip
end
end

However I am unsure if this is the correct way to fix it. It Works On My Machine (tm).


Thread View

Thread Author Date
win32-dir fails on Japanese (resolution?)Clifford Caoile2010-12-28 14:30

Post a followup to this message