Class: Cabriolet::Models::HLPHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/cabriolet/models/hlp_header.rb

Overview

QuickHelp database header model

Represents the metadata of a QuickHelp help database (.HLP file). HLP files contain topics, context strings, and optional compression (keyword dictionary and Huffman coding).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(magic: nil, version: 2, attributes: 0, control_character: 0x3A, topic_count: 0, context_count: 0, display_width: 80, predefined_ctx_count: 0, database_name: "", topic_index_offset: 0, context_strings_offset: 0, context_map_offset: 0, keywords_offset: 0, huffman_tree_offset: 0, topic_text_offset: 0, database_size: 0, filename: nil) ⇒ HLPHeader

Initialize QuickHelp database header

Parameters:

  • magic (String) (defaults to: nil)

    Magic number (should be 0x4C 0x4E)

  • version (Integer) (defaults to: 2)

    Format version (should be 2)

  • attributes (Integer) (defaults to: 0)

    Attribute flags

  • control_character (Integer) (defaults to: 0x3A)

    Control character (usually ':' or 0xFF)

  • topic_count (Integer) (defaults to: 0)

    Number of topics

  • context_count (Integer) (defaults to: 0)

    Number of context strings

  • display_width (Integer) (defaults to: 80)

    Display width in characters

  • database_name (String) (defaults to: "")

    Database name for external links



27
28
29
30
31
32
33
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
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/cabriolet/models/hlp_header.rb', line 27

def initialize(
  magic: nil,
  version: 2,
  attributes: 0,
  control_character: 0x3A,
  topic_count: 0,
  context_count: 0,
  display_width: 80,
  predefined_ctx_count: 0,
  database_name: "",
  topic_index_offset: 0,
  context_strings_offset: 0,
  context_map_offset: 0,
  keywords_offset: 0,
  huffman_tree_offset: 0,
  topic_text_offset: 0,
  database_size: 0,
  filename: nil
)
  @magic = magic || Binary::HLPStructures::SIGNATURE
  @version = version
  @attributes = attributes
  @control_character = control_character
  @topic_count = topic_count
  @context_count = context_count
  @display_width = display_width
  @predefined_ctx_count = predefined_ctx_count
  @database_name = database_name
  @topic_index_offset = topic_index_offset
  @context_strings_offset = context_strings_offset
  @context_map_offset = context_map_offset
  @keywords_offset = keywords_offset
  @huffman_tree_offset = huffman_tree_offset
  @topic_text_offset = topic_text_offset
  @database_size = database_size
  @filename = filename

  # Collections
  @topics = []
  @contexts = []
  @context_map = []
  @keywords = []
  @huffman_tree = nil
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def attributes
  @attributes
end

#context_countObject

Returns the value of attribute context_count.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def context_count
  @context_count
end

#context_mapObject

Topics and context data



15
16
17
# File 'lib/cabriolet/models/hlp_header.rb', line 15

def context_map
  @context_map
end

#context_map_offsetObject

Returns the value of attribute context_map_offset.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def context_map_offset
  @context_map_offset
end

#context_strings_offsetObject

Returns the value of attribute context_strings_offset.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def context_strings_offset
  @context_strings_offset
end

#contextsObject

Topics and context data



15
16
17
# File 'lib/cabriolet/models/hlp_header.rb', line 15

def contexts
  @contexts
end

#control_characterObject

Returns the value of attribute control_character.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def control_character
  @control_character
end

#database_nameObject

Returns the value of attribute database_name.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def database_name
  @database_name
end

#database_sizeObject

Returns the value of attribute database_size.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def database_size
  @database_size
end

#display_widthObject

Returns the value of attribute display_width.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def display_width
  @display_width
end

#filenameObject

Returns the value of attribute filename.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def filename
  @filename
end

#huffman_treeObject

Returns the value of attribute huffman_tree.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def huffman_tree
  @huffman_tree
end

#huffman_tree_offsetObject

Returns the value of attribute huffman_tree_offset.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def huffman_tree_offset
  @huffman_tree_offset
end

#keywordsObject

Returns the value of attribute keywords.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def keywords
  @keywords
end

#keywords_offsetObject

Returns the value of attribute keywords_offset.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def keywords_offset
  @keywords_offset
end

#magicObject

Returns the value of attribute magic.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def magic
  @magic
end

#predefined_ctx_countObject

Returns the value of attribute predefined_ctx_count.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def predefined_ctx_count
  @predefined_ctx_count
end

#topic_countObject

Returns the value of attribute topic_count.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def topic_count
  @topic_count
end

#topic_index_offsetObject

Returns the value of attribute topic_index_offset.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def topic_index_offset
  @topic_index_offset
end

#topic_text_offsetObject

Returns the value of attribute topic_text_offset.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def topic_text_offset
  @topic_text_offset
end

#topicsObject

Topics and context data



15
16
17
# File 'lib/cabriolet/models/hlp_header.rb', line 15

def topics
  @topics
end

#versionObject

Returns the value of attribute version.



11
12
13
# File 'lib/cabriolet/models/hlp_header.rb', line 11

def version
  @version
end

Instance Method Details

#case_sensitive?Boolean

Check if case-sensitive context strings

Returns:

  • (Boolean)

    true if case-sensitive



85
86
87
# File 'lib/cabriolet/models/hlp_header.rb', line 85

def case_sensitive?
  @attributes.anybits?(Binary::HLPStructures::Attributes::CASE_SENSITIVE)
end

#control_charString

Get control character as string

Returns:

  • (String)

    control character



113
114
115
# File 'lib/cabriolet/models/hlp_header.rb', line 113

def control_char
  @control_character.chr(Encoding::ASCII)
end

#db_nameString

Get database name without null padding

Returns:

  • (String)

    trimmed database name



120
121
122
# File 'lib/cabriolet/models/hlp_header.rb', line 120

def db_name
  @database_name.split("\x00").first || ""
end

#has_huffman?Boolean

Check if Huffman compression is used

Returns:

  • (Boolean)

    true if Huffman tree present



106
107
108
# File 'lib/cabriolet/models/hlp_header.rb', line 106

def has_huffman?
  @huffman_tree_offset.positive? && !@huffman_tree.nil?
end

#has_keywords?Boolean

Check if keyword compression is used

Returns:

  • (Boolean)

    true if keywords present



99
100
101
# File 'lib/cabriolet/models/hlp_header.rb', line 99

def has_keywords?
  @keywords_offset.positive? && !@keywords.empty?
end

#locked?Boolean

Check if database is locked (cannot be decoded by HELPMAKE)

Returns:

  • (Boolean)

    true if locked



92
93
94
# File 'lib/cabriolet/models/hlp_header.rb', line 92

def locked?
  @attributes.anybits?(Binary::HLPStructures::Attributes::LOCKED)
end

#valid?Boolean

Check if header is valid

Returns:

  • (Boolean)

    true if header appears valid



75
76
77
78
79
80
# File 'lib/cabriolet/models/hlp_header.rb', line 75

def valid?
  @magic == Binary::HLPStructures::SIGNATURE &&
    @version == 2 &&
    @topic_count >= 0 &&
    @context_count >= 0
end