From 8a16bd3b3b35727241a473b2e20f91a9a4aa2112 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:53:35 +0300 Subject: [PATCH 01/14] Detect itch.io updates and offer to install them Installed itch games are compared with the uploads itch lists for them. A game with a newer upload shows an Update label in the Library and an Update button on its page, a replaced build asks first, and a Check for updates button in the itch Library header runs the check on demand. --- .../droiddeck/launcher/stores/StoresState.kt | 5 +- .../launcher/stores/itch/ItchInstaller.kt | 2 + .../launcher/stores/itch/ItchUpdates.kt | 149 ++++++++++++++++++ .../launcher/stores/itch/ItchUploads.kt | 2 + .../com/droiddeck/launcher/ui/GameDetail.kt | 1 + .../droiddeck/launcher/ui/ItchUpdateButton.kt | 51 ++++++ .../com/droiddeck/launcher/ui/LibraryPage.kt | 21 ++- app/src/main/res/values-ar/strings.xml | 2 + app/src/main/res/values-b+es+419/strings.xml | 2 + app/src/main/res/values-bg/strings.xml | 2 + app/src/main/res/values-cs/strings.xml | 2 + app/src/main/res/values-da/strings.xml | 2 + app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values-el/strings.xml | 2 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-fi/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values-hi/strings.xml | 2 + app/src/main/res/values-hu/strings.xml | 2 + app/src/main/res/values-in/strings.xml | 2 + app/src/main/res/values-it/strings.xml | 2 + app/src/main/res/values-ja/strings.xml | 2 + app/src/main/res/values-ko/strings.xml | 2 + app/src/main/res/values-ms/strings.xml | 2 + app/src/main/res/values-nb/strings.xml | 2 + app/src/main/res/values-nl/strings.xml | 2 + app/src/main/res/values-pl/strings.xml | 2 + app/src/main/res/values-pt-rPT/strings.xml | 2 + app/src/main/res/values-pt/strings.xml | 2 + app/src/main/res/values-ro/strings.xml | 2 + app/src/main/res/values-ru/strings.xml | 2 + app/src/main/res/values-sv/strings.xml | 2 + app/src/main/res/values-th/strings.xml | 2 + app/src/main/res/values-tr/strings.xml | 2 + app/src/main/res/values-uk/strings.xml | 2 + app/src/main/res/values-vi/strings.xml | 2 + app/src/main/res/values-zh-rCN/strings.xml | 2 + app/src/main/res/values-zh-rHK/strings.xml | 2 + app/src/main/res/values-zh-rTW/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + .../launcher/stores/itch/ItchUpdatesTest.kt | 69 ++++++++ docs/development/itch-updates.md | 29 ++++ 42 files changed, 392 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt create mode 100644 app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/stores/itch/ItchUpdatesTest.kt create mode 100644 docs/development/itch-updates.md diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt index 3edac79a4b..0cea0681ed 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt @@ -191,7 +191,10 @@ object StoresState { backend?.signOut(app) if (store == Store.GOG) com.droiddeck.launcher.stores.gog.GogComet.replaceAccount { StoreAccounts.clear(app, store) } else if (store != Store.XBOX || backend == null) StoreAccounts.clear(app, store) - if (store == Store.ITCH) com.droiddeck.launcher.stores.itch.ItchCollections.clear() + if (store == Store.ITCH) { + com.droiddeck.launcher.stores.itch.ItchCollections.clear() + com.droiddeck.launcher.stores.itch.ItchUpdates.clear(app) + } main.post { if (store == Store.XBOX && StoreAccounts.signedInAs(app, store) != null) return@post accounts.remove(store); library.remove(store); status.remove(store); problems.remove(store); libraryAsked.remove(store) 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 5037de863c..0d7949daeb 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 @@ -58,6 +58,7 @@ internal class ItchInstaller( download(key, downloadKeyId, uploadId, upload.optString("updated_at", upload.optString("updatedAt")), archive, size, handle) if (cancelled.get()) return null handle.stage(DownloadStage.INSTALL) + if (StoreGameSidecar.read(folder)?.isInstalled == true) StoreInstalls.markUpdating(folder) install(archive, filename, handle, resuming) } catch (t: Throwable) { if (!cancelled.get()) StoreInstalls.discard(app, folder, listOf(scratch)) @@ -83,6 +84,7 @@ internal class ItchInstaller( cloud = false, ) StoreInstalls.complete(app, folder, sidecar) { done, steps -> handle.stageProgress(done.toLong(), steps.toLong()) } + ItchUpdates.applied(app, item.key) return folder.path } 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 new file mode 100644 index 0000000000..f7656b017c --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt @@ -0,0 +1,149 @@ +package com.droiddeck.launcher.stores.itch + +import android.content.Context +import android.widget.Toast +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateMapOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import com.droiddeck.launcher.R +import com.droiddeck.launcher.stores.CatalogItem +import com.droiddeck.launcher.stores.InstalledStoreGame +import com.droiddeck.launcher.stores.Store +import com.droiddeck.launcher.stores.StoresState +import org.json.JSONArray +import org.json.JSONObject +import java.util.concurrent.atomic.AtomicBoolean + +internal class ItchUpdate(val uploadId: String, val updatedAt: String, val filename: String, val replaced: Boolean) + +internal object ItchUpdates { + private const val KEY_AT = "updates_checked_at" + private const val KEY_FOUND = "updates_found" + private const val THROTTLE_MS = 6 * 60 * 60 * 1000L + private const val GAP_MS = 1_000L + + val available = mutableStateMapOf() + var checking by mutableStateOf(false) + private set + var done by mutableIntStateOf(0) + private set + var total by mutableIntStateOf(0) + private set + + private val running = AtomicBoolean(false) + private val restored = AtomicBoolean(false) + + internal fun evaluate(uploads: JSONArray?, uploadId: String, version: String): ItchUpdate? { + if (uploads == null || version.isBlank()) return null + val current = ItchUploads.byId(uploads, uploadId) + if (current != null) { + val stamp = ItchUploads.updatedAt(current) + return if (stamp > version) ItchUpdate(uploadId, stamp, ItchUploads.filename(current), false) else null + } + val next = ItchUploads.windows(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()) + } + + internal fun encode(found: Map): String = JSONObject().also { out -> + for ((key, u) in found) out.put(key, JSONObject().put("uploadId", u.uploadId).put("updatedAt", u.updatedAt).put("filename", u.filename).put("replaced", u.replaced)) + }.toString() + + internal fun decode(raw: String?): Map { + val json = runCatching { JSONObject(raw.orEmpty()) }.getOrNull() ?: return emptyMap() + val out = LinkedHashMap() + for (key in json.keys()) { + val u = json.optJSONObject(key) ?: continue + val id = u.optString("uploadId").ifBlank { continue } + out[key] = ItchUpdate(id, u.optString("updatedAt"), u.optString("filename"), u.optBoolean("replaced")) + } + return out + } + + private fun restore(app: Context) { + if (!restored.compareAndSet(false, true)) return + val saved = decode(ItchPrefs.get(app).getString(KEY_FOUND, null)) + StoresState.post { for ((k, v) in saved) if (k !in available) available[k] = v } + } + + private fun save(app: Context) { + ItchPrefs.get(app).edit().putString(KEY_FOUND, encode(available.toMap())).apply() + } + + fun check(context: Context, force: Boolean) { + val app = context.applicationContext + if (!running.compareAndSet(false, true)) return + Thread({ + try { + restore(app) + val prefs = ItchPrefs.get(app) + if (!force && System.currentTimeMillis() - prefs.getLong(KEY_AT, 0L) < THROTTLE_MS) return@Thread + val key = ItchAuth.key(app) + if (key.isBlank()) return@Thread + val games = StoresState.installed.toList().filter { it.sidecar.store == Store.ITCH && it.sidecar.isInstalled } + StoresState.post { total = games.size; done = 0; checking = true } + val found = LinkedHashMap() + val answered = HashSet() + var failed = false + games.forEachIndexed { i, game -> + if (i > 0) Thread.sleep(GAP_MS) + val extra = game.sidecar.extra + val gameId = extra["gameId"].orEmpty() + if (gameId.isNotEmpty()) { + val uploads = ItchApi.uploads(key, gameId, extra["downloadKeyId"].orEmpty()) + if (uploads == null) failed = true + else { + answered += game.key + evaluate(uploads, extra["uploadId"].orEmpty(), game.sidecar.installVersion)?.let { found[game.key] = it } + } + } + StoresState.post { done = i + 1 } + } + StoresState.post { + for (k in answered) { + val u = found[k] + if (u != null) available[k] = u else available.remove(k) + } + save(app) + } + if (!failed) prefs.edit().putLong(KEY_AT, System.currentTimeMillis()).apply() + StoresState.logLine("itch.io: checked ${games.size} installed games, ${found.size} with updates") + if (force) StoresState.post { + val text = if (found.isNotEmpty()) app.getString(R.string.stores_itch_updates_found, found.size) else app.getString(R.string.upd_current_status) + Toast.makeText(app, text, Toast.LENGTH_SHORT).show() + } + } finally { + running.set(false) + StoresState.post { checking = false } + } + }, "itch-updates").start() + } + + fun start(context: Context, game: InstalledStoreGame, update: ItchUpdate) { + val app = context.applicationContext + val root = game.folder.parentFile?.parentFile ?: return + val extra = game.sidecar.extra + ("uploadId" to update.uploadId) + val item = CatalogItem( + Store.ITCH, game.sidecar.id, game.sidecar.title, game.sidecar.hero, tallImageUrl = game.sidecar.cover, + isFree = extra["downloadKeyId"].isNullOrBlank(), owned = true, extra = extra, + ) + StoresState.install(app, item, root) + } + + fun applied(context: Context, key: String) { + val app = context.applicationContext + StoresState.post { + available.remove(key) + save(app) + } + } + + fun clear(context: Context) { + val app = context.applicationContext + ItchPrefs.get(app).edit().remove(KEY_AT).remove(KEY_FOUND).apply() + StoresState.post { available.clear() } + } +} 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 7e3ed94b47..b0d636a981 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 @@ -52,6 +52,8 @@ internal object ItchUploads { return (0 until uploads.length()).mapNotNull { uploads.optJSONObject(it) }.firstOrNull { it.optString("id") == id } } + fun updatedAt(upload: JSONObject): String = upload.optString("updated_at", upload.optString("updatedAt")) + fun size(upload: JSONObject): Long = upload.optLong("size", upload.optLong("size_bytes")) fun filename(upload: JSONObject): String = upload.optString("filename").substringAfterLast('/') diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt index 5350d2afa5..e46a15b239 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt @@ -357,6 +357,7 @@ internal fun GameActions( GameShortcutMenu(game, a) EditArtButton(game) } + if (store == Store.ITCH && installed != null) ItchUpdateButton(installed, download == null) if (store == Store.XBOX && id != null) XboxInstalledStream(id, game?.name ?: item?.title.orEmpty(), item) if (store == Store.XBOX && installed != null && id != null) { SecondaryButton(stringResource(R.string.stores_xbox_update), enabled = download == null && !XboxRuntime.isActive(id)) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt b/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt new file mode 100644 index 0000000000..37151db81a --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt @@ -0,0 +1,51 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.droiddeck.launcher.R +import com.droiddeck.launcher.stores.InstalledStoreGame +import com.droiddeck.launcher.stores.itch.ItchUpdate +import com.droiddeck.launcher.stores.itch.ItchUpdates + +@Composable +internal fun ItchUpdateButton(installed: InstalledStoreGame, enabled: Boolean) { + val ctx = LocalContext.current + val update = ItchUpdates.available[installed.key] ?: return + var asking by remember { mutableStateOf(false) } + SecondaryButton(stringResource(R.string.common_update), enabled = enabled) { + if (update.replaced) asking = true else ItchUpdates.start(ctx, installed, update) + } + if (asking) ReplacedDialog(installed, update) { asking = false } +} + +@Composable +private fun ReplacedDialog(installed: InstalledStoreGame, update: ItchUpdate, onDismiss: () -> Unit) { + val ctx = LocalContext.current + val shown = rememberShown(onDismiss) + val close = { shown.targetState = false } + AppDialog(shown, close, "itchUpdate", wide = false, maxWidth = 460.dp) { + DialogTitleRow(installed.sidecar.title, close) + Text( + stringResource(R.string.stores_itch_update_replaced, update.filename.ifBlank { update.uploadId }), + fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + PrimaryButton(stringResource(R.string.common_update)) { + close() + ItchUpdates.start(ctx, installed, update) + } + SecondaryButton(stringResource(R.string.common_cancel)) { close() } + } + } +} diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt index 4a3b24ce67..1353e38228 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt @@ -38,6 +38,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.FilterAlt import androidx.compose.material.icons.filled.GridView import androidx.compose.material.icons.filled.PlayArrow +import androidx.compose.material.icons.filled.Refresh import androidx.compose.material.icons.filled.Sort import androidx.compose.material.icons.filled.ViewList import androidx.compose.material.icons.filled.ViewModule @@ -91,6 +92,7 @@ import com.droiddeck.launcher.stores.download.DownloadEntry import com.droiddeck.launcher.stores.formatBytes import com.droiddeck.launcher.stores.itch.ItchCollection import com.droiddeck.launcher.stores.itch.ItchCollections +import com.droiddeck.launcher.stores.itch.ItchUpdates import com.droiddeck.launcher.stores.retainOrder import com.droiddeck.launcher.stores.xbox.XboxLibraryFilter import com.droiddeck.launcher.stores.sortGames @@ -194,7 +196,10 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, val source = LibraryView.source.takeIf { it == LIBRARY_ALL || it in sources } ?: LIBRARY_ALL val q = LibraryView.query.trim().lowercase() val xboxFilter = if (source == Store.XBOX.id) XboxLibraryFilter.current else XboxLibraryFilter.ALL - LaunchedEffect(source, itchSignedIn) { if (source == Store.ITCH.id && itchSignedIn) ItchCollections.load(ctx) } + LaunchedEffect(source, itchSignedIn) { if (source == Store.ITCH.id && itchSignedIn) { + ItchCollections.load(ctx) + ItchUpdates.check(ctx, false) + } } val collection = if (source == Store.ITCH.id) ItchCollections.chosen() else null val pool = if (collection == null) all else collectionEntries(all, ItchCollections.gamesOf(collection.id).orEmpty()) val matching = pool.filter { @@ -468,7 +473,10 @@ private fun LibraryHeader( }, ) { if (showUninstalled != null || xbox) LibraryFilterButton(showUninstalled, onShowUninstalled, xbox) - if (collections) CollectionsButton() + if (collections) { + CollectionsButton() + UpdatesButton() + } SortButton(s, a) ViewButton(s, a) GameFileFolderActions(s, a) @@ -582,6 +590,7 @@ internal fun LibraryMarker(e: LibraryEntry, download: DownloadEntry?) { download != null -> Text("${download.percent}%", fontSize = 10.sp, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1) e.item != null && StoresState.isUnfinished(e.item) -> Text(stringResource(R.string.stores_resume), fontSize = 10.sp, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1) else -> Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(3.dp)) { + if (e.installed && e.storeKey?.let { it in ItchUpdates.available } == true) Text(stringResource(R.string.common_update), fontSize = 10.sp, fontWeight = FontWeight.Bold, color = pal.signal, maxLines = 1) if (size != null && size > 0) Text(formatBytes(size), fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Color.White, maxLines = 1) if (!e.installed) Icon(Icons.Outlined.Download, stringResource(R.string.stores_section_not_installed), tint = Color.White, modifier = Modifier.size(12.dp)) } @@ -722,6 +731,14 @@ private fun LibraryFilterButton(showUninstalled: Boolean?, onShowUninstalled: (B } } +@Composable +private fun UpdatesButton() { + val ctx = LocalContext.current + val title = stringResource(R.string.store_check_updates) + val description = if (ItchUpdates.checking) title + " · " + ItchUpdates.done + "/" + ItchUpdates.total else title + HeaderIconButton(description, Icons.Filled.Refresh, "itch-updates") { ItchUpdates.check(ctx, true) } +} + @Composable private fun CollectionsButton() { val pal = LocalPalette.current diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index f78cf3014d..032b601303 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -3219,6 +3219,8 @@ في المكتبة عرض المجموعات + التحديثات المتاحة: %1$d + استبدل المطوّر هذا الإصدار بـ %1$s. هل تريد التحديث إليه؟ سحابية إعدادات السحابة diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index 09e76582e9..60793feeda 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -3069,6 +3069,8 @@ En Biblioteca Mostrar Colecciones + Actualizaciones disponibles: %1$d + El desarrollador reemplazó esta versión por %1$s. ¿Actualizar a ella? Nube Configuración de nube diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 314b01f305..4f29236a90 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -3083,6 +3083,8 @@ В Библиотека Показване Колекции + Налични актуализации: %1$d + Разработчикът замени тази версия с %1$s. Да се актуализира ли до нея? Облак Настройки на облака diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index e0278767d6..8865d265d7 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -3151,6 +3151,8 @@ V knihovně Zobrazit Kolekce + Dostupné aktualizace: %1$d + Vývojář nahradil tuto verzi souborem %1$s. Aktualizovat na ni? Cloud Nastavení cloudu diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 789cbc762d..e086236a8e 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -3083,6 +3083,8 @@ I Bibliotek Vis Samlinger + Opdateringer tilgængelige: %1$d + Udvikleren har erstattet denne version med %1$s. Opdater til den? Sky Skyindstillinger diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 1ddc2655d3..cd25cb81db 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -3083,6 +3083,8 @@ In der Bibliothek Anzeigen Sammlungen + Verfügbare Updates: %1$d + Der Entwickler hat diesen Build durch %1$s ersetzt. Darauf aktualisieren? Cloud Cloud-Einstellungen diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 85e3befcd8..5f8e5fb325 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -3083,6 +3083,8 @@ Στη Βιβλιοθήκη Εμφάνιση Συλλογές + Διαθέσιμες ενημερώσεις: %1$d + Ο προγραμματιστής αντικατέστησε αυτήν την έκδοση με %1$s. Να γίνει ενημέρωση σε αυτήν; Cloud Ρυθμίσεις cloud diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index f6d49f6f92..95c323a10c 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -3119,6 +3119,8 @@ En la Biblioteca Mostrar Colecciones + Actualizaciones disponibles: %1$d + El desarrollador reemplazó esta versión por %1$s. ¿Actualizar a ella? Nube Ajustes de nube diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 79737e2e0f..b59170ed4f 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -3083,6 +3083,8 @@ Kirjastossa Näytä Kokoelmat + Päivityksiä saatavilla: %1$d + Kehittäjä korvasi tämän version tiedostolla %1$s. Päivitetäänkö siihen? Pilvi Pilviasetukset diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 97cb78aa59..6bb04341a7 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -3119,6 +3119,8 @@ Dans la Bibliothèque Afficher Collections + Mises à jour disponibles : %1$d + Le développeur a remplacé cette version par %1$s. Mettre à jour vers celle-ci ? Cloud Paramètres cloud diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index a1edf261e0..72045e4502 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -3083,6 +3083,8 @@ लाइब्रेरी में दिखाएँ संग्रह + उपलब्ध अपडेट: %1$d + डेवलपर ने इस बिल्ड को %1$s से बदल दिया है। क्या उस पर अपडेट करें? क्लाउड क्लाउड सेटिंग्स diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 747b7ed5c1..51040c93ff 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -3083,6 +3083,8 @@ A könyvtárban Megjelenítés Gyűjtemények + Elérhető frissítések: %1$d + A fejlesztő lecserélte ezt a buildet erre: %1$s. Frissít rá? Felhő Felhőbeállítások diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 79291d8e70..3ed0b2f76d 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -3073,6 +3073,8 @@ Di Pustaka Tampilkan Koleksi + Pembaruan tersedia: %1$d + Pengembang mengganti build ini dengan %1$s. Perbarui ke build itu? Cloud Pengaturan cloud diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index bbe5351461..7ba1e9dbd3 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -3117,6 +3117,8 @@ Nella Libreria Mostra Raccolte + Aggiornamenti disponibili: %1$d + Lo sviluppatore ha sostituito questa build con %1$s. Aggiornare a quella? Cloud Impostazioni cloud diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 19f6dbfaee..f8ea6e2944 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -3060,6 +3060,8 @@ ライブラリにあります 表示 コレクション + 利用可能なアップデート: %1$d + 開発者がこのビルドを %1$s に置き換えました。更新しますか? クラウド クラウド設定 diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 9163a3a7d7..653be3788f 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -3060,6 +3060,8 @@ 라이브러리에 있음 표시 컬렉션 + 사용 가능한 업데이트: %1$d + 개발자가 이 빌드를 %1$s(으)로 교체했습니다. 업데이트할까요? 클라우드 클라우드 설정 diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index eb41beb9b0..14b01731b3 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -3058,6 +3058,8 @@ Dalam Pustaka Tunjukkan Koleksi + Kemas kini tersedia: %1$d + Pembangun telah menggantikan binaan ini dengan %1$s. Kemas kini kepadanya? Awan Tetapan awan diff --git a/app/src/main/res/values-nb/strings.xml b/app/src/main/res/values-nb/strings.xml index 75653c225f..4f65587763 100644 --- a/app/src/main/res/values-nb/strings.xml +++ b/app/src/main/res/values-nb/strings.xml @@ -3083,6 +3083,8 @@ I Bibliotek Vis Samlinger + Oppdateringer tilgjengelig: %1$d + Utvikleren har erstattet denne versjonen med %1$s. Oppdatere til den? Sky Skyinnstillinger diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 53748c36ab..2cee4c6650 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -3083,6 +3083,8 @@ In Bibliotheek Weergeven Collecties + Beschikbare updates: %1$d + De ontwikkelaar heeft deze build vervangen door %1$s. Bijwerken naar die build? Cloud Cloudinstellingen diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 37619c513a..5ffea86be0 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -3154,6 +3154,8 @@ W bibliotece Pokaż Kolekcje + Dostępne aktualizacje: %1$d + Deweloper zastąpił tę wersję plikiem %1$s. Zaktualizować do niej? Chmura Ustawienia chmury diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 177799c1a2..ccaa84a63a 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -3117,6 +3117,8 @@ Na Biblioteca Mostrar Coleções + Atualizações disponíveis: %1$d + O programador substituiu esta versão por %1$s. Atualizar para ela? Nuvem Definições da nuvem diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 2bdda9aacd..99db07b1f2 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -3117,6 +3117,8 @@ Na Biblioteca Mostrar Coleções + Atualizações disponíveis: %1$d + O desenvolvedor substituiu esta versão por %1$s. Atualizar para ela? Nuvem Configurações da nuvem diff --git a/app/src/main/res/values-ro/strings.xml b/app/src/main/res/values-ro/strings.xml index 49a0503c69..d4573054bb 100644 --- a/app/src/main/res/values-ro/strings.xml +++ b/app/src/main/res/values-ro/strings.xml @@ -3117,6 +3117,8 @@ În Bibliotecă Afișează Colecții + Actualizări disponibile: %1$d + Dezvoltatorul a înlocuit această versiune cu %1$s. Actualizezi la ea? Cloud Setări cloud diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index b4d440f2c9..40ca2d7478 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -3153,6 +3153,8 @@ В библиотеке Показать Коллекции + Доступные обновления: %1$d + Разработчик заменил эту сборку на %1$s. Обновиться до неё? Облако Настройки облака diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 35c26e8f21..584ad5ee0b 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -3083,6 +3083,8 @@ I Bibliotek Visa Samlingar + Uppdateringar tillgängliga: %1$d + Utvecklaren har ersatt den här versionen med %1$s. Uppdatera till den? Moln Molninställningar diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 348740686b..ec8977e8e9 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -3058,6 +3058,8 @@ อยู่ในไลบรารี แสดง คอลเลกชัน + มีอัปเดตพร้อมใช้งาน: %1$d + ผู้พัฒนาได้แทนที่บิลด์นี้ด้วย %1$s ต้องการอัปเดตเป็นบิลด์นั้นไหม คลาวด์ การตั้งค่าคลาวด์ diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 78cdc1f700..26b9195d6c 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -3085,6 +3085,8 @@ Kütüphane içinde Göster Koleksiyonlar + Mevcut güncellemeler: %1$d + Geliştirici bu sürümü %1$s ile değiştirdi. Ona güncellensin mi? Bulut Bulut ayarları diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 050fd0fdcf..94f3b0762c 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -3151,6 +3151,8 @@ У бібліотеці Показати Колекції + Доступні оновлення: %1$d + Розробник замінив цю збірку на %1$s. Оновити до неї? Хмара Налаштування хмари diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 9c75292d7f..130f66630e 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -3058,6 +3058,8 @@ Trong Thư viện Hiển thị Bộ sưu tập + Có bản cập nhật: %1$d + Nhà phát triển đã thay bản dựng này bằng %1$s. Cập nhật lên bản đó? Đám mây Cài đặt đám mây diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index ade2de5de3..b2aa8d0705 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -3062,6 +3062,8 @@ 已在游戏库 显示 收藏集 + 可用更新:%1$d + 开发者已将此版本替换为 %1$s。要更新到该版本吗? 云 云设置 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 94ed816a9f..4abd923766 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -3061,6 +3061,8 @@ 已在收藏庫 顯示 收藏集 + 可用更新:%1$d + 開發者已將此版本替換為 %1$s。要更新到該版本嗎? 雲端 雲端設定 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0c3257ead8..444fa00998 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -3061,6 +3061,8 @@ 已在收藏庫 顯示 收藏集 + 可用更新:%1$d + 開發者已將此版本替換為 %1$s。要更新到該版本嗎? 雲端 雲端設定 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc6649cc86..f9cb5f69e8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3234,6 +3234,8 @@ In Library Show Collections + Updates available: %1$d + The developer replaced this build with %1$s. Update to it? Cloud Cloud settings Xbox Cloud Gaming 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 new file mode 100644 index 0000000000..8c263173d0 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchUpdatesTest.kt @@ -0,0 +1,69 @@ +package com.droiddeck.launcher.stores.itch + +import org.json.JSONArray +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +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") + .put("platforms", JSONObject().put("windows", windows).put("linux", !windows)) + + private fun list(vararg uploads: JSONObject) = JSONArray().also { a -> uploads.forEach { a.put(it) } } + + @Test fun aNewerStampOnTheSameUploadIsAnUpdate() { + val update = ItchUpdates.evaluate(list(upload("7", "2026-10-20T10:00:00Z")), "7", "2026-09-01T10:00:00Z")!! + assertEquals("7", update.uploadId) + assertEquals("2026-10-20T10:00:00Z", update.updatedAt) + assertFalse(update.replaced) + } + + @Test fun theSameStampIsNotAnUpdate() { + assertNull(ItchUpdates.evaluate(list(upload("7", "2026-09-01T10:00:00Z")), "7", "2026-09-01T10:00:00Z")) + } + + @Test fun anOlderStampIsNotAnUpdate() { + assertNull(ItchUpdates.evaluate(list(upload("7", "2026-08-01T10:00:00Z")), "7", "2026-09-01T10:00:00Z")) + } + + @Test fun aMissingUploadFallsBackToTheNewestWindowsOneAndAsksFirst() { + val update = ItchUpdates.evaluate( + list(upload("8", "2026-10-01T10:00:00Z"), upload("9", "2026-10-05T10:00:00Z"), upload("10", "2026-10-09T10:00:00Z", windows = false)), + "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", "")) + } + + @Test fun noAnswerOrNoWindowsBuildMeansNoUpdate() { + assertNull(ItchUpdates.evaluate(null, "7", "2026-09-01T10:00:00Z")) + assertNull(ItchUpdates.evaluate(JSONArray(), "7", "2026-09-01T10:00:00Z")) + } + + @Test fun anInstallWithoutAnUploadIdComparesTheNewestWindowsBuild() { + val update = ItchUpdates.evaluate(list(upload("8", "2026-10-01T10:00:00Z")), "", "2026-09-01T10:00:00Z")!! + assertEquals("8", update.uploadId) + assertFalse(update.replaced) + assertNull(ItchUpdates.evaluate(list(upload("8", "2026-08-01T10:00:00Z")), "", "2026-09-01T10:00:00Z")) + } + + @Test fun foundUpdatesSurviveTheCache() { + val found = mapOf("itch:a/b" to ItchUpdate("9", "2026-10-05T10:00:00Z", "b.zip", true)) + val back = ItchUpdates.decode(ItchUpdates.encode(found)) + assertEquals(setOf("itch:a/b"), back.keys) + assertEquals("9", back.getValue("itch:a/b").uploadId) + assertTrue(back.getValue("itch:a/b").replaced) + assertEquals(emptyMap(), ItchUpdates.decode(null)) + assertEquals(emptyMap(), ItchUpdates.decode("not json")) + } +} diff --git a/docs/development/itch-updates.md b/docs/development/itch-updates.md new file mode 100644 index 0000000000..13f7bdca7b --- /dev/null +++ b/docs/development/itch-updates.md @@ -0,0 +1,29 @@ +# itch.io updates + +An installed itch game is checked against the uploads itch lists for it. A game with an update shows an +Update label on its Library tile and an Update button on its game page. A Check for updates button sits +in the Library header while the itch chip is selected. + +## Detection + +The install record (`.droiddeck-store.json`) keeps three things from the install: the upload's +`updated_at` as `installVersion`, and `gameId`, `downloadKeyId` and `uploadId` in `extra`. +`ItchUpdates.evaluate` compares them with `GET /games//uploads`: + +- the installed upload is still listed and its `updated_at` is later: an update to the same upload; +- the installed upload is gone: the newest Windows upload is offered as a replaced build; +- an install without an `uploadId` compares the newest Windows upload's stamp; +- an unknown installed version or no answer from itch never reports an update. + +The check walks the installed itch games one at a time, one second apart, and logs +`itch.io: checked installed games, with updates`. It runs when the itch tab opens, at most every +six hours, and whenever the header button is pressed. A game itch did not answer for keeps its last +result, and the six-hour clock only advances after a fully answered pass. Results are kept in the itch +preferences until the update is installed or the account signs out. + +## Installing + +The Update button reruns the normal install over the game's own folder, keeping its storage location. +For a replaced build the game page asks first and names the new file. The installer marks the install +record as updating before it touches files, so a failure leaves a resumable record, and the finished +record carries the new `installVersion` and `uploadId`. From c90ad997b1e1d174d9ce78074a593c52f5e8808d Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:00:29 +0300 Subject: [PATCH 02/14] Unpack itch updates into a staging folder before touching the game --- .../launcher/stores/itch/ItchInstaller.kt | 53 +++++++++++++------ .../launcher/stores/itch/ItchStaging.kt | 23 ++++++++ .../launcher/stores/itch/ItchStagingTest.kt | 50 +++++++++++++++++ docs/development/itch-updates.md | 16 ++++-- 4 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt 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 0d7949daeb..94cab7a28e 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 @@ -33,6 +33,7 @@ internal class ItchInstaller( private val folder: File, ) : DownloadQueue.DownloadJob { private val cancelled = AtomicBoolean(false) + private var work: File = folder override fun run(handle: DownloadQueue.JobHandle): String? { val key = ItchAuth.key(app) @@ -58,7 +59,6 @@ internal class ItchInstaller( download(key, downloadKeyId, uploadId, upload.optString("updated_at", upload.optString("updatedAt")), archive, size, handle) if (cancelled.get()) return null handle.stage(DownloadStage.INSTALL) - if (StoreGameSidecar.read(folder)?.isInstalled == true) StoreInstalls.markUpdating(folder) install(archive, filename, handle, resuming) } catch (t: Throwable) { if (!cancelled.get()) StoreInstalls.discard(app, folder, listOf(scratch)) @@ -160,23 +160,42 @@ internal class ItchInstaller( } private fun install(archive: File, filename: String, handle: DownloadQueue.JobHandle, resuming: Boolean): String? { - folder.mkdirs() + val existing = StoreGameSidecar.read(folder) + val updating = existing != null && (existing.isInstalled || existing.state == StoreGameSidecar.STATE_UPDATING) + work = if (updating) File(folder, ItchStaging.DIR) else folder + if (updating) work.deleteRecursively() + work.mkdirs() if (resuming) clearPartialInstall() - when (val kind = sniff(archive, filename)) { - "zip" -> unzip(archive, handle) - "7z" -> sevenZip(archive, handle) - "rar" -> unrar(archive, handle) - "exe" -> copy(archive, File(folder, filename.ifBlank { "game.exe" })) - "tar" -> untar(archive, null, handle) - "gz", "bz2", "xz" -> untar(archive, kind, handle) ?: single(archive, kind, handle) - else -> copy(archive, File(folder, filename.ifBlank { "game" })) + val exe = try { + when (val kind = sniff(archive, filename)) { + "zip" -> unzip(archive, handle) + "7z" -> sevenZip(archive, handle) + "rar" -> unrar(archive, handle) + "exe" -> copy(archive, File(work, filename.ifBlank { "game.exe" })) + "tar" -> untar(archive, null, handle) + "gz", "bz2", "xz" -> untar(archive, kind, handle) ?: single(archive, kind, handle) + else -> copy(archive, File(work, filename.ifBlank { "game" })) + } + val hint = filename.substringBeforeLast('.') + StoreExe.pick(work, hint.ifBlank { null }, item.title) + } catch (t: Throwable) { + if (updating) work.deleteRecursively() + throw t } - val hint = filename.substringBeforeLast('.') - val exe = StoreExe.pick(folder, hint.ifBlank { null }, item.title) if (exe.isBlank()) { handle.log("itch.io: no exe found in ${folder.name}") + if (updating) work.deleteRecursively() return null } + if (updating) { + if (cancelled.get()) { + work.deleteRecursively() + return null + } + StoreInstalls.markUpdating(folder) + ItchStaging.merge(work, folder) + work.deleteRecursively() + } return exe } @@ -199,8 +218,8 @@ internal class ItchInstaller( } private fun target(name: String): File? { - val file = File(folder, name.replace('\\', '/')) - val root = folder.canonicalPath + val file = File(work, name.replace('\\', '/')) + val root = work.canonicalPath val path = file.canonicalPath return if (path == root || path.startsWith(root + File.separator)) file else null } @@ -208,8 +227,8 @@ internal class ItchInstaller( // No JVM library reads RAR5; the runtime's bsdtar (libarchive) does. private fun unrar(archive: File, handle: DownloadQueue.JobHandle) { if (!LinuxRuntime.isInstalled(app)) throw IllegalStateException(app.getString(R.string.stores_itch_archive, "rar")) - val binds = if (listOf(app.filesDir, app.cacheDir).any { folder.absolutePath.startsWith(it.absolutePath + "/") }) null - else listOf(folder.absolutePath) + val binds = if (listOf(app.filesDir, app.cacheDir).any { work.absolutePath.startsWith(it.absolutePath + "/") }) null + else listOf(work.absolutePath) fun bsdtar(args: List, onLine: (String) -> Unit) = GuestCommand.run(app, listOf("/usr/bin/bsdtar") + args, logName = "itch-unrar", extraBinds = binds, fastPath = true) { line -> if (!line.startsWith("proot ")) onLine(line) @@ -218,7 +237,7 @@ internal class ItchInstaller( bsdtar(listOf("-tf", archive.absolutePath)) { entries++ } var done = 0L val tail = ArrayDeque() - val code = bsdtar(listOf("-xvf", archive.absolutePath, "-C", folder.absolutePath)) { line -> + val code = bsdtar(listOf("-xvf", archive.absolutePath, "-C", work.absolutePath)) { line -> if (line.startsWith("x ")) handle.stageProgress(++done, entries) else { if (tail.size == 5) tail.removeFirst() tail.addLast(line) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt new file mode 100644 index 0000000000..27426650c0 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt @@ -0,0 +1,23 @@ +package com.droiddeck.launcher.stores.itch + +import java.io.File +import java.nio.file.Files + +internal object ItchStaging { + const val DIR = ".droiddeck-update" + + fun merge(from: File, to: File) { + for (child in from.listFiles().orEmpty()) { + val dest = File(to, child.name) + val destPath = dest.toPath() + if (child.isDirectory && dest.isDirectory && !Files.isSymbolicLink(destPath)) { + merge(child, dest) + continue + } + if (Files.isSymbolicLink(destPath) || dest.exists()) { + if (dest.isDirectory && !Files.isSymbolicLink(destPath)) dest.deleteRecursively() else dest.delete() + } + Files.move(child.toPath(), destPath) + } + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt new file mode 100644 index 0000000000..c6363ce663 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt @@ -0,0 +1,50 @@ +package com.droiddeck.launcher.stores.itch + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder +import java.io.File + +class ItchStagingTest { + @get:Rule val tmp = TemporaryFolder() + + private fun file(root: File, path: String, text: String) = File(root, path).also { it.parentFile?.mkdirs(); it.writeText(text) } + + @Test fun newFilesReplaceOldOnesAndEverythingElseStays() { + val game = tmp.newFolder("game") + val staged = tmp.newFolder("staged") + file(game, "game.exe", "old") + file(game, "data/level.dat", "old") + file(game, "saves/slot1.sav", "mine") + file(game, ".droiddeck-store.json", "record") + file(staged, "game.exe", "new") + file(staged, "data/level.dat", "new") + file(staged, "data/extra.dat", "new") + file(staged, "saves/default.sav", "new") + ItchStaging.merge(staged, game) + assertEquals("new", File(game, "game.exe").readText()) + assertEquals("new", File(game, "data/level.dat").readText()) + assertEquals("new", File(game, "data/extra.dat").readText()) + assertEquals("mine", File(game, "saves/slot1.sav").readText()) + assertEquals("new", File(game, "saves/default.sav").readText()) + assertEquals("record", File(game, ".droiddeck-store.json").readText()) + assertTrue(staged.listFiles().orEmpty().all { it.isDirectory && it.listFiles().orEmpty().isEmpty() }) + } + + @Test fun aFileReplacingADirectoryAndTheOtherWayRound() { + val game = tmp.newFolder("game") + val staged = tmp.newFolder("staged") + file(game, "a/inner.txt", "old") + file(game, "b", "old") + file(staged, "a", "new") + file(staged, "b/inner.txt", "new") + ItchStaging.merge(staged, game) + assertTrue(File(game, "a").isFile) + assertEquals("new", File(game, "a").readText()) + assertEquals("new", File(game, "b/inner.txt").readText()) + assertFalse(File(game, "a/inner.txt").exists()) + } +} diff --git a/docs/development/itch-updates.md b/docs/development/itch-updates.md index 13f7bdca7b..f2f4e49ce1 100644 --- a/docs/development/itch-updates.md +++ b/docs/development/itch-updates.md @@ -24,6 +24,16 @@ preferences until the update is installed or the account signs out. ## Installing The Update button reruns the normal install over the game's own folder, keeping its storage location. -For a replaced build the game page asks first and names the new file. The installer marks the install -record as updating before it touches files, so a failure leaves a resumable record, and the finished -record carries the new `installVersion` and `uploadId`. +For a replaced build the game page asks first and names the new file. + +An update never extracts into the live game. The download goes to the scratch folder, as for any +install, and the archive is unpacked into `.droiddeck-update` inside the game folder. The new build is +checked there (an executable must be found) before a single game file is touched. A failed or cancelled +download or extraction removes the staging folder and leaves the game as it was. + +Only then does `ItchStaging.merge` move the staged files into place, which are renames inside one +folder: a staged file replaces the file with the same path, directories are merged, and anything the new +build does not contain (saves, settings, the install record, launcher and art) stays. The install record +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. From 0a7397cd0e83f8fdafcfaf1e628f5916754e63b2 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:25:42 +0300 Subject: [PATCH 03/14] Fix the itch update cache reader for Kotlin 2.1 and keep symlinked staged entries out of the merge recursion --- .../java/com/droiddeck/launcher/stores/itch/ItchStaging.kt | 2 +- .../java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt index 27426650c0..b44201d8d2 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt @@ -10,7 +10,7 @@ internal object ItchStaging { for (child in from.listFiles().orEmpty()) { val dest = File(to, child.name) val destPath = dest.toPath() - if (child.isDirectory && dest.isDirectory && !Files.isSymbolicLink(destPath)) { + if (child.isDirectory && !Files.isSymbolicLink(child.toPath()) && dest.isDirectory && !Files.isSymbolicLink(destPath)) { merge(child, dest) continue } 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 f7656b017c..f35ab42183 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 @@ -57,7 +57,8 @@ internal object ItchUpdates { val out = LinkedHashMap() for (key in json.keys()) { val u = json.optJSONObject(key) ?: continue - val id = u.optString("uploadId").ifBlank { continue } + val id = u.optString("uploadId") + if (id.isBlank()) continue out[key] = ItchUpdate(id, u.optString("updatedAt"), u.optString("filename"), u.optBoolean("replaced")) } return out From e34db5adcbc3750f529cdbe7dabf991a4af03482 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:41:38 +0300 Subject: [PATCH 04/14] Count an itch install without a game id as unanswered in the update pass --- .../main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f35ab42183..e6c3a7eeab 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 @@ -100,7 +100,7 @@ internal object ItchUpdates { answered += game.key evaluate(uploads, extra["uploadId"].orEmpty(), game.sidecar.installVersion)?.let { found[game.key] = it } } - } + } else failed = true StoresState.post { done = i + 1 } } StoresState.post { From efaf5bf9b7dc3696ac011651b8551175b1604971 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:43:00 +0300 Subject: [PATCH 05/14] Make staging cleanup symlink-safe and drop update checks that outlive a sign-out --- .../launcher/stores/itch/ItchInstaller.kt | 10 ++++---- .../launcher/stores/itch/ItchStaging.kt | 7 +++++- .../launcher/stores/itch/ItchUpdates.kt | 13 ++++++++-- .../launcher/stores/itch/ItchStagingTest.kt | 24 +++++++++++++++++++ 4 files changed, 46 insertions(+), 8 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 94cab7a28e..daa0a8f757 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 @@ -163,7 +163,7 @@ internal class ItchInstaller( val existing = StoreGameSidecar.read(folder) val updating = existing != null && (existing.isInstalled || existing.state == StoreGameSidecar.STATE_UPDATING) work = if (updating) File(folder, ItchStaging.DIR) else folder - if (updating) work.deleteRecursively() + if (updating) ItchStaging.delete(work) work.mkdirs() if (resuming) clearPartialInstall() val exe = try { @@ -179,22 +179,22 @@ internal class ItchInstaller( val hint = filename.substringBeforeLast('.') StoreExe.pick(work, hint.ifBlank { null }, item.title) } catch (t: Throwable) { - if (updating) work.deleteRecursively() + if (updating) ItchStaging.delete(work) throw t } if (exe.isBlank()) { handle.log("itch.io: no exe found in ${folder.name}") - if (updating) work.deleteRecursively() + if (updating) ItchStaging.delete(work) return null } if (updating) { if (cancelled.get()) { - work.deleteRecursively() + ItchStaging.delete(work) return null } StoreInstalls.markUpdating(folder) ItchStaging.merge(work, folder) - work.deleteRecursively() + ItchStaging.delete(work) } return exe } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt index b44201d8d2..df7258cb74 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt @@ -15,9 +15,14 @@ internal object ItchStaging { continue } if (Files.isSymbolicLink(destPath) || dest.exists()) { - if (dest.isDirectory && !Files.isSymbolicLink(destPath)) dest.deleteRecursively() else dest.delete() + delete(dest) } Files.move(child.toPath(), destPath) } } + + fun delete(file: File) { + if (!Files.isSymbolicLink(file.toPath()) && file.isDirectory) file.listFiles().orEmpty().forEach { delete(it) } + file.delete() + } } 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 e6c3a7eeab..d255c790e4 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 @@ -34,6 +34,7 @@ internal object ItchUpdates { private val running = AtomicBoolean(false) private val restored = AtomicBoolean(false) + @Volatile private var generation = 0 internal fun evaluate(uploads: JSONArray?, uploadId: String, version: String): ItchUpdate? { if (uploads == null || version.isBlank()) return null @@ -66,8 +67,12 @@ internal object ItchUpdates { private fun restore(app: Context) { if (!restored.compareAndSet(false, true)) return + val started = generation val saved = decode(ItchPrefs.get(app).getString(KEY_FOUND, null)) - StoresState.post { for ((k, v) in saved) if (k !in available) available[k] = v } + StoresState.post { + if (started != generation) return@post + for ((k, v) in saved) if (k !in available) available[k] = v + } } private fun save(app: Context) { @@ -77,6 +82,7 @@ internal object ItchUpdates { fun check(context: Context, force: Boolean) { val app = context.applicationContext if (!running.compareAndSet(false, true)) return + val started = generation Thread({ try { restore(app) @@ -103,14 +109,16 @@ internal object ItchUpdates { } else failed = true StoresState.post { done = i + 1 } } + if (started != generation) return@Thread StoresState.post { + if (started != generation) return@post for (k in answered) { val u = found[k] if (u != null) available[k] = u else available.remove(k) } save(app) } - if (!failed) prefs.edit().putLong(KEY_AT, System.currentTimeMillis()).apply() + if (!failed && started == generation) prefs.edit().putLong(KEY_AT, System.currentTimeMillis()).apply() StoresState.logLine("itch.io: checked ${games.size} installed games, ${found.size} with updates") if (force) StoresState.post { val text = if (found.isNotEmpty()) app.getString(R.string.stores_itch_updates_found, found.size) else app.getString(R.string.upd_current_status) @@ -144,6 +152,7 @@ internal object ItchUpdates { fun clear(context: Context) { val app = context.applicationContext + generation++ ItchPrefs.get(app).edit().remove(KEY_AT).remove(KEY_FOUND).apply() StoresState.post { available.clear() } } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt index c6363ce663..918c62d8f7 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt @@ -47,4 +47,28 @@ class ItchStagingTest { assertEquals("new", File(game, "b/inner.txt").readText()) assertFalse(File(game, "a/inner.txt").exists()) } + + @Test fun deletingFollowsNoLinkOutOfTheTree() { + val outside = tmp.newFolder("outside") + file(outside, "keep.txt", "keep") + val staged = tmp.newFolder("staged") + file(staged, "own.txt", "x") + java.nio.file.Files.createSymbolicLink(File(staged, "link").toPath(), outside.toPath()) + ItchStaging.delete(staged) + assertFalse(staged.exists()) + assertEquals("keep", File(outside, "keep.txt").readText()) + } + + @Test fun aLinkInTheGameIsReplacedNotFollowed() { + val outside = tmp.newFolder("outside") + file(outside, "keep.txt", "keep") + val game = tmp.newFolder("game") + java.nio.file.Files.createSymbolicLink(File(game, "data").toPath(), outside.toPath()) + val staged = tmp.newFolder("staged") + file(staged, "data/level.dat", "new") + ItchStaging.merge(staged, game) + assertEquals("keep", File(outside, "keep.txt").readText()) + assertFalse(File(outside, "level.dat").exists()) + assertEquals("new", File(game, "data/level.dat").readText()) + } } From 2cce33d6f860efc5648a14b2ada3565678b3c02d Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:53:06 +0300 Subject: [PATCH 06/14] Keep the install record out of update merges and drop update results that went stale mid-check --- .../com/droiddeck/launcher/stores/itch/ItchStaging.kt | 6 ++++-- .../com/droiddeck/launcher/stores/itch/ItchUpdates.kt | 4 ++++ .../droiddeck/launcher/stores/itch/ItchStagingTest.kt | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt index df7258cb74..73e8f85961 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/itch/ItchStaging.kt @@ -5,13 +5,15 @@ import java.nio.file.Files internal object ItchStaging { const val DIR = ".droiddeck-update" + const val RECORD = ".droiddeck-store.json" - fun merge(from: File, to: File) { + fun merge(from: File, to: File, top: Boolean = true) { for (child in from.listFiles().orEmpty()) { + if (top && child.name == RECORD) continue val dest = File(to, child.name) val destPath = dest.toPath() if (child.isDirectory && !Files.isSymbolicLink(child.toPath()) && dest.isDirectory && !Files.isSymbolicLink(destPath)) { - merge(child, dest) + merge(child, dest, false) continue } if (Files.isSymbolicLink(destPath) || dest.exists()) { 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 d255c790e4..e178ed5a24 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 @@ -94,10 +94,12 @@ internal object ItchUpdates { StoresState.post { total = games.size; done = 0; checking = true } val found = LinkedHashMap() val answered = HashSet() + val snapshot = HashMap>() var failed = false games.forEachIndexed { i, game -> if (i > 0) Thread.sleep(GAP_MS) val extra = game.sidecar.extra + snapshot[game.key] = game.sidecar.installVersion to extra["uploadId"].orEmpty() val gameId = extra["gameId"].orEmpty() if (gameId.isNotEmpty()) { val uploads = ItchApi.uploads(key, gameId, extra["downloadKeyId"].orEmpty()) @@ -113,6 +115,8 @@ internal object ItchUpdates { StoresState.post { if (started != generation) return@post for (k in answered) { + val now = StoresState.installed.firstOrNull { it.key == k } ?: continue + if (snapshot[k] != now.sidecar.installVersion to now.sidecar.extra["uploadId"].orEmpty()) continue val u = found[k] if (u != null) available[k] = u else available.remove(k) } diff --git a/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt index 918c62d8f7..226ef3b9b0 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchStagingTest.kt @@ -71,4 +71,15 @@ class ItchStagingTest { assertFalse(File(outside, "level.dat").exists()) assertEquals("new", File(game, "data/level.dat").readText()) } + + @Test fun theInstallRecordIsNeverReplacedByTheArchive() { + val game = tmp.newFolder("game") + val staged = tmp.newFolder("staged") + file(game, ".droiddeck-store.json", "record") + file(staged, ".droiddeck-store.json", "forged") + file(staged, "sub/.droiddeck-store.json", "nested") + ItchStaging.merge(staged, game) + assertEquals("record", File(game, ".droiddeck-store.json").readText()) + assertEquals("nested", File(game, "sub/.droiddeck-store.json").readText()) + } } From e7907d0c7414e418a4ab87fcce470d7c23343b67 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Wed, 28 Oct 2026 01:08:33 +0300 Subject: [PATCH 07/14] Check itch updates per game from the game page instead of from the Library header --- .../launcher/stores/itch/ItchUpdates.kt | 53 +++++++++++++------ .../com/droiddeck/launcher/ui/GameDetail.kt | 9 +++- .../droiddeck/launcher/ui/ItchUpdateButton.kt | 10 ++++ .../com/droiddeck/launcher/ui/LibraryPage.kt | 16 +----- docs/development/itch-updates.md | 7 +-- 5 files changed, 61 insertions(+), 34 deletions(-) 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 e178ed5a24..a23195780c 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 @@ -3,7 +3,6 @@ package com.droiddeck.launcher.stores.itch import android.content.Context import android.widget.Toast import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue @@ -25,11 +24,7 @@ internal object ItchUpdates { private const val GAP_MS = 1_000L val available = mutableStateMapOf() - var checking by mutableStateOf(false) - private set - var done by mutableIntStateOf(0) - private set - var total by mutableIntStateOf(0) + var checkingKey by mutableStateOf(null) private set private val running = AtomicBoolean(false) @@ -79,7 +74,7 @@ internal object ItchUpdates { ItchPrefs.get(app).edit().putString(KEY_FOUND, encode(available.toMap())).apply() } - fun check(context: Context, force: Boolean) { + fun check(context: Context) { val app = context.applicationContext if (!running.compareAndSet(false, true)) return val started = generation @@ -87,11 +82,10 @@ internal object ItchUpdates { try { restore(app) val prefs = ItchPrefs.get(app) - if (!force && System.currentTimeMillis() - prefs.getLong(KEY_AT, 0L) < THROTTLE_MS) return@Thread + if (System.currentTimeMillis() - prefs.getLong(KEY_AT, 0L) < THROTTLE_MS) return@Thread val key = ItchAuth.key(app) if (key.isBlank()) return@Thread val games = StoresState.installed.toList().filter { it.sidecar.store == Store.ITCH && it.sidecar.isInstalled } - StoresState.post { total = games.size; done = 0; checking = true } val found = LinkedHashMap() val answered = HashSet() val snapshot = HashMap>() @@ -109,7 +103,6 @@ internal object ItchUpdates { evaluate(uploads, extra["uploadId"].orEmpty(), game.sidecar.installVersion)?.let { found[game.key] = it } } } else failed = true - StoresState.post { done = i + 1 } } if (started != generation) return@Thread StoresState.post { @@ -124,17 +117,47 @@ internal object ItchUpdates { } if (!failed && started == generation) prefs.edit().putLong(KEY_AT, System.currentTimeMillis()).apply() StoresState.logLine("itch.io: checked ${games.size} installed games, ${found.size} with updates") - if (force) StoresState.post { - val text = if (found.isNotEmpty()) app.getString(R.string.stores_itch_updates_found, found.size) else app.getString(R.string.upd_current_status) - Toast.makeText(app, text, Toast.LENGTH_SHORT).show() - } } finally { running.set(false) - StoresState.post { checking = false } } }, "itch-updates").start() } + fun checkGame(context: Context, game: InstalledStoreGame) { + val app = context.applicationContext + if (checkingKey != null) return + checkingKey = game.key + val started = generation + val version = game.sidecar.installVersion + val uploadId = game.sidecar.extra["uploadId"].orEmpty() + Thread({ + try { + val key = ItchAuth.key(app) + val extra = game.sidecar.extra + val gameId = extra["gameId"].orEmpty() + val uploads = if (key.isBlank() || gameId.isEmpty()) null else ItchApi.uploads(key, gameId, extra["downloadKeyId"].orEmpty()) + val found = evaluate(uploads, uploadId, version) + StoresState.post { + if (started != generation) return@post + val now = StoresState.installed.firstOrNull { it.key == game.key } + if (uploads != null && now != null && now.sidecar.installVersion == version && now.sidecar.extra["uploadId"].orEmpty() == uploadId) { + if (found != null) available[game.key] = found else available.remove(game.key) + save(app) + } + val text = when { + uploads == null -> app.getString(R.string.stores_sync_failed) + found != null -> app.getString(R.string.stores_itch_updates_found, 1) + else -> app.getString(R.string.upd_current_status) + } + Toast.makeText(app, text, Toast.LENGTH_SHORT).show() + } + StoresState.logLine("itch.io: checked ${game.sidecar.title}, ${if (found != null) "update available" else "up to date"}") + } finally { + StoresState.post { checkingKey = null } + } + }, "itch-update-check").start() + } + fun start(context: Context, game: InstalledStoreGame, update: ItchUpdate) { val app = context.applicationContext val root = game.folder.parentFile?.parentFile ?: return diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt index e46a15b239..8cd08db1a4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt @@ -205,7 +205,12 @@ internal fun GameDetail( GameHero( title, item, installed, game, Modifier.fillMaxWidth().heightIn(min = if (narrow) 170.dp else 210.dp).onGloballyPositioned { StoresMotion.heroAt = it.boundsInRoot() }, - corner = { if (!s.shortcutPicker) RemoveButton(title, game, installed, a) }, + corner = { + if (!s.shortcutPicker) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + if (installed != null && installed.sidecar.store == Store.ITCH) ItchCheckButton(installed) + RemoveButton(title, game, installed, a) + } + }, scores = scores.takeIf { !stacked }, ) { HeroEyebrow(source, game, item, installed, download?.location ?: failed?.location) @@ -530,7 +535,7 @@ private fun EditArtButton(g: Library.SteamGame) { } @Composable -private fun IconAction(icon: androidx.compose.ui.graphics.vector.ImageVector, label: String, id: String, danger: Boolean = false, enabled: Boolean = true, onClick: () -> Unit) { +internal fun IconAction(icon: androidx.compose.ui.graphics.vector.ImageVector, label: String, id: String, danger: Boolean = false, enabled: Boolean = true, onClick: () -> Unit) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val src = remember { MutableInteractionSource() } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt b/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt index 37151db81a..2e254a5b9d 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ItchUpdateButton.kt @@ -2,6 +2,8 @@ package com.droiddeck.launcher.ui import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Refresh import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -18,6 +20,14 @@ import com.droiddeck.launcher.stores.InstalledStoreGame import com.droiddeck.launcher.stores.itch.ItchUpdate import com.droiddeck.launcher.stores.itch.ItchUpdates +@Composable +internal fun ItchCheckButton(installed: InstalledStoreGame) { + val ctx = LocalContext.current + IconAction(Icons.Filled.Refresh, stringResource(R.string.store_check_updates), "game:check-updates", enabled = ItchUpdates.checkingKey == null) { + ItchUpdates.checkGame(ctx, installed) + } +} + @Composable internal fun ItchUpdateButton(installed: InstalledStoreGame, enabled: Boolean) { val ctx = LocalContext.current diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt index 1353e38228..a180e25113 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt @@ -38,7 +38,6 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.FilterAlt import androidx.compose.material.icons.filled.GridView import androidx.compose.material.icons.filled.PlayArrow -import androidx.compose.material.icons.filled.Refresh import androidx.compose.material.icons.filled.Sort import androidx.compose.material.icons.filled.ViewList import androidx.compose.material.icons.filled.ViewModule @@ -198,7 +197,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, val xboxFilter = if (source == Store.XBOX.id) XboxLibraryFilter.current else XboxLibraryFilter.ALL LaunchedEffect(source, itchSignedIn) { if (source == Store.ITCH.id && itchSignedIn) { ItchCollections.load(ctx) - ItchUpdates.check(ctx, false) + ItchUpdates.check(ctx) } } val collection = if (source == Store.ITCH.id) ItchCollections.chosen() else null val pool = if (collection == null) all else collectionEntries(all, ItchCollections.gamesOf(collection.id).orEmpty()) @@ -473,10 +472,7 @@ private fun LibraryHeader( }, ) { if (showUninstalled != null || xbox) LibraryFilterButton(showUninstalled, onShowUninstalled, xbox) - if (collections) { - CollectionsButton() - UpdatesButton() - } + if (collections) CollectionsButton() SortButton(s, a) ViewButton(s, a) GameFileFolderActions(s, a) @@ -731,14 +727,6 @@ private fun LibraryFilterButton(showUninstalled: Boolean?, onShowUninstalled: (B } } -@Composable -private fun UpdatesButton() { - val ctx = LocalContext.current - val title = stringResource(R.string.store_check_updates) - val description = if (ItchUpdates.checking) title + " · " + ItchUpdates.done + "/" + ItchUpdates.total else title - HeaderIconButton(description, Icons.Filled.Refresh, "itch-updates") { ItchUpdates.check(ctx, true) } -} - @Composable private fun CollectionsButton() { val pal = LocalPalette.current diff --git a/docs/development/itch-updates.md b/docs/development/itch-updates.md index f2f4e49ce1..a9dfabaea1 100644 --- a/docs/development/itch-updates.md +++ b/docs/development/itch-updates.md @@ -2,7 +2,7 @@ An installed itch game is checked against the uploads itch lists for it. A game with an update shows an Update label on its Library tile and an Update button on its game page. A Check for updates button sits -in the Library header while the itch chip is selected. +in the top right of an installed itch game's page, next to the delete button, and checks that game only. ## Detection @@ -15,9 +15,10 @@ The install record (`.droiddeck-store.json`) keeps three things from the install - an install without an `uploadId` compares the newest Windows upload's stamp; - an unknown installed version or no answer from itch never reports an update. -The check walks the installed itch games one at a time, one second apart, and logs +The automatic check walks the installed itch games one at a time, one second apart, and logs `itch.io: checked installed games, with updates`. It runs when the itch tab opens, at most every -six hours, and whenever the header button is pressed. A game itch did not answer for keeps its last +six hours. The button on a game page checks only that game, at any time, answers with a toast ("Update +available", "Up to date" or "Sync failed") and logs `itch.io: checked , ...`. A game itch did not answer for keeps its last result, and the six-hour clock only advances after a fully answered pass. Results are kept in the itch preferences until the update is installed or the account signs out. From 29e8b2f679a58c3e9df4e5cd6aaa421da3619bbc Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Wed, 28 Oct 2026 01:10:47 +0300 Subject: [PATCH 08/14] Never delete the install record while replacing it and clean the staging folder if marking fails --- .../java/com/droiddeck/launcher/stores/StoreGameSidecar.kt | 2 +- .../java/com/droiddeck/launcher/stores/StoreInstalls.kt | 7 ++++++- .../com/droiddeck/launcher/stores/itch/ItchInstaller.kt | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt index aa42aa75e8..e4d828372f 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt @@ -63,7 +63,7 @@ class StoreGameSidecar( val file = File(folder, FILE_NAME) val tmp = File(folder, "$FILE_NAME.tmp") tmp.writeText(toJson().toString(2)) - if (!tmp.renameTo(file)) { file.delete(); tmp.renameTo(file) } + if (!tmp.renameTo(file)) java.nio.file.Files.move(tmp.toPath(), file.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } companion object { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt index 9b73f8cc87..2f4df83f20 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt @@ -30,7 +30,12 @@ object StoreInstalls { it.write(before.copy(state = StoreGameSidecar.STATE_UPDATING, installVersion = "").toJson().toString(2).toByteArray(Charsets.UTF_8)) it.fd.sync() } - Files.move(stage.toPath(), StoreGameSidecar.file(folder).toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING) + val record = StoreGameSidecar.file(folder).toPath() + try { + Files.move(stage.toPath(), record, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING) + } catch (e: java.nio.file.AtomicMoveNotSupportedException) { + Files.move(stage.toPath(), record, StandardCopyOption.REPLACE_EXISTING) + } } finally { stage.delete() } 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 daa0a8f757..5da0f7708c 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 @@ -192,7 +192,12 @@ internal class ItchInstaller( ItchStaging.delete(work) return null } - StoreInstalls.markUpdating(folder) + try { + StoreInstalls.markUpdating(folder) + } catch (t: Throwable) { + ItchStaging.delete(work) + throw t + } ItchStaging.merge(work, folder) ItchStaging.delete(work) } From bcec13ab632441c56691856a929b9d65613543a3 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Wed, 28 Oct 2026 01:14:18 +0300 Subject: [PATCH 09/14] Keep an updating itch game's folder out of every failed-download cleanup --- .../launcher/stores/itch/ItchInstaller.kt | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 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 5da0f7708c..95632c346c 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 @@ -34,6 +34,7 @@ internal class ItchInstaller( ) : DownloadQueue.DownloadJob { private val cancelled = AtomicBoolean(false) private var work: File = folder + private var updating = false override fun run(handle: DownloadQueue.JobHandle): String? { val key = ItchAuth.key(app) @@ -41,7 +42,9 @@ internal class ItchInstaller( val downloadKeyId = item.extra["downloadKeyId"].orEmpty() if (downloadKeyId.isBlank() && !item.isFree) throw IllegalStateException(app.getString(R.string.stores_itch_not_owned)) val gameId = ItchGame.resolveId(item) ?: throw IllegalStateException(app.getString(R.string.stores_itch_no_game)) - val resuming = StoreGameSidecar.read(folder)?.let { it.state == StoreGameSidecar.STATE_INSTALLING && it.id == item.id } == true + val before = StoreGameSidecar.read(folder) + updating = before != null && (before.isInstalled || before.state == StoreGameSidecar.STATE_UPDATING) + val resuming = before?.let { it.state == StoreGameSidecar.STATE_INSTALLING && it.id == item.id } == true StoreInstalls.begin(folder, Store.ITCH, item.id, item.title, item.imageUrl, item.imageUrl) handle.stage(DownloadStage.MANIFEST) val uploads = ItchApi.uploads(key, gameId, downloadKeyId) @@ -61,12 +64,12 @@ internal class ItchInstaller( handle.stage(DownloadStage.INSTALL) install(archive, filename, handle, resuming) } catch (t: Throwable) { - if (!cancelled.get()) StoreInstalls.discard(app, folder, listOf(scratch)) + if (!cancelled.get()) dropCaches(scratch) throw t } if (exe == null) { if (cancelled.get()) return null - StoreInstalls.discard(app, folder, listOf(scratch)) + dropCaches(scratch) throw IllegalStateException(app.getString(R.string.stores_itch_no_exe)) } archive.delete() @@ -90,7 +93,16 @@ internal class ItchInstaller( override fun cancel(deleteFiles: Boolean) { cancelled.set(true) - if (deleteFiles) StoreInstalls.discard(app, folder, listOf(StoreInstallRoot.scratchDir(app, Store.ITCH, item.id))) + if (deleteFiles) dropCaches(StoreInstallRoot.scratchDir(app, Store.ITCH, item.id)) + } + + private fun dropCaches(scratch: File) { + if (!updating) { + StoreInstalls.discard(app, folder, listOf(scratch)) + return + } + StoreInstalls.deleteTree(scratch) + ItchStaging.delete(File(folder, ItchStaging.DIR)) } private fun download(key: String, downloadKeyId: String, uploadId: String, version: String, target: File, expected: Long, @@ -160,8 +172,6 @@ internal class ItchInstaller( } private fun install(archive: File, filename: String, handle: DownloadQueue.JobHandle, resuming: Boolean): String? { - val existing = StoreGameSidecar.read(folder) - val updating = existing != null && (existing.isInstalled || existing.state == StoreGameSidecar.STATE_UPDATING) work = if (updating) File(folder, ItchStaging.DIR) else folder if (updating) ItchStaging.delete(work) work.mkdirs() From f371149e1f47366fd2f887ab80aa17a32a1c1af3 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Wed, 28 Oct 2026 01:29:46 +0300 Subject: [PATCH 10/14] Keep launch options across itch updates and stop cancellation from racing the file merge --- .../droiddeck/launcher/stores/itch/ItchInstaller.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 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 95632c346c..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 @@ -35,6 +35,8 @@ internal class ItchInstaller( private val cancelled = AtomicBoolean(false) private var work: File = folder private var updating = false + private var previous: StoreGameSidecar? = null + private val commit = Any() override fun run(handle: DownloadQueue.JobHandle): String? { val key = ItchAuth.key(app) @@ -43,6 +45,7 @@ internal class ItchInstaller( if (downloadKeyId.isBlank() && !item.isFree) throw IllegalStateException(app.getString(R.string.stores_itch_not_owned)) val gameId = ItchGame.resolveId(item) ?: throw IllegalStateException(app.getString(R.string.stores_itch_no_game)) val before = StoreGameSidecar.read(folder) + previous = before updating = before != null && (before.isInstalled || before.state == StoreGameSidecar.STATE_UPDATING) val resuming = before?.let { it.state == StoreGameSidecar.STATE_INSTALLING && it.id == item.id } == true StoreInstalls.begin(folder, Store.ITCH, item.id, item.title, item.imageUrl, item.imageUrl) @@ -79,6 +82,8 @@ internal class ItchInstaller( id = item.id, title = item.title, exe = exe, + args = previous?.args.orEmpty(), + env = previous?.env.orEmpty(), installVersion = upload.optString("updated_at", upload.optString("updatedAt")), installedAt = System.currentTimeMillis(), cover = item.imageUrl, @@ -101,8 +106,10 @@ internal class ItchInstaller( StoreInstalls.discard(app, folder, listOf(scratch)) return } - StoreInstalls.deleteTree(scratch) - ItchStaging.delete(File(folder, ItchStaging.DIR)) + synchronized(commit) { + StoreInstalls.deleteTree(scratch) + ItchStaging.delete(File(folder, ItchStaging.DIR)) + } } private fun download(key: String, downloadKeyId: String, uploadId: String, version: String, target: File, expected: Long, @@ -197,7 +204,7 @@ internal class ItchInstaller( if (updating) ItchStaging.delete(work) return null } - if (updating) { + if (updating) synchronized(commit) { if (cancelled.get()) { ItchStaging.delete(work) return null From ab130c775444baf86b6139d5e89c87553c326410 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Wed, 28 Oct 2026 01:55:02 +0300 Subject: [PATCH 11/14] Forget a pending itch update when its game is uninstalled --- app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt index 0cea0681ed..686cfd13ba 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt @@ -285,6 +285,7 @@ object StoresState { main.post { installed = installed.filterNot { it.folder.absolutePath == game.folder.absolutePath } uninstalling.remove(key) + if (game.sidecar.store == Store.ITCH) com.droiddeck.launcher.stores.itch.ItchUpdates.applied(app, key) } }) main.post(onDone) From 0e173ed05a70d5f5dbbd9a3bbd828d589432ff51 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Wed, 28 Oct 2026 02:13:48 +0300 Subject: [PATCH 12/14] Block itch updates while the game is being uninstalled --- .../main/java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt | 1 + app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 a23195780c..44d9887046 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 @@ -160,6 +160,7 @@ internal object ItchUpdates { fun start(context: Context, game: InstalledStoreGame, update: ItchUpdate) { val app = context.applicationContext + if (StoresState.uninstalling.containsKey(game.key)) return val root = game.folder.parentFile?.parentFile ?: return val extra = game.sidecar.extra + ("uploadId" to update.uploadId) val item = CatalogItem( diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt index 8cd08db1a4..df84306106 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GameDetail.kt @@ -362,7 +362,7 @@ internal fun GameActions( GameShortcutMenu(game, a) EditArtButton(game) } - if (store == Store.ITCH && installed != null) ItchUpdateButton(installed, download == null) + if (store == Store.ITCH && installed != null) ItchUpdateButton(installed, download == null && StoresState.uninstalling[installed.key] == null) if (store == Store.XBOX && id != null) XboxInstalledStream(id, game?.name ?: item?.title.orEmpty(), item) if (store == Store.XBOX && installed != null && id != null) { SecondaryButton(stringResource(R.string.stores_xbox_update), enabled = download == null && !XboxRuntime.isActive(id)) { From 9b44bf798dfa27afa56ba84a3fa4f0aeef4b6e23 Mon Sep 17 00:00:00 2001 From: FX192 <120828496+FX192@users.noreply.github.com> Date: Wed, 28 Oct 2026 08:47:50 +0300 Subject: [PATCH 13/14] Offer only Windows builds as a replaced itch upload and stop a cancelled update from completing --- .../com/droiddeck/launcher/stores/itch/ItchInstaller.kt | 1 + .../java/com/droiddeck/launcher/stores/itch/ItchUpdates.kt | 2 +- .../com/droiddeck/launcher/stores/itch/ItchUpdatesTest.kt | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) 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 f084e503d6..83dbd4752c 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,6 +216,7 @@ 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 44d9887046..30bcbb324e 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) ?: return null + val next = ItchUploads.windows(uploads)?.takeIf { ItchUploads.windows(it) } ?: 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/test/java/com/droiddeck/launcher/stores/itch/ItchUpdatesTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/itch/ItchUpdatesTest.kt index 8c263173d0..d8f969a8a0 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 @@ -41,6 +41,12 @@ class ItchUpdatesTest { assertTrue(update.replaced) } + @Test fun aReplacedUploadWithNoWindowsBuildLeftIsNotOffered() { + val linux = list(upload("8", "2026-10-01T10:00:00Z", windows = false)) + assertNull(ItchUpdates.evaluate(linux, "7", "2026-09-01T10:00:00Z")) + assertNull(ItchUpdates.evaluate(linux, "", "2026-09-01T10:00:00Z")) + } + @Test fun anUnknownInstalledVersionNeverReportsAnUpdate() { assertNull(ItchUpdates.evaluate(list(upload("7", "2026-10-20T10:00:00Z")), "7", "")) } 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 14/14] 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.