Sha256: 5024b8d9330fb1efb31b09628f054e28f6f74832f35ef069ee74ba0977d10f16

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

require 'pdk/util/windows'

module PDK::Util::Windows::File
  require 'ffi'
  extend FFI::Library
  extend PDK::Util::Windows::String

  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) == FFI::WIN32_FALSE
          raise _('Failed to call GetLongPathName')
        end

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

    converted
  end
  module_function :get_long_pathname

  ffi_convention :stdcall

  # https://msdn.microsoft.com/en-us/library/windows/desktop/aa364980(v=vs.85).aspx
  # DWORD WINAPI GetLongPathName(
  #   _In_  LPCTSTR lpszShortPath,
  #   _Out_ LPTSTR  lpszLongPath,
  #   _In_  DWORD   cchBuffer
  # );
  ffi_lib :kernel32
  attach_function :GetLongPathNameW, [:lpcwstr, :lpwstr, :dword], :dword
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
pdk-1.10.0 lib/pdk/util/windows/file.rb
pdk-akerl-1.9.1.1 lib/pdk/util/windows/file.rb
pdk-1.9.1 lib/pdk/util/windows/file.rb
pdk-1.9.0 lib/pdk/util/windows/file.rb
pdk-akerl-1.8.0.1 lib/pdk/util/windows/file.rb
pdk-1.8.0 lib/pdk/util/windows/file.rb
pdk-1.7.1 lib/pdk/util/windows/file.rb