Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Commit

Permalink
fixed hang in Random Game.pak
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Inman committed Oct 22, 2022
1 parent 3580395 commit d21dbcd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion extras/Tools/Random Game.pak/launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@

# TODO: write a daemon that binds this to Y?

say "Finding a random game..."
sleep 1

cd $SDCARD_PATH
ROMS="$SDCARD_PATH/Roms"
FILE="$ROMS"
LOOPS=0
while :; do
if [[ ! -d "$FILE" ]]; then
break
fi

LINES=`find "$FILE" -maxdepth 1 -not -path '*/.*'`
TOTAL=`echo -n "$LINES" | grep -c '^'`
if [[ "$TOTAL" -le "1" ]]; then # the current directory seems to be listed first
FILE="$ROMS" # take it again from the top?
LOOPS=`expr ${LOOPS} + 1`
if [[ "$LOOPS" -ge "16" ]]; then
FILE=""
break
fi
fi

R=`expr ${RANDOM} % ${TOTAL} + 1`
FILE=`echo "$LINES" | head -n $R | tail -1`

Expand All @@ -29,6 +42,14 @@ while :; do
fi
done

if [[ -z "$FILE" ]]; then
show okay.png
say "Could not find any games."$'\n'"(Too many empty folders?)"$'\n'
sleep 0.1
confirm only
exit
fi

# the shell isn't liking parameter expansion
# when the var contains spaces so we have to
# pop the directories manually
Expand Down Expand Up @@ -57,4 +78,4 @@ if [[ -f "$SDCARD_PATH/Emus/${EMU_TAG}.pak/launch.sh" ]]; then
"$SDCARD_PATH/Emus/${EMU_TAG}.pak/launch.sh" "$FILE"
elif [[ -f "$SDCARD_PATH/.system/paks/Emus/${EMU_TAG}.pak/launch.sh" ]]; then
"$SDCARD_PATH/.system/paks/Emus/${EMU_TAG}.pak/launch.sh" "$FILE"
fi
fi
1 change: 1 addition & 0 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Please see the README.txt in the zip file for installation and update instructions.

-
- extras: fixed hang in Random Game.pak (it could get lost in empty folders, poor guy)

-------------------------------

Expand Down

0 comments on commit d21dbcd

Please sign in to comment.