class OceanPackage::Ipa

Attributes

path[RW]

ipa 文件路径

Public Class Methods

new(path) click to toggle source
# File lib/ocean_package/ipa.rb, line 8
def initialize(path)
  @path = path
end

Public Instance Methods

build_version() click to toggle source

build 版本

# File lib/ocean_package/ipa.rb, line 158
def build_version
  info_plist_value["CFBundleVersion"]
end
bundle_identifier() click to toggle source

bundle id

# File lib/ocean_package/ipa.rb, line 148
def bundle_identifier
  info_plist_value["CFBundleIdentifier"]
end
cp_to_tmp_dir() click to toggle source

拷贝ipa文件到临时目录下

# File lib/ocean_package/ipa.rb, line 70
def cp_to_tmp_dir
  FileUtils.cp(@path, ipa_tmp_dir_path)
end
display_name() click to toggle source

app 名称

# File lib/ocean_package/ipa.rb, line 143
def display_name
  info_plist_value["CFBundleDisplayName"]
end
find_info_plist_dir() click to toggle source
# File lib/ocean_package/ipa.rb, line 114
def find_info_plist_dir
  plist_path = find_info_plist_path
  dir = File.dirname(plist_path)

  # Log.info("find info plist dir: #{dir}")

  dir
end
find_info_plist_path() click to toggle source

查找 info.plist 文件

# File lib/ocean_package/ipa.rb, line 96
def find_info_plist_path
  plist_dir = ipa_tmp_dir_path
  plist_dir += '/Payload'

  cmd = 'find ' + plist_dir
  cmd += ' -maxdepth 2'
  cmd += ' -name Info.plist'

  Log.info("find info plist path cmd: #{cmd}")

  res = %x(#{cmd})
  # res = system(cmd)

  Log.info("info plist path: #{res}")

  res
end
info_plist_value() click to toggle source

读取 info.plist 文件的值

# File lib/ocean_package/ipa.rb, line 124
def info_plist_value
  @info ||= CFPropertyList.native_types(
      CFPropertyList::List.new(file: File.join(find_info_plist_dir, 'Info.plist')).value)

  # Log.info("info plist value: #{@info}")

  @info

  # 这种写法不行的,会有如下错误
  # UnexpectedError: IOError: File /Users/ocean/Documents/myipas/ztoExpressClient_tmp/Payload/ztoExpressClient.app/Info.plist  not readable!
  # @info ||= CFPropertyList.native_types(
  #     CFPropertyList::List.new(file: find_info_plist_path).value)
  #
  # puts "info_plist_value: #{@info}"
  # @info

end
ipa_base_name() click to toggle source

ipa文件名称,包含后缀

# File lib/ocean_package/ipa.rb, line 31
def ipa_base_name
  name = File.basename(@path)

  Log.info(puts "ipa base name: #{name}")

  name
end
ipa_dir_path() click to toggle source

ipa 文件所在的文件夹路径

# File lib/ocean_package/ipa.rb, line 13
def ipa_dir_path
  dir_path = File.dirname(@path)

  Log.info("ipa dir path: #{dir_path}")

  dir_path
end
ipa_name() click to toggle source

ipa 文件名

# File lib/ocean_package/ipa.rb, line 22
def ipa_name
  name = File.basename(@path, ".*")

  Log.info("ipa name: #{name}")

  name
end
ipa_tmp_dir_path() click to toggle source

临时目录路径

# File lib/ocean_package/ipa.rb, line 40
def ipa_tmp_dir_path
  tmp_path = ipa_dir_path
  tmp_path += '/' + ipa_name + '_tmp'
  tmp_path
end
log_value() click to toggle source
# File lib/ocean_package/ipa.rb, line 162
def log_value
  display_name_value = display_name
  puts "CFBundleDisplayName: #{display_name_value}"

  bundle_identifier_value = bundle_identifier
  puts "CFBundleIdentifier: #{bundle_identifier_value}"

  version_value = version
  puts "CFBundleShortVersionString: #{version_value}"

  build_version_value = build_version
  puts "CFBundleVersion: #{build_version_value}"
end
make_tmp_dir() click to toggle source

创建临时文件夹

# File lib/ocean_package/ipa.rb, line 65
def make_tmp_dir
  FileUtils.mkdir_p(ipa_tmp_dir_path)
end
rename_tmp_ipa_file() click to toggle source

冲命名ipa文件,ipa -> zip

# File lib/ocean_package/ipa.rb, line 75
def rename_tmp_ipa_file
  ipa_file = tmp_ipa_file_path
  new_ipa_file = tmp_ipa_zip_file_path

  Log.info("rename ipa file #{ipa_file} to: #{new_ipa_file}")

  File.rename(ipa_file, new_ipa_file)
end
run() click to toggle source

执行相关操作

# File lib/ocean_package/ipa.rb, line 177
def run
  make_tmp_dir
  cp_to_tmp_dir
  rename_tmp_ipa_file
  unzip_ipa_file
  info_plist_value
  log_value
end
tmp_ipa_file_path() click to toggle source

临时目录下的ipa文件

# File lib/ocean_package/ipa.rb, line 47
def tmp_ipa_file_path
  tmp_path = ipa_tmp_dir_path + '/' + ipa_base_name

  Log.info("tmp ipa file path: #{tmp_path}")

  tmp_path
end
tmp_ipa_zip_file_path() click to toggle source

临时目录下的 zip 文件路径,把 ipa 后缀改为 zip 后缀

# File lib/ocean_package/ipa.rb, line 56
def tmp_ipa_zip_file_path
  zip_file = ipa_tmp_dir_path + '/' + ipa_name + '.zip'

  Log.info(puts "tmp ipa zip file path: #{zip_file}")

  zip_file
end
unzip_ipa_file() click to toggle source

解压缩 zip 文件

# File lib/ocean_package/ipa.rb, line 85
def unzip_ipa_file
  cmd = 'unzip -o'
  cmd += ' -d ' + ipa_tmp_dir_path
  cmd += ' ' + tmp_ipa_zip_file_path

  Log.info("unzip cmd: #{cmd}")

  res = system(cmd)
end
version() click to toggle source

版本

# File lib/ocean_package/ipa.rb, line 153
def version
  info_plist_value["CFBundleShortVersionString"]
end