Class: AppInfo::HAP

Inherits:
HarmonyOS show all
Defined in:
lib/app_info/hap.rb

Overview

Parse HAP file parser

Constant Summary

Constants included from AppInfo::Helper::HumanFileSize

AppInfo::Helper::HumanFileSize::FILE_SIZE_UNITS

Instance Attribute Summary

Attributes inherited from File

#file, #logger

Instance Method Summary collapse

Methods inherited from HarmonyOS

#contents, #device, #info_path, #manufacturer, #pack_info, #platform, #size

Methods included from AppInfo::Helper::Archive

#tempdir, #unarchive

Methods included from AppInfo::Helper::HumanFileSize

#file_to_human_size, #number_to_human_size

Methods inherited from File

#device, #format, #initialize, #manufacturer, #not_implemented_error!, #platform, #size

Constructor Details

This class inherits a constructor from AppInfo::File

Instance Method Details

#clear!Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/app_info/hap.rb', line 58

def clear!
  return unless @contents

  FileUtils.rm_rf(@contents)

  @pack_info = nil
  @info_path = nil
  @contents = nil

  @module_info_path = nil
  @module_info = nil
  @icons_path = nil
  @icons = nil
end

#iconsArray<Hash{Symbol => String, Array<Integer>}>

Full icons metadata

Examples:

ipa.icons
# => [
#   {
#     name: 'icon.png',
#     file: '/path/to/icon.png',
#     uncrushed_file: '/path/to/uncrushed_icon.png',
#     dimensions: [64, 64]
#   },
#   {
#     name: 'icon1.png',
#     file: '/path/to/icon1.png',
#     uncrushed_file: '/path/to/uncrushed_icon1.png',
#     dimensions: [120, 120]
#   }
# ]

Returns:

  • (Array<Hash{Symbol => String, Array<Integer>}>)

    icons paths of icons



24
25
26
27
28
29
30
31
32
33
# File 'lib/app_info/hap.rb', line 24

def icons
  @icons ||= icons_path.each_with_object([]) do |file, obj|
    obj << {
      name: ::File.basename(file),
      file: file,
      uncrushed_file: file,
      dimensions: ImageSize.path(file).size
    }
  end
end

#icons_pathArray<String>

Returns:

  • (Array<String>)


36
37
38
# File 'lib/app_info/hap.rb', line 36

def icons_path
  @icons_path ||= [::File.join(contents, 'resources', 'base', 'media', 'app_icon.png')]
end

#module_infoJSON

Returns:

  • (JSON)


41
42
43
# File 'lib/app_info/hap.rb', line 41

def module_info
  @module_info ||= JSON.parse(::File.read(module_info_path))
end

#module_info_pathString

Returns:

  • (String)


46
47
48
# File 'lib/app_info/hap.rb', line 46

def module_info_path
  @module_info_path ||= ::File.join(contents, 'module.json')
end

#nameString

Returns:

  • (String)


51
52
53
54
55
56
# File 'lib/app_info/hap.rb', line 51

def name
  # TODO: The application display name should be determined by looking up
  # the value of the variable named in the "label" field of the "module.json"
  # file within the "resources.index" file.
  pack_info.bundle_name
end