-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmega_lib.go
115 lines (99 loc) · 1.94 KB
/
mega_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"github.com/cheikhshift/gos/core"
"os"
"path/filepath"
"runtime"
"strings"
"time"
)
func inArr(arr []string, lookup string) (res bool) {
for _, val := range arr {
if val == lookup {
res = true
}
}
return
}
//Verify if the last time your
// logs were reset
// exceeds the set period and delete the server's.
// request log.
func ShouldDeleteLog(server string) {
now := time.Now().Unix()
if Config.Misc.ResetInterval == 0 {
return
}
if (now - Config.LastReset) > (DayInSeconds * Config.Misc.ResetInterval) {
DeleteLog(server)
}
}
func InitConfigLoad() {
logpath := filepath.Join(megaWorkspace, logDirectory)
if _, err := os.Stat(logpath); os.IsNotExist(err) {
err = os.MkdirAll(logpath, 0700)
if err != nil {
panic(err)
}
Config = &MegaConfig{}
if DispatcherAddressPort != DefaultAddress {
SaveConfig(&Config)
}
} else {
err = LoadConfig(&Config)
if err != nil {
Config = &MegaConfig{}
}
}
}
func LaunchBrowser() {
Windows := strings.Contains(runtime.GOOS, "windows")
if Prod {
if !Windows {
if isMac := strings.Contains(runtime.GOOS, "arwin"); isMac {
core.RunCmd(DarwinOpen)
} else {
core.RunCmd(LinuxOpen)
}
} else {
core.RunCmd(NTOpen)
}
}
}
func ChdirHome() {
Windows := strings.Contains(runtime.GOOS, "windows")
if Windows {
os.Chdir(os.ExpandEnv("$USERPROFILE"))
} else {
os.Chdir(os.ExpandEnv("$HOME"))
}
}
func AddToHistory(ID string) {
ShouldLock()
Config.AlertsHistory[ID] = false
ShouldUnlock()
}
func RemoveWithID(ID string) {
ShouldLock()
delete(Config.AlertsHistory, ID)
ShouldUnlock()
}
func ClearHistory() {
ShouldLock()
Config.AlertsHistory = make(Tracker)
ShouldUnlock()
}
func CheckHistory(ID string) (exists bool) {
ShouldLock()
_, exists = Config.AlertsHistory[ID]
ShouldUnlock()
return
}
func ShouldAlert(ID string) (alert bool) {
InHistory := CheckHistory(ID)
if !InHistory {
alert = true
AddToHistory(ID)
}
return
}