@ECHO off
REG QUERY "HKU\S-1-5-19">NUL 2>&1||powershell -Command "Start-Process '%~sdpnx0' -Verb RunAs"&&exit

:Menu
ECHO.&ECHO. 1.绿化
ECHO.&ECHO. 2.卸载
ECHO.
SET /P Options=请输入选择项目序号（1，2）：
IF /I "%Options%"=="1" GOTO install
IF /I "%Options%"=="2" GOTO uninstall
ECHO.&ECHO.序号无效，请重新输入！
timeout /t 2 >NUL
CLS
GOTO Menu

:install
netsh advfirewall firewall show rule name="Xmind" >NUL 2>NUL
if errorlevel 1 (
    netsh advfirewall firewall add rule name="Xmind" dir=in action=block program="%~dp0Xmind.exe" >NUL 2>NUL
) else (
    netsh advfirewall firewall set rule name="Xmind" new enable=yes
)
reg add "HKCU\SOFTWARE\Classes\.xmind" /f /ve /d "XMind Workbook" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\.xmind" /f /v "XMind Workbook_backup" /d "" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind" /f /ve /d "URL:xmind" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind" /f /v "URL Protocol" /d "" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind\DefaultIcon" /f /ve /d "%~dp0XMind.exe" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind\shell" /f /ve /d "" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind\shell\Open" /f /ve /d "" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind\shell\Open\command" /f /ve /d "\"%~dp0XMind.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind-zen" /f /ve /d "URL:xmind-zen" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind-zen" /f /v "URL Protocol" /d "" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind-zen\DefaultIcon" /f /ve /d "%~dp0XMind.exe" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind-zen\shell" /f /ve /d "" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind-zen\shell\Open" /f /ve /d "" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\xmind-zen\shell\Open\command" /f /ve /d "\"%~dp0XMind.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\XMind Workbook" /f /ve /d "XMind Workbook" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\XMind Workbook\DefaultIcon" /f /ve /d "%~dp0resources\xmind_file.ico" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\XMind Workbook\shell" /f /ve /d "open" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\XMind Workbook\shell\open" /f /ve /d "Open with XMind" >NUL 2>NUL
reg add "HKCU\SOFTWARE\Classes\XMind Workbook\shell\open\command" /f /ve /d "\"%~dp0XMind.exe\" \"%%1\"" >NUL 2>NUL
regsvr32 /s "%~dp0resources\app.asar.unpacked\static\native\XMindShellExt.dll"
call config.exe
IF %ERRORLEVEL%==0 (
ECHO.&ECHO 绿化完成&timeout /t 2 >nul&CLS&GOTO LNK
) ELSE (
ECHO.&ECHO 绿化失败&timeout /t 2 >nul&CLS&GOTO Menu
)

:uninstall
::删除注册表数据
reg delete "HKLM\Software\Classes\.xmind" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Classes\xmind" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Classes\xmind-zen" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Classes\XMind Workbook" /f >NUL 2>NUL
reg delete "HKCU\SOFTWARE\Classes\.xmind" /f >NUL 2>NUL
reg delete "HKCU\SOFTWARE\Classes\xmind" /f >NUL 2>NUL
reg delete "HKCU\SOFTWARE\Classes\xmind-zen" /f >NUL 2>NUL
reg delete "HKCU\SOFTWARE\Classes\XMind Workbook" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\XMind" /f >NUL 2>NUL
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\XMind" /f /reg:32 >NUL 2>NUL
::卸载文件关联
regsvr32 /s /u "%~dp0resources\app.asar.unpacked\static\native\XMindShellExt.dll"
::删除数据及快捷方式
rd/s/q "%AppData%\XMind" 2>NUL
rd/s/q "%Temp%\net.xmind.vana.app" 2>NUL
rd/s/q "%LocalAppData%\Programs\Xmind" 2>NUL
rd/s/q "%LocalAppData%\xmind-updater" 2>NUL
rd/s/q "%LocalAppData%\xmind-vana-updater" 2>NUL
SET DS="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
FOR /F "tokens=2,*" %%I IN ('REG QUERY %DS% /v Desktop 2^>NUL^|FIND /I "Desktop"') DO SET "MYDesktop=%%~J"
del /q "%Public%\Desktop\XMind.lnk" >NUL 2>NUL
del /q "%MYDesktop%\XMind.lnk" >NUL 2>NUL
ECHO.&ECHO.卸载完成 &timeout /t 2 >nul&EXIT /B

:LNK
ECHO.&ECHO.是否添加桌面快捷方式？
ECHO.&ECHO.[是] 请按任意键，[否] 直接关掉本窗口！
ECHO.&ECHO.&ECHO BY GNDOWN.COM&PAUSE >NUL
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\XMind.lnk""):b.TargetPath=""%~dp0XMind.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")
