Skip to content

Commit

Permalink
feat: one line install command: Weasel+PowerShell
Browse files Browse the repository at this point in the history
  • Loading branch information
amorphobia committed Jul 14, 2023
1 parent c2a537c commit e40f3ca
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 12 deletions.
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@

## 安装

四种方式可以使用,前两种方式无法对 cizu 词典进行非覆盖式的修改,后两种可用补丁形式对 cizu 进行修改,请自行选择,注意每种方式都需要在 `default.custom.yaml` 里添加本方案 (jiandao)。
五种方式可以使用,前两种可用补丁形式对 cizu 进行修改,后三种方式无法对 cizu 词典进行非覆盖式的修改,请自行选择,注意有可能需要手动在 `default.custom.yaml` 里添加本方案 (jiandao)。

### 1. 下载 Zip 包
### 1. 使用 Github Actions 自动生成方案文件

请在[发布页面](https://github.com/amorphobia/rime-jiandao/releases)下载打包好的方案,解压文件到对应的目录。

### 2. 东风破

```bash
bash rime-install amorphobia/rime-jiandao@release
```
Fork 本仓库后,可以把需要添加、删除、修改权重的词语按需要的格式放到 `dicts` 目录下的 `cizu_append.txt`, `cizu_delete.txt`, 和 `cizu_modify.txt` 文件中,当推送到 Github 的时候,可以自动生成方案文件,生成的文件可以在 Actions 里面找到。

### 3. 克隆并在本地生成词库
### 2. 克隆并在本地生成词库

> Windows 用户请使用 WSL 运行
Expand All @@ -36,9 +30,23 @@ scrips/make_dicts.sh --append <cizu_append.txt> --delete <cizu_delete.txt> --mod

需要修改为你自己的对应文件名,也可省略选项。生成的方案在 `schema` 目录中。

### 4. 使用 Github Actions 自动生成方案文件
### 3. 使用 PowerShell 命令安装(小狼毫)

Fork 本仓库后,可以把需要添加、删除、修改权重的词语按需要的格式放到 `dicts` 目录下的 `cizu_append.txt`, `cizu_delete.txt`, 和 `cizu_modify.txt` 文件中,当推送到 Github 的时候,可以自动生成方案文件,生成的文件可以在 Actions 里面找到。
```PowerShell
irm tinyurl.com/weasel-jd | iex
```

如果遇到错误,运行一次 `Set-ExecutionPolicy RemoteSigned -Scope CurrentUser` 再试。

### 4. 下载 Zip 包

请在[发布页面](https://github.com/amorphobia/rime-jiandao/releases)下载打包好的方案,解压文件到对应的目录。

### 5. 东风破

```bash
bash rime-install amorphobia/rime-jiandao@release
```

## 与官方方案不同之处

Expand Down
98 changes: 98 additions & 0 deletions scripts/install_for_weasel.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Install for Weasel
# Copyright (C) 2023 Xuesong Peng <[email protected]>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

<#
.SYNOPSYS
Rime schema installer
.DESCRIPTION
Install rime-jiandao for Weasel
.LINK
https://github.com/amorphobia/rime-jiandao
#>

function Get-RimeUserDir {
$dir = ""
$registry_root = "HKCU:\SOFTWARE\Rime\Weasel"
if (Test-Path -Path $registry_root) {
$dir = (Get-ItemProperty -Path $registry_root).RimeUserDir
}
if (!$dir) {
$dir = "$Env:APPDATA\Rime"
}

return $dir
}

function Get-WeaselRoot {
$registry_root = "HKLM:\SOFTWARE\WOW6432Node\Rime\Weasel"
if (Test-Path -Path $registry_root) {
return (Get-ItemProperty -Path $registry_root).WeaselRoot
} else {
return ""
}
}

function Get-DownloadUrl {
$query_url = "https://api.github.com/repos/amorphobia/rime-jiandao/releases/latest"
$tag = (Invoke-WebRequest $query_url | ConvertFrom-Json).tag_name
$zip = "jiandao-$tag.zip"

return "https://github.com/amorphobia/rime-jiandao/releases/download/$tag/$zip"
}

function Start-Deployment {
param (
[switch] $deploy
)
$dir = Get-WeaselRoot
if ($deploy) {
$opt = "/deploy"
}
if ($dir -and (Test-Path "$dir\WeaselDeployer.exe")) {
& "$dir\WeaselDeployer.exe" $opt
}
}

$download_url = Get-DownloadUrl
$tmp = New-TemporaryFile
$zip = Move-Item -Path (Convert-Path $tmp.PSPath) -Destination ((Convert-Path $tmp.PSParentPath) + "\" + ([uri]$download_url).Segments[-1]) -PassThru -Force
$dest_path = "$env:TEMP\" + [io.path]::GetFileNameWithoutExtension($zip)

Write-Host "Downloading latest Jiandao schema ..."
Invoke-WebRequest $download_url -Out $zip

Write-Host "Expanding zip archive ..."
Expand-Archive -Path $zip -DestinationPath $dest_path -Force

$rime_user_dir = Get-RimeUserDir

if (Test-Path "$rime_user_dir\jiandao.user.dict.yaml") {
Remove-Item -Force "$dest_path\jiandao.user.dict.yaml"
}

Write-Host "Copying files to rime user data directory ..."
Copy-Item -Force -Recurse "$dest_path\*" "$rime_user_dir\"

Write-Host "Cleaning up downloaded files ..."
Remove-Item -Recurse -Force $zip
Remove-Item -Recurse -Force $dest_path

if (!(Test-Path "$rime_user_dir\default.custom.yaml" -PathType Leaf)) {
Set-Content -Path "$rime_user_dir\default.custom.yaml" -Value "patch:`n schema_list:`n - schema: jiandao"
}

Write-Host "Choose the schemas you desired in the popping up dialog."
Start-Deployment

0 comments on commit e40f3ca

Please sign in to comment.