@ echo off

setlocal enableDelayedExpansion

:: Shifty's RetroArch Playlist Script

::

:: This script will create per-system ROM playlists, the files used to display system columns in the RetroArch XMB UI

:: It exists to work around the romset checksumming that is forced in the current (1.2.2 at time of writing) build of RetroArch

:: Put simply, this will let you create playlists with ROMs that the Add Content > Scan Directory/File process would usually ignore

::

:: WARNING: This script is not compatible with the Add Content > Scan Directory/File process

:: It will erase existing playlists as part of the generation process, so make sure to back them up beforehand if necessary

:: Change these to point to your RetroArch and top-level ROM directories

set RADir=D:\Emulators\retroarch

set ROMDir=D:\ConsoleGames

:: For each RetroArch core, add one of these blocks below:

:: set RomDirs[n]=

:: set CoreLibs[n]=

:: set CoreNames[n]=

:: set PlaylistNames[n]=

:: set SupportedExtensions[n]=

::

:: The numbers in square brackets need to start at 0, and be incremented by 1 for each block added

:: RomDirs[n] should be set to the ROM subdirectory for this core (ex. "SNES" will cause the script to scan ROMDir\SNES)

:: CoreLibs[n] should be set to the core's DLL filename (in RetroArch\cores)

:: CoreNames[n] should be set to the human-readable name of the RetroArch core (bracketed names in the RetroArch 'Load Core' menu)

:: PlaylistNames[n] should be set to the RetroArch name of this core's platform (look at the icon filenames in RetroArch\assets\xmb\monochrome\png\)

:: SupportedExtensions[n] should be set to the supported extensions for this core, prefixed with the wildcard (*) character (available in the RetroArch Information -> Core Info menu)

::

:: Example Config

:: The config below will create playlist files for SNES, MegaDrive/Genesis and Sega Master System ROMs

::

:: set RomDirs[0]=SNES

:: set CoreLibs[0]=snes9x_next_libretro.dll

:: set CoreNames[0]=Snes9x Next

:: set PlaylistNames[0]=Nintendo - Super Nintendo Entertainment System

:: set SupportedExtensions[0]=*.smc *.fig *.sfc *.gd3 *.gd7 *.dx2 *.bsx *.swc

::

:: set RomDirs[1]=MD

:: set CoreLibs[1]=genesis_plus_gx_libretro.dll

:: set CoreNames[1]=Genesis Plus GX

:: set PlaylistNames[1]=Sega - Mega Drive - Genesis

:: set SupportedExtensions[1]=*.md *.mdx *.gen *.sg *.bin

::

:: set RomDirs[2]=SMS

:: set CoreLibs[2]=genesis_plus_gx_libretro.dll

:: set CoreNames[2]=Genesis Plus GX

:: set PlaylistNames[2]=Sega - Master System - Mark III

:: set SupportedExtensions[2]=*.sms *.bin

:: You can safely ignore everything below here.

echo ============================================

echo Shifty's RetroArch Playlist Script

echo ============================================

echo .

echo Configured Playlists:

set "x=0"

: InfoLoop

if defined RomDirs[ % x % ] (

echo ! PlaylistNames[% x %] !

set /a "x+=1"

GOTO : InfoLoop

)

echo .

PAUSE

echo .

set "x=0"

: MainLoop

if defined RomDirs[ % x % ] (

echo ============================================

echo ! PlaylistNames[% x %] !

echo ============================================

del " % RADir % \playlists\ ! PlaylistNames[% x %] ! .lpl";

echo Deleted % RADir % \playlists\ ! PlaylistNames[% x %] ! .lpl

echo .

echo Entering % ROMDir % \ ! RomDirs[% x %] !

echo .

echo Adding:

pushd " % ROMDir % \ ! RomDirs[% x %] ! "

for /R %% f in (! SupportedExtensions[% x %] !) do (

echo % % ~nf % % ~xf

(

echo %% f

echo % % ~nf

echo % RADir % \cores\ ! CoreLibs[% x %] !

echo ! CoreNames[% x %] !

echo 0 ^| crc

call echo .

) >> " % RADir % \playlists\ ! PlaylistNames[% x %] ! .lpl"

)

popd

echo .

echo Writing % RADir % \playlists\ ! PlaylistNames[% x %] ! .lpl

echo . >> " % RADir % \playlists\ ! PlaylistNames[% x %] ! .lpl"

echo .

set /a "x+=1"

GOTO : MainLoop

)