@echo off

>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
    echo This script requires administrative privileges.
    pause
    exit /b
)
set "nssmPath=%~dp0nssm.exe"
set "serviceNameM=3DFF-Mount"
set "serviceNameD=3DFF-DLNA"
set "logFileD=%~dp0DLNAlog.txt"
set "logFileM=%~dp0Mountlog.txt"
set "cachemount=%~dp0cache_mount"
set "cachedlna=%~dp0cache_dlna"

call :RemoveService %serviceNameM%
call :RemoveService %serviceNameD%

set /p cleanupLogs=Do you want to clean up the logs? (y/n): 
if /i "%cleanupLogs%"=="y" (
    del "%logFileD%" 2>nul
    del "%logFileM%" 2>nul
	rmdir /s /q "%cachemount%" 2>nul	
	rmdir /s /q "%cachedlna%" 2>nul
    echo Logs cleaned up.
) else if /i "%cleanupLogs%"=="yes" (
    del "%logFileD%" 2>nul
    del "%logFileM%" 2>nul
	rmdir /s /q "%cachemount%" 2>nul	
	rmdir /s /q "%cachedlna%" 2>nul
    echo Logs cleaned up.
) else (
    echo Logs not cleaned up.
)

goto :EOF

:RemoveService
%nssmPath% status %1 >nul 2>&1
if %errorlevel% EQU 0 (
    %nssmPath% stop %1 >nul 2>&1
    %nssmPath% remove %1 confirm >nul 2>&1
    echo Service %1 stopped and removed successfully.
) else (
    echo Service %1 not found or already removed.
)
exit /b