Last active
January 8, 2024 23:17
-
-
Save zambonin/bf4f60699c74e13aa4e77ad0be214dee to your computer and use it in GitHub Desktop.
Compare two directories with GSBA files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# | |
# A POSIX-compliant shell script that compares the contents of GSBA files, | |
# created by the GameSave Manager [1] Windows application. Such files are | |
# essentially ZIP files with a GSM_INFO.xml metadata descriptor. | |
# | |
# The script accepts two directories as the arguments; the first is treated as | |
# containing "old" files, and the second, the "new" files. Only games in the | |
# second directory are compared with their counterparts. | |
# | |
# [1] https://www.gamesave-manager.com/ | |
OLD_FILES_DIR="$(readlink -f "$1")" | |
NEW_FILES_DIR="$(readlink -f "$2")" | |
if [ ! -d "$OLD_FILES_DIR" ] || [ ! -d "$NEW_FILES_DIR" ] ; then | |
exit 1 | |
fi | |
OLD_FILES="$(mktemp -d --suffix="-old")" | |
NEW_FILES="$(mktemp -d --suffix="-new")" | |
find "$NEW_FILES_DIR" -type f -iname "*.gsba" -printf "%p\n" \ | |
| sort -u \ | |
| while IFS= read -r NEW_FILE_PATH ; do | |
GAME_NAME="$(basename "$NEW_FILE_PATH" \ | |
| awk -F"_" '{print $1}' \ | |
| sort -u)" | |
OLD_FILE_PATH="$(find "$OLD_FILES_DIR" -type f -iname "$GAME_NAME*.gsba" \ | |
| sort -u \ | |
| head -1)" | |
if [ -n "$OLD_FILE_PATH" ] ; then | |
unzip -q "$OLD_FILE_PATH" -d "$OLD_FILES" -x GSM_INFO.xml | |
else | |
mkdir "$OLD_FILES" | |
fi | |
unzip -q "$NEW_FILE_PATH" -d "$NEW_FILES" -x GSM_INFO.xml | |
DIFF="$(diff --brief --recursive --text "$OLD_FILES" "$NEW_FILES")" | |
if [ -n "$DIFF" ] ; then | |
echo "$GAME_NAME" | |
echo "$DIFF" | |
echo | |
fi | |
rm -rf "$OLD_FILES" "$NEW_FILES" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment