ECHO OFF
SET ISX64=0
REG QUERY HKLM\SOFTWARE\Autodesk\QTO2011\ProductInfo /V Location
IF %ERRORLEVEL%==1 SET ISX64=1

REM READ REGISTRY TO GET THE QTO INSTALL ROOT DIRECTORY
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 UN-INSTALLING HOT FIX FOR YOUR QTO 2011....
ECHO.
ECHO *************************************************************
ECHO.


IF "%QTOINSTALLDIRPATHFOUND%"=="1" (
 GOTO DOUNINSTALL
)ELSE (
GOTO ERROREXIT
)

:DOUNINSTALL
ECHO YOUR QTO2011 INSTALL DIRECTORY IS :
ECHO %QTOINSTALLDIR%
SET PATCHFILEPATH=%~DP0
IF EXIST "%QTOINSTALLDIR%dwf\ecomposite\EPlotGeometry.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%dwf\ecomposite\EPlotGeometry.DLL"
	RENAME "%QTOINSTALLDIR%dwf\ecomposite\EPlotGeometry.dll.BAK" EPlotGeometry.DLL)
IF EXIST "%QTOINSTALLDIR%dwf\ecomposite\EPlotEditorTools.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%dwf\ecomposite\EPlotEditorTools.DLL"
	RENAME "%QTOINSTALLDIR%dwf\ecomposite\EPlotEditorTools.dll.BAK" EPlotEditorTools.DLL)
IF EXIST "%QTOINSTALLDIR%FileUpgrader.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%FileUpgrader.DLL"
	RENAME "%QTOINSTALLDIR%FileUpgrader.dll.BAK" FileUpgrader.DLL)
IF EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.Core.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%Autodesk.Takeoff.Core.DLL"
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.Core.dll.BAK" Autodesk.Takeoff.Core.DLL)
IF EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.Workbook.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%Autodesk.Takeoff.Workbook.DLL"
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.Workbook.dll.BAK" Autodesk.Takeoff.Workbook.DLL)
IF EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.UI.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%Autodesk.Takeoff.UI.DLL"
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.UI.dll.BAK" Autodesk.Takeoff.UI.DLL)
IF EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.Utilities.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%Autodesk.Takeoff.Utilities.DLL"
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.Utilities.dll.BAK" Autodesk.Takeoff.Utilities.DLL)
IF EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.plugin.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%Autodesk.Takeoff.plugin.DLL"
	RENAME "%QTOINSTALLDIR%Autodesk.Takeoff.plugin.dll.BAK" Autodesk.Takeoff.plugin.DLL)
IF EXIST "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.ATT.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.ATT.DLL"
	RENAME "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.ATT.dll.BAK" Autodesk.Takeoff.Plugin.ATT.DLL)
IF EXIST "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.CSV.dll.BAK" (
	DEL /F/Q "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.CSV.DLL"
	RENAME "%QTOINSTALLDIR%Plugins\Autodesk.Takeoff.Plugin.CSV.dll.BAK" Autodesk.Takeoff.Plugin.CSV.DLL)
IF %QTOLOCALID%==0x407 (REG IMPORT "%PATCHFILEPATH%hotfix\drawingUnit-en.reg")


IF EXIST "%QTOINSTALLDIR%Autodesk.Takeoff.Core.dll.BAK" (
GOTO ERROREXIT
)ELSE (
ECHO.
ECHO UN-INSTALL THE PATCH SUCCESSFULLY!
ECHO.
)
PAUSE
EXIT
:ERROREXIT
ECHO.
ECHO FAIL TO UNINSTALL THE HOTFIX, PLEASE RUN IT AS ADMINISTRATOR AGAIN
ECHO IF YOU STILL SEE THIS MESSAGE, PLEASE READ THE README MANUAL AND  UNINSTALL IT MANUALLY
ECHO.
PAUSE
EXIT

