diff --git a/src/main/kotlin/ley/anvil/modpacktools/commands/BuildTechnic.kt b/src/main/kotlin/ley/anvil/modpacktools/commands/BuildTechnic.kt index eca7431..8d6eb71 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/commands/BuildTechnic.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/commands/BuildTechnic.kt @@ -1,6 +1,8 @@ package ley.anvil.modpacktools.commands import ley.anvil.addonscript.wrapper.FileOrLink +import ley.anvil.addonscript.wrapper.IInstaller +import ley.anvil.addonscript.wrapper.IInstaller.create import ley.anvil.modpacktools.CONFIG import ley.anvil.modpacktools.MPJH import ley.anvil.modpacktools.TERMC @@ -38,7 +40,7 @@ object BuildTechnic : AbstractCommand("BuildTechnic") { val fileList = mutableListOf() //Map of File to Installer - val toDownload = mutableMapOf() + val toDownload = mutableMapOf() //RELATIONS fileList.addAll( @@ -57,7 +59,7 @@ object BuildTechnic : AbstractCommand("BuildTechnic") { File(download, "modpack.jar"), forge.url ) - ] = "internal.dir:bin" + ] = create("internal.dir", listOf("bin"))!! fileList.forEach { when { @@ -74,7 +76,10 @@ object BuildTechnic : AbstractCommand("BuildTechnic") { downloadFiles(toDownload.keys.toList()) { if(it.downloadedFile != null) { - fPrintln("${it.responseCode} ${it.responseMessage} ${it.file.url} ${it.downloadedFile}", TERMC.brightBlue) + fPrintln( + "${it.responseCode} ${it.responseMessage} ${it.file.url} ${it.downloadedFile}", + TERMC.brightBlue + ) //Use map of file to installer to get installer for given file installFile(toDownload[it.file]!!, it.downloadedFile, tmp).printf() } else if(it.exception != null) { diff --git a/src/main/kotlin/ley/anvil/modpacktools/commands/DownloadMods.kt b/src/main/kotlin/ley/anvil/modpacktools/commands/DownloadMods.kt index e71b54e..3bd35da 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/commands/DownloadMods.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/commands/DownloadMods.kt @@ -48,14 +48,12 @@ object DownloadMods : AbstractCommand("DownloadMods") { fileList .filter {it.isURL} .filter { - val (installer, dir) = it.installer.split(':') - - installer == "internal.dir" && (args.getBoolean("all") || dir == "mods") + it.installer.installerID() == "internal.dir" && (args.getBoolean("all") || it.installer.arguments[0] == "mods") } .map { FileToDownload( if(args.getBoolean("all")) - File(args.get("dir"), it.installer.split(':')[1]) + File(args.get("dir"), it.installer.arguments[1]) else args.get("dir"), it.url, diff --git a/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt b/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt index c44ceb9..a5f126b 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/util/Util.kt @@ -169,3 +169,9 @@ fun File.unzip(outputDir: File) { fun ArgumentParser.arg(vararg names: String, block: Argument.() -> Unit) { addArgument(*names).block() } + +/** + * Gets the base name of the file without the directory. + */ +val File.baseName + get() = this.toPath().fileName.toString() diff --git a/src/main/kotlin/ley/anvil/modpacktools/util/addonscript/ASUtil.kt b/src/main/kotlin/ley/anvil/modpacktools/util/addonscript/ASUtil.kt index 9b228fb..694b102 100644 --- a/src/main/kotlin/ley/anvil/modpacktools/util/addonscript/ASUtil.kt +++ b/src/main/kotlin/ley/anvil/modpacktools/util/addonscript/ASUtil.kt @@ -2,7 +2,9 @@ package ley.anvil.modpacktools.util.addonscript import ley.anvil.addonscript.curse.ManifestJSON import ley.anvil.addonscript.wrapper.ASWrapper +import ley.anvil.addonscript.wrapper.IInstaller import ley.anvil.modpacktools.TERMC +import ley.anvil.modpacktools.util.baseName import ley.anvil.modpacktools.util.fPrintln import ley.anvil.modpacktools.util.manifest.ManifestLinksPair import org.apache.commons.io.FileUtils @@ -38,9 +40,9 @@ data class InstallFileSuccess( * @param file the file to install * @param outDir the directory to install the [file] to */ -fun installFile(installer: String, file: File, outDir: File): InstallFileSuccess { - when { - installer == "internal.override" -> { +fun installFile(installer: IInstaller, file: File, outDir: File): InstallFileSuccess { + when(installer.installerID()) { + "internal.override" -> { when { file.extension == "zip" -> { TODO("unzip to ./.mpt/twitch/overrides") @@ -56,12 +58,12 @@ fun installFile(installer: String, file: File, outDir: File): InstallFileSuccess } } - installer.startsWith("internal.dir") -> { - val (_, dir) = installer.split(":") - FileUtils.copyFile(file, File(outDir, dir).resolve(file)) + "internal.dir" -> { + val (dir) = installer.arguments + FileUtils.copyFile(file, File(outDir, dir).resolve(file.baseName)) } - installer.startsWith("internal.zip") -> { + "internal.zip" -> { TODO() } @@ -150,3 +152,10 @@ fun convertAStoManifest( return ml } + +fun installFile(installer: String, file: File, outDir: File) = + installFile( + installer.split(':').let {IInstaller.create(it[0], it.slice(1 until it.size))!!}, + file, + outDir + )