Class: Flappy::IpaInfo::Ipa

Inherits:
Object show all
Defined in:
lib/flappy/util/ipa_info.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Ipa

include Parser::Common



8
9
10
# File 'lib/flappy/util/ipa_info.rb', line 8

def initialize(path)
  @path = path   # ipa包的路径
end

Instance Method Details

#appObject



34
35
36
# File 'lib/flappy/util/ipa_info.rb', line 34

def app
  @app ||= App.new(app_path, is_stored)
end

#app_pathObject



30
31
32
# File 'lib/flappy/util/ipa_info.rb', line 30

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

#cleanupObject



38
39
40
41
42
# File 'lib/flappy/util/ipa_info.rb', line 38

def cleanup
  return unless @contents
  FileUtils.rm_rf(@contents)
  @contents = nil
end

#contentsObject

contents为ipa解压路径



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/flappy/util/ipa_info.rb', line 12

def contents   # contents为ipa解压路径
  return @contents if @contents

  @contents = "#{Dir.tmpdir}/#{Time.now.strftime('%Y%m%d%H%M%S')}_ipa_files"
  Zip::File.open(@path) do |zip_file|  # zip_file为待解压的文件路径
    # puts "zipfile: #{zip_file}"
    zip_file.each do |f|    # f为解压出来的文件
      # puts "file: #{f}"
      f_path = File.join(@contents, f.name)   # f_path为解压出来的文件路径
      # puts "path: #{f_path}"
      # FileUtils.mkdir_p(File.dirname(f_path))  # File.dirname(f_path)为所有的文件夹、资源束文件;这里建立压缩包里面的每个文件夹,这一步可以省略的
      # puts "dir: #{File.dirname(f_path)}"
      zip_file.extract(f, f_path) unless File.exist?(f_path)  # 解压文件到相应位置
    end
  end
  @contents
end

#has_metadata?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/flappy/util/ipa_info.rb', line 53

def has_metadata?
  File.file?()
end

#is_storedObject

是否是appstore包



61
62
63
# File 'lib/flappy/util/ipa_info.rb', line 61

def is_stored   # 是否是appstore包
  has_metadata? ? true : false
end

#metadataObject



44
45
46
47
48
49
50
51
# File 'lib/flappy/util/ipa_info.rb', line 44

def 
  return unless has_metadata?
  begin
    @metadata ||= CFPropertyList.native_types(CFPropertyList::List.new(file: ).value)
  rescue CFFormatError
    @metadata = {}
  end
end

#metadata_pathObject



57
58
59
# File 'lib/flappy/util/ipa_info.rb', line 57

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