2024-07-08 05:29:39 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Check for Configs
|
|
|
|
STCS_GLOBAL_CONFIG="$HOME/.local/share/CereSaves/stcs-global-config.sh"
|
2024-07-08 07:42:47 +00:00
|
|
|
|
|
|
|
if [ -z ${STCS_GAME_CONFIG+x} ]; then
|
|
|
|
echo "[CereSaves] Game config not defined, trying default!";
|
|
|
|
STCS_GAME_CONFIG="./stcs-config.sh"
|
|
|
|
else
|
|
|
|
echo "[CereSaves] Game config is set to '$STCS_GAME_CONFIG'";
|
|
|
|
fi
|
2024-07-08 05:29:39 +00:00
|
|
|
|
|
|
|
if [ ! -f "$STCS_GLOBAL_CONFIG" ]; then
|
2024-07-08 05:35:35 +00:00
|
|
|
echo "[CereSaves] Global config not found!"
|
2024-07-08 05:29:39 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# TODO - find a way to make this not a static filename, for multiple games in one folder.
|
2024-07-08 07:42:47 +00:00
|
|
|
if [ ! -f "$STCS_GAME_CONFIG" ]; then
|
2024-07-08 05:35:35 +00:00
|
|
|
echo "[CereSaves] Game config not found!"
|
2024-07-08 05:29:39 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
source "$STCS_GLOBAL_CONFIG"
|
2024-07-08 07:42:47 +00:00
|
|
|
source "$STCS_GAME_CONFIG"
|
2024-07-08 05:29:39 +00:00
|
|
|
|
|
|
|
STCS_CACHED_TIMESTAMP_PATH="${STCS_TIMESTAMPS_DIR}/${STCS_GAMENAME}.timestamp"
|
|
|
|
STCS_SYNCED_TIMESTAMP_PATH="${STCS_SAVEGAME_SYNCDIR}/${STCS_GAMENAME}.timestamp"
|
|
|
|
STCS_SYNCED_SAVADATA_PATH="${STCS_SAVEGAME_SYNCDIR}/${STCS_GAMENAME}"
|
|
|
|
|
|
|
|
prelaunch () {
|
|
|
|
echo "[CereSaves] prelaunch start"
|
|
|
|
if checkpretimestamps; then
|
|
|
|
# Assume Save Data needs to be restored!
|
|
|
|
if [ -f "$STCS_SAVEPATH" ]; then
|
|
|
|
#echo "Savedata $STCS_SAVEPATH is a file!"
|
|
|
|
cp "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)" "$STCS_SAVEPATH"
|
|
|
|
fi
|
|
|
|
if [ -d "$STCS_SAVEPATH" ]; then
|
|
|
|
#echo "Savedata $STCS_SAVEPATH is a folder!"
|
|
|
|
rsync -az "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" "$STCS_SAVEPATH/"
|
|
|
|
fi
|
|
|
|
cp "$STCS_SYNCED_TIMESTAMP_PATH" "$STCS_CACHED_TIMESTAMP_PATH"
|
|
|
|
fi
|
|
|
|
echo "[CereSaves] prelaunch complete"
|
|
|
|
}
|
|
|
|
|
|
|
|
postlaunch () {
|
|
|
|
echo "[CereSaves] postlaunch start"
|
|
|
|
# Create Backup Dir if it doesn't exist.
|
|
|
|
if [ ! -d "$STCS_SYNCED_SAVADATA_PATH" ]; then
|
|
|
|
mkdir "$STCS_SYNCED_SAVADATA_PATH"
|
|
|
|
fi
|
|
|
|
# Back up Save Data
|
|
|
|
if [ -f "$STCS_SAVEPATH" ]; then
|
|
|
|
#echo "Savedata $STCS_SAVEPATH is a file!"
|
|
|
|
cp "$STCS_SAVEPATH" "$STCS_SYNCED_SAVADATA_PATH/"
|
|
|
|
fi
|
|
|
|
if [ -d "$STCS_SAVEPATH" ]; then
|
|
|
|
#echo "Savedata $STCS_SAVEPATH is a folder!"
|
|
|
|
if [ -d "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/" ]; then
|
|
|
|
mkdir "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/"
|
|
|
|
fi
|
|
|
|
rsync -az "$STCS_SAVEPATH/" "$STCS_SYNCED_SAVADATA_PATH/$(basename $STCS_SAVEPATH)/"
|
|
|
|
fi
|
|
|
|
date +%s > "$STCS_SYNCED_TIMESTAMP_PATH"
|
|
|
|
echo "[CereSaves] postlaunch complete"
|
|
|
|
}
|
|
|
|
|
|
|
|
checkpretimestamps () {
|
|
|
|
if [ ! -f "$STCS_CACHED_TIMESTAMP_PATH" ]; then
|
|
|
|
# Cached timestamp does not exist.
|
|
|
|
echo "1" > $STCS_CACHED_TIMESTAMP_PATH
|
|
|
|
elif [ ! -f "$STCS_SYNCED_TIMESTAMP_PATH" ]; then
|
|
|
|
# Synced timestamp does not exist
|
|
|
|
echo "0" > $STCS_SYNCED_TIMESTAMP_PATH
|
|
|
|
fi
|
|
|
|
if [ $(cat "$STCS_SYNCED_TIMESTAMP_PATH") -gt $(cat "$STCS_CACHED_TIMESTAMP_PATH") ]; then
|
|
|
|
# Update Needed!
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
prelaunch
|
|
|
|
exec "$@"
|
|
|
|
postlaunch
|