@echo off
rem 设置窗口行列大小
mode con: cols=77 lines=27
rem 设置窗口颜色
color 3f
rem 进入本程序的当前目录
cd /d "%~dp0"
set P=%~dp0

rem 中止可能存在的进程


rem 先结束可能存在的输入法进程，防止升级安装时的进程冲突
taskkill /f /t /im WeaselServer.exe >nul 2>nul

rem 设置用户数据目录为%P%
Reg add "HKCU\Software\Rime\Weasel" /f /v "RimeUserDir" /t REG_SZ /d "%P%User_Data" >nul 2>nul

rem 设置输入法服务以管理员身份运行，否则可能无法加载成功
reg add "HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /f /v "%~dp0WeaselServer.exe" /t REG_SZ /d "~ RUNASADMIN" >nul 2>nul
Reg add "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run" /f /v "WeaselServer" /t REG_SZ /d "%~dp0WeaselServer.exe"  >nul 2>nul
Reg add "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Rime\Weasel" /f /v "WeaselRoot" /t REG_SZ /d "%~dp0"  >nul 2>nul
Reg add "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Rime\Weasel" /f /v "ServerExecutable" /t REG_SZ /d "WeaselServer.exe" >nul 2>nul

rem 设置小狼毫调用热键为 Ctrl+Shift+1
reg add "HKLM\SOFTWARE\Microsoft\CTF\TIP\{A3F4CDED-B1E9-41EE-9CA6-7B4D0DE6CB0A}\LanguageProfile\0x00000804\{3D02CAB6-2B8E-4781-BA20-1C9267529467}" /f /v "Enable" /t REG_DWORD /d "1" >nul 2>nul
reg add "HKCU\Software\Microsoft\CTF\TIP\{A3F4CDED-B1E9-41EE-9CA6-7B4D0DE6CB0A}\LanguageProfile\0x00000804\{3D02CAB6-2B8E-4781-BA20-1C9267529467}" /f /v "Enable" /t REG_DWORD /d "1" >nul 2>nul
reg add "HKCU\Software\Microsoft\CTF\DirectSwitchHotkeys\00001001" /f /v "CLSID" /t REG_SZ /d "{A3F4CDED-B1E9-41EE-9CA6-7B4D0DE6CB0A}" >nul 2>nul
reg add "HKCU\Software\Microsoft\CTF\DirectSwitchHotkeys\00001001" /f /v "LangId" /t REG_SZ /d "00000804" >nul 2>nul
reg add "HKCU\Software\Microsoft\CTF\DirectSwitchHotkeys\00001001" /f /v "Modifiers" /t REG_SZ /d "0000c006" >nul 2>nul
reg add "HKCU\Software\Microsoft\CTF\DirectSwitchHotkeys\00001001" /f /v "PreservedKeyId" /t REG_SZ /d "{77AFA2B6-402B-11EA-B282-D8CB8A6ECFD3}" >nul 2>nul
reg add "HKCU\Software\Microsoft\CTF\DirectSwitchHotkeys\00001001" /f /v "Profile" /t REG_SZ /d "{3D02CAB6-2B8E-4781-BA20-1C9267529467}" >nul 2>nul
reg add "HKCU\Software\Microsoft\CTF\DirectSwitchHotkeys\00001001" /f /v "VirtualKey" /t REG_SZ /d "00000031 >nul 2>nul

rem 调用输入法自身的程序设置完成标准安装
cmd /c start WeaselSetup.exe /i
cmd /c start WeaselDeployer.exe /install
cmd /c start WeaselServer.exe

cls
echo.
echo        用户数据目录为：
echo.
echo        %P%User_Data
echo.
echo        任意键退出……
pause>nul

:end
exit