@echo off
REM  RAID800                               
REM  Perl Install tool for RAID800 SVP
REM       All Rights Reserved, Copyright (C) 2020,Hitachi, Ltd. 
REM
REM History  :Version    :DATE        : Coder        : Patch No
REM RAID 800 
REM          :01-00      :2020.01.28  : T.Yamanaka   : #97547 (Strawberry Perl 5.28.2 is supported) 
REM
REM Document
REM   MSI File Installer 
REM Required Environment 
REM   PerlName ,GUID    ,InsDir
REM

if "'%PerlName%'" equ "''" (
	echo Environment Error PerlName
	exit /b 1
)

if "'%GUID%'" equ "''" (
	echo Environment Error GUID
	exit /b 1
)

if "'%InsDir%'" equ "''" (
	echo Environment Error InsDir
	exit /b 1
)

call :Install_check
set BF_CHK=%ERRORLEVEL%
if not %BF_CHK% equ 0 (
	echo Skip the %PerlName% uninstallation.
	exit /b 2
)

tasklist | findstr  /I "^PERL.EXE\>" >NUL
set EXEC_CHK=%ERRORLEVEL%
if %EXEC_CHK% equ 0 timeout /T 10 /NOBREAK

tasklist | findstr  /I "^PERL.EXE\>" >NUL
set EXEC_CHK=%ERRORLEVEL%
if %EXEC_CHK% equ 0 (
	echo %PerlName% Path uninstallation failed EXEC_PERL_ERROR:%EXEC_CHK%
	exit /b 1
)

echo %PerlName% uninstallation start
start /wait msiexec.exe /uninstall %GUID% /qn /L*v C:\Perl_UnInstall.log /norestart
set INS_ERR=%ERRORLEVEL%
if not %INS_ERR% equ 0 (
	echo %PerlName% uninstallation failed UNINSTALL_ERROR:%INS_ERR%
	exit /b 1
)

call :Install_check
set AF_CHK=%ERRORLEVEL%
if %AF_CHK% equ 0 (
	echo %PerlName% uninstallation failed REG_CHK_ERROR:%AF_CHK%
	exit /b 1
)

echo delete %PerlName% file
rmdir /s /q %InsDir%

echo %PerlName% uninstallation succeeded.

exit /b 0

:Install_check
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%GUID%" /v DisplayName  /reg:64 > nul 2>&1
exit /b %ERRORLEVEL%

