#!/bin/sh

################################################################################
#      This file is part of LibreELEC - https://libreelec.tv
#      Copyright (C) 2017-present Team LibreELEC
#
#  LibreELEC is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 2 of the License, or
#  (at your option) any later version.
#
#  LibreELEC is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with LibreELEC.  If not, see <http://www.gnu.org/licenses/>.
################################################################################

. /etc/profile

oe_setup_addon tools.comskip

ADDON_SETTINGS="$ADDON_HOME/settings.xml"

INI_DIR_DEFAULT="$ADDON_HOME/ini"
INI_FILE_DEFAULT="$INI_DIR_DEFAULT/comskip.ini"

chmod a+x $ADDON_DIR/bin/*

# copy config files to userdata
if [ ! -f "$INI_FILE_DEFAULT" ]; then
  mkdir -p $INI_DIR_DEFAULT
  cp $ADDON_DIR/defaults/ini/comskip.ini $INI_FILE_DEFAULT
fi

echo "$INI_SELECT"

# check if alternate ini specified
if [ "$INI_SELECT" = "0" ] ; then
  # Use Default INI File
  INI="--ini=$INI_FILE_DEFAULT "
elif [ "$INI_SELECT" = "1" ] && [ "$INI_FILE_ALT" != "" ] ; then
  # Use Alternative INI File
  INI="--ini=$INI_FILE_ALT "
elif [ "$INI_SELECT" = "2" ] ; then
  # Use No INI File
  INI=""
else
  # Use Default INI File as fallback
  INI="--ini=$INI_FILE_DEFAULT "
fi

if [ "$HW_DECODE" = "true" ] ; then
  HW_ASSIST="--hwassist "
fi

exec $ADDON_DIR/bin/comskip.bin "$INI""$HW_ASSIST""$1" "$2" "$3" &>$ADDON_LOG_FILE
