Skip to content

Commit

Permalink
Look for config files in the configDir
Browse files Browse the repository at this point in the history
Instead of appDir.
  • Loading branch information
hinerm committed May 20, 2024
1 parent 0171b23 commit e44236b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/commonMain/kotlin/vars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ class Vars(appDir: File, configDir: File, exeFile: File?) {
vars["config-dir"] = configDir.path
if (exeFile?.exists == true) vars["executable"] = exeFile.path

// Read matching .cfg files, containing key=value pairs, from the app-dir.
var cfgName = exeFile?.base?.name
// Build the list of config files
val cfgFiles = mutableListOf<File>()
var cfgName = exeFile?.base?.name
while (cfgName != null) {
val cfgFile = appDir / "$cfgName.cfg"
val cfgFile = configDir / "$cfgName.cfg"
if (cfgFile.exists) cfgFiles += cfgFile
val dash = cfgName.lastIndexOf("-")
cfgName = if (dash < 0) null else cfgName.substring(0, dash)
}

// Read matching .cfg files, containing key=value pairs.
for (cfgFile in cfgFiles.reversed()) {
vars += cfgFile.lines()
.filter { it.indexOf("=") >= 0 }
Expand Down

0 comments on commit e44236b

Please sign in to comment.