#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

#Checking if wine is installed
if ! command -v wine &>/dev/null ; then
  echo 'Wine Is Not Installed'
  #Installing wine
  $DIRECTORY/manage install 'Wine (x86)' || error 'Failed to install wine'
fi


#Removing any files which were created by corrupted installation
rm -rf npp.zip ~/Notepad++

#Downloading npp files
wget https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v7.9.4/npp.7.9.4.portable.zip -O npp.zip || error 'Failed to download npp files'
#Extracting npp files
unzip npp.zip -d ~/Notepad++ || error 'Failed to extract npp archive'
#Removing npp archive
rm npp.zip 

#Creating Desktop Entry
echo "[Desktop Entry]
Name=Notepad++
Comment=Notepad++ is a free source code editor and Notepad replacement that supports several languages.
Exec=wine '$HOME/Notepad++/notepad++.exe'
Icon=$(dirname "$0")/icon-64.png
Terminal=false
StartupNotify=true
Type=Application
Categories=Utility;" > ~/.local/share/applications/notepad++.desktop || error "Failed to create menu button!"


