This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
plugins { | ||
kotlin("jvm") | ||
application | ||
id("com.github.johnrengelman.shadow") version "5.2.0" | ||
} | ||
|
||
dependencies { | ||
implementation(project(":modsman-core")) | ||
implementation(group = "com.beust", name = "jcommander", version = "1.71") | ||
} | ||
|
||
application { | ||
mainClassName = "modsman.packutil.MainKt" | ||
} | ||
|
||
tasks { | ||
shadowJar { | ||
// defaults to project.name | ||
// archiveBaseName.set("${project.name}-fat") | ||
|
||
// defaults to all, so removing this overrides the normal, non-fat jar | ||
archiveClassifier.set("") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package modsman.packutil | ||
|
||
import com.beust.jcommander.JCommander | ||
import com.beust.jcommander.Parameter | ||
import com.beust.jcommander.ParameterException | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.FlowPreview | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.withContext | ||
import modsman.BuildConfig | ||
import modsman.Modsman | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
import java.util.logging.Logger | ||
import kotlin.system.exitProcess | ||
|
||
object Args { | ||
@Parameter(names = ["--minecraft-root", "-M"], required = true, order = 0) | ||
lateinit var minecraftRoot: String | ||
|
||
@Parameter(names = ["--invoke-in", "-i"], required = true, order = 1) | ||
lateinit var targetDirs: List<String> | ||
|
||
@Parameter(names = ["--force", "-f"], order = 2) | ||
var force: Boolean = false | ||
|
||
@Parameter(names = ["--version", "-v"], help = true, order = 3) | ||
var version: Boolean = false | ||
} | ||
|
||
@FlowPreview | ||
fun main(args: Array<String>) { | ||
val jc = JCommander.newBuilder().addObject(Args).build() | ||
jc.programName = "modsman-packutil" | ||
|
||
try { | ||
jc.parse(*args) | ||
} catch (e: ParameterException) { | ||
JCommander.getConsole().println(e.message) | ||
exitProcess(1) | ||
} | ||
|
||
if (Args.version) { | ||
JCommander.getConsole().println(BuildConfig.VERSION) | ||
exitProcess(0) | ||
} | ||
|
||
System.setProperty( | ||
"java.util.logging.SimpleFormatter.format", | ||
"[%1\$tF %1\$tT] [%4\$s] %5\$s %n" | ||
) | ||
val log = Logger.getGlobal() | ||
|
||
runBlocking { | ||
val mcPath = Paths.get(Args.minecraftRoot) | ||
|
||
for (target in Args.targetDirs) { | ||
val targetPath = mcPath.resolve(target) | ||
val markerPath = targetPath.resolve(".MODSMAN_FIRST_RUN_COMPLETE") | ||
|
||
if (!Args.force && Files.exists(markerPath)) { | ||
log.info("Skipping $targetPath ...") | ||
continue | ||
} | ||
|
||
log.info("Invoking Modsman in $targetPath ...") | ||
Modsman(targetPath, 10).use { modsman -> | ||
val projectIds = modsman.modlist.mods.map { it.projectId } | ||
modsman.reinstallMods(projectIds).collect { result -> | ||
result | ||
.onSuccess { log.info("Downloaded '${it.projectName}' as '${it.fileName}'") } | ||
.onFailure { log.severe("${it::class.java.simpleName}: ${it.message}") } | ||
} | ||
} | ||
|
||
log.info("Creating marker $markerPath ...") | ||
withContext(Dispatchers.IO) { | ||
try { | ||
Files.createFile(markerPath) | ||
} catch (ignored: java.nio.file.FileAlreadyExistsException) { | ||
} | ||
} | ||
} | ||
} | ||
|
||
log.info("Done") | ||
exitProcess(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ rootProject.name = "modsman" | |
|
||
include("modsman-core") | ||
include("modsman-cli") | ||
include("modsman-packutil") |