-
-
Notifications
You must be signed in to change notification settings - Fork 210
refactor: Moved Proton downloading to launch deps (again, but mirroring original behaviour + tests) #1052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
utkarshdalal
merged 4 commits into
utkarshdalal:master
from
unbelievableflavour:proton-mirror-previous
Apr 16, 2026
Merged
refactor: Moved Proton downloading to launch deps (again, but mirroring original behaviour + tests) #1052
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3fcfdeb
Reapply "Refactored default Proton downloads to launch deps" (#1050)
unbelievableflavour 0ca8233
Moved proton download to original location by moving launch deps call
unbelievableflavour 795180c
Removed deletion since previously we didnt do that either.
unbelievableflavour 2c604d1
Added test for new launch dep
unbelievableflavour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
app/src/main/java/app/gamenative/utils/launchdependencies/BionicDefaultProtonDependency.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package app.gamenative.utils.launchdependencies | ||
|
|
||
| import android.content.Context | ||
| import app.gamenative.data.GameSource | ||
| import app.gamenative.service.SteamService | ||
| import app.gamenative.utils.LOADING_PROGRESS_UNKNOWN | ||
| import com.winlator.container.Container | ||
| import com.winlator.core.TarCompressorUtils | ||
| import com.winlator.xenvironment.ImageFs | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.coroutineScope | ||
| import kotlinx.coroutines.withContext | ||
| import timber.log.Timber | ||
| import java.io.File | ||
|
|
||
| /** | ||
| * Ensures Proton (arm64ec or x86_64) is downloaded and extracted into opt/<wineVersion> for Bionic. | ||
| * Only runs when container variant is BIONIC and wine version is proton-9.0-arm64ec or proton-9.0-x86_64. | ||
| */ | ||
| object BionicDefaultProtonDependency : LaunchDependency { | ||
| override fun appliesTo(container: Container, gameSource: GameSource, gameId: Int): Boolean { | ||
| if (container.containerVariant != Container.BIONIC) return false | ||
| val v = container.wineVersion | ||
| return v.contains("proton-9.0-arm64ec") || v.contains("proton-9.0-x86_64") | ||
| } | ||
|
|
||
| override fun isSatisfied(context: Context, container: Container, gameSource: GameSource, gameId: Int): Boolean { | ||
| val protonVersion = container.wineVersion | ||
| val outFile = File(ImageFs.find(context).getRootDir(), "opt/$protonVersion") | ||
| val binDir = File(outFile, "bin") | ||
| return binDir.exists() && binDir.isDirectory | ||
| } | ||
|
|
||
| override fun getLoadingMessage(context: Context, container: Container, gameSource: GameSource, gameId: Int): String { | ||
| return when { | ||
| container.wineVersion.contains("proton-9.0-arm64ec") -> "Downloading arm64ec Proton" | ||
| container.wineVersion.contains("proton-9.0-x86_64") -> "Downloading x86_64 Proton" | ||
| else -> "Extracting Proton" | ||
| } | ||
| } | ||
|
|
||
| override suspend fun install( | ||
| context: Context, | ||
| container: Container, | ||
| callbacks: LaunchDependencyCallbacks, | ||
| gameSource: GameSource, | ||
| gameId: Int, | ||
| ) = coroutineScope { | ||
| val protonVersion = container.wineVersion | ||
| val imageFs = withContext(Dispatchers.IO) { ImageFs.find(context) } | ||
| val archiveName = when { | ||
| protonVersion.contains("proton-9.0-arm64ec") -> "proton-9.0-arm64ec.txz" | ||
| protonVersion.contains("proton-9.0-x86_64") -> "proton-9.0-x86_64.txz" | ||
| else -> return@coroutineScope | ||
| } | ||
|
|
||
| if (!withContext(Dispatchers.IO) { SteamService.isFileInstallable(context, archiveName) }) { | ||
| callbacks.setLoadingMessage("Downloading $protonVersion") | ||
| withContext(Dispatchers.IO) { | ||
| SteamService.downloadFile( | ||
| onDownloadProgress = { callbacks.setLoadingProgress(it) }, | ||
| parentScope = this@coroutineScope, | ||
| context = context, | ||
| fileName = archiveName, | ||
| ).await() | ||
|
unbelievableflavour marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| val outFile = File(ImageFs.find(context).getRootDir(), "opt/$protonVersion") | ||
| val binDir = File(outFile, "bin") | ||
| val needsExtract = withContext(Dispatchers.IO) { !binDir.exists() || !binDir.isDirectory } | ||
| if (needsExtract) { | ||
| Timber.i("Extracting $protonVersion to ${outFile.absolutePath}") | ||
| callbacks.setLoadingMessage("Extracting $protonVersion") | ||
| callbacks.setLoadingProgress(LOADING_PROGRESS_UNKNOWN) | ||
| val downloaded = File(imageFs.getFilesDir(), archiveName) | ||
| withContext(Dispatchers.IO) { | ||
| val success = TarCompressorUtils.extract( | ||
| TarCompressorUtils.Type.XZ, | ||
| downloaded, | ||
| outFile, | ||
| ) | ||
| if (!success) { | ||
| throw IllegalStateException("Failed to extract $protonVersion from ${downloaded.absolutePath}") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
170 changes: 170 additions & 0 deletions
170
...rc/test/java/app/gamenative/utils/launchdependencies/BionicDefaultProtonDependencyTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| package app.gamenative.utils.launchdependencies | ||
|
|
||
| import android.content.Context | ||
| import androidx.test.core.app.ApplicationProvider | ||
| import app.gamenative.data.GameSource | ||
| import app.gamenative.service.SteamService | ||
| import com.winlator.container.Container | ||
| import com.winlator.core.TarCompressorUtils | ||
| import com.winlator.xenvironment.ImageFs | ||
| import io.mockk.coEvery | ||
| import io.mockk.every | ||
| import io.mockk.mockk | ||
| import io.mockk.mockkObject | ||
| import io.mockk.mockkStatic | ||
| import io.mockk.slot | ||
| import io.mockk.unmockkAll | ||
| import io.mockk.verify | ||
| import kotlinx.coroutines.Deferred | ||
| import kotlinx.coroutines.runBlocking | ||
| import org.junit.After | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertFalse | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
| import java.io.File | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| class BionicDefaultProtonDependencyTest { | ||
| private lateinit var context: Context | ||
| private lateinit var container: Container | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| context = ApplicationProvider.getApplicationContext() | ||
| container = mockk(relaxed = true) | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| unmockkAll() | ||
| } | ||
|
|
||
| @Test | ||
| fun appliesTo_returnsFalse_whenContainerIsNotBionic() { | ||
| every { container.containerVariant } returns "glibc" | ||
| every { container.wineVersion } returns "proton-9.0-arm64ec" | ||
|
|
||
| val result = BionicDefaultProtonDependency.appliesTo(container, GameSource.STEAM, 1) | ||
|
|
||
| assertFalse(result) | ||
| } | ||
|
|
||
| @Test | ||
| fun appliesTo_returnsTrue_whenBionicAndSupportedProtonVersion() { | ||
| every { container.containerVariant } returns Container.BIONIC | ||
| every { container.wineVersion } returns "proton-9.0-arm64ec" | ||
|
|
||
| val armResult = BionicDefaultProtonDependency.appliesTo(container, GameSource.STEAM, 2) | ||
|
|
||
| every { container.wineVersion } returns "proton-9.0-x86_64" | ||
| val x64Result = BionicDefaultProtonDependency.appliesTo(container, GameSource.STEAM, 3) | ||
|
|
||
| assertTrue(armResult) | ||
| assertTrue(x64Result) | ||
| } | ||
|
|
||
| @Test | ||
| fun isSatisfied_returnsTrue_whenProtonBinDirectoryExists() { | ||
| every { container.wineVersion } returns "proton-9.0-arm64ec" | ||
|
|
||
| val imageFsRoot = ImageFs.find(context).rootDir | ||
| val binDir = File(imageFsRoot, "opt/proton-9.0-arm64ec/bin") | ||
| binDir.mkdirs() | ||
|
|
||
| val result = BionicDefaultProtonDependency.isSatisfied(context, container, GameSource.STEAM, 4) | ||
|
|
||
| assertTrue(result) | ||
| } | ||
|
|
||
| @Test | ||
| fun getLoadingMessage_returnsExpectedMessagePerVersion() { | ||
| every { container.wineVersion } returns "proton-9.0-arm64ec" | ||
| val armMessage = BionicDefaultProtonDependency.getLoadingMessage(context, container, GameSource.STEAM, 5) | ||
|
|
||
| every { container.wineVersion } returns "proton-9.0-x86_64" | ||
| val x64Message = BionicDefaultProtonDependency.getLoadingMessage(context, container, GameSource.STEAM, 6) | ||
|
|
||
| every { container.wineVersion } returns "wine-ge-custom" | ||
| val fallbackMessage = BionicDefaultProtonDependency.getLoadingMessage(context, container, GameSource.STEAM, 7) | ||
|
|
||
| assertEquals("Downloading arm64ec Proton", armMessage) | ||
| assertEquals("Downloading x86_64 Proton", x64Message) | ||
| assertEquals("Extracting Proton", fallbackMessage) | ||
| } | ||
|
|
||
| @Test | ||
| fun install_returnsEarly_whenProtonVersionIsUnsupported() = runBlocking { | ||
| every { container.wineVersion } returns "wine-ge-custom" | ||
| mockkObject(SteamService.Companion) | ||
| mockkStatic(TarCompressorUtils::class) | ||
|
|
||
| BionicDefaultProtonDependency.install( | ||
| context = context, | ||
| container = container, | ||
| callbacks = LaunchDependencyCallbacks({}, {}), | ||
| gameSource = GameSource.STEAM, | ||
| gameId = 8, | ||
| ) | ||
|
|
||
| verify(exactly = 0) { | ||
| SteamService.downloadFile( | ||
| onDownloadProgress = any(), | ||
| parentScope = any(), | ||
| context = any(), | ||
| fileName = any(), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun install_downloadsArchive_andForwardsProgress() = runBlocking { | ||
| every { container.wineVersion } returns "proton-9.0-arm64ec" | ||
| mockkObject(SteamService.Companion) | ||
|
|
||
| val imageFsRoot = ImageFs.find(context).rootDir | ||
| val binDir = File(imageFsRoot, "opt/proton-9.0-arm64ec/bin") | ||
| binDir.mkdirs() | ||
|
|
||
| every { SteamService.isFileInstallable(context, "proton-9.0-arm64ec.txz") } returns false | ||
|
|
||
| val onProgressSlot = slot<(Float) -> Unit>() | ||
| val deferred = mockk<Deferred<Unit>>() | ||
| every { | ||
| SteamService.downloadFile( | ||
| onDownloadProgress = capture(onProgressSlot), | ||
| parentScope = any(), | ||
| context = context, | ||
| fileName = "proton-9.0-arm64ec.txz", | ||
| ) | ||
| } returns deferred | ||
| coEvery { deferred.await() } returns Unit | ||
|
|
||
| val progressValues = mutableListOf<Float>() | ||
| BionicDefaultProtonDependency.install( | ||
| context = context, | ||
| container = container, | ||
| callbacks = LaunchDependencyCallbacks( | ||
| setLoadingMessage = {}, | ||
| setLoadingProgress = { progressValues += it }, | ||
| ), | ||
| gameSource = GameSource.STEAM, | ||
| gameId = 9, | ||
| ) | ||
|
|
||
| onProgressSlot.captured(0.42f) | ||
|
|
||
| verify(exactly = 1) { | ||
| SteamService.downloadFile( | ||
| onDownloadProgress = any(), | ||
| parentScope = any(), | ||
| context = context, | ||
| fileName = "proton-9.0-arm64ec.txz", | ||
| ) | ||
| } | ||
| assertEquals(listOf(0.42f), progressValues) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.