Class: AppInfo::IPA

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Helper::Archive, Helper::HumanFileSize
Defined in:
lib/app_info/ipa.rb

Overview

IPA parser

Defined Under Namespace

Modules: ExportType

Constant Summary collapse

IPHONE_KEY =
'CFBundleIcons'
IPAD_KEY =
'CFBundleIcons~ipad'

Constants included from Helper::HumanFileSize

Helper::HumanFileSize::FILE_SIZE_UNITS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Archive

#tempdir, #unarchive

Methods included from Helper::HumanFileSize

#file_to_human_size, #number_to_human_size

Constructor Details

#initialize(file) ⇒ IPA



28
29
30
# File 'lib/app_info/ipa.rb', line 28

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



15
16
17
# File 'lib/app_info/ipa.rb', line 15

def file
  @file
end

Instance Method Details

#app_pathObject



156
157
158
# File 'lib/app_info/ipa.rb', line 156

def app_path
  @app_path ||= Dir.glob(File.join(contents, 'Payload', '*.app')).first
end

#archsObject Also known as: architectures



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/app_info/ipa.rb', line 72

def archs
  return unless File.exist?(bundle_path)

  file = MachO.open(bundle_path)
  case file
  when MachO::MachOFile
    [file.cpusubtype]
  else
    file.machos.each_with_object([]) do |arch, obj|
      obj << arch.cpusubtype
    end
  end
end

#build_typeObject



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

def build_type
  if mobileprovision?
    if devices
      ExportType::ADHOC
    else
      ExportType::ENTERPRISE
    end
  else
    ExportType::DEBUG
  end
end

#bundle_pathObject



144
145
146
# File 'lib/app_info/ipa.rb', line 144

def bundle_path
  @bundle_path ||= File.join(app_path, info.bundle_name)
end

#clear!Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/app_info/ipa.rb', line 184

def clear!
  return unless @contents

  FileUtils.rm_rf(@contents)

  @contents = nil
  @app_path = nil
  @info_path = nil
  @info = nil
  @metadata_path = nil
  @metadata = nil
  @icons_path = nil
  @icons = nil
end

#contentsObject



199
200
201
# File 'lib/app_info/ipa.rb', line 199

def contents
  @contents ||= unarchive(@file, path: 'ios')
end

#distribution_nameObject



48
49
50
# File 'lib/app_info/ipa.rb', line 48

def distribution_name
  "#{profile_name} - #{team_name}" if profile_name && team_name
end

#frameworksObject



101
102
103
# File 'lib/app_info/ipa.rb', line 101

def frameworks
  @frameworks ||= Framework.parse(app_path)
end

#hide_developer_certificatesObject



105
106
107
# File 'lib/app_info/ipa.rb', line 105

def hide_developer_certificates
  mobileprovision.delete('DeveloperCertificates') if mobileprovision?
end

#icons(uncrush: true) ⇒ Object



87
88
89
90
91
# File 'lib/app_info/ipa.rb', line 87

def icons(uncrush: true)
  @icons ||= icons_path.each_with_object([]) do |file, obj|
    obj << (file, uncrush: uncrush)
  end
end

#icons_pathObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/app_info/ipa.rb', line 163

def icons_path
  return @icons_path if @icons_path

  @icons_path = []
  icon_keys.each do |name|
    filenames = info.try(:[], name)
                    .try(:[], 'CFBundlePrimaryIcon')
                    .try(:[], 'CFBundleIconFiles')

    next if filenames.nil? || filenames.empty?

    filenames.each do |filename|
      Dir.glob(File.join(app_path, "#{filename}*")).find_all.each do |file|
        @icons_path << file
      end
    end
  end

  @icons_path
end

#infoObject



148
149
150
# File 'lib/app_info/ipa.rb', line 148

def info
  @info ||= InfoPlist.new(info_path)
end

#info_pathObject



152
153
154
# File 'lib/app_info/ipa.rb', line 152

def info_path
  @info_path ||= File.join(app_path, 'Info.plist')
end

#metadataObject



130
131
132
133
134
# File 'lib/app_info/ipa.rb', line 130

def 
  return unless metadata?

  @metadata ||= CFPropertyList.native_types(CFPropertyList::List.new(file: ).value)
end

#metadata?Boolean



136
137
138
# File 'lib/app_info/ipa.rb', line 136

def metadata?
  File.exist?()
end

#metadata_pathObject



140
141
142
# File 'lib/app_info/ipa.rb', line 140

def 
  @metadata_path ||= File.join(contents, 'iTunesMetadata.plist')
end

#mobileprovisionObject



109
110
111
112
113
114
# File 'lib/app_info/ipa.rb', line 109

def mobileprovision
  return unless mobileprovision?
  return @mobileprovision if @mobileprovision

  @mobileprovision = MobileProvision.new(mobileprovision_path)
end

#mobileprovision?Boolean



116
117
118
# File 'lib/app_info/ipa.rb', line 116

def mobileprovision?
  File.exist?(mobileprovision_path)
end

#mobileprovision_pathObject



120
121
122
123
124
125
126
127
128
# File 'lib/app_info/ipa.rb', line 120

def mobileprovision_path
  filename = 'embedded.mobileprovision'
  @mobileprovision_path ||= File.join(@file, filename)
  unless File.exist?(@mobileprovision_path)
    @mobileprovision_path = File.join(app_path, filename)
  end

  @mobileprovision_path
end

#osObject Also known as: file_type



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

def os
  Platform::IOS
end

#pluginsObject



97
98
99
# File 'lib/app_info/ipa.rb', line 97

def plugins
  @plugins ||= Plugin.parse(app_path)
end

#release_typeObject



52
53
54
55
56
57
58
# File 'lib/app_info/ipa.rb', line 52

def release_type
  if stored?
    ExportType::RELEASE
  else
    build_type
  end
end

#size(human_size: false) ⇒ Object



32
33
34
# File 'lib/app_info/ipa.rb', line 32

def size(human_size: false)
  file_to_human_size(@file, human_size: human_size)
end

#stored?Boolean



93
94
95
# File 'lib/app_info/ipa.rb', line 93

def stored?
  !!metadata?
end