Created
October 11, 2015 02:09
-
-
Save jamiely/f988ab7e08611929b6fe 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_zip(tmpdir, filename) | |
cmd = "unzip -d\"#{tmpdir}\" -q \"#{filename}\"" | |
STDERR.puts "Attempting command #{cmd}" | |
`#{cmd}` | |
end | |
def extract_7z(tmpdir, filename) | |
cmd = "7z e -yo\"#{tmpdir}\" \"#{filename}\"" | |
STDERR.puts "Attempting command #{cmd}" | |
`#{cmd}` | |
end | |
def extract(tmpdir, filename) | |
if filename =~ /.+\.7z$/ | |
extract_7z tmpdir, filename | |
else | |
extract_zip tmpdir, filename | |
end | |
end | |
def patterns | |
nds_patterns | |
end | |
def goodmerged_patterns | |
[/\([J]*U[E]*\)/, /\(S\)/] | |
end | |
# Not goodmerged | |
def nds_patterns | |
[/\((US|EU)\)/] | |
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 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