@Echo Off

Echo multiMAN_FCEU90000_RomPacker - by ozayturay (aka Simon) of SimJoy Software
Echo.

If [%1]==[] GoTo Usage

Set BATFOLDER=%~dp0
Set ROMFOLDER=%~n1
Set TITLEID=FCEU90000
Set UNRAR=%BATFOLDER%UnRAR.exe
Set SONY_KEYS=%BATFOLDER%BatchTemp/.ps3
Set PACKAGE=%BATFOLDER%BatchTemp\psn_package_npdrm.exe
Set FINALIZE=%BATFOLDER%BatchTemp\package_finalize.exe

If Exist "UP0001-%TITLEID%_00-0000000000000000.pkg" Erase "UP0001-%TITLEID%_00-0000000000000000.pkg"
If Exist "multiMAN %ROMFOLDER% (Unsigned).pkg" Erase "multiMAN %ROMFOLDER% (Unsigned).pkg"
If Exist "multiMAN %ROMFOLDER% (Signed).pkg" Erase "multiMAN %ROMFOLDER% (Signed).pkg"
If Exist "%BATFOLDER%BatchTemp" RmDir /s /q "%BATFOLDER%BatchTemp"

If Not Exist "%BATFOLDER%BatchTemp" MkDir "%BATFOLDER%BatchTemp"
"%UNRAR%" x "%BATFOLDER%PS3Tools.rar" "%BATFOLDER%BatchTemp"
Echo.
Dir /b %1\*.* > "multiMAN %ROMFOLDER% (List).txt"
XCopy %1\*.* "%BATFOLDER%BatchTemp\%TITLEID%\USRDIR\roms\*.*" /e /y
"%UNRAR%" x "%BATFOLDER%ParamFCEU90000.rar" "%BATFOLDER%BatchTemp\%TITLEID%"

Echo Content-ID = UP0001-%TITLEID%_00-0000000000000000 > "%BATFOLDER%BatchTemp\%TITLEID%.conf"
Echo k_licensee = 0x00000000000000000000000000000000 >> "%BATFOLDER%BatchTemp\%TITLEID%.conf"
Echo DRM_Type = Free >> "%BATFOLDER%BatchTemp\%TITLEID%.conf"
Echo Content_Type = GameData >> "%BATFOLDER%BatchTemp\%TITLEID%.conf"
Echo PackageVersion = 01.00 >> "%BATFOLDER%BatchTemp\%TITLEID%.conf"

"%PACKAGE%" "%BATFOLDER%BatchTemp/%TITLEID%.conf" "%BATFOLDER%BatchTemp/%TITLEID%"
Copy "UP0001-%TITLEID%_00-0000000000000000.pkg" "multiMAN %ROMFOLDER% (Unsigned).pkg"

"%FINALIZE%" "UP0001-%TITLEID%_00-0000000000000000.pkg"
Rename "UP0001-%TITLEID%_00-0000000000000000.pkg" "multiMAN %ROMFOLDER% (Signed).pkg"

Echo.
Pause

Echo.
Echo Deleting Temporary Files
Echo.
If Exist "UP0001-%TITLEID%_00-0000000000000000.pkg" Del "UP0001-%TITLEID%_00-0000000000000000.pkg"
If Exist "%BATFOLDER%BatchTemp" RmDir /s /q "%BATFOLDER%BatchTemp"

GoTo End

:Usage
Echo Usage: multiMAN_FCEU90000_RomPacker RomFolderName
Echo.
Echo Example: multiMAN_FCEU90000_RomPacker "FCEU90000 Sample Roms (USA)"
Echo.
Echo PS: You can also drag the rom folder to the batch file. ;)
Echo.
Pause

:End
