lib/xcselect/xcapp.rb in xcselect-0.1.3 vs lib/xcselect/xcapp.rb in xcselect-0.1.4

- old
+ new

@@ -1,19 +1,20 @@ module Xcselect require 'pathname' require 'json' require "plist" + require 'xcselect/nkissue' class XcApp include Comparable attr_reader :path - attr_reader :plist + attr_reader :info_plist def initialize(path) @path = path - @plist = JSON.parse read_plist(plist_path) + @info_plist = JSON.parse read_plist(plist_path) end def to_s "#{name} (#{sim_version})" end @@ -26,11 +27,11 @@ def sim_version path.split('/')[-4] end def [](k) - @plist[k] + @info_plist[k] end def base_dir File.dirname path end @@ -57,78 +58,81 @@ def documents_path "#{base_dir}/Documents" end + def cache_path + "#{base_dir}/Library/Caches" + end + def oomph_app? File.exists? "#{path}/Oomph.plist" end def newsstand? self['UINewsstandApp'] || false end + # Returns a hash of NKIssues in the form {"issue_name" => path } def newsstand_objects - issues = {} + issues = NKIssue.parse "#{base_dir}/Library/Application Support/com.apple.newsstand-library.plist" + return issues unless newsstand? - # this is an NSKeyedArchiver plist - ns_plist = Plist::parse_xml(read_bin_plist_to_xml("#{base_dir}/Library/Application Support/com.apple.newsstand-library.plist")) - - # this is the integer that we will use to filter all archived nkissue objects - nk_issue_key = ns_plist['$objects'].index(ns_plist['$objects'].select{|o| o['$classname'] == "NKIssue"}.last) - - # filter just the nkissue hashes - obj_key_hashs = ns_plist['$objects'].select{|o| o.class == Hash && o['$class'] && nk_issue_key == o['$class']['CF$UID'] } - object_array = ns_plist['$objects'] - - # load these paths as our apps have 1 folder inside the newsstand folders - paths = newsstand_issue_paths if oomph_app? - - obj_key_hashs.each do |nskey| - name = object_array[nskey['name']['CF$UID']] - uuid = object_array[nskey['directory']['CF$UID']] - next if name.nil? - issues[name] = "#{newsstand_path}/#{uuid}" - issues[name] = paths.select{|p| p[uuid] }.last if oomph_app? # specially for me :) + paths = newsstand_issue_paths if oomph_app? + issues.values.each do |issue| + issue.content_path = "#{newsstand_path}/#{issue.uuid}" + issue.content_path = paths.select{|p| p[issue.uuid] }.last if oomph_app? end + return issues end + # path to the app's root newsstand folder def newsstand_path "#{base_dir}/Library/Caches/Newsstand" end + # all directories in newsstand folder def newsstand_issue_paths #TODO: make this read the newsstand db and return a hash of names/paths if oomph_app? Dir["#{newsstand_path}/*-*/*"] else Dir["#{newsstand_path}/*-*"] end end - + def last_build_time File.mtime path end + + # Class methods + # the iPhone Simulator support folder def self.app_support_folder File.expand_path("~/Library/Application Support/iPhone Simulator/") end + # all applications for all simulator versions, unsorted def self.all_apps Dir["#{app_support_folder}/**/*.app"].map{|a| XcApp.new a } end - + + # every newsstand application def self.all_newsstand_apps self.all_apps.select(&:newsstand?) end def self.last_built_newsstand_app all_newsstand_apps.sort_by!{|e| e.last_build_time }.last end + def self.sort_by_touch_time array + array.sort_by{|e| e.last_build_time } + end + def self.last_built_app - XcApp.all_apps.sort_by!{|e| e.last_build_time }.last + XcApp.sort_by_touch_time(all_apps).last end end \ No newline at end of file