class Object

Constants

CloseHandle
CreateFile
CreateHardLinkA
FILE_FLAG_BACKUP_SEMANTICS
GENERIC_WRITE
GetLocaleInfo
GetLocaltime
GetModuleFileName
GetVolumeInformation
LOCALE_SABBREVLANGNAME
LOCALE_USER_DEFAULT
LOCALE_USE_CP_ACP
LoadIcon
OPEN_EXISTING
SW_HIDE
SW_SHOWNORMAL
SetFileTime
ShellExecute
SystemTimeToFileTime

Public Instance Methods

expand_special_folders(dir) click to toggle source
# File lib/qdumpfs/win32.rb, line 28
def expand_special_folders(dir)
  specials = %w[(?:AllUsers)?(?:Desktop|Programs|Start(?:Menu|up)) Favorites
  Fonts MyDocuments NetHood PrintHood Recent SendTo Templates]

  pattern = Regexp.compile(sprintf('^@(%s)', specials.join('|')))

  dir.sub(pattern) do |match|
    WIN32OLE.new("WScript.Shell").SpecialFolders(match)
  end.tr('\\', File::SEPARATOR)
end
get_exe_file_name() click to toggle source
# File lib/qdumpfs/win32.rb, line 120
def get_exe_file_name
  path = "\0" * 1024
  length = GetModuleFileName.call(0 ,path, path.length)
  return path[0, length].tr('\\', File::SEPARATOR)
end
get_file_time(time) click to toggle source
# File lib/qdumpfs/win32.rb, line 56
def get_file_time(time)
  pSYSTEMTIME = ' ' * 2 * 8     # 2byte x 8
  pFILETIME = ' ' * 2 * 8       # 2byte x 8

  GetLocaltime.call(pSYSTEMTIME)
  t1 = pSYSTEMTIME.unpack("S8")
  t1[0..1] = time.year, time.month
  t1[3..6] = time.day, time.hour, time.min, time.sec

  SystemTimeToFileTime.call(t1.pack("S8"), pFILETIME)

  pFILETIME
end
get_filesystem_type(path) click to toggle source
# File lib/qdumpfs/win32.rb, line 40
def get_filesystem_type(path)
  return nil unless(FileTest.exist?(path))

  drive = File.expand_path(path)[0..2]
  buff = "\0" * 1024
  GetVolumeInformation.call(drive, nil, 0, nil, nil, nil, buff, 1024)

  buff.sub(/\000+/, '')
end
get_locale_name() click to toggle source
# File lib/qdumpfs/win32.rb, line 101
def get_locale_name
  locale_name = " " * 32
  status = GetLocaleInfo.call(LOCALE_USER_DEFAULT,
  LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP,
  locale_name, 32)
  if status == 0
    return nil
  else
    return locale_name.split("\x00").first
  end
end
get_program_directory() click to toggle source
# File lib/qdumpfs/win32.rb, line 135
def get_program_directory
  program_file_name = get_program_file_name
  return File.dirname(program_file_name)
end
get_program_file_name() click to toggle source
# File lib/qdumpfs/win32.rb, line 126
def get_program_file_name
  exe_file_name = get_exe_file_name
  if File.basename(exe_file_name) == "ruby.exe"
    return File.expand_path($0).gsub('\\', File::SEPARATOR)
  else
    return exe_file_name
  end
end
init() click to toggle source
# File lib/qdumpfs/win32.rb, line 140
def init
  locale_name = get_locale_name
  #    $KCODE = "SJIS" if locale_name == "JPN"
end
ntfs?(dir) click to toggle source
# File lib/qdumpfs/win32.rb, line 50
def ntfs?(dir)
  get_filesystem_type(dir) == "NTFS"
end
which(cmd) click to toggle source

stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby

Cross-platform way of finding an executable in the $PATH.

  which('ruby') #=> /usr/bin/ruby
# File lib/qdumpfs/util.rb, line 10
def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  nil
end
windows?() click to toggle source
# File lib/qdumpfs/win32.rb, line 3
def windows?
  /mswin32|cygwin|mingw|bccwin/.match(RUBY_PLATFORM)
end
wprintf(format, *args) click to toggle source
# File lib/qdumpfs/util.rb, line 2
def wprintf(format, *args)
  STDERR.printf("pdumpfs: " + format + "\n", *args)
end