-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
229 lines (196 loc) · 5.39 KB
/
main.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
)
const cdn string = "http://cdn-11.eft-store.com"
type eftDLV struct {
GameType string
Version string
GUID string
Size string
URL string
}
var categories = map[string][]eftDLV{
"EFT": make([]eftDLV, 0),
"ETS": make([]eftDLV, 0),
"ARENA": make([]eftDLV, 0),
}
func main() {
logDirectory := filepath.Join(os.Getenv("USERPROFILE"), "AppData", "Local", "Battlestate Games", "BsgLauncher", "Logs")
_, err := os.Stat(logDirectory)
if err != nil {
if os.IsNotExist(err) {
fmt.Println("Folder does not exist, exiting")
os.Exit(0)
} else {
fmt.Println(err)
fmt.Println("Error checking folder at:", logDirectory)
os.Exit(0)
}
}
fmt.Println()
fmt.Println(">> Automatic DownloadLink Creator from BsgLauncher Logs <<")
fmt.Println("Created by TheMaoci; Rewritten by King")
logFiles, err := os.ReadDir(logDirectory)
if err != nil {
fmt.Println(err)
fmt.Println("Unable to read", logDirectory)
os.Exit(0)
}
var fileName, filePath string
fmt.Println("--------------------")
fmt.Println("Detected 'Game Versions' on your machine:")
fmt.Println()
for _, file := range logFiles {
fileName = file.Name()
if !strings.Contains(fileName, "BSG_Launcher_") {
continue
}
filePath = filepath.Join(logDirectory, fileName)
lines := readLines(filePath, "(DWN1) The file", "has a size of")
if len(lines) == 0 {
continue
}
for _, line := range lines {
extractInfo(line)
}
}
for name, category := range categories {
sort.SliceStable(category, func(i, j int) bool {
return category[i].Version < category[j].Version
})
fmt.Println("[", name, "]")
for _, dlv := range category {
if dlv.Version != "" && dlv.GUID != "" && dlv.URL != "" {
fmt.Println("Version:", dlv.Version, "GUID:", dlv.GUID, "FileSize:", dlv.Size)
fmt.Println("Download Link:", dlv.URL)
fmt.Println()
}
}
}
//for name, category := range categories {
// fmt.Println("[", name, "]")
// for _, dlv := range category {
// if dlv.Version != "" && dlv.GUID != "" && dlv.URL != "" {
// fmt.Println("Version:", dlv.Version, "GUID:", dlv.GUID, "FileSize:", dlv.Size)
// fmt.Println("Download Link:", dlv.URL)
// fmt.Println()
// }
// }
//}
fmt.Println("Press Enter to exit...")
_, err = fmt.Scanln()
if err != nil {
return
}
}
// var output = make([]eftDLV, 0)
var duplicates = make(map[string]struct{})
func extractInfo(line string) {
var isUpdate bool
var clientInfo string
var gameType string
var filepathSplit = "/client"
var guidSplit []string
if strings.Contains(line, "/arena/client") {
gameType = "ARENA"
filepathSplit = "/arena"
} else if strings.Contains(line, "/eft/client") {
if strings.Contains(line, "ets") {
gameType = "ETS"
} else {
gameType = "EFT"
}
filepathSplit = "/eft"
}
if strings.Contains(line, ".update") {
isUpdate = true
clientInfo = line[strings.Index(line, filepathSplit):strings.Index(line, ".update")]
} else if strings.Contains(line, ".zip") {
clientInfo = line[strings.Index(line, filepathSplit):strings.Index(line, ".zip")]
} else {
fmt.Println(".update or .zip was not found on line, exiting")
fmt.Println()
os.Exit(0)
}
splitClientInfo := strings.Split(clientInfo, "/")
if filepathSplit == "/eft" || filepathSplit == "/arena" {
guidSplit = strings.Split(splitClientInfo[5], "_")
} else {
guidSplit = strings.Split(splitClientInfo[4], "_")
}
if isUpdate {
updateURL := cdn + clientInfo + ".update"
if _, ok := duplicates[guidSplit[0]]; ok {
return
}
categories[gameType] = append(categories[gameType], eftDLV{
GameType: gameType,
Version: guidSplit[0],
GUID: guidSplit[1],
URL: updateURL,
Size: line[strings.Index(line, "size of")+8:],
})
duplicates[guidSplit[0]] = struct{}{}
if filepathSplit == "/client" {
versionSplit := strings.Split(guidSplit[0], "-")[1]
if _, ok := duplicates[versionSplit]; ok {
return
}
zipURL := cdn + "/" + splitClientInfo[1] + "/" + splitClientInfo[2] + "/distribs/" + versionSplit + "_" + guidSplit[1] + "/Client." + versionSplit + ".zip"
categories[gameType] = append(categories[gameType], eftDLV{
GameType: gameType,
Version: versionSplit,
GUID: guidSplit[1],
URL: zipURL,
Size: "Unknown",
})
duplicates[versionSplit] = struct{}{}
}
} else {
if _, ok := duplicates[guidSplit[0]]; ok {
return
}
categories[gameType] = append(categories[gameType], eftDLV{
GameType: gameType,
Version: guidSplit[0],
GUID: guidSplit[1],
URL: cdn + clientInfo + ".zip",
Size: line[strings.Index(line, "size of")+8:],
})
duplicates[guidSplit[0]] = struct{}{}
}
}
const errorSubstring = "Substrings '%s' and '%s' not found in file '%s'"
var buffer = make([]string, 0, 1024)
func readLines(filename string, firstSubstring string, secondSubstring string) []string {
buffer = buffer[0:]
output := make([]string, 0)
file, err := os.Open(filename)
if err != nil {
return output
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
fmt.Println(err)
os.Exit(0)
}
}(file)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, firstSubstring) && strings.Contains(line, secondSubstring) {
output = append(output, line)
}
}
if err := scanner.Err(); err != nil {
return output
}
return output
}