forked from MatsuriDayo/Matsuri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.go
78 lines (62 loc) · 1.67 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
74
75
76
77
78
package libcore
import (
"fmt"
"libcore/device"
"os"
"path/filepath"
"strings"
"time"
)
func Setenv(key, value string) error {
return os.Setenv(key, value)
}
func Unsetenv(key string) error {
return os.Unsetenv(key)
}
func initCoreDefer() {
device.AllDefer("InitCore", ForceLog)
}
func InitCore(internalAssets string, externalAssets string, prefix string, useOfficial BoolFunc, // extractV2RayAssets
cachePath string, process string, //InitCore
enableLog bool, maxKB int32, //SetEnableLog
) {
defer initCoreDefer()
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 initCoreDefer()
device.GoDebug(process)
externalAssetsPath = externalAssets
internalAssetsPath = internalAssets
assetsPrefix = prefix
Setenv("v2ray.conf.geoloader", "memconservative")
setupV2rayFileSystem(internalAssets, externalAssets)
setupResolvers()
if time.Now().Unix() >= GetExpireTime() {
outdated = "Your version is too old! Please update!! 版本太旧,请升级!"
} else if time.Now().Unix() < (GetBuildTime() - 86400) {
outdated = "Wrong system time! 系统时间错误!"
}
// Extract assets
if isBgProcess {
extractV2RayAssets(useOfficial)
}
}()
if !isBgProcess {
return
}
device.AutoGoMaxProcs()
}