ECHO Off
SET ISX64=0
REG QUERY HKLM\SOFTWARE\Autodesk\QTO2011\ProductInfo /V Location
IF %ERRORLEVEL%==1 SET ISX64=1
SET QTOINSTALLDIRPATHFOUND=0
REM ENGLISH LOCALE ID
SET QTOLOCALID=0x409 
IF %ISX64%==0 (FOR /F "usebackq skip=2 tokens=1,2*" %%a IN (`REG QUERY HKLM\SOFTWARE\Autodesk\QTO2011\ProductInfo /V Location`) DO (
IF "%%a"=="Location" (
SET QTOINSTALLDIRPATHFOUND=1
SET QTOINSTALLDIR=%%c)
)
FOR /F "usebackq skip=2 tokens=1,2*" %%a IN (`REG QUERY HKLM\SOFTWARE\Autodesk\QTO2011\ProductInfo /V LocaleId`) DO (
IF "%%a"=="LocaleId" (
SET QTOLOCALID=%%c)
)
)

IF %ISX64%==1 (
FOR /F "usebackq skip=2 tokens=1,2*" %%a IN (`REG QUERY HKLM\SOFTWARE\Wow6432Node\Autodesk\QTO2011\ProductInfo /V Location`) DO (
IF "%%a"=="Location" (
SET QTOINSTALLDIRPATHFOUND=1
SET QTOINSTALLDIR=%%c)
)
FOR /F "usebackq skip=2 tokens=1,2*" %%a IN (`REG QUERY HKLM\SOFTWARE\Wow6432Node\Autodesk\QTO2011\ProductInfo /V LocaleId`) DO (
IF "%%a"=="LocaleId" (
SET QTOLOCALID=%%c)
)
)
CLS
ECHO.
ECHO *************************************************************
ECHO.
ECHO THIS IS A HOT FIX FOR QTO 2011 RELEASE AND WE ARE INSTALLING HOT FIX FOR YOUR QTO 2011....
ECHO.
ECHO *************************************************************
REM READ REGISTRY TO GET THE QTO INSTALL ROOT DIRECTORY


IF %QTOINSTALLDIRPATHFOUND%==1 (
	GOTO DOINSTALL 
)ELSE (
GOTO ERROREXIT
)

:DOINSTALL
SET PATCHFILEPATH=%~DP0
ECHO YOUR QTO2011 INSTALL DIRECTORY IS :
ECHO %QTOINSTALLDIR%

REM BACKUP USER'S DLLS TO BE CHANGED
IF NOT EXIST "%QTOINSTALLDIR%dwf\ecomposite\EPlotGeometry.dll.BAK" (
	RENAME "%QTOINSTALLDIR%dwf\ecomposite\EPlotGeometry.dll" EPlotGeometry.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%dwf\ecomposite\EPlotEditorTools.dll.BAK" (
	RENAME "%QTOINSTALLDIR%dwf\ecomposite\EPlotEditorTools.dll" EPlotEditorTools.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%en-US\Autodesk.Takeoff.Plugin.resources.dll.BAK" (
	RENAME "%QTOINSTALLDIR%en-US\Autodesk.Takeoff.Plugin.resources.dll" Autodesk.Takeoff.Plugin.resources.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%FileUpgrader.dll.BAK" (
	RENAME "%QTOINSTALLDIR%FileUpgrader.dll" FileUpgrader.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.Core.dll.BAK" (
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.Core.dll" Autodesk.Takeoff.Core.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.Workbook.dll.BAK" (
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.Workbook.dll" Autodesk.Takeoff.Workbook.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.UI.dll.BAK" (
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.UI.dll" Autodesk.Takeoff.UI.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.Utilities.dll.BAK" (
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.Utilities.dll" Autodesk.Takeoff.Utilities.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.plugin.dll.BAK" (
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.plugin.dll" Autodesk.Takeoff.plugin.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.ATT.dll.BAK" (
	RENAME "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.ATT.dll" Autodesk.Takeoff.Plugin.ATT.dll.BAK)

IF NOT EXIST "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.CSV.dll.BAK" (
	RENAME "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.CSV.dll" Autodesk.Takeoff.Plugin.CSV.dll.BAK)

REM COPY THE DLLS CHANGED TO TARGET FOLDER.
XCOPY /E/C/Y/R/Q "%PATCHFILEPATH%hotfix\*.*" "%QTOINSTALLDIR%"
IF %QTOLOCALID%==0x407 (REG IMPORT hotfix\drawingUnit-deu.reg)
IF EXIST "%QTOINSTALLDIR%drawingUnit-Deu.reg" (
	DEL /F/Q "%QTOINSTALLDIR%drawingUnit-Deu.reg"
	DEL /F/Q "%QTOINSTALLDIR%drawingUnit-En.reg")
IF %ERRORLEVEL%==0 (GOTO SUCCESSED) ELSE (GOTO ERROREXIT)

:ERROREXIT
ECHO.
ECHO THERE ARE SOME ERRORS WHEN PARTCHING, PLEASE RUN INSTALL AGAIN AS ADMINISTRATOR
ECHO IF YOU STILL CAN SEE THIS MESSAGES, PLEASE READ THE README MANUAL AND  INSTALL IT MANUALLY
ECHO.
PAUSE
EXIT
:SUCCESSED
REM CHECK IF PATCHING SUCCESSFULLY AGAIN
IF NOT EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.Core.dll.BAK" (GOTO ERROREXIT)
ECHO.
ECHO PATCH SUCCESSFULLY!
ECHO.
PAUSE



