Created
October 11, 2015 01:56
-
-
Save jamiely/d942b6a8ba583c01e409 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extracts the first potential in a goodrom set | |
# | |
require 'tmpdir' | |
require 'fileutils' | |
def extract_7z(tmpdir, filename) | |
cmd = "7z e -yo\"#{tmpdir}\" \"#{filename}\"" | |
STDERR.puts "Attempting command #{cmd}" | |
`#{cmd}` | |
end | |
def patterns | |
[/\([J]*U[E]*\)/, /\(S\)/] | |
end | |
def find_us_rom(tmpdir) | |
entries = Dir.entries(tmpdir) | |
found = entries.find do | entry | | |
entry if patterns.find do | pattern | | |
entry =~ pattern | |
end | |
end | |
found | |
end | |
Dir.mktmpdir do |tmpdir| | |
outputdir = ARGV[0] | |
filename = ARGV[1] | |
STDERR.puts "Arguments: #{ARGV}" | |
STDERR.puts "Finding US ROM for #{filename}" | |
results = extract_7z tmpdir, filename | |
STDERR.puts results | |
rom = find_us_rom(tmpdir) | |
if rom | |
tmppath = File.join(tmpdir, rom) | |
newpath = File.join(outputdir, rom) | |
FileUtils.mv(tmppath, newpath) | |
puts "#{newpath}" | |
else | |
puts "NOT FOUND - #{filename}" | |
puts Dir.entries(tmpdir) | |
exit 1 | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment