Skip to content

Commit

Permalink
change multimc launch command
Browse files Browse the repository at this point in the history
fixes for local provider
  • Loading branch information
NikkyAI committed Jan 23, 2021
1 parent 799de1f commit 0b57749
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 55 deletions.
17 changes: 8 additions & 9 deletions core/src/main/kotlin/voodoo/data/lock/LockPack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class LockPack(
val entries: List<LockEntry> = listOf(),
) {
companion object : KLogging() {
const val extension = "lock.pack.json"
const val FILENAME = "lock.pack.json"

// maybe make this configurable ?
const val outputFolder = "lock"
Expand All @@ -43,18 +43,18 @@ data class LockPack(
return baseDir.resolve(outputFolder).resolve(version)
}
fun fileForVersion(version: String, baseDir: File): File {
return baseFolderForVersion(version, baseDir).resolve(extension)
return baseFolderForVersion(version, baseDir).resolve(FILENAME)
}

fun parseAll(baseFolder: File): List<LockPack> {
val outputDir = baseFolder.resolve(outputFolder)
outputDir.mkdirs()
return outputDir
.listFiles { folder ->
folder.resolve(extension).exists()
folder.resolve(FILENAME).exists()
}!!
.map { lockBaseFolder ->
val lockpackFile = lockBaseFolder.resolve(extension)
val lockpackFile = lockBaseFolder.resolve(FILENAME)
parse(lockpackFile, lockBaseFolder)
}
}
Expand All @@ -65,7 +65,7 @@ data class LockPack(
throw IllegalStateException("baseFolder: '$baseFolder' is not absolute")
}
val lockpack: LockPack = json.decodeFromString(LockPack.serializer(), packFile.readText())
lockpack.lockBaseFolder = baseFolder
lockpack.lockBaseFolder = packFile.absoluteFile.parentFile

lockpack.sourceFolder.deleteRecursively()
if(lockpack.sourceZip.exists()) {
Expand All @@ -84,10 +84,9 @@ data class LockPack(
lockpack.localFolder
)
}
// lockpack.entries.forEach {
// it.srcFolder = lockpack.sourceFolder
// }
//TODO: unzip src and local and point sourceFolder and localFolder to extracted locations
lockpack.entries.forEach {
it.parent = lockpack
}
return lockpack
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/kotlin/voodoo/provider/LocalProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ object LocalProvider : ProviderBase("Local Provider") {
): Pair<String?, File> = stopwatch {
entry as LockEntry.Local
val fileSrc = entry.parent.localFolder.resolve(entry.fileSrc)
val targetFile = targetFolder.resolve(fileSrc.name)
logger.info(fileSrc.absolutePath)
val targetFile = targetFolder.resolve(entry.fileName ?: fileSrc.name)
logger.info { "copying ${fileSrc.absolutePath} -> ${targetFile.absolutePath}" }
fileSrc.copyTo(targetFile, overwrite = true)
return Pair(null, targetFile)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ before deploying the pack, lets make sure it runs first
before this make sure multimc is in your `PATH`

```bash
voodoo launch multimc --id magicpack
voodoo launch multimc magicpack/v0.0.1.voodoo.json
```

## Packaging and Upload
Expand Down
2 changes: 1 addition & 1 deletion pack/tester/src/main/kotlin/voodoo/tester/MultiMCTester.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object MultiMCTester : AbstractTester() {
modsDir.deleteRecursively()

val minecraftSrcDir = modpack.sourceFolder
Downloader.logger.info { "copying files into minecraft dir ('$minecraftSrcDir' => '$minecraftDir')" }
Downloader.logger.info { "copying files into minecraft dir ('$minecraftSrcDir' -> '$minecraftDir')" }
if (minecraftSrcDir.exists()) {
minecraftSrcDir.copyRecursively(minecraftDir, overwrite = true)
}
Expand Down
8 changes: 8 additions & 0 deletions samples/fabricpack/164Version.voodoo.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
"type": "curse",
"projectName": "Fabric16/hwyla",
"validMcVersions": ["1.16.3"]
},
{
"type": "local",
"folder": "",
"fileName": "_icon.png",
"localProperties": {
"fileSrc": "256.png"
}
}
]
}
2 changes: 1 addition & 1 deletion samples/fabricpack/lock/0.0.2/lock.pack.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"recommendation": "starred"
},
"projectID": 317514,
"fileID": 3160335
"fileID": 3174699
},
{
"type": "curse",
Expand Down
Binary file added samples/fabricpack/lock/0.0.3/local.zip
Binary file not shown.
11 changes: 9 additions & 2 deletions samples/fabricpack/lock/0.0.3/lock.pack.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"uploadUrl": "https://nikky.moe/.mc/voodoo/fabricPack"
},
"entries": [
{
"type": "local",
"id": "256.png",
"path": "",
"fileName": "_icon.png",
"fileSrc": "256.png"
},
{
"type": "curse",
"id": "appleskin",
Expand Down Expand Up @@ -85,7 +92,7 @@
"recommendation": "starred"
},
"projectID": 317514,
"fileID": 3160333
"fileID": 3174695
},
{
"type": "curse",
Expand All @@ -97,7 +104,7 @@
"fabric-api": "REQUIRED"
},
"projectID": 310111,
"fileID": 3142186
"fileID": 3175580
},
{
"type": "curse",
Expand Down
Binary file added samples/local/256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class InstallServerCommand: CliktCommand() {
help = "lockpack or folder containing lockpack"
).file(mustExist = true, canBeFile = true, canBeDir = true)
.defaultLazy {
parentFolder.resolve(LockPack.extension).takeIf { it.exists() }
?: File(LockPack.extension)
parentFolder.resolve(LockPack.FILENAME).takeIf { it.exists() }
?: File(LockPack.FILENAME)
}
.validate { packFile ->
require(packFile.exists()) { "$packFile does not exist" }
require(packFile.isFile && packFile.name.endsWith(LockPack.extension)
|| packFile.isDirectory && packFile.resolve(LockPack.extension).exists()) {
"$packFile must either be a ${LockPack.extension} file or a directoy containing ${LockPack.extension}"
require(packFile.isFile && packFile.name.endsWith(LockPack.FILENAME)
|| packFile.isDirectory && packFile.resolve(LockPack.FILENAME).exists()) {
"$packFile must either be a ${LockPack.FILENAME} file or a directoy containing ${LockPack.FILENAME}"
}
}

Expand Down Expand Up @@ -71,8 +71,8 @@ class InstallServerCommand: CliktCommand() {
val stopwatch = Stopwatch(commandName)
stopwatch {
val packFile = when {
packFile.exists() && packFile.isFile && packFile.name.endsWith(LockPack.extension) -> packFile
packFile.exists() && packFile.isDirectory && packFile.resolve(LockPack.extension).exists() -> packFile.resolve(LockPack.extension)
packFile.exists() && packFile.isFile && packFile.name.endsWith(LockPack.FILENAME) -> packFile
packFile.exists() && packFile.isDirectory && packFile.resolve(LockPack.FILENAME).exists() -> packFile.resolve(LockPack.FILENAME)
else ->error("cannot find $packFile")
}

Expand Down
2 changes: 1 addition & 1 deletion util/src/main/kotlin/voodoo/util/UnzipUtility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object UnzipUtility {
*/
@Throws(IOException::class)
fun unzip(zipFile: File, destDir: File) {
logger.info("unzipping: $zipFile into $destDir")
logger.info("unzipping: $zipFile -> $destDir")
require(zipFile.exists()) { "$zipFile does not exist" }
require(zipFile.isFile) { "$zipFile not not a file" }
val destDir = destDir.absoluteFile
Expand Down
2 changes: 0 additions & 2 deletions voodoo/src/main/kotlin/voodoo/cli/CompileCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class CompileCommand() : CliktCommand(

val rootDir = cliContext.rootDir

// require(id.isNotBlank()) { "id must not be blank" }

stopwatch {

val config = Configuration.parse(rootDir = rootDir)
Expand Down
47 changes: 22 additions & 25 deletions voodoo/src/main/kotlin/voodoo/cli/launch/LaunchMultiMCCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.eyeem.watchadoin.saveAsHtml
import com.eyeem.watchadoin.saveAsSvg
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.requireObject
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.arguments.validate
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.file
import kotlinx.coroutines.runBlocking
Expand All @@ -13,8 +16,11 @@ import mu.KotlinLogging
import mu.withLoggingContext
import voodoo.cli.CLIContext
import voodoo.data.lock.LockPack
import voodoo.pack.MetaPack
import voodoo.pack.VersionPack
import voodoo.tester.MultiMCTester
import voodoo.util.VersionComparator
import voodoo.util.json
import java.io.File

class LaunchMultiMCCommand(): CliktCommand(
Expand All @@ -24,44 +30,35 @@ class LaunchMultiMCCommand(): CliktCommand(
private val logger = KotlinLogging.logger {}
val cliContext by requireObject<CLIContext>()

val id by option(
"--id",
help = "pack id"
).required()

val versionOption by option(
"--version",
help = "launch a specified version"
).validate { version ->
require(version.matches("^\\d+(?:\\.\\d+)+$".toRegex())) {
"version must match pattern '^\\d+(\\.\\d+)+\$' eg: 0.1 or 4.11.6 or 1.2.3.4 "
val packFile by argument(
"PACK_FILE",
"path to .voodoo.json file"
).file(mustExist = true, canBeFile = true, canBeDir = false)
.validate { file ->
require(file.name.endsWith("." + VersionPack.extension)) {
"file $file does not end with ${VersionPack.extension}"
}
}
}

val clean by option("--clean").flag(default = false)

val uploadDirOption by option("--uploadDir")
.file(canBeDir = true, mustBeWritable = true)

override fun run(): Unit = withLoggingContext("command" to commandName) {
runBlocking(MDCContext()) {
val stopwatch = Stopwatch(commandName)

//TODO: look up rootDir based on lockpack input file
val rootDir = cliContext.rootDir
val baseDir = rootDir.resolve(id)

val baseDir = packFile.absoluteFile.parentFile
val id = baseDir.name
stopwatch {
val lockpacks = LockPack.parseAll(baseFolder = baseDir)
.sortedWith(compareBy(VersionComparator, LockPack::version))
val metaPackFile = baseDir.resolve(MetaPack.FILENAME)
val versionPack = VersionPack.parse(packFile = packFile)

val versionOption = versionOption
val lockpack = if(versionOption != null) {
lockpacks.firstOrNull { VersionComparator.compare(it.version, versionOption) == 0 }
?: error("$versionOption is not available, existing versions are: ${lockpacks.map { it.version }}")
} else {
lockpacks.last()
}
val lockpack = LockPack.parse(
LockPack.fileForVersion(versionPack.version, baseDir),
baseDir.absoluteFile
)

MultiMCTester.execute("launch-multimc".watch, modpack = lockpack, clean = clean)
}
Expand Down
8 changes: 4 additions & 4 deletions voodoo/src/main/kotlin/voodoo/pack/FileEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ sealed class FileEntry(
}
}

protected fun toCommonComponent(): CommonComponent {
protected fun toCommonComponent(defaultId: String? = null): CommonComponent {
return CommonComponent(
id = id ?: error("$id must be set on $this"),
id = id ?: defaultId ?: error("id must be set on $this"),
name = name,
folder = folder,
description = description,
Expand Down Expand Up @@ -181,7 +181,7 @@ sealed class FileEntry(
}
}
override fun toEntry(): FlatEntry = FlatEntry.Jenkins(
common = toCommonComponent(),
common = toCommonComponent(jenkins.job),
jenkins = jenkins.copy()
)
}
Expand All @@ -208,7 +208,7 @@ sealed class FileEntry(
}
}
override fun toEntry(): FlatEntry = FlatEntry.Local(
common = toCommonComponent(),
common = toCommonComponent(local.fileSrc),
local = local.copy()
)
}
Expand Down

0 comments on commit 0b57749

Please sign in to comment.