@echo off

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

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

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

rmdir /S /Q C:\ProgramData\micromamba >> "%logFile%" 2>&1

if exist "C:\ProgramData\micromamba" (
    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%"