Method: Unpack#unpack!

Defined in:
lib/unpack.rb

#unpack!Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/unpack.rb', line 89

def unpack!
  @files.each  do |file|
    type = Mimer.identify(file)
    
    # Have the user specified a destenation folder to where the files are going to be unpacked?
    # If so, use that, if not use the current location of the archive file
    path = self.options[:to] ? @directory : File.dirname(file)
    
    before = Dir.new(path).entries
    
    if type.zip?
      @removeable.merge!(path => {:file_type => 'zip'})
      self.unzip(:path => path, :file => file)
    elsif type.rar?
      @removeable.merge!(path => {:file_type => 'rar'})
      self.unrar(:path => path, :file => file)
    else
      puts "Something went wrong, the mime type does not match zip or rar" if @options[:debugger]
    end
    
    # What files/folders where unpacked?
    diff = Dir.new(path).entries - before
    
    @removeable[path] ? @removeable[path].merge!(:diff => diff) : @removeable.delete(path)
      
    # Some debug info
    if @options[:debugger] and diff.any? and @removeable[path]
      puts "#{diff.count} where unpacked"
      puts "The archive was of type #{@removeable[path][:file_type]}"
      puts "The name of the file(s) are #{diff.join(', ')}"
      puts "The path is #{path}"
      STDOUT.flush
    end
  end
end