mirror of
https://github.com/Anvilcraft/modpacktools
synced 2024-06-11 15:09:24 +02:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
312cb39459
|
@ -21,7 +21,7 @@ import java.nio.charset.StandardCharsets
|
|||
@LoadCommand
|
||||
object CreateModlist : ICommand {
|
||||
override val name: String = "createmodlist"
|
||||
override val helpMessage: String = "This creates a modlist either as html or csv file. Syntax: <html/csv> outFile"
|
||||
override val helpMessage: String = "This creates a modlist either as html or csv file. if the \'all\' option is supplied, not only mods will be included Syntax: <html/csv> <outFile> [all]"
|
||||
|
||||
override fun execute(args: Array<out String>): CommandReturn {
|
||||
if(!args.checkArgs())
|
||||
|
@ -32,20 +32,21 @@ object CreateModlist : ICommand {
|
|||
if(outFile.exists())
|
||||
return fail("File already exists!")
|
||||
|
||||
val all = args.getOrNull(3) == "all"
|
||||
return if(args[1] == "html")
|
||||
doHtml(outFile)
|
||||
doHtml(outFile, all)
|
||||
else
|
||||
doCsv(outFile)
|
||||
doCsv(outFile, all)
|
||||
}
|
||||
|
||||
private fun doCsv(outFile: File): CommandReturn {
|
||||
private fun doCsv(outFile: File, all: Boolean): CommandReturn {
|
||||
println("Making CSV file $outFile")
|
||||
val printer = CSVPrinter(FileWriter(outFile), CSVFormat.EXCEL.withDelimiter(';'))
|
||||
|
||||
printer.printRecord("Name", "Contributors", "Link")
|
||||
printer.println()
|
||||
|
||||
for(mod in getMods()) {
|
||||
for(mod in getMods(all)) {
|
||||
printer.printRecord(
|
||||
mod.name,
|
||||
mod.contributors.keys.joinToString(),
|
||||
|
@ -57,7 +58,7 @@ object CreateModlist : ICommand {
|
|||
return success("Wrote CSV file")
|
||||
}
|
||||
|
||||
private fun doHtml(outFile: File): CommandReturn {
|
||||
private fun doHtml(outFile: File, all: Boolean): CommandReturn {
|
||||
println("Making HTML file $outFile")
|
||||
val writer = FileWriter(outFile)
|
||||
val html = html(
|
||||
|
@ -75,18 +76,22 @@ object CreateModlist : ICommand {
|
|||
td(b("Contributors")),
|
||||
td(b("Description"))
|
||||
),
|
||||
each(getMods()) {
|
||||
each(getMods(all)) {
|
||||
tr(
|
||||
td(if(it.icon != null) a(
|
||||
img().withSrc(it.icon)
|
||||
.withClass("img")
|
||||
).withHref(it.website) else null
|
||||
),
|
||||
td(a(it.name)
|
||||
.withHref(it.website)
|
||||
//Open in new tab
|
||||
.withRel("noopener noreferrer")
|
||||
.withTarget("_blank")),
|
||||
td(run {
|
||||
val a = a(it.name)
|
||||
//Open in new tab
|
||||
.withRel("noopener noreferrer")
|
||||
.withTarget("_blank")
|
||||
if(it.website != null)
|
||||
a.withHref(it.website)
|
||||
a
|
||||
}),
|
||||
td(ul(
|
||||
each(it.contributors) {contr ->
|
||||
li(contr.key)
|
||||
|
@ -106,13 +111,13 @@ object CreateModlist : ICommand {
|
|||
return success("Wrote HTML file")
|
||||
}
|
||||
|
||||
private fun getMods(): List<MetaData> {
|
||||
private fun getMods(all: Boolean): List<MetaData> {
|
||||
println("Getting mods...")
|
||||
val asJson = MPJH.asWrapper
|
||||
val mods = mutableListOf<MetaData>()
|
||||
val toGet = mutableListOf<ArtifactDestination>()
|
||||
|
||||
for(rel in asJson!!.defaultVersion.getRelations(arrayOf("client"), arrayOf("mod", "modloader"))) {
|
||||
for(rel in asJson!!.defaultVersion.getRelations(arrayOf("included"), /*null means all*/ if(all) null else arrayOf("mod"))) {
|
||||
if(rel.hasLocalMeta())
|
||||
mods.add(rel.localMeta)
|
||||
else if(rel.hasFile() && rel.file.isArtifact)
|
||||
|
@ -122,6 +127,11 @@ object CreateModlist : ICommand {
|
|||
return mods.sortedBy {m -> m.name?.toLowerCase()}
|
||||
}
|
||||
|
||||
private fun Array<out String>.checkArgs(): Boolean = this.size >= 3 && this[1] in arrayOf("html", "csv")
|
||||
|
||||
private fun Array<out String>.checkArgs(): Boolean =
|
||||
//must be right length
|
||||
this.size >= 3 &&
|
||||
//second option must be html or csv
|
||||
this[1] in arrayOf("html", "csv") &&
|
||||
//3rd option must either be "all" or nothing
|
||||
this.getOrElse(3) {"all"} == "all"
|
||||
}
|
|
@ -87,7 +87,7 @@ open class FileDownloader(
|
|||
val responseCode: Int?,
|
||||
val responseMessage: String?,
|
||||
val exception: Exception?
|
||||
) {}
|
||||
)
|
||||
}
|
||||
|
||||
enum class ExistingFileBehaviour {
|
||||
|
|
Loading…
Reference in a new issue