set _WIN7_PATH="%~dp0%win7"
set _WIN8_PATH="%~dp0%win8"
set _WIN81_PATH="%~dp0%win81"
set _WIN10_PATH="%~dp0%win10"
set _CUR_PATH="%~dp0%"
set _AP_WIN10_NAME=Win10_AP
set _AP_WIN81_NAME=Win8_AP
set _AP_WIN8_NAME=Win8_AP
set _AP_WIN7_NAME=AsTPCenter
set _DM_WIN10_NAME=DesktopManager_win10
set _DM_WIN81_NAME=DesktopManager_win8
set _DM_WIN8_NAME=DesktopManager_win8
set _DM_WIN7_NAME=DesktopManager
set _CG_WIN10_NAME=Configure_win10
set _CG_WIN8_NAME=Configure_win8
set _HOTFIX_PATH_="HKLM\SOFTWARE\ASUS\Hotfix\ASUS Smart Gesture"
set _REMOTE_PAGE_="HKLM\SOFTWARE\ASUS\ASUS Smart Gesture"
set addinkey="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\PowerPoint\Addins\AsusRemoteLinkAddIn"

reg ADD %_HOTFIX_PATH_% /v DisplayName /t REG_SZ /d "ASUS Smart Gesture" /f
reg ADD %_HOTFIX_PATH_% /v DisplayVersion /t REG_SZ /d "4.0.24" /f

del /F /Q "%ALLUSERSPROFILE%\DriverInstallFail.txt"

if defined ProgramFiles(x86) (
reg ADD %_REMOTE_PAGE_% /v "RemotePage" /t REG_DWORD /d "1" /f /reg:64
reg ADD %_REMOTE_PAGE_% /v "InstallModel" /t REG_DWORD /d "0" /f /reg:64
reg ADD %_REMOTE_PAGE_% /v "DisableUsbDetectorLoading" /t REG_DWORD /d "1" /f /reg:64
reg ADD %_REMOTE_PAGE_% /v "PipeDebugEnabled" /t REG_DWORD /d "1" /f /reg:64
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\ATP" /f
reg delete %addinkey% /f /reg:64 > nul 2> nul
reg delete %addinkey% /f /reg:32 > nul 2> nul
) else (
reg ADD %_REMOTE_PAGE_% /v "RemotePage" /t REG_DWORD /d "1" /f /reg:32
reg ADD %_REMOTE_PAGE_% /v "InstallModel" /t REG_DWORD /d "0" /f /reg:32
reg ADD %_REMOTE_PAGE_% /v "DisableUsbDetectorLoading" /t REG_DWORD /d "1" /f /reg:32
reg ADD %_REMOTE_PAGE_% /v "PipeDebugEnabled" /t REG_DWORD /d "1" /f /reg:32
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\ATP" /f
reg delete %addinkey% /f /reg:64 > nul 2> nul
reg delete %addinkey% /f /reg:32 > nul 2> nul
)

pushd %_CUR_PATH%
check_os.exe
popd
if %ERRORLEVEL% == 4 goto ver_7
if %ERRORLEVEL% == 5 goto ver_8
if %ERRORLEVEL% == 6 goto ver_8_1
if %ERRORLEVEL% == 7 goto ver_10

goto warnthenexit

:ver_7
echo "Windows 7 Install Procedure"
pushd %_WIN7_PATH%
call install_all.bat
popd

pushd %_CUR_PATH%
rmdir /Q /S %_AP_WIN8_NAME%
rmdir /Q /S %_DM_WIN8_NAME%
rmdir /Q /S %_AP_WIN10_NAME%
rmdir /Q /S %_DM_WIN10_NAME%
popd

pushd %_CUR_PATH%
echo "copy Win7 Configure to the other folder"
xcopy /E /Y %_CG_WIN8_NAME% %_AP_WIN7_NAME%
rmdir /Q /S %_CG_WIN8_NAME%
rmdir /Q /S %_CG_WIN10_NAME%
popd

pushd %_CUR_PATH%
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto x64 
if "%PROCESSOR_ARCHITEW6432%" == "AMD64" goto x64 
if "%PROCESSOR_ARCHITECTURE%" == "x86" goto x86 

goto exit

