From 68e859bd6a02461151527852b3e98b3a4bee5f01 Mon Sep 17 00:00:00 2001 From: Cal Date: Sun, 17 Nov 2024 21:43:37 +1100 Subject: [PATCH 1/2] Backend: Add Minecraft Version to jar file name --- build.gradle.kts | 2 + .../update/CustomGithubReleaseUpdateSource.kt | 40 +++++++++++++++++++ .../features/misc/update/UpdateManager.kt | 3 +- .../skyhanni/utils/system/PlatformUtils.kt | 2 + 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt diff --git a/build.gradle.kts b/build.gradle.kts index e85907187835..65cf45276c8a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -312,6 +312,7 @@ tasks.withType(JavaCompile::class) { tasks.withType(org.gradle.jvm.tasks.Jar::class) { archiveBaseName.set("SkyHanni") + archiveAppendix.set(target.minecraftVersion.versionName) duplicatesStrategy = DuplicatesStrategy.EXCLUDE // Why do we have this here? This only *hides* errors. manifest.attributes.run { this["Main-Class"] = "SkyHanniInstallerFrame" @@ -384,6 +385,7 @@ preprocess { blossom { replaceToken("@MOD_VERSION@", version) + replaceToken("@MC_VERSION@", target.minecraftVersion.versionName) } val sourcesJar by tasks.creating(Jar::class) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt new file mode 100644 index 000000000000..bfcf836678b7 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt @@ -0,0 +1,40 @@ +package at.hannibal2.skyhanni.features.misc.update + +import at.hannibal2.skyhanni.utils.system.PlatformUtils +import com.google.gson.JsonPrimitive +import moe.nea.libautoupdate.GithubReleaseUpdateData +import moe.nea.libautoupdate.GithubReleaseUpdateSource +import moe.nea.libautoupdate.UpdateData + +class CustomGithubReleaseUpdateSource(owner: String, repository: String) : GithubReleaseUpdateSource(owner, repository) { + + override fun findAsset(release: GithubRelease?): UpdateData? { + release ?: return null + + return release.assets.stream() + .filter { it.filterAsset() } + .map { it.createReleaseData(release) } + .findFirst().orElse(null) + } + + private fun GithubRelease.Download.filterAsset(): Boolean { + name ?: return false + browserDownloadUrl ?: return false + if (!name.endsWith(".jar")) return false + return name.contains(PlatformUtils.MC_VERSION) + } + + private fun GithubRelease.Download.createReleaseData(release: GithubRelease): GithubReleaseUpdateData { + return GithubReleaseUpdateData( + if (release.name == null) release.tagName else release.name, + JsonPrimitive(release.tagName), + null, + browserDownloadUrl, + release.body, + release.targetCommitish, + release.created_at, + release.publishedAt, + release.htmlUrl, + ) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt index 1f9b2e66ffa7..76ed7c14cd1e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/update/UpdateManager.kt @@ -16,7 +16,6 @@ import io.github.notenoughupdates.moulconfig.processor.MoulConfigProcessor import moe.nea.libautoupdate.CurrentVersion import moe.nea.libautoupdate.PotentialUpdate import moe.nea.libautoupdate.UpdateContext -import moe.nea.libautoupdate.UpdateSource import moe.nea.libautoupdate.UpdateTarget import moe.nea.libautoupdate.UpdateUtils import net.minecraft.client.Minecraft @@ -134,7 +133,7 @@ object UpdateManager { } private val context = UpdateContext( - UpdateSource.githubUpdateSource("hannibal002", "SkyHanni"), + CustomGithubReleaseUpdateSource("hannibal002", "SkyHanni"), UpdateTarget.deleteAndSaveInTheSameFolder(UpdateManager::class.java), object : CurrentVersion { val normalDelegate = CurrentVersion.ofTag(SkyHanniMod.version) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/system/PlatformUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/system/PlatformUtils.kt index b13921401fd1..d42fefec922a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/system/PlatformUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/system/PlatformUtils.kt @@ -10,6 +10,8 @@ import net.minecraftforge.fml.common.ModContainer */ object PlatformUtils { + const val MC_VERSION = "@MC_VERSION@" + private val modPackages: Map by lazy { Loader.instance().modList.flatMap { mod -> mod.ownedPackages.map { it to mod } }.toMap() } From 7b073e2d0a158e43e9de01ded25cfa71cf1c4b75 Mon Sep 17 00:00:00 2001 From: Cal Date: Mon, 18 Nov 2024 10:45:00 +1100 Subject: [PATCH 2/2] make the jar name now `SkyHanni-mc1.8.9-0.28.Beta.13.jar` --- build.gradle.kts | 2 +- .../features/misc/update/CustomGithubReleaseUpdateSource.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 65cf45276c8a..e04764ae7526 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -312,7 +312,7 @@ tasks.withType(JavaCompile::class) { tasks.withType(org.gradle.jvm.tasks.Jar::class) { archiveBaseName.set("SkyHanni") - archiveAppendix.set(target.minecraftVersion.versionName) + archiveAppendix.set("mc${target.minecraftVersion.versionName}") duplicatesStrategy = DuplicatesStrategy.EXCLUDE // Why do we have this here? This only *hides* errors. manifest.attributes.run { this["Main-Class"] = "SkyHanniInstallerFrame" diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt index bfcf836678b7..d244c0f8806b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt @@ -6,6 +6,9 @@ import moe.nea.libautoupdate.GithubReleaseUpdateData import moe.nea.libautoupdate.GithubReleaseUpdateSource import moe.nea.libautoupdate.UpdateData +/** + * This class is a custom implementation of the [GithubReleaseUpdateSource] that filters assets based on the mod's version. + */ class CustomGithubReleaseUpdateSource(owner: String, repository: String) : GithubReleaseUpdateSource(owner, repository) { override fun findAsset(release: GithubRelease?): UpdateData? {