#!/bin/bash
# TBC Guild - WoW Combat Log Clearer for Mac
# This script clears your WoWCombatLog.txt file even while WoW is running
# Save this to your Desktop, make it executable, and double-click before raids

echo "========================================"
echo "  WoW Combat Log Clearer"
echo "  HYDRA Guild"
echo "========================================"
echo ""

# Common WoW installation paths for Mac (Wine/CrossOver)
COMMON_PATHS=(
    "$HOME/Library/Application Support/CrossOver/Bottles/TurtleWoW/drive_c/Games/TurtleWoW/Logs/WoWCombatLog.txt"
    "$HOME/.wine/drive_c/Games/TurtleWoW/Logs/WoWCombatLog.txt"
    "$HOME/Games/TurtleWoW/Logs/WoWCombatLog.txt"
)

LOG_PATH=""

# Try to find the log file
for path in "${COMMON_PATHS[@]}"; do
    if [ -f "$path" ]; then
        LOG_PATH="$path"
        break
    fi
done

if [ -z "$LOG_PATH" ]; then
    echo "Could not automatically find WoWCombatLog.txt"
    echo ""
    echo "Please enter the full path to your WoWCombatLog.txt file:"
    echo "Example: ~/Library/Application Support/CrossOver/Bottles/.../WoWCombatLog.txt"
    echo ""
    read -p "Path: " LOG_PATH

    if [ ! -f "$LOG_PATH" ]; then
        echo ""
        echo "Error: File not found at: $LOG_PATH"
        echo ""
        read -p "Press Enter to exit..."
        exit 1
    fi
fi

# Get file size before clearing
FILE_SIZE=$(stat -f%z "$LOG_PATH" 2>/dev/null || stat -c%s "$LOG_PATH" 2>/dev/null)
FILE_SIZE_MB=$(echo "scale=2; $FILE_SIZE / 1048576" | bc)

echo "Found log file: $LOG_PATH"
echo "Current size: ${FILE_SIZE_MB} MB"
echo ""
echo "Clearing log file..."

# Clear the file (this works even while WoW is running)
> "$LOG_PATH"

if [ $? -eq 0 ]; then
    echo ""
    echo "Success! Log file cleared."
    echo "Old size: ${FILE_SIZE_MB} MB -> New size: 0 KB"
    echo ""
    echo "You can now start a fresh combat log in-game with /combatlog"
else
    echo ""
    echo "Error: Failed to clear log file."
    echo "The file may be locked. Try closing WoW first."
fi

echo ""
read -p "Press Enter to exit..."
