2011-11-19 14:59:13 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'fileutils'
|
|
|
|
|
2012-10-31 10:42:19 +00:00
|
|
|
class UnrarError < RuntimeError ; end
|
|
|
|
class ZipError < RuntimeError ; end
|
|
|
|
|
2011-11-19 14:59:13 +00:00
|
|
|
where = Dir.pwd
|
|
|
|
|
|
|
|
ARGV.each do |arg|
|
|
|
|
Dir.chdir where
|
|
|
|
|
|
|
|
cbr_path = File.expand_path arg
|
|
|
|
cbz_path = cbr_path.gsub(/.cbr$/,'.cbz')
|
|
|
|
|
|
|
|
name = File.basename(arg).dup
|
|
|
|
name.gsub!(/\.cbr/i,'')
|
2012-10-31 10:42:19 +00:00
|
|
|
if File.exists? name then
|
|
|
|
FileUtils.rm_rf name
|
|
|
|
end
|
2011-11-19 14:59:13 +00:00
|
|
|
FileUtils.mkdir_p name
|
|
|
|
Dir.chdir name
|
|
|
|
system "unrar e \"#{cbr_path}\""
|
2012-10-31 10:42:19 +00:00
|
|
|
if not $?.success? then
|
|
|
|
raise UnrarError
|
|
|
|
end
|
|
|
|
|
2011-11-19 14:59:13 +00:00
|
|
|
Dir.chdir where
|
|
|
|
system "zip -r \"#{cbz_path}\" \"#{name}\""
|
2012-10-31 10:42:19 +00:00
|
|
|
if not $?.success? then
|
|
|
|
raise ZipError
|
|
|
|
end
|
2011-11-19 14:59:13 +00:00
|
|
|
FileUtils.rm_rf name
|
|
|
|
end
|
|
|
|
|