@REM
@REM	This file rebuilds our templates from Input.nbh and reconstructs a dump
@REM	created by BuildOS, all the way to a flashable RUU_signed.nbh.
@REM	Thanks to sfaure3, tadzio, and bepe for the the help and awesome tools.
@REM

@echo Rebuilding templates...
@mkdir .\Temp2
@cd .\Temp2
@..\Tools\imgfsfromnb.exe ..\ROM\8004000-OS.nb imgfs.old.bin
@echo .... Done.

@echo Building new imgfs.bin from dump...
@cd ..\Temp
@start /wait ..\Tools\imgfsfromdump.exe ..\Temp2\imgfs.old.bin ..\Temp2\imgfs.bin
@del ..\Temp2\imgfs.old.bin
@echo .... Done.

@echo Building OS-new.nb...
@cd ..\Temp2
@start /wait ..\Tools\imgfstonb.exe imgfs.bin ..\ROM\8004000-OS.nb OS.nb.payload
@del imgfs.bin
@start /wait ..\Tools\nbmerge.exe -titan OS.nb
@del OS.nb.payload
@ren OS.nb OS-new.nb
@cd ..
@mkdir .\Output
@move .\Temp2\OS-new.nb .\Output
@cd .\Output
@echo .... Done.

@echo Building RUU_signed.nbh...
@..\Tools\nbhgen.exe ..\Tools\raphael_nbh.txt
@echo .... Done.

@echo Clean up time!
@cd ..
@rd /s /q .\Temp
@rd /s /q .\Temp2
@move .\Output\RUU_signed.nbh .\RUU
@rd /s /q .\Output
@echo .... Done.

@echo BuildIt is Complete. 
@echo Flash your new RUU_Signed.nbh, and enjoy!
@pause
