mirror of
https://github.com/Anvilcraft/modpacktools
synced 2024-06-02 10:39:59 +02:00
started making BuildTechnic command. not yet working
local files aren't being installed for no good reason whatsoever mod loader not getting installed yet
This commit is contained in:
parent
5b29bfe3f4
commit
e67995d6a0
|
@ -46,7 +46,7 @@ dependencies {
|
||||||
"org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.8",
|
"org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.8",
|
||||||
|
|
||||||
//IO
|
//IO
|
||||||
"com.squareup.okhttp3:okhttp:4.8.0", //HTTP client
|
"com.squareup.okhttp3:okhttp:4.8.1", //HTTP client
|
||||||
"com.moandjiezana.toml:toml4j:0.7.2", //Config file parser
|
"com.moandjiezana.toml:toml4j:0.7.2", //Config file parser
|
||||||
"org.apache.commons:commons-csv:1.8",
|
"org.apache.commons:commons-csv:1.8",
|
||||||
"com.j2html:j2html:1.4.0", //HTML builder
|
"com.j2html:j2html:1.4.0", //HTML builder
|
||||||
|
@ -68,6 +68,7 @@ dependencies {
|
||||||
|
|
||||||
//This exists so options can be set for test compile and compile at once
|
//This exists so options can be set for test compile and compile at once
|
||||||
val kOptions = {obj: GroovyObject ->
|
val kOptions = {obj: GroovyObject ->
|
||||||
|
|
||||||
//This is sorta garbage, but if i would do this the proper way Intelli'ntJ would think its an error even tho it is not
|
//This is sorta garbage, but if i would do this the proper way Intelli'ntJ would think its an error even tho it is not
|
||||||
obj.withGroovyBuilder {
|
obj.withGroovyBuilder {
|
||||||
"kotlinOptions" {
|
"kotlinOptions" {
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
package ley.anvil.modpacktools.commands
|
||||||
|
|
||||||
|
import ley.anvil.addonscript.wrapper.FileOrLink
|
||||||
|
import ley.anvil.modpacktools.CONFIG
|
||||||
|
import ley.anvil.modpacktools.MPJH
|
||||||
|
import ley.anvil.modpacktools.TERMC
|
||||||
|
import ley.anvil.modpacktools.command.CommandReturn
|
||||||
|
import ley.anvil.modpacktools.command.CommandReturn.Companion.fail
|
||||||
|
import ley.anvil.modpacktools.command.ICommand
|
||||||
|
import ley.anvil.modpacktools.command.LoadCommand
|
||||||
|
import ley.anvil.modpacktools.util.addonscript.installFile
|
||||||
|
import ley.anvil.modpacktools.util.downloadFiles
|
||||||
|
import ley.anvil.modpacktools.util.fPrintln
|
||||||
|
import ley.anvil.modpacktools.util.toZip
|
||||||
|
import net.sourceforge.argparse4j.ArgumentParsers
|
||||||
|
import net.sourceforge.argparse4j.inf.ArgumentParser
|
||||||
|
import net.sourceforge.argparse4j.inf.Namespace
|
||||||
|
import org.apache.commons.io.FileUtils
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.net.URL
|
||||||
|
import java.util.zip.ZipOutputStream
|
||||||
|
|
||||||
|
@LoadCommand
|
||||||
|
object BuildTechnic : ICommand {
|
||||||
|
override val name = "buildtechnic"
|
||||||
|
override val helpMessage = "Builds a technic export"
|
||||||
|
|
||||||
|
override val parser: ArgumentParser = ArgumentParsers.newFor("BuildTechnic")
|
||||||
|
.build()
|
||||||
|
.description(helpMessage)
|
||||||
|
|
||||||
|
private val tempDir by lazy {File(CONFIG.config.pathOrException<String>("Locations/tempDir"))}
|
||||||
|
private val tmp: File by lazy {File(tempDir, "technic")}
|
||||||
|
private val download: File by lazy {File(tempDir, "download")}
|
||||||
|
val srcDir by lazy {File(CONFIG.config.pathOrException<String>("Locations/src"))}
|
||||||
|
|
||||||
|
override fun execute(args: Namespace): CommandReturn {
|
||||||
|
//Setup dirs
|
||||||
|
arrayOf(tmp, download)
|
||||||
|
.forEach {
|
||||||
|
it.mkdirs()
|
||||||
|
FileUtils.cleanDirectory(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
val fileList = mutableListOf<FileOrLink>()
|
||||||
|
val toDownload = mutableMapOf<URL, Pair<String, File>>()
|
||||||
|
MPJH.asWrapper!!.defaultVersion.getRelations {"client" in it.options}.forEach {
|
||||||
|
if(it.hasFile())
|
||||||
|
fileList.add(it.file.get())
|
||||||
|
}
|
||||||
|
|
||||||
|
fileList.forEach {
|
||||||
|
when {
|
||||||
|
it.isFile -> {
|
||||||
|
if(!it.isASDirSet)
|
||||||
|
it.setASDir(srcDir)
|
||||||
|
|
||||||
|
if(it.file.exists())
|
||||||
|
installFile(it.installer, it.file, tmp).printf()
|
||||||
|
}
|
||||||
|
it.isURL -> toDownload[it.url] = it.installer to download
|
||||||
|
else -> return fail("${it.link} is neither a file nor an URL")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadFiles(
|
||||||
|
toDownload.mapValues {it.value.second},
|
||||||
|
{
|
||||||
|
if(it.exception == null) {
|
||||||
|
fPrintln("downloaded file ${it.file}", TERMC.brightBlue)
|
||||||
|
installFile(toDownload[it.url]!!.first, it.file, tmp).printf()
|
||||||
|
} else {
|
||||||
|
fPrintln("ERROR DOWNLOADING ${it.url}")
|
||||||
|
it.exception.printStackTrace()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resolveFileName = true
|
||||||
|
)
|
||||||
|
|
||||||
|
fPrintln("Making Zip", TERMC.brightGreen)
|
||||||
|
ZipOutputStream(FileOutputStream("build/${MPJH.asWrapper!!.json.id}-${MPJH.asWrapper!!.defaultVersion.versionName}-technic.zip"))
|
||||||
|
.use {
|
||||||
|
tmp.toZip(it)
|
||||||
|
it.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
return CommandReturn.success("Built export")
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,10 +8,10 @@ import ley.anvil.modpacktools.command.CommandReturn.Companion.fail
|
||||||
import ley.anvil.modpacktools.command.CommandReturn.Companion.success
|
import ley.anvil.modpacktools.command.CommandReturn.Companion.success
|
||||||
import ley.anvil.modpacktools.command.ICommand
|
import ley.anvil.modpacktools.command.ICommand
|
||||||
import ley.anvil.modpacktools.command.LoadCommand
|
import ley.anvil.modpacktools.command.LoadCommand
|
||||||
|
import ley.anvil.modpacktools.util.addonscript.installFile
|
||||||
import ley.anvil.modpacktools.util.downloadFiles
|
import ley.anvil.modpacktools.util.downloadFiles
|
||||||
import ley.anvil.modpacktools.util.fPrintln
|
import ley.anvil.modpacktools.util.fPrintln
|
||||||
import ley.anvil.modpacktools.util.manifest.convertAStoManifest
|
import ley.anvil.modpacktools.util.manifest.convertAStoManifest
|
||||||
import ley.anvil.modpacktools.util.mergeTo
|
|
||||||
import ley.anvil.modpacktools.util.toZip
|
import ley.anvil.modpacktools.util.toZip
|
||||||
import net.sourceforge.argparse4j.ArgumentParsers
|
import net.sourceforge.argparse4j.ArgumentParsers
|
||||||
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
||||||
|
@ -49,6 +49,7 @@ object BuildTwitch : ICommand {
|
||||||
val dir = File("./build")
|
val dir = File("./build")
|
||||||
val toDownload = mutableMapOf<URL, Pair<File, String>>()
|
val toDownload = mutableMapOf<URL, Pair<File, String>>()
|
||||||
val srcDir by lazy {File(CONFIG.config.pathOrException<String>("Locations/src"))}
|
val srcDir by lazy {File(CONFIG.config.pathOrException<String>("Locations/src"))}
|
||||||
|
val overrides by lazy {File(tmp, "overrides")}
|
||||||
dir.mkdirs()
|
dir.mkdirs()
|
||||||
tmp.mkdirs()
|
tmp.mkdirs()
|
||||||
downloadDir.mkdirs()
|
downloadDir.mkdirs()
|
||||||
|
@ -65,7 +66,7 @@ object BuildTwitch : ICommand {
|
||||||
uf.key.setASDir(srcDir)
|
uf.key.setASDir(srcDir)
|
||||||
val file = uf.key.file
|
val file = uf.key.file
|
||||||
if(file.exists()) {
|
if(file.exists()) {
|
||||||
installFile(uf.value, file).apply {println(this)}
|
installFile(uf.value, file, overrides).printf()
|
||||||
}
|
}
|
||||||
} else if(uf.key.isURL) {
|
} else if(uf.key.isURL) {
|
||||||
val filePath = URL(uf.key.link)
|
val filePath = URL(uf.key.link)
|
||||||
|
@ -79,7 +80,7 @@ object BuildTwitch : ICommand {
|
||||||
toDownload.mapValues {it.value.first},
|
toDownload.mapValues {it.value.first},
|
||||||
{
|
{
|
||||||
fPrintln("downloaded file ${it.file}", TERMC.brightBlue)
|
fPrintln("downloaded file ${it.file}", TERMC.brightBlue)
|
||||||
fPrintln(installFile(toDownload[it.url]!!.second, it.file), TERMC.green)
|
installFile(toDownload[it.url]!!.second, it.file, overrides).printf()
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
@ -91,42 +92,4 @@ object BuildTwitch : ICommand {
|
||||||
zip.close()
|
zip.close()
|
||||||
return success("Successfully built twitch zip")
|
return success("Successfully built twitch zip")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun installFile(installer: String, file: File): String {
|
|
||||||
when {
|
|
||||||
installer == "internal.override" -> {
|
|
||||||
when {
|
|
||||||
file.extension == "zip" -> {
|
|
||||||
TODO("unzip to ./.mpt/twitch/overrides")
|
|
||||||
}
|
|
||||||
|
|
||||||
file.isDirectory -> {
|
|
||||||
FileUtils.copyDirectory(file, File(tmp, "overrides"))
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
return "Only zip files can be used with 'internal.override'"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
installer.startsWith("internal.dir") -> {
|
|
||||||
val parts = installer.split(":")
|
|
||||||
if(parts.size >= 2) {
|
|
||||||
FileUtils.copyFile(file, File(File(tmp, "overrides"), parts[1]) mergeTo file)
|
|
||||||
} else {
|
|
||||||
return "No directory was given for installer 'internal.dir'"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
installer.startsWith("internal.zip") -> {
|
|
||||||
TODO()
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
return "The installer '$installer' is not supported for Twitch export"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "installed $file"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import ley.anvil.modpacktools.command.ICommand
|
||||||
import ley.anvil.modpacktools.command.LoadCommand
|
import ley.anvil.modpacktools.command.LoadCommand
|
||||||
import ley.anvil.modpacktools.util.DownloadFileTask
|
import ley.anvil.modpacktools.util.DownloadFileTask
|
||||||
import ley.anvil.modpacktools.util.downloadFiles
|
import ley.anvil.modpacktools.util.downloadFiles
|
||||||
|
import ley.anvil.modpacktools.util.fPrintln
|
||||||
import net.sourceforge.argparse4j.ArgumentParsers
|
import net.sourceforge.argparse4j.ArgumentParsers
|
||||||
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
import net.sourceforge.argparse4j.impl.Arguments.storeTrue
|
||||||
import net.sourceforge.argparse4j.impl.type.FileArgumentType
|
import net.sourceforge.argparse4j.impl.type.FileArgumentType
|
||||||
|
@ -44,7 +45,12 @@ object DownloadMods : ICommand {
|
||||||
override fun execute(args: Namespace): CommandReturn {
|
override fun execute(args: Namespace): CommandReturn {
|
||||||
val json = MPJH.asWrapper
|
val json = MPJH.asWrapper
|
||||||
val fileList = mutableListOf<FileOrLink>()
|
val fileList = mutableListOf<FileOrLink>()
|
||||||
for(rel in json!!.defaultVersion!!.getRelations(arrayOf("client"), if(args.getBoolean("all")) null else arrayOf("mod"))!!) //TODO only client? what if someone wants a server?
|
for(
|
||||||
|
rel in json!!.defaultVersion!!.getRelations(
|
||||||
|
arrayOf("client"),
|
||||||
|
if(args.getBoolean("all")) null else arrayOf("mod")
|
||||||
|
)!!
|
||||||
|
) //TODO only client? what if someone wants a server?
|
||||||
if(rel.hasFile())
|
if(rel.hasFile())
|
||||||
fileList.add(rel.file.get())
|
fileList.add(rel.file.get())
|
||||||
|
|
||||||
|
@ -71,11 +77,10 @@ object DownloadMods : ICommand {
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
{r: DownloadFileTask.Return ->
|
{r: DownloadFileTask.Return ->
|
||||||
//synced so error message gets printed under response
|
println("${r.responseCode} ${r.responseMessage} ${r.url} ${r.file}")
|
||||||
synchronized(this) {
|
if(r.exception != null) {
|
||||||
println("${r.responseCode} ${r.responseMessage} ${r.url} ${r.file}")
|
fPrintln("ERROR DOWNLOADING ${r.url}")
|
||||||
if(r.exception != null)
|
r.exception.printStackTrace()
|
||||||
println(r.exception.message)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
!args.getBoolean("force"),
|
!args.getBoolean("force"),
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package ley.anvil.modpacktools.util.addonscript
|
||||||
|
|
||||||
|
import ley.anvil.modpacktools.TERMC
|
||||||
|
import ley.anvil.modpacktools.util.fPrintln
|
||||||
|
import ley.anvil.modpacktools.util.mergeTo
|
||||||
|
import org.apache.commons.io.FileUtils
|
||||||
|
import java.io.File
|
||||||
|
import java.io.PrintStream
|
||||||
|
|
||||||
|
data class InstallFileSuccess(
|
||||||
|
val success: Boolean,
|
||||||
|
val msg: String? = null
|
||||||
|
) {
|
||||||
|
@JvmOverloads
|
||||||
|
fun printf(out: PrintStream = System.out) {
|
||||||
|
if(msg != null)
|
||||||
|
out.fPrintln(msg, if(success) TERMC.green else TERMC.red)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun installFile(installer: String, file: File, outDir: File): InstallFileSuccess {
|
||||||
|
when {
|
||||||
|
installer == "internal.override" -> {
|
||||||
|
when {
|
||||||
|
file.extension == "zip" -> {
|
||||||
|
TODO("unzip to ./.mpt/twitch/overrides")
|
||||||
|
}
|
||||||
|
|
||||||
|
file.isDirectory -> {
|
||||||
|
FileUtils.copyDirectory(file, outDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
InstallFileSuccess(false, "Only zip files can be used with \'internal.override\'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
installer.startsWith("internal.dir") -> {
|
||||||
|
val (_, dir) = installer.split(":")
|
||||||
|
FileUtils.copyFile(file, File(outDir, dir) mergeTo file)
|
||||||
|
}
|
||||||
|
|
||||||
|
installer.startsWith("internal.zip") -> {
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
return InstallFileSuccess(false, "The installer \'$installer\' is not supported")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return InstallFileSuccess(true, "installed $file")
|
||||||
|
}
|
Loading…
Reference in a new issue