-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind_latest_apks.go
49 lines (47 loc) · 1 KB
/
find_latest_apks.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
package updates
import (
"OwlGramServer/consts"
"fmt"
"os"
"path"
"strconv"
)
func (ctx *Context) findLatestApks(isBeta bool) string {
pathFiles := path.Join(consts.ServerFilesFolder, "versions")
f, err := os.Open(pathFiles)
if err != nil {
panic(fmt.Sprintf("Error opening folder %s", pathFiles))
return ""
}
files, err := f.Readdir(0)
if err != nil {
panic("Error reading directory")
}
latestVersion := -1
filePath := ""
for _, v := range files {
if v.IsDir() {
var fileName string
if isBeta {
fileName = path.Join(pathFiles, v.Name(), "universal-beta.apk")
} else {
fileName = path.Join(pathFiles, v.Name(), "universal-stable.apk")
}
if _, err := os.Stat(fileName); os.IsNotExist(err) {
continue
}
intVersion, err := strconv.Atoi(v.Name())
if err != nil {
continue
}
if intVersion > latestVersion {
latestVersion = intVersion
filePath = fileName
}
}
}
if latestVersion == -1 && isBeta {
ctx.findLatestApks(false)
}
return filePath
}