Module: Device::Library::Windows

Defined in:
lib/device/library/windows.rb,
lib/device/library/windows/eject.rb

Instance Method Summary collapse

Instance Method Details

#drivesObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/device/library/windows.rb', line 28

def drives
  result = []
  bits = WinAPI.GetLogicalDrives
  26.times do |i|
    if bits & (1 << i) != 0
      result << "#{(65 + i).chr}:\\"
    end
  end
  result
end

#eject(volume_name) ⇒ Object



12
13
14
15
16
17
# File 'lib/device/library/windows/eject.rb', line 12

def eject(volume_name)
  device_root = get_device_root_dir(volume_name)
  unless ejectVolume(device_root)
    raise Device::CantEject, "端末を取り外せませんでした"
  end
end

#get_device_root_dir(volume_name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/device/library/windows.rb', line 16

def get_device_root_dir(volume_name)
  @@FileSystemObject ||= WIN32OLE.new("Scripting.FileSystemObject")
  drives.each do |drive_letter|
    drive_info = @@FileSystemObject.GetDrive(drive_letter)
    vol = drive_info.VolumeName rescue ""
    if vol.casecmp(volume_name) == 0
      return File.expand_path(drive_letter)
    end
  end
  nil
end