Skip to content

Commit

Permalink
add version picker to multimc installer
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Jan 15, 2021
1 parent 2ef4add commit 8614763
Show file tree
Hide file tree
Showing 448 changed files with 89 additions and 8,948 deletions.
2 changes: 1 addition & 1 deletion .run/CLI --help.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI --version.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI autocompletes bash.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<envs>
<env name="_VOODOO_COMPLETE" value="bash" />
</envs>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI autocompletes fish.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<envs>
<env name="_VOODOO_COMPLETE" value="fish" />
</envs>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI autocompletes zsh.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<envs>
<env name="_VOODOO_COMPLETE" value="zsh" />
</envs>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI build --help.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI build --id forgePack.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI build.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI create pack.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI generateSchema.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI launch multimc --help.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI launch multimc forgepack.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI pack --help.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI pack fabricPack all.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/CLI pack fabricPack voodoo.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/samples" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
2 changes: 1 addition & 1 deletion .run/InstallServer .run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="MAIN_CLASS_NAME" value="voodoo.server.Main" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/voodoo/example/build/_upload/server/fabricPack_v0.0.2" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/sample/build/_upload/server/fabricPack_v0.0.2" />
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ object PackageBuilder : KLogging() {
val manifestDest: File = outputPath.resolve("${modpackId}_${modpackVersion}.json")
val versionlistingFile: File = outputPath.resolve("$modpackId.json")


val uniqueVersion = "$modpackVersion." + DateTimeFormatter
.ofPattern("yyyyMMddHHmm")
.withZone(ZoneOffset.UTC)
Expand Down Expand Up @@ -132,13 +131,16 @@ object PackageBuilder : KLogging() {
val versionsListing = if (versionlistingFile.exists()) {
voodoo.util.json.decodeFromString(VersionsList.serializer(), versionlistingFile.readText())
} else {
VersionsList(mapOf())
VersionsList(
installerLocation = installerLocation,
versions = mapOf()
)
}

val versionEntry = VersionEntry(
version = modpackVersion,
title = "$modpackTitle $modpackVersion",
location = manifestDest.toRelativeUnixPath(versionlistingFile)
location = manifestDest.toRelativeUnixPath(versionlistingFile.absoluteFile.parentFile)
)

//TODO: add updateChannels to version listing
Expand Down Expand Up @@ -215,8 +217,7 @@ object PackageBuilder : KLogging() {

val sha2 = MessageDigest.getInstance("SHA-256")
val hash = sha2.digest(file.readBytes()).toHexString()
val to =
relPath.toString().replace('\\', '/') //FilenameUtils.separatorsToUnix(FilenameUtils.normalize(relPath))
val to = relPath.toString().replace('\\', '/')
val urlFile = file.parentFile.resolve(file.name + URL_FILE_SUFFIX)
val (location, copy) = if (urlFile.exists()) {
// TODO: validate urlFile by downloading ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import kotlinx.serialization.Serializable

@Serializable
data class VersionsList(
val installerLocation: String,
val versions: Map<String, VersionEntry>
)
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 9 additions & 7 deletions multimc/installer/src/main/kotlin/voodoo/multimc/Installer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package voodoo.multimc


import Modloader
import io.ktor.client.request.*
import io.ktor.client.statement.*
Expand Down Expand Up @@ -109,10 +108,10 @@ object Installer : KLogging() {
minecraftDir: File,
phase: Phase
) {
logger.info("installing into $instanceId")
logger.info { "installing into $instanceId" }
val urlFile = instanceDir.resolve("voodoo.url.txt")
val packUrl = urlFile.readText().trim()
logger.info("pack url: $packUrl")
logger.info { "pack url: $packUrl" }

val versionListing = withContext(Dispatchers.IO) {
try {
Expand All @@ -132,7 +131,7 @@ object Installer : KLogging() {
json.decodeFromString(VersionsList.serializer(), jsonString)
}
} catch (e: IOException) {
logger.error("packUrl: $packUrl")
logger.error { "packUrl: $packUrl" }
logger.error(e) { "unable to get pack from $packUrl" }
error("failed to get $packUrl")
}
Expand All @@ -145,10 +144,13 @@ object Installer : KLogging() {
versionChoiceFile.readLines().first()
} else null

if(selectedVersionKey == null || selectedVersionKey !in versionListing.versions) {
if(selectedVersionKey == null && versionListing.versions.keys.size == 1) {
selectedVersionKey = versionListing.versions.keys.first()
} else if(selectedVersionKey == null || selectedVersionKey !in versionListing.versions) {
selectedVersionKey = MMCUtil.selectVersion(
versions = versionListing.versions
versions = versionListing.versions.toSortedMap()
)
versionChoiceFile.writeText(selectedVersionKey)
}
val selectedVersion = versionListing.versions.getValue(selectedVersionKey)

Expand Down Expand Up @@ -202,7 +204,7 @@ object Installer : KLogging() {
"--mc",
minecraftDir.path,
"--phase",
"reboot"
phase.name
)

logger.info { "Executing ${args.joinToString()}" }
Expand Down
4 changes: 3 additions & 1 deletion multimc/src/main/kotlin/voodoo/mmc/MMCUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.serialization.json.Json
import moe.nikky.voodoo.format.VersionEntry
import moe.nikky.voodoo.format.modpack.Recommendation
import mu.KLogging
import mu.KotlinLogging
import voodoo.mmc.data.MultiMCPack
import voodoo.mmc.data.PackComponent
import voodoo.util.Directories
Expand All @@ -22,7 +23,8 @@ import javax.swing.*
import kotlin.system.exitProcess


object MMCUtil : KLogging() {
object MMCUtil {
private val logger = KotlinLogging.logger {}
private val directories = Directories.get(moduleName = "multimc")
private val cacheHome = directories.cacheHome
private val configHome = directories.configHome
Expand Down
2 changes: 1 addition & 1 deletion pack/src/main/kotlin/voodoo/pack/AbstractPack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.io.File
* @author Nikky
*/

abstract class AbstractPack(open val id: String) : KLogging() {
abstract class AbstractPack(open val id: String) {
abstract val label: String
abstract fun File.getOutputFolder(id: String, version: String): File

Expand Down
2 changes: 2 additions & 0 deletions pack/src/main/kotlin/voodoo/pack/CursePack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.html.li
import kotlinx.html.stream.createHTML
import kotlinx.html.ul
import Modloader
import mu.KotlinLogging
import voodoo.data.Side
import voodoo.data.curse.CurseFile
import voodoo.data.curse.CurseManifest
Expand All @@ -29,6 +30,7 @@ import java.io.File
*/

object CursePack : AbstractPack("curse") {
private val logger = KotlinLogging.logger {}
override val label = "Curse Pack"

override fun File.getOutputFolder(id: String, version: String): File = resolve("curse")
Expand Down
10 changes: 6 additions & 4 deletions pack/src/main/kotlin/voodoo/pack/MMCFatPack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.launch
import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import voodoo.data.DependencyType
import voodoo.data.Side
import voodoo.data.lock.LockPack
Expand All @@ -20,6 +21,7 @@ import voodoo.util.withPool
import java.io.File

object MMCFatPack : AbstractPack("mmc-fat") {
private val logger = KotlinLogging.logger {}
override val label = "MultiMC Pack (frozen pack)"

override fun File.getOutputFolder(id: String, version: String): File = resolve("multimc-fat")
Expand Down Expand Up @@ -117,7 +119,7 @@ object MMCFatPack : AbstractPack("mmc-fat") {
val matchedOptioalsList = if(modpack.isEntryOptional(entry.id)) {
val selectedSelf = optionals[entry.id] ?: true
if (!selectedSelf) {
MMCUtil.logger.info("${entry.displayName} is disabled, skipping download")
logger.info { "${entry.displayName} is disabled, skipping download" }
return@launch
}
modpack.optionalEntries.filter {
Expand All @@ -141,15 +143,15 @@ object MMCFatPack : AbstractPack("mmc-fat") {
if (matchedOptioalsList.isNotEmpty()) {
val selected = matchedOptioalsList.any { optionals[it.id] ?: false }
if (!selected) {
MMCUtil.logger.info("${matchedOptioalsList.map { it.displayName }} is disabled, disabling ${entry.id}")
logger.info {"${matchedOptioalsList.map { it.displayName }} is disabled, disabling ${entry.id}" }
file.renameTo(file.parentFile.resolve(file.name + ".disabled"))
}
}
}
}

delay(10)
CursePack.logger.info("waiting for jobs to finish")
logger.info { "waiting for jobs to finish" }
}
}

Expand All @@ -171,6 +173,6 @@ object MMCFatPack : AbstractPack("mmc-fat") {

instanceZip.delete()
packToZip(zipRootDir, instanceZip)
logger.info("created mmc pack $instanceZip")
logger.info { "created mmc pack $instanceZip" }
}
}
19 changes: 13 additions & 6 deletions pack/src/main/kotlin/voodoo/pack/MMCSelfupdatingPackVoodoo.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package voodoo.pack

import com.eyeem.watchadoin.Stopwatch
import mu.KotlinLogging
import voodoo.data.lock.LockPack
import voodoo.mmc.MMCUtil
import voodoo.util.Directories
Expand All @@ -13,6 +14,7 @@ import java.net.URI
import kotlin.system.exitProcess

object MMCSelfupdatingPackVoodoo : AbstractPack("mmc-voodoo") {
private val logger = KotlinLogging.logger {}
override val label = "MultiMC Pack"

override fun File.getOutputFolder(id: String, version: String): File = resolve("multimc-voodoo")
Expand Down Expand Up @@ -58,15 +60,14 @@ object MMCSelfupdatingPackVoodoo : AbstractPack("mmc-voodoo") {
postExitCommand = postExitCommand
)

logger.info("created pack in $minecraftDir")
logger.info("tmp dir: $instanceDir")

logger.info { "created pack in $minecraftDir" }
logger.info { "tmp dir: $instanceDir" }
val selfupdateUrl = modpack.packOptions.uploadUrl?.let { uploadUrl ->
val relativeSelfupdateUrl = (modpack.packOptions.multimcOptions.relativeSelfupdateUrl ?: "${modpack.id}.json")
URI(uploadUrl).resolve(relativeSelfupdateUrl).toASCIIString()
}
if (selfupdateUrl == null) {
logger.error("selfupdateUrl in multimc options is not set")
logger.error { "selfupdateUrl in multimc options is not set" }
exitProcess(3)
}
val urlFile = instanceDir.resolve("voodoo.url.txt")
Expand All @@ -80,10 +81,16 @@ object MMCSelfupdatingPackVoodoo : AbstractPack("mmc-voodoo") {
)

output.mkdirs()
val instanceZip = output.resolve("${modpack.id}-${modpack.version}.zip")
val instanceZipVersioned = output.resolve("${modpack.id}-${modpack.version}.zip")
val instanceZip = output.resolve("${modpack.id}.zip")

instanceZip.delete()
packToZip(zipRootDir, instanceZip)
logger.info("created mmc pack $instanceZip")

instanceDir.resolve("voodoo.version.txt").writeText(modpack.version)

instanceZipVersioned.delete()
packToZip(zipRootDir, instanceZipVersioned)
logger.info { "created mmc pack $instanceZip" }
}
}
Loading

0 comments on commit 8614763

Please sign in to comment.