@echo off
echo Converting ISO to EBOOT...

set CURDIR=%~dp0
cd "%curdir%"
set CURDRIVE=%curdir:~0,2%
%CURDRIVE%

if not {%2}=={} set tmp_folders=%2

set DONOR=
if exist DONOR.PBP set DONOR=DONOR.PBP

set DonorSize=
FOR %%A IN (%DONOR%) DO set DonorSize=%%~zA
if "%DonorSize%"=="" set DonorSize=139952128

set iso=NP
set pbp=EBOOT.PBP
if exist "%1" copy /y "%1" NP.ISO
if exist NP.ISO (goto :compress_yes)

set /p iso=Input ISO name WITHOUT extension (hit ENTER to use 'NP.ISO'): 
if {%iso%}=={} (set iso=NP)
if not exist %iso%.iso goto NoIso
set /p pbp=Input output name WITH extension (hit ENTER to use recommended name 'EBOOT.PBP'): 
if /i {%pbp%}=={} (set pbp=EBOOT.PBP)
:compression
SET /P ANSWER=Do you want to enable compression of output EBOOT? (Y/N): 
if /i {%ANSWER%}=={} (set ANSWER=y)
if /i {%ANSWER%}=={y} (goto :compress_yes)
if /i {%ANSWER%}=={yes} (goto :compress_yes)
if /i {%ANSWER%}=={n} (goto :compress_no)
if /i {%ANSWER%}=={no} (goto :compress_no)

:compress_yes

FOR %%A IN (%iso%.iso) DO set size=%%~zA

if %size% LEQ 139952128 (
copy tools\fake_np_small.exe .\fake_np.exe >nul
set DONOR=
) else if %size% LEQ %DonorSize% (
copy tools\fake_np_small.exe .\fake_np.exe >nul
) else (
copy tools\fake_np.exe .\fake_np.exe >nul
set DONOR=
)

fake_np -c %DONOR% %iso%.iso %pbp%
del fake_np.exe>nul
if not exist "%pbp%" goto NoPBP
echo Creating EBOOT.PBP Done! As %pbp% (Compression enabled)
if exist "EBOOT.PBP" ("CEX.bat")
exit

:compress_no

if %size% LEQ 139952128 (
copy tools\fake_np_small.exe .\fake_np.exe >nul
set DONOR=
) else if %size% LEQ %DonorSize% (
copy tools\fake_np_small.exe .\fake_np.exe >nul
) else (
copy tools\fake_np.exe .\fake_np.exe >nul
set DONOR=
)

fake_np %DONOR% %iso%.iso %pbp%
del fake_np.exe>nul
if not exist "%pbp%" goto NoPBP
echo Creating EBOOT.PBP Done! As %pbp% (Compression disabled)
if exist "EBOOT.PBP" ("CEX.bat")
exit

:NoPBP
echo ERROR: %pbp% was not created.
pause
exit

:NoIso
cls
echo ERROR: Please enter the name of the ISO to be converted to PBP.
pause
exit
