@echo off
chcp 65001 >nul
mode con cp select=65001 >nul
:: 自动申请管理员权限
fltmc filters >nul 2>&1 || (powershell -Command "Start-Process cmd -ArgumentList '/c ""%~0""' -Verb RunAs" & exit)
color 0A
cls
echo ================================================================================================
echo             系统垃圾深度清理 - 增强纯净版--新途3.0版本（13325501750）【https://www.p911.cn/】
echo ================================================================================================
echo.
:: 获取清理前C盘占用
echo 【正在统计清理前C盘占用空间...】
for /f "delims=" %%a in ('powershell "(Get-PSDrive C).Used / 1GB"') do set beforeSize=%%a
echo 清理前 C盘已占用：%beforeSize% GB
echo.
echo 正在安全清理垃圾，请稍等...
echo.

:: 基础系统临时文件
del /f /s /q %systemdrive%\*.tmp 2>nul
del /f /s /q %systemdrive%\*._mp 2>nul
del /f /s /q %systemdrive%\*.log 2>nul
del /f /s /q %systemdrive%\*.gid 2>nul
del /f /s /q %systemdrive%\*.chk 2>nul
del /f /s /q %systemdrive%\*.old 2>nul
del /f /s /q %windir%\*.bak 2>nul

:: 系统Temp目录重建
if exist "%windir%\temp" rd /s /q "%windir%\temp" 2>nul
md "%windir%\temp" 2>nul
del /f /s /q %windir%\prefetch\*.* 2>nul

:: 用户临时文件
del /f /s /q "%temp%\*.*" 2>nul
del /f /s /q "%localappdata%\Temp\*.*" 2>nul
del /f /q "%userprofile%\recent\*.*" 2>nul

:: 浏览器缓存 IE/Edge/Chrome/Firefox
del /f /s /q "%localappdata%\Microsoft\Windows\INetCache\*.*" 2>nul
del /f /s /q "%localappdata%\Google\Chrome\User Data\Default\Cache\*.*" 2>nul
del /f /s /q "%localappdata%\Microsoft\Edge\User Data\Default\Cache\*.*" 2>nul
del /f /s /q "%localappdata%\Mozilla\Firefox\Profiles\*.cache2\*.*" 2>nul

:: 系统日志、崩溃转储
del /f /s /q "%windir%\Logs\*.*" 2>nul
del /f /s /q "%windir%\Minidump\*.*" 2>nul
del /f /s /q "%localappdata%\CrashDumps\*.*" 2>nul

:: 缩略图图标缓存
del /f /s /q "%localappdata%\Microsoft\Explorer\thumbcache_*.db" 2>nul
del /f /s /q "%localappdata%\Microsoft\Explorer\iconcache_*.db" 2>nul

:: 显卡安装残留
del /f /s /q "%systemdrive%\AMD\*.*" 2>nul
del /f /s /q "%systemdrive%\NVIDIA\*.*" 2>nul

:: 全盘回收站清理
echo 正在清理全分区回收站...
for %%d in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    if exist %%d:\$Recycle.Bin rd /s /q %%d:\$Recycle.Bin 2>nul
)

:: QQ 微信缓存清理
echo 清理QQ、微信缓存文件...
del /f /s /q "%userprofile%\Documents\WeChat Files\*Cache" 2>nul
del /f /s /q "%localappdata%\Tencent\WeChat\Cache\*.*" 2>nul
del /f /s /q "%userprofile%\Documents\Tencent Files\*Cache" 2>nul
del /f /s /q "%localappdata%\Tencent\QQ\Cache\*.*" 2>nul

:: Office缓存
echo 清理Office临时文件...
del /f /s /q "%localappdata%\Microsoft\Office\UnsavedFiles\*.*" 2>nul
del /f /s /q "%localappdata%\Microsoft\Office\Office*\OfficeFileCache\*.*" 2>nul

:: 打印后台缓存
echo 清理打印机残留任务...
net stop spooler >nul 2>&1
del /f /s /q "%windir%\System32\spool\PRINTERS\*.*" 2>nul
net start spooler >nul 2>&1

:: Windows更新完整重置缓存
echo 重置Windows更新缓存...
net stop wuauserv >nul 2>&1
net stop cryptSvc >nul 2>&1
net stop bits >nul 2>&1
net stop msiserver >nul 2>&1
ren "%windir%\SoftwareDistribution" SoftwareDistribution.old 2>nul
ren "%windir%\System32\catroot2" catroot2.old 2>nul
md "%windir%\SoftwareDistribution" 2>nul
md "%windir%\System32\catroot2" 2>nul
net start wuauserv >nul 2>&1
net start cryptSvc >nul 2>&1
net start bits >nul 2>&1
net start msiserver >nul 2>&1

:: 重启资源管理器刷新缩略图
echo 刷新桌面缓存...
taskkill /f /im explorer.exe >nul 2>&1
start explorer.exe

:: 休眠功能选择菜单
echo.
echo 是否关闭系统休眠文件（关闭后C盘释放数GB空间，但无法睡眠休眠）
set /p sleepSel=输入Y关闭，其他键跳过：
if /i "%sleepSel%"=="Y" (
    powercfg -h off
    echo 已关闭休眠
) else (
    echo 保留休眠功能
)

:: 统计清理后空间并计算差值
echo.
echo 【正在统计清理后C盘占用空间...】
for /f "delims=" %%a in ('powershell "(Get-PSDrive C).Used / 1GB"') do set afterSize=%%a
:: 计算释放空间
for /f "delims=" %%a in ('powershell "%beforeSize% - %afterSize%"') do set freeSize=%%a

echo.
echo ======================================================
echo               ✅ 垃圾清理全部完成！
echo ======================================================
echo 清理前C盘占用：%beforeSize% GB
echo 清理后C盘占用：%afterSize% GB
echo 本次共释放磁盘空间：%freeSize% GB
echo ======================================================
echo.
echo 本次清理包含：
echo 1. 用户/系统全部临时文件
echo 2. 全分区回收站文件
echo 3. Windows更新完整缓存重置
echo 4. Chrome/Edge/火狐浏览器缓存
echo 5. 系统日志、蓝屏崩溃报告
echo 6. 缩略图、图标缓存（自动刷新桌面）
echo 7. AMD/NVIDIA显卡安装残留
echo 8. QQ、微信聊天缓存垃圾
echo 9. Office文档临时缓存
echo 10.打印机卡住的打印任务缓存
echo.
echo 建议重启电脑，释放完整磁盘空间！
echo.
echo 按任意键继续...
pause >nul