module Facter::Util::Windows::Dir

Constants

COMMON_APPDATA
MAX_PATH
S_OK

Public Class Methods

get_common_appdata() click to toggle source
# File lib/facter/util/windows/dir.rb, line 11
def get_common_appdata
  common_appdata = ''

  # this pointer actually points to a :lpwstr (pointer) since we're letting Windows allocate for us
  FFI::MemoryPointer.new(:pointer, ((MAX_PATH + 1) * 2)) do |buffer_ptr|
    # hwndOwner, nFolder, hToken, dwFlags, pszPath
    if SHGetFolderPathW(0, COMMON_APPDATA, 0, 0, buffer_ptr) != S_OK
      raise Facter::Util::Windows::Error.new("Could not find COMMON_APPDATA path")
    end

    common_appdata = Facter::Util::Windows::FFI.read_arbitrary_wide_string_up_to(buffer_ptr, MAX_PATH + 1)
  end

  common_appdata
end

Private Instance Methods

get_common_appdata() click to toggle source
# File lib/facter/util/windows/dir.rb, line 11
def get_common_appdata
  common_appdata = ''

  # this pointer actually points to a :lpwstr (pointer) since we're letting Windows allocate for us
  FFI::MemoryPointer.new(:pointer, ((MAX_PATH + 1) * 2)) do |buffer_ptr|
    # hwndOwner, nFolder, hToken, dwFlags, pszPath
    if SHGetFolderPathW(0, COMMON_APPDATA, 0, 0, buffer_ptr) != S_OK
      raise Facter::Util::Windows::Error.new("Could not find COMMON_APPDATA path")
    end

    common_appdata = Facter::Util::Windows::FFI.read_arbitrary_wide_string_up_to(buffer_ptr, MAX_PATH + 1)
  end

  common_appdata
end