feat/dict: Support updating Rime user dir via script on Windows and add entries for GDP per capita (#793)

This commit is contained in:
hegotit 2024-04-12 23:05:30 +08:00 committed by GitHub
parent 83aa7087e2
commit 4b3184fcf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 75 additions and 10 deletions

View File

@ -908,3 +908,5 @@ TF版本 TFbanben
TF版本 tfbanben
O不OK ObuOK
O不OK obuok
人均GDP renjunGDP
人均GDP renjungdp

View File

@ -908,3 +908,5 @@ TF版本 TFbjbf
TF版本 tfbjbf
O不OK ObuOK
O不OK obuok
人均GDP rfjnGDP
人均GDP rfjngdp

View File

@ -908,3 +908,5 @@ TF版本 TFbjbf
TF版本 tfbjbf
O不OK ObuOK
O不OK obuok
人均GDP rfjpGDP
人均GDP rfjpgdp

View File

@ -908,3 +908,5 @@ TF版本 TFbjbf
TF版本 tfbjbf
O不OK ObuOK
O不OK obuok
人均GDP rfjyGDP
人均GDP rfjygdp

View File

@ -908,3 +908,5 @@ TF版本 TFbjbf
TF版本 tfbjbf
O不OK ObuOK
O不OK obuok
人均GDP rfjpGDP
人均GDP rfjpgdp

View File

@ -908,3 +908,5 @@ TF版本 TFbjbf
TF版本 tfbjbf
O不OK ObuOK
O不OK obuok
人均GDP rfjpGDP
人均GDP rfjpgdp

View File

@ -908,3 +908,5 @@ TF版本 TFbrbw
TF版本 tfbrbw
O不OK ObuOK
O不OK obuok
人均GDP rwjmGDP
人均GDP rwjmgdp

View File

@ -7911,7 +7911,6 @@ GCC GCC
# GCSE GCSE
# gd gd
# GDB GDB
GDP GDP
# ge ge
gear gear
geared geared

View File

@ -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

View File

@ -460,3 +460,4 @@ QQ三国
TF版
TF版本
O不OK
人均GDP

View File

@ -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
)

View File

@ -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=

View File

@ -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)
}
}

View File

@ -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"
@ -43,13 +45,54 @@ var (
汉字拼音映射TXT = filepath.Join(RimeDir, "others/script/rime/汉字拼音映射.txt")
)
// 获取 macOS Rime 配置目录
// 获取 macOS/Windows Rime 配置目录
func getRimeDir() string {
var dir string
switch runtime.GOOS {
case "darwin": // macOS
u, err := user.Current()
if err != nil {
log.Fatalln(err)
}
return filepath.Join(u.HomeDir, "Library/Rime")
dir = filepath.Join(u.HomeDir, "Library/Rime")
case "windows": // Windows
dir = getWeaselDir()
default:
log.Fatalf("Unsupported OS: %s so far", runtime.GOOS)
}
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供检查或排序使用