#!/bin/bash
#
# Sparky-IA is a simply tool which lets you play old games
# in a web browser via Internet Archive
#
# Created by Paweł "pavroo" Pijanowski 2015/05/31
# Copyright 2015-2024 under the GNU GPL2 License
# Last update 2024/08/22

# get default's locale file
DEFLOCDIR="/usr/share/sparky/sparky-ia"
if [ "`cat /etc/default/locale | grep LANG= | grep de`" != "" ]; then
. $DEFLOCDIR/de
elif [ "`cat /etc/default/locale | grep LANG= | grep el`" != "" ]; then
. $DEFLOCDIR/el
elif [ "`cat /etc/default/locale | grep LANG= | grep es`" != "" ]; then
	if [ "`cat /etc/default/locale | grep LANG= | grep es_AR`" != "" ]; then
. $DEFLOCDIR/es_AR
	else
. $DEFLOCDIR/es_ES
	fi
elif [ "`cat /etc/default/locale | grep LANG= | grep fi`" != "" ]; then
. $DEFLOCDIR/fi
elif [ "`cat /etc/default/locale | grep LANG= | grep fr`" != "" ]; then
. $DEFLOCDIR/fr
elif [ "`cat /etc/default/locale | grep LANG= | grep hu`" != "" ]; then
. $DEFLOCDIR/hu
elif [ "`cat /etc/default/locale | grep LANG= | grep id_ID`" != "" ]; then
. $DEFLOCDIR/id_ID
elif [ "`cat /etc/default/locale | grep LANG= | grep it`" != "" ]; then
. $DEFLOCDIR/it
elif [ "`cat /etc/default/locale | grep LANG= | grep ja`" != "" ]; then
. $DEFLOCDIR/ja
elif [ "`cat /etc/default/locale | grep LANG= | grep pl`" != "" ]; then
. $DEFLOCDIR/pl
elif [ "`cat /etc/default/locale | grep LANG= | grep pt_BR`" != "" ]; then
. $DEFLOCDIR/pt_BR
elif [ "`cat /etc/default/locale | grep LANG= | grep pt_PT`" != "" ]; then
. $DEFLOCDIR/pt_PT
elif [ "`cat /etc/default/locale | grep LANG= | grep ru`" != "" ]; then
. $DEFLOCDIR/ru
elif [ "`cat /etc/default/locale | grep LANG= | grep sv`" != "" ]; then
. $DEFLOCDIR/se
elif [ "`cat /etc/default/locale | grep LANG= | grep uk`" != "" ]; then
. $DEFLOCDIR/uk
else
. $DEFLOCDIR/en
fi

DIALOG="yad --window-icon=applications-games --image=applications-games --width=400 --height=270 --image-on-top --icons"
DIALOG450="yad --window-icon=applications-games --image=applications-games --width=450 --height=300 --center"
TITLE="--title="
TEXT="--text="
WINDOWTEXT="$LOCAL1"
TITLETEXT="Internet Archive Games"
DIRS="--read-dir=/usr/lib/sparky-ia --item-width=100 --sort-by-name --center"
NOBUTTONS="--no-buttons"
MSGBOX="--button=Ok:0"

# check is x-www-browser installed
if [ ! -f /etc/alternatives/x-www-browser ]; then
	$DIALOG450 $TITLE"$TITLETEXT" $TEXT"$LOCAL2" $MSGBOX
	exit 0
else
	$DIALOG $TEXT"$WINDOWTEXT" $DIRS $TITLE"$TITLETEXT" $NOBUTTONS
fi

exit 0
