instant_play save/load

Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
This commit is contained in:
Michel-FK
2021-05-09 23:09:52 +02:00
parent 0d19c7a7f1
commit ee49693543
12 changed files with 69 additions and 47 deletions

View File

@@ -23,6 +23,7 @@ export HOME=/mnt/FunKey
mkdir -p "${HOME}"
export MEDNAFEN_HOME=$HOME/.mednafen
mkdir -p "${MEDNAFEN_HOME}"
cp -n "/usr/games/lynxboot.img" "/usr/games/mednafen-09x.cfg" "${MEDNAFEN_HOME}/"
export GMENU2X_HOME="$HOME/.gmenu2x"
mkdir -p "${GMENU2X_HOME}"
@@ -55,6 +56,9 @@ brightness set $(brightness get) >/dev/null 2>&1
# Start Assembly tests (blocking process)
assembly_tests >/dev/null 2>&1
# Restart saved application/game if any
instant_play load
# Start launcher
echo "Start launcher"
start_launcher >/dev/null 2>&1 &

View File

@@ -3,35 +3,71 @@
# Uncomment the following line to get debug info
#set -x
# Check args
if [ ${#} -eq 0 ]; then
echo "Usage: $(basename ${0}) args..."
SELF="$(basename ${0})"
INSTANT_PLAY_FILE="/mnt/instant_play"
RESUME_PLAY_FILE="/mnt/resume_play"
usage() {
>&2 echo "Usage: ${SELF} load"
>&2 echo " ${SELF} save application args..."
exit 1
}
# Check number of arguments
if [ ${#} -lt 1 ]; then
usage
fi
INSTANT_PLAY_FILE="/mnt/instant_play"
case ${1} in
load)
if [ ${#} -ne 1 ]; then
usage
fi
# Write quick load file args
echo -n "" > "${INSTANT_PLAY_FILE}"
for arg in "$@"; do
if $(echo "${arg}" | egrep -q '[[:space:]]'); then
# Launch Previous Game if any
if [ -f "${INSTANT_PLAY_FILE}" ]; then
keymap resume
echo -n "Found Instant Play file, restarting previous game with command: "
echo $(head -n 1 "${INSTANT_PLAY_FILE}")
rm -f "${RESUME_PLAY_FILE}"
mv "${INSTANT_PLAY_FILE}" "${RESUME_PLAY_FILE}"
source "${RESUME_PLAY_FILE}"
rm -f "${RESUME_PLAY_FILE}"
keymap default
termfix_all
fi
;;
# Add quotes around arguments containing spaces
echo -n "\"${arg}\" " >> "${INSTANT_PLAY_FILE}"
else
echo -n "${arg} " >> "${INSTANT_PLAY_FILE}"
fi
done
save)
if [ ${#} -lt 2 ]; then
usage
fi
shift
# Add the magic sauce to launch the process in background, record the
# PID into a file, wait for the process to terminate and erase the
# recorded PID
cat << EOF >> "${INSTANT_PLAY_FILE}"
# Write quick load file args
echo -n "" > "${INSTANT_PLAY_FILE}"
for arg in "$@"; do
# Add quotes around all arguments
echo -n "'${arg}' " >> "${INSTANT_PLAY_FILE}"
done
# Add the magic sauce to launch the process in background,
# record the PID into a file, wait for the process to
# terminate and erase the recorded PID
cat << EOF >> "${INSTANT_PLAY_FILE}"
&
record_pid \$!
wait \$!
erase_pid
EOF
# Now terminate gracefully
exec shutdown_funkey
# Now terminate gracefully
exec shutdown_funkey
;;
*)
usage
;;
esac
exit 0

View File

@@ -4,8 +4,6 @@
#set -x
LOCK_FILE="/var/lock/launcher.lock"
INSTANT_PLAY_FILE="/mnt/instant_play"
RESUME_PLAY_FILE="/mnt/resume_play"
PREVENT_LAUNCHER_FILE="/mnt/prevent_launcher"
REBOOTING_FILE="/run/rebooting"
@@ -16,22 +14,6 @@ if [ -f "${LOCK_FILE}" ]; then
fi
touch "${LOCK_FILE}"
# Sanity cmd: in case these files do not exist
mkdir -p "${MEDNAFEN_HOME}"
cp "/usr/games/lynxboot.img" "/usr/games/mednafen-09x.cfg" "${MEDNAFEN_HOME}/"
# Launch Previous Game if any
if [ -f "${INSTANT_PLAY_FILE}" ]; then
keymap resume
echo "Found Instant Play file, restarting previous game with command: "$(head -n 1 "${INSTANT_PLAY_FILE}")
rm -f "${RESUME_PLAY_FILE}"
mv "${INSTANT_PLAY_FILE}" "${RESUME_PLAY_FILE}"
source "${RESUME_PLAY_FILE}"
rm -f "${RESUME_PLAY_FILE}"
keymap default
termfix_all
fi
# Then loop to launch the launcher indefinitely
while true; do