#!/bin/bash

###uncomment below if required software not on system
#sudo apt-get install -y mame-tools p7zip-full

readonly cue="$1"
readonly destdir="$2"

# procesa el fitxer

  readonly gameName="$(basename "$cue" .cue)"

  if [ -f  "${destdir}/${gameName}.chd" ]; then
    echo -e "\e[1m\e[41m${gameName}.chd already exists\033[0m"
  else
    echo -e "\e[1m\e[41mProcessing ${gameName}...\033[0m"
    chdman createcd -i "${cue}" -o "${destdir}/${gameName}.chd"
  fi

  echo "!!!!!!!!!!${gameName} complete..."
