Make log decoding build on non-Windows CI
Some checks failed
build-windows-exe / build (push) Failing after 1m43s

This commit is contained in:
messypy
2026-07-27 23:13:30 +09:00
parent dd165d9301
commit b25e002092
3 changed files with 57 additions and 33 deletions

View File

@@ -0,0 +1,7 @@
//go:build !windows
package app
func decodeWithCodePage(_ []byte, _ uint32) string {
return ""
}

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

View File

@@ -9,9 +9,8 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
"syscall"
"time" "time"
"unsafe" "unicode/utf16"
) )
var ( var (
@@ -315,14 +314,14 @@ func decodeVRChatLog(b []byte) string {
for i := 2; i+1 < len(b); i += 2 { for i := 2; i+1 < len(b); i += 2 {
u16 = append(u16, uint16(b[i])|uint16(b[i+1])<<8) 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 { if b[0] == 0xfe && b[1] == 0xff {
u16 := make([]uint16, 0, (len(b)-2)/2) u16 := make([]uint16, 0, (len(b)-2)/2)
for i := 2; i+1 < len(b); i += 2 { for i := 2; i+1 < len(b); i += 2 {
u16 = append(u16, uint16(b[i+1])|uint16(b[i])<<8) 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'}) lines := bytes.Split(b, []byte{'\n'})
@@ -377,6 +376,16 @@ func tryRepairShiftJISMojibake(s string) string {
return "" 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 { func scoreReadable(s string) int {
if s == "" { if s == "" {
return -1 return -1
@@ -401,35 +410,6 @@ func scoreReadable(s string) int {
return score 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) { func updateWorldState(state *vrcLogState, line string) (bool, string) {
worldID := "" worldID := ""
instanceID := "" instanceID := ""