@echo off
REM - Opens a Delphi project in the appropriate IDE
REM - There are the following ways to determine the name of the dproj file:
REM - 1. It can be passed as %1 parameter
REM - 2. If __SetProjectName.cmd exists in the current directory, it gets called
REM -    and should set the %project% environment variable.
REM - 3. It is assumed that the current directory is also the project name (this is probably
REM -    the most common case).
REM - The Delphi version is assumed to be Delphi 2007 unless a __SetDelphiVersion.cmd exists
REM - in the current directory. If it exists, it gets called and is supposed to set the
REM - %DelphiVer% environment variable to one of
REM - 6, 7, 2005, 2006, 2007, 2009, 2010, XE, XE2, XE3, XE4, XE5
setlocal

call %~dp0\_DetermineProject.cmd

set DelphiVer=2007
if exist __SetDelphiVersion.cmd call __SetDelphiVersion.cmd
@rem remove spaces which might have been added in the script
set DelphiVer=%DelphiVer: =%

call %~p0\delphipath.cmd %DelphiVer%

set DPROJ=%project%.%DelphiVer%.dproj
if not exist src\%DPROJ% set DPROJ=%project%.dproj
start "Delphi %DelphiVer%" "%DelphiPath%\bin\bds.exe" -pDelphi src\%DPROJ%
endlocal
goto :eof
