Skip to content

Instantly share code, notes, and snippets.

@DNA64
Created October 7, 2017 08:56
Show Gist options
  • Save DNA64/31a7b6914fde34743dc7144fd778994a to your computer and use it in GitHub Desktop.
Save DNA64/31a7b6914fde34743dc7144fd778994a to your computer and use it in GitHub Desktop.
Bulk Convert and Naming Tool for SNES Classic ROMS
# Bulk Convert Tool for SNES Classic ROMS
#
# Uses my modified sfc2from.py script
# https://gist.github.com/DNA64/5e79c6449785949f86744fa7dcb50ad7#file-sfc2sfrom-py
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
import random, shutil, os
def generate_id():
id = "CLV-X-"
i = 0
while i < 5:
id += random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
i += 1
return id
def process_rom(src_path):
id = generate_id()
# create a directory named with the random identifier
os.mkdir(id)
# use sfc2sfrom script to convert the rom
sfrom_path = id + ".sfrom"
os.system("python.exe sfc2sfrom.py \"{0}\" {1}".format(src_path, sfrom_path))
# compress the rom into a gzip archive and move it into the rom folder
gz_path = "{0}.gz".format(id)
os.system("7za.exe a -tgzip {0} {1} -mmt".format(gz_path, sfrom_path))
shutil.move(gz_path, "{0}/{1}".format(id, gz_path))
# also make a helper file in the folder with the original rom file name
helper_path = "{0}/{1}.txt".format(id, src_path)
helper_file_handle = os.open(helper_path, os.O_WRONLY|os.O_CREAT)
os.close(helper_file_handle)
# move the processed rom file into the processed folder
if (not os.path.exists(os.getcwd() + "/processed")):
os.mkdir("processed")
shutil.move(src_path, "processed/" + src_path)
# clean up
os.remove(sfrom_path)
if __name__ == "__main__":
all_files = os.listdir()
for src_path in all_files:
if (src_path.endswith(".smc") or src_path.endswith(".sfc")):
process_rom(src_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment