89 lines
No EOL
2.9 KiB
Bash
Executable file
89 lines
No EOL
2.9 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Check for Configs
|
|
STCS_GLOBAL_CONFIG="$HOME/.local/share/CereSaves/stcs-global-config.sh"
|
|
|
|
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
|
|
|
|
if [ ! -f "$STCS_GLOBAL_CONFIG" ]; then
|
|
echo "[CereSaves] Global config not found!"
|
|
exit 1
|
|
fi
|
|
|
|
# TODO - find a way to make this not a static filename, for multiple games in one folder.
|
|
if [ ! -f "$STCS_GAME_CONFIG" ]; then
|
|
echo "[CereSaves] Game config not found!"
|
|
exit 1
|
|
fi
|
|
|
|
source "$STCS_GLOBAL_CONFIG"
|
|
source "$STCS_GAME_CONFIG"
|
|
|
|
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 | tee "$STCS_SYNCED_TIMESTAMP_PATH"
|
|
echo "[CereSaves] postlaunch complete"
|
|
}
|
|
|
|
checkpretimestamps () {
|
|
if [ ! -f "$STCS_CACHED_TIMESTAMP_PATH" ]; then
|
|
# Cached timestamp does not exist.
|
|
echo "1" | tee "$STCS_CACHED_TIMESTAMP_PATH"
|
|
fi
|
|
if [ ! -f "$STCS_SYNCED_TIMESTAMP_PATH" ]; then
|
|
# Synced timestamp does not exist
|
|
echo "0" | tee "$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 |