Sha256: a140eb2e9972a518b70918c360390c0fb4c8e86f3f4b0703f90fe55988f04a8e

Contents?: true

Size: 966 Bytes

Versions: 5

Compression:

Stored size: 966 Bytes

Contents

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

require "dl/import"
require "win32ole"

module WinAPI
  class InvalidOS < StandardError; end
  extend DL::Importer
  begin
    dlload "kernel32"
    extern "long GetLogicalDriveStrings(long, void*)"
  rescue DL::DLError
    raise InvalidOS, "not Windows"
  end
end

module Device::Library
  module Windows
    def get_device_root_dir(volume_name)
      @@FileSystemObject ||= WIN32OLE.new("Scripting.FileSystemObject")
      drive_strings = " " * 1000
      result_len = WinAPI.GetLogicalDriveStrings(1000, drive_strings)
      drives = drive_strings[0, result_len].split("\0")
      drives.each do |drive_letter|
        drive_info = @@FileSystemObject.GetDrive(drive_letter)
        vol = drive_info.VolumeName rescue ""
        if vol == volume_name
          return File.expand_path(drive_letter)
        end
      end
      nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
narou-1.1.0.rc2 lib/device/library/windows.rb
narou-1.1.0.rc1 lib/device/library/windows.rb
narou-1.0.2 lib/device/library/windows.rb
narou-1.0.1 lib/device/library/windows.rb
narou-1.0.0 lib/device/library/windows.rb