Skip to content

Commit

Permalink
Various code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed May 20, 2024
1 parent 5c69a6b commit cd091f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PackInstaller(
private val modsDir = DOT_MINECRAFT / packVersion.launcherFolderPath

@OptIn(ExperimentalPathApi::class)
private fun writeVersionDir(clientJson: JsonObject) {
private fun writeVersionDir(clientJson: JsonObject) {
progressHandler.newTask(I18N.getString("creating.version.folder"))
val versionDir = VERSIONS / packVersion.launcherVersionId
versionDir.deleteRecursively()
Expand Down Expand Up @@ -154,7 +154,7 @@ class PackInstaller(
} else {
Pair(destination, destination / path)
}
if (!dest.startsWith(destRoot)) {
if (!dest.normalize().startsWith(destRoot)) {
throw IllegalArgumentException("Path doesn't start with mods dir?")
}
dest.parent.createDirectories()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.gaming32.additiveinstaller

import com.google.gson.FormattingStyle
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.google.gson.JsonParser
Expand Down Expand Up @@ -72,7 +73,9 @@ fun requestCriticalJson(url: String) = try {

fun String.capitalize() = replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() }

fun JsonElement.writeTo(writer: Writer) = Streams.write(this, JsonWriter(writer).apply { setIndent(" ") })
fun JsonElement.writeTo(writer: Writer) = Streams.write(this, JsonWriter(writer).apply {
formattingStyle = FormattingStyle.PRETTY
})

fun String.hexToByteArray(): ByteArray {
require((length and 1) == 0) { "$this has an odd number of chars" }
Expand Down

0 comments on commit cd091f1

Please sign in to comment.