#!/bin/bash
# Deb Exploder, extract the content of a Debian Package.
# Concept and Testing by Glen MacArthur, coded by Google Gemini 3.

TARGET_DEB="$1"

# 1. Logic Check
if [ -z "$TARGET_DEB" ] || [ ! -f "$TARGET_DEB" ]; then
    yad --error --center --width=350 --title="Exploder Error!" \
        --text="No valid .deb file selected."
    exit 1
fi

# 2. Setup Paths
DIR="${TARGET_DEB%%.deb}"

# 3. The Extraction Process
if mkdir -p "$DIR/DEBIAN" && dpkg -x "$TARGET_DEB" "$DIR" && dpkg -e "$TARGET_DEB" "$DIR/DEBIAN"; then
    yad --info --center --width=480 \
        --title="Debian Package Exploder" \
        --window-icon="/usr/local/share/icons/custom/debexploder.png" \
        --image="/usr/local/share/icons/custom/debexploder-app.png" \
        --text="<b>Deb Exploded Successfully!</b>\n\nExtracted to:\n$DIR" \
        --button="OK:0"
    
    # Optional: Open the directory in e_fm after success
    # enlightenment_remote -desktop-show-dir "$DIR"
else
    yad --error --center --width=350 \
        --title="Exploder Error!" \
        --window-icon="error" \
        --image="error" \
        --text="Failed to unpack ${TARGET_DEB##*/}"
fi