From 52e9810fbc621a0e599aa5b9df3a27856dd6d7ae Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:00:36 +0300 Subject: [PATCH] Pick the newest Windows upload across types for replaced builds and let an update past its commit point finish --- .../droiddeck/launcher/stores/itch/ItchInstaller.kt | 1 - .../droiddeck/launcher/stores/itch/ItchUpdates.kt | 2 +- .../droiddeck/launcher/stores/itch/ItchUploads.kt | 8 ++++++++ .../launcher/stores/itch/ItchUpdatesTest.kt | 13 +++++++++++-- docs/development/itch-updates.md | 4 ++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchInstaller.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchInstaller.kt index 83dbd4752c..f084e503d6 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchInstaller.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchInstaller.kt @@ -216,7 +216,6 @@ internal class ItchInstaller( throw t } ItchStaging.merge(work, folder) - if (cancelled.get()) return null ItchStaging.delete(work) } return exe diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt index 30bcbb324e..2a1d105ed2 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt @@ -38,7 +38,7 @@ internal object ItchUpdates { val stamp = ItchUploads.updatedAt(current) return if (stamp > version) ItchUpdate(uploadId, stamp, ItchUploads.filename(current), false) else null } - val next = ItchUploads.windows(uploads)?.takeIf { ItchUploads.windows(it) } ?: return null + val next = ItchUploads.newestWindows(uploads) ?: return null val stamp = ItchUploads.updatedAt(next) if (uploadId.isBlank() && stamp <= version) return null return ItchUpdate(next.optString("id"), stamp, ItchUploads.filename(next), uploadId.isNotBlank()) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUploads.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUploads.kt index b0d636a981..208c11169f 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUploads.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUploads.kt @@ -18,6 +18,14 @@ internal object ItchUploads { return candidates.maxWithOrNull(compareBy({ it.optString("updated_at", it.optString("updatedAt")) }, { it.optLong("id") })) } + fun newestWindows(uploads: JSONArray?): JSONObject? { + if (uploads == null) return null + val windows = (0 until uploads.length()).mapNotNull { uploads.optJSONObject(it) } + .filter { it.optString("storage") != "external" && !it.optBoolean("demo") && windows(it) } + val games = windows.filter { it.optString("type") in GAME_TYPES } + return games.ifEmpty { windows }.maxWithOrNull(compareBy({ updatedAt(it) }, { it.optLong("id") })) + } + fun windows(upload: JSONObject): Boolean { val platforms = upload.optJSONObject("platforms") if (platforms != null) { diff --git a/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchUpdatesTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchUpdatesTest.kt index d8f969a8a0..8193235c3f 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchUpdatesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchUpdatesTest.kt @@ -11,8 +11,8 @@ import org.junit.Test @org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class) @org.robolectric.annotation.Config(sdk = [33], application = android.app.Application::class) class ItchUpdatesTest { - private fun upload(id: String, updated: String, filename: String = "game-$id.zip", windows: Boolean = true) = - JSONObject().put("id", id).put("filename", filename).put("updated_at", updated).put("type", "default").put("storage", "hosted") + private fun upload(id: String, updated: String, filename: String = "game-$id.zip", windows: Boolean = true, type: String = "default") = + JSONObject().put("id", id).put("filename", filename).put("updated_at", updated).put("type", type).put("storage", "hosted") .put("platforms", JSONObject().put("windows", windows).put("linux", !windows)) private fun list(vararg uploads: JSONObject) = JSONArray().also { a -> uploads.forEach { a.put(it) } } @@ -47,6 +47,15 @@ class ItchUpdatesTest { assertNull(ItchUpdates.evaluate(linux, "", "2026-09-01T10:00:00Z")) } + @Test fun aWindowsBuildOfAnotherTypeBeatsALinuxDefaultOne() { + val update = ItchUpdates.evaluate( + list(upload("8", "2026-10-09T10:00:00Z", windows = false), upload("9", "2026-10-01T10:00:00Z", type = "other")), + "7", "2026-09-01T10:00:00Z", + )!! + assertEquals("9", update.uploadId) + assertTrue(update.replaced) + } + @Test fun anUnknownInstalledVersionNeverReportsAnUpdate() { assertNull(ItchUpdates.evaluate(list(upload("7", "2026-10-20T10:00:00Z")), "7", "")) } diff --git a/docs/development/itch-updates.md b/docs/development/itch-updates.md index a9dfabaea1..574253b9f3 100644 --- a/docs/development/itch-updates.md +++ b/docs/development/itch-updates.md @@ -38,3 +38,7 @@ build does not contain (saves, settings, the install record, launcher and art) s is marked updating just before the move, so an interruption in that short step is resumable, and the finished record carries the new `installVersion` and `uploadId`. Free space for one extra copy of the build is needed while the update runs. + +A cancel that arrives before the files are moved in stops the update and removes the staging folder. Once +the move has started the update is past the point of no return: it finishes and writes the new record, so +a cancel during that short step cannot leave new files under an old record.