Top Level Namespace

Defined Under Namespace

Modules: Qdumpfs, QdumpfsFind, QdumpfsUtils Classes: File

Constant Summary collapse

CreateHardLinkA =
Win32API.new("kernel32", "CreateHardLinkA", "ppl", 'i')
GetVolumeInformation =
Win32API.new("kernel32", "GetVolumeInformation", "PPLPPPPL", "I")
GetLocaltime =
Win32API.new("kernel32", "GetLocalTime", "P", 'V')
SystemTimeToFileTime =
Win32API.new("kernel32", "SystemTimeToFileTime", "PP", 'I')
GENERIC_WRITE =
0x40000000
OPEN_EXISTING =
3
FILE_FLAG_BACKUP_SEMANTICS =
0x02000000
CreateFile =
Win32API.new("kernel32", "CreateFileA","PLLLLLL", "L")
SetFileTime =
Win32API.new("kernel32", "SetFileTime", "LPPP", "I")
CloseHandle =
Win32API.new("kernel32", "CloseHandle", "L", "I")
LOCALE_USER_DEFAULT =
0x400
LOCALE_SABBREVLANGNAME =
3
LOCALE_USE_CP_ACP =
0x40000000
GetLocaleInfo =
Win32API.new("kernel32", "GetLocaleInfo", "IIPI", "I")
SW_HIDE =
0
SW_SHOWNORMAL =
1
ShellExecute =
Win32API.new("shell32",  "ShellExecute", "LPPPPL", 'L')
LoadIcon =
Win32API.new("user32",   "LoadIcon", "II", "I")
GetModuleFileName =
Win32API.new("kernel32", "GetModuleFileName","IPI","I")

Instance Method Summary collapse

Instance Method Details

#expand_special_folders(dir) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# 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_nameObject



120
121
122
123
124
# 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) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object



40
41
42
43
44
45
46
47
48
# 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_nameObject



101
102
103
104
105
106
107
108
109
110
111
# 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_directoryObject



135
136
137
138
# 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_nameObject



126
127
128
129
130
131
132
133
# 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

#initObject



140
141
142
143
# File 'lib/qdumpfs/win32.rb', line 140

def init
  locale_name = get_locale_name
  #    $KCODE = "SJIS" if locale_name == "JPN"
end

#ntfs?(dir) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/qdumpfs/win32.rb', line 50

def ntfs?(dir)
  get_filesystem_type(dir) == "NTFS"
end

#which(cmd) ⇒ Object

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


9
10
11
12
13
14
15
16
17
18
# File 'lib/qdumpfs/util.rb', line 9

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?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/qdumpfs/win32.rb', line 3

def windows?
  /mswin32|cygwin|mingw|bccwin/.match(RUBY_PLATFORM)
end

#wprintf(format, *args) ⇒ Object



1
2
3
# File 'lib/qdumpfs/util.rb', line 1

def wprintf(format, *args)
  STDERR.printf("pdumpfs: " + format + "\n", *args)
end