@echo off

:start
cls
set ccs_dir=%BIOS_INSTALL_DIR:/=\%
if "%ccs_dir%"=="/=\" goto err
if not exist %ccs_dir% goto err
set ccs_bin=%ccs_dir%\..\cc\bin
set ccs_bin_org=%ccs_dir%\..\cc\bin_org
set ccs_bin_wintech=%ccs_dir%\..\cc\bin_wintech
set ccs_xml=%ccs_dir%\..\drivers\TargetDB\connections
set ccs_xml_org=%ccs_dir%\..\drivers\TargetDB\connections_org
set ccs_xml_wintech=%ccs_dir%\..\drivers\TargetDB\connections_wintech

goto choose

:choose
if exist %ccs_bin_wintech% goto link
if exist %ccs_bin_org% goto link
goto update

:update
if exist ccs3.3 cd ccs3.3
xcopy /eyi %ccs_bin% %ccs_bin_wintech%
xcopy /eyi .\bin %ccs_bin_wintech%
xcopy /eyi %ccs_xml% %ccs_xml_wintech%
xcopy /eyi .\xml %ccs_xml_wintech%
goto link

:link
cls
echo Input I to install update packet;
echo Input U to uninstall update packet;
echo Input Q to exit;
echo Install(I),Uninstall(U) or Exit(Q):
set /p IorD=[I,U,Q]?
if "%IorD%" == "I" goto link_to_wintech
if "%IorD%" == "i" goto link_to_wintech
if "%IorD%" == "U" goto delete_check
if "%IorD%" == "u" goto delete_check
if "%IorD%" == "Q" goto end
if "%IorD%" == "q" goto end
goto link

:link_to_wintech
if exist %ccs_bin%\sd560v2u_server.exe goto success
ren %ccs_bin% bin_org
ren %ccs_bin_wintech% bin
ren %ccs_xml% connections_org
ren %ccs_xml_wintech% connections
goto success

:link_to_org
if not exist %ccs_bin%\sd560v2u_server.exe goto success
ren %ccs_bin% bin_wintech
ren %ccs_bin_org% bin
ren %ccs_xml% connections_wintech
ren %ccs_xml_org% connections
goto success

:delete_check
if not exist %ccs_bin%\sd560v2u_server.exe goto delete
ren %ccs_bin% bin_wintech
ren %ccs_bin_org% bin
ren %ccs_xml% connections_wintech
ren %ccs_xml_org% connections
goto delete

:delete
rd /q /s %ccs_bin_wintech% 2>nul
rd /q /s %ccs_xml_wintech% 2>nul
goto success

:err
echo No ccs3.3 detected!
goto end

:success
echo success!
goto end

:end
pause