Sha256: 7f1ff12b443a6db759db1d38fa63732eb98c2617a33aa462fd322a72615ea9c3

Contents?: true

Size: 919 Bytes

Versions: 3

Compression:

Stored size: 919 Bytes

Contents

# -*- coding: utf-8 -*-
#
# Copyright 2013 whiteleaf. All rights reserved.
#

# rubocop:disable Naming/VariableName

require "win32ole"
require_relative "../../extensions/windows"
require_relative "windows/eject"

class Device
  module Library
    module Windows
      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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
narou-3.2.5.1 lib/device/library/windows.rb
narou-3.2.5 lib/device/library/windows.rb
narou-3.2.4 lib/device/library/windows.rb