#!/bin/bash
# Power Source progress fill (2026-10-03): install the staged DLL (+ master HJ_HoardWnd.xml) into one client folder (default: Trevor desktop
# client) for testing on the TEST world. Backups: *.bak-psfill (made once).
# Run on the desktop:  bash install_desktop.sh [client_dir]     (after copying this folder there)
# Launch with the "(Direct)" launcher: the Patcher launcher puts the shipped (live) files back.
# Undo: bash install_desktop.sh --revert [client_dir]   (or just run the Patcher launcher once)
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
revert=0; [ "${1:-}" = "--revert" ] && { revert=1; shift; }
dst="${1:-/home/tj/Desktop/everquest_rof2_tanks}"
for f in dinput8.dll uifiles/default/HJ_HoardWnd.xml; do
    if [ $revert = 1 ]; then
        if [ -f "$dst/$f.bak-psfill" ]; then mv -f "$dst/$f.bak-psfill" "$dst/$f"; echo "restored $f"; else echo "no backup of $f"; fi
        continue
    fi
    if [ -f "$dst/$f" ] && [ ! -f "$dst/$f.bak-psfill" ]; then cp -p "$dst/$f" "$dst/$f.bak-psfill"; fi
    cp "$here/$(basename "$f")" "$dst/$f.new" && mv -f "$dst/$f.new" "$dst/$f"   # rename: a running client keeps its mapped copy
    echo "installed $f ($(md5sum < "$dst/$f" | cut -c1-8))"
done
