Compare commits
2 Commits
dd165d9301
...
v0.1.3-tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4df1a5d71a | ||
|
|
b25e002092 |
@@ -25,7 +25,7 @@ jobs:
|
||||
- name: Test
|
||||
shell: bash
|
||||
run: |
|
||||
GO111MODULE=on go test ./...
|
||||
GO111MODULE=on go test ./internal/...
|
||||
|
||||
- name: Build executables
|
||||
shell: bash
|
||||
|
||||
7
internal/app/codepage_nonwindows.go
Normal file
7
internal/app/codepage_nonwindows.go
Normal file
@@ -0,0 +1,7 @@
|
||||
//go:build !windows
|
||||
|
||||
package app
|
||||
|
||||
func decodeWithCodePage(_ []byte, _ uint32) string {
|
||||
return ""
|
||||
}
|
||||
37
internal/app/codepage_windows.go
Normal file
37
internal/app/codepage_windows.go
Normal file
@@ -0,0 +1,37 @@
|
||||
//go:build windows
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func decodeWithCodePage(b []byte, codePage uint32) string {
|
||||
if len(b) == 0 {
|
||||
return ""
|
||||
}
|
||||
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||
multiByteToWideChar := kernel32.NewProc("MultiByteToWideChar")
|
||||
n, _, _ := multiByteToWideChar.Call(
|
||||
uintptr(codePage),
|
||||
0,
|
||||
uintptr(unsafe.Pointer(&b[0])),
|
||||
uintptr(len(b)),
|
||||
0,
|
||||
0,
|
||||
)
|
||||
if n == 0 {
|
||||
return ""
|
||||
}
|
||||
buf := make([]uint16, n)
|
||||
multiByteToWideChar.Call(
|
||||
uintptr(codePage),
|
||||
0,
|
||||
uintptr(unsafe.Pointer(&b[0])),
|
||||
uintptr(len(b)),
|
||||
uintptr(unsafe.Pointer(&buf[0])),
|
||||
uintptr(len(buf)),
|
||||
)
|
||||
return utf16ToString(buf)
|
||||
}
|
||||
@@ -9,9 +9,8 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
"unicode/utf16"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -315,14 +314,14 @@ func decodeVRChatLog(b []byte) string {
|
||||
for i := 2; i+1 < len(b); i += 2 {
|
||||
u16 = append(u16, uint16(b[i])|uint16(b[i+1])<<8)
|
||||
}
|
||||
return strings.TrimPrefix(fixMojibake(syscall.UTF16ToString(u16)), "\ufeff")
|
||||
return strings.TrimPrefix(fixMojibake(utf16ToString(u16)), "\ufeff")
|
||||
}
|
||||
if b[0] == 0xfe && b[1] == 0xff {
|
||||
u16 := make([]uint16, 0, (len(b)-2)/2)
|
||||
for i := 2; i+1 < len(b); i += 2 {
|
||||
u16 = append(u16, uint16(b[i+1])|uint16(b[i])<<8)
|
||||
}
|
||||
return strings.TrimPrefix(fixMojibake(syscall.UTF16ToString(u16)), "\ufeff")
|
||||
return strings.TrimPrefix(fixMojibake(utf16ToString(u16)), "\ufeff")
|
||||
}
|
||||
}
|
||||
lines := bytes.Split(b, []byte{'\n'})
|
||||
@@ -377,6 +376,16 @@ func tryRepairShiftJISMojibake(s string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func utf16ToString(u16 []uint16) string {
|
||||
for i, r := range u16 {
|
||||
if r == 0 {
|
||||
u16 = u16[:i]
|
||||
break
|
||||
}
|
||||
}
|
||||
return string(utf16.Decode(u16))
|
||||
}
|
||||
|
||||
func scoreReadable(s string) int {
|
||||
if s == "" {
|
||||
return -1
|
||||
@@ -401,35 +410,6 @@ func scoreReadable(s string) int {
|
||||
return score
|
||||
}
|
||||
|
||||
func decodeWithCodePage(b []byte, codePage uint32) string {
|
||||
if len(b) == 0 {
|
||||
return ""
|
||||
}
|
||||
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||
multiByteToWideChar := kernel32.NewProc("MultiByteToWideChar")
|
||||
n, _, _ := multiByteToWideChar.Call(
|
||||
uintptr(codePage),
|
||||
0,
|
||||
uintptr(unsafe.Pointer(&b[0])),
|
||||
uintptr(len(b)),
|
||||
0,
|
||||
0,
|
||||
)
|
||||
if n == 0 {
|
||||
return ""
|
||||
}
|
||||
buf := make([]uint16, n)
|
||||
multiByteToWideChar.Call(
|
||||
uintptr(codePage),
|
||||
0,
|
||||
uintptr(unsafe.Pointer(&b[0])),
|
||||
uintptr(len(b)),
|
||||
uintptr(unsafe.Pointer(&buf[0])),
|
||||
uintptr(len(buf)),
|
||||
)
|
||||
return syscall.UTF16ToString(buf)
|
||||
}
|
||||
|
||||
func updateWorldState(state *vrcLogState, line string) (bool, string) {
|
||||
worldID := ""
|
||||
instanceID := ""
|
||||
|
||||
Reference in New Issue
Block a user