forked from lambda-client/lambda-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigManager.kt
More file actions
56 lines (46 loc) · 1.87 KB
/
ConfigManager.kt
File metadata and controls
56 lines (46 loc) · 1.87 KB
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
package com.lambda.loader.config
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.JsonObject
import java.io.File
object ConfigManager {
private val configFile: File = File("lambda/config", "modules.json")
private val gson: Gson = GsonBuilder().setPrettyPrinting().create()
var config: Config = loadConfig()
private fun loadConfig(): Config {
return if (configFile.exists()) {
try {
val json = configFile.readText()
val rootObject = gson.fromJson(json, JsonObject::class.java)
// Extract AutoUpdater object
val autoUpdater = rootObject.getAsJsonObject("AutoUpdater")
if (autoUpdater != null) {
val debug = autoUpdater.get("Debug")?.asBoolean ?: false
val loaderBranch = autoUpdater.get("Loader Branch")?.asString ?: "RELEASE"
val clientBranch = autoUpdater.get("Client Branch")?.asString ?: "RELEASE"
Config(
clientReleaseMode = branchToReleaseMode(clientBranch),
loaderReleaseMode = branchToReleaseMode(loaderBranch),
debug = debug
)
} else {
// AutoUpdater section doesn't exist, use defaults
Config()
}
} catch (_: Exception) {
// If parsing fails, use defaults
Config()
}
} else {
// Config file doesn't exist, use defaults
Config()
}
}
private fun branchToReleaseMode(branch: String): ReleaseMode {
return when (branch.uppercase()) {
"RELEASE", "STABLE" -> ReleaseMode.STABLE
"SNAPSHOT" -> ReleaseMode.SNAPSHOT
else -> ReleaseMode.STABLE
}
}
}