返回 DeepSeek-Reasonix
find_dll.go
1 //go:build windows
2
3 package webviewloader
4
5 import (
6 "errors"
7 "fmt"
8 "os"
9 "path/filepath"
10 "runtime"
11
12 "golang.org/x/sys/windows/registry"
13 )
14
15 var (
16 errNoClientDLLFound = errors.New("no webview2 found")
17 )
18
19 func findEmbeddedBrowserVersion(filename string) (string, error) {
20 block, err := getFileVersionInfo(filename)
21 if err != nil {
22 return "", err
23 }
24
25 info, err := verQueryValueString(block, "\\StringFileInfo\\040904B0\\ProductVersion")
26 if err != nil {
27 return "", err
28 }
29
30 return info, nil
31 }
32
33 func findEmbeddedClientDll(embeddedEdgeSubFolder string) (outClientPath string, err error) {
34 if !filepath.IsAbs(embeddedEdgeSubFolder) {
35 exe, err := os.Executable()
36 if err != nil {
37 return "", err
38 }
39
40 embeddedEdgeSubFolder = filepath.Join(filepath.Dir(exe), embeddedEdgeSubFolder)
41 }
42
43 return findClientDllInFolder(embeddedEdgeSubFolder)
44 }
45
46 func findClientDllInFolder(folder string) (string, error) {
47 arch := ""
48 switch runtime.GOARCH {
49 case "arm64":
50 arch = "arm64"
51 case "amd64":
52 arch = "x64"
53 case "386":
54 arch = "x86"
55 default:
56 return "", fmt.Errorf("Unsupported architecture")
57 }
58
59 dllPath := filepath.Join(folder, "EBWebView", arch, "EmbeddedBrowserWebView.dll")
60 if _, err := os.Stat(dllPath); err != nil {
61 return "", mapFindErr(err)
62 }
63 return dllPath, nil
64 }
65
66 func mapFindErr(err error) error {
67 if errors.Is(err, registry.ErrNotExist) {
68 return errNoClientDLLFound
69 }
70 if errors.Is(err, os.ErrNotExist) {
71 return errNoClientDLLFound
72 }
73 return err
74 }
75
75 lines GO