Cool guide!
I’ll add a few optimization notes on the AutoHotKey processing in step 4. Your “Friendly Image Renaming Script” copies and renames all of the 36K + 35K images. Overkill since earlier steps filtered out a ton of games. A quicker approach is to loop over roms in the created subfolders and only copy/rename their corresponding images. That would take a bigger rewrite. But here are three quicker tweaks
First put
SetBatchLines -1
at the top of the Friendly Image Renaming Script to increase the script speed, https://autohotkey.com/docs/commands/SetBatchLines.htm
Second slim down the dat file with the below code (takes only a few seconds) and then use “~slim.dat” in Friendly Image Renaming Script instead
SetBatchLines, -1
x = C:\MAME Roms\~MAME - ROMs (v0.176_XML).dat
y = C:\MAME Roms\~slim.dat
Loop, Read, %x%, %y%
{
If (InStr(A_LoopReadLine, "<game name=") or InStr(A_LoopReadLine, "<description>"))
FileAppend %A_LoopReadLine%`n
}
With those two changes to the Friendly Image Renaming Script the time to rename 200 images dropped from 27 to 5-6 seconds. So your one hour might drop to 10-15 minutes or so.
But it gets better. We can filter out some obviously unwanted images before running the Friendly Image Renaming Script. For example the snaps set pS_snap_fullset_170.zip has about 20K snaps with the MAME mechanical/screenless/device placeholder image. We can filter them by filesize and move them to another folder (also only takes a few seconds).
;57825 bytes mechanical 9000 images
;56475 bytes device 2000 images
;56467 bytes device 1000 images
;53466 bytes screenless system 9000 images
;that leaves ~14000 images in pS_snap_fullset_170.zip
FileCreateDir, C:\MAME Roms\~SnapsSkip\
Loop, Files, C:\MAME Roms\~Snaps\*.png
{
FileGetSize, s, % A_LoopFileFullPath
if (s==57825) or (s==56475) or (s==56467) or (s==53466)
FileMove, % A_LoopFileFullPath , C:\MAME Roms\~SnapsSkip\
}
With all these three tweaks applied the Friendly Image Renaming Script took 2 minutes to process the pS_snap_fullset_170.zip on my system.
edit:
Here is Alexandra’s script with these two tweaks added in
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines -1 ;max script speed
;AUTOHOTKEY SCRIPT TO GENERATE FRIENDLY IMAGE NAMES FOR RETROARCH PLAYLIST USE
;"Friendly Image Renaming Script"
;### SETUP, ADD YOUR PATHS HERE
content = C:\MAME Roms\~Snaps
;### Path to folder containing MAME Snap or Title images
destination = C:\MAME Roms\~SnapsFriendly
;### Path to folder where script should place renamed images
dat = C:\MAME Roms\~MAME - ROMs (v0.176_XML).dat
;### path to a MAME ROM database file
;### example C:\files\MAME - ROMs (v0.164_XML).dat
;### get dat here http://www.emulab.it/rommanager/datfiles.php
;### TIP: If you're renaming both Snaps and Titles, make a second copy of this script, point
;### the folder paths at the other image type, and run both at once. You'll save time.
;### slim down the dat file to speed up processing
SplitPath, dat, datfolder
slimdat := datfolder "\~slim.dat"
if !FileExist(datfolder "\~slim.dat")
{
Loop, Read, %dat%, %slimdat%
If (InStr(A_LoopReadLine, "<game name=") or InStr(A_LoopReadLine, "<description>"))
FileAppend %A_LoopReadLine%`n
}
;### filter out unwanted snap png by size in bytes to speed up processing
;57825 bytes mechanical 9000 images
;56475 bytes device 2000 images
;56467 bytes device 1000 images
;53466 bytes screenless system 9000 images
;that leaves ~14000 images in pS_snap_fullset_170.zip
SplitPath, content, contentroot
FileCreateDir, %contentroot%\~SnapsSkip\
Loop, Files, %content%\*.png
{
FileGetSize, s, % A_LoopFileFullPath
if (s==57825) or (s==56475) or (s==56467) or (s==53466)
FileMove, % A_LoopFileFullPath , %contentroot%\~SnapsSkip\
}
;### needed: a version of the above filter/move code for the title png files
FileRead, dat, %slimdat%
Loop, %content%\*.png
{
name := SubStr(A_LoopFileName,1,-4) ;trim .png
needle2 = <game name=.%name%. (isbios|isdevice)
if RegExMatch(dat, needle2)
continue
needle = <game name=.%name%.(?:| ismechanical=.*)(?:| cloneof=.*)(?:| romof=.*)>\R\s*<description>(.*)</description>
RegExMatch(dat, needle, datname)
if !datname1
datname1 := name ;fallback to filename
datname1 := RegExReplace(datname1, "[/\?<>\\:*\|]","") ;replace win forbidden chars
datname1 := RegExReplace(datname1, "'","'") ;may need more replace like this
datname1 := RegExReplace(datname1, "&","&")
;### datname1 := RegExReplace(datname1, " \(.*","") ;trim stuff like "(World version 2.2)"
datname1 := RegExReplace(datname1, "\.$","")
;list = %xx%`n%datname1% ;for troubleshooting
FileCopy, %A_LoopFileFullPath%, %destination%\%datname1%.png
}
;msgbox % list ;for troubleshooting