mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
fix(steam): store review fixes: session interlock, account identity, safer cancel and uninstall
- A Steam download or uninstall holds every session that can run Steam, including a restored activity and a queued launch, which now waits instead of being dropped; the engine is not signed out under a running download. - The store account is the SteamID64; only real logon refusals clear it. - Cancel deletes only a game folder this download created; uninstall removes the copy in the row's library and reports a failed fallback delete. - Plans are cached per language; install scans cannot overwrite newer ones. - Reordering tabs from the Library keeps the Steam store's place; games the Steam client hides stay hidden in the Library.
This commit is contained in:
1 parent
3d8ba67913
commit
39362cdb4d
11 files changed
+123
-42
No files matched your search
@@ -1259,6 +1259,10 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
|
||||
private fun startAfterSession(next: Intent) {
|
||||
if (com.droiddeck.launcher.stores.steam.SteamStore.blocksSession(next)) {
|
||||
android.widget.Toast.makeText(this, R.string.steam_store_session_wait, android.widget.Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
SessionService.stop(this)
|
||||
awaitSessionEnd(next, android.os.SystemClock.uptimeMillis() + SESSION_SWITCH_WAIT_MS)
|
||||
}
|
||||
@@ -3097,7 +3101,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
}
|
||||
val target = com.droiddeck.launcher.frontend.GameRemoval.steamFiles(g) ?: return
|
||||
if (Library.fromSteamClient(g)) {
|
||||
com.droiddeck.launcher.stores.steam.SteamStore.uninstall(this, g.appId, fallback = { com.droiddeck.launcher.frontend.GameRemoval.delete(target) }) { refreshAddedGames(); refresh() }
|
||||
com.droiddeck.launcher.stores.steam.SteamStore.uninstall(this, g.appId, target.manifest, fallback = { com.droiddeck.launcher.frontend.GameRemoval.delete(target) }) { refreshAddedGames(); refresh() }
|
||||
return
|
||||
}
|
||||
Thread({
|
||||
@@ -3541,9 +3545,10 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
retryMs = GATE_LAUNCH_RETRY_MS,
|
||||
)
|
||||
|
||||
/** The conditions under which a Steam start waits instead of being refused: setup, a runtime or desktop install, or a storage cleanup. */
|
||||
/** The conditions under which a Steam start waits instead of being refused: setup, a runtime or desktop install, a storage cleanup, or a Steam store download. */
|
||||
private fun steamStartBusy(): Boolean = busy || LinuxRuntimeInstaller.isBusy() || com.droiddeck.launcher.session.Onboarding.settling() ||
|
||||
(SessionState.installing != null && !SessionState.running) || com.droiddeck.launcher.storage.StorageState.cleaning
|
||||
(SessionState.installing != null && !SessionState.running) || com.droiddeck.launcher.storage.StorageState.cleaning ||
|
||||
(!SessionState.running && com.droiddeck.launcher.stores.steam.SteamStore.downloading())
|
||||
|
||||
private fun refreshPhantomStatus() {
|
||||
phantomProcessStatus = PhantomProcessLimit.read(this)
|
||||
|
||||
@@ -842,13 +842,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
finish()
|
||||
return
|
||||
}
|
||||
if (savedInstanceState == null && !SessionState.running && com.droiddeck.launcher.stores.steam.SteamStore.blocksSession(intent)) {
|
||||
if (!SessionState.running && com.droiddeck.launcher.stores.steam.SteamStore.blocksSession(intent)) {
|
||||
runtimeRemovalBlocked = true
|
||||
android.widget.Toast.makeText(this, R.string.steam_store_session_wait, android.widget.Toast.LENGTH_SHORT).show()
|
||||
finish()
|
||||
return
|
||||
}
|
||||
if (savedInstanceState == null && !SessionState.running) {
|
||||
if (savedInstanceState == null && !SessionState.running && !com.droiddeck.launcher.stores.steam.SteamStore.downloading()) {
|
||||
// The Steam client signs in itself; the store's own sign-in must not overlap it.
|
||||
Thread({ com.droiddeck.launcher.stores.steam.SteamEngine.forget() }, "steam-store-signout").start()
|
||||
}
|
||||
|
||||
@@ -35,6 +35,15 @@ internal object SteamClient {
|
||||
|
||||
private fun aliases(arch: String) = listOf(guestRoot(arch), "${guestHome(arch)}/.steam/steam", "${guestHome(arch)}/.steam/root")
|
||||
|
||||
/** [guest] names [library]; the main library also answers to the client's other spellings of its root. */
|
||||
fun sameLibrary(context: Context, library: SteamLibraryFolders.Library, guest: String): Boolean {
|
||||
if (library.guest == guest) return true
|
||||
if (!library.main) return false
|
||||
val arch = activeArch(context)
|
||||
val wanted = SteamLibraryFolders.normalize(guest) ?: return false
|
||||
return (aliases(arch) + guestRoot(arch)).mapNotNull(SteamLibraryFolders::normalize).contains(wanted)
|
||||
}
|
||||
|
||||
fun root(context: Context, arch: String = activeArch(context)): File = SessionPrefs.steamRoot(context, arch)
|
||||
|
||||
fun registry(context: Context, arch: String = activeArch(context)): File =
|
||||
|
||||
@@ -20,6 +20,9 @@ internal object SteamEngine {
|
||||
|
||||
private val lock = Any()
|
||||
@Volatile private var signedIn = false
|
||||
/** The saved login the last sign-in attempt read, so a refusal rejects that login and not one saved since. */
|
||||
@Volatile var attempted: String? = null
|
||||
private set
|
||||
private var failed: JSONObject? = null
|
||||
private var failedAt = 0L
|
||||
|
||||
@@ -47,6 +50,7 @@ internal object SteamEngine {
|
||||
.put(SessionPrefs.steamRoot(context, "arm64").absolutePath)
|
||||
.put(SessionPrefs.steamRoot(context, SteamClient.X86_64).absolutePath)
|
||||
val registry = SteamClient.registry(context).absolutePath
|
||||
attempted = SteamStore.fingerprint(context)
|
||||
val answer = call("signIn") { SteamNative.nativeSignIn(roots.toString(), registry, "") }
|
||||
signedIn = answer.optBoolean("ok")
|
||||
failed = if (signedIn) null else answer
|
||||
|
||||
@@ -28,13 +28,14 @@ internal class SteamInstallJob(
|
||||
@Volatile private var discard = false
|
||||
@Volatile private var installDir: String? = null
|
||||
@Volatile private var libraryHost: File? = null
|
||||
@Volatile private var createdDir = false
|
||||
|
||||
override fun run(handle: DownloadQueue.JobHandle): String? {
|
||||
started.set(true)
|
||||
try {
|
||||
return install(handle)
|
||||
} finally {
|
||||
if (discard) SteamStore.discardPartial(app, appId, libraryGuest, libraryHost, installDir)
|
||||
if (discard) SteamStore.discardPartial(app, appId, libraryGuest, libraryHost, installDir, createdDir)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +43,7 @@ internal class SteamInstallJob(
|
||||
handle.stage(DownloadStage.MANIFEST)
|
||||
if (SteamClient.clientMayRun()) throw IllegalStateException(app.getString(R.string.steam_store_close_steam))
|
||||
val engine = SteamClient.engineLibraries(app)
|
||||
val target = engine.libraries.firstOrNull { it.first.guest == libraryGuest }
|
||||
val target = engine.libraries.firstOrNull { SteamClient.sameLibrary(app, it.first, libraryGuest) }
|
||||
?: throw IllegalStateException(app.getString(R.string.game_sync_err_steam_library))
|
||||
libraryHost = target.second
|
||||
val signIn = SteamEngine.signIn(app)
|
||||
@@ -54,6 +55,7 @@ internal class SteamInstallJob(
|
||||
val (plan, planned) = SteamStore.plan(app, appId, language)
|
||||
if (plan == null) throw IllegalStateException(SteamStore.errorText(app, planned))
|
||||
installDir = plan.installDir
|
||||
createdDir = !File(target.second, "steamapps/common/${plan.installDir}").exists() || SteamStore.resuming(app, appId)
|
||||
if (plan.installBytes > 0) handle.diskSize(plan.installBytes)
|
||||
if (cancelled.get()) return null
|
||||
|
||||
@@ -92,7 +94,7 @@ internal class SteamInstallJob(
|
||||
}
|
||||
val native = try {
|
||||
SteamNative.nativeStart(
|
||||
appId, language, SteamClient.root(app).absolutePath, target.second.absolutePath, libraryGuest, engine.json,
|
||||
appId, language, SteamClient.root(app).absolutePath, target.second.absolutePath, target.first.guest, engine.json,
|
||||
journal.absolutePath, "", tier.networkWindow.coerceIn(1, 128), tier.processWorkers, listener,
|
||||
)
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
@@ -136,7 +138,7 @@ internal class SteamInstallJob(
|
||||
cancelled.set(true)
|
||||
if (!deleteFiles) return
|
||||
discard = true
|
||||
if (!started.get()) SteamStore.discardPartial(app, appId, libraryGuest, null, null)
|
||||
if (!started.get()) SteamStore.discardPartial(app, appId, libraryGuest, null, null, SteamStore.resuming(app, appId))
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
@@ -89,7 +89,8 @@ internal object SteamLibraryFolders {
|
||||
val mains = (aliases + mainGuest).mapNotNull(::normalize).toSet()
|
||||
val listed = if (folders.any { normalize(it.path) in mains }) folders else listOf(Folder(mainGuest, "")) + folders
|
||||
val out = ArrayList<Library>()
|
||||
for (f in listed) {
|
||||
// The main library first, so an entry reaching the same folder under another path cannot take its place.
|
||||
for (f in listed.sortedByDescending { normalize(it.path) in mains }) {
|
||||
val guest = normalize(f.path) ?: continue
|
||||
val main = guest in mains
|
||||
val host = if (main) mainHost else hostFor(guest, mounts, rootfs) ?: continue
|
||||
@@ -117,17 +118,22 @@ internal object SteamLibraryFolders {
|
||||
return out
|
||||
}
|
||||
|
||||
/** The account the client signs in with by itself: remembered, the most recent one first. */
|
||||
fun savedAccount(loginUsers: String): String? {
|
||||
data class SavedAccount(val id: String, val name: String)
|
||||
|
||||
fun savedAccount(loginUsers: String): String? = savedLogin(loginUsers)?.name
|
||||
|
||||
/** The account the client signs in with by itself: remembered, the most recent one first. [SavedAccount.id] is its SteamID64. */
|
||||
fun savedLogin(loginUsers: String): SavedAccount? {
|
||||
val users = LinkedHashMap<String, HashMap<String, String>>()
|
||||
walk(loginUsers, pair = { blocks, key, value ->
|
||||
if (blocks.size == 2 && blocks[0].equals("users", ignoreCase = true)) users.getOrPut(blocks[1]) { HashMap() }[key.lowercase()] = value
|
||||
})
|
||||
val remembered = users.values.filter { it["rememberpassword"] == "1" }
|
||||
val user = remembered.firstOrNull { it["mostrecent"] == "1" }
|
||||
?: remembered.maxByOrNull { it["timestamp"]?.toLongOrNull() ?: 0L }
|
||||
val remembered = users.entries.filter { it.value["rememberpassword"] == "1" }
|
||||
val (id, user) = remembered.firstOrNull { it.value["mostrecent"] == "1" }
|
||||
?: remembered.maxByOrNull { it.value["timestamp"]?.toLongOrNull() ?: 0L }
|
||||
?: return null
|
||||
return user["personaname"]?.takeIf { it.isNotBlank() } ?: user["accountname"]?.takeIf { it.isNotBlank() }
|
||||
val name = user["personaname"]?.takeIf { it.isNotBlank() } ?: user["accountname"]?.takeIf { it.isNotBlank() } ?: return null
|
||||
return SavedAccount(id, name)
|
||||
}
|
||||
|
||||
fun language(registry: String): String? {
|
||||
|
||||
@@ -43,6 +43,9 @@ internal object SteamStore {
|
||||
private const val LIBRARY = "library"
|
||||
private const val LIBRARY_LABEL = "libraryLabel"
|
||||
private val SIGNED_OUT = setOf("no_saved_login", "remember_me_off", "decrypt_failed")
|
||||
private val REFUSED = Regex("logon_failed: eresult=(-?\\d+).*")
|
||||
/** InvalidPassword, AccessDenied, AccountNotFound, Revoked, Expired, AccountLogonDenied. */
|
||||
private val REFUSALS = setOf(5, 15, 18, 26, 27, 63)
|
||||
|
||||
var installed by mutableStateOf<Map<Int, SteamLibraryFolders.Installed>>(emptyMap())
|
||||
private set
|
||||
@@ -61,7 +64,8 @@ internal object SteamStore {
|
||||
|
||||
internal const val LINUX_BUILD = "linux_build"
|
||||
|
||||
private val plans = ConcurrentHashMap<Int, Plan>()
|
||||
/** Each plan with the language it was made for. */
|
||||
private val plans = ConcurrentHashMap<Int, Pair<String, Plan>>()
|
||||
private val work = Executors.newSingleThreadExecutor { r -> Thread(r, "steam-store") }
|
||||
@Volatile private var rejectedThisRun: String? = null
|
||||
|
||||
@@ -76,7 +80,9 @@ internal object SteamStore {
|
||||
StoresState.post { Toast.makeText(app, text, Toast.LENGTH_LONG).show() }
|
||||
}
|
||||
|
||||
internal fun isSignInError(error: String) = error in SIGNED_OUT || error.startsWith("logon_failed")
|
||||
/** Steam refusing the saved login; a connection failure or a throttled logon leaves the account as it is. */
|
||||
internal fun isSignInError(error: String) =
|
||||
error in SIGNED_OUT || REFUSED.matchEntire(error)?.groupValues?.get(1)?.toIntOrNull() in REFUSALS
|
||||
|
||||
internal fun errorText(context: Context, answer: JSONObject): String {
|
||||
val error = answer.optString("error")
|
||||
@@ -89,36 +95,46 @@ internal object SteamStore {
|
||||
}
|
||||
}
|
||||
|
||||
private fun fingerprint(context: Context): String {
|
||||
internal fun fingerprint(context: Context): String {
|
||||
val users = SteamClient.loginUsers(context)
|
||||
val registry = SteamClient.registry(context)
|
||||
return "${SteamClient.activeArch(context)}:${users.lastModified()}:${users.length()}:${registry.lastModified()}:${registry.length()}"
|
||||
}
|
||||
|
||||
private fun savedAccount(context: Context): String? {
|
||||
private fun savedAccount(context: Context): SteamLibraryFolders.SavedAccount? {
|
||||
val print = fingerprint(context)
|
||||
if (print == rejectedThisRun || print == prefs(context).getString("rejected", null)) return null
|
||||
return runCatching { SteamLibraryFolders.savedAccount(SteamClient.loginUsers(context).readText()) }.getOrNull()
|
||||
return runCatching { SteamLibraryFolders.savedLogin(SteamClient.loginUsers(context).readText()) }.getOrNull()
|
||||
}
|
||||
|
||||
/** Mirrors the client's saved sign-in into the store account; reads storage. */
|
||||
/** Mirrors the client's saved sign-in into the store account; reads storage. A new name for the same account only relabels it. */
|
||||
fun syncAccount(context: Context): Boolean {
|
||||
val name = savedAccount(context)
|
||||
if (name == StoreAccounts.signedInAs(context, Store.STEAM)) return false
|
||||
if (name == null) StoreAccounts.clear(context, Store.STEAM)
|
||||
else StoreAccounts.write(context, Store.STEAM, JSONObject().put("display_name", name))
|
||||
val saved = savedAccount(context)
|
||||
val stored = StoreAccounts.read(context, Store.STEAM)
|
||||
val storedId = stored?.optString("steam_id").orEmpty()
|
||||
if (saved != null && saved.id == storedId) {
|
||||
if (saved.name != stored?.optString("display_name")) {
|
||||
StoreAccounts.write(context, Store.STEAM, JSONObject().put("display_name", saved.name).put("steam_id", saved.id))
|
||||
}
|
||||
return false
|
||||
}
|
||||
if (saved == null && stored == null) return false
|
||||
if (saved == null) StoreAccounts.clear(context, Store.STEAM)
|
||||
else StoreAccounts.write(context, Store.STEAM, JSONObject().put("display_name", saved.name).put("steam_id", saved.id))
|
||||
plans.clear()
|
||||
SteamEngine.forget()
|
||||
StoresState.post {
|
||||
StoresState.library.remove(Store.STEAM)
|
||||
StoresState.problems.remove(Store.STEAM)
|
||||
}
|
||||
Log.i(TAG, if (name == null) "no saved Steam sign-in" else "Steam sign-in found")
|
||||
Log.i(TAG, if (saved == null) "no saved Steam sign-in" else "Steam sign-in found")
|
||||
return true
|
||||
}
|
||||
|
||||
internal fun signInFailed(context: Context, error: String) {
|
||||
if (error == SteamEngine.MISSING) return
|
||||
val print = fingerprint(context)
|
||||
if (SteamEngine.attempted?.let { it != print } == true) return
|
||||
rejectedThisRun = print
|
||||
if (error in SIGNED_OUT) prefs(context).edit().putString("rejected", print).apply()
|
||||
StoreAccounts.clear(context, Store.STEAM)
|
||||
@@ -138,6 +154,8 @@ internal object SteamStore {
|
||||
}
|
||||
}
|
||||
|
||||
private val scans = java.util.concurrent.atomic.AtomicLong()
|
||||
|
||||
private class Read(val modified: Long, val length: Long, val text: String)
|
||||
private val manifests = ConcurrentHashMap<String, Read>()
|
||||
|
||||
@@ -152,8 +170,10 @@ internal object SteamStore {
|
||||
|
||||
/** Owned games count as installed when an appmanifest with StateFlags 4 is in one of the active client's libraries. */
|
||||
fun scanInstalled(context: Context) {
|
||||
val scan = scans.incrementAndGet()
|
||||
val found = SteamLibraryFolders.installed(SteamClient.libraries(context), ::readManifest)
|
||||
StoresState.post {
|
||||
if (scan != scans.get()) return@post
|
||||
if (found != installed) installed = found
|
||||
for ((id, game) in found) if (game.sizeOnDisk > 0 && StoreSizes.onDisk[key(id)] != game.sizeOnDisk) StoreSizes.onDisk[key(id)] = game.sizeOnDisk
|
||||
}
|
||||
@@ -166,7 +186,7 @@ internal object SteamStore {
|
||||
/** A Steam store download holds every session that could start the Steam client. */
|
||||
fun blocksSession(intent: Intent?): Boolean {
|
||||
val mode = intent?.getStringExtra(SessionService.EXTRA_MODE) ?: SessionService.MODE_STEAM
|
||||
return mode != SessionService.MODE_RUN && downloading()
|
||||
return mode != SessionService.MODE_RUN && (downloading() || StoresState.uninstalling.keys.any { it.startsWith("${Store.STEAM.id}:") })
|
||||
}
|
||||
|
||||
internal fun syncLibrary(context: Context, force: Boolean) {
|
||||
@@ -221,11 +241,11 @@ internal object SteamStore {
|
||||
|
||||
/** Reaches the network; call off the main thread. */
|
||||
internal fun plan(context: Context, appId: Int, language: String = SteamClient.language(context)): Pair<Plan?, JSONObject> {
|
||||
val plan = plans[appId] ?: run {
|
||||
val plan = plans[appId]?.takeIf { it.first == language }?.second ?: run {
|
||||
val answer = SteamEngine.plan(context, appId, language)
|
||||
val error = answer.optString("error")
|
||||
if (isSignInError(error)) signInFailed(context, error)
|
||||
Plan.of(answer)?.also { plans[appId] = it } ?: return null to answer
|
||||
Plan.of(answer)?.also { plans[appId] = language to it } ?: return null to answer
|
||||
}
|
||||
if (plan.linuxBuild && !protonMapped(context, appId)) return null to SteamEngine.failure(LINUX_BUILD)
|
||||
return plan to JSONObject().put("ok", true)
|
||||
@@ -255,7 +275,7 @@ internal object SteamStore {
|
||||
toast(app, R.string.steam_store_close_steam)
|
||||
return
|
||||
}
|
||||
val plan = plans[appId]
|
||||
val plan = plans[appId]?.second
|
||||
val needed = plan?.installBytes ?: 0L
|
||||
val tagged = item.copy(extra = item.extra + mapOf(LIBRARY to target.library.guest, LIBRARY_LABEL to target.label))
|
||||
val entry = DownloadEntry(
|
||||
@@ -281,7 +301,7 @@ internal object SteamStore {
|
||||
}
|
||||
|
||||
/** Removes a game like the client does; [fallback] deletes it when the engine cannot (no engine, or a library it does not map). */
|
||||
fun uninstall(context: Context, appId: Int, fallback: () -> Unit, onDone: () -> Unit = {}) {
|
||||
fun uninstall(context: Context, appId: Int, manifest: File?, fallback: () -> Boolean, onDone: () -> Unit = {}) {
|
||||
val app = context.applicationContext
|
||||
if (SteamClient.clientMayRun()) {
|
||||
toast(app, R.string.steam_store_close_steam)
|
||||
@@ -292,11 +312,18 @@ internal object SteamStore {
|
||||
StoresState.uninstalling[key] = 0f
|
||||
Thread({
|
||||
val answer = runCatching {
|
||||
val game = SteamLibraryFolders.installed(SteamClient.libraries(app))[appId]
|
||||
val libraries = SteamClient.libraries(app)
|
||||
val apps = manifest?.parentFile?.let(::canonical)
|
||||
val chosen = if (apps == null) libraries else libraries.filter { canonical(File(it.host, "steamapps")) == apps }
|
||||
val game = SteamLibraryFolders.installed(chosen)[appId]
|
||||
val engine = SteamClient.engineLibraries(app)
|
||||
val answer = if (game == null) SteamEngine.failure(SteamEngine.MISSING)
|
||||
else SteamEngine.uninstall(appId, SteamClient.root(app).absolutePath, engine.hostOf(game.library).absolutePath, game.library.guest, engine.json)
|
||||
if (answer.optString("error") == SteamEngine.MISSING) { fallback(); JSONObject().put("ok", true) } else answer
|
||||
when {
|
||||
answer.optString("error") != SteamEngine.MISSING -> answer
|
||||
fallback() -> JSONObject().put("ok", true)
|
||||
else -> SteamEngine.failure("remove_failed")
|
||||
}
|
||||
}.getOrElse { SteamEngine.failure(it.javaClass.simpleName) }
|
||||
val ok = answer.optBoolean("ok")
|
||||
StoresState.logLine(if (ok) "Steam: uninstalled $appId" else "Steam: uninstall of $appId failed: ${answer.optString("error")}")
|
||||
@@ -310,18 +337,29 @@ internal object SteamStore {
|
||||
}, "steam-uninstall").start()
|
||||
}
|
||||
|
||||
/** Removes what a cancelled download left; a finished install stays. */
|
||||
internal fun discardPartial(context: Context, appId: Int, guest: String, host: File?, installDir: String?) {
|
||||
private fun canonical(file: File): String = runCatching { file.canonicalPath }.getOrDefault(file.absolutePath)
|
||||
|
||||
/** An earlier run of this download left its journal, so the game folder is its own. */
|
||||
internal fun resuming(context: Context, appId: Int): Boolean = File(context.filesDir, "$JOURNAL/$appId").list()?.isNotEmpty() == true
|
||||
|
||||
/**
|
||||
* Removes what a cancelled download left; a finished install stays. The game folder goes only when this download made it
|
||||
* ([createdDir]) and no other installed game uses it.
|
||||
*/
|
||||
internal fun discardPartial(context: Context, appId: Int, guest: String, host: File?, installDir: String?, createdDir: Boolean) {
|
||||
File(context.filesDir, "$JOURNAL/$appId").deleteRecursively()
|
||||
val library = host ?: runCatching {
|
||||
SteamClient.engineLibraries(context).libraries.firstOrNull { it.first.guest == guest }?.second
|
||||
SteamClient.engineLibraries(context).libraries.firstOrNull { SteamClient.sameLibrary(context, it.first, guest) }?.second
|
||||
}.getOrNull() ?: return
|
||||
val apps = File(library, "steamapps")
|
||||
val acf = File(apps, "appmanifest_$appId.acf")
|
||||
val manifest = acf.takeIf { it.isFile }?.let { f -> runCatching { SteamStorage.parseManifest(f, f.readText()) }.getOrNull() }
|
||||
if (manifest?.installed == true) return
|
||||
val dir = (installDir ?: manifest?.installDir ?: plans[appId]?.installDir)?.takeIf { validDir(it) }
|
||||
if (dir != null) StoreInstalls.deleteTree(File(apps, "common/$dir"))
|
||||
val dir = (installDir ?: manifest?.installDir ?: plans[appId]?.second?.installDir)?.takeIf { validDir(it) }
|
||||
val shared = dir != null && apps.listFiles { f -> f.name.startsWith("appmanifest_") && f.name != acf.name }.orEmpty().any { f ->
|
||||
runCatching { SteamStorage.parseManifest(f, f.readText()) }.getOrNull()?.installDir == dir
|
||||
}
|
||||
if (dir != null && createdDir && !shared) StoreInstalls.deleteTree(File(apps, "common/$dir"))
|
||||
StoreInstalls.deleteTree(File(apps, "downloading/$appId"))
|
||||
if (manifest != null) acf.delete()
|
||||
StoresState.logLine("Steam: removed the unfinished download of $appId")
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.droiddeck.launcher.frontend.AddedGames
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.frontend.SteamHidden
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.stores.Store
|
||||
|
||||
internal const val LIBRARY_HIDDEN = "hidden"
|
||||
internal val HIDDEN_DOT = androidx.compose.ui.graphics.Color(0xFF9AA0A6)
|
||||
@@ -50,7 +51,8 @@ internal object LibraryHidden {
|
||||
|
||||
fun isHidden(key: String, game: Library.SteamGame?): Boolean = key in keys || steamId(game)?.let { it in steam } == true
|
||||
|
||||
fun isHidden(entry: LibraryEntry): Boolean = isHidden(entry.favoriteKey, entry.game)
|
||||
fun isHidden(entry: LibraryEntry): Boolean =
|
||||
isHidden(entry.favoriteKey, entry.game) || entry.item?.takeIf { it.store == Store.STEAM }?.id?.toLongOrNull()?.let { it in steam } == true
|
||||
|
||||
fun set(context: Context, key: String, game: Library.SteamGame?, hidden: Boolean): Boolean {
|
||||
val id = steamId(game)
|
||||
|
||||
@@ -85,7 +85,10 @@ internal object StoreTabsState {
|
||||
libraryHidden = SessionPrefs.libraryTabsHidden(context) + listOfNotNull(LIBRARY_HIDDEN.takeUnless { SessionPrefs.libraryShowHidden(context) })
|
||||
}
|
||||
|
||||
/** [ids] may hold the Library's own tabs among the stores; each one's place is kept as the tab it follows. */
|
||||
/**
|
||||
* [ids] may hold the Library's own tabs among the stores; each one's place is kept as the tab it follows. A store [ids]
|
||||
* leaves out (the Steam store, which the Library shows as its own Steam tab) keeps its index.
|
||||
*/
|
||||
fun reorder(context: android.content.Context, ids: List<String>) {
|
||||
if (ids.any { it in LIBRARY_OWN_TABS }) {
|
||||
val places = libraryPlacesOf(ids)
|
||||
@@ -93,7 +96,8 @@ internal object StoreTabsState {
|
||||
SessionPrefs.setLibraryTabPlaces(context, places)
|
||||
}
|
||||
val byId = tabs.associateBy { it.store.id }
|
||||
val order = ids.mapNotNull { byId[it] }
|
||||
val order = ids.mapNotNull { byId[it] }.toMutableList()
|
||||
tabs.forEachIndexed { i, tab -> if (tab.store.id !in ids) order.add(i.coerceAtMost(order.size), tab) }
|
||||
if (order.map { it.store } != tabs.map { it.store }) {
|
||||
tabs = order
|
||||
save(context, arranged = true)
|
||||
|
||||
@@ -231,6 +231,7 @@ class SteamLibraryFoldersTest {
|
||||
}
|
||||
""".trimIndent()
|
||||
assertEquals("Player", SteamLibraryFolders.savedAccount(users))
|
||||
assertEquals(SteamLibraryFolders.SavedAccount("76561190000000002", "Player"), SteamLibraryFolders.savedLogin(users))
|
||||
assertEquals("Old One", SteamLibraryFolders.savedAccount(users.replace("\"MostRecent\"\t\t\"1\"", "\"MostRecent\"\t\t\"0\"").replace("\"1700000000\"", "\"1500000000\"")))
|
||||
assertEquals("player", SteamLibraryFolders.savedAccount(users.replace("\"PersonaName\"\t\t\"Player\"", "\"PersonaName\"\t\t\"\"").replace("\"Old One\"", "\"\"").replace("\"1600000000\"", "\"1\"")))
|
||||
assertNull(SteamLibraryFolders.savedAccount(users.replace("\"RememberPassword\"\t\t\"1\"", "\"RememberPassword\"\t\t\"0\"")))
|
||||
|
||||
@@ -31,6 +31,16 @@ class StoreTabsStateTest {
|
||||
assertEquals(moved, StoreTabsState.tabs.map { it.store.id })
|
||||
}
|
||||
|
||||
@Test fun aLibraryReorderWithoutTheSteamStoreKeepsItsPlace() {
|
||||
val ids = StoreTabsState.tabs.map { it.store.id }
|
||||
val at = ids.indexOf(Store.STEAM.id)
|
||||
val rest = ids - Store.STEAM.id
|
||||
StoreTabsState.reorder(ctx, listOf(rest[1], rest[0]) + rest.drop(2))
|
||||
val after = StoreTabsState.tabs.map { it.store.id }
|
||||
assertEquals(at, after.indexOf(Store.STEAM.id))
|
||||
assertEquals(listOf(rest[1], rest[0]) + rest.drop(2), after - Store.STEAM.id)
|
||||
}
|
||||
|
||||
@Test fun hidingIsSavedButTheLastShownStoreStays() {
|
||||
assertTrue(StoreTabsState.setShown(ctx, Store.GOG, false))
|
||||
assertTrue(Store.GOG.id in SessionPrefs.storesTabHidden(ctx))
|
||||
|
||||
Reference in new issue
Block a user