Skip to content

Commit 72024ed

Browse files
committed
update api
1 parent 1fea935 commit 72024ed

7 files changed

Lines changed: 28 additions & 14 deletions

File tree

build.gradle.kts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ plugins {
66
}
77

88
group = "org.bundleproject"
9-
version = "0.2.5"
9+
version = "0.2.6"
1010

1111
repositories {
1212
mavenCentral()
13+
maven("https://jitpack.io")
1314
}
1415

1516
dependencies {
16-
implementation("io.ktor:ktor-client-gson:1.6.5")
17-
implementation("io.ktor:ktor-client-core:1.6.5")
18-
implementation("io.ktor:ktor-client-apache:1.6.5")
17+
implementation("io.ktor:ktor-client-gson:1.6.6")
18+
implementation("io.ktor:ktor-client-core:1.6.6")
19+
implementation("io.ktor:ktor-client-apache:1.6.6")
1920

2021
implementation(kotlin("stdlib-jdk8", "1.6.0"))
2122
implementation(kotlin("reflect", "1.6.0"))
@@ -25,6 +26,8 @@ dependencies {
2526
implementation("com.xenomachina:kotlin-argparser:2.0.7") {
2627
exclude(module = "kotlin-stdlib")
2728
}
29+
30+
implementation("org.bundleproject:libversion:0.0.2")
2831
}
2932

3033
blossom {

src/main/kotlin/org/bundleproject/installer/Main.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import org.bundleproject.installer.utils.launcher.profiles.LauncherProfileTypes
1919
import org.bundleproject.installer.utils.launcher.profiles.LauncherProfilesJson
2020
import org.bundleproject.installer.utils.launcher.version.VersionJson
2121
import org.bundleproject.installer.utils.launcher.version.VersionLibrary
22+
import org.bundleproject.libversion.Version
2223
import java.awt.Desktop
2324
import java.io.File
2425
import java.io.InputStreamReader
@@ -34,15 +35,15 @@ import kotlin.system.exitProcess
3435
*/
3536
fun main(args: Array<String>) = mainBody {
3637
if (vmVersion < 9) {
37-
println("Bundle installer requires Java 9 or later.")
38-
InstallerGui.err("Bundle installer requires Java 9 or later.")
38+
println("Bundle installer requires Java 9 or later. This is due to a Ktor bug. The restriction will be lifted soon.")
39+
InstallerGui.err("Bundle installer requires Java 9 or later. This is due to a Ktor bug. The restriction will be lifted soon.")
3940
exitProcess(-1)
4041
}
4142

4243
ArgParser(args, helpFormatter = DefaultHelpFormatter()).parseInto(::InstallerParams).run {
4344
val update = try {
4445
if (!noUpdate) {
45-
runBlocking { getLatestUpdate() }.takeIf { it != INSTALLER_VERSION }
46+
runBlocking { Version.of(getLatestUpdate()) }.takeIf { it > INSTALLER_VERSION }
4647
} else null
4748
} catch (e: Exception) {
4849
e.printStackTrace()
@@ -91,7 +92,7 @@ suspend fun installOfficial(path: File, mcversion: String) {
9192
println("Installing using the official launcher.")
9293

9394
val latest = try {
94-
http.get<VersionResponse>("$API/$API_VERSION/bundle/version").data.launchWrapper
95+
http.get<VersionResponse>("$API/$API_VERSION/bundle/version").data.let { if (PRERELEASE) it.prerelease else it.release }.launchWrapper
9596
} catch (e: ServerResponseException) {
9697
e.printStackTrace()
9798
InstallerGui.err("Couldn't get latest Bundle version to install: ${e.message}")
@@ -169,7 +170,7 @@ suspend fun installMultiMC(instanceFolder: File, instance: String) {
169170
val bundleMetaFolder = File(metaFolder, "org.bundleproject")
170171
bundleMetaFolder.mkdir()
171172

172-
val latest = http.get<VersionResponse>("$API/$API_VERSION/bundle/version").data.updater
173+
val latest = http.get<VersionResponse>("$API/$API_VERSION/bundle/version").data.let { if (PRERELEASE) it.prerelease else it.release }.launchWrapper
173174

174175
val versionFile = File(bundleMetaFolder, "$latest.json")
175176

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.bundleproject.installer.api.data
22

3+
import com.google.gson.annotations.SerializedName
4+
35
data class VersionData(
46
val installer: String,
57
val updater: String,
6-
val launchWrapper: String
8+
@SerializedName("launchwrapper") val launchWrapper: String
79
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package org.bundleproject.installer.api.data
2+
3+
data class VersionsData(val release: VersionData, val prerelease: VersionData)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package org.bundleproject.installer.api.response
22

3-
import org.bundleproject.installer.api.data.VersionData
3+
import org.bundleproject.installer.api.data.VersionsData
44

5-
data class VersionResponse(val success: Boolean, val data: VersionData)
5+
data class VersionResponse(val success: Boolean, val data: VersionsData)

src/main/kotlin/org/bundleproject/installer/updater/UpdateChecker.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package org.bundleproject.installer.updater
22

33
import io.ktor.client.request.*
44
import org.bundleproject.installer.api.data.VersionData
5+
import org.bundleproject.installer.api.response.VersionResponse
56
import org.bundleproject.installer.utils.API
67
import org.bundleproject.installer.utils.API_VERSION
8+
import org.bundleproject.installer.utils.PRERELEASE
79
import org.bundleproject.installer.utils.http
810

911
suspend fun getLatestUpdate(): String =
10-
http.get<VersionData>("$API/$API_VERSION/bundle/version").installer
12+
http.get<VersionResponse>("$API/$API_VERSION/bundle/version").data.let { if (PRERELEASE) it.prerelease else it.release }.installer
1113

1214

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.bundleproject.installer.utils
22

3+
import org.bundleproject.libversion.Version
4+
35
const val API = "https://api.bundleproject.org"
46
const val API_VERSION = "v1"
57

6-
const val INSTALLER_VERSION = "__GRADLE_VERSION__"
8+
val INSTALLER_VERSION = Version.of("__GRADLE_VERSION__")
9+
const val PRERELEASE = true

0 commit comments

Comments
 (0)