Skip to content
8 changes: 8 additions & 0 deletions app/src/main/java/app/gamenative/PrefManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,14 @@ object PrefManager {
setPref(DOWNLOAD_SPEED, value)
}

private val SD_CARD_CAP = booleanPreferencesKey("sd_card_cap")
var sdCardCap: Boolean
get() = getPref(SD_CARD_CAP, false)
set(value) {
Timber.d("Setting SD_CARD_CAP to $value")
setPref(SD_CARD_CAP, value)
}

private val USE_EXTERNAL_STORAGE = booleanPreferencesKey("use_external_storage")
var useExternalStorage: Boolean
get() = getPref(USE_EXTERNAL_STORAGE, false)
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/app/gamenative/service/SteamService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,9 @@ class SteamService : Service(), IChallengeUrlChanged {
// Some notes here:
// Write should always be 1 in mobile device, as normally it does not use a SSD for storage
// And to have maximum throughput, set downloadRatio = decompressRatio = 1.0 x CPU Cores
//Update: This does not seem to hold true for external storage, and especially SD cards
//Initial testing seems to indicate decompress should be one thread only, and download threads only slightly higher

var downloadRatio = 0.0
var decompressRatio = 0.0

Expand All @@ -1499,7 +1502,7 @@ class SteamService : Service(), IChallengeUrlChanged {

val cpuCores = Runtime.getRuntime().availableProcessors()
val maxDownloads = (cpuCores * downloadRatio).toInt().coerceAtLeast(1)
val maxDecompress = (cpuCores * decompressRatio).toInt().coerceAtLeast(1)
val maxDecompress = if (PrefManager.sdCardCap && PrefManager.useExternalStorage) 2 else (cpuCores * decompressRatio).toInt().coerceAtLeast(1)

Timber.i("CPU Cores: $cpuCores")
Timber.i("maxDownloads: $maxDownloads")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ fun SettingsGroupInterface(
sm.getStorageVolume(dir)?.getDescription(ctx) ?: dir.name
}
}

var useExternalStorage by rememberSaveable { mutableStateOf(PrefManager.useExternalStorage) }
var sdCardCap by rememberSaveable {mutableStateOf(PrefManager.sdCardCap)}
SettingsSwitch(
colors = settingsTileColorsAlt(),
enabled = dirs.isNotEmpty(),
Expand All @@ -606,11 +608,31 @@ fun SettingsGroupInterface(
onCheckedChange = {
useExternalStorage = it
PrefManager.useExternalStorage = it

if (it && dirs.isNotEmpty()) {
PrefManager.externalStoragePath = dirs[0].absolutePath
PrefManager.sdCardCap = it
sdCardCap = true
} else {
PrefManager.sdCardCap = false
sdCardCap = false
}
},
)

if (useExternalStorage) {
SettingsSwitch(
colors = settingsTileColorsAlt(),
title = { Text(text = stringResource(R.string.settings_interface_sd_card_cap_title)) },
subtitle = { Text(text = stringResource(R.string.settings_interface_sd_card_cap_subtitle)) },
state = sdCardCap,
onCheckedChange = {
sdCardCap = it
PrefManager.sdCardCap = it
}
)
}

if (useExternalStorage) {
// Currently selected item
var selectedIndex by rememberSaveable {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@
<string name="settings_interface_icon_style">Icon style</string>
<string name="settings_interface_wifi_only_title">Download only over Wi-Fi</string>
<string name="settings_interface_wifi_only_subtitle">Prevent downloads on cellular data</string>
<string name="settings_interface_sd_card_cap_title">Optimize downloads for external storage</string>
<string name="settings_interface_sd_card_cap_subtitle">May improve performance and stability when downloading to SD cards</string>
<string name="settings_interface_external_storage_title">Write to external storage</string>
<string name="settings_interface_no_external_storage">No external storage detected</string>
<string name="settings_interface_external_storage_subtitle">Save games to external storage</string>
Expand Down