@echo off
color 0a
:MENU
CLS
>nul 2>&1 REG.exe query "HKU\S-1-5-19" || (
    ECHO SET UAC = CreateObject^("Shell.Application"^) > "%TEMP%\Getadmin.vbs"
    ECHO UAC.ShellExecute "%~f0", "%1", "", "runas", 1 >> "%TEMP%\Getadmin.vbs"
    "%TEMP%\Getadmin.vbs"
    DEL /f /q "%TEMP%\Getadmin.vbs" 2>nul
    Exit /b
)
ECHO.
ECHO.========== foobar2000 便携关联助手 ==========
ECHO.
ECHO. 关联音频文件格式, 注册相关组件 (请先关闭 foobar2000!)

tasklist|find /i "foobar2000.exe" > nul
if %errorlevel%==0 ( 
	echo 检测到 foobar2000 正在运行，请先把它关闭再继续本操作。
)
if exist "%~dp0Fb2kShellExt.dll" (
	regsvr32.exe /s "%~dp0Fb2kShellExt.dll"
	echo 已注册 Fb2kShellExt.dll
)

start /wait "" "%~dp0foobar2000.exe" /install /quiet /exportshelldata "%~dp0fb2kshelldata.tmp"
if exist "%~dp0foobar2000 Shell Associations Updater.exe" (start /wait "" "%~dp0foobar2000 Shell Associations Updater.exe" "%~dp0fb2kshelldata.tmp")
del /q "%~dp0fb2kshelldata.tmp"
reg add "HKLM\SOFTWARE\Classes\foobar2000.FTH" /t REG_SZ /d "foobar2000 主题文件" /f
reg add "HKLM\SOFTWARE\Classes\foobar2000.FTH\DefaultIcon" /t REG_SZ /d "%~dp0icons\FTH.ico" /f
reg add "HKLM\SOFTWARE\Classes\foobar2000.FTH\shell" /t REG_SZ /d "open" /f
reg add "HKLM\SOFTWARE\Classes\foobar2000.FTH\shell\open" /t REG_SZ /d "打开" /f
reg add "HKLM\SOFTWARE\Classes\foobar2000.FTH\shell\open\command" /t REG_SZ /d "\"%~dp0foobar2000.exe\" /theme \"%%1\"" /f
reg add "HKLM\SOFTWARE\Classes\foobar2000.FB2K-COMPONENT" /t REG_SZ /d "foobar2000 组件" /f
reg add "HKLM\SOFTWARE\Classes\foobar2000.FB2K-COMPONENT\DefaultIcon" /t REG_SZ /d "%~dp0icons\DLL.ico" /f
reg add "HKLM\SOFTWARE\Classes\foobar2000.FB2K-COMPONENT\shell" /t REG_SZ /d "open" /f
reg add "HKLM\SOFTWARE\Classes\foobar2000.FB2K-COMPONENT\shell\open" /t REG_SZ /d "安装" /f
reg add "HKLM\SOFTWARE\Classes\foobar2000.FB2K-COMPONENT\shell\open\command" /t REG_SZ /d "\"%~dp0foobar2000.exe\" /addcomponent \"%%1\"" /f
start /wait "" ie4uinit.exe -ClearIconCache
start /wait "" ie4uinit.exe -show
echo 注册组件和关联文件格式操作完成！
