@echo off

set "logFile=..\..\log\miniconda_uninstallation.log"
set "maxRetries=3"
set "delayBetweenRetries=5"
set "retryCount=0"

echo %logFile% >> "%logFile%"
echo "Starting Uninstallation of miniconda at %date% %time%" >> "%logFile%"

:uninstall
echo Attempt: %retryCount% >> "%logFile%"
dir "C:\ProgramData\" >> "%logFile%"

C:\ProgramData\miniconda3\Uninstall-Miniconda3.exe /S >> "%logFile%" 2>&1

if exist "C:\ProgramData\miniconda3" (
    set /a "retryCount+=1"
    echo Uninstallation failed at %date% %time%, retrying in %delayBetweenRetries% seconds... >> "%logFile%"
    if %retryCount% LSS %maxRetries% (
        timeout /T %delayBetweenRetries% /NOBREAK > nul
        goto uninstall
    ) else (
        echo Maximum retry attempts reached. Uninstallation failed at %date% %time% >> "%logFile%"
    )
) else (
    echo Uninstallation successful at %date% %time% >> "%logFile%"
    goto end
)

:end
echo Uninstallation process completed at %date% %time% >> "%logFile%"