Skip to content

Commit

Permalink
Merge pull request #3 from hiulit/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
hiulit authored Sep 12, 2018
2 parents 2d9bb94 + f8e4310 commit 766597c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

* Up to date

## [2.1.0] - 2018-09-12

### Added

* Dialog asking if the user wants to restart EmulationStation when the script is done.
* Output message for the games that will be shown in the 'last played' section.

### Fixed

* When there are duplicated <lastplayed> tags in different games the script crashes. Now, if the scripts find duplicates, it looks for the game's name (it should be different).

## [2.0.0] - 2018-09-07

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Retropie Limit Last Played Games

A tool for RetroPie to limit the number of 'last played' games.

## Installation
Expand Down
38 changes: 28 additions & 10 deletions retropie-limit-last-played-games.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@ function create_gamelist_xml_backup() {

function get_sorted_lastplayed() {
check_lastplayed_exists
while read -r line; do
if [[ -n "$line" ]]; then
# Add only the 'last played' games with a 'playcount' greater than 0.
if [[ "$(xmlstarlet sel -t -v "/gameList/game[lastplayed='$line']/playcount" -n "$(dirname "$gamelist_path")/gamelist.xml")" -ne 0 ]]; then
last_played_array+=("$line")
fi
while read -r last_played_line; do
if [[ -n "$last_played_line" ]]; then
while read -r game_line; do
# Add only the 'last played' games with a 'playcount' greater than 0.
if [[ "$(xmlstarlet sel -t -v "/gameList/game[name='$game_line']/playcount" -n "$(dirname "$gamelist_path")/gamelist.xml")" -ne 0 ]]; then
last_played_array+=("$game_line")
fi
done < <(xmlstarlet sel -t -v "/gameList/game[lastplayed='$last_played_line']/name" -n "$(dirname "$gamelist_path")/gamelist.xml")
fi
done < <(sort -r <(xmlstarlet sel -t -v "/gameList/game/lastplayed" -n "$(dirname "$gamelist_path")/gamelist.xml"))
done < <(sort -u -r <(xmlstarlet sel -t -v "/gameList/game/lastplayed" -n "$(dirname "$gamelist_path")/gamelist.xml"))
}


Expand All @@ -142,15 +144,23 @@ function reset_playcount() {
fi
echo "> Removing the 'last played' games surplus for '$system' ..."
if [[ "$NTH_LAST_PLAYED" -lt "${#last_played_array[@]}" ]]; then
# Games to remove.
for last_played_item in "${last_played_array[@]:$NTH_LAST_PLAYED}"; do
local game_name
game_name="$(xmlstarlet sel -t -v "/gameList/game[lastplayed='$last_played_item']/name" -n "$(dirname "$gamelist_path")/gamelist.xml")"
game_name="$last_played_item"
log "- $game_name ... removed successfully!"
if [[ "$DEBUG_FLAG" -eq 0 ]]; then
xmlstarlet ed -L -u "/gameList/game[lastplayed[contains(text(),'$last_played_item')]]/playcount" -v "0" "$(dirname "$gamelist_path")/gamelist.xml"
xmlstarlet ed -L -u "/gameList/game[name[contains(text(),'$game_name')]]/playcount" -v "0" "$(dirname "$gamelist_path")/gamelist.xml"
fi
done
echo "> Done!"
# Games to show in 'last played' section.
log "Games that will be shown in the 'last played' section:"
for last_played_item in "${last_played_array[@]:0:$NTH_LAST_PLAYED}"; do
local game_name
game_name="$last_played_item"
log "- $game_name"
done
elif [[ "$NTH_LAST_PLAYED" -eq "${#last_played_array[@]}" ]]; then
log "WHOOPS! There $is_are already only ${#last_played_array[@]} $game_s in '$system'. Nothing do to here ..."
else
Expand Down Expand Up @@ -310,7 +320,7 @@ function main() {
fi
log "Number of 'last played' games to limit is set to '$NTH_LAST_PLAYED'."
for system in "${SYSTEMS[@]}"; do
last_played_array=()
local last_played_array=()

log
underline "$system"
Expand Down Expand Up @@ -339,6 +349,14 @@ function main() {
text+="Check the log file in '$LOG_DIR'."
dialog_msgbox "Info" "$text" "$dialog_height"
fi
# Check if EmulationStation is running
if pidof emulationstation > /dev/null; then
dialog_yesno "Info" "In order to see the changes applied to the game lists, EmulationStation need to be restarted.\n\nWould you like to restart EmulationStation?"
local return_value="$?"
if [[ "$return_value" -eq "$DIALOG_OK" ]]; then
restart_ES
fi
fi
}

main "$@"
7 changes: 7 additions & 0 deletions utils/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ function is_retropie() {
[[ -d "$RP_DIR" && -d "$home/.emulationstation" && -d "/opt/retropie" ]]
}

function restart_ES() {
local restart_file="/tmp/es-restart"
touch "$restart_file"
chown -R "$user":"$user" "$restart_file"
kill $(pidof emulationstation)
}


function log() {
if [[ "$GUI_FLAG" -eq 1 ]]; then
Expand Down
15 changes: 15 additions & 0 deletions utils/dialogs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ function dialog_msgbox() {
--msgbox "$2" "$dialog_height" "$dialog_width" 2>&1 >/dev/tty
}

function dialog_yesno() {
local title="$1"
local message="$2"
local dialog_height="$3"
local dialog_width="$4"
[[ -z "$title" ]] && echo "ERROR: '${FUNCNAME[0]}' needs a title as an argument!" && exit 1
[[ -z "$message" ]] && echo "ERROR: '${FUNCNAME[0]}' needs a message as an argument!" && exit 1
[[ -z "$dialog_height" ]] && dialog_height=8
[[ -z "$dialog_width" ]] && dialog_width="$DIALOG_WIDTH"
dialog \
--backtitle "$DIALOG_BACKTITLE" \
--title "$1" \
--yesno "$2" "$dialog_height" "$dialog_width" 2>&1 >/dev/tty
}


function dialog_choose_nth() {
local nth
Expand Down

0 comments on commit 766597c

Please sign in to comment.