Skip to content

Instantly share code, notes, and snippets.

@wychwitch
Last active October 17, 2019 13:45
Show Gist options
  • Save wychwitch/5f71bf571517d81384b9292b46b6147f to your computer and use it in GitHub Desktop.
Save wychwitch/5f71bf571517d81384b9292b46b6147f to your computer and use it in GitHub Desktop.
A simple python3 program to quickly make batch files that will automatically launch the rom in the user defined emulator. Created for use with gog galaxy 2.0 but it may work with other launchers. It also includes the option to save settings for easy updating.
import glob, os, json
# a simple python3 program to quickly make batch files that will automatically launch the rom in the user defined emulator. Also include the option to save settings for easy updating.
#Recommended to run it its own folder if you plan on saving configs as it will create a batGenConfigs.json file wherever the script is located, but it should be fine either way.
# Here is an example usecase:
#Please enter the command-line launch command for your emulator (MUST have quotes around paths): "C:\Users\wych\AppData\Roaming\RetroArch\retroarch.exe" -L "C:\Users\wych\AppData\Roaming\RetroArch\cores\pcsx_rearmed_libretro.dll"
#Please enter the extension of the rom files (with period): .m3u
#Please enter the rom directory: D:\Files\Roms\PSX
#Please enter the directory that the bat files will be stored (WILL OVERWRITE ANY BATS INSIDE IT): D:\Files\Roms\Batch Files\PSX
#Please enter any additional arguments that come after the path to rom file (just hit enter if none): --fullscreen
#Processed Animetic Story Game 1 - Card Captor Sakura.m3u
#Processed Azure Dreams.m3u
#Finished!
#Would you like to save these settings for later? This will create a json file in the same location as this script(y/n): y
#please enter the name of the system you wish to save: PSX
#Name = PSX
#Emulator command = "C:\Users\wych\AppData\Roaming\RetroArch\retroarch.exe" -L "C:\Users\wych\AppData\Roaming\RetroArch\cores\pcsx_rearmed_libretro.dll"
#Rom Directory = D:\Files\Roms\PSX
#.bat directory = D:\Files\Roms\Batch Files\PSX
#Additional arguments = --fullscreen
#Saved configuration!
loadedConfig = False
configs = {}
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
if os.path.exists(os.getcwd()+"/batGenConfigs.json"):
with open(os.getcwd()+'/batGenConfigs.json', 'r') as fp:
configs = json.load(fp)
print("Found saved configurations for the following systems:")
for key in configs.keys():
print(key)
userInput = input("Would you like to run any of these configurations? (y/n): ")
if userInput.lower() == "y":
while True:
userInput = input("Please type the name of the system you wish to use: ")
if userInput in configs.keys():
emulator = configs[userInput]["emulator"]
romExt = configs[userInput]["romExt"]
romDir = configs[userInput]["romDir"]
batDir = configs[userInput]["batDir"]
postfix = configs[userInput]["postfix"]
loadedConfig = True
input("settings loaded, press any key to continue.")
break
else:
print("Invalid system name")
else:
print("Skipping")
emulator = input("Please enter the command-line launch command for your emulator (MUST have quotes around paths): ")
romExt = input("Please enter the extension of the rom files (with period): ")
romDir = input("Please enter the rom directory: ")
batDir = input("Please enter the directory that the bat files will be stored (WILL OVERWRITE ANY BATS INSIDE IT): ")
postfix = input("Please enter any additional arguments that come after the path to rom file (hit enter if none): ")
else:
emulator = input("Please enter the command-line launch command for your emulator (MUST have quotes around paths): ")
romExt = input("Please enter the extension of the rom files (with period): ")
romDir = input("Please enter the rom directory: ")
batDir = input("Please enter the directory that the bat files will be stored (WILL OVERWRITE ANY BATS INSIDE IT): ")
postfix = input("Please enter any additional arguments that come after the path to rom file (hit enter if none)")
os.chdir(romDir)
for file in glob.glob("*"+romExt):
strippedFileName = file.rsplit( ".", 1 )[ 0 ]
f = open(batDir+"/"+strippedFileName+".bat", "w")
f.write(emulator+" \""+os.path.abspath(file)+"\" "+postfix)
f.close()
print("Processed "+file)
if not loadedConfig:
userInput = input("Would you like to save these settings for later? This will create a json file in the same location as this script(y/n): ")
if userInput.lower() == "y":
systemName = input("please enter the name of the system you wish to save: ")
configs[systemName] = {
"emulator":emulator,
"romExt":romExt,
"romDir":romDir,
"batDir":batDir,
"postfix":postfix
}
print("Name = "+systemName+"\nEmulator command = "+emulator+"\nRom Directory = "+romDir+"\n.bat directory = "+batDir+"\nAdditional arguments = "+postfix)
os.chdir(dname)
with open(os.getcwd()+'\\batGenConfigs.json', 'w') as fp:
json.dump(configs, fp, indent = 4)
input("Finished! Click any key to quit.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment