@echo off
echo This script will rebuild your Sonic Colors disc image with translated files
echo Make sure you have at least 10 GiB of free space in the image folder

if [%1]==[] goto usage
goto :repack

:usage
echo.
echo Just drag and drop your ISO image onto this script to create translated one...
goto :finish

:repack
echo.
echo Unpacking image...
"%~dp0tools\wit\bin\wit.exe" EXTRACT %1 "%~dp1unpack"

echo.
echo Unpacking CPK...
cd /D "%~dp1unpack"
if exist DATA cd DATA
cd files
"%~dp0tools\quickbms\quickbms.exe" -o -d "%~dp0tools\quickbms\cpk.bms" sonic2010_0.cpk

echo.
echo Copying files...
xcopy /R /S /Q /Y "%~dp0cpk" sonic2010_0

echo.
echo Repacking CPK...
"%~dp0tools\crifilesystem\cpkmakec.exe" "%~dp0sonic2010_0.csv" sonic2010_0.cpk -mode=FULL -align=64
rem Добавьте -forcecompress для получения сжатого CPK, по-умолчанию отключено ради более быстрой сборки

echo.
echo Rebuilding image...
rmdir /S /Q sonic2010_0
"%~dp0tools\wit\bin\wit.exe" COPY "%~dp1unpack" "%~dp1Sonic Colors (RUS).iso"

echo.
echo Removing temp files...
cd /D %~dp0
rmdir /S /Q "%~dp1unpack"

echo.
echo %~dp1Sonic Colors (RUS).iso is ready!

:finish
pause