forked from MatsuriDayo/Matsuri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.go
73 lines (58 loc) · 1.61 KB
/
core.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
64
65
66
67
68
69
70
71
72
73
package libcore
import (
"fmt"
"libcore/device"
"os"
"path/filepath"
"strings"
)
func Setenv(key, value string) error {
return os.Setenv(key, value)
}
func Unsetenv(key string) error {
return os.Unsetenv(key)
}
func InitCore(internalAssets string, externalAssets string, prefix string, useOfficial BoolFunc, // extractV2RayAssets
cachePath string, process string, //InitCore
enableLog bool, maxKB int32, //SetEnableLog
) {
defer device.DeferPanicToError("InitCore", func(err error) { ForceLog(fmt.Sprintln(err)) })
isBgProcess := strings.HasSuffix(process, ":bg")
// Working dir
os.Chdir(filepath.Join(cachePath, "../no_backup"))
// Set up log
SetEnableLog(enableLog, maxKB)
s := fmt.Sprintln("InitCore called", externalAssets, cachePath, process, isBgProcess)
s = strings.TrimRight(s, "\n")
err := setupLogger(filepath.Join(cachePath, "neko.log"))
if err == nil {
go ForceLog(s)
} else {
// not fatal
// ForceLog(fmt.Sprintln("Log not inited:", s, err.Error()))
}
// Set up some component
go func() {
defer device.DeferPanicToError("InitCore-go", func(err error) { ForceLog(fmt.Sprintln(err)) })
device.GoDebug(process)
externalAssetsPath = externalAssets
internalAssetsPath = internalAssets
assetsPrefix = prefix
Setenv("v2ray.conf.geoloader", "memconservative")
setupV2rayFileSystem(internalAssets, externalAssets)
setupResolvers()
// certs
pem, err := os.ReadFile(externalAssetsPath + "ca.pem")
if err == nil {
updateRootCACerts(pem)
}
// Extract assets
if isBgProcess {
extractV2RayAssets(useOfficial)
}
}()
if !isBgProcess {
return
}
device.AutoGoMaxProcs()
}