@echo off
echo This program copies all png and jpg elements with "@2x" in their filenames,
echo reduces them to half size, and then renames them to their old name minus "@2x".
echo It will replace original SD elements if they already exist.
echo.
echo WARNING! You need to install ImageMagick for the resize command to work.
echo Otherwise it will just copy and rename the files without resizing.
echo Get it here: http://www.imagemagick.org/script/download.php
echo.
echo Original program by Isamuyaso, edited by Mio Winter.
echo Source: https://osu.ppy.sh/forum/t/354445
echo.
pause

rem Make a temporary directory "SDtemp"
mkdir SDtemp

rem Copy all png and jpg files with "@2x" in their names into "SDtemp".
copy *@2x*.png SDtemp
copy *@2x*.jpg SDtemp

rem Copy all "@2x" png files from the "numbers" directory to the "SDtemp" directory.
copy numbers\*@2x*.png SDtemp

rem Reduce the files to half size, using a command from ImageMagick.
magick mogrify -format png -resize 50%% SDtemp/*@2x*.png
magick mogrify -format jpg -resize 50%% SDtemp/*@2x*.jpg

pushd SDtemp
setlocal enableDelayedExpansion

rem Renames all png files.
for %%a in (*.png) do (
	set "filename=%%~nxa"
	set "purged_filename=!filename:@2x=!"
	ren %%~nxa !purged_filename!
)

for %%a in (*.jpg) do (
	set "filename=%%~nxa"
	set "purged_filename=!filename:@2x=!"
	ren %%~nxa !purged_filename!
)
	
endlocal

rem Move all png and jpg files into the directory above SDtemp.
move *.png ..
move *.jpg ..
popd
rmdir /s /q SDtemp

rem Move all "number" png files back into the "numbers" directory.
move *number*.png numbers

echo.
echo  You may get error messages if you don't have @2x jpg or png files. Just ignore them.
echo.
pause