#!/bin/bash # Check for Configs STCS_GLOBAL_CONFIG="$HOME/.local/share/CereSaves/stcs-global-config.sh" 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-config.sh" ]; then echo "[CereSaves] Game config not found!" exit 1 fi source "$STCS_GLOBAL_CONFIG" source ./stcs-config.sh 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