@echo off
setlocal enabledelayedexpansion

:: Define target file and directory paths
set "CONFIG_FILE=%USERPROFILE%\.planet-helper.json"
set "APP_DIR=%USERPROFILE%\planet-helper"

echo.
echo WARNING: 该操作将删除所有数据，软件和设置信息，请再三确认.
echo 包括:
echo - 文件 "%CONFIG_FILE%"
echo - 文件夹 "%APP_DIR%"
echo.

:: Task 1: Warn user and ask for confirmation
set /p CONFIRM="按 'y' 继续执行, 按其他按键则终止: "

:: Convert input to lowercase for case-insensitive comparison
set CONFIRM=!CONFIRM!

if /i "%CONFIRM%" == "y" (
    echo.
    echo 开始执行...
    echo.

    :: Task 2: Check and delete the specific file
    if exist "%CONFIG_FILE%" (
        echo 删除文件: "%CONFIG_FILE%" ...
        del /q "%CONFIG_FILE%"
        if errorlevel 1 (
            echo 警告: 无法删除文件 "%CONFIG_FILE%". 该文件可能正在被使用.
        ) else (
            echo 文件删除成功.
        )
    ) else (
        echo 文件不存在，跳过.
    )

    :: Task 3: Check and delete the whole directory
    if exist "%APP_DIR%" (
        echo 删除文件夹: "%APP_DIR%" ...
        :: Use rmdir /s /q for silent, forced recursive deletion
        rmdir /s /q "%APP_DIR%"
        if errorlevel 1 (
            echo 警告: 无法删除文件夹 "%APP_DIR%". 某些文件可能正在被使用.
        ) else (
            echo 文件夹删除成功.
        )
    ) else (
        echo 文件夹不存在，跳过.
    )

    echo.
    echo 执行成功.

) else (
    :: User did not press 'y'
    echo.
    echo 程序终止.
    echo.
)

:: Task 4: Press any key to quit
pause

exit /b 0