@echo off
REM :::: Set echo to off, and clean out variables
title "AutoPopstation3"
echo Starting AutoPopstation3
echo Popstation, created by Dark_Alex
echo docmaker, created by Dark_Alex
echo PSP DocMaker (GUI), created by TheNameless (http://www.svensoftware.de)
echo ISO Producer, created by Jens Duttke (http://www.emucheater.com/)
echo ISO Producer, created by Aldo Vargas (http://www.aldostools.com/)
echo popstrip, created by flatwhatson (http://tinyurl.com/szret)
echo Pete's PSX CDR Plugin, created by... umm... Pete. (http://www.pbernert.com/html/cdr.htm)
echo AutoPopstation.Bat, created by TheAceOfFire (http://theaceoffire.8k.com)
echo Checking all files present...
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:top
cls
REM :::: Check that files are here, move them to CoreData if not there already.
set fail=false
set retry=false
IF EXIST CoreData\Check.bat (
call CoreData\Check.bat Ask.bat
call CoreData\Check.bat BASE.PBP
call CoreData\Check.bat BASE2.exe
call CoreData\Check.bat BASE3.dat
call CoreData\Check.bat cdr.dll
call CoreData\Check.bat cdrPeops.dll
call CoreData\Install.bat cygwin1.dll
call CoreData\Install.bat cygz.dll
call CoreData\Check.bat docmaker.exe
call CoreData\Check.bat Install.bat
call CoreData\Check.bat ISOProducer.exe
call CoreData\Check.bat MoveNew.bat
call CoreData\Check.bat KEYS.BIN
call CoreData\Check.bat popstrip.exe
call CoreData\Check.bat PSPDocMaker.exe
)ELSE echo Check.bat not found.
if '%fail%'=='true' goto failed
if '%retry%'=='true' goto top

cls
REM :::: Make sure to clean out the variables, just in case.
set targetISO= 
set name=
set gameCode=
set compress=
set confirm=
set docmaker=0

REM :::: If there are no images, offer a chance to make an ISO.
IF NOT EXIST *.iso IF NOT EXIST *.bin goto ISOchoice

REM :::: Moved all the asking crud to this file, for simplicity.
call CoreData\Ask.bat
if '%confirm%'=='Q' goto end 
if '%confirm%'=='q' goto end
if '%confirm%'=='Y' goto moveon 
if '%confirm%'=='y' goto moveon
if '%confirm%'=='n' (
cls
goto noISO)
goto top

:moveon
cls

REM :::: Based on what they picked, either do it auto or launch the GUI.
echo Creating Tutorial...
if '%docmaker%'=='0' (CoreData\docmaker.exe %gameCode% CoreData\DocmakerImages\) else (
echo Press any key to start PSP DocMaker.
echo Save the Document.dat file to the same folder as AutoPopstation3.bat.
CoreData\PSPDocMaker.exe)

REM :::: JUst in case, move file to CoreData, check for new stuff in wrong place.
call CoreData\MoveNew.bat DOCUMENT.DAT
call CoreData\MoveNew.bat PIC0.PNG
call CoreData\MoveNew.bat PIC1.PNG
call CoreData\MoveNew.bat ICON0.PNG
call CoreData\MoveNew.bat ICON1.PMF
call CoreData\MoveNew.bat SND0.AT3
echo.

echo Converting %targetISO%
echo.
cd CoreData
BASE2.exe "%name%" %gameCode% %compress% .\..\%targetISO%
cd..

REM :::: create folder, move files.
IF NOT EXIST CoreData\EBOOT.PBP goto failed
echo Moving completed files to Result
IF NOT EXIST Result\%targetISO% mkdir Result\%targetISO%
move CoreData\EBOOT.PBP Result\%targetISO%\EBOOT.PBP
copy CoreData\KEYS.BIN Result\%targetISO%\KEYS.BIN
IF EXIST CoreData\DOCUMENT.DAT (move CoreData\DOCUMENT.DAT Result\%targetISO%\DOCUMENT.DAT) else (copy Base3.DAT Result\DOCUMENT.DAT)
echo Files moved successfully to Result\%targetISO%!
echo To play this game, move the folder %targetISO% to (/psp/game/).
pause
start Result\
goto last





:ISOchoice
set Mytemp='1' or
echo There is no ISO or BIN file to convert into an EBOOT.PBP
echo.
echo What would you like to do?
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo 1} Create an ISO from a CD?
echo 2} Extract the ISO from EBOOT.PBP?
echo  }[EBOOT.PBP Must be in same folder as AutoPopstation3.bat]
echo  }[If EBOOT.PBP is not a PSX game, this will not work]
echo Q} Quit?
echo.
set confirm=
set /p confirm=Please enter '1', '2' or 'Q'=
if '%confirm%'=='1' goto noISO
if '%confirm%'=='2' goto noISO2
goto last





:noISO
REM :::: Give instructions for burning ISO. If it already asked them once, skip to end.
cls
if '%checking%'=='4' goto last
echo Note: Please read this.
echo If you see a popup with -1, that is normal. 
echo You just need to configure the plugin, you only need to do this once.
echo.
echo 1. Once the program starts, click on "Configure Program"
echo.
echo 2. Change the interface to "W2K/XP - 10CTL scsi commands"
echo.
echo 3. Change Drive to your drive.
echo.
echo 4. Change Read mode to "BE_2(ATAPI SPEC 2)"
echo.
echo 5. Change Subchannel reading to "Read subchannels".
echo.
echo ^_^ There ya go! Save the ISO to the same folder as AutoPopstation3.bat please.
CoreData\ISOProducer.exe
if not exist *.iso set checking=4
goto top




:noISO2
REM :::: Give instructions for extracting ISO from EBOOT.PBP
cls
if NOT EXIST EBOOT.PBP (
echo There is no EBOOT.PBP in the same folder as AutoPopstation3.bat.
echo Press any key to go back to main menu.
echo.
pause
goto top
)
if '%checking%'=='3' goto last
echo Please enter the name of the ISO to be extracted:
echo.
echo {Example, FFVIII.iso or Spyro.iso}
set Mytemp=
set /p Mytemp=Please enter FULL ISO name=
CoreData\popstrip.exe -o %Mytemp% EBOOT.PBP
if not exist *.iso set checking=3
goto top




:failed
REM :::: Explain possible reasons for failure.
echo EBOOT.PBP was not created, an error occured.
echo.
echo Try the following:
echo Get a copy of HotShot's 2 Golf's eboot, rename it to BASE.PBP
echo Get a copy of HotShot's 2 Golf's KEYS.BIN
echo Move both above files to the same folder as "AutoPopstation3.bat"
echo Input the correct name of the ISO
echo Move ISO to same folder as "AutoPopstation3.bat"
echo Make sure your BASE.PBP is 143 MB (150,733,537 bytes)
echo Ask for help at http://psp3d.com

:last
echo.
pause