Class: Cabriolet::HLP::CommandHandler

Inherits:
Commands::BaseCommandHandler show all
Defined in:
lib/cabriolet/hlp/command_handler.rb

Overview

Command handler for HLP (Help) format

This handler implements the unified command interface for HLP files, wrapping the existing HLP::Decompressor and HLP::Compressor classes. Supports both QuickHelp and Windows Help formats.

Instance Method Summary collapse

Methods inherited from Commands::BaseCommandHandler

#initialize

Constructor Details

This class inherits a constructor from Cabriolet::Commands::BaseCommandHandler

Instance Method Details

#create(output, files = [], options = {}) ⇒ void

This method returns an undefined value.

Create a new HLP archive

Creates an HLP file from source files using QuickHelp format.

Parameters:

  • Output HLP file path

  • (defaults to: [])

    List of input files to add

  • (defaults to: {})

    Additional options

Options Hash (options):

  • :format (String)

    HLP format (:quickhelp, :winhelp)

Raises:

  • if no files specified



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cabriolet/hlp/command_handler.rb', line 70

def create(output, files = [], options = {})
  raise ArgumentError, "No files specified" if files.empty?

  files.each do |f|
    raise ArgumentError, "File does not exist: #{f}" unless File.exist?(f)
  end

  format = parse_format_option(options[:format])

  if format == :winhelp
    create_winhelp(output, files, options)
  else
    create_quickhelp(output, files, options)
  end
end

#extract(file, output_dir = nil, _options = {}) ⇒ void

This method returns an undefined value.

Extract files from HLP archive

Extracts all files from the HLP file to the specified output directory. Supports both QuickHelp and Windows Help formats.

Parameters:

  • Path to the HLP file

  • (defaults to: nil)

    Output directory path (default: current directory)

  • Additional options (unused)



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cabriolet/hlp/command_handler.rb', line 45

def extract(file, output_dir = nil, _options = {})
  validate_file_exists(file)

  output_dir ||= "."
  output_dir = ensure_output_dir(output_dir)

  decompressor = Decompressor.new
  header = decompressor.open(file)

  count = decompressor.extract_all(header, output_dir)
  decompressor.close(header)

  puts "Extracted #{count} file(s) to #{output_dir}"
end

#info(file, _options = {}) ⇒ void

This method returns an undefined value.

Display detailed HLP file information

Shows comprehensive information about the HLP structure, including format type, file count, and metadata.

Parameters:

  • Path to the HLP file

  • Additional options (unused)



94
95
96
97
98
99
100
101
102
103
# File 'lib/cabriolet/hlp/command_handler.rb', line 94

def info(file, _options = {})
  validate_file_exists(file)

  decompressor = Decompressor.new
  header = decompressor.open(file)

  display_hlp_info(header, file)

  decompressor.close(header)
end

#list(file, _options = {}) ⇒ void

This method returns an undefined value.

List HLP file contents

Displays information about the HLP file including format type, and lists all contained files with their sizes.

Parameters:

  • Path to the HLP file

  • Additional options (unused)



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cabriolet/hlp/command_handler.rb', line 24

def list(file, _options = {})
  validate_file_exists(file)

  decompressor = Decompressor.new
  header = decompressor.open(file)

  display_header(header, file)
  display_files(decompressor, header)

  decompressor.close(header)
end

#test(file, _options = {}) ⇒ void

This method returns an undefined value.

Test HLP file integrity

Verifies the HLP file structure.

Parameters:

  • Path to the HLP file

  • Additional options (unused)



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/cabriolet/hlp/command_handler.rb', line 112

def test(file, _options = {})
  validate_file_exists(file)

  decompressor = Decompressor.new
  header = decompressor.open(file)

  puts "Testing #{file}..."
  # TODO: Implement full integrity testing
  format_name = if header.respond_to?(:version)
                  version_value = header.version
                  # Convert BinData objects to integer for comparison
                  version_int = version_value.to_i if version_value.respond_to?(:to_i)

                  if version_value.is_a?(Integer) || version_int&.positive?
                    "QUICKHELP v#{version_value}"
                  elsif version_value.is_a?(Symbol)
                    version_value.to_s.upcase.sub("WINHELP", "WinHelp ")
                  else
                    "unknown"
                  end
                end
  puts "OK: HLP file structure is valid (#{format_name} format)"

  decompressor.close(header)
end