Let GOG and Epic installs pick a game language (#1199)

This commit is contained in:
Tomasz Kloc authored and GitHub committed 2026-10-22 00:38:01 -04:00
1 parent 138d313b7f
commit 593014fe8c
15 files changed
+427 -37

No files matched your search

@@ -146,6 +146,13 @@ object SessionPrefs {
prefs(context).edit().putString("storesInstallTarget", path).apply()
}
/** Empty means follow the app/system language for GOG and Epic installs. */
fun storesInstallLanguage(context: Context): String = prefs(context).getString("storesInstallLanguage", "") ?: ""
fun setStoresInstallLanguage(context: Context, code: String) {
prefs(context).edit().putString("storesInstallLanguage", code).apply()
}
fun gameStoresParallel(context: Context): Int = prefs(context).getInt("gameStoresParallel", 1).coerceIn(1, 3)
fun setGameStoresParallel(context: Context, count: Int) {
@@ -13,6 +13,7 @@ object SettingsReset {
internal val SESSION_KEYS = setOf(
"orientation", "launcherFullscreen", "animations", "theme", "runSteamAtStartup", "addedGamesArt",
"gameStoresEnabled", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature",
"storesInstallLanguage",
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "backActionsInverted", "touch", "osc", "shape", "steamController",
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "stretch16x9", "picturePosition",
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
@@ -0,0 +1,160 @@
package com.droiddeck.launcher.stores
import android.content.Context
import com.droiddeck.launcher.core.AppLanguage
import com.droiddeck.launcher.session.SessionPrefs
import org.json.JSONArray
import java.util.Locale
/**
* Language for a third-party store install ([Store.GOG], [Store.EPIC]): the app/system locale by
* default, or the code the user picked in the install dialog / store settings.
*
* GOG depots and Epic install tags use overlapping but not identical codes (`en` vs `en-US`,
* `nb` vs `no`). Matching is on the language part plus a few aliases, so a Polish phone selects
* `pl-PL` depots without the user having to know the store's spelling.
*/
object StoreLanguage {
const val EXTRA = "installLanguage"
/** Codes the settings list and Epic's tag table share; GOG often uses the same with a region. */
val KNOWN: List<String> = listOf(
"en", "pl", "de", "fr", "es", "es-419", "pt", "pt-BR", "it", "ru", "uk", "cs", "hu",
"nl", "sv", "da", "fi", "nb", "ro", "bg", "el", "tr", "ar", "th", "vi", "ja", "ko",
"zh-Hans", "zh-Hant",
)
private val ALIASES = mapOf(
"english" to "en", "polish" to "pl", "german" to "de", "french" to "fr", "spanish" to "es",
"italian" to "it", "russian" to "ru", "ukrainian" to "uk", "czech" to "cs", "hungarian" to "hu",
"dutch" to "nl", "swedish" to "sv", "danish" to "da", "finnish" to "fi", "norwegian" to "nb",
"no" to "nb", "romanian" to "ro", "bulgarian" to "bg", "greek" to "el", "turkish" to "tr",
"arabic" to "ar", "thai" to "th", "vietnamese" to "vi", "japanese" to "ja", "korean" to "ko",
"schinese" to "zh-hans", "tchinese" to "zh-hant", "chinese" to "zh-hans",
"brazilian" to "pt-br", "portuguese" to "pt",
)
fun selectable(store: Store): Boolean = store == Store.GOG || store == Store.EPIC
/** Tag actually sent to the store: settings override, else the app/system locale. */
@JvmStatic
fun preferredCode(context: Context): String {
val chosen = SessionPrefs.storesInstallLanguage(context)
if (chosen.isNotEmpty()) return chosen
return tagFor(AppLanguage.effective(context))
}
@JvmStatic
fun preferredCode(): String = tagFor(Locale.getDefault())
fun tagFor(locale: Locale): String {
val language = locale.language.ifEmpty { "en" }
val country = locale.country
val script = locale.script
return when {
language == "zh" && (script == "Hant" || country == "TW" || country == "HK" || country == "MO") -> "zh-Hant"
language == "zh" -> "zh-Hans"
language == "pt" && (country.isEmpty() || country == "BR") -> "pt-BR"
language == "es" && country.isNotEmpty() && country != "ES" -> "es-419"
country.isNotEmpty() -> "$language-$country"
else -> language
}
}
fun localeFor(code: String?, context: Context): Locale {
val tag = code?.takeIf { it.isNotBlank() } ?: preferredCode(context)
return Locale.forLanguageTag(tag.replace('_', '-'))
}
fun fallbackList(store: Store): List<String> = if (selectable(store)) KNOWN else emptyList()
/**
* One code from [available]. An exact normalized code wins (`pl-PL` over `pl`). A base-language
* match is used only when that exact code is not offered, then English, then the first code.
*/
@JvmStatic
fun pick(available: List<String>, preferred: String): String {
if (available.isEmpty()) return preferred
val want = primary(preferred) ?: return available.first()
return available.firstOrNull { primary(it) == want }
?: available.firstOrNull { depotAccepted(arrayOf(it), preferred) }
?: available.firstOrNull { depotAccepted(arrayOf(it), "en") }
?: available.first()
}
/**
* True when a GOG depot whose `languages` array is [listed] overlaps [chosen], including a
* base-language match (`pl` accepts `pl-PL`). Shared depots (`*`, empty, missing) always match.
* Install selection uses [depotMatchesResolved] after [pick] has chosen a single code.
*/
@JvmStatic
fun depotAccepted(listed: Array<String>?, chosen: String): Boolean {
if (listed.isNullOrEmpty()) return true
val want = tokens(chosen)
return listed.any { have ->
val parts = tokens(have)
parts.contains("*") || parts.any { it in want }
}
}
/**
* True when [listed] is shared, or contains the one code [resolved] already selected.
* `pl-PL` does not also keep a `pl` depot.
*/
@JvmStatic
fun depotMatchesResolved(listed: Array<String>?, resolved: String): Boolean {
if (listed.isNullOrEmpty()) return true
if (listed.any { it.trim() == "*" }) return true
val want = primary(resolved) ?: return false
return listed.any { primary(it) == want }
}
/** Normalized code without collapsing to the base language. `pl-PL` stays `pl-pl`. */
internal fun primary(code: String): String? {
val raw = code.trim().lowercase().replace('_', '-')
if (raw.isEmpty()) return null
if (raw == "*") return "*"
return ALIASES[raw] ?: raw
}
@JvmStatic
fun codesFromDepots(depots: JSONArray?): List<String> {
if (depots == null) return emptyList()
val seen = LinkedHashSet<String>()
for (i in 0 until depots.length()) {
val langs = depots.optJSONObject(i)?.optJSONArray("languages") ?: continue
for (j in 0 until langs.length()) {
val raw = langs.optString(j, "").trim()
if (raw.isEmpty() || raw == "*") continue
val key = raw.lowercase()
if (seen.none { it.lowercase() == key }) seen.add(raw)
}
}
return seen.toList()
}
fun displayName(code: String): String {
if (code.isEmpty()) return ""
val locale = Locale.forLanguageTag(code.replace('_', '-'))
AppLanguage.supportedTag(locale)?.let { return AppLanguage.nativeName(it) }
val name = locale.getDisplayName(locale)
return name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(locale) else it.toString() }
}
internal fun tokens(code: String): Set<String> {
val raw = code.trim().lowercase().replace('_', '-')
if (raw.isEmpty()) return emptySet()
if (raw == "*") return setOf("*")
val mapped = ALIASES[raw] ?: raw
val lang = mapped.substringBefore('-').let { ALIASES[it] ?: it }
val out = mutableSetOf(mapped, lang)
if (mapped.startsWith("zh-hant") || mapped == "zh-tw" || mapped == "zh-hk") {
out.add("zh-hant"); out.add("zh")
}
if (mapped.startsWith("zh-hans") || mapped == "zh-cn") {
out.add("zh-hans"); out.add("zh")
}
if (mapped == "pt-br" || mapped == "br") out.add("pt-br")
return out
}
}
@@ -99,7 +99,10 @@ object StoreSizes {
val json = EpicApiClient.getManifestApiJson(token, ns, catalogItemId, item.id) ?: return 0L
val bytes = EpicDownloadManager.downloadManifest(json, EpicDownloadManager.parseCdnUrls(json)) ?: return 0L
val manifest = EpicDownloadManager.parseManifest(bytes) ?: return 0L
EpicDownloadManager.resolveInstallFiles(manifest, EpicInstallTags.tagsForDevice()).sumOf { it.fileSize() }
EpicDownloadManager.resolveInstallFiles(
manifest,
EpicInstallTags.tagsFor(StoreLanguage.localeFor(null, context)),
).sumOf { it.fileSize() }
}
Store.AMAZON -> {
val token = AmazonCredentialStore.getValidAccessToken(context) ?: return 0L
@@ -202,32 +202,35 @@ object StoresState {
askForNotifications(context)
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)
if (targets.size > 1 || StoreLanguage.selectable(item.store)) pendingInstall = item
else install(context, item, targets.first().root)
}
fun install(context: Context, item: CatalogItem, root: java.io.File? = null) {
fun install(context: Context, item: CatalogItem, root: java.io.File? = null, language: String? = null) {
val app = context.applicationContext
val folder = StoreInstallRoot.folderFor(app, item.store, item.id, item.title, root ?: StoreInstallRoot.installRoot(app))
val target = folder.parentFile!!.parentFile!!
val check = StoreInstallRoot.checkStorage(app, item, target)
val code = language?.takeIf { it.isNotBlank() } ?: StoreLanguage.preferredCode(app)
val tagged = if (StoreLanguage.selectable(item.store)) item.copy(extra = item.extra + (StoreLanguage.EXTRA to code)) else item
val check = StoreInstallRoot.checkStorage(app, tagged, target)
if (!check.enough) {
val errorMsg = check.errorMessage ?: app.getString(com.droiddeck.launcher.R.string.stores_storage_insufficient, formatBytes(check.requiredBytes), formatBytes(check.availableBytes))
val entry = com.droiddeck.launcher.stores.download.DownloadEntry(
item.store,
item.id,
item.title,
cover = item.imageUrl,
bytesTotal = item.sizeBytes,
tagged.store,
tagged.id,
tagged.title,
cover = tagged.imageUrl,
bytesTotal = tagged.sizeBytes,
location = StoreInstallRoot.labelFor(app, folder)
)
com.droiddeck.launcher.stores.download.SavedQueue.remember(app, item, target)
com.droiddeck.launcher.stores.download.SavedQueue.remember(app, tagged, target)
com.droiddeck.launcher.stores.download.DownloadQueue.recordFailed(app, entry, errorMsg) {
install(app, item, target)
install(app, tagged, target, code)
}
return
}
com.droiddeck.launcher.stores.download.SavedQueue.remember(app, item, target)
backends[item.store]?.install(app, item, target) ?: logLine("${item.store.label}: this build cannot install yet")
com.droiddeck.launcher.stores.download.SavedQueue.remember(app, tagged, target)
backends[tagged.store]?.install(app, tagged, target) ?: logLine("${tagged.store.label}: this build cannot install yet")
}
val uninstalling = mutableStateMapOf<String, Float>()
@@ -8,17 +8,20 @@ object EpicInstallTags {
@Volatile private var last: Answer? = null
private fun current(): Answer? {
val locale = Locale.getDefault()
private fun answer(locale: Locale): Answer? {
last?.takeIf { it.locale == locale }?.let { return it }
val answer = EpicNative.call("locale", JSONObject().put("language", locale.language).put("region", locale.country)) ?: return null
val list = answer.optJSONArray("tags")
val call = EpicNative.call("locale", JSONObject().put("language", locale.language).put("region", locale.country)) ?: return null
val list = call.optJSONArray("tags")
val tags = List(list?.length() ?: 0) { list!!.optString(it) }.filter { it.isNotEmpty() }
return Answer(locale, tags, answer.optString("launchLocale", "en").ifEmpty { "en" }).also { last = it }
return Answer(locale, tags, call.optString("launchLocale", "en").ifEmpty { "en" }).also { last = it }
}
@JvmStatic
fun tagsForDevice(): List<String> = current()?.tags ?: emptyList()
fun tagsFor(locale: Locale): List<String> = answer(locale)?.tags ?: emptyList()
fun launchLocale(): String = current()?.launchLocale ?: "en"
fun launchLocale(locale: Locale): String = answer(locale)?.launchLocale ?: "en"
@JvmStatic
fun tagsForDevice(): List<String> = tagsFor(Locale.getDefault())
fun launchLocale(): String = launchLocale(Locale.getDefault())
}
@@ -9,6 +9,7 @@ import com.droiddeck.launcher.stores.StoreExe
import com.droiddeck.launcher.stores.StoreGameSidecar
import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.StoreInstalls
import com.droiddeck.launcher.stores.StoreLanguage
import com.droiddeck.launcher.stores.download.DownloadQueue
import com.droiddeck.launcher.stores.download.DownloadStage
import com.droiddeck.launcher.stores.download.StoreDownloadTier
@@ -29,6 +30,8 @@ internal class EpicInstaller(
private fun scratch(): File = StoreInstallRoot.scratchDir(app, Store.EPIC, item.id)
private fun installLocale() = StoreLanguage.localeFor(item.extra[StoreLanguage.EXTRA], app)
override fun run(handle: DownloadQueue.JobHandle): String? {
handle.stage(DownloadStage.MANIFEST, app.getString(R.string.stores_sync_sign_in))
val token = EpicCredentialStore.getValidAccessToken(app) ?: throw IllegalStateException("Not signed in to Epic Games")
@@ -47,7 +50,7 @@ internal class EpicInstaller(
.put("gameDir", folder.absolutePath)
.put("scratchDir", if (StoreInstallRoot.isRemovable(app, folder)) scratch().absolutePath else "")
.put("storageLabel", StoreInstallRoot.labelFor(app, folder))
.put("tags", JSONArray(EpicInstallTags.tagsForDevice()))
.put("tags", JSONArray(EpicInstallTags.tagsFor(installLocale())))
.put("maxWorkers", tier.networkWindow.coerceIn(1, 128))
.put("processWorkers", tier.processWorkers)
.put("caBundle", "")
@@ -111,7 +114,7 @@ internal class EpicInstaller(
val argsAnswer = EpicNative.call(
"launch.args",
JSONObject().put("displayName", creds?.displayName.orEmpty()).put("accountId", creds?.accountId.orEmpty())
.put("namespace", namespace).put("locale", EpicInstallTags.launchLocale()).put("appName", item.id)
.put("namespace", namespace).put("locale", EpicInstallTags.launchLocale(installLocale())).put("appName", item.id)
.put("deploymentId", deployment).put("additional", additional),
)
val argList = argsAnswer?.optJSONArray("args")
@@ -122,6 +125,7 @@ internal class EpicInstaller(
extra["namespace"] = namespace
extra["catalogItemId"] = catalogItemId
if (deployment.isNotEmpty()) extra["deploymentId"] = deployment
extra[StoreLanguage.EXTRA] = item.extra[StoreLanguage.EXTRA] ?: StoreLanguage.preferredCode(app)
extra[WinCompSources.EPIC_PREREQ_PATH] = result.optString("prereqPath")
extra[WinCompSources.EPIC_PREREQ_NAME] = result.optString("prereqName")
if (result.optBoolean("prereqRead", false)) extra[WinCompSources.LIST_READ] = "1"
@@ -9,6 +9,7 @@ import com.droiddeck.launcher.stores.StoreBackend
import com.droiddeck.launcher.stores.StoreGameSidecar
import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.StoreInstalls
import com.droiddeck.launcher.stores.StoreLanguage
import com.droiddeck.launcher.stores.StoreLoginActivity
import com.droiddeck.launcher.stores.StoresState
import com.droiddeck.launcher.stores.download.DownloadEntry
@@ -91,6 +92,7 @@ object GogBackend : StoreBackend {
handle.stage(DownloadStage.MANIFEST)
StoreInstalls.begin(folder, Store.GOG, game.gameId, game.title, item.tallImageUrl ?: item.imageUrl, item.imageUrl)
var downloading = false
val language = item.extra[StoreLanguage.EXTRA] ?: StoreLanguage.preferredCode(app)
val result = GogDownloadManager.install(app, game, folder, object : GogDownloadManager.Callback {
override fun onProgress(message: String, pct: Int) {
when {
@@ -108,15 +110,17 @@ object GogBackend : StoreBackend {
handle.stage(when (stage) { "check" -> DownloadStage.MANIFEST; "verify" -> DownloadStage.VERIFY; else -> DownloadStage.INSTALL })
handle.stageProgress(done, total, items, itemsTotal, bytes = stage == "install")
}
}, cancelled) ?: return null
}, cancelled, language) ?: return null
if (cancelled.get()) return null
handle.stage(DownloadStage.INSTALL, app.getString(com.droiddeck.launcher.R.string.stores_registering))
val installedLanguage = result.language?.takeIf { it.isNotEmpty() } ?: language
val sidecar = StoreGameSidecar(
Store.GOG, game.gameId, game.title, exe = result.exeRelative.ifEmpty { "" },
installVersion = result.buildId, installedAt = System.currentTimeMillis(),
cover = item.tallImageUrl ?: item.imageUrl, hero = item.imageUrl,
extra = mapOf(com.droiddeck.launcher.frontend.WinCompSources.GOG_DEPENDENCIES to result.dependencies.joinToString(","))
+ (if (result.dependenciesRead) mapOf(com.droiddeck.launcher.frontend.WinCompSources.LIST_READ to "1") else emptyMap()),
+ (if (result.dependenciesRead) mapOf(com.droiddeck.launcher.frontend.WinCompSources.LIST_READ to "1") else emptyMap())
+ mapOf(StoreLanguage.EXTRA to installedLanguage),
)
if (sidecar.exe.isEmpty()) handle.log("gog: no exe found in ${folder.name}; pick one in Steam settings › Added games")
StoreInstalls.complete(app, folder, onStep = { done, steps -> handle.stageProgress(done.toLong(), steps.toLong()) }, sidecar = if (sidecar.exe.isEmpty()) sidecar.copy(exe = "game.exe") else sidecar)
@@ -3,6 +3,7 @@ package com.droiddeck.launcher.stores.gog;
import android.content.Context;
import android.util.Log;
import com.droiddeck.launcher.stores.StoreLanguage;
import com.droiddeck.launcher.stores.StoreLog;
import com.droiddeck.launcher.stores.download.StoreDownloadTier;
@@ -57,6 +58,8 @@ public final class GogDownloadManager {
public final long bytes;
public List<String> dependencies = new ArrayList<>();
public boolean dependenciesRead = false;
/** Language actually written, after the manifest's depot list resolved the request. Null for builds that have no language depots. */
public String language;
Result(String exeRelative, String buildId, long bytes) { this.exeRelative = exeRelative; this.buildId = buildId; this.bytes = bytes; }
}
@@ -67,17 +70,23 @@ public final class GogDownloadManager {
private GogDownloadManager() {}
public static Result install(Context ctx, GogGame game, File installPath, Callback cb, AtomicBoolean cancelled) throws InstallException {
return install(ctx, game, installPath, cb, cancelled, null);
}
public static Result install(Context ctx, GogGame game, File installPath, Callback cb, AtomicBoolean cancelled, String language) throws InstallException {
cb.onProgress("Checking sign-in…", 0);
String token = GogAuth.validToken(ctx);
if (token == null) throw new InstallException("Not signed in to GOG");
if (cancelled.get()) return null;
String lang = (language == null || language.isEmpty()) ? StoreLanguage.preferredCode(ctx) : language;
cb.onLog("gog: installing language " + lang);
cb.onProgress("Fetching builds…", 2);
String buildsUrl = "https://content-system.gog.com/products/" + game.gameId + "/os/windows/builds?generation=2";
String buildsJson = httpGet(buildsUrl, null);
if (buildsJson == null) buildsJson = httpGet(buildsUrl, token);
if (buildsJson != null) {
Gen2Outcome out = runGen2(ctx, game, token, buildsJson, installPath, cb, cancelled);
Gen2Outcome out = runGen2(ctx, game, token, buildsJson, installPath, cb, cancelled, lang);
if (out.result != null || cancelled.get()) return out.result;
if (out.hardStop) throw new InstallException(out.error);
cb.onLog("gen2 unavailable: " + out.error);
@@ -100,7 +109,7 @@ public final class GogDownloadManager {
Result result; String error; boolean hardStop;
}
private static Gen2Outcome runGen2(Context ctx, GogGame game, String token, String buildsJson, File installPath, Callback cb, AtomicBoolean cancelled) {
private static Gen2Outcome runGen2(Context ctx, GogGame game, String token, String buildsJson, File installPath, Callback cb, AtomicBoolean cancelled, String language) {
Gen2Outcome out = new Gen2Outcome();
try {
cb.onProgress("Fetching manifest…", 5);
@@ -127,12 +136,21 @@ public final class GogDownloadManager {
cb.onProgress("Reading depot manifests…", 10);
List<DepotFile> files = new ArrayList<>();
List<String> depotJsons = new ArrayList<>();
JSONArray owned = new JSONArray();
List<JSONObject> ownedDepots = new ArrayList<>();
for (int i = 0; i < depots.length(); i++) {
if (cancelled.get()) return out;
JSONObject depot = depots.getJSONObject(i);
String depotPid = depot.optString("productId", "");
if (!depotPid.isEmpty() && !depotPid.equals(baseProductId)) continue;
if (!languageCompatible(depot)) continue;
owned.put(depot);
ownedDepots.add(depot);
}
String resolved = StoreLanguage.pick(StoreLanguage.codesFromDepots(owned), language);
cb.onLog("gog: language " + resolved);
for (int i = 0; i < ownedDepots.size(); i++) {
if (cancelled.get()) return out;
JSONObject depot = ownedDepots.get(i);
if (!depotSelected(depot, resolved)) continue;
String manifestHash = depot.optString("manifest");
if (manifestHash == null || manifestHash.isEmpty()) continue;
byte[] dmRaw = fetchBytes("https://gog-cdn-fastly.gog.com/content-system/v2/meta/" + buildCdnPath(manifestHash), null);
@@ -232,6 +250,7 @@ public final class GogDownloadManager {
out.result = new Result(pickExe(installPath, tempExe, game.title), gm.buildId, planned);
out.result.dependencies = dependencies;
out.result.dependenciesRead = true;
out.result.language = resolved;
return out;
} catch (Exception e) {
out.error = "exception: " + e.getClass().getSimpleName() + (e.getMessage() != null ? ": " + e.getMessage() : "");
@@ -270,11 +289,31 @@ public final class GogDownloadManager {
}
}
private static boolean languageCompatible(JSONObject depot) {
private static boolean depotSelected(JSONObject depot, String resolved) {
JSONArray languages = depot.optJSONArray("languages");
if (languages == null || languages.length() == 0) return true;
String s = languages.toString();
return s.contains("*") || s.contains("en-US") || s.contains("\"en\"") || s.contains("english");
String[] listed = new String[languages.length()];
for (int i = 0; i < languages.length(); i++) listed[i] = languages.optString(i, "");
return StoreLanguage.depotMatchesResolved(listed, resolved);
}
/** Language codes listed on this product's Windows gen2 depots, excluding `*`. */
public static List<String> listLanguages(Context ctx, String gameId) {
try {
String token = GogAuth.validToken(ctx);
String buildsUrl = "https://content-system.gog.com/products/" + gameId + "/os/windows/builds?generation=2";
String buildsJson = httpGet(buildsUrl, null);
if (buildsJson == null) buildsJson = httpGet(buildsUrl, token);
if (buildsJson == null) return Collections.emptyList();
Callback silent = new Callback() {
@Override public void onProgress(String message, int pct) {}
};
Gen2Manifest gm = resolveGen2Manifest(buildsJson, token, silent);
if (gm == null) return Collections.emptyList();
return StoreLanguage.codesFromDepots(gm.manifest.optJSONArray("depots"));
} catch (Exception e) {
return Collections.emptyList();
}
}
@@ -1037,9 +1076,10 @@ public final class GogDownloadManager {
JSONArray depots = new JSONObject(manifestStr).optJSONArray("depots");
if (depots == null) return -1;
long total = 0;
String resolved = StoreLanguage.pick(StoreLanguage.codesFromDepots(depots), StoreLanguage.preferredCode());
for (int i = 0; i < depots.length(); i++) {
JSONObject depot = depots.getJSONObject(i);
if (languageCompatible(depot)) total += depot.optLong("size", 0);
if (depotSelected(depot, resolved)) total += depot.optLong("size", 0);
}
return total > 0 ? total : -1;
} catch (Exception e) {
@@ -84,6 +84,7 @@ import androidx.compose.ui.unit.sp
import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.StoreLanguage
import com.droiddeck.launcher.stores.StoresState
import com.droiddeck.launcher.stores.download.DownloadEntry
import com.droiddeck.launcher.stores.download.DownloadQueue
@@ -495,6 +496,7 @@ internal fun storesSettingsStep(at: Rect, s: androidx.compose.runtime.State<Fron
verticalArrangement = Arrangement.spacedBy(6.dp),
) {
val st = s.value
val context = androidx.compose.ui.platform.LocalContext.current
SettingsRow(stringResource(R.string.stores_tabs_arrange), null) {
RoundAction(Icons.Filled.SwapHoriz, stringResource(R.string.stores_tabs_arrange), size = 36.dp) {
StoresMotion.fold()
@@ -510,8 +512,33 @@ internal fun storesSettingsStep(at: Rect, s: androidx.compose.runtime.State<Fron
SettingsRow(stringResource(R.string.stores_show_mature), null) {
ToggleSwitch(st.storesShowMature, label = stringResource(R.string.stores_show_mature)) { a.onStoresShowMature(it) }
}
var langOpen by remember { mutableStateOf(false) }
val storedLanguage = SessionPrefs.storesInstallLanguage(context)
var language by remember(storedLanguage, StoreLanguage.preferredCode(context)) { mutableStateOf(storedLanguage) }
SettingsRow(stringResource(R.string.stores_install_language), stringResource(R.string.stores_install_language_hint), stacked = true) {
Box {
ValueChip(
if (language.isEmpty()) stringResource(R.string.stores_install_language_system)
else StoreLanguage.displayName(language),
langOpen,
) { langOpen = !langOpen }
AnchoredMenu(langOpen, { langOpen = false }, title = stringResource(R.string.stores_install_language)) { first ->
val options = listOf("") + StoreLanguage.KNOWN
options.forEachIndexed { i, code ->
MenuItem(
if (code.isEmpty()) stringResource(R.string.stores_install_language_system) else StoreLanguage.displayName(code),
checked = language == code,
focusRequester = if (i == 0) first else null,
) {
language = code
SessionPrefs.setStoresInstallLanguage(context, code)
langOpen = false
}
}
}
}
}
Column(Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 11.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { DownloadControls(st, a) }
val context = androidx.compose.ui.platform.LocalContext.current
var gogAchievements by androidx.compose.runtime.remember { androidx.compose.runtime.mutableStateOf(com.droiddeck.launcher.stores.gog.GogComet.enabled(context)) }
androidx.compose.runtime.LaunchedEffect(Unit) {
if (gogAchievements) com.droiddeck.launcher.core.AddonPack.COMET.ensure(context)
@@ -25,7 +25,10 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@@ -42,8 +45,12 @@ import com.droiddeck.launcher.R
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.StoreLanguage
import com.droiddeck.launcher.stores.StoresState
import com.droiddeck.launcher.stores.formatBytes
import com.droiddeck.launcher.stores.gog.GogDownloadManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@Composable
internal fun InstallWhereDialog(item: CatalogItem, onDismiss: () -> Unit) {
@@ -55,7 +62,19 @@ internal fun InstallWhereDialog(item: CatalogItem, onDismiss: () -> Unit) {
val remembered = remember { SessionPrefs.storesInstallTarget(ctx) }
val defaultIndex = targets.indexOfFirst { it.root.absolutePath == remembered }.coerceAtLeast(0)
val focus = remember { List(targets.size) { FocusRequester() } }
val askLanguage = StoreLanguage.selectable(item.store)
val preferredLanguage = StoreLanguage.preferredCode(ctx)
var languages by remember { mutableStateOf(StoreLanguage.fallbackList(item.store)) }
var chosen by remember(preferredLanguage) { mutableStateOf(StoreLanguage.pick(languages, preferredLanguage)) }
var menuOpen by remember { mutableStateOf(false) }
LaunchedEffect(Unit) { focusWithinFrames({ false }) { focus[defaultIndex] } }
LaunchedEffect(item.key) {
if (item.store != com.droiddeck.launcher.stores.Store.GOG) return@LaunchedEffect
val listed = withContext(Dispatchers.IO) { GogDownloadManager.listLanguages(ctx, item.id) }
if (listed.isEmpty()) return@LaunchedEffect
languages = listed
chosen = StoreLanguage.pick(listed, chosen)
}
AppDialog(shown, close, "installWhere", wide = false, maxWidth = if (targets.size > 2) 600.dp else 440.dp) {
Rise(0) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
@@ -69,7 +88,23 @@ internal fun InstallWhereDialog(item: CatalogItem, onDismiss: () -> Unit) {
)
}
}
Rise(1) {
if (askLanguage) Rise(1) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth()) {
Text(stringResource(R.string.stores_install_language), fontSize = 13.sp, color = colors.onSurfaceVariant)
Box(Modifier.weight(1f)) {
ValueChip(StoreLanguage.displayName(chosen).ifEmpty { chosen }, menuOpen, modifier = Modifier.fillMaxWidth()) { menuOpen = !menuOpen }
AnchoredMenu(menuOpen, { menuOpen = false }, title = stringResource(R.string.stores_install_language), compact = true) { first ->
languages.forEachIndexed { i, code ->
MenuItem(StoreLanguage.displayName(code).ifEmpty { code }, checked = code == chosen, focusRequester = if (i == 0) first else null) {
chosen = code
menuOpen = false
}
}
}
}
}
}
Rise(if (askLanguage) 2 else 1) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
targets.forEachIndexed { i, t ->
val needed = com.droiddeck.launcher.stores.StoreInstallRoot.estimatedBytesNeeded(item)
@@ -89,7 +124,7 @@ internal fun InstallWhereDialog(item: CatalogItem, onDismiss: () -> Unit) {
warning = isLow, modifier = Modifier.weight(1f),
) {
SessionPrefs.setStoresInstallTarget(ctx, t.root.absolutePath)
StoresState.install(ctx, item, t.root)
StoresState.install(ctx, item, t.root, if (askLanguage) chosen else null)
close()
}
}
@@ -30,6 +30,7 @@ import androidx.compose.ui.layout.boundsInParent
import androidx.compose.ui.layout.boundsInRoot
import androidx.compose.ui.layout.positionInRoot
import com.droiddeck.launcher.stores.StoreInstallRoot
import com.droiddeck.launcher.stores.StoreLanguage
import com.droiddeck.launcher.stores.epic.EpicClient
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
@@ -543,7 +544,10 @@ private fun InstallWhere(item: CatalogItem) {
val ctx = LocalContext.current
val pal = LocalPalette.current
val from = remember(item) { StoresMotion.recentInstall() }
if (from == null) { InstallWhereDialog(item) { StoresState.pendingInstall = null }; return }
if (from == null || StoreLanguage.selectable(item.store)) {
InstallWhereDialog(item) { StoresState.pendingInstall = null }
return
}
val title = stringResource(R.string.stores_install_title, item.title)
val internalLabel = stringResource(R.string.stores_target_internal)
val label = StoresMotion.installLabel