feat/dict: Support updating Rime user dir via script on Windows and add entries for GDP per capita (#793)
This commit is contained in:
parent
83aa7087e2
commit
4b3184fcf5
@ -908,3 +908,5 @@ TF版本 TFbanben
|
||||
TF版本 tfbanben
|
||||
O不OK ObuOK
|
||||
O不OK obuok
|
||||
人均GDP renjunGDP
|
||||
人均GDP renjungdp
|
||||
|
@ -908,3 +908,5 @@ TF版本 TFbjbf
|
||||
TF版本 tfbjbf
|
||||
O不OK ObuOK
|
||||
O不OK obuok
|
||||
人均GDP rfjnGDP
|
||||
人均GDP rfjngdp
|
||||
|
@ -908,3 +908,5 @@ TF版本 TFbjbf
|
||||
TF版本 tfbjbf
|
||||
O不OK ObuOK
|
||||
O不OK obuok
|
||||
人均GDP rfjpGDP
|
||||
人均GDP rfjpgdp
|
||||
|
@ -908,3 +908,5 @@ TF版本 TFbjbf
|
||||
TF版本 tfbjbf
|
||||
O不OK ObuOK
|
||||
O不OK obuok
|
||||
人均GDP rfjyGDP
|
||||
人均GDP rfjygdp
|
||||
|
@ -908,3 +908,5 @@ TF版本 TFbjbf
|
||||
TF版本 tfbjbf
|
||||
O不OK ObuOK
|
||||
O不OK obuok
|
||||
人均GDP rfjpGDP
|
||||
人均GDP rfjpgdp
|
||||
|
@ -908,3 +908,5 @@ TF版本 TFbjbf
|
||||
TF版本 tfbjbf
|
||||
O不OK ObuOK
|
||||
O不OK obuok
|
||||
人均GDP rfjpGDP
|
||||
人均GDP rfjpgdp
|
||||
|
@ -908,3 +908,5 @@ TF版本 TFbrbw
|
||||
TF版本 tfbrbw
|
||||
O不OK ObuOK
|
||||
O不OK obuok
|
||||
人均GDP rwjmGDP
|
||||
人均GDP rwjmgdp
|
||||
|
@ -7911,7 +7911,6 @@ GCC GCC
|
||||
# GCSE GCSE
|
||||
# gd gd
|
||||
# GDB GDB
|
||||
GDP GDP
|
||||
# ge ge
|
||||
gear gear
|
||||
geared geared
|
||||
|
@ -331,8 +331,10 @@ APC APC
|
||||
Ability Power Carry APC
|
||||
Ability Power Carry AbilityPowerCarry
|
||||
GDP GDP
|
||||
GDP per capita GDPpercapita
|
||||
Gross Domestic Product GDP
|
||||
Gross Domestic Product GrossDomesticProduct
|
||||
Gross Domestic Product per capita GrossDomesticProductpercapita
|
||||
LOL LOL
|
||||
League of Legends LOL
|
||||
League of Legends LeagueofLegends
|
||||
|
@ -460,3 +460,4 @@ QQ三国
|
||||
TF版
|
||||
TF版本
|
||||
O不OK
|
||||
人均GDP
|
||||
|
@ -4,4 +4,7 @@ go 1.20
|
||||
|
||||
require github.com/deckarep/golang-set/v2 v2.3.0
|
||||
|
||||
require github.com/yanyiwu/gojieba v1.3.0
|
||||
require (
|
||||
github.com/yanyiwu/gojieba v1.3.0
|
||||
golang.org/x/sys v0.19.0
|
||||
)
|
||||
|
@ -2,3 +2,5 @@ github.com/deckarep/golang-set/v2 v2.3.0 h1:qs18EKUfHm2X9fA50Mr/M5hccg2tNnVqsiBI
|
||||
github.com/deckarep/golang-set/v2 v2.3.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
|
||||
github.com/yanyiwu/gojieba v1.3.0 h1:6VeaPOR+MawnImdeSvWNr7rP4tvUfnGlEKaoBnR33Ds=
|
||||
github.com/yanyiwu/gojieba v1.3.0/go.mod h1:54wkP7sMJ6bklf7yPl6F+JG71dzVUU1WigZbR47nGdY=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
|
@ -71,7 +71,8 @@ func areYouOK() {
|
||||
fmt.Println("Are you OK:")
|
||||
var isOK string
|
||||
_, _ = fmt.Scanf("%s", &isOK)
|
||||
if strings.ToLower(isOK) != "ok" {
|
||||
isOK = strings.ToLower(isOK)
|
||||
if isOK != "ok" && isOK != "y" && isOK != "yes" {
|
||||
os.Exit(123)
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,13 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"golang.org/x/sys/windows/registry"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -22,8 +24,8 @@ type lemma struct {
|
||||
}
|
||||
|
||||
var (
|
||||
mark = "# +_+" // 词库中的标记符号,表示从这行开始进行检查或排序
|
||||
RimeDir = getRimeDir() // Rime 配置目录
|
||||
mark = "# +_+" // 词库中的标记符号,表示从这行开始进行检查或排序
|
||||
RimeDir = getRimeDir() // Rime 配置目录
|
||||
|
||||
EmojiMapPath = filepath.Join(RimeDir, "others/emoji-map.txt")
|
||||
EmojiPath = filepath.Join(RimeDir, "opencc/emoji.txt")
|
||||
@ -43,13 +45,54 @@ var (
|
||||
汉字拼音映射TXT = filepath.Join(RimeDir, "others/script/rime/汉字拼音映射.txt")
|
||||
)
|
||||
|
||||
// 获取 macOS Rime 配置目录
|
||||
// 获取 macOS/Windows Rime 配置目录
|
||||
func getRimeDir() string {
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
var dir string
|
||||
switch runtime.GOOS {
|
||||
case "darwin": // macOS
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
dir = filepath.Join(u.HomeDir, "Library/Rime")
|
||||
case "windows": // Windows
|
||||
dir = getWeaselDir()
|
||||
default:
|
||||
log.Fatalf("Unsupported OS: %s so far", runtime.GOOS)
|
||||
}
|
||||
return filepath.Join(u.HomeDir, "Library/Rime")
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
func getWeaselDir() string {
|
||||
keyPath := `Software\Rime\Weasel`
|
||||
valueName := "RimeUserDir"
|
||||
|
||||
// Get from Windows registry
|
||||
k, err := registry.OpenKey(registry.CURRENT_USER, keyPath, registry.QUERY_VALUE)
|
||||
if err != nil {
|
||||
log.Printf("Failed to open registry key: %v\n", err)
|
||||
// Fallback to default dir
|
||||
return getDefaultWeaselDir()
|
||||
}
|
||||
defer k.Close()
|
||||
|
||||
rimeUserDir, _, err := k.GetStringValue(valueName)
|
||||
if err != nil {
|
||||
log.Printf("Failed to read registry value: %v\n", err)
|
||||
// Fallback to default dir
|
||||
return getDefaultWeaselDir()
|
||||
}
|
||||
|
||||
return rimeUserDir
|
||||
}
|
||||
|
||||
func getDefaultWeaselDir() string {
|
||||
appData := os.Getenv("APPDATA") // AppData\Roaming
|
||||
if appData == "" {
|
||||
log.Fatalln("APPDATA environment variable is not set.")
|
||||
}
|
||||
return filepath.Join(appData, "Rime")
|
||||
}
|
||||
|
||||
// 将所有词库读入 set,供检查或排序使用
|
||||
|
Loading…
Reference in New Issue
Block a user