tempFolder=./temp/
outputFolder=./output/

rm -rf $tempFolder*
./7za.exe x $1 -otemp
echo Doing image processing...
for i in ${tempFolder}*.png; do
	if [ -e ${i//".png"/"@2x.png"} ]; then
		rm -rf $i
	fi
done
for i in ${tempFolder}*.png; do
	if [ ! $i == "${tempFolder}*.png" ]; then
		if [[ ! $i == *"@2x"* ]]; then
			magick convert -colorspace CIELab $i -filter lanczos -scale 200% -blur 1x8 -sharpen 2x5 -colorspace sRGB ${i//".png"/"@2x.png"}
		else
			magick convert -colorspace CIELab $i -scale 50% -colorspace sRGB ${i//"@2x"/}
		fi
	fi
done
for i in ${tempFolder}*.jpg; do
	if [ ! $i == "${tempFolder}*.jpg" ]; then
		if [[ ! $i == *"@2x"* ]]; then
			magick convert -colorspace CIELab $i -filter lanczos -scale 200% -blur 1x8 -sharpen 2x5 -colorspace sRGB ${i//".jpg"/"@2x.jpg"}
		else
			magick convert -colorspace CIELab $i -scale 50% -colorspace sRGB ${i//"@2x"/}
		fi
	fi
done
echo Doing image compression...
./pingo.exe -s9 ${tempFolder}*.png > /dev/null & 
./pingo.exe -jpgquality=95 ${tempFolder}*.jpg > /dev/null & 
wait
./pingo.exe -s9 ${tempFolder}*/*.png > /dev/null & 
./pingo.exe -jpgquality=95 ${tempFolder}*/*.jpg > /dev/null & 
wait
./pingo.exe -s9 ${tempFolder}*/*/*.png > /dev/null & 
./pingo.exe -jpgquality=95 ${tempFolder}*/*/*.jpg > /dev/null & 
wait
./pingo.exe -s9 ${tempFolder}*/*/*/*.png > /dev/null & 
./pingo.exe -jpgquality=95 ${tempFolder}*/*/*/*.jpg > /dev/null & 
wait
echo Doing audio processing...
for i in ${tempFolder}*.wav; do 
	a=${i%.*}
	if [[ $i = *"drum-"* ]] || [[ $i = *"normal-"* ]] || [[ $i = *"soft-"* ]]; then
		ffmpeg.exe -loglevel panic -y -i -ac 1 $a.wav $a.wav &
	else
		{
		ffmpeg.exe -loglevel panic -y -i $a.wav -ar 44100 -qscale:a 3 -f mp3 $a.mp3
		rm -rf $i
		} &
	fi
done
wait
echo Creating HD/SD...
b=${1//"./input/"/""}
./7za.exe a -tzip -mx9 ${outputFolder}/${b//".osk"/""}/$b ${tempFolder}*
echo Creating HD...
./7za.exe x ${outputFolder}/${b//".osk"/""}/$b -o${outputFolder}/${b//".osk"/""}/temp
for i in ${outputFolder}/${b//".osk"/""}/temp/*@2x*; do
	rm -rf ${i//"@2x"/}
done
./7za.exe a -tzip -mx9 ${outputFolder}/${b//".osk"/""}/hd/$b ${outputFolder}/${b//".osk"/""}/temp/*
rm -rf ${outputFolder}/${b//".osk"/""}/temp/*
echo Creating SD...
./7za.exe x ${outputFolder}/${b//".osk"/""}/$b -o${outputFolder}/${b//".osk"/""}/temp
for i in ${outputFolder}/${b//".osk"/""}/temp/*@2x*; do
	rm -rf $i
done
./7za.exe a -tzip -mx9 ${outputFolder}/${b//".osk"/""}/sd/$b ${outputFolder}/${b//".osk"/""}/temp/*
rm -rf ${outputFolder}/${b//".osk"/""}/temp/
echo FINISHED $b