File tree Expand file tree Collapse file tree 2 files changed +15
-28
lines changed Expand file tree Collapse file tree 2 files changed +15
-28
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "fmt "
4
+ "github.com/whtiehack/wingui/winapi "
5
5
"log"
6
6
"math/rand"
7
7
"net"
8
8
"net/url"
9
- "os"
10
- "os/exec"
11
9
"strconv"
12
- "strings"
13
10
"time"
14
11
"unsafe"
15
12
@@ -118,24 +115,6 @@ func randomMoveMouse() {
118
115
119
116
}
120
117
121
- func GetLocale () (string , error ) {
122
- // Check the LANG environment variable, common on UNIX.
123
- // XXX: we can easily override as a nice feature/bug.
124
- envlang , ok := os .LookupEnv ("LANG" )
125
- if ok {
126
- return strings .Split (envlang , "." )[0 ], nil
127
- }
128
-
129
- // Exec powershell Get-Culture on Windows.
130
- cmd := exec .Command ("powershell" , "Get-Culture | select -exp Name" )
131
- output , err := cmd .Output ()
132
- if err == nil {
133
- return strings .Trim (string (output ), "\r \n " ), nil
134
- }
135
-
136
- return "" , fmt .Errorf ("cannot determine locale" )
137
- }
138
-
139
118
type Statistics struct {
140
119
prevTime time.Time
141
120
si string
@@ -155,9 +134,8 @@ func NewStatistics(baseUrl string, si string) *Statistics {
155
134
params .Add ("et" , "0" )
156
135
params .Add ("ja" , "0" )
157
136
params .Add ("ln" , "zh-cn" )
158
- lang , err := GetLocale ()
159
- if err != nil {
160
- log .Println ("system lang:" , lang )
137
+ lang := winapi .GetSystemDefaultLocaleName ()
138
+ if lang != "" {
161
139
params .Set ("ln" , lang )
162
140
}
163
141
params .Add ("lo" , "0" )
Original file line number Diff line number Diff line change @@ -6,11 +6,20 @@ import (
6
6
)
7
7
8
8
var (
9
- kernel32 = syscall .NewLazyDLL ("kernel32.dll" )
10
- procCreateMutex = kernel32 .NewProc ("CreateMutexW" )
11
- procOpenMutex = kernel32 .NewProc ("OpenMutexW" )
9
+ kernel32 = syscall .NewLazyDLL ("kernel32.dll" )
10
+ procCreateMutex = kernel32 .NewProc ("CreateMutexW" )
11
+ procOpenMutex = kernel32 .NewProc ("OpenMutexW" )
12
+ getSystemDefaultLocaleName = kernel32 .NewProc ("GetSystemDefaultLocaleName" )
13
+ getSystemDefaultLCID = kernel32 .NewProc ("GetSystemDefaultLCID" )
12
14
)
13
15
16
+ func GetSystemDefaultLocaleName () string {
17
+ lcid , _ , _ := getSystemDefaultLCID .Call ()
18
+ buf := make ([]uint16 , 128 )
19
+ _ , _ , _ = getSystemDefaultLocaleName .Call (uintptr (unsafe .Pointer (& buf [0 ])), lcid )
20
+ return syscall .UTF16ToString (buf )
21
+ }
22
+
14
23
//CreateMutex kernel32 API CreateMutex
15
24
func CreateMutex (name string ) (uintptr , error ) {
16
25
paramMutexName := uintptr (unsafe .Pointer (syscall .StringToUTF16Ptr (name )))
You can’t perform that action at this time.
0 commit comments