Skip to content

Commit

Permalink
Merge pull request #6 from hiulit/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
hiulit authored Sep 20, 2018
2 parents 4448072 + 3d105b4 commit add12cc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
logs/
logs/
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@

* Up to date

## [2.1.2] - 2018-09-20

### Fixed

* Escape special characters function.

### Added

* Validate XML function.

## [2.1.1] - 2018-09-13

## Fixed
### Fixed

* Issue with duplicate game names but different `<lastplayed>` tags in `gamelist.xml`. Now the script takes both the game name and its `<lastplayed>` tag to avoid duplicates. **If there are more than one game with same name and `<lastplayed>` tag, the script won't work.**
* Escape game names with single quotes in `gamelist.xml`.
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ You can help make **RetroPie Limit Last Played Games** better by [reporting issu

* Fork **RetroPie Limit Last Played Games**: `git clone git@github.com:your-username/RetroPie-Limit-Last-Played-Games.git`.
* Create a **new branch** and make the desired changes there.
* [Create a pull request](https://github.com/hiulit/RetroPie-Limit-Last-Played-Games/pulls).
* [Create a pull request](https://github.com/hiulit/RetroPie-Limit-Last-Played-Games/pulls).
39 changes: 34 additions & 5 deletions retropie-limit-last-played-games.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,24 @@ source "$SCRIPT_DIR/utils/dialogs.sh"

# Functions ######################################

function escape_ampersands() {
sed -i 's/&/&amp;/g' "$(dirname "$gamelist_path")/gamelist.xml"
function escape_xml() {
if [[ -z "$1" ]]; then
echo "ERROR: '$FUNCNAME' needs an XML as an argument!" >&2
exit 1
fi
xmlstarlet esc "$1" > /dev/null
}


function validate_xml() {
if [[ -z "$1" ]]; then
echo "ERROR: '$FUNCNAME' needs an XML as an argument!" >&2
exit 1
fi
xmlstarlet val "$1" > /dev/null
}


function check_lastplayed_exists() {
if [[ "$(xmlstarlet sel -t -v "/gameList/game/lastplayed" -n "$(dirname "$gamelist_path")/gamelist.xml")" == "" ]]; then
log "ERROR: No <lastplayed> tag found in '"$(dirname "$gamelist_path")/gamelist.xml"'." >&2
Expand All @@ -100,6 +114,23 @@ function find_gamelist_xml() {
else
gamelist_path="$RP_ROMS_DIR/$system/gamelist.xml"
echo "'gamelist.xml' for '$system' found!"

# Escape special characters.
echo "> Escaping special characters for the 'gamelist.xml' for '$system' ..."
if escape_xml "$gamelist_path"; then
echo "Special characters for the 'gamelist.xml' for '$system' escaped successfully!"
else
log "ERROR: Couldn't escape special characters for the 'gamelist.xml' for '$system'." >&2
exit 1
fi
# Validate XML.
echo "> Validating 'gamelist.xml' for '$system' ..."
if validate_xml "$gamelist_path"; then
echo "'gamelist.xml' for '$system' validated successfully!"
else
log "ERROR: Couldn't validate 'gamelist.xml' for '$system'." >&2
exit 1
fi
fi
}

Expand Down Expand Up @@ -132,7 +163,7 @@ function get_sorted_lastplayed() {
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
fi
done < <(sort -u -r <(xmlstarlet sel -t -v "/gameList/game/lastplayed" -n "$(dirname "$gamelist_path")/gamelist.xml"))
}

Expand Down Expand Up @@ -332,8 +363,6 @@ function main() {
underline "$system"
# Find gamelist.xml path.
find_gamelist_xml || continue
# Escape ampersands in gamelist.xml
escape_ampersands || continue
#Create backup for gamelist.xml.
create_gamelist_xml_backup || continue
# Populate array with <lastplayed> tags found and sort them in a descending order.
Expand Down
2 changes: 1 addition & 1 deletion utils/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ function underline() {
[[ "$GUI_FLAG" -eq 1 ]] && log "$message" || echo "$message"
for ((i=1; i<="${#message}"; i+=1)); do [[ -n "$dashes" ]] && dashes+="-" || dashes="-"; done
[[ "$GUI_FLAG" -eq 1 ]] && log "$dashes" || echo "$dashes"
}
}
2 changes: 1 addition & 1 deletion utils/dialogs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@ function dialog_choose_systems() {
elif [[ "$return_value" -eq "$DIALOG_EXTRA" ]]; then
dialog_choose_all_systems_or_systems
fi
}
}

0 comments on commit add12cc

Please sign in to comment.