4
0
Fork 0
mirror of https://github.com/Anvilcraft/modpacktools synced 2024-05-19 20:04:07 +02:00

fix installer stuff due to new as version

This commit is contained in:
LordMZTE 2020-08-19 15:05:13 +02:00
parent 4944f7c934
commit dcc36e7ebf
4 changed files with 32 additions and 14 deletions

View file

@ -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<FileOrLink>()
//Map of File to Installer
val toDownload = mutableMapOf<FileToDownload, String>()
val toDownload = mutableMapOf<FileToDownload, IInstaller>()
//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) {

View file

@ -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<File>("dir"), it.installer.split(':')[1])
File(args.get<File>("dir"), it.installer.arguments[1])
else
args.get("dir"),
it.url,

View file

@ -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()

View file

@ -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
)