commit 1775358a9c0e95444aea8b8eb21a884946196bbf Author: Cere Date: Mon Jul 8 01:29:39 2024 -0400 Initial Push diff --git a/README.md b/README.md new file mode 100644 index 0000000..b75c653 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# CereSaves +~~(aka Syncthing-CloudSaves)~~ + +This is a basic little wrapper utility that automatically checks to see if newer savedata exists in some sort of synced directory, and automatically loads in any newer data it finds. + +Obviously this is a WIP and not very good, but I wanted a quick and dirty cloud saves solution for non-steam games. + +## Installation +```bash +git clone repo_url_here.git +cd reponame +``` +Edit `stcs-global-config.sh` +* `STCS_SAVEGAME_SYNCDIR` should point to the folder being synced by your syncing solution of choice (ie Syncthing, Resilio Sync, etc) +* `STCS_TIMESTAMPS_DIR` should point to a local directory to store a timestamp of each game that's backed up. + +```bash +mkdir ~/.local/share/CereSaves/ +cp stcs-global-config.sh ~/.local/share/CereSaves/ +cp stcs-wrapper.sh ~/.local/bin # Or anywhere else on the $PATH +mkdir "$HOME/.local/share/CereSaves/Timestamps" # Or whatever you changed the value of STCS_TIMESTAMPS_DIR to be +``` + +## Usage +* Place a copy of `stcs-config.sh.example` next to the game being executed. +* Edit the file, removing the `.example` and filling out the gamename and the location of the savedata to back up. (It can be a file or folder of savedata) +* Prefix any launch command you wish to invoke with `stcs-wrapper.sh`, similar to how you'd load `mangohud`! \ No newline at end of file diff --git a/stcs-config.sh.example b/stcs-config.sh.example new file mode 100644 index 0000000..eae79dd --- /dev/null +++ b/stcs-config.sh.example @@ -0,0 +1,4 @@ +#!/bin/bash + +export STCS_GAMENAME="GameName Goes Here" +export STCS_SAVEPATH="/path/to/SaveData" diff --git a/stcs-global-config.sh b/stcs-global-config.sh new file mode 100644 index 0000000..67b7dd1 --- /dev/null +++ b/stcs-global-config.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +export STCS_SAVEGAME_SYNCDIR="$HOME/.savesync" +export STCS_TIMESTAMPS_DIR="$HOME/.local/share/CereSaves/Timestamps" diff --git a/stcs-wrapper.sh b/stcs-wrapper.sh new file mode 100644 index 0000000..63b4679 --- /dev/null +++ b/stcs-wrapper.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# Check for Configs +STCS_GLOBAL_CONFIG="$HOME/.local/share/CereSaves/stcs-global-config.sh" + +if [ ! -f "$STCS_GLOBAL_CONFIG" ]; then + echo "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 "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 \ No newline at end of file