diff --git a/WINDOWS_README.md b/WINDOWS_README.md index 4da1a9b..99314eb 100644 --- a/WINDOWS_README.md +++ b/WINDOWS_README.md @@ -2,6 +2,44 @@ # Windows下的说明 +## 🚀 快速部署 (推荐, 无需安装 Ruby) + +如果你不想装 Ruby, 仓库提供了 `install.ps1` (PowerShell) 一键脚本, 双击 `install.bat` 即可完成部署。 + +### 前置条件 + +1. 已安装 [Git for Windows](https://git-scm.com/downloads) +2. 已安装 [小狼毫 Weasel](https://rime.im/download/) (任意安装路径均可, 脚本会自动定位) +3. 已 `git clone` 本仓库到本地 + +### 操作步骤 + +1. 进入仓库目录 +2. **双击 `install.bat`** (推荐), 或在 PowerShell 中运行: + ```powershell + powershell -ExecutionPolicy Bypass -File .\install.ps1 + ``` + +### 脚本做了什么 + +| 步骤 | 操作 | +|---|---| +| 1 | 自动结束所有 `Weasel*` 进程 (避免文件占用导致部署失败) | +| 2 | 删除旧的 `%APPDATA%\Rime` 配置目录 | +| 3 | `git clone --depth=1` 最新雾凇拼音 (rime-ice) | +| 4 | 复制 `custom/*.yaml` 到 `%APPDATA%\Rime` | +| 5 | 智能查找 `WeaselDeployer.exe` (注册表 → 多盘 Program Files 扫描), 启动 `WeaselServer` 并触发部署 | + +### ⚠️ 注意 + +- 第 2 步会**直接删除**旧 Rime 目录, 包括用户词库 (userdb)。如有重要数据, 先手动备份 `%APPDATA%\Rime`。 +- 脚本不需要管理员权限, `%APPDATA%` 是用户目录。 +- 如果 PowerShell 提示 "无法加载, 因为禁止运行脚本", 用 `install.bat` 双击即可 (内置 `-ExecutionPolicy Bypass`)。 + +--- + +下面是**老的 Ruby 脚本流程** (`installer.rb`), 保留作为参考。如果上面的快速部署能用, 可以跳过下面所有步骤。 + 不同于 MacOS、Linux 大部分的工具已经内置,亦或者系统有包管理器(方便下载软件的一种软件)可以方便安装软件。Windows 用户需要自己安装必要的软件环境。 ## 01 环境准备:安装 Ruby diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..932b9e8 --- /dev/null +++ b/install.bat @@ -0,0 +1,6 @@ +@echo off +REM Rime Ice one-click installer - double-click to run +REM Invokes install.ps1 with ExecutionPolicy Bypass +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0install.ps1" +echo. +pause diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..9a69a58 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,125 @@ +# 雾凇拼音一键部署脚本 (Windows / PowerShell) +# 作用: 清除 %APPDATA%\Rime -> 重新 clone rime-ice -> 覆盖 custom/*.yaml -> 触发部署 +# 使用: 在仓库根目录执行 powershell -ExecutionPolicy Bypass -File .\install.ps1 +# 或双击同目录下的 install.bat + +$ErrorActionPreference = 'Stop' + +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$RimeDir = Join-Path $env:APPDATA 'Rime' +$CustomDir = Join-Path $ScriptDir 'custom' +$RimeIceRepo = 'https://github.com/iDvel/rime-ice.git' + +function Write-Step($msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan } +function Write-OK($msg) { Write-Host " $msg" -ForegroundColor Green } +function Write-Warn($msg) { Write-Host " $msg" -ForegroundColor Yellow } +function Write-Err($msg) { Write-Host " $msg" -ForegroundColor Red } + +Write-Host "===== 雾凇拼音一键部署 =====" -ForegroundColor Green + +if (-not (Get-Command git -ErrorAction SilentlyContinue)) { + Write-Err "未检测到 git, 请先安装 Git for Windows: https://git-scm.com/downloads" + exit 1 +} +if (-not (Test-Path $CustomDir)) { + Write-Err "找不到 custom 目录 ($CustomDir), 请从仓库根目录运行本脚本" + exit 1 +} + +Write-Step "[1/5] 结束 Weasel 相关进程" +$procs = Get-Process -Name Weasel* -ErrorAction SilentlyContinue +if ($procs) { + $procs | ForEach-Object { + Write-OK "停止 $($_.ProcessName) (PID $($_.Id))" + Stop-Process -Id $_.Id -Force + } + Start-Sleep -Milliseconds 500 +} else { + Write-OK "无需结束 (未运行)" +} + +Write-Step "[2/5] 清除旧配置 $RimeDir" +if (Test-Path $RimeDir) { + Remove-Item -Path $RimeDir -Recurse -Force + Write-OK "已删除" +} else { + Write-OK "不存在, 跳过" +} + +Write-Step "[3/5] Clone 雾凇拼音到 $RimeDir" +git clone --depth=1 $RimeIceRepo $RimeDir +if ($LASTEXITCODE -ne 0) { + Write-Err "git clone 失败 — 检查网络 / 代理设置" + Write-Warn "如果是 GFW 问题, 先设置代理: \$env:HTTPS_PROXY='http://127.0.0.1:7890'" + exit 1 +} + +Write-Step "[4/5] 复制自定义配置" +$yamls = Get-ChildItem $CustomDir -Filter *.yaml +if (-not $yamls) { + Write-Warn "custom/ 下无 yaml 文件, 跳过" +} else { + $yamls | ForEach-Object { + Copy-Item $_.FullName -Destination $RimeDir -Force + Write-OK "复制 $($_.Name)" + } +} + +Write-Step "[5/5] 启动小狼毫并触发部署" + +# 查找 WeaselDeployer.exe — 多盘符 / 多 Program Files 变体 / 注册表 +function Find-WeaselDir { + # 1) 先看注册表 (官方安装会写入) + $regKeys = @( + 'HKLM:\SOFTWARE\Rime\Weasel', + 'HKLM:\SOFTWARE\WOW6432Node\Rime\Weasel' + ) + foreach ($k in $regKeys) { + $v = (Get-ItemProperty -Path $k -Name 'WeaselRoot' -ErrorAction SilentlyContinue).WeaselRoot + if ($v -and (Test-Path (Join-Path $v 'WeaselDeployer.exe'))) { return $v } + } + # 2) 扫描所有固定盘的 Program Files / Program Files (x86) + $drives = (Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Free -ne $null }).Name + foreach ($d in $drives) { + foreach ($pf in @('Program Files','Program Files (x86)')) { + $glob = "${d}:\${pf}\Rime\weasel-*\WeaselDeployer.exe" + $hit = Get-Item $glob -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($hit) { return $hit.DirectoryName } + } + } + return $null +} + +$weaselDir = Find-WeaselDir +if (-not $weaselDir) { + Write-Warn "未找到小狼毫安装目录, 请手动: 右键托盘小狼毫图标 -> 重新部署" +} else { + Write-OK "小狼毫目录: $weaselDir" + $server = Join-Path $weaselDir 'WeaselServer.exe' + $deployer = Join-Path $weaselDir 'WeaselDeployer.exe' + + # 启动 WeaselServer (如果没在跑) + if (-not (Get-Process -Name WeaselServer -ErrorAction SilentlyContinue)) { + if (Test-Path $server) { + Start-Process -FilePath $server + Write-OK "已启动 WeaselServer" + Start-Sleep -Seconds 1 + } else { + Write-Warn "找不到 WeaselServer.exe ($server)" + } + } else { + Write-OK "WeaselServer 已在运行" + } + + # 触发部署 + if (Test-Path $deployer) { + & $deployer /deploy + Write-OK "已触发部署 ($deployer)" + } else { + Write-Warn "找不到 WeaselDeployer.exe ($deployer)" + } +} + +Write-Host "`n===== 完成 =====" -ForegroundColor Green +Write-Host "配置路径: $RimeDir" +Write-Host "测试: 在任何窗口打字, 默认应为英文; 按 Shift 切到中文."