Class: Exerb::Win32::IconFile

Inherits:
Object
  • Object
show all
Defined in:
lib/exerb/win32/icon_file.rb

Overview

#

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIconFile

Returns a new instance of IconFile.



20
21
22
# File 'lib/exerb/win32/icon_file.rb', line 20

def initialize
  @entries = []
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



24
25
26
# File 'lib/exerb/win32/icon_file.rb', line 24

def entries
  @entries
end

Class Method Details

.read(input) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/exerb/win32/icon_file.rb', line 26

def self.read(input)
  case input
  when IO     then return self.new.read(input)
  when String then return File.open(input, 'rb') { |file| self.read(file) }
  else raise(ArgumentError, "input must be IO or String object")
  end
end

Instance Method Details

#read(io) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/exerb/win32/icon_file.rb', line 34

def read(io)
  base = io.pos
  icon_header = Exerb::Win32::Struct::IconHeader.read(io)

  @entries = (1..icon_header.count).collect {
    Exerb::Win32::Struct::IconDirEntry.read(io)
  }.collect { |icon_dir_entry|
    io.seek(base + icon_dir_entry.image_offset)
    icon_image_header = Exerb::Win32::Struct::IconImageHeader.read(io)
    io.seek(icon_image_header.position)

    entry = Exerb::Win32::IconFile::Entry.new
    entry.width     = icon_dir_entry.width
    entry.height    = icon_dir_entry.height
    entry.bit_count = icon_image_header.bit_count
    entry.value     = io.read(icon_dir_entry.bytes_in_res)
    if entry.width == 0
      entry.bit_count = icon_dir_entry.bit_count
      entry.width = entry.height = 256
    end
    entry
  }

  return self
end