Module: PDK::Util::Windows::File

Extended by:
FFI::Library, String
Defined in:
lib/pdk/util/windows.rb,
lib/pdk/util/windows/file.rb

Class Method Summary collapse

Methods included from String

wide_string

Class Method Details

.get_long_pathname(path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pdk/util/windows/file.rb', line 8

def get_long_pathname(path)
  converted = ''
  FFI::Pointer.from_string_to_wide_string(path) do |path_ptr|
    # includes terminating NULL
    buffer_size = GetLongPathNameW(path_ptr, FFI::Pointer::NULL, 0)
    FFI::MemoryPointer.new(:wchar, buffer_size) do |converted_ptr|
      if GetLongPathNameW(path_ptr, converted_ptr, buffer_size) == PDK::Util::Windows::WIN32_FALSE
        raise _('Failed to call GetLongPathName')
      end

      converted = converted_ptr.read_wide_string(buffer_size - 1)
    end
  end

  converted
end