Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/kotlin/com/lambda/loader/LoaderVersionController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LoaderVersionController(
* The maven repository URL for the loader artifacts.
* Can be overridden for testing or custom repositories.
*/
loaderMavenUrl: String = "https://maven.thcfree.dev"
loaderMavenUrl: String = "https://maven.lambda-client.org"
) : BaseMavenVersionController(cache, versionMatchingEnabled = false) {

override val mavenUrl: String = loaderMavenUrl
Expand Down Expand Up @@ -48,7 +48,7 @@ class LoaderVersionController(

if (loaderMod.isPresent) {
val version = loaderMod.get().metadata.version.friendlyString
if (com.lambda.loader.config.ConfigManager.config.debug) {
if (ConfigManager.config.debug) {
logger.info("Current loader version: $version")
}
return version
Expand Down Expand Up @@ -85,7 +85,7 @@ class LoaderVersionController(
val currentVersion = getCurrentLoaderVersion()

// Try to get latest version based on release mode, with fallback
var latestVersion = when (getReleaseMode()) {
val latestVersion = when (getReleaseMode()) {
ReleaseMode.STABLE -> {
val releaseVersion = checkReleasesVersion()
if (releaseVersion == null) {
Expand Down
59 changes: 31 additions & 28 deletions src/main/kotlin/com/lambda/loader/config/ConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,55 @@ 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", "loader.json")
private val configFile: File = File("lambda/config", "modules.json")
private val gson: Gson = GsonBuilder().setPrettyPrinting().create()

var config: Config = loadConfig()
private set

private fun loadConfig(): Config {
return if (configFile.exists()) {
try {
val json = configFile.readText()
val loadedConfig = gson.fromJson(json, Config::class.java)

// Merge with defaults to handle new fields
val defaultConfig = Config()
val mergedConfig = Config(
clientReleaseMode = loadedConfig?.clientReleaseMode ?: defaultConfig.clientReleaseMode,
loaderReleaseMode = loadedConfig?.loaderReleaseMode ?: defaultConfig.loaderReleaseMode,
debug = loadedConfig?.debug ?: defaultConfig.debug
)

// Save merged config to add any new fields
saveConfig(mergedConfig)
mergedConfig
} catch (e: Exception) {
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
val defaultConfig = Config()
saveConfig(defaultConfig)
defaultConfig
Config()
}
} else {
val defaultConfig = Config()
saveConfig(defaultConfig)
defaultConfig
// Config file doesn't exist, use defaults
Config()
}
}

fun saveConfig(config: Config) {
if (!configFile.parentFile.exists()) {
configFile.parentFile.mkdirs()
private fun branchToReleaseMode(branch: String): ReleaseMode {
return when (branch.uppercase()) {
"RELEASE", "STABLE" -> ReleaseMode.STABLE
"SNAPSHOT" -> ReleaseMode.SNAPSHOT
else -> ReleaseMode.STABLE
}
val json = gson.toJson(config)
configFile.writeText(json)
this.config = config
}

}
22 changes: 11 additions & 11 deletions src/test/kotlin/com/lambda/loader/VersionControllerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class VersionControllerTest {

// Test STABLE mode
println("Checking STABLE releases for MC $mcVersion...")
ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE)

val stableJar = versionController.getOrDownloadLatestVersion()
if (stableJar != null) {
Expand All @@ -105,7 +105,7 @@ class VersionControllerTest {

// Test SNAPSHOT mode
println("Checking SNAPSHOT releases for MC $mcVersion...")
ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.SNAPSHOT))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.SNAPSHOT)

val snapshotJar = versionController.getOrDownloadLatestVersion()
if (snapshotJar != null) {
Expand Down Expand Up @@ -136,7 +136,7 @@ class VersionControllerTest {
val versionController = VersionController(minecraftVersionOverride = mcVersion)

// Set to STABLE mode
ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE)

val jarFile = versionController.getOrDownloadLatestVersion()

Expand Down Expand Up @@ -166,7 +166,7 @@ class VersionControllerTest {
val versionController = VersionController(minecraftVersionOverride = mcVersion)

// Set to SNAPSHOT mode
ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.SNAPSHOT))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.SNAPSHOT)

val jarFile = versionController.getOrDownloadLatestVersion()

Expand Down Expand Up @@ -194,7 +194,7 @@ class VersionControllerTest {

val versionController = VersionController(minecraftVersionOverride = mcVersion)

ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE)

// First call - should download
val jarFile1 = versionController.getOrDownloadLatestVersion()
Expand Down Expand Up @@ -224,7 +224,7 @@ class VersionControllerTest {

val versionController = VersionController(minecraftVersionOverride = mcVersion)

ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE)

val jarFile = versionController.getOrDownloadLatestVersion()
assertNotNull(jarFile, "JAR file should not be null")
Expand All @@ -250,13 +250,13 @@ class VersionControllerTest {
val versionController = VersionController(minecraftVersionOverride = mcVersion)

// Get STABLE version
ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE)
val stableJar = versionController.getOrDownloadLatestVersion()
assertNotNull(stableJar, "STABLE JAR should not be null")
println("STABLE: ${stableJar!!.name}")

// Switch to SNAPSHOT
ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.SNAPSHOT))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.SNAPSHOT)
val snapshotJar = versionController.getOrDownloadLatestVersion()
assertNotNull(snapshotJar, "SNAPSHOT JAR should not be null")
println("SNAPSHOT: ${snapshotJar!!.name}")
Expand Down Expand Up @@ -284,7 +284,7 @@ class VersionControllerTest {
val versionController = VersionController(minecraftVersionOverride = mcVersion)

// Test SNAPSHOT mode (more likely to have versions available)
ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.SNAPSHOT))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.SNAPSHOT)
val jarFile = versionController.getOrDownloadLatestVersion()

if (jarFile != null) {
Expand Down Expand Up @@ -329,7 +329,7 @@ class VersionControllerTest {
val versionController = VersionController(minecraftVersionOverride = mcVersion)

// Set to STABLE mode - should fallback to snapshot if stable doesn't exist
ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE, debug = true))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE, debug = true)

val jarFile = versionController.getOrDownloadLatestVersion()

Expand All @@ -355,7 +355,7 @@ class VersionControllerTest {
val versionController = VersionController(minecraftVersionOverride = nonExistentVersion)

// Set to STABLE mode
ConfigManager.saveConfig(ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE, debug = true))
ConfigManager.config = ConfigManager.config.copy(clientReleaseMode = ReleaseMode.STABLE, debug = true)

val jarFile = versionController.getOrDownloadLatestVersion()

Expand Down