:ver_8
echo "Windows 8 Install Procedure"
pushd %_WIN8_PATH%
call install_all.bat
popd

pushd %_CUR_PATH%
echo "copy AsusTPCenter Win8 to the other folder"
xcopy /E /Y %_AP_WIN8_NAME% %_AP_WIN7_NAME%
rmdir /Q /S %_AP_WIN8_NAME%
rmdir /Q /S %_AP_WIN10_NAME%

echo "copy Desktop Manager Win8 to the other folder"
xcopy /E /Y %_DM_WIN8_NAME% %_DM_WIN7_NAME%
rmdir /Q /S %_DM_WIN8_NAME%
rmdir /Q /S %_DM_WIN10_NAME%

echo "copy Win8 Configure to the other folder"
xcopy /E /Y %_CG_WIN8_NAME% %_AP_WIN7_NAME%
rmdir /Q /S %_CG_WIN8_NAME%
rmdir /Q /S %_CG_WIN10_NAME%
popd

pushd %_CUR_PATH%
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto x64 
if "%PROCESSOR_ARCHITEW6432%" == "AMD64" goto x64 
if "%PROCESSOR_ARCHITECTURE%" == "x86" goto x86 
goto exit


:ver_8_1
echo "Windows 8.1 Install Procedure"
pushd %_WIN81_PATH%
call install_all.bat
popd

pushd %_CUR_PATH%
echo "copy AsusTPCenter Win81 to the other folder"
xcopy /E /Y %_AP_WIN81_NAME% %_AP_WIN7_NAME%
rmdir /Q /S %_AP_WIN81_NAME%
rmdir /Q /S %_AP_WIN10_NAME%

echo "copy Desktop Manager Win81 to the other folder"
xcopy /E /Y %_DM_WIN81_NAME% %_DM_WIN7_NAME%
rmdir /Q /S %_DM_WIN81_NAME%
rmdir /Q /S %_DM_WIN10_NAME%

echo "copy Win81 Configure to the other folder"
xcopy /E /Y %_CG_WIN8_NAME% %_AP_WIN7_NAME%
rmdir /Q /S %_CG_WIN8_NAME%
rmdir /Q /S %_CG_WIN10_NAME%
popd
pushd %_CUR_PATH%
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto x64 
if "%PROCESSOR_ARCHITEW6432%" == "AMD64" goto x64 
if "%PROCESSOR_ARCHITECTURE%" == "x86" goto x86 
goto exit

:ver_10
echo "Windows 10 Install Procedure"

if defined ProgramFiles(x86) (
reg ADD %_REMOTE_PAGE_% /v "SupportWin10" /t REG_DWORD /d "1" /f /reg:64
) else (
reg ADD %_REMOTE_PAGE_% /v "SupportWin10" /t REG_DWORD /d "1" /f /reg:32
)

echo Replacing app folders...
pushd %_CUR_PATH%
echo "copy AsusTPCenter Win10 to the other folder"
xcopy /E /Y %_AP_WIN10_NAME% %_AP_WIN7_NAME%
rmdir /Q /S %_AP_WIN8_NAME%
rmdir /Q /S %_AP_WIN10_NAME%

echo "copy Desktop Manager Win10 to the other folder"
xcopy /E /Y %_DM_WIN10_NAME% %_DM_WIN7_NAME%
rmdir /Q /S %_DM_WIN8_NAME%
rmdir /Q /S %_DM_WIN10_NAME%

echo "copy Win10 Configure to the other folder"
xcopy /E /Y %_CG_WIN10_NAME% %_AP_WIN7_NAME%
rmdir /Q /S %_CG_WIN8_NAME%
rmdir /Q /S %_CG_WIN10_NAME%
popd

pushd %_CUR_PATH%
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto x64 
if "%PROCESSOR_ARCHITEW6432%" == "AMD64" goto x64 
if "%PROCESSOR_ARCHITECTURE%" == "x86" goto x86 

:x64
start /wait /b CopyCommonFile64.exe
goto driver

:x86
start /wait /b CopyCommonFile.exe
goto driver

:driver
if "%1%" == "WU" (goto exit)
echo Installing driver now...
pushd %_WIN10_PATH%
call install_all.bat
popd
goto exit

:warnthenexit
echo Machine undetermined.

:exit

