Class: Cabriolet::HLP::Decompressor

Inherits:
Object
  • Object
show all
Defined in:
lib/cabriolet/hlp/decompressor.rb

Overview

Main decompressor for HLP files

Detects the HLP format variant and delegates to the appropriate decompressor:

  • QuickHelp (DOS format)

  • Windows Help (WinHelp 3.x/4.x format)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io_system = nil) ⇒ Decompressor

Initialize decompressor



19
20
21
22
23
24
# File 'lib/cabriolet/hlp/decompressor.rb', line 19

def initialize(io_system = nil)
  @io_system = io_system || System::IOSystem.new
  @parser = Parser.new(@io_system)
  @delegate = nil
  @current_format = nil
end

Instance Attribute Details

#io_systemObject (readonly)

Returns the value of attribute io_system.



14
15
16
# File 'lib/cabriolet/hlp/decompressor.rb', line 14

def io_system
  @io_system
end

#parserObject (readonly)

Returns the value of attribute parser.



14
15
16
# File 'lib/cabriolet/hlp/decompressor.rb', line 14

def parser
  @parser
end

Class Method Details

.extract(filename, output_dir, io_system = nil) ⇒ Integer

Extract (alternate API taking filename directly)



119
120
121
122
123
124
# File 'lib/cabriolet/hlp/decompressor.rb', line 119

def self.extract(filename, output_dir, io_system = nil)
  io_sys = io_system || System::IOSystem.new
  decompressor = new(io_sys)
  header = decompressor.open(filename)
  decompressor.extract_all(header, output_dir)
end

Instance Method Details

#close(header) ⇒ nil

Close HLP file



49
50
51
52
# File 'lib/cabriolet/hlp/decompressor.rb', line 49

def close(header)
  @delegate&.close(header) if @delegate.respond_to?(:close)
  nil
end

#extract_all(header, output_dir) ⇒ Integer

Extract all files

Raises:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/cabriolet/hlp/decompressor.rb', line 98

def extract_all(header, output_dir)
  raise ArgumentError, "Header must not be nil" if header.nil?

  if output_dir.nil?
    raise ArgumentError,
          "Output directory must not be nil"
  end

  case @current_format
  when :quickhelp
    @delegate.extract_all(header, output_dir)
  when :winhelp
    @delegate.extract_all(output_dir)
  end
end

#extract_file(header, hlp_file, output_path) ⇒ Integer

Extract a file

Raises:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cabriolet/hlp/decompressor.rb', line 60

def extract_file(header, hlp_file, output_path)
  raise ArgumentError, "Header must not be nil" if header.nil?
  raise ArgumentError, "HLP file must not be nil" if hlp_file.nil?
  raise ArgumentError, "Output path must not be nil" if output_path.nil?

  case @current_format
  when :quickhelp
    @delegate.extract_file(header, hlp_file, output_path)
  when :winhelp
    # WinHelp uses different extraction model
    raise NotImplementedError,
          "WinHelp file extraction not yet implemented via this API"
  end
end

#extract_file_to_memory(header, hlp_file) ⇒ String

Extract file to memory

Raises:



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/cabriolet/hlp/decompressor.rb', line 80

def extract_file_to_memory(header, hlp_file)
  raise ArgumentError, "Header must not be nil" if header.nil?
  raise ArgumentError, "HLP file must not be nil" if hlp_file.nil?

  case @current_format
  when :quickhelp
    @delegate.extract_file_to_memory(header, hlp_file)
  when :winhelp
    raise NotImplementedError,
          "WinHelp memory extraction not yet implemented via this API"
  end
end

#open(filename) ⇒ Models::HLPHeader, Models::WinHelpHeader

Open and parse HLP file



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cabriolet/hlp/decompressor.rb', line 30

def open(filename)
  @current_format = detect_format(filename)

  case @current_format
  when :quickhelp
    @delegate = QuickHelp::Decompressor.new(@io_system)
    @delegate.open(filename)
  when :winhelp
    @delegate = WinHelp::Decompressor.new(filename, @io_system)
    @delegate.parse
  else
    raise Cabriolet::ParseError, "Unknown HLP format"
  end
end