@echo ------- Free MC Boot loader v 1.953 multi region/model full installation ------------------- original script ^& applications by jimmikaelkael et al. ------------------------------- updated for SP193^'s FMCB v 1.953 by Yuki -------------------

:: sign the kelfs/kirx for the memory card
@echo Signing FMCB kelf...
@ps3mca-tool.exe -k fmcb-install\SYSTEM\FMCB.XLF fmcb-install\SYSTEM\osdmain.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to sign FMCB kelf
	@goto end)
@echo Signing osd110 kelf...
@ps3mca-tool.exe -k fmcb-install\SYSTEM\OSD110.XLF fmcb-install\SYSTEM\osd110.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to sign osd110 kelf
	@goto end)
@echo Signing OSDSYS update kelf...
@ps3mca-tool.exe -k fmcb-install\SYSTEM\OSDSYS.XLF fmcb-install\SYSTEM\osdsys.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to sign OSDSYS update kelf
	@goto end)
@echo Signing DVD kirx...
@ps3mca-tool.exe -k fmcb-install\SYSTEM\ENDVDPL.XRX fmcb-install\SYS-CONF\endvdpl.irx > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to sign DVD kirx
	@goto end)

@echo Creating necessary directories...
@ps3mca-tool.exe -mkdir /APPS > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create 'APPS' directory
	@goto end)
@ps3mca-tool.exe -mkdir /BOOT > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create 'BOOT' directory
	@goto end)
@ps3mca-tool.exe -mkdir /BAEXEC-SYSTEM > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create 'BAEXEC-SYSTEM' directory
	@goto end)
@ps3mca-tool.exe -mkdir /BCEXEC-SYSTEM > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create 'BCEXEC-SYSTEM' directory
	@goto end)
@ps3mca-tool.exe -mkdir /BEEXEC-SYSTEM > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create 'BEEXEC-SYSTEM' directory
	@goto end)
@ps3mca-tool.exe -mkdir /BIEXEC-SYSTEM > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create 'BIEXEC-SYSTEM' directory
	@goto end)
@ps3mca-tool.exe -mkdir /SYS-CONF > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create 'SYS-CONF' directory
	@goto end)

:: copy the signed kelfs/kirx to mc
@echo Copying signed FMCB kelf...
@ps3mca-tool.exe -in fmcb-install\SYSTEM\osdmain.elf /BIEXEC-SYSTEM/osdmain.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy signed FMCB kelf
	@goto end)
@echo Copying signed osd110 kelf...
@ps3mca-tool.exe -in fmcb-install\SYSTEM\osd110.elf /BIEXEC-SYSTEM/osd110.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy signed osd110 kelf
	@goto end)
@echo Copying signed OSDSYS update kelf...
@ps3mca-tool.exe -in fmcb-install\SYSTEM\osdsys.elf /BIEXEC-SYSTEM/osdsys.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy signed OSDSYS update kelf
	@goto end)
@echo Copying signed DVD kirx...
@ps3mca-tool.exe -in fmcb-install\SYS-CONF\endvdpl.irx /SYS-CONF/endvdpl.irx > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy signed DVD kirx
	@goto end)

:: write all required files
@echo Copying default configuration file...
@ps3mca-tool.exe -in fmcb-install\SYS-CONF\FREEMCB.CNF /SYS-CONF/FREEMCB.CNF > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy default configuration file
	@goto end)
@echo Copying FMCB configurator...
@ps3mca-tool.exe -in fmcb-install\SYS-CONF\FMCB_CFG.ELF /SYS-CONF/FMCB_CFG.ELF > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy FMCB configurator
	@goto end)
@echo Copying HDD modules...
@ps3mca-tool.exe -in fmcb-install\SYSTEM\atad.irx /BIEXEC-SYSTEM/atad.irx > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'atad.irx'
	@goto end)
@ps3mca-tool.exe -in fmcb-install\SYSTEM\hddload.irx /BIEXEC-SYSTEM/hddload.irx > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'hddload.irx'
	@goto end)
@echo Copying USB modules...
@ps3mca-tool.exe -in fmcb-install\SYS-CONF\USBD.IRX /SYS-CONF/USBD.IRX > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'USBD.IRX'
	@goto end)
@ps3mca-tool.exe -in fmcb-install\SYS-CONF\USBHDFSD.IRX /SYS-CONF/USBHDFSD.IRX > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'USBHDFSD.IRX'
	@goto end)
@echo Copying FMCB icons...
@ps3mca-tool.exe -in fmcb-install\SYSTEM\icon.sys /BIEXEC-SYSTEM/icon.sys > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'icon.sys'
	@goto end)
@ps3mca-tool.exe -in fmcb-install\SYSTEM\FMCB.icn /BIEXEC-SYSTEM/FMCB.icn > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'FMCB.icn'
	@goto end)
