2011-03-20 12:40:01 +00:00
|
|
|
#!/bin/sh
|
2011-03-20 18:46:04 +00:00
|
|
|
###
|
2011-03-20 20:46:34 +00:00
|
|
|
## Wrapper script that enables loading of compressed roms for SSNES.
|
2011-03-20 18:46:04 +00:00
|
|
|
## Author: Themaister
|
|
|
|
## License: Do whatever you want with it.
|
|
|
|
#
|
2011-03-20 12:40:01 +00:00
|
|
|
|
|
|
|
die()
|
|
|
|
{
|
|
|
|
echo "Error: $1"
|
2011-03-20 18:16:22 +00:00
|
|
|
rm "$TMPROM"
|
|
|
|
rm -r "$TMPDIR"
|
2011-03-20 12:40:01 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
die "Need at least one argument"
|
|
|
|
fi
|
|
|
|
|
|
|
|
COMP_FILE="$1"
|
|
|
|
TMPROM="`mktemp`"
|
2011-03-20 18:16:22 +00:00
|
|
|
TMPDIR="`mktemp -d`"
|
2011-03-20 12:40:01 +00:00
|
|
|
shift
|
|
|
|
|
|
|
|
extract_zip()
|
|
|
|
{
|
2011-03-20 18:16:22 +00:00
|
|
|
which unzip >/dev/null 2>&1 || die "Cannot find unzip"
|
|
|
|
which zipinfo >/dev/null 2>&1 || die "Cannot find zipinfo"
|
|
|
|
FILENAME="`zipinfo -1 \"$1\" | grep '\.s[mf]c$' | head -n1`"
|
|
|
|
if [ -z "$FILENAME" ]; then
|
|
|
|
die "Cannot find .smc nor .sfc file in archive"
|
2011-03-20 12:40:01 +00:00
|
|
|
fi
|
|
|
|
|
2011-03-20 18:46:04 +00:00
|
|
|
unzip -p "$1" "$FILENAME" > "$TMPROM"
|
2011-03-20 18:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extract_7z()
|
|
|
|
{
|
|
|
|
which 7z >/dev/null 2>&1 || die "Cannot find 7z"
|
|
|
|
7z x "$1" -o"$TMPDIR" >/dev/null 2>&1 || die "Couldn't extract from archive"
|
|
|
|
FILENAME="`ls \"$TMPDIR\" | grep '\.s[mf]c$' | head -n1`"
|
2011-03-20 12:40:01 +00:00
|
|
|
if [ -z "$FILENAME" ]; then
|
|
|
|
die "Cannot find .smc nor .sfc file in archive"
|
|
|
|
fi
|
|
|
|
|
2011-03-20 18:16:22 +00:00
|
|
|
mv "${TMPDIR}/${FILENAME}" "$TMPROM"
|
2011-03-20 12:40:01 +00:00
|
|
|
}
|
|
|
|
|
2011-03-20 18:46:04 +00:00
|
|
|
extract_rar()
|
|
|
|
{
|
|
|
|
which unrar >/dev/null 2>&1 || die "Cannot find unrar"
|
|
|
|
unrar x "$1" "$TMPDIR" >/dev/null 2>&1 || die "Couldn't extract from archive"
|
|
|
|
FILENAME="`ls \"$TMPDIR\" | grep '\.s[mf]c$' | head -n1`"
|
|
|
|
if [ -z "$FILENAME" ]; then
|
|
|
|
die "Cannot find .smc nor .sfc file in archive"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mv "${TMPDIR}/${FILENAME}" "$TMPROM"
|
|
|
|
}
|
|
|
|
|
2011-03-20 12:40:01 +00:00
|
|
|
case "$COMP_FILE" in
|
|
|
|
*.zip )
|
2011-03-20 18:46:04 +00:00
|
|
|
extract_zip "$COMP_FILE"
|
2011-03-20 12:40:01 +00:00
|
|
|
EXTENSION=".zip"
|
|
|
|
;;
|
2011-03-20 18:16:22 +00:00
|
|
|
*.7z )
|
2011-03-20 18:46:04 +00:00
|
|
|
extract_7z "$COMP_FILE"
|
2011-03-20 18:16:22 +00:00
|
|
|
EXTENSION=".7z"
|
|
|
|
;;
|
2011-03-20 18:46:04 +00:00
|
|
|
*.rar )
|
|
|
|
extract_rar "$COMP_FILE"
|
|
|
|
EXTENSION=".rar"
|
|
|
|
;;
|
2011-03-20 12:40:01 +00:00
|
|
|
* )
|
|
|
|
die "Couldn't find valid zipped rom."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
SAVENAME="`basename \"$COMP_FILE\" $EXTENSION`"
|
|
|
|
DIRNAME="`dirname \"$COMP_FILE\"`"
|
|
|
|
SAVENAME="${SAVENAME}.srm"
|
|
|
|
echo "Savename: ${DIRNAME}/${SAVENAME}"
|
|
|
|
|
|
|
|
SSNES_PATH="`which ssnes`"
|
|
|
|
if [ -z "$SSNES_PATH" ]; then
|
|
|
|
die "Cannot find SSNES in path."
|
|
|
|
fi
|
|
|
|
|
|
|
|
"$SSNES_PATH" "$TMPROM" -s "${DIRNAME}/${SAVENAME}" "$@"
|
2011-03-20 18:16:22 +00:00
|
|
|
rm "$TMPROM"
|
|
|
|
rm -r "$TMPDIR"
|