Pick the newest Windows upload across types for replaced builds and let an update past its commit point finish

This commit is contained in:
FX192 committed 2026-10-28 09:00:36 +03:00
1 parent 9b44bf798d
commit 52e9810fbc
5 files changed
+24 -4

No files matched your search

@@ -216,7 +216,6 @@ internal class ItchInstaller(
throw t
}
ItchStaging.merge(work, folder)
if (cancelled.get()) return null
ItchStaging.delete(work)
}
return exe
@@ -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())
@@ -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) {
@@ -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", ""))
}