Skip to content

Instantly share code, notes, and snippets.

@dvessel
Last active January 5, 2021 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvessel/bdbeeba754948640ad2e3f7a770d052a to your computer and use it in GitHub Desktop.
Save dvessel/bdbeeba754948640ad2e3f7a770d052a to your computer and use it in GitHub Desktop.
Shell functions for scanning/repairing MAME ROMs for OpenEmu on a Mac. Copy into your .zshrc file. Not tested on bash.
# advscan MAME roms/disks/samples scans and repairs.
function oemame.scan {
local command=${@:-scan}
local base_dir=$HOME/Library/Application\ Support/OpenEmu
local version=${${${:-`defaults read \
$base_dir/Cores/MAME.oecoreplugin/Contents/Info.plist CFBundleVersion`
}/./}%%.*}
# Go back to current directory when done.
# advscan can't resolve paths when run outside advscan.rc.
trap "cd `pwd`" INT TERM EXIT
if [[ ! -e $base_dir/AdvanceScan ]]; then
echo Setting up AdvanceScan...
mkdir -p $base_dir/AdvanceScan && cd "$_" && open .
mkdir -p _import _unknown/roms _unknown/disks _unknown/samples ../MAME/samples
ln -s ../Game\ Library/roms/Arcade roms && ln -s ../MAME/samples samples
cat <<-EOF > advscan.rc
rom_import _import
rom_new roms
rom roms
disk roms
sample samples
rom_unknown _unknown/roms
disk_unknown _unknown/disks
sample_unknown _unknown/samples
EOF
else
cd $base_dir/AdvanceScan
fi
if [[ ! -f mame${version}.xml ]]; then
if [[ ! -f $TMPDIR/mame${version}lx.zip ]]; then
curl -Lo $TMPDIR/mame${version}lx.zip \
https://github.com/mamedev/mame/releases/download/mame${version}/mame${version}lx.zip
fi
unzip $TMPDIR/mame${version}lx.zip -d ./
fi
# @todo
# AdvanceScan will not read chd files within its own directory.
# Add each sub-directory to the .rc file so it can see them.
# - read advscan.rc
# - get rom directory
# - look for subdirectories with rom directory
# - check for a corresponding zip file
# - add all to the 'disk' entry within advscan.rc
if [[ $command == scan ]]; then
echo Scanning...
# Ignore errors about missing samples and clean excessive output.
# There's a bug where it lists a missing rom as good.
advscan -rkspP < mame${version}.xml 2> >(grep -v sampleof >&2) |
grep -vE "(^game_(rom|disk|sample)_miss|.*\s{6}0\s.*)"
elif [[ $command == repair ]]; then
echo Repairing...
advscan -rksbdutgP < mame${version}.xml 2> >(grep -v sampleof >&2)
elif [[ $command == repair-preview ]]; then
echo "Repairing (preview)..."
advscan -rksbdugtnP < mame${version}.xml 2> >(grep -v sampleof >&2)
else
echo Invalid command.
fi
}
function oemame.repair {
oemame.scan repair
}
function oemame.repair-preview {
oemame.scan repair-preview
}
@dvessel
Copy link
Author

dvessel commented Jan 3, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment