mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
feat: Epic Games Launcher for Linux (#928)
* feat: Epic Games Launcher for Linux Install Epic's official Linux launcher (EGLv2) from Epic's CDN with Valve's Steam Runtime 4 and run it under FEX, signed in with the linked Epic account. Epic games launch through a hidden launcher instance so they get the launcher's own arguments, with the exchange-code launch as the fallback, and DroidDeck installs show up in the launcher as installed. In the launcher, touch scrolls like a phone app and the gamepad drives the UI: D-pad and left stick move the selection, A opens, B goes back, the right stick and triggers scroll proportionally, X opens the options menu, Y the keyboard and LB/RB switch tabs. * feat: Epic Games Launcher for Linux Install Epic's official Linux launcher (EGLv2) from Epic's CDN with Valve's Steam Runtime 4 and run it under FEX, signed in with the linked Epic account. Epic games launch through a hidden launcher instance so they get the launcher's own arguments, with the exchange-code launch as the fallback, and DroidDeck installs show up in the launcher as installed. In the launcher, touch scrolls like a phone app and the gamepad drives the UI: D-pad and left stick move the selection, A opens, B goes back, the right stick and triggers scroll proportionally, X opens the options menu, Y the keyboard and LB/RB switch tabs. * Route Epic games through Steam, import launcher installs, offer the second library - Every Epic launch goes Steam -> Epic Games Launcher -> game; Play inside the open launcher hands the game to Steam - Games installed from inside the launcher get a Games-tab entry and launch through Steam; the launcher installs to the last Stores target - Stores install picker offers the Steam second library, with side-by-side choices - uruntime xattr-only failures no longer fail the launcher unpack (app-extract) * Hand launcher Play and Steam links to Steam, wait for FEX on first run Play on a game the launcher just installed is matched to its install record and handed to Steam. Steam games listed in the launcher open steam://rungameid links, which now start the game in a Steam session. Opening the launcher before Steam has downloaded FEX asks Steam for it and starts Steam instead of failing with no-fex. * Address review: FEX check, play-in-Steam action, touch route thread, scroll scale fexReady needs a FEX binary in Steam's FEX tool, not just its folder. The play-in-Steam action stays until the link is handled, so Run Steam at startup can't start a session first. The pad touch route reads the mouse mode without side effects off the main thread and posts the pad update there. Vertical scroll uses the output height. A status-2 unpack counts only when AppRun is there. The xdg-open command is tested end to end for Steam links. * Open the launcher through Steam, recover dropped shortcuts, sign out of both The Epic Games Launcher now runs as its own Steam shortcut, so opening it starts Steam, which opens the launcher, and Play inside it goes to the running Steam. Steam dropped a running shortcut from its library when the game exited after a sleep/wake replay or a server re-logon, and launching it then waited forever at ShowInterstitials. login1 only replays sleep/wake when Steam is asleep. The session restarts Steam when a requested shortcut is missing, and when a game exits with its shortcut gone and nothing else runs. Resuming after a long pause no longer reports failure while traced processes are still waking, so "Steam is paused" goes away on the first tap. Signing out of the launcher signs DroidDeck's Epic store out, and signing out in DroidDeck restarts the launcher signed out and clears the Epic web cookies. * Address review: one session-switch poll, Epic setup can't block a session A new switch confirmation replaces the pending poll instead of adding a second one that could start the session again. Epic library sync and install-folder setup at session start are each guarded, so a bad preference no longer stops the guest from launching. * Uninstall the Epic Games Launcher from the Games tab An Uninstall button next to Launch asks first, closes a running session, and removes the launcher and its runtime. The launcher's sign-in and install records stay, so its games keep their Games-tab entries and a reinstall comes back signed in. Its Steam shortcut goes away on the next Steam start. * Address review: uninstall only after the session has ended The launcher's files are removed only once the session is not running and its phase has ended; a shutdown still in progress after the wait reports failure instead. The confirmation reads the session state from the front-end state. * Find FEX that Steam installed on the second library Steam's tools on a second library live in DroidDeck's private copy, which the session binds over the library. The launcher's FEX check only looked on the shared storage, so with FEX there it always asked Steam for FEX and only Steam opened. It now checks the private copy too. * Start games without Steam, per-game Settings menu with Wine sync "Start without Steam" now really leaves the Steam client out: the game runs in its own Proton/FEX through droiddeck-proton-run in a run session, and the Epic Games Launcher opens on its own with its games playing in it. Run sessions for these games are not pinned to the big cores and get DirectAudio and the added-games list like Steam. The Games tab card is now "Settings", titled "<game> Settings": Start without Steam, FEX preset, Wine sync (ntsync, fsync, esync, wineserver or the app default) and Default, which puts everything changed for the game back to the app's settings. The app-wide Wine sync choice is shown in the Steam settings Session tab. * Address review: uninstall guard, routed games, shortcut matching Opening or reinstalling the Epic Games Launcher waits while it is being uninstalled. Added games that are Steam installs keep their Start without Steam setting under their Steam app id and start as that Steam game. Live shortcut lookups wait for Steam's library to load and match a same-name shortcut by its executable, so no duplicate is added. The session treats the open launcher as itself even when it could not tell its Steam app id. * Address review: drop a queued launcher switch when it is uninstalled A confirmed switch to the Epic Games Launcher that is still waiting for the old session to end is cancelled when the launcher is uninstalled, and never starts while the uninstall runs. The launcher id test sets its environment for its own runs only.
This commit is contained in:
1 parent
83eda433c8
commit
97f976ef6c
107 files changed
+8860
-371
No files matched your search
@@ -122,4 +122,26 @@ class GameEnvironmentTest {
|
||||
assertEquals("value", compatibility.games.getValue("42")["CUSTOM"])
|
||||
assertEquals("COMPATIBILITY", GameEnvironment.gameFexPreset(compatibility, "42"))
|
||||
}
|
||||
|
||||
@Test fun gameSyncChoiceMatchesTheAppWideChoiceAndCanInheritAgain() {
|
||||
val base = GameEnvironment.Config(games = mapOf("42" to mapOf("FEX_TSOENABLED" to "1", "PROTON_NO_ESYNC" to "1")))
|
||||
assertEquals(GameEnvironment.CUSTOM_SYNC, GameEnvironment.gameSync(base, "42"))
|
||||
assertNull(GameEnvironment.gameSync(base, "43"))
|
||||
for (backend in GameEnvironment.syncBackends) {
|
||||
val chosen = GameEnvironment.withGameSync(base, "42", backend)
|
||||
assertEquals(backend, GameEnvironment.gameSync(chosen, "42"))
|
||||
assertEquals("1", chosen.games["42"]!!["FEX_TSOENABLED"])
|
||||
}
|
||||
val ntsync = GameEnvironment.withGameSync(base, "42", "ntsync").games["42"]!!
|
||||
assertEquals(listOf("1", "0", "1"), listOf(ntsync["BL_SYNC"], ntsync["BL_FSYNC_FIRST"], ntsync["BL_SYNC_FALLBACK"]))
|
||||
assertFalse(ntsync.containsKey("PROTON_NO_ESYNC"))
|
||||
val fsync = GameEnvironment.withGameSync(base, "42", "fsync").games["42"]!!
|
||||
assertEquals(listOf("0", "1", "1", "1"), listOf(fsync["BL_SYNC"], fsync["BL_FSYNC_FIRST"], fsync["BL_SYNC_FALLBACK"], fsync["PROTON_NO_ESYNC"]))
|
||||
val wineserver = GameEnvironment.withGameSync(base, "42", "wineserver").games["42"]!!
|
||||
assertEquals(listOf("0", "0", "0"), listOf(wineserver["BL_SYNC"], wineserver["BL_FSYNC_FIRST"], wineserver["BL_SYNC_FALLBACK"]))
|
||||
val inherited = GameEnvironment.withGameSync(base, "42", null)
|
||||
assertNull(GameEnvironment.gameSync(inherited, "42"))
|
||||
assertEquals(mapOf("FEX_TSOENABLED" to "1"), inherited.games["42"])
|
||||
assertTrue(GameEnvironment.withGameSync(GameEnvironment.Config(), "42", null).games.isEmpty())
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,23 @@ class AddedGamesStoreScanTest {
|
||||
assertEquals(Store.EPIC.id, game.source)
|
||||
}
|
||||
|
||||
@Test fun anEpicGameAlwaysUsesItsLauncherWrapperEvenAfterAnExeIsPicked() {
|
||||
val folder = install(Store.EPIC, "picked", "Picked Epic", "Binaries/Game.exe", launcher = true)
|
||||
AddedExes.put(app, AddedExes.Entry(folder.path, File(folder, "Binaries/Game.exe").path, picked = true))
|
||||
val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath }
|
||||
assertEquals("Binaries/Game.exe", game.exe.relativeTo(folder).path)
|
||||
assertTrue(game.guestExe.endsWith("/" + StoreLaunch.LAUNCHER))
|
||||
}
|
||||
|
||||
@Test fun aDifferentPickedExeOnAnEpicGameIsRunDirectly() {
|
||||
val folder = install(Store.EPIC, "other", "Other Epic", "Binaries/Game.exe", launcher = true)
|
||||
val tool = File(folder, "Tools/Editor.exe").apply { parentFile!!.mkdirs(); writeText("tool") }
|
||||
AddedExes.put(app, AddedExes.Entry(folder.path, tool.path, picked = true))
|
||||
val game = AddedGames.scan(app).single { it.folder.absolutePath == folder.absolutePath }
|
||||
assertEquals("Tools/Editor.exe", game.exe.relativeTo(folder).path)
|
||||
assertTrue(game.guestExe.endsWith("/Tools/Editor.exe"))
|
||||
}
|
||||
|
||||
@Test fun anOlderSidecarsSteamSwitchIsIgnoredEveryInstallIsListed() {
|
||||
val folder = install(Store.AMAZON, "amzn1.adg.product.x", "Yakuza 0", "Yakuza0.exe")
|
||||
val file = StoreGameSidecar.file(folder)
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
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 org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class PadMouseTest {
|
||||
private val events = mutableListOf<String>()
|
||||
private var scrolledX = 0f
|
||||
private var scrolledY = 0f
|
||||
private var now = 1000L
|
||||
private lateinit var pad: PadMouse
|
||||
|
||||
private val listener = object : PadMouse.Listener {
|
||||
override fun active() = true
|
||||
override fun onScrollStart() { events += "scroll start" }
|
||||
override fun onScroll(dx: Float, dy: Float) {
|
||||
scrolledX += dx
|
||||
scrolledY += dy
|
||||
}
|
||||
override fun onKey(evdev: Int, pressed: Boolean) { events += "key $evdev ${if (pressed) "down" else "up"}" }
|
||||
override fun onKeyboard() { events += "keyboard" }
|
||||
override fun onNavigate() {}
|
||||
override fun scrollSpeed() = 2000f
|
||||
}
|
||||
|
||||
@Before fun setUp() {
|
||||
pad = PadMouse(listener) { now }
|
||||
}
|
||||
|
||||
@Test fun aOpensTheSelection() {
|
||||
key(KeyEvent.KEYCODE_BUTTON_A, true)
|
||||
key(KeyEvent.KEYCODE_BUTTON_A, false)
|
||||
key(KeyEvent.KEYCODE_DPAD_DOWN, true)
|
||||
key(KeyEvent.KEYCODE_DPAD_DOWN, false)
|
||||
key(KeyEvent.KEYCODE_BUTTON_A, true)
|
||||
key(KeyEvent.KEYCODE_BUTTON_A, false)
|
||||
assertEquals(listOf("key 28 down", "key 28 up", "key 108 down", "key 108 up", "key 28 down", "key 28 up"), events)
|
||||
}
|
||||
|
||||
@Test fun rightStickScrollsByHowFarItIsPushedThenSettlesTheSelection() {
|
||||
motion(rightY = 0.5f)
|
||||
pad.step(0.1f)
|
||||
assertEquals(33.9f, scrolledY, 0.1f)
|
||||
motion(rightY = 1f, rightX = -1f)
|
||||
pad.step(0.1f)
|
||||
assertEquals(175.3f, scrolledY, 0.1f)
|
||||
assertEquals(-141.4f, scrolledX, 0.1f)
|
||||
motion()
|
||||
pad.step(0.1f)
|
||||
pad.step(0.1f)
|
||||
assertEquals(listOf("scroll start", "key 183 down", "key 183 up"), events)
|
||||
}
|
||||
|
||||
@Test fun eachControllerKeepsItsOwnSticksAndButtons() {
|
||||
motion(rightY = 1f, device = 1)
|
||||
motion(device = 2)
|
||||
pad.step(0.1f)
|
||||
assertEquals(200f, scrolledY, 0.01f)
|
||||
key(KeyEvent.KEYCODE_BUTTON_A, true, device = 1)
|
||||
key(KeyEvent.KEYCODE_BUTTON_A, true, device = 2)
|
||||
key(KeyEvent.KEYCODE_BUTTON_A, false, device = 2)
|
||||
assertEquals(listOf("scroll start", "key 28 down"), events)
|
||||
key(KeyEvent.KEYCODE_BUTTON_A, false, device = 1)
|
||||
assertEquals(listOf("scroll start", "key 28 down", "key 28 up"), events)
|
||||
}
|
||||
|
||||
@Test fun resetLetsGoOfAHeldModifierAndTheNextPressWorks() {
|
||||
key(KeyEvent.KEYCODE_BUTTON_L1, true)
|
||||
pad.reset()
|
||||
key(KeyEvent.KEYCODE_BUTTON_L1, false)
|
||||
key(KeyEvent.KEYCODE_BUTTON_Y, true)
|
||||
pad.reset()
|
||||
key(KeyEvent.KEYCODE_BUTTON_Y, true)
|
||||
assertEquals(listOf("key 29 down", "key 104 down", "key 104 up", "key 29 up", "keyboard", "keyboard"), events)
|
||||
}
|
||||
|
||||
@Test fun leftStickMovesFromHalfway() {
|
||||
motion(leftX = 0.45f)
|
||||
pad.step(0.016f)
|
||||
motion(leftX = 0.55f)
|
||||
pad.step(0.016f)
|
||||
assertEquals(listOf("key 106 down", "key 106 up"), events)
|
||||
}
|
||||
|
||||
@Test fun otherButtons() {
|
||||
for (code in listOf(KeyEvent.KEYCODE_BUTTON_X, KeyEvent.KEYCODE_BUTTON_B, KeyEvent.KEYCODE_BUTTON_START,
|
||||
KeyEvent.KEYCODE_BUTTON_L1, KeyEvent.KEYCODE_BUTTON_R1)) {
|
||||
key(code, true)
|
||||
key(code, false)
|
||||
}
|
||||
assertEquals(listOf("key 127 down", "key 127 up", "key 1 down", "key 158 down", "key 158 up", "key 1 up", "key 28 down", "key 28 up",
|
||||
"key 29 down", "key 104 down", "key 104 up", "key 29 up", "key 29 down", "key 109 down", "key 109 up", "key 29 up"), events)
|
||||
}
|
||||
|
||||
@Test fun yOpensTheKeyboardOnce() {
|
||||
key(KeyEvent.KEYCODE_BUTTON_Y, true)
|
||||
pad.onKey(KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_Y, 1))
|
||||
key(KeyEvent.KEYCODE_BUTTON_Y, false)
|
||||
assertEquals(listOf("keyboard"), events)
|
||||
}
|
||||
|
||||
@Test fun guideAndSelectStayWithTheGamepad() {
|
||||
assertFalse(pad.onKey(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_MODE)))
|
||||
assertFalse(pad.onKey(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_SELECT)))
|
||||
assertTrue(pad.onKey(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_R2)))
|
||||
assertEquals(emptyList<String>(), events)
|
||||
}
|
||||
|
||||
@Test fun dpadKeysAndHatShareOnePress() {
|
||||
key(KeyEvent.KEYCODE_DPAD_RIGHT, true)
|
||||
motion(hatX = 1f)
|
||||
key(KeyEvent.KEYCODE_DPAD_RIGHT, false)
|
||||
motion()
|
||||
motion(hatY = -1f)
|
||||
motion()
|
||||
assertEquals(listOf("key 106 down", "key 106 up", "key 103 down", "key 103 up"), events)
|
||||
}
|
||||
|
||||
@Test fun heldDpadRepeatsAtTheMenuPace() {
|
||||
key(KeyEvent.KEYCODE_DPAD_RIGHT, true)
|
||||
pad.step(0.016f)
|
||||
now += 299
|
||||
pad.step(0.016f)
|
||||
now += 1
|
||||
pad.step(0.016f)
|
||||
now += 120
|
||||
pad.step(0.016f)
|
||||
key(KeyEvent.KEYCODE_DPAD_RIGHT, false)
|
||||
pad.step(0.016f)
|
||||
now += 1000
|
||||
pad.step(0.016f)
|
||||
assertEquals(List(3) { listOf("key 106 down", "key 106 up") }.flatten(), events)
|
||||
}
|
||||
|
||||
@Test fun leftStickStepsThroughItemsAndRepeats() {
|
||||
motion(leftY = 1f)
|
||||
pad.step(0.016f)
|
||||
pad.step(0.016f)
|
||||
now += 400
|
||||
pad.step(0.016f)
|
||||
now += 100
|
||||
pad.step(0.016f)
|
||||
now += 50
|
||||
pad.step(0.016f)
|
||||
motion()
|
||||
pad.step(0.016f)
|
||||
motion(leftX = -0.3f)
|
||||
pad.step(0.016f)
|
||||
assertEquals(listOf("key 108 down", "key 108 up", "key 108 down", "key 108 up", "key 108 down", "key 108 up"), events)
|
||||
}
|
||||
|
||||
@Test fun touchPadDrivesTheSameMapping() {
|
||||
val state = PadState()
|
||||
state.press(PadState.A, true)
|
||||
pad.onTouchPad(state)
|
||||
state.press(PadState.A, false)
|
||||
state.down = true
|
||||
pad.onTouchPad(state)
|
||||
state.down = false
|
||||
state.rightTrigger = 1f
|
||||
pad.onTouchPad(state)
|
||||
pad.step(0.1f)
|
||||
assertEquals(listOf("key 28 down", "key 28 up", "key 108 down", "key 108 up", "scroll start"), events)
|
||||
assertEquals(200f, scrolledY, 0.01f)
|
||||
}
|
||||
|
||||
@Test fun resetReleasesEverythingHeld() {
|
||||
key(KeyEvent.KEYCODE_BUTTON_X, true)
|
||||
key(KeyEvent.KEYCODE_DPAD_DOWN, true)
|
||||
pad.reset()
|
||||
key(KeyEvent.KEYCODE_DPAD_DOWN, false)
|
||||
assertEquals(listOf("key 127 down", "key 108 down", "key 108 up", "key 127 up"), events)
|
||||
}
|
||||
|
||||
@Test fun stickCurveIsGentleNearTheMiddle() {
|
||||
val (half, _) = PadMouse.curve(0.575f, 0f)
|
||||
assertEquals(0.25f, half, 0.01f)
|
||||
assertEquals(0f to 0f, PadMouse.curve(0.1f, 0.1f))
|
||||
}
|
||||
|
||||
@Test fun triggersScroll() {
|
||||
motion(rightTrigger = 1f)
|
||||
pad.step(0.1f)
|
||||
assertEquals(200f, scrolledY, 0.01f)
|
||||
motion(leftTrigger = 1f)
|
||||
pad.step(0.1f)
|
||||
assertEquals(0f, scrolledY, 0.01f)
|
||||
motion()
|
||||
pad.step(0.1f)
|
||||
assertEquals(listOf("scroll start", "key 183 down", "key 183 up"), events)
|
||||
}
|
||||
|
||||
private fun key(code: Int, down: Boolean, device: Int = 0) {
|
||||
val action = if (down) KeyEvent.ACTION_DOWN else KeyEvent.ACTION_UP
|
||||
assertTrue(pad.onKey(KeyEvent(0, 0, action, code, 0, 0, device, 0)))
|
||||
}
|
||||
|
||||
private fun motion(leftX: Float = 0f, leftY: Float = 0f, rightX: Float = 0f, rightY: Float = 0f, hatX: Float = 0f, hatY: Float = 0f,
|
||||
leftTrigger: Float = 0f, rightTrigger: Float = 0f, device: Int = 0) {
|
||||
val properties = arrayOf(MotionEvent.PointerProperties().apply { id = 0; toolType = MotionEvent.TOOL_TYPE_UNKNOWN })
|
||||
val coords = arrayOf(MotionEvent.PointerCoords().apply {
|
||||
setAxisValue(MotionEvent.AXIS_X, leftX)
|
||||
setAxisValue(MotionEvent.AXIS_Y, leftY)
|
||||
setAxisValue(MotionEvent.AXIS_Z, rightX)
|
||||
setAxisValue(MotionEvent.AXIS_RZ, rightY)
|
||||
setAxisValue(MotionEvent.AXIS_HAT_X, hatX)
|
||||
setAxisValue(MotionEvent.AXIS_HAT_Y, hatY)
|
||||
setAxisValue(MotionEvent.AXIS_LTRIGGER, leftTrigger)
|
||||
setAxisValue(MotionEvent.AXIS_RTRIGGER, rightTrigger)
|
||||
})
|
||||
val event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 1, properties, coords, 0, 0, 1f, 1f, device, 0,
|
||||
android.view.InputDevice.SOURCE_JOYSTICK, 0)
|
||||
pad.onMotion(event)
|
||||
event.recycle()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Looper
|
||||
import android.view.MotionEvent
|
||||
import java.time.Duration
|
||||
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 org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [28], manifest = Config.NONE)
|
||||
class ScrollTouchGesturesTest {
|
||||
private val events = mutableListOf<String>()
|
||||
private var scrolledX = 0f
|
||||
private var scrolledY = 0f
|
||||
private lateinit var gestures: ScrollTouchGestures
|
||||
private var time = 1000L
|
||||
private var downTime = 0L
|
||||
|
||||
private val listener = object : ScrollTouchGestures.Listener {
|
||||
override fun onMove(x: Float, y: Float) { events += "move ${x.toInt()},${y.toInt()}" }
|
||||
override fun onButton(button: Int, pressed: Boolean) {
|
||||
val name = if (button == PointerGestures.BTN_RIGHT) "right" else "left"
|
||||
events += "$name ${if (pressed) "down" else "up"}"
|
||||
}
|
||||
override fun onScroll(dx: Float, dy: Float) {
|
||||
scrolledX += dx
|
||||
scrolledY += dy
|
||||
}
|
||||
override fun onLongPress() { events += "long press" }
|
||||
}
|
||||
|
||||
@Before fun setUp() {
|
||||
gestures = ScrollTouchGestures(SLOP, MIN_FLING, listener)
|
||||
}
|
||||
|
||||
@Test fun tapClicksWhereTheFingerIs() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
|
||||
advance(80)
|
||||
touch(MotionEvent.ACTION_UP, 400f, 300f)
|
||||
advance(100)
|
||||
assertEquals(listOf("move 400,300", "left down", "left up"), events)
|
||||
}
|
||||
|
||||
@Test fun draggingScrollsWithTheFingerAndNeverClicks() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 800f)
|
||||
advance(200)
|
||||
touch(MotionEvent.ACTION_MOVE, 403f, 600f)
|
||||
advance(200)
|
||||
touch(MotionEvent.ACTION_MOVE, 405f, 300f)
|
||||
advance(200)
|
||||
touch(MotionEvent.ACTION_UP, 405f, 300f)
|
||||
advance(100)
|
||||
assertEquals(500f, scrolledY, 0.01f)
|
||||
assertEquals(0f, scrolledX, 0.01f)
|
||||
assertEquals(listOf("move 400,800"), events)
|
||||
}
|
||||
|
||||
@Test fun sidewaysDragScrollsSideways() {
|
||||
touch(MotionEvent.ACTION_DOWN, 900f, 400f)
|
||||
advance(200)
|
||||
touch(MotionEvent.ACTION_MOVE, 600f, 410f)
|
||||
advance(200)
|
||||
touch(MotionEvent.ACTION_UP, 600f, 410f)
|
||||
assertEquals(300f, scrolledX, 0.01f)
|
||||
assertEquals(0f, scrolledY, 0.01f)
|
||||
}
|
||||
|
||||
@Test fun quickSwipeKeepsScrollingAfterLiftingAndATapStopsIt() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 900f)
|
||||
advance(16)
|
||||
touch(MotionEvent.ACTION_MOVE, 400f, 800f)
|
||||
advance(16)
|
||||
touch(MotionEvent.ACTION_MOVE, 400f, 700f)
|
||||
advance(16)
|
||||
touch(MotionEvent.ACTION_UP, 400f, 600f)
|
||||
val lifted = scrolledY
|
||||
repeat(3) { shadowOf(Looper.getMainLooper()).runOneTask() }
|
||||
assertTrue(scrolledY > lifted)
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
|
||||
val stopped = scrolledY
|
||||
advance(80)
|
||||
touch(MotionEvent.ACTION_UP, 400f, 300f)
|
||||
advance(500)
|
||||
assertEquals(stopped, scrolledY, 0.01f)
|
||||
assertFalse(events.contains("left down"))
|
||||
}
|
||||
|
||||
@Test fun longPressRightClicks() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
|
||||
advance(600)
|
||||
touch(MotionEvent.ACTION_UP, 402f, 301f)
|
||||
advance(100)
|
||||
assertEquals(listOf("move 400,300", "long press", "right down", "right up"), events)
|
||||
}
|
||||
|
||||
@Test fun longPressThenMoveDragsWithTheLeftButton() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
|
||||
advance(600)
|
||||
touch(MotionEvent.ACTION_MOVE, 500f, 300f)
|
||||
advance(50)
|
||||
touch(MotionEvent.ACTION_UP, 500f, 300f)
|
||||
assertEquals(listOf("move 400,300", "long press", "left down", "move 500,300", "left up"), events)
|
||||
assertEquals(0f, scrolledY, 0.01f)
|
||||
}
|
||||
|
||||
@Test fun cancelReleasesAHeldDrag() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
|
||||
advance(600)
|
||||
touch(MotionEvent.ACTION_MOVE, 500f, 300f)
|
||||
gestures.cancel()
|
||||
assertEquals("left up", events.last())
|
||||
events.clear()
|
||||
touch(MotionEvent.ACTION_UP, 500f, 300f)
|
||||
advance(100)
|
||||
assertEquals(emptyList<String>(), events)
|
||||
}
|
||||
|
||||
@Test fun aLiftAfterACancelDoesNotClick() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 300f)
|
||||
advance(50)
|
||||
gestures.cancel()
|
||||
touch(MotionEvent.ACTION_UP, 400f, 300f)
|
||||
advance(100)
|
||||
assertEquals(listOf("move 400,300"), events)
|
||||
}
|
||||
|
||||
@Test fun aSecondFingerDoesNotJumpTheScroll() {
|
||||
touch(MotionEvent.ACTION_DOWN, 400f, 900f)
|
||||
advance(100)
|
||||
touch(MotionEvent.ACTION_MOVE, 400f, 700f)
|
||||
advance(100)
|
||||
pointers(MotionEvent.ACTION_POINTER_DOWN, 1, 0 to (400f to 700f), 1 to (900f to 200f))
|
||||
advance(100)
|
||||
pointers(MotionEvent.ACTION_POINTER_UP, 0, 0 to (400f to 700f), 1 to (900f to 200f))
|
||||
advance(100)
|
||||
pointers(MotionEvent.ACTION_UP, 0, 1 to (900f to 150f))
|
||||
advance(500)
|
||||
assertEquals(200f, scrolledY, 0.01f)
|
||||
assertFalse(events.contains("left down"))
|
||||
}
|
||||
|
||||
@Test fun wheelUnitsLandOnWholePixelsOfWebKitsLineStep() {
|
||||
for (view in listOf(720, 1280)) {
|
||||
val step = kotlin.math.floor(Math.pow(view.toDouble(), 2.0 / 3.0)).toFloat()
|
||||
for (pixels in -300..300) {
|
||||
val scrolled = ScrollTouchGestures.wheelUnits(pixels, view) / 120f * step
|
||||
assertEquals(pixels, scrolled.toInt())
|
||||
}
|
||||
}
|
||||
assertEquals(0, ScrollTouchGestures.wheelUnits(0, 720))
|
||||
assertEquals(2, ScrollTouchGestures.wheelUnits(1, 720))
|
||||
assertEquals(-2, ScrollTouchGestures.wheelUnits(-1, 720))
|
||||
}
|
||||
|
||||
private fun advance(ms: Long) {
|
||||
time += ms
|
||||
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofMillis(ms))
|
||||
}
|
||||
|
||||
private fun touch(action: Int, x: Float, y: Float) {
|
||||
if (action == MotionEvent.ACTION_DOWN) downTime = time
|
||||
val event = MotionEvent.obtain(downTime, time, action, x, y, 0)
|
||||
gestures.onTouch(event)
|
||||
event.recycle()
|
||||
}
|
||||
|
||||
private fun pointers(action: Int, index: Int, vararg at: Pair<Int, Pair<Float, Float>>) {
|
||||
val properties = at.map { (id, _) ->
|
||||
MotionEvent.PointerProperties().apply { this.id = id; toolType = MotionEvent.TOOL_TYPE_FINGER }
|
||||
}.toTypedArray()
|
||||
val coords = at.map { (_, xy) ->
|
||||
MotionEvent.PointerCoords().apply { x = xy.first; y = xy.second; pressure = 1f; size = 1f }
|
||||
}.toTypedArray()
|
||||
val event = MotionEvent.obtain(downTime, time, action or (index shl MotionEvent.ACTION_POINTER_INDEX_SHIFT), at.size, properties, coords, 0, 0, 1f, 1f, 0, 0, 0, 0)
|
||||
gestures.onTouch(event)
|
||||
event.recycle()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val SLOP = 8f
|
||||
const val MIN_FLING = 50f
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [33])
|
||||
class AddedGameMoveTest {
|
||||
private val app get() = RuntimeEnvironment.getApplication()
|
||||
private val prefs get() = app.getSharedPreferences("session", Context.MODE_PRIVATE)
|
||||
private val from = "/data/root/Games/Stores/Epic/Fig"
|
||||
private val to = "/storage/emulated/0/Games/Games/Epic/Fig"
|
||||
|
||||
@Test
|
||||
fun settingsOfTheOldFolderMoveToTheNewOne() {
|
||||
val all = mapOf(
|
||||
"addedAppId:$from" to 3703311242L,
|
||||
"addedExe:$from" to "$from/Fig.exe",
|
||||
"addedExeSeen:$from" to 2,
|
||||
"addedArt:hero:$from" to "https://cdn/hero.png",
|
||||
"addedAdopted:exe:$from" to from,
|
||||
"addedAppId:$from-2" to 5L,
|
||||
"addedName:/other" to "Other",
|
||||
"theme" to "graphite",
|
||||
)
|
||||
assertEquals(
|
||||
mapOf(
|
||||
"addedAppId:$from" to ("addedAppId:$to" to 3703311242L),
|
||||
"addedExe:$from" to ("addedExe:$to" to "$to/Fig.exe"),
|
||||
"addedExeSeen:$from" to ("addedExeSeen:$to" to 2),
|
||||
"addedArt:hero:$from" to ("addedArt:hero:$to" to "https://cdn/hero.png"),
|
||||
"addedAdopted:exe:$from" to ("addedAdopted:exe:$to" to to),
|
||||
),
|
||||
SessionPrefs.movedAddedGame(all, from, to),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nothingMovesWithoutSettings() {
|
||||
assertEquals(emptyMap<String, Pair<String, Any?>>(), SessionPrefs.movedAddedGame(mapOf("theme" to "x"), from, to))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aMovedStoreGameKeepsItsAppIdAndRemoval() {
|
||||
SessionPrefs.followStoreGame(app, "epic:fig", from) { true }
|
||||
assertEquals(3703311242L, SessionPrefs.addedGameAppId(app, from, 3703311242L))
|
||||
SessionPrefs.setAddedGameExe(app, from, "$from/Fig.exe")
|
||||
SessionPrefs.setAddedGameRemoved(app, from, true)
|
||||
SessionPrefs.followStoreGame(app, "epic:fig", to) { true }
|
||||
assertEquals(3703311242L, SessionPrefs.addedGameAppId(app, to, 1L))
|
||||
assertEquals("$to/Fig.exe", SessionPrefs.addedGameExe(app, to))
|
||||
assertEquals(listOf(to), SessionPrefs.removedAddedGames(app))
|
||||
assertEquals(false, prefs.contains("addedAppId:$from"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aCopyThatIsStillThereKeepsItsOwnSettings() {
|
||||
SessionPrefs.followStoreGame(app, "epic:fig", from) { false }
|
||||
SessionPrefs.addedGameAppId(app, from, 7L)
|
||||
SessionPrefs.followStoreGame(app, "epic:fig", to) { false }
|
||||
assertEquals(9L, SessionPrefs.addedGameAppId(app, to, 9L))
|
||||
assertEquals(7L, SessionPrefs.addedGameAppId(app, from, 1L))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import com.droiddeck.launcher.core.GameEnvironment
|
||||
import com.droiddeck.launcher.frontend.AddedGames
|
||||
import com.droiddeck.launcher.frontend.Library
|
||||
import com.droiddeck.launcher.stores.epic.EpicClient
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import java.io.File
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class NoSteamLaunchTest {
|
||||
private val context get() = RuntimeEnvironment.getApplication()
|
||||
|
||||
@After fun clean() {
|
||||
File(context.filesDir, "game-environment.json").delete()
|
||||
NoSteamLaunch.names.clear()
|
||||
}
|
||||
|
||||
private val steamGame = Library.SteamGame(413150, "Stardew Valley", null, "internal")
|
||||
private val shortcut = Library.SteamGame((2733369024L).toInt(), "Hogwarts Legacy", null, Library.ADDED, source = "epic")
|
||||
private val launcher = Library.SteamGame(EpicClient.LAUNCHER_APP_ID, Library.EPIC_LAUNCHER_NAME, null, Library.EPIC_LAUNCHER, source = "epic")
|
||||
|
||||
@Test fun eachKindOfGameKeepsTheSettingUnderItsOwnId() {
|
||||
assertEquals("413150", NoSteamLaunch.scope(steamGame))
|
||||
assertEquals("2733369024", NoSteamLaunch.scope(shortcut))
|
||||
assertEquals(EpicClient.shortcutAppId.toString(), NoSteamLaunch.scope(launcher))
|
||||
assertNull(NoSteamLaunch.scope(Library.SteamGame(0, "nothing", null, "internal")))
|
||||
}
|
||||
|
||||
@Test fun theSettingIsRememberedPerGame() {
|
||||
assertFalse(NoSteamLaunch.enabled(context, shortcut))
|
||||
GameEnvironmentStore.setGameNoSteam(context, "2733369024", true)
|
||||
assertTrue(NoSteamLaunch.enabled(context, shortcut))
|
||||
assertTrue(NoSteamLaunch.enabled(context, 2733369024L))
|
||||
assertFalse(NoSteamLaunch.enabled(context, steamGame))
|
||||
assertFalse(NoSteamLaunch.enabled(context, launcher))
|
||||
GameEnvironmentStore.setGameNoSteam(context, EpicClient.shortcutAppId.toString(), true)
|
||||
assertTrue(NoSteamLaunch.enabled(context, launcher))
|
||||
GameEnvironmentStore.setGameNoSteam(context, "2733369024", false)
|
||||
assertFalse(NoSteamLaunch.enabled(context, shortcut))
|
||||
assertTrue(GameEnvironment.gameNoSteam(GameEnvironmentStore.read(context), EpicClient.shortcutAppId.toString()))
|
||||
}
|
||||
|
||||
@Test fun eachGameStartsInItsOwnProtonOrTheLauncherWithoutSteam() {
|
||||
val game = AddedGames.Game(
|
||||
File("/x/Hogwarts Legacy"), "Hogwarts Legacy", File("/x/Hogwarts Legacy/.droiddeck-launch.bat"),
|
||||
"/mnt/droiddeck-sd/Games/Epic/Hogwarts Legacy/.droiddeck-launch.bat", "/mnt/droiddeck-sd/Games/Epic/Hogwarts Legacy",
|
||||
2733369024L, 0L, emptyList(), source = "epic", launchOptions = "-windowed",
|
||||
)
|
||||
val added = NoSteamLaunch.command(shortcut, game)!!
|
||||
assertEquals(NoSteamLaunch.PROTON_RUN, added.program)
|
||||
assertEquals(
|
||||
listOf("--app", "2733369024", "--dir", game.guestDir, "--options", "-windowed", "--", game.guestExe),
|
||||
added.args,
|
||||
)
|
||||
assertNull(NoSteamLaunch.command(shortcut, null))
|
||||
val steam = NoSteamLaunch.command(steamGame, null)!!
|
||||
assertEquals(listOf("--app", "413150"), steam.args)
|
||||
val epic = NoSteamLaunch.command(launcher, null)!!
|
||||
assertEquals(NoSteamLaunch.EPIC to listOf("run"), epic.program to epic.args)
|
||||
}
|
||||
|
||||
@Test fun anAddedGameOwnedOnSteamUsesItsSteamIdForSettingsAndLaunch() {
|
||||
val routed = AddedGames.Game(
|
||||
File("/x/Stardew Valley"), "Stardew Valley", File("/x/Stardew Valley/Stardew Valley.exe"),
|
||||
"/mnt/droiddeck-sd/Games/Stardew Valley/Stardew Valley.exe", "/mnt/droiddeck-sd/Games/Stardew Valley",
|
||||
2733369024L, 413150L, emptyList(), steamAppId = 413150,
|
||||
)
|
||||
assertEquals(413150L, NoSteamLaunch.settingsId(routed))
|
||||
val entry = Library.SteamGame(413150, "Stardew Valley", null, Library.ADDED)
|
||||
assertEquals(NoSteamLaunch.settingsId(routed).toString(), NoSteamLaunch.scope(entry))
|
||||
val command = NoSteamLaunch.command(entry, routed)!!
|
||||
assertEquals(NoSteamLaunch.PROTON_RUN to listOf("--app", "413150"), command.program to command.args)
|
||||
val plain = AddedGames.Game(File("/x/a"), "a", File("/x/a/a.exe"), "/g/a.exe", "/g", 2733369024L, 0L, emptyList())
|
||||
assertEquals(2733369024L, NoSteamLaunch.settingsId(plain))
|
||||
}
|
||||
|
||||
@Test fun theRunningSessionIsNamedAfterItsGame() {
|
||||
val command = NoSteamLaunch.command(steamGame, null)!!
|
||||
assertNull(NoSteamLaunch.nameFor(command.program, command.args))
|
||||
NoSteamLaunch.remember(command)
|
||||
assertEquals("Stardew Valley", NoSteamLaunch.nameFor(command.program, command.args))
|
||||
assertEquals(Library.EPIC_LAUNCHER_NAME, NoSteamLaunch.nameFor(NoSteamLaunch.EPIC, listOf("run")))
|
||||
assertNull(NoSteamLaunch.nameFor("/usr/bin/retroarch", emptyList()))
|
||||
assertNull(NoSteamLaunch.nameFor(NoSteamLaunch.PROTON_RUN, listOf("/x/a.exe")))
|
||||
}
|
||||
}
|
||||
@@ -113,12 +113,34 @@ class StoreGameSidecarTest {
|
||||
assertFalse(text.contains("DD_AUTH"))
|
||||
}
|
||||
|
||||
@Test fun epicLauncherPrefersTheClientsArguments() {
|
||||
val text = StoreLaunch.launcherText(sample.copy(exe = "Binaries/Win64/Celeste.exe"))
|
||||
val lines = text.split("\r\n")
|
||||
val jump = lines.indexOf("if exist \"%~dp0.droiddeck-epic-args\" goto client")
|
||||
assertTrue(jump in 0 until lines.indexOf("set \"DD_X=\""))
|
||||
val client = lines.indexOf(":client")
|
||||
assertTrue(client > lines.indexOfFirst { it.contains("-AUTH_TYPE=exchangecode") })
|
||||
assertEquals("goto :eof", lines[client - 1])
|
||||
assertEquals(
|
||||
listOf(
|
||||
"set \"DD_A=\"",
|
||||
"set /p DD_A=<\"%~dp0.droiddeck-epic-args\"",
|
||||
"del \"%~dp0.droiddeck-epic-args\"",
|
||||
"if exist \"%~dp0.droiddeck-epic-code\" del \"%~dp0.droiddeck-epic-code\"",
|
||||
"set \"DD_A=\" & \"%~dp0Binaries\\Win64\\Celeste.exe\" %DD_A%",
|
||||
),
|
||||
lines.subList(client + 1, client + 6),
|
||||
)
|
||||
assertTrue(text.endsWith("%DD_A%\r\n"))
|
||||
}
|
||||
|
||||
@Test fun gogLauncherHasNoEpicBlockAndIsOnlyWrittenWhenNeeded() {
|
||||
val plain = StoreGameSidecar(Store.GOG, "1", "T", "game.exe")
|
||||
val text = StoreLaunch.launcherText(plain.copy(args = listOf("-windowed")))
|
||||
assertFalse(text.contains("exchangecode"))
|
||||
assertTrue(text.contains("\"%~dp0game.exe\" -windowed\r\n"))
|
||||
assertFalse(text.contains("DD_X"))
|
||||
assertFalse(text.contains("droiddeck-epic-args"))
|
||||
assertEquals("\"two words\"", StoreLaunch.quoteArg("two words"))
|
||||
assertEquals("-x=\"a b\"", StoreLaunch.quoteArg("-x=\"a b\""))
|
||||
}
|
||||
|
||||
@@ -26,6 +26,18 @@ class StoreInstallRootTest {
|
||||
assertFalse(StoreInstallRoot.targets(app).first().removable)
|
||||
}
|
||||
|
||||
@Test fun theSteamLibraryFolderIsOfferedAsAnInstallTarget() {
|
||||
val library = File(app.filesDir, "Documents/Games").apply { mkdirs() }
|
||||
SessionPrefs.setGameStorage(app, library.path, "Games")
|
||||
val targets = StoreInstallRoot.targets(app)
|
||||
assertEquals(2, targets.size)
|
||||
assertEquals(File(library, "Games").absolutePath, targets.last().root.absolutePath)
|
||||
assertTrue(targets.last().folder)
|
||||
assertTrue(targets.last().label.startsWith("Games"))
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
assertEquals(1, StoreInstallRoot.targets(app).size)
|
||||
}
|
||||
|
||||
@Test fun anExistingInstallWinsOverAFreshFolderUnderTheChosenRoot() {
|
||||
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
val existing = File(StoreInstallRoot.storeDir(StoreInstallRoot.internalRoot(app), Store.GOG), "Old Name").apply { mkdirs() }
|
||||
|
||||
@@ -0,0 +1,448 @@
|
||||
package com.droiddeck.launcher.stores.epic
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import java.io.File
|
||||
import java.security.MessageDigest
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class EpicClientTest {
|
||||
@get:Rule val tmp = TemporaryFolder()
|
||||
|
||||
private fun game(appId: Int, source: String) =
|
||||
com.droiddeck.launcher.frontend.Library.SteamGame(appId, "g$appId", null, "internal", source = source)
|
||||
|
||||
@Test fun theLauncherSitsRightAboveTheFirstEpicGame() {
|
||||
val launcher = game(EpicClient.LAUNCHER_APP_ID, "epic")
|
||||
val games = listOf(game(1, "steam"), game(2, "epic"), game(3, "steam"), game(4, "epic"))
|
||||
assertEquals(listOf(1, 0, 2, 3, 4), EpicClient.withLauncher(games, launcher).map { it.appId })
|
||||
assertEquals(listOf(1, 3, 0), EpicClient.withLauncher(listOf(games[0], games[2]), launcher).map { it.appId })
|
||||
assertEquals(listOf(1, 2), EpicClient.withLauncher(games.take(2), null).map { it.appId })
|
||||
}
|
||||
|
||||
private fun added(name: String, source: String, storeId: String?) =
|
||||
com.droiddeck.launcher.frontend.AddedGames.Game(File(tmp.root, name), name, File(tmp.root, "$name/$name.exe"),
|
||||
"/root/Games/$name/$name.exe", "/root/Games/$name", 3_000_000_000L, 0L, emptyList(), source = source, storeId = storeId)
|
||||
|
||||
private fun inSteamSession(block: (android.app.Application) -> Unit) {
|
||||
val app = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val state = com.droiddeck.launcher.session.SessionState
|
||||
state.running = true
|
||||
state.stopRequested = false
|
||||
val mode = state.mode
|
||||
state.mode = com.droiddeck.launcher.session.SessionService.MODE_STEAM
|
||||
try {
|
||||
block(app)
|
||||
} finally {
|
||||
state.running = false
|
||||
state.mode = mode
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aGameFromTheLauncherIsFoundAsItsSteamShortcut() {
|
||||
val shortcut = added("Fig", "epic", "Fig")
|
||||
val games = listOf(added("Gog", "gog", "Fig"), added("Plain", "added", null), shortcut)
|
||||
assertEquals(shortcut, EpicClient.steamShortcut(games, "Fig"))
|
||||
assertNull(EpicClient.steamShortcut(games, "Other"))
|
||||
}
|
||||
|
||||
@Test fun onlyARunningSteamSessionTakesGamesFromTheLauncher() {
|
||||
val app = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
assertEquals("no-steam", EpicClient.playInSteam(app, "Fig").getString("reason"))
|
||||
assertEquals("no-steam", EpicClient.runSteamGame(app, "1091500").getString("reason"))
|
||||
val state = com.droiddeck.launcher.session.SessionState
|
||||
val mode = state.mode
|
||||
state.running = true
|
||||
state.mode = com.droiddeck.launcher.session.SessionService.MODE_RUN
|
||||
try {
|
||||
assertEquals("no-steam", EpicClient.runSteamGame(app, "1091500").getString("reason"))
|
||||
} finally {
|
||||
state.running = false
|
||||
state.mode = mode
|
||||
}
|
||||
inSteamSession {
|
||||
com.droiddeck.launcher.session.SessionState.stopRequested = true
|
||||
try {
|
||||
assertEquals("no-steam", EpicClient.runSteamGame(it, "1091500").getString("reason"))
|
||||
} finally {
|
||||
com.droiddeck.launcher.session.SessionState.stopRequested = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aSteamGameTheLauncherListsIsStartedInTheRunningClient() = inSteamSession { app ->
|
||||
assertEquals("bad-id", EpicClient.runSteamGame(app, "0").getString("reason"))
|
||||
assertTrue(EpicClient.runSteamGame(app, "1091500").getBoolean("ok"))
|
||||
val started = org.robolectric.Shadows.shadowOf(app).nextStartedService
|
||||
assertEquals(com.droiddeck.launcher.session.SessionService.ACTION_LAUNCH_GAME, started.action)
|
||||
assertEquals("1091500", started.getStringExtra(com.droiddeck.launcher.session.SessionService.EXTRA_GAME_ID))
|
||||
}
|
||||
|
||||
@Test fun anEpicGameWithoutAShortcutIsNotHandedToSteam() = inSteamSession { app ->
|
||||
assertEquals("not-registered", EpicClient.playInSteam(app, "Missing").getString("reason"))
|
||||
}
|
||||
|
||||
@Test fun theLauncherShortcutHasTheIdSteamGivesIt() {
|
||||
val crc = java.util.zip.CRC32().apply { update("\"/usr/local/bin/droiddeck-epic-steam\"Epic Games Launcher".toByteArray()) }.value
|
||||
assertEquals(crc or 0x80000000L, EpicClient.shortcutAppId)
|
||||
assertTrue(EpicClient.shortcutAppId in 0x80000000L..0xFFFFFFFFL)
|
||||
assertEquals("12918456320", EpicClient.gameId(3L))
|
||||
assertEquals(java.lang.Long.toUnsignedString((EpicClient.shortcutAppId shl 32) or 0x02000000L), EpicClient.gameId(EpicClient.shortcutAppId))
|
||||
assertTrue(EpicClient.gameId(EpicClient.shortcutAppId).toBigInteger() > Long.MAX_VALUE.toBigInteger())
|
||||
}
|
||||
|
||||
@Test fun theSteamListingCarriesTheLauncherOnlyOnceInstalled() {
|
||||
val app = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
assertNull(EpicClient.steamListing(app))
|
||||
val listing = com.droiddeck.launcher.frontend.AddedGames.writeListing(app, emptyList(),
|
||||
listOf(org.json.JSONObject().put("name", "A").put("native", true), org.json.JSONObject().put("name", "B")))
|
||||
val parsed = org.json.JSONArray(listing.readText())
|
||||
assertEquals(2, parsed.length())
|
||||
assertTrue(parsed.getJSONObject(0).getBoolean("native"))
|
||||
assertEquals("B", parsed.getJSONObject(1).getString("name"))
|
||||
assertEquals(0, org.json.JSONArray(com.droiddeck.launcher.frontend.AddedGames.writeListing(app, emptyList()).readText()).length())
|
||||
}
|
||||
|
||||
@Test fun thePadDrivesTheLauncherOnlyWhileSteamShowsIt() = inSteamSession { app ->
|
||||
val root = com.droiddeck.launcher.runtime.LinuxRuntime.sessionRoot(app).apply { mkdirs() }
|
||||
val open = File(root, EpicClient.OPEN)
|
||||
val focused = File(root, EpicClient.FOCUSED_APP)
|
||||
try {
|
||||
assertFalse(EpicClient.launcherRunning(app))
|
||||
assertFalse(EpicClient.launcherFocused(app))
|
||||
open.writeText("1\n")
|
||||
assertTrue(EpicClient.launcherRunning(app))
|
||||
focused.writeText("769\n")
|
||||
assertFalse(EpicClient.launcherFocused(app))
|
||||
focused.writeText("${EpicClient.shortcutAppId}\n")
|
||||
assertTrue(EpicClient.launcherFocused(app))
|
||||
open.writeText("3000000001\n")
|
||||
assertFalse(EpicClient.launcherFocused(app))
|
||||
focused.writeText("3000000001\n")
|
||||
assertTrue(EpicClient.launcherFocused(app))
|
||||
com.droiddeck.launcher.session.SessionState.mode = com.droiddeck.launcher.session.SessionService.MODE_RUN
|
||||
assertFalse(EpicClient.launcherFocused(app))
|
||||
assertFalse(EpicClient.launcherRunning(app))
|
||||
} finally {
|
||||
open.delete()
|
||||
focused.delete()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theLauncherEntryNeedsAnInstalledLauncherAndUsesItsIcon() {
|
||||
val app = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
assertNull(EpicClient.launcherEntry(app, "Epic Games Launcher", EpicClient.Status(installed = false, version = "1.0")))
|
||||
val icon = File(EpicClient.stateDir(app), "app/1.0/epic-games-launcher.png").apply { parentFile!!.mkdirs(); writeBytes(byteArrayOf(1)) }
|
||||
val entry = EpicClient.launcherEntry(app, "Epic Games Launcher", EpicClient.Status(installed = true, version = "1.0"))!!
|
||||
assertEquals(com.droiddeck.launcher.frontend.Library.EPIC_LAUNCHER, entry.library)
|
||||
assertEquals("epic", entry.source)
|
||||
assertEquals(icon, entry.art)
|
||||
assertNull(EpicClient.launcherEntry(app, "x", EpicClient.Status(installed = true, version = "2.0"))!!.art)
|
||||
}
|
||||
|
||||
@Test fun onlyAnInstalledLauncherIsUpdatedAutomatically() {
|
||||
assertFalse(EpicClient.updateWanted(EpicClient.Status(installed = false), "1.0"))
|
||||
assertFalse(EpicClient.updateWanted(EpicClient.Status(installed = false, version = "0.9"), "1.0"))
|
||||
assertTrue(EpicClient.updateWanted(EpicClient.Status(installed = true, version = "0.9"), "1.0"))
|
||||
assertFalse(EpicClient.updateWanted(EpicClient.Status(installed = true, version = "1.0"), "1.0"))
|
||||
assertFalse(EpicClient.updateWanted(EpicClient.Status(installed = true, version = "0.9"), null))
|
||||
}
|
||||
|
||||
@Test fun anAutomaticSignInSkipsTheAccountPicker() {
|
||||
val url = "https://www.epicgames.com/id/authorize?client_id=c85f&prompt=select_account&redirect_uri=http%3A%2F%2F127.0.0.1%3A4%2Fa"
|
||||
assertEquals("https://www.epicgames.com/id/authorize?client_id=c85f&redirect_uri=http%3A%2F%2F127.0.0.1%3A4%2Fa", EpicClient.withoutAccountPrompt(url))
|
||||
assertEquals("https://www.epicgames.com/id/authorize", EpicClient.withoutAccountPrompt("https://www.epicgames.com/id/authorize?prompt=select_account"))
|
||||
val other = "https://www.epicgames.com/id/authorize?prompt=login&x=prompt%3Dselect_account"
|
||||
assertEquals(other, EpicClient.withoutAccountPrompt(other))
|
||||
assertEquals("https://www.epicgames.com/id/authorize", EpicClient.withoutAccountPrompt("https://www.epicgames.com/id/authorize"))
|
||||
}
|
||||
|
||||
@Test fun noDroidDeckAccountMeansNoHandOff() {
|
||||
assertFalse(EpicClient.canHandOff(org.robolectric.RuntimeEnvironment.getApplication()))
|
||||
}
|
||||
|
||||
@Test fun signingOutDropsTheLaunchersSignInAndTellsARunningLauncher() {
|
||||
val app = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val auth = File(EpicClient.dataDir(app), "auth/auth.json").apply { parentFile?.mkdirs() }
|
||||
val marker = File(EpicClient.stateDir(app), "signed-out")
|
||||
val auto = File(EpicClient.stateDir(app), "auto-sign-in").apply { parentFile?.mkdirs(); writeText("1\n") }
|
||||
try {
|
||||
auth.writeText("""{"prod":{"refresh_token":"t"}}""")
|
||||
assertTrue(EpicClient.signOut(app))
|
||||
assertFalse(auth.exists())
|
||||
assertFalse(auto.exists())
|
||||
assertTrue(marker.isFile)
|
||||
marker.delete()
|
||||
auth.writeText("""{"prod":{"refresh_token":""}}""")
|
||||
assertFalse(EpicClient.signOut(app))
|
||||
assertFalse(auth.exists())
|
||||
assertFalse(marker.exists())
|
||||
assertFalse(EpicClient.signOut(app))
|
||||
} finally {
|
||||
auth.delete(); marker.delete(); auto.delete()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun uninstallingRemovesTheProgramButKeepsGamesRecordsAndSignIn() {
|
||||
val app = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val state = EpicClient.stateDir(app)
|
||||
val runtime = File(state, "runtime/4.0").apply { mkdirs() }
|
||||
File(runtime, "files").mkdirs()
|
||||
val loop = File(runtime, "files/usr")
|
||||
java.nio.file.Files.createSymbolicLink(loop.toPath(), java.nio.file.Paths.get("."))
|
||||
val outside = File(app.filesDir, "outside-keep").apply { mkdirs() }
|
||||
java.nio.file.Files.createSymbolicLink(File(runtime, "files/elsewhere").toPath(), outside.toPath())
|
||||
File(outside, "keep.txt").writeText("x")
|
||||
File(state, "app/0.97.0").mkdirs()
|
||||
File(state, "app/0.97.0/AppRun").writeText("x")
|
||||
File(state, "current.json").writeText("""{"app":"0.97.0","runtime":"4.0"}""")
|
||||
val imports = File(state, "client-imports.json").apply { writeText("{}") }
|
||||
val auth = File(EpicClient.dataDir(app), "auth/auth.json").apply { parentFile?.mkdirs(); writeText("{}") }
|
||||
val records = File(EpicClient.dataDir(app), "installations.jsonl").apply { writeText("{}\n") }
|
||||
try {
|
||||
assertTrue(EpicClient.uninstall(app))
|
||||
assertFalse(File(state, "app").exists())
|
||||
assertFalse(File(state, "runtime").exists())
|
||||
assertFalse(File(state, "current.json").exists())
|
||||
assertTrue(imports.isFile)
|
||||
assertTrue(auth.isFile)
|
||||
assertTrue(records.isFile)
|
||||
assertTrue(File(outside, "keep.txt").isFile)
|
||||
} finally {
|
||||
imports.delete(); auth.delete(); records.delete(); outside.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theWebSignInIsExpiredForEveryCookieOnBothPathsAndTheDomain() {
|
||||
assertEquals(emptyList<String>(), EpicClient.expiredCookies(null))
|
||||
assertEquals(emptyList<String>(), EpicClient.expiredCookies(" ; "))
|
||||
val lines = EpicClient.expiredCookies("EPIC_SSO=abc; EPIC_SSO_RM=1; EPIC_SSO=again;__Host-x=y")
|
||||
assertEquals(12, lines.size)
|
||||
assertTrue(lines.contains("EPIC_SSO=; Max-Age=0; Path=/; Secure"))
|
||||
assertTrue(lines.contains("EPIC_SSO_RM=; Max-Age=0; Path=/id; Secure; Domain=.epicgames.com"))
|
||||
assertTrue(lines.contains("__Host-x=; Max-Age=0; Path=/; Secure"))
|
||||
assertTrue(lines.none { "abc" in it })
|
||||
val www = EpicClient.expiredCookies("__cf_bm=1", "www.epicgames.com")
|
||||
assertEquals(6, www.size)
|
||||
assertTrue(www.contains("__cf_bm=; Max-Age=0; Path=/; Secure; Domain=www.epicgames.com"))
|
||||
assertEquals(4, EpicClient.expiredCookies("a=1", "example.com").size)
|
||||
}
|
||||
|
||||
@Test fun launcherVersionComesFromTheRedirect() {
|
||||
val location = "https://content-download-egs.distro.on.epicgames.com/Builds/EGLv2/0.95.2%2Bgfa9ad49/Linux/EpicGamesLauncher-x86_64.AppImage?launcherfilename=EpicGamesLauncher-x86_64.AppImage"
|
||||
assertEquals("0.95.2+gfa9ad49", EpicClientSources.launcherVersion(location))
|
||||
assertNull(EpicClientSources.launcherVersion("http://content-download-egs.distro.on.epicgames.com/Builds/EGLv2/1.0/Linux/a"))
|
||||
assertNull(EpicClientSources.launcherVersion("https://example.com/Builds/EGLv2/..%2F..%2Fetc/Linux/a"))
|
||||
assertNull(EpicClientSources.launcherVersion("https://example.com/other/path"))
|
||||
}
|
||||
|
||||
@Test fun runtimeChecksumIsReadFromTheSumsFile() {
|
||||
val sums = """
|
||||
0f3e16b00ed7256db38733d50995b82484ef730167cbf5693e19634dcb04f39a *com.valvesoftware.SteamRuntime.Platform-amd64,i386-steamrt4-runtime-debug.tar.gz
|
||||
A0F3E16B00ED7256DB38733D50995B82484EF730167CBF5693E19634DCB04F39 *com.valvesoftware.SteamRuntime.Platform-amd64,i386-steamrt4-runtime.tar.gz
|
||||
""".trimIndent()
|
||||
assertEquals("a0f3e16b00ed7256db38733d50995b82484ef730167cbf5693e19634dcb04f39", EpicClientSources.sha256For(sums, EpicClientSources.RUNTIME_FILE))
|
||||
assertNull(EpicClientSources.sha256For(sums, "missing.tar.gz"))
|
||||
}
|
||||
|
||||
private fun md5(bytes: ByteArray) = MessageDigest.getInstance("MD5").digest(bytes)
|
||||
private fun hex(bytes: ByteArray) = bytes.joinToString("") { "%02x".format(it) }
|
||||
|
||||
@Test fun multipartEtagIsChecked() {
|
||||
val part = 8 shl 20
|
||||
val data = ByteArray(part * 2 + 123) { (it * 31).toByte() }
|
||||
val file = File(tmp.root, "image").apply { writeBytes(data) }
|
||||
val digest = hex(md5(md5(data.copyOfRange(0, part)) + md5(data.copyOfRange(part, 2 * part)) + md5(data.copyOfRange(2 * part, data.size))))
|
||||
assertEquals(true, EpicClientSources.etagMatches(file, "\"$digest-3\""))
|
||||
assertEquals(false, EpicClientSources.etagMatches(file, "\"${"0".repeat(32)}-3\""))
|
||||
assertNull(EpicClientSources.etagMatches(file, "\"$digest-99\""))
|
||||
assertNull(EpicClientSources.etagMatches(file, "W/\"$digest-3\""))
|
||||
assertEquals(true, EpicClientSources.etagMatches(file, hex(md5(data))))
|
||||
}
|
||||
|
||||
@Test fun appImageMagicIsRequired() {
|
||||
val good = File(tmp.root, "a").apply { writeBytes(byteArrayOf(0x7f, 'E'.code.toByte(), 'L'.code.toByte(), 'F'.code.toByte(), 2, 1, 1, 0, 'A'.code.toByte(), 'I'.code.toByte(), 2, 0)) }
|
||||
val bad = File(tmp.root, "b").apply { writeBytes(ByteArray(16)) }
|
||||
assertTrue(EpicClientSources.isAppImage(good))
|
||||
assertFalse(EpicClientSources.isAppImage(bad))
|
||||
}
|
||||
|
||||
@Test fun signInUrlsMustRedirectToLoopback() {
|
||||
val good = "https://www.epicgames.com/id/authorize?client_id=c85f4c6238b04d3399bc0080e83b83fd&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1%3A41234%2Flauncher%2Fauthorized&state=x"
|
||||
assertEquals("http://127.0.0.1:41234/launcher/authorized", EpicClient.redirectOf(good))
|
||||
assertNull(EpicClient.redirectOf(good.replace("www.epicgames.com", "evil.example")))
|
||||
assertNull(EpicClient.redirectOf(good.replace("https://", "http://")))
|
||||
assertNull(EpicClient.redirectOf(good.replace("127.0.0.1%3A41234", "example.com%3A80")))
|
||||
assertNull(EpicClient.redirectOf(good.replace("%3A41234", "")))
|
||||
assertFalse(EpicClient.loopback("http://user@127.0.0.1:1/x"))
|
||||
assertTrue(EpicClient.loopback("http://localhost:5/launcher/authorized?code=1"))
|
||||
}
|
||||
|
||||
@Test fun itemsDescribeTheInstallForTheLauncher() {
|
||||
val install = EpicClientLibrary.Install(
|
||||
"Fig", "ns1", "item1", "Fig Game", "1.0.5", "Binaries/Win64/Fig.exe", "/root/Games/Stores/Epic/Fig Game",
|
||||
File(tmp.root, "Fig Game"), "dep1", 1234L,
|
||||
)
|
||||
val item = EpicClientLibrary.item(install, listOf("en"), ownership = true)
|
||||
val guid = EpicClientLibrary.guid("Fig")
|
||||
assertEquals(32, guid.length)
|
||||
assertEquals(guid, EpicClientLibrary.guid("Fig"))
|
||||
assertTrue(guid.all { it in "0123456789ABCDEF" })
|
||||
assertEquals(guid, item.getString("InstallationGuid"))
|
||||
assertEquals("/root/Games/Stores/Epic/Fig Game", item.getString("InstallLocation"))
|
||||
assertEquals("/root/Games/Stores/Epic/Fig Game/.egstore", item.getString("ManifestLocation"))
|
||||
assertEquals("Binaries/Win64/Fig.exe", item.getString("LaunchExecutable"))
|
||||
assertEquals("Fig", item.getString("AppName"))
|
||||
assertEquals("Fig", item.getString("MainGameAppName"))
|
||||
assertEquals("ns1", item.getString("CatalogNamespace"))
|
||||
assertEquals("item1", item.getString("CatalogItemId"))
|
||||
assertEquals("1.0.5", item.getString("AppVersionString"))
|
||||
assertEquals("true", item.getString("OwnershipToken"))
|
||||
assertEquals("dep1", item.getString("SidecarDeploymentId"))
|
||||
assertEquals("Fig Game", item.getString("MandatoryAppFolderName"))
|
||||
assertFalse(item.getBoolean("bIsIncompleteInstall"))
|
||||
val list = EpicClientLibrary.aggregateFromManifests(File(tmp.root, "none"), listOf(install)).getJSONArray("InstallationList")
|
||||
assertEquals(1, list.length())
|
||||
assertEquals("Fig", list.getJSONObject(0).getString("ArtifactId"))
|
||||
assertEquals("ns1", list.getJSONObject(0).getString("NamespaceId"))
|
||||
assertEquals("item1", list.getJSONObject(0).getString("ItemId"))
|
||||
}
|
||||
|
||||
@Test fun clientManifestsRemainInTheAggregateAndSupplyDroidDeckShortcuts() {
|
||||
val manifests = File(tmp.root, "Manifests").apply { mkdirs() }
|
||||
File(manifests, "client.item").writeText(
|
||||
"""{"AppName":"ClientGame","CatalogNamespace":"ns2","CatalogItemId":"item2","InstallLocation":"/root/Games/ClientGame","LaunchExecutable":"Binaries/ClientGame.exe","AppVersionString":"2.0","DisplayName":"Client Game","bIsIncompleteInstall":false}""",
|
||||
)
|
||||
File(manifests, "partial.item").writeText(
|
||||
"""{"AppName":"Partial","CatalogNamespace":"ns","CatalogItemId":"partial","InstallLocation":"/root/partial","bIsIncompleteInstall":true}""",
|
||||
)
|
||||
val managed = EpicClientLibrary.Install(
|
||||
"RustGame", "ns1", "item1", "Rust Game", "1.0", "Game.exe", "/root/Games/RustGame", File(tmp.root, "RustGame"), "dep", 10,
|
||||
)
|
||||
val old = org.json.JSONObject().put("InstallationList", org.json.JSONArray().put(
|
||||
org.json.JSONObject().put("AppName", "InstallingGame").put("ArtifactId", "InstallingGame").put("InstallLocation", "/root/Games/InstallingGame"),
|
||||
))
|
||||
val list = EpicClientLibrary.aggregateFromManifests(manifests, listOf(managed), old).getJSONArray("InstallationList")
|
||||
assertEquals(3, list.length())
|
||||
val names = (0 until list.length()).map { list.getJSONObject(it).getString("AppName") }
|
||||
assertTrue("ClientGame" in names)
|
||||
assertTrue("RustGame" in names)
|
||||
assertTrue("InstallingGame" in names)
|
||||
assertEquals("Binaries/ClientGame.exe", EpicClientLibrary.executableRelative("/root/Games/ClientGame", "Binaries/ClientGame.exe"))
|
||||
assertNull(EpicClientLibrary.executableRelative("/root/Games/ClientGame", "../outside.exe"))
|
||||
assertNull(EpicClientLibrary.executableRelative("/root/Games/ClientGame", "C:/outside.exe"))
|
||||
}
|
||||
|
||||
@Test fun gamesInstalledByTheClientBecomeEpicLibraryShortcuts() {
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val game = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/Games/ClientGame")
|
||||
File(game, "Binaries").mkdirs()
|
||||
File(game, "Binaries/ClientGame.exe").writeBytes(byteArrayOf(1))
|
||||
val manifests = EpicClientLibrary.manifestsDir(context).apply { mkdirs() }
|
||||
File(manifests, "client.item").writeText(
|
||||
"""{"AppName":"ClientGame","CatalogNamespace":"ns2","CatalogItemId":"item2","InstallLocation":"/root/Games/ClientGame","LaunchExecutable":"Binaries/ClientGame.exe","AppVersionString":"2.0","DisplayName":"Client Game","bIsIncompleteInstall":false}""",
|
||||
)
|
||||
|
||||
assertTrue(EpicClientLibrary.importClientGames(context))
|
||||
val sidecar = com.droiddeck.launcher.stores.StoreGameSidecar.read(game)!!
|
||||
assertEquals(com.droiddeck.launcher.stores.Store.EPIC, sidecar.store)
|
||||
assertEquals("ClientGame", sidecar.id)
|
||||
assertEquals("Binaries/ClientGame.exe", sidecar.exe)
|
||||
assertEquals("true", sidecar.extra["clientManaged"])
|
||||
assertTrue(File(game, sidecar.launcher!!).isFile)
|
||||
assertEquals(File(game, "Binaries/ClientGame.exe").path,
|
||||
com.droiddeck.launcher.frontend.AddedExes.list(context).first { it.folder == game.path }.exe)
|
||||
}
|
||||
|
||||
@Test fun gamesTheLauncherInstallsItselfAreImportedFromItsInstallationList() {
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val game = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/Games/Stores/Epic/Luftrausers51924")
|
||||
File(game, "bin").mkdirs()
|
||||
File(game, "bin/Luftrausers.exe").writeBytes(byteArrayOf(1))
|
||||
val list = EpicClientLibrary.installationsFile(context).apply { parentFile!!.mkdirs() }
|
||||
list.writeText(listOf(
|
||||
"""{"version":1,"entries":2}""",
|
||||
"""{"installationId":"F00B","complete":false,"dir":"/root/Games/Stores/Epic/Luftrausers51924","platform":"Windows","namespace":"ns","itemId":"it","artifactId":"luft","launchExecutable":"bin/Luftrausers.exe"}""",
|
||||
"""{"installationId":"F00B","complete":true,"dir":"/root/Games/Stores/Epic/Luftrausers51924","platform":"Windows","namespace":"ns","itemId":"it","artifactId":"luft","version":"1.0","sidecar":{"deploymentId":"dep"},"launchExecutable":"bin/Luftrausers.exe"}""",
|
||||
).joinToString("\n"))
|
||||
|
||||
assertTrue(EpicClientLibrary.importClientGames(context))
|
||||
val sidecar = com.droiddeck.launcher.stores.StoreGameSidecar.read(game)!!
|
||||
assertEquals(listOf("luft", "Luftrausers51924", "bin/Luftrausers.exe", "1.0", "dep", "true"),
|
||||
listOf(sidecar.id, sidecar.title, sidecar.exe, sidecar.installVersion, sidecar.extra["deploymentId"], sidecar.extra["clientManaged"]))
|
||||
assertTrue(com.droiddeck.launcher.frontend.AddedGames.scan(context).any { it.folder.path == game.path && it.source == "epic" })
|
||||
assertFalse(EpicClientLibrary.importClientGames(context))
|
||||
|
||||
list.appendText("\n" + """{"installationId":"F00B","deleted":true}""")
|
||||
assertTrue(EpicClientLibrary.importClientGames(context))
|
||||
assertNull(com.droiddeck.launcher.stores.StoreGameSidecar.read(game))
|
||||
assertTrue(com.droiddeck.launcher.frontend.AddedExes.list(context).none { it.folder == game.path })
|
||||
}
|
||||
|
||||
@Test fun anUnfinishedOrLinuxInstallIsNotImported() {
|
||||
val (records, readable) = EpicClientLibrary.clientInstallations(tmp.newFile().apply {
|
||||
writeText("""{"installationId":"a","complete":true,"platform":"Linux","artifactId":"x","dir":"/root/Games/X"}""" + "\nnot json\n")
|
||||
})
|
||||
assertFalse(readable)
|
||||
assertTrue(EpicClientLibrary.manifestOf(records.single(), null).getBoolean("bIsIncompleteInstall"))
|
||||
assertEquals("X", EpicClientLibrary.manifestOf(records.single(), " ").getString("DisplayName"))
|
||||
assertEquals(emptyList<org.json.JSONObject>() to true, EpicClientLibrary.clientInstallations(File(tmp.root, "missing")))
|
||||
}
|
||||
|
||||
@Test fun theLauncherWaitsForTheFexToolSteamInstalls() {
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
com.droiddeck.launcher.session.SessionPrefs.setGameStorage(context, com.droiddeck.launcher.session.SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
val steamapps = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/.local/share/Steam/steamapps").apply { mkdirs() }
|
||||
assertFalse(EpicClient.fexReady(context))
|
||||
EpicClient.requestFex(context)
|
||||
assertTrue(File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/.config/droiddeck/fex-wanted").isFile)
|
||||
File(steamapps, "appmanifest_3127680.acf").writeText("\"AppState\"\n{\n\t\"appid\"\t\t\"3127680\"\n\t\"installdir\"\t\t\"FEX-Emu\"\n}\n")
|
||||
assertFalse(EpicClient.fexReady(context))
|
||||
File(steamapps, "common/FEX-Emu/usr/bin").mkdirs()
|
||||
assertFalse(EpicClient.fexReady(context))
|
||||
File(steamapps, "common/FEX-Emu/usr/bin/FEXInterpreter").writeText("")
|
||||
assertTrue(EpicClient.fexReady(context))
|
||||
}
|
||||
|
||||
@Test fun fexOnASecondLibraryIsFoundInItsPrivateToolCopy() {
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val library = File(context.cacheDir, "card-library").apply { mkdirs() }
|
||||
com.droiddeck.launcher.session.SessionPrefs.setGameStorage(context, library.path, "SD Card")
|
||||
try {
|
||||
val steamapps = File(library, "steamapps").apply { mkdirs() }
|
||||
File(steamapps, "appmanifest_3127680.acf").writeText("\"AppState\"\n{\n\t\"appid\"\t\t\"3127680\"\n\t\"installdir\"\t\t\"FEX-Emu\"\n}\n")
|
||||
File(steamapps, "common/FEX-Emu").mkdirs()
|
||||
assertFalse(EpicClient.fexReady(context))
|
||||
val private = com.droiddeck.launcher.session.SecondaryLibrary.privateRoot(context.filesDir, library)
|
||||
File(private, "steamapps/common/FEX-Emu/usr/bin").mkdirs()
|
||||
File(private, "steamapps/common/FEX-Emu/usr/bin/FEX").writeText("")
|
||||
assertTrue(EpicClient.fexReady(context))
|
||||
} finally {
|
||||
com.droiddeck.launcher.session.SessionPrefs.setGameStorage(context, com.droiddeck.launcher.session.SessionPrefs.GAME_STORAGE_OFF, "")
|
||||
library.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theLauncherInstallsWhereDroidDeckInstallsEpicGames() {
|
||||
val context = org.robolectric.RuntimeEnvironment.getApplication()
|
||||
val settings = File(EpicClient.dataDir(context), "settings/app-settings.json").apply { parentFile!!.mkdirs() }
|
||||
settings.writeText("""{"defaultInstallDir":"/root/Games","verboseLogs":false}""")
|
||||
assertEquals("/root/Games/Stores/Epic", EpicClient.prepareInstallDir(context))
|
||||
val written = org.json.JSONObject(settings.readText())
|
||||
assertEquals("/root/Games/Stores/Epic", written.getString("defaultInstallDir"))
|
||||
assertFalse(written.getBoolean("verboseLogs"))
|
||||
assertTrue(File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/Games/Stores/Epic").isDirectory)
|
||||
settings.writeText("""{"defaultInstallDir":"/root/MyGames"}""")
|
||||
assertEquals("/root/MyGames", EpicClient.prepareInstallDir(context))
|
||||
assertEquals("/root/MyGames", org.json.JSONObject(settings.readText()).getString("defaultInstallDir"))
|
||||
settings.writeText("""{"defaultInstallDir":"/mnt/droiddeck-sd/Stores/Epic"}""")
|
||||
assertEquals("/root/Games/Stores/Epic", EpicClient.prepareInstallDir(context))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user