[Win32utils-devel] win32-dir, unicode

Daniel Berger djberg96 at gmail.com
Fri May 26 15:12:46 EDT 2006


Heesob Park wrote:
> Hi,
> 2006/5/26, Daniel Berger <djberg96 at gmail.com>:> Hi,>> I've got a preliminary version of the pure Ruby version of win32-dir in> CVS.  However, I was hoping to work out the Unicode issue.  Run this:>> from = "C:\\test"> to = "Ελλάσ"> Dir.mkdir(from) unless File.exists?(from)> Dir.create_junction(to, from)>> It works, but my explorer (and dos) window shows the name garbled.  I> don't think it's a font encoding issue within Explorer, since I can> create a folder called "Ελλάσ" manually within Explorer and it looks> correct.>You can check whether the  folder name is whether unicode or ansi ?
> How about some modification of create_function method like this:
>   def self.create_junction(to, from,unicode=false)      # Normalize the paths      to.tr!('/', "\\")      from.tr!('/', "\\")
>       to_path    = 0.chr * 260      from_path  = 0.chr * 260      buf_target = 0.chr * 260
>       if GetFullPathName(from, from_path.size, from_path, 0) == 0         raise StandardError, 'GetFullPathName() failed: ' + get_last_error      endif unicode      if GetFullPathNameW(to, to_path.size, to_path, 0) == 0         raise StandardError, 'GetFullPathName() failed: ' + get_last_error      endelse      if GetFullPathName(to, to_path.size, to_path, 0) == 0         raise StandardError, 'GetFullPathName() failed: ' + get_last_error      endend      to_path   = to_path.split("\0\0").first      from_path = from_path.split(0.chr).first
>       # You can create a junction to a directory that already exists, so      # long as it's empty.
> if unicode      rv = CreateDirectoryW(to_path, 0)      if rv == 0 && rv != ERROR_ALREADY_EXISTS         raise StandardError, 'CreateDirectory() failed: ' + get_last_error      end
>       handle = CreateFileW(         to_path,         GENERIC_READ | GENERIC_WRITE,         0,         0,         OPEN_EXISTING,         FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS,         0      )else      rv = CreateDirectory(to_path, 0)      if rv == 0 && rv != ERROR_ALREADY_EXISTS         raise StandardError, 'CreateDirectory() failed: ' + get_last_error      end
>       handle = CreateFile(         to_path,         GENERIC_READ | GENERIC_WRITE,         0,         0,         OPEN_EXISTING,         FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS,         0      )end...end
> And call like this:from = "C:\\test"Dir.mkdir(from) unless File.exists?(from)#unicode folder nameto = "\x95\x03\xBB\x03\xBB\x03\xAC\x03\xC3\x03\0\0"  #  "Ελλάσ"Dir.create_junction(to, from,true)#ansi folder nameto = "ansi"Dir.create_junction(to, from,false)
> Regards,
> Park Heesob
> _______________________________________________
> win32utils-devel mailing list
> win32utils-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/win32utils-devel

Hi Heesob,

That came through as a single line for some reason...

Anyway, I modified the approach somewhat.  Instead of adding a 'unicode' 
flag, I altered the windows-pr package to wrap methods like this:

def CreateDirectory(path, attributes)
    if $KCODE != 'NONE'
       CreateDirectoryW.call(path, attributes) != 0
    else
       CreateDirectory.call(path, attributes) != 0
    end
end

Within dir.rb, I did this:

if $KCODE != 'NONE'
    to_path = to_path.split("\0\0").first
else
    to_path = to_path.split(0.chr).first
end

However, after making those changes I got this:

dir.rb:123:in `create_junction': DeviceIoControl() failed: The data 
present in the reparse point buffer is invalid. (RuntimeError).

Does rdb need to be packed differently?

BTW, I also tinkered with the idea of using IsTextUnicode():

def CreateDirectory(path, attributes)
    if IsTextUnicode(path, path.size, 0)
       CreateDirectoryW.call(path, attributes) != 0
    else
       CreateDirectory.call(path, attributes) != 0
    end
end

But this didn't seem to handle UCS-2, i.e it worked for 
"\x95\x03\xBB\x03\xBB\x03\xAC\x03\xC3\x03\0\0" but not "Ελλάσ".  I 
imagine it's also slower.

Regards,

Dan


More information about the win32utils-devel mailing list