mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-15 06:50:32 +00:00
4df7e775f9
Now it just assumes the largest file in the root of the archive is the desired ROM.
83 lines
1.7 KiB
Bash
Executable File
83 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
###
|
|
## Wrapper script that enables loading of compressed roms for RetroArch.
|
|
## Author: Themaister
|
|
## License: Do whatever you want with it.
|
|
#
|
|
|
|
die()
|
|
{
|
|
echo "Error: $1"
|
|
rm "${TMPROM}"
|
|
rm -r "${TMPDIR}"
|
|
exit 1
|
|
}
|
|
|
|
if [ -z "$1" ]; then
|
|
die "Need at least one argument"
|
|
fi
|
|
|
|
COMP_FILE="$1"
|
|
TMPROM="`mktemp`"
|
|
TMPDIR="`mktemp -d`"
|
|
shift
|
|
|
|
extract_zip()
|
|
{
|
|
which unzip >/dev/null 2>&1 || die "Cannot find unzip"
|
|
unzip "$1" -d "${TMPDIR}" >/dev/null 2>&1 || die "Couldn't extract from archive"
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
case "${COMP_FILE}" in
|
|
*.zip )
|
|
extract_zip "${COMP_FILE}"
|
|
EXTENSION=".zip"
|
|
;;
|
|
*.7z )
|
|
extract_7z "${COMP_FILE}"
|
|
EXTENSION=".7z"
|
|
;;
|
|
*.rar )
|
|
extract_rar "${COMP_FILE}"
|
|
EXTENSION=".rar"
|
|
;;
|
|
* )
|
|
die "Couldn't find valid zipped rom."
|
|
;;
|
|
esac
|
|
|
|
# pick the largest non-directory in the root of the unpacked archive
|
|
FILENAME="`ls -Sp \"${TMPDIR}\" | grep -v /$ | head -n1`"
|
|
if [ -z "${FILENAME}" ]; then
|
|
die "Cannot find any files in root of archive"
|
|
fi
|
|
mv "${TMPDIR}/${FILENAME}" "${TMPROM}"
|
|
|
|
SAVENAME="`basename \"${COMP_FILE}\" ${EXTENSION}`"
|
|
DIRNAME="`dirname \"${COMP_FILE}\"`"
|
|
SAVENAME="${SAVENAME}.srm"
|
|
|
|
EXE="`which retroarch`"
|
|
if [ -z "${EXE}" ]; then
|
|
die "Cannot find RetroArch in path."
|
|
fi
|
|
|
|
echo "Temp ROM: ${TMPROM}"
|
|
echo "Savename: ${DIRNAME}/${SAVENAME}"
|
|
"${EXE}" "${TMPROM}" -s "${DIRNAME}/${SAVENAME}" "$@"
|
|
rm "${TMPROM}"
|
|
rm -r "${TMPDIR}"
|
|
|