class RSGuitarTech::Multipacker
Public Class Methods
new(title:, directory:, unpack_dir:, repack_dir:, dest_dir:, filters: {}, options: {})
click to toggle source
# File lib/rsgt/multipacker.rb, line 10 def initialize(title:, directory:, unpack_dir:, repack_dir:, dest_dir:, filters: {}, options: {}) @title = title @directory = directory @unpack_dir = unpack_dir @repack_dir = repack_dir @dest_dir = dest_dir @filters = filters @options = options @count = {psarcs: 0, skipped: 0, failed: 0, total: 0} end
process!(*args)
click to toggle source
# File lib/rsgt/multipacker.rb, line 4 def self.process!(*args) self.new(*args).process! end
Public Instance Methods
ensure_dir!(dir)
click to toggle source
# File lib/rsgt/multipacker.rb, line 39 def ensure_dir!(dir) shell_out "mkdir -p #{dir}/" end
move!()
click to toggle source
# File lib/rsgt/multipacker.rb, line 58 def move! packed_psarc = repack_dir.split("/").last + ".psarc" puts "Moving packed psarc (#{packed_psarc}) to: #{title} - #{count[:total]} songs _m.psarc" shell_out "mv #{packed_psarc} #{dest_dir}/#{title}\\ \\-\\ #{count[:total]}\\ songs\\ \\_m.psarc" end
process!()
click to toggle source
# File lib/rsgt/multipacker.rb, line 21 def process! reset! unpack_dir if options[:reset_unpack] reset! repack_dir if options[:reset_repack] ensure_dir! unpack_dir ensure_dir! repack_dir unpack! if count[:skipped] >= count[:total] puts "All done! No new files found to repack" return end repack! move! end
repack!()
click to toggle source
# File lib/rsgt/multipacker.rb, line 53 def repack! puts "Packing #{count[:total]} songs into #{repack_dir}.psarc" shell_out %Q{pyrocksmith --no-crypto --pack "#{repack_dir}"} end
reset!(dir)
click to toggle source
# File lib/rsgt/multipacker.rb, line 35 def reset!(dir) shell_out "rm -rf #{dir}" end
unpack!()
click to toggle source
# File lib/rsgt/multipacker.rb, line 43 def unpack! filtered_psarscs.each do |dlc| if unpack dlc count[:total] = count[:total] + 1 else count[:failed] = count[:failed] + 1 end end end
Private Instance Methods
filtered_psarscs()
click to toggle source
# File lib/rsgt/multipacker.rb, line 85 def filtered_psarscs @filtered_psarscs ||= begin reject_filters = Array(filters[:reject]).flatten select_filters = Array(filters[:select]).flatten limit = options[:limit] _fp = psarcs _fp = _fp.take(limit) if limit _fp = _fp.reject { |filename| reject_filters.include? simplfied(filename) } if reject_filters.any? _fp = _fp.select { |filename| select_filters.include? simplfied(filename) } if select_filters.any? _fp end end
psarcs()
click to toggle source
# File lib/rsgt/multipacker.rb, line 99 def psarcs @psarcs ||= Dir.glob("#{directory}/*.psarc") end
shell_out(cmd)
click to toggle source
# File lib/rsgt/multipacker.rb, line 107 def shell_out(cmd) puts cmd if options[:verbose] return true if system(cmd) puts "FAILED: #{cmd}" false end
simplfied(filename)
click to toggle source
# File lib/rsgt/multipacker.rb, line 103 def simplfied(filename) filename.split("/").last.split(" _m").first end
unpack(dlc)
click to toggle source
# File lib/rsgt/multipacker.rb, line 66 def unpack(dlc) count[:psarcs] = count[:psarcs] + 1 base_name = File.basename dlc, '.*' if Dir.exists? "#{unpack_dir}/#{base_name}" puts "Skipping #{dlc} (#{base_name})" count[:skipped] = count[:skipped] + 1 return true end puts "Unpacking #{dlc} (#{base_name})" return false unless shell_out %Q{pyrocksmith --no-crypto --unpack "#{dlc}"} return false unless shell_out %Q{mv "#{base_name}/" #{unpack_dir}/} return false unless shell_out %Q{ditto "#{unpack_dir}/#{base_name}/" "#{repack_dir}"} true end