#!/bin/bash

directory="${PWD}/.painttoolsai"
patchDir="${PWD}/download"
ptsDir="drive_c/Program Files/PaintTool SAI English Pack"

pack="https://lunasqu.ee/public/Linux_PTS/pts_pack.tar"
startScript="https://lunasqu.ee/public/Linux_PTS/start.sh"

cd "${PWD}"

if [ ! -d "$patchDir/" ]; then
	mkdir "$patchDir"
	echo "***  Download: PTS English Pack  ***"
	$(curl "$pack" > "$patchDir/pts_pack.tar")
fi

cd "${PWD}"

if [ ! -d "$directory/" ]; then
	echo "***  Start: wineboot  ***"
	WINEPREFIX="$directory/" WINEARCH=win32 wine wineboot
	echo "***  Start: extracting  ***"
	if [ ! -d "$directory/$ptsDir" ]; then
		mkdir "$directory/$ptsDir"
	fi
	$(tar -x --overwrite -f "$patchDir/pts_pack.tar" -C "$directory/$ptsDir/")
fi

if [ ! -f "${PWD}/start.sh" ]; then
	echo "***  Download: start script  ***"
	$(curl "$startScript" > "${PWD}/start.sh")
	$(chmod +x "${PWD}/start.sh")
fi

echo "************************************"
echo "***"
echo "*** PaintTool SAI installed!"
echo "***"
echo "*** Run ./start.sh to start PTS."
echo "***"
echo "************************************"
echo "***"
echo "*** If you need pen pressure, edit the following file:"
echo "*** $directory/$ptsDir/misc.ini"
echo "*** Go down to line 46 and set TabletMouseSimulation to 1"
echo "***"
echo "*** For usage of Wacom tablets, check out this wiki:"
echo "*** http://linuxwacom.sourceforge.net/wiki/index.php/Wacom_Tablet_Set_Up"
echo "***"
echo "*** Enjoy!"
