forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
retroarch-zip
executable file
·95 lines (81 loc) · 2.21 KB
/
retroarch-zip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/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"
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"
fi
# The people who made the [!] naming convention obviously have never used regex ... <_<
FILENAME_FIXED="`echo $FILENAME | sed -e 's|\[|\\\\[|g' -e 's|!|\\\\!|g' -e 's|\]|\\\\]|g'`"
unzip -p "$1" "$FILENAME_FIXED" > "$TMPROM"
}
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"
}
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"
}
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
SAVENAME="`basename \"$COMP_FILE\" $EXTENSION`"
DIRNAME="`dirname \"$COMP_FILE\"`"
SAVENAME="${SAVENAME}.srm"
RetroArch_PATH="`which retroarch`"
if [ -z "$RetroArch_PATH" ]; then
die "Cannot find RetroArch in path."
fi
echo "Temp ROM: $TMPROM"
echo "Savename: ${DIRNAME}/${SAVENAME}"
"$RetroArch_PATH" "$TMPROM" -s "${DIRNAME}/${SAVENAME}" "$@"
rm "$TMPROM"
rm -r "$TMPDIR"