#!/bin/bash

#############################
# Start DIMTree.exe with wine
#############################
function fatal(){
 if which notify-send >/dev/null 2>&1; then
  notify-send -i dialog-error -t 10000 "dimtree" "$1";
 fi;
 1>&2 echo "$@";
 exit 1;
};

function launch(){
 "$@" </dev/null >/dev/null 2>&1 & disown;
};

function launch_dimtree(){
 if which wine >/dev/null 2>&1; then
  local scriptfile="${BASH_SOURCE[0]}";
  local scriptFILE="$(realpath $scriptfile)";
  local scriptHOME="$(dirname  $scriptFILE)";
  local dimtreedir="$(realpath $scriptHOME/../bin)";
  if [ -n "$dimtreedir" ] && [ -e "$dimtreedir/" ]; then
   local dimtreeexe="$(find $dimtreedir | grep -i '/dimtree.exe$' | head -n 1)";
   if [ -n "$dimtreeexe" ] && [ -e "$dimtreeexe" ]; then
    echo launch wine $dimtreeexe;
         launch wine $dimtreeexe;
   else
    fatal "Error: DIMTree.exe file not found.";
   fi;
  else
   fatal "Error: DIMTree.exe directory not found.";
  fi;
 else
  fatal "Error: wine is not found.";
 fi;
};

#######
## MAIN
#######

function main(){
 ##################
 ## Execute command
 ##################
 launch_dimtree "$@";
};

main "$@";

##############
## END OF FILE
##############
