diff --git a/serverpackcreator-api/src/commonMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt b/serverpackcreator-api/src/commonMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt index 5e233229c..eb509fb01 100644 --- a/serverpackcreator-api/src/commonMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt +++ b/serverpackcreator-api/src/commonMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt @@ -200,7 +200,8 @@ expect fun File.regexWalk( expect fun File.filteredWalk( filters: List, filterType: FilterType = FilterType.CONTAINS, - direction: FileWalkDirection = FileWalkDirection.TOP_DOWN + direction: FileWalkDirection = FileWalkDirection.TOP_DOWN, + recursive: Boolean = true ): MutableList /** diff --git a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/ServerPackHandler.kt b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/ServerPackHandler.kt index 5ef21cee2..6c7e9dd01 100644 --- a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/ServerPackHandler.kt +++ b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/ServerPackHandler.kt @@ -766,7 +766,7 @@ actual class ServerPackHandler actual constructor( modloader: String ): List { log.info("Preparing a list of mods to include in server pack...") - val filesInModsDir: Collection = File(modsDir).list().filter { entry -> modFileEndings.any { entry.endsWith(it) } }.map { File(it) } + val filesInModsDir: Collection = File(modsDir).filteredWalk(modFileEndings, FilterType.ENDS_WITH, FileWalkDirection.TOP_DOWN, recursive = false) val modsInModpack = TreeSet(filesInModsDir) val autodiscoveredClientMods: MutableList = ArrayList(100) diff --git a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt index ce339cfaf..f1a5773a8 100644 --- a/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt +++ b/serverpackcreator-api/src/jvmMain/kotlin/de/griefed/serverpackcreator/api/utilities/common/FileUtilities.kt @@ -460,19 +460,32 @@ actual fun File.regexWalk(filters: List, direction: FileWalkDirection): M actual fun File.filteredWalk( filters: List, filterType: FilterType, - direction: FileWalkDirection + direction: FileWalkDirection, + recursive: Boolean ): MutableList = when (filterType) { FilterType.CONTAINS -> { - this.walk(direction).asStream().filter { filters.contains(it.name) }.toList() + if (recursive) { + this.walk(direction).asStream().filter { filters.contains(it.name) }.toList() + } else { + this.walk(direction).maxDepth(1).asStream().filter { filters.contains(it.name) }.toList() + } } FilterType.ENDS_WITH -> { - this.walk(direction).asStream().filter { filters.endsWith(it.name) }.toList() + if (recursive) { + this.walk(direction).asStream().filter { filters.endsWith(it.name) }.toList() + } else { + this.walk(direction).maxDepth(1).asStream().filter { filters.endsWith(it.name) }.toList() + } } FilterType.STARTS_WITH -> { - this.walk(direction).asStream().filter { filters.startsWith(it.name) }.toList() + if (recursive) { + this.walk(direction).asStream().filter { filters.startsWith(it.name) }.toList() + } else { + this.walk(direction).maxDepth(1).asStream().filter { filters.endsWith(it.name) }.toList() + } } }