Initial Push

This commit is contained in:
Cere 2024-07-08 01:29:39 -04:00
commit 1775358a9c
4 changed files with 116 additions and 0 deletions

27
README.md Normal file
View file

@ -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`!

4
stcs-config.sh.example Normal file
View file

@ -0,0 +1,4 @@
#!/bin/bash
export STCS_GAMENAME="GameName Goes Here"
export STCS_SAVEPATH="/path/to/SaveData"

4
stcs-global-config.sh Normal file
View file

@ -0,0 +1,4 @@
#!/bin/bash
export STCS_SAVEGAME_SYNCDIR="$HOME/.savesync"
export STCS_TIMESTAMPS_DIR="$HOME/.local/share/CereSaves/Timestamps"

81
stcs-wrapper.sh Normal file
View file

@ -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