Class: AppInfo::IPA

Inherits:
Object show all
Extended by:
Forwardable
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'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ IPA

Returns a new instance of IPA.



26
27
28
# File 'lib/app_info/ipa.rb', line 26

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



13
14
15
# File 'lib/app_info/ipa.rb', line 13

def file
  @file
end

Instance Method Details

#app_pathObject



154
155
156
# File 'lib/app_info/ipa.rb', line 154

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

#archsObject Also known as: architectures



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

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



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

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

#bundle_pathObject



142
143
144
# File 'lib/app_info/ipa.rb', line 142

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

#clear!Object



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

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



197
198
199
# File 'lib/app_info/ipa.rb', line 197

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

#distribution_nameObject



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

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

#frameworksObject



99
100
101
# File 'lib/app_info/ipa.rb', line 99

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

#hide_developer_certificatesObject



103
104
105
# File 'lib/app_info/ipa.rb', line 103

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

#icons(uncrush: true) ⇒ Object



85
86
87
88
89
# File 'lib/app_info/ipa.rb', line 85

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

#icons_pathObject



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

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



146
147
148
# File 'lib/app_info/ipa.rb', line 146

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

#info_pathObject



150
151
152
# File 'lib/app_info/ipa.rb', line 150

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

#metadataObject



128
129
130
131
132
# File 'lib/app_info/ipa.rb', line 128

def 
  return unless metadata?

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

#metadata?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/app_info/ipa.rb', line 134

def metadata?
  File.exist?()
end

#metadata_pathObject



138
139
140
# File 'lib/app_info/ipa.rb', line 138

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

#mobileprovisionObject



107
108
109
110
111
112
# File 'lib/app_info/ipa.rb', line 107

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

  @mobileprovision = MobileProvision.new(mobileprovision_path)
end

#mobileprovision?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/app_info/ipa.rb', line 114

def mobileprovision?
  File.exist?(mobileprovision_path)
end

#mobileprovision_pathObject



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

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



34
35
36
# File 'lib/app_info/ipa.rb', line 34

def os
  AppInfo::Platform::IOS
end

#pluginsObject



95
96
97
# File 'lib/app_info/ipa.rb', line 95

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

#release_typeObject



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

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

#size(human_size: false) ⇒ Object



30
31
32
# File 'lib/app_info/ipa.rb', line 30

def size(human_size: false)
  AppInfo::Util.file_size(@file, human_size)
end

#stored?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/app_info/ipa.rb', line 91

def stored?
  !!metadata?
end