echo off
echo ** GuruCE Patch 3.0 QT5.6.0 Official**
set PATCH_EXTENTION=.guruce

REM enable or disable individual patches (could be that some of these patches a are fixed in future releases
set VS2015_SUPPORT_PATCH=1
set MKSPEC_COPY_EN=1
set QWINDOWS_INTEGRATION_PATCH=1
set QUICKCONTROLS_TEXTEDITOR_PATCH=1

if '%1'=='' (echo pass parameter -u to Undo the patches)

set VS2015_SUPPORT_PATH=..\qtbase\qmake\generators\win32\
set VS2015_SUPPORT_FILE=cesdkhandler.cpp
if '%VS2015_SUPPORT_PATCH%'=='1' (
   if '%1'=='-u' (
      echo undo VS2015 support patch
      if exist "%VS2015_SUPPORT_PATH%%VS2015_SUPPORT_FILE%%PATCH_EXTENTION%" (
         del %VS2015_SUPPORT_PATH%%VS2015_SUPPORT_FILE%
         rename %VS2015_SUPPORT_PATH%%VS2015_SUPPORT_FILE%%PATCH_EXTENTION% %VS2015_SUPPORT_FILE%
      )
   ) else (
      echo applying VS2015 support patch
      rename %VS2015_SUPPORT_PATH%%VS2015_SUPPORT_FILE% %VS2015_SUPPORT_FILE%%PATCH_EXTENTION%
      copy %VS2015_SUPPORT_FILE% %VS2015_SUPPORT_PATH%
   )
)

REM Copy the GuruCE mkspec for the iMX6 SDK for Visual Studio 2013 and 2015
set MKSPEC_PATH=..\qtbase\mkspecs\
set MKSPEC_FOLDER_2013=wince80GuruCE-armv7-msvc2013
set MKSPEC_FOLDER_2015=wince80GuruCE-armv7-msvc2015
if '%MKSPEC_COPY_EN%'=='1' (
   if '%1'=='-u' (
      echo remove GuruCE mkspec config VS2013
      if exist "%MKSPEC_PATH%%MKSPEC_FOLDER_2013%" (
        rmdir /S /Q %MKSPEC_PATH%%MKSPEC_FOLDER_2013%
      )
      echo remove GuruCE mkspec config VS2015
      if exist "%MKSPEC_PATH%%MKSPEC_FOLDER_2015%" (
        rmdir /S /Q %MKSPEC_PATH%%MKSPEC_FOLDER_2015%
      )
   ) else (
      echo adding GuruCE mkspec config VS2013
      xcopy /I /Y %MKSPEC_FOLDER_2013% %MKSPEC_PATH%%MKSPEC_FOLDER_2013%
      echo adding GuruCE mkspec config VS2015
      xcopy /I /Y %MKSPEC_FOLDER_2015% %MKSPEC_PATH%%MKSPEC_FOLDER_2015%
   )
)

REM 5.6.0 official fixes

REM Copy qwindowsintegration.cpp to platforms\windows\: fixes qmlscene crashes
set QWINDOWS_INTEGRATION_PATH=..\qtbase\src\plugins\platforms\windows\
set QWINDOWS_INTEGRATION_FILE=qwindowsintegration.cpp
if '%QWINDOWS_INTEGRATION_PATCH%'=='1' (
   if '%1'=='-u' (
      echo undo windows integration patch
      if exist "%QWINDOWS_INTEGRATION_PATH%%QWINDOWS_INTEGRATION_FILE%%PATCH_EXTENTION%" (
         del %QWINDOWS_INTEGRATION_PATH%%QWINDOWS_INTEGRATION_FILE%
         rename %QWINDOWS_INTEGRATION_PATH%%QWINDOWS_INTEGRATION_FILE%%PATCH_EXTENTION% %QWINDOWS_INTEGRATION_FILE%
      )
   ) else (
      echo applying windows integration patch
      rename %QWINDOWS_INTEGRATION_PATH%%QWINDOWS_INTEGRATION_FILE% %QWINDOWS_INTEGRATION_FILE%%PATCH_EXTENTION%
      copy %QWINDOWS_INTEGRATION_FILE% %QWINDOWS_INTEGRATION_PATH%
   )
)

REM Copy documenthandler.cpp to qtquickcontrols\examples\quick\controls\texteditor\src\: fixes compile error
set QUICKCONTROLS_TEXTEDITOR_PATH=..\qtquickcontrols\examples\quick\controls\texteditor\src\
set QUICKCONTROLS_TEXTEDITOR_FILE=documenthandler.cpp
if '%QUICKCONTROLS_TEXTEDITOR_PATCH%'=='1' (
   if '%1'=='-u' (
      echo undo windows integration patch
      if exist "%QUICKCONTROLS_TEXTEDITOR_PATH%%QUICKCONTROLS_TEXTEDITOR_FILE%%PATCH_EXTENTION%" (
         del %QUICKCONTROLS_TEXTEDITOR_PATH%%QUICKCONTROLS_TEXTEDITOR_FILE%
         rename %QUICKCONTROLS_TEXTEDITOR_PATH%%QUICKCONTROLS_TEXTEDITOR_FILE%%PATCH_EXTENTION% %QUICKCONTROLS_TEXTEDITOR_FILE%
      )
   ) else (
      echo applying windows integration patch
      rename %QUICKCONTROLS_TEXTEDITOR_PATH%%QUICKCONTROLS_TEXTEDITOR_FILE% %QUICKCONTROLS_TEXTEDITOR_FILE%%PATCH_EXTENTION%
      copy %QUICKCONTROLS_TEXTEDITOR_FILE% %QUICKCONTROLS_TEXTEDITOR_PATH%
   )
)
