Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
how do i know if the argument works?
Browse files Browse the repository at this point in the history
  • Loading branch information
NanamiNakano committed Jan 14, 2024
1 parent 05fea8c commit 1eaf79b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 13 deletions.
7 changes: 7 additions & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ tasks.jar {
)
}
}

tasks.register("writeVersionProperties") {
doLast {
val propertiesFile = File(project.projectDir, "version.properties")
propertiesFile.writeText("version=${project.version}")
}
}
28 changes: 25 additions & 3 deletions lib/src/main/kotlin/mikataneko/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.serialization.kotlinx.json.*
import mikataneko.models.*
import mikataneko.models.GameInstance
import mikataneko.models.JvmArgumentClass
import mikataneko.models.StringArgument
import mikataneko.models.minecraft.FoundProfile
import mikataneko.models.minecraft.GameInstanceConfig
import mikataneko.utils.*
import java.nio.file.Path
import java.nio.file.Paths
import java.util.*
import kotlin.io.path.exists
import kotlin.io.path.reader


val globalClient by lazy {
Expand All @@ -32,6 +38,18 @@ val globalClient by lazy {
}
}

const val launcherCoreName = "MikataNeko"
val launcherCoreVersion: String by lazy {
val properties = Properties()
val propertiesFile: Path = Path.of("version.properties")
if (propertiesFile.exists()) {
properties.load(propertiesFile.reader())
properties.getProperty("version")
} else {
""
}
}

class Core(
val gameDirectory: GameDirectory = loadGameDirectory(Paths.get("").toAbsolutePath()),
client: HttpClient = globalClient,
Expand Down Expand Up @@ -116,10 +134,14 @@ class Core(
is StringArgument -> argument.value
}
}
return "$jvmArgument $loggingArgument ${manifest.mainClass} ${gameArguments.joinToString(" ")}"

val modifiedJvmArgument = jvmArgument.replace("\${launcher_name}", launcherCoreName)
.replace("\${launcher_version}", launcherCoreVersion)
.replace("\${natives_directory}", instance.rootDirectory.natives.toString())
.replace("\${classpath}", manifestHelper.listJars(instance).joinToString(getClassSeperator()))
return "$modifiedJvmArgument $loggingArgument ${manifest.mainClass} ${gameArguments.joinToString(" ")}"
}

return "$loggingArgument ${manifest.mainClass} ${gameArguments.joinToString(" ")}"
}

}
2 changes: 1 addition & 1 deletion lib/src/main/kotlin/mikataneko/models/GameInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GameInstance(
val version: Version,
directory: GameDirectory,
val id: String = version.id,
isolation: Boolean = true,
val isolation: Boolean = true,
) {
var rootDirectory: GameDirectory

Expand Down
1 change: 1 addition & 0 deletions lib/src/main/kotlin/mikataneko/utils/DirectoryHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class GameDirectory(
val assetIndexes: Path = assets.resolve("indexes"),
val objects: Path = assets.resolve("objects"),
val legacy: Path = assets.resolve("virtual/legacy"),
val natives: Path = path.resolve("natives"),
)

fun loadGameDirectory(path: Path): GameDirectory {
Expand Down
12 changes: 12 additions & 0 deletions lib/src/main/kotlin/mikataneko/utils/ManifestHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ class ManifestHelper(
downloader.downloadSingleFile(file, path)
}
}

suspend fun listJars(instance: GameInstance): List<Path> {
val jarList: MutableList<Path> = mutableListOf()
jarList.add(instance.rootDirectory.versions.resolve("${instance.id}.jar"))
val manifest = getVersionManifest(instance)
val libs = manifest.libraries.mapNotNull(Library::resolve).filterIsInstance<UniversalLibrary>()
jarList.addAll(libs.map {
instance.rootDirectory.libraries.resolve(it.path)
})
return jarList
}

}

inline fun <reified T : Exception> retryOnException(retries: Int, block: () -> Unit) {
Expand Down
22 changes: 15 additions & 7 deletions lib/src/main/kotlin/mikataneko/utils/PlatformHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ fun getArch(): Arch {
}
}

enum class Platform(val detail:String,val key: String) {
WINDOWS("windows","windows"),
OSX("osx","macos"),
LINUX("linux","linux"),
UNIVERSAL("",""),
fun getClassSeperator(): String {
return if (getPlatform() == Platform.WINDOWS) {
";"
} else {
":"
}
}

enum class Platform(val detail: String, val key: String) {
WINDOWS("windows", "windows"),
OSX("osx", "macos"),
LINUX("linux", "linux"),
UNIVERSAL("", ""),
}

enum class Arch(val detail: String, val type: String) {
ARM64("-arm64", "64"),
X86("-x86", "32"),
X64("","64"),
UNIVERSAL("","")
X64("", "64"),
UNIVERSAL("", "")
}
4 changes: 2 additions & 2 deletions lib/src/test/kotlin/mikataneko/TestGetGameArgument.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ suspend fun main() {
run {
with(core) {
val versionManifest = manifestHelper.getLatestVersionManifest()
val release = versionManifest.version("1.8.9")!!
val instance = GameInstance(release, gameDirectory)
val release = versionManifest.version("1.20.4")!!
val instance = GameInstance(release, gameDirectory, isolation = false)
val time = measureTime {
manifestHelper.verifyObjects(instance, 64)
manifestHelper.verifyAndDownloadClientJar(instance)
Expand Down

0 comments on commit 1eaf79b

Please sign in to comment.