-
Notifications
You must be signed in to change notification settings - Fork 12
/
lib.go
63 lines (50 loc) · 1.09 KB
/
lib.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// +build windows
package gowebview
import (
"crypto/subtle"
"golang.org/x/crypto/blake2b"
"io"
"io/ioutil"
"os"
"path/filepath"
)
// extract will save all DLLs (or equivalent) into the given path. If the path is `C:\Something`, it will create exactly
// C:\Something\WebView2Loader.dll.
//
// The file is extracted by default when use `New(nil)`.
func extract(path string) error {
var approved int
blake, _ := blake2b.New256(nil)
for n, h := range FilesHashes {
blake.Reset()
file, err := os.Open(filepath.Join(path, n))
if err != nil {
if os.IsNotExist(err) {
continue
}
return err
}
_, err = io.Copy(blake, file)
if err != nil {
return err
}
if subtle.ConstantTimeCompare(h, blake.Sum(nil)) == 1 {
approved += 1
}
}
if approved == len(Files) {
return nil
}
if err := os.MkdirAll(path, 0755); err != nil {
return err
}
for n, f := range Files {
if _, err := os.Stat(filepath.Join(path, n)); !os.IsNotExist(err) {
continue
}
if err := ioutil.WriteFile(filepath.Join(path, n), f, 755); err != nil {
return err
}
}
return nil
}