@ECHO OFF


IF NOT EXIST _Livery.* EXIT

COPY aircraft.cfg aircraft.backup

SET /A COUNT=0


:START

SET /A COUNT=%COUNT%+1

FOR %%G IN (_Livery.*) DO SET TEXTURESUFFIX=%%~xG

SET TEXTURESUFFIX=%TEXTURESUFFIX:~1,40%

SET SOURCE=texture
SET DEST=texture.%TEXTURESUFFIX%

FOR %%G IN (%SOURCE%\*.*) DO IF NOT EXIST %DEST%\%%~nxG COPY %%G %DEST%\%%~nxG                                            

ECHO:>>aircraft.cfg
ECHO:>>aircraft.cfg
ECHO //THE FOLLOWING SECTION WAS AUTOMATICALLY ADDED>>aircraft.cfg
ECHO:>>aircraft.cfg
ECHO:>>aircraft.cfg

SET /A VAR=0

:CHECK
FIND /C /I "[fltsim.%VAR%]" aircraft.cfg
IF ERRORLEVEL 1 GOTO WRITE
IF NOT ERRORLEVEL 1 SET /A VAR=%VAR%+1 
GOTO CHECK

:WRITE
ECHO [fltsim.%VAR%]>>aircraft.cfg

COPY aircraft.cfg+_Livery.%TEXTURESUFFIX%

ECHO:>>aircraft.cfg

DEL _Livery.%TEXTURESUFFIX%

IF EXIST _Livery.* GOTO START

ECHO:
IF %COUNT%==1 ECHO INSTALLED %COUNT% LIVERY!
IF NOT %COUNT%==1 ECHO INSTALLED %COUNT% LIVERIES!
ECHO:

PAUSE

DEL %0

EXIT