This commit is contained in:
Themaister 2011-03-20 19:16:22 +01:00
parent de30ce9ef5
commit 37c0b49a99

View File

@ -3,6 +3,8 @@
die() die()
{ {
echo "Error: $1" echo "Error: $1"
rm "$TMPROM"
rm -r "$TMPDIR"
exit 1 exit 1
} }
@ -12,25 +14,31 @@ fi
COMP_FILE="$1" COMP_FILE="$1"
TMPROM="`mktemp`" TMPROM="`mktemp`"
TMPDIR="`mktemp -d`"
shift shift
extract_zip() extract_zip()
{ {
ZIP_LOC="`which unzip`" which unzip >/dev/null 2>&1 || die "Cannot find unzip"
ZIPINFO_LOC="`which zipinfo`" which zipinfo >/dev/null 2>&1 || die "Cannot find zipinfo"
if [ -z "$ZIP_LOC" ]; then FILENAME="`zipinfo -1 \"$1\" | grep '\.s[mf]c$' | head -n1`"
die "Cannot find location of unzip"
fi
if [ -z "$ZIPINFO_LOC" ]; then
die "Cannot find location of zipinfo"
fi
FILENAME="`$ZIPINFO_LOC -1 \"$1\" | grep '\.s[mf]c$' | head -n1`"
if [ -z "$FILENAME" ]; then if [ -z "$FILENAME" ]; then
die "Cannot find .smc nor .sfc file in archive" die "Cannot find .smc nor .sfc file in archive"
fi fi
$ZIP_LOC -p "$1" "$FILENAME" > "$2" unzip -p "$1" "$FILENAME" > "$2"
}
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`"
if [ -z "$FILENAME" ]; then
die "Cannot find .smc nor .sfc file in archive"
fi
mv "${TMPDIR}/${FILENAME}" "$TMPROM"
} }
case "$COMP_FILE" in case "$COMP_FILE" in
@ -38,6 +46,10 @@ case "$COMP_FILE" in
extract_zip "$COMP_FILE" "$TMPROM" extract_zip "$COMP_FILE" "$TMPROM"
EXTENSION=".zip" EXTENSION=".zip"
;; ;;
*.7z )
extract_7z "$COMP_FILE" "$TMPROM"
EXTENSION=".7z"
;;
* ) * )
die "Couldn't find valid zipped rom." die "Couldn't find valid zipped rom."
;; ;;
@ -54,4 +66,5 @@ if [ -z "$SSNES_PATH" ]; then
fi fi
"$SSNES_PATH" "$TMPROM" -s "${DIRNAME}/${SAVENAME}" "$@" "$SSNES_PATH" "$TMPROM" -s "${DIRNAME}/${SAVENAME}" "$@"
rm -f "$TMPROM" rm "$TMPROM"
rm -r "$TMPDIR"