#!/bin/bash
# Advanced Loot Rules window (2026-10-03): install the staged DLL and UI files into one client folder
# (default: Trevor's desktop client) for testing on the TEST world. Backups: *.bak-lootrules (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/EQUI.xml uifiles/default/HJ_AdvLootWnd.xml uifiles/default/HJ_AdvLootRulesWnd.xml; do
    if [ $revert = 1 ]; then
        if [ -f "$dst/$f.bak-lootrules" ]; then mv -f "$dst/$f.bak-lootrules" "$dst/$f"; echo "restored $f"
        elif [ "$(basename "$f")" = HJ_AdvLootRulesWnd.xml ]; then rm -f "$dst/$f"; echo "removed $f"; fi
        continue
    fi
    src="$here/$(basename "$f")"
    if [ -f "$dst/$f" ] && [ ! -f "$dst/$f.bak-lootrules" ]; then cp -p "$dst/$f" "$dst/$f.bak-lootrules"; fi
    cp "$src" "$dst/$f.new" && mv -f "$dst/$f.new" "$dst/$f"   # rename: a running client keeps its mapped copy
    echo "installed $f"
done
