Skip to content

Instantly share code, notes, and snippets.

@tristansokol
Created April 6, 2018 16:56
Show Gist options
  • Save tristansokol/fbd537a272080440f35411519009514d to your computer and use it in GitHub Desktop.
Save tristansokol/fbd537a272080440f35411519009514d to your computer and use it in GitHub Desktop.
def merge(*args, quiet=True):
import retro
known_hashes = {}
for game in retro.list_games():
shafile = os.path.join(retro.get_game_path(game), 'rom.sha')
with open(shafile) as f:
shas = f.read().strip().split('\n')
for ext, platform in retro.EMU_EXTENSIONS.items():
if game.endswith('-' + platform):
break
for sha in shas:
known_hashes[sha] = (game, ext)
for rom in args:
try:
data, hash = groom_rom(rom)
except IOError:
continue
if hash in known_hashes:
game, ext = known_hashes[hash]
if not quiet:
print('Importing', game)
with open(os.path.join(retro.get_game_path(game), 'rom%s' % ext), 'wb') as f:
f.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment