From fbb631cf295099aae7f24b1e0d32df0683098e76 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 7 Feb 2024 20:55:51 -0600 Subject: [PATCH] Read all intended config files in correct order The intended order is: - jaunch.toml - jaunch-.toml - jaunch--.toml - launcher.toml - launcher-.toml - launcher--.toml Since later configuration details are *prepended* to earlier ones, which lets launcher- and platform-specific settings take precedence. --- src/commonMain/kotlin/Jaunch.kt | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/commonMain/kotlin/Jaunch.kt b/src/commonMain/kotlin/Jaunch.kt index bc77296..230a49a 100644 --- a/src/commonMain/kotlin/Jaunch.kt +++ b/src/commonMain/kotlin/Jaunch.kt @@ -74,20 +74,28 @@ fun main(args: Array) { error("Jaunch config directory not found. Please place config in one of: $configDirs") debug("configDir -> ", configDir) - // Load the configuration from the TOML file(s). - var config = readConfig(configDir / "jaunch.toml") - config += readConfig(configDir / "jaunch-$$OS_NAME.toml") - config += readConfig(configDir / "jaunch-$$OS_NAME-$CPU_ARCH.toml") + // Make a list of relevant configuration files to read. + val osName = OS_NAME.lowercase() + val cpuArch = CPU_ARCH.lowercase() + var config = JaunchConfig() + val configFiles = mutableListOf( + configDir / "jaunch.toml", + configDir / "jaunch-$osName.toml", + configDir / "jaunch-$osName-$cpuArch.toml", + ) if (exeFile != null) { - // Parse and merge the app-specific TOML file(s) as well. + // Include the app-specific config file(s) as well. + val index = configFiles.size var fileName = exeFile.base.name while (true) { - config += readConfig(configDir / "$fileName.toml") + configFiles.add(index, configDir / "$fileName.toml") val dash = fileName.lastIndexOf("-") if (dash < 0) break fileName = fileName.substring(0, dash) } } + // Read and merge all the config files. + for (configFile in configFiles) config += readConfig(configFile) val programName = config.programName ?: exeFile?.base?.name ?: "Jaunch" debug("programName -> ", programName)