From b6903db58cda9a280d133f160678f44c77da99f6 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Thu, 8 Oct 2026 19:52:28 -0400 Subject: [PATCH] Stores: an install that stops is an unfinished install, not a Custom game A half-installed Epic game on the card (files up to a 0-byte one, 9.1 GB of .chunks, no sidecar) showed in Games as a Custom folder: the sidecar was only written at the very end, the queue's row lives in memory, and the scan took any sidecar-less folder under a store root for a hand-added game. The sidecar is now written when an install starts, in state installing, and rewritten finished at its end; a finished install being repaired keeps its record. Folders still installing, or with no sidecar, are never scanned as games; the Stores card and page offer Resume install, which reuses the folder (and an Epic .chunks beside it) instead of a fresh one. Writing the launcher or the finished record fails the download with its message; the art and the Steam side stay best-effort. The Epic cache holds whole chunk windows shared with files this device does not install, so it outgrows the game; the free-space check now runs after the delta pass and counts the missing chunks and files on their own volumes. The Install-to dialog is a 440 dp card with two tiles that are the action, one line of caption and Cancel in the title row; the cog popup is capped at the same width. --- .../droiddeck/launcher/frontend/AddedGames.kt | 3 +- .../launcher/stores/StoreGameSidecar.kt | 25 ++++++-- .../launcher/stores/StoreInstallRoot.kt | 42 +++++++++++--- .../launcher/stores/StoreInstalls.kt | 26 +++++++-- .../droiddeck/launcher/stores/StoresState.kt | 14 ++++- .../launcher/stores/amazon/AmazonBackend.kt | 1 + .../launcher/stores/epic/EpicBackend.kt | 9 ++- .../stores/epic/EpicDownloadManager.java | 19 +++++- .../launcher/stores/gog/GogBackend.kt | 1 + .../com/droiddeck/launcher/ui/AddAppDialog.kt | 5 +- .../com/droiddeck/launcher/ui/StoresDetail.kt | 1 + .../droiddeck/launcher/ui/StoresDownloads.kt | 2 +- .../launcher/ui/StoresInstallDialog.kt | 58 ++++++++++++------- .../com/droiddeck/launcher/ui/StoresPage.kt | 1 + app/src/main/res/values/strings.xml | 4 +- .../launcher/stores/StoreGameSidecarTest.kt | 12 ++++ .../launcher/stores/StoreInstallRootTest.kt | 18 ++++++ docs/development/stores.md | 13 +++++ docs/progress-log.md | 16 +++++ 19 files changed, 220 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt index a000d2ec87..bc4386a477 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/AddedGames.kt @@ -122,7 +122,8 @@ object AddedGames { } } // Games the Stores section installed: one folder each under //, with a sidecar. - for (folder in StoreInstallRoot.gameFolders(context)) scanGame(context, folder, out) + // An unfinished one (sidecar still `installing`, or none at all) is neither a game nor Custom. + for (folder in StoreInstallRoot.gameFolders(context)) if (StoreInstallRoot.isFinished(folder)) scanGame(context, folder, out) return out.distinctBy { it.folder.canonicalPath } } 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 a7602ac566..56fe350225 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreGameSidecar.kt @@ -17,6 +17,11 @@ import java.io.File * * Paths are relative to the game folder with forward slashes, so the folder can move between * storage volumes and stay valid. + * + * An install writes the sidecar twice: at its start with [state] `installing` (store, id, title - + * no exe yet), and at its end with the exe, the launcher and `installed`. A folder whose sidecar + * still says `installing` is an unfinished install, never a game: the scan leaves it out and the + * Stores page offers to resume it. A sidecar without the field (an earlier build) is installed. */ class StoreGameSidecar( val store: Store, @@ -32,7 +37,10 @@ class StoreGameSidecar( val hero: String? = null, /** Per-store identifiers the launcher needs again (Epic namespace / catalog id, Amazon entitlement). */ val extra: Map = emptyMap(), + val state: String = STATE_INSTALLED, ) { + val isInstalled: Boolean get() = state == STATE_INSTALLED + fun exeFile(folder: File): File = File(folder, exe) fun launcherFile(folder: File): File? = launcher?.takeIf { it.isNotEmpty() }?.let { File(folder, it) } @@ -40,15 +48,16 @@ class StoreGameSidecar( exe: String = this.exe, launcher: String? = this.launcher, args: List = this.args, env: Map = this.env, installVersion: String = this.installVersion, installedAt: Long = this.installedAt, cover: String? = this.cover, hero: String? = this.hero, - extra: Map = this.extra, - ) = StoreGameSidecar(store, id, title, exe, launcher, args, env, installVersion, installedAt, cover, hero, extra) + extra: Map = this.extra, state: String = this.state, + ) = StoreGameSidecar(store, id, title, exe, launcher, args, env, installVersion, installedAt, cover, hero, extra, state) fun toJson(): JSONObject = JSONObject().apply { put("version", VERSION) put("store", store.id) put("id", id) put("title", title) - put("exe", exe) + if (exe.isNotEmpty()) put("exe", exe) + if (state != STATE_INSTALLED) put("state", state) if (!launcher.isNullOrEmpty()) put("launcher", launcher) if (args.isNotEmpty()) put("args", JSONArray(args)) if (env.isNotEmpty()) put("env", JSONObject(env as Map<*, *>)) @@ -70,6 +79,8 @@ class StoreGameSidecar( companion object { const val FILE_NAME = ".droiddeck-store.json" const val VERSION = 1 + const val STATE_INSTALLED = "installed" + const val STATE_INSTALLING = "installing" fun file(folder: File): File = File(folder, FILE_NAME) @@ -87,9 +98,12 @@ class StoreGameSidecar( val id = o.optString("id", "") val title = o.optString("title", "") val exe = o.optString("exe", "").replace('\\', '/') - if (id.isEmpty() || title.isEmpty() || exe.isEmpty()) return null + val state = o.optString("state", STATE_INSTALLED).ifEmpty { STATE_INSTALLED } + if (id.isEmpty() || title.isEmpty()) return null + // An unfinished install has no exe yet; a finished one must name one. + if (exe.isEmpty() && state == STATE_INSTALLED) return null // A relative path only: a sidecar that points outside its folder is not trusted. - if (!relativeInside(exe)) return null + if (exe.isNotEmpty() && !relativeInside(exe)) return null val launcher = o.optString("launcher", "").replace('\\', '/').takeIf { it.isNotEmpty() && relativeInside(it) } val args = o.optJSONArray("args")?.let { a -> List(a.length()) { a.optString(it) }.filter { it.isNotEmpty() } } ?: emptyList() val env = LinkedHashMap() @@ -103,6 +117,7 @@ class StoreGameSidecar( cover = o.optString("cover", "").ifEmpty { null }, hero = o.optString("hero", "").ifEmpty { null }, extra = extra, + state = state, ) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt index 31a57029a6..468f924198 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstallRoot.kt @@ -101,18 +101,44 @@ object StoreInstallRoot { } /** - * The folder a game installs into under [root]; a folder with this game's sidecar anywhere wins - * over a fresh name, so a repair or an update lands on the existing install. + * The folder a game installs into under [root]. An existing folder wins over a fresh one, so a + * repair, an update or a resume lands on what is already there: one with this game's sidecar + * anywhere, else one under any root with this game's folder name and no finished sidecar (an + * install an earlier build left without one, or that stopped before writing it). */ - fun folderFor(context: Context, store: Store, id: String, title: String, root: File = installRoot(context)): File { - for (r in roots(context)) { - val dir = storeDir(r, store) - dir.listFiles { f -> f.isDirectory }?.forEach { folder -> + fun folderFor(context: Context, store: Store, id: String, title: String, root: File = installRoot(context)): File = + existingFolder(context, store, id, title) ?: File(storeDir(root, store), folderName(title, id)) + + /** The folder an earlier install of this game left, finished or not; null when there is none. */ + fun existingFolder(context: Context, store: Store, id: String, title: String): File? { + val all = roots(context).flatMap { r -> storeDir(r, store).listFiles { f -> f.isDirectory }?.toList().orEmpty() } + all.firstOrNull { folder -> StoreGameSidecar.read(folder)?.let { it.store == store && it.id == id } == true }?.let { return it } + val name = folderName(title, id) + return all.firstOrNull { it.name == name && StoreGameSidecar.read(it)?.isInstalled != true } + } + + /** An unfinished install: [id] from its `installing` sidecar, null when it has none (matched by folder name then). */ + class Unfinished(val store: Store, val id: String?, val folder: File) + + /** + * A folder under a store root is a game only once its sidecar says installed. Without one it is + * an install that never finished (stopped, killed, or from a build that wrote the sidecar last): + * not a Custom game, and not listed in Steam. + */ + fun isFinished(folder: File): Boolean = StoreGameSidecar.read(folder)?.isInstalled == true + + /** Every unfinished install under every root, for the Stores page's "Resume install". */ + fun unfinished(context: Context): List = roots(context).flatMap { root -> + Store.entries.flatMap { store -> + storeDir(root, store).listFiles { f -> f.isDirectory }.orEmpty().mapNotNull { folder -> val sidecar = StoreGameSidecar.read(folder) - if (sidecar != null && sidecar.store == store && sidecar.id == id) return folder + when { + sidecar == null -> Unfinished(store, null, folder) + !sidecar.isInstalled -> Unfinished(store, sidecar.id, folder) + else -> null + } } } - return File(storeDir(root, store), folderName(title, id)) } /** A scratch folder in the app's cache for an install's in-flight pieces, when the install itself is on a card. */ 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 6c436a4ee8..40e312c7c5 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreInstalls.kt @@ -22,14 +22,30 @@ object StoreInstalls { private const val TAG = "StoreInstalls" /** - * Finishes an install: writes the sidecar (and the launcher), then registers the game. Runs on - * the caller's worker thread. + * Marks [folder] as an install under way before anything is fetched: a sidecar in state + * `installing` with the store, id and title. Whatever stops the install from here on - a + * failure, a cancel, the process killed - leaves a folder the scan skips and the Stores page + * offers to resume, never a half-written Custom game. A finished install being repaired or + * updated keeps its finished sidecar, so the game stays in Steam meanwhile. + */ + fun begin(folder: File, store: Store, id: String, title: String, cover: String?, hero: String?) { + if (StoreGameSidecar.read(folder)?.isInstalled == true) return + StoreGameSidecar(store, id, title, exe = "", cover = cover, hero = hero, state = StoreGameSidecar.STATE_INSTALLING).write(folder) + } + + /** + * Finishes an install: writes the launcher and the finished sidecar, then the art, then + * registers the game. Runs on the caller's worker thread. The launcher and sidecar writes + * throw, so a failure there fails the download with its message; the art and the Steam side + * are best-effort and only logged. */ fun complete(context: Context, folder: File, sidecar: StoreGameSidecar) { val app = context.applicationContext - StoreLaunch.writeLauncher(folder, sidecar).write(folder) - // The art first, so the listing written below already carries it for the client's grid. - StoreArt.fetchInto(folder, sidecar) + val finished = StoreLaunch.writeLauncher(folder, sidecar.copy(state = StoreGameSidecar.STATE_INSTALLED)) + finished.write(folder) + if (StoreGameSidecar.read(folder)?.isInstalled != true) throw java.io.IOException("the install record could not be written in ${folder.name}") + // The art before the listing, so the listing already carries it for the client's grid. + try { StoreArt.fetchInto(folder, finished) } catch (e: Exception) { Log.w(TAG, "art for ${folder.name}: ${e.message}") } register(app) } 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 1372a8d316..28cc05024f 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt @@ -74,13 +74,15 @@ object StoresState { Thread({ val found = Store.entries.mapNotNull { store -> StoreAccounts.signedInAs(app, store)?.let { store to it } } val onDisk = StoreInstallRoot.gameFolders(app).mapNotNull { folder -> - StoreGameSidecar.read(folder)?.let { InstalledStoreGame(it, folder) } + StoreGameSidecar.read(folder)?.takeIf { it.isInstalled }?.let { InstalledStoreGame(it, folder) } } + val partial = StoreInstallRoot.unfinished(app) val version = if (StoresNative.available) StoresNative.version ?: "" else "" main.post { accounts.clear() found.forEach { (store, name) -> accounts[store] = name } installed = onDisk + unfinished = partial engine = version } }, "stores-refresh").start() @@ -88,6 +90,14 @@ object StoresState { fun isSignedIn(store: Store): Boolean = accounts.containsKey(store) + /** Installs that stopped before they finished; their Install button reads "Resume install". */ + var unfinished by mutableStateOf>(emptyList()) + internal set + + fun isUnfinished(item: CatalogItem): Boolean = unfinished.any { + it.store == item.store && (it.id == item.id || (it.id == null && it.folder.name == StoreInstallRoot.folderName(item.title, item.id))) + } + fun installedGame(store: Store, id: String): InstalledStoreGame? = installed.firstOrNull { it.sidecar.store == store && it.sidecar.id == id } /** The user's library and the shelves for [store], from the cache first and the network when stale. */ @@ -124,6 +134,8 @@ object StoresState { * storage at once. */ fun requestInstall(context: Context, item: CatalogItem) { + // A resume goes where the files already are; there is nothing to choose. + if (isUnfinished(item)) { install(context, item); return } val targets = StoreInstallRoot.targets(context) if (targets.size > 1) pendingInstall = item else install(context, item, targets.first().root) } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonBackend.kt b/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonBackend.kt index 18d679461a..d4c404060e 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonBackend.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/amazon/AmazonBackend.kt @@ -93,6 +93,7 @@ object AmazonBackend : StoreBackend { override fun run(handle: DownloadQueue.JobHandle): String? { handle.stage(DownloadStage.MANIFEST, "Checking sign-in…") val token = AmazonCredentialStore.getValidAccessToken(app) ?: throw AmazonDownloadManager.InstallException("Not signed in to Amazon Games") + StoreInstalls.begin(folder, Store.AMAZON, game.productId, game.title, item.tallImageUrl ?: item.imageUrl, item.imageUrl) var downloading = false val result = AmazonDownloadManager.install(app, game, token, folder, cancelled, object : AmazonDownloadManager.Callback { override fun onProgress(message: String, pct: Int) { diff --git a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicBackend.kt b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicBackend.kt index 16c7dcf035..01d631eb35 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicBackend.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicBackend.kt @@ -101,12 +101,17 @@ object EpicBackend : StoreBackend, EpicLaunchSupport { private val cancelled = AtomicBoolean(false) // On a card the in-flight chunks go to the app's cache instead: the card's write rate paces // the whole install, and chunks are read back once at assembly. Internal installs keep the - // cache beside the game, as the engine's contract has it today. - private val scratch: File? = if (StoreInstallRoot.isRemovable(app, folder)) StoreInstallRoot.scratchDir(app, Store.EPIC, item.id) else null + // cache beside the game. A resume keeps whichever cache the stopped run filled: a + // `.chunks` already beside the game is reused, not fetched again into the scratch folder. + private val scratch: File? = if (StoreInstallRoot.isRemovable(app, folder) && !hasChunks(File(folder, ".chunks"))) StoreInstallRoot.scratchDir(app, Store.EPIC, item.id) else null + + private fun hasChunks(dir: File): Boolean = dir.isDirectory && (dir.list()?.isNotEmpty() == true) override fun run(handle: DownloadQueue.JobHandle): String? { handle.stage(DownloadStage.MANIFEST, "Checking sign-in…") val token = EpicCredentialStore.getValidAccessToken(app) ?: throw EpicDownloadManager.InstallException("Not signed in to Epic Games") + StoreInstalls.begin(folder, Store.EPIC, item.id, item.title, item.tallImageUrl ?: item.imageUrl, item.imageUrl) + if (scratch == null && hasChunks(File(folder, ".chunks"))) handle.log("epic: resuming \"${item.title}\" with the chunks already beside it") val manifestJson = EpicApiClient.getManifestApiJson(token, namespace, catalogItemId, item.id) ?: throw EpicDownloadManager.InstallException("The manifest could not be fetched") val tags = EpicInstallTags.tagsForDevice() diff --git a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicDownloadManager.java b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicDownloadManager.java index 4f219425bf..0c9d373b80 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicDownloadManager.java +++ b/app/src/main/java/com/droiddeck/launcher/stores/epic/EpicDownloadManager.java @@ -149,8 +149,7 @@ public final class EpicDownloadManager { long installBytes = 0; for (FileInfo f : selected) installBytes += f.fileSize(); final long planned = installBytes; - long usable = installDir.getUsableSpace(); - if (planned > 0 && usable > 0 && planned > usable) throw new InstallException("Not enough free space: need " + fmt(planned) + ", only " + fmt(usable) + " free"); + // Free space is checked after the delta pass, against what is still missing (below). cb.onProgress("Verifying existing files…", 0); List pending = new ArrayList<>(selected.size()); @@ -169,6 +168,22 @@ public final class EpicDownloadManager { return new Result(manifest.launchExe, manifest.buildVersion, planned); } List needed = uniqueChunksForFiles(manifest, pending); + // The cache holds whole chunk windows (~1 MiB each), and a window is shared with files + // this device does not install (other tags, other builds' data): the cache is often + // larger than the game itself (Metalstorm: 9.1 GB of chunks for 4.4 GB of files). Both + // have to fit at once until assembly, so the check counts both, on their own volumes. + long cacheMissing = 0, pendingBytes = 0; + for (ChunkInfo c : needed) if (!new File(chunkCacheDir, c.guidStr()).isFile()) cacheMissing += Math.max(c.windowSize, 1); + for (FileInfo f : pending) pendingBytes += f.fileSize(); + if (cachePath.isEmpty()) { + long free = installDir.getUsableSpace(); + if (free > 0 && cacheMissing + pendingBytes > free) throw new InstallException("Not enough free space: need " + fmt(cacheMissing + pendingBytes) + " (" + fmt(pendingBytes) + " of game files + " + fmt(cacheMissing) + " of download cache), only " + fmt(free) + " free"); + } else { + long freeCache = chunkCacheDir.getUsableSpace(), freeGame = installDir.getUsableSpace(); + if (freeCache > 0 && cacheMissing > freeCache) throw new InstallException("Not enough internal space for the download cache: need " + fmt(cacheMissing) + ", only " + fmt(freeCache) + " free"); + if (freeGame > 0 && pendingBytes > freeGame) throw new InstallException("Not enough free space: need " + fmt(pendingBytes) + ", only " + fmt(freeGame) + " free"); + } + cb.onLog("epic: cache " + (cachePath.isEmpty() ? "beside the game" : "scratch") + ", " + fmt(cacheMissing) + " to fetch for " + fmt(pendingBytes) + " of files"); long totalBytes = 0; for (ChunkInfo c : needed) totalBytes += Math.max(c.fileSize, 1); final long fTotalBytes = totalBytes; diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogBackend.kt b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogBackend.kt index 4745226022..a7bc48ae00 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogBackend.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogBackend.kt @@ -81,6 +81,7 @@ object GogBackend : StoreBackend { override fun run(handle: DownloadQueue.JobHandle): String? { handle.stage(DownloadStage.MANIFEST) + StoreInstalls.begin(folder, Store.GOG, game.gameId, game.title, item.tallImageUrl ?: item.imageUrl, item.imageUrl) var downloading = false val result = GogDownloadManager.install(app, game, folder, object : GogDownloadManager.Callback { override fun onProgress(message: String, pct: Int) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AddAppDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/AddAppDialog.kt index b18aa114ef..07237e0deb 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AddAppDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AddAppDialog.kt @@ -83,6 +83,7 @@ import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.sp import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties @@ -312,7 +313,7 @@ internal fun rememberShown(onDismiss: () -> Unit): MutableTransitionState, close: () -> Unit, label: String, wide: Boolean, - modifier: Modifier = Modifier, content: @Composable ColumnScope.() -> Unit, + modifier: Modifier = Modifier, maxWidth: Dp? = null, content: @Composable ColumnScope.() -> Unit, ) { val pal = LocalPalette.current // The page's ring stays out of sight behind it. @@ -335,7 +336,7 @@ internal fun AppDialog( verticalArrangement = Arrangement.spacedBy(14.dp), modifier = Modifier .padding(12.dp) - .widthIn(max = if (wide) 860.dp else 560.dp) + .widthIn(max = maxWidth ?: if (wide) 860.dp else 560.dp) .fillMaxWidth() .heightIn(max = (LocalConfiguration.current.screenHeightDp - 24).dp) .shadow(24.dp, Shape16, ambientColor = Color.Black, spotColor = Color.Black) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresDetail.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresDetail.kt index 95aef70af4..de37996003 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoresDetail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresDetail.kt @@ -93,6 +93,7 @@ internal fun StoreGameDetail(store: Store, key: String, s: FrontEndState, a: Fro else PrimaryButton(stringResource(R.string.stores_dl_resume), main = true) { com.droiddeck.launcher.stores.download.DownloadQueue.resume(ctx, download.key) } SecondaryButton(stringResource(R.string.stores_dl_cancel)) { com.droiddeck.launcher.stores.download.DownloadQueue.cancel(ctx, download.key) } } + item?.owned == true && StoresState.isUnfinished(item) -> PrimaryButton(stringResource(R.string.stores_resume_install), main = true) { StoresState.requestInstall(ctx, item) } item?.owned == true -> PrimaryButton( if (item.sizeBytes > 0) stringResource(R.string.stores_install_size, formatBytes(item.sizeBytes)) else stringResource(R.string.stores_install), main = true, ) { StoresState.requestInstall(ctx, item) } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt index 7ec1941108..d1fd5d8a4b 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt @@ -228,7 +228,7 @@ internal fun DownloadControls(s: FrontEndState, a: FrontEndActions) { internal fun StoresSettingsDialog(s: FrontEndState, a: FrontEndActions, onDismiss: () -> Unit) { val shown = rememberShown(onDismiss) val close = { shown.targetState = false } - AppDialog(shown, close, "storesSettings", wide = false) { + AppDialog(shown, close, "storesSettings", wide = false, maxWidth = 440.dp) { DialogHeader(stringResource(R.string.stores_settings_eyebrow), stringResource(R.string.stores_title)) Rise(1) { Column { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresInstallDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresInstallDialog.kt index 9ffda1e732..140a59c6d2 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoresInstallDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresInstallDialog.kt @@ -6,11 +6,12 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.hoverable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.SdCard import androidx.compose.material.icons.outlined.Smartphone @@ -29,6 +30,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.Role import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.droiddeck.launcher.R @@ -39,13 +41,14 @@ import com.droiddeck.launcher.stores.StoresState import com.droiddeck.launcher.stores.formatBytes /** - * "Install to": internal storage or a card, each with its free space, asked only when a card is - * there. The row picked last time starts focused, so a pad confirms the usual place with one press; - * nothing is chosen for the user. + * "Install to": a small card with one tile per place - internal storage, the card - each the + * action itself, with its free space. Asked only when a card is there. The tile picked last time + * starts focused, so a pad confirms the usual place with one press; nothing is chosen for the user. */ @Composable internal fun InstallWhereDialog(item: CatalogItem, onDismiss: () -> Unit) { val ctx = LocalContext.current + val colors = MaterialTheme.colorScheme val shown = rememberShown(onDismiss) val close = { shown.targetState = false } val targets = remember { StoreInstallRoot.targets(ctx) } @@ -53,47 +56,58 @@ internal fun InstallWhereDialog(item: CatalogItem, onDismiss: () -> Unit) { val defaultIndex = targets.indexOfFirst { it.root.absolutePath == remembered }.coerceAtLeast(0) val focus = remember { List(targets.size) { FocusRequester() } } LaunchedEffect(Unit) { focusWithinFrames({ false }) { focus[defaultIndex] } } - AppDialog(shown, close, "installWhere", wide = false) { - DialogHeader(item.title, stringResource(R.string.stores_install_where)) + AppDialog(shown, close, "installWhere", wide = false, maxWidth = 440.dp) { + Rise(0) { + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { + Column(Modifier.weight(1f)) { + Eyebrow(stringResource(R.string.stores_install_where)) + Text(item.title, fontSize = 18.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) + } + Text( + stringResource(R.string.common_cancel), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = colors.onSurfaceVariant, + modifier = Modifier.clip(Shape12).clickable(role = Role.Button, onClick = close).padding(horizontal = 10.dp, vertical = 6.dp), + ) + } + } Rise(1) { - Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { + Row(horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth()) { targets.forEachIndexed { i, t -> - TargetRow( - label = t.label, free = stringResource(R.string.stores_target_free, formatBytes(t.freeBytes)), - removable = t.removable, focus = focus[i], + TargetTile( + label = if (t.removable) t.label else stringResource(R.string.stores_target_internal), + free = stringResource(R.string.stores_target_free, formatBytes(t.freeBytes)), + removable = t.removable, focus = focus[i], modifier = Modifier.weight(1f), ) { SessionPrefs.setStoresInstallTarget(ctx, t.root.absolutePath) StoresState.install(ctx, item, t.root) close() } } - Text(stringResource(R.string.stores_install_where_note), fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant) } } - Rise(2) { Actions { SecondaryButton(stringResource(R.string.common_cancel), onClick = close) } } + Text(stringResource(R.string.stores_install_where_note), fontSize = 12.sp, color = colors.onSurfaceVariant) } } @Composable -private fun TargetRow(label: String, free: String, removable: Boolean, focus: FocusRequester, onPick: () -> Unit) { +private fun TargetTile(label: String, free: String, removable: Boolean, focus: FocusRequester, modifier: Modifier, onPick: () -> Unit) { val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val src = remember { MutableInteractionSource() } val hot = rememberHot(src) - Row( - verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(14.dp), - modifier = Modifier.fillMaxWidth().heightIn(min = 56.dp).focusRequester(focus).clip(Shape12) + Box( + modifier.focusRequester(focus).clip(Shape12) .background(if (hot) pal.signal.copy(alpha = 0.14f) else colors.surface.copy(alpha = 0.6f)) .glideBorder(hot, Shape12, pal.signal, pal.line) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onPick) .controllerConfirm(onClick = onPick) - .padding(horizontal = 14.dp, vertical = 10.dp), + .padding(horizontal = 12.dp, vertical = 12.dp), ) { - Icon(if (removable) Icons.Outlined.SdCard else Icons.Outlined.Smartphone, null, tint = if (hot) pal.signal else colors.onBackground) - Column(Modifier.weight(1f)) { - Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1) - Text(free, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1) + Column(verticalArrangement = Arrangement.spacedBy(6.dp)) { + Icon(if (removable) Icons.Outlined.SdCard else Icons.Outlined.Smartphone, null, tint = if (hot) pal.signal else colors.onBackground, modifier = Modifier.size(22.dp)) + Column { + Text(label, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) + Text(free, fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1) + } } - Text(stringResource(R.string.stores_install), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = pal.signal) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt index cebbb69b80..b0d61149e1 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresPage.kt @@ -461,6 +461,7 @@ private fun GameCard(item: CatalogItem, store: Store, s: FrontEndState, a: Front ProgressBarThin(download.fraction, paused = download.state == DownloadState.PAUSED, verify = download.stage == DownloadStage.VERIFY) CardButton(downloadLabel(download.state, download.stage, download.percent), primary = false) { } } + item.owned && StoresState.isUnfinished(item) -> CardButton(stringResource(R.string.stores_resume_install), primary = true) { StoresState.requestInstall(ctx, item) } item.owned -> CardButton(if (item.sizeBytes > 0) stringResource(R.string.stores_install_size, formatBytes(item.sizeBytes)) else stringResource(R.string.stores_install), primary = true) { StoresState.requestInstall(ctx, item) } item.isFree -> CardButton(stringResource(R.string.stores_get_free), primary = true) { openStoreUrl(ctx, item) } else -> CardButton(stringResource(R.string.stores_view_on, store.shortLabel), primary = false) { openStoreUrl(ctx, item) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c7c3042ab7..bef0ecc41c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2018,6 +2018,7 @@ Owned on %1$s Play Install + Resume install Install · %1$s Get for free View on %1$s @@ -2075,7 +2076,8 @@ Caps how many chunks the engine fetches at once: Balanced 16 · Fast 32 · Max 96 in flight. Downloads at a time Install to - Internal storage is the default; a card streams more slowly. Your pick is remembered as the first choice next time. + A card installs more slowly. + Internal %1$s free Balanced / Fast / Max pull harder from the store; 2–3 at a time share the link. Speed shown is the install rate. One manager for all three stores; Steam\'s own downloads are unaffected. diff --git a/app/src/test/java/com/droiddeck/launcher/stores/StoreGameSidecarTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/StoreGameSidecarTest.kt index a3836dc941..c2c2ef8d61 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/StoreGameSidecarTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/StoreGameSidecarTest.kt @@ -41,6 +41,18 @@ class StoreGameSidecarTest { assertEquals("bin/game.exe", back.exe) assertNull(back.launcher) assertTrue(back.args.isEmpty()) + // No state field = an earlier build's finished install. + assertTrue(back.isInstalled) + } + + @Test fun anInstallUnderWayHasNoExeYetAndIsNotInstalled() { + val started = StoreGameSidecar(Store.EPIC, "Metalstorm", "Metalstorm", exe = "", state = StoreGameSidecar.STATE_INSTALLING) + val back = StoreGameSidecar.parse(started.toJson().toString())!! + assertFalse(back.isInstalled) + assertEquals("", back.exe) + // A finished one must still name its exe. + assertNull(StoreGameSidecar.parse("""{"store":"gog","id":"1","title":"T","exe":""}""")) + assertTrue(StoreGameSidecar.parse(back.copy(exe = "Metalstorm.exe", state = StoreGameSidecar.STATE_INSTALLED).toJson().toString())!!.isInstalled) } @Test fun refusesWhatIsNotASidecar() { diff --git a/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt b/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt index 9a98da7a85..3856ed562d 100644 --- a/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/stores/StoreInstallRootTest.kt @@ -36,6 +36,24 @@ class StoreInstallRootTest { assertEquals(File(StoreInstallRoot.storeDir(other, Store.GOG), "Fresh").absolutePath, StoreInstallRoot.folderFor(app, Store.GOG, "7", "Fresh", other).absolutePath) } + @Test fun aFolderLeftWithoutASidecarIsAnUnfinishedInstallAndIsResumedInPlace() { + SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "") + val epic = StoreInstallRoot.storeDir(StoreInstallRoot.internalRoot(app), Store.EPIC) + val half = File(epic, StoreInstallRoot.folderName("Metalstorm", "abc")).apply { mkdirs() } + File(half, ".chunks").mkdirs() + File(half, "Metalstorm.exe").writeText("MZ") + assertFalse(StoreInstallRoot.isFinished(half)) + assertTrue(StoreInstallRoot.unfinished(app).any { it.store == Store.EPIC && it.id == null && it.folder.absolutePath == half.absolutePath }) + // Install again, even with another root picked: the same folder, no duplicate. + assertEquals(half.absolutePath, StoreInstallRoot.folderFor(app, Store.EPIC, "abc", "Metalstorm", File(app.filesDir, "card/Games")).absolutePath) + // Begun and finished: the folder becomes a game. + StoreInstalls.begin(half, Store.EPIC, "abc", "Metalstorm", null, null) + assertTrue(StoreInstallRoot.unfinished(app).any { it.id == "abc" }) + StoreGameSidecar(Store.EPIC, "abc", "Metalstorm", "Metalstorm.exe").write(half) + assertTrue(StoreInstallRoot.isFinished(half)) + assertTrue(StoreInstallRoot.unfinished(app).none { it.folder.absolutePath == half.absolutePath }) + } + @Test fun theScratchCacheIsPrivateAndNamedSafely() { val dir = StoreInstallRoot.scratchDir(app, Store.EPIC, "a/b:c") assertTrue(dir.absolutePath.startsWith(app.cacheDir.absolutePath)) diff --git a/docs/development/stores.md b/docs/development/stores.md index 4617042d21..045192ead2 100644 --- a/docs/development/stores.md +++ b/docs/development/stores.md @@ -29,6 +29,10 @@ An Epic install on a card keeps its in-flight chunks in `cacheDir/stores/epic/