@ECHO OFF
NET SESSION >nul 2>&1
IF "%ERRORLEVEL%"=="0" goto Adm
   echo ######## ########  ########   #######  ########  
   echo ##       ##     ## ##     ## ##     ## ##     ## 
   echo ##       ##     ## ##     ## ##     ## ##     ## 
   echo ######   ########  ########  ##     ## ########  
   echo ##       ##   ##   ##   ##   ##     ## ##   ##   
   echo ##       ##    ##  ##    ##  ##     ## ##    ##  
   echo ######## ##     ## ##     ##  #######  ##     ## 
   echo.
   echo.
   echo ####### ERROR: ADMINISTRATOR PRIVILEGES REQUIRED #########
   echo This script must be run as administrator to work properly!  
   echo If you're seeing this ERROR, then right-click on the file
   echo "install.bat" and select "Run As Administrator".
   echo ##########################################################
   echo.
   echo.
   PAUSE
   GOTO End
:Adm
ECHO Administrator PRIVILEGES detected!

%~d0
cd %~dp0

IF EXIST "%CommonProgramFiles(x86)%\BinarySense\hldasvc.exe" (
	SET CMF="%CommonProgramFiles(x86)%\BinarySense"
	) ELSE (
	SET CMF="%CommonProgramFiles%\BinarySense"
)

for /f "tokens=* delims=" %%P in (%CMF%) do (
    SET CMF=%%P
)

IF NOT EXIST "%CMF%\hldasvc.exe" (
	echo.
	echo."Error! Service file hldascv.exe not found in destination directory. Exiting"
	echo.
	echo.
	PAUSE
	GOTO End
)

echo.
echo."Stopping HDDlife HDD access service. Please wait..."
echo.
net stop "HDDlife HDD access service"
echo.

echo.Copying armaccess.dll...
copy /b /y "armaccess.dll" "%CMF%\armaccess.dll">nul
IF "%ERRORLEVEL%"=="0" (
	echo."Copy success."
	echo.
	) ELSE (
		echo."Error while copying armaccess.dll."
		echo.
		echo.
		PAUSE
		GOTO End
)

echo.Replacing hldasvc.exe by the cracked one...
copy /b /y "hldasvc.exe" "%CMF%\hldasvc.exe">nul
IF "%ERRORLEVEL%"=="0" (
	echo."Copy success."
	echo.
	) ELSE (
		echo."Error while copying hldascv.exe."
		echo.
		echo.
		PAUSE
		GOTO End
	)
fc /B "hldasvc.exe" "%CMF%\hldasvc.exe">nul

IF NOT "%ERRORLEVEL%"=="0" goto err

echo.Service installation success.
echo.
echo.Restarting service. Please wait...
echo.
net start "HDDlife HDD access service"
echo.
echo.Cracked HDDlife service successfuly installed and running.
echo.
echo.Restarting HDDlife Pro. Please Wait...
start "" /B "HDDlifePro.exe"
echo.
echo.Well done!
del "hldasvc.exe"
del "install.bat"
echo.
echo.
PAUSE
goto end

:err
echo.Installation failed :(
echo.Please, proceed to a manual installation like this:
echo.
echo.1. Open a console command and type:
echo.	sc stop "HDDlife HDD access service"
echo.2. Copy and overwrite armaccess.dll and hldascv.exe into Common File directory:
echo.		For x32: C:\Program Files\Common Files\BinarySense\
echo.		For x64: C:\Program Files (x86)\Common Files\BinarySense\
echo.3. with the same console command, type:
echo.		sc start "HDDlife HDD access service"
echo.

:End