@echo Copying APPS folder icons...
@ps3mca-tool.exe -in fmcb-install\APPS\icon.sys /APPS/icon.sys > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'icon.sys'
	@goto end)
@ps3mca-tool.exe -in fmcb-install\APPS\FMCBapps.icn /APPS/FMCBapps.icn > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'FMCBapps.icn'
	@goto end)
@echo Copying BOOT folder icons...
@ps3mca-tool.exe -in fmcb-install\BOOT\icon.sys /BOOT/icon.sys > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'icon.sys'
	@goto end)
@ps3mca-tool.exe -in fmcb-install\BOOT\BOOT.icn /BOOT/BOOT.icn > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'BOOT.icn'
	@goto end)
@echo Copying SYS-CONF folder icons...
@ps3mca-tool.exe -in fmcb-install\SYS-CONF\icon.sys /SYS-CONF/icon.sys > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'icon.sys'
	@goto end)
@ps3mca-tool.exe -in fmcb-install\SYS-CONF\sysconf.icn /SYS-CONF/sysconf.icn > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy 'sysconf.icn'
	@goto end)

:: write external homebrew apps
@echo Copying wLaunchELF...
@ps3mca-tool.exe -in fmcb-install\BOOT\BOOT.ELF /BOOT/BOOT.ELF > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy wLaunchELF
	@goto end)
@echo Copying ESR...
@ps3mca-tool.exe -in fmcb-install\BOOT\ESR.ELF /BOOT/ESR.ELF > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy ESR
	@goto end)
@echo Copying ESR GUI...
@ps3mca-tool.exe -in fmcb-install\APPS\ESRGUI.ELF /APPS/ESRGUI.ELF > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy ESR GUI
	@goto end)
@echo Copying OPL...
@ps3mca-tool.exe -in fmcb-install\APPS\OPL.ELF /APPS/OPL.ELF > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy OPL
	@goto end)
@echo Copying SMS...
@ps3mca-tool.exe -in fmcb-install\APPS\SMS.ELF /APPS/SMS.ELF > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy SMS
	@goto end)
@echo Copying Power Off elf...
@ps3mca-tool.exe -in fmcb-install\APPS\OFF.ELF /APPS/OFF.ELF > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy Power Off elf
	@goto end)

@echo Cross-linking files for multi region/model installation...
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/osdmain.elf /BAEXEC-SYSTEM/osd120.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BAEXEC-SYSTEM/osd120.elf'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/osdmain.elf /BAEXEC-SYSTEM/osd130.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BAEXEC-SYSTEM/osd130.elf'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/osdmain.elf /BAEXEC-SYSTEM/osdmain.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BAEXEC-SYSTEM/osdmain.elf'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/osdmain.elf /BCEXEC-SYSTEM/osdmain.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BCEXEC-SYSTEM/osdmain.elf'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/osdmain.elf /BEEXEC-SYSTEM/osd130.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BEEXEC-SYSTEM/osd130.elf'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/osdmain.elf /BEEXEC-SYSTEM/osdmain.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BEEXEC-SYSTEM/osdmain.elf'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/osdmain.elf /BIEXEC-SYSTEM/osd130.elf > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BIEXEC-SYSTEM/osd130.elf'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/icon.sys /BAEXEC-SYSTEM/icon.sys > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BAEXEC-SYSTEM/icon.sys'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/FMCB.icn /BAEXEC-SYSTEM/FMCB.icn > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BAEXEC-SYSTEM/FMCB.icn'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/icon.sys /BCEXEC-SYSTEM/icon.sys > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BCEXEC-SYSTEM/icon.sys'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/FMCB.icn /BCEXEC-SYSTEM/FMCB.icn > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BCEXEC-SYSTEM/FMCB.icn'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/icon.sys /BEEXEC-SYSTEM/icon.sys > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BEEXEC-SYSTEM/icon.sys'
	@goto end)
@ps3mca-tool.exe -cl /BIEXEC-SYSTEM/FMCB.icn /BEEXEC-SYSTEM/FMCB.icn > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to create link '/BEEXEC-SYSTEM/FMCB.icn'
	@goto end)

@echo Copying Install Log...
@ps3mca-tool.exe -in fmcb-install\SYS-CONF\FMCBUINST.dat /SYS-CONF/FMCBUINST.dat > nul
@if ERRORLEVEL 1 (
	@echo ERROR: failed to copy Install Log
	@goto end)

@echo Installation complete!

:end

@echo Deleting temporary files...
@del fmcb-install\SYSTEM\osdmain.elf fmcb-install\SYSTEM\osd110.elf fmcb-install\SYSTEM\osdsys.elf fmcb-install\SYS-CONF\endvdpl.irx > nul

@pause
