#!/bin/sh
# Adds Dark Sun to the desktop's application menu (the freedesktop.org menus of GNOME, KDE, Xfce, the Steam Deck's desktop
# mode ...) for this user: a "Dark Sun Shattered Lands Enhanced" entry that opens the launcher. The entry points to this
# folder: run the script again after moving it. Nothing is written outside ~/.local/share/applications. --remove takes it away.
set -e
here=$(cd "$(dirname "$0")" && pwd)
apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
entry="$apps/darksun-enhanced.desktop"

if [ "$1" = "--remove" ]; then
  rm -f "$entry"
  echo "Removed the Dark Sun entry from $apps."
  exit 0
fi

mkdir -p "$apps"
cat > "$entry" <<EOF
[Desktop Entry]
Type=Application
Name=Dark Sun Shattered Lands Enhanced
Comment=Dark Sun: Shattered Lands (1993), enhanced: the launcher, whose Play starts the game
Exec="$here/DarkSun-Launcher"
Path=$here
Terminal=false
Categories=Game;RolePlaying;
EOF
echo "Added $entry"
