mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
fix: Epic games get their manifest launch command
Epic manifests carry a launch command next to the launch executable, which the Epic launcher passes to the game. It was read and dropped, so Caravan SandWitch never got -PCStore=EGS and quit with "started outside of any known PC store". The manifest's launch command now joins the game's arguments, including for games already installed.
This commit is contained in:
1 parent
6e1621fe53
commit
46cd8e1777
6 files changed
+94
-4
No files matched your search
@@ -358,7 +358,11 @@ internal object EpicClientLibrary {
|
||||
write(File(manifests, "$guid.item"), item(install, tags, ownership == true).toString(2))
|
||||
runCatching { egstore(install, guid) { token } }.onFailure { Log.w(TAG, "${install.appName}: .egstore not written (${it.javaClass.simpleName})") }
|
||||
after.put(install.appName, JSONObject().put("guid", guid).put("signature", install.signature).apply { if (ownership != null) put("ownership", ownership) })
|
||||
StoreGameSidecar.read(install.folder)?.let { StoreLaunch.refreshLauncher(install.folder, it) }
|
||||
StoreGameSidecar.read(install.folder)?.let { sidecar ->
|
||||
val next = runCatching { manifestArgs(install, guid) }.getOrNull()?.let { withLaunchArgs(sidecar, it) } ?: sidecar
|
||||
if (next !== sidecar) next.write(install.folder)
|
||||
StoreLaunch.refreshLauncher(install.folder, next)
|
||||
}
|
||||
}
|
||||
for (name in before.keys().asSequence().toList()) {
|
||||
if (after.has(name)) continue
|
||||
@@ -376,6 +380,23 @@ internal object EpicClientLibrary {
|
||||
return changed
|
||||
}
|
||||
|
||||
private const val LAUNCH_ARGS = "launchArgs"
|
||||
|
||||
private fun manifestArgs(install: Install, guid: String): List<String>? {
|
||||
val manifest = File(install.folder, ".egstore/$guid.manifest").takeIf { it.isFile } ?: return null
|
||||
val args = EpicNative.inspect(manifest.readBytes(), JSONObject().put("op", "launch"))?.optJSONArray("args") ?: return null
|
||||
return List(args.length()) { args.optString(it) }.filter { it.isNotEmpty() }
|
||||
}
|
||||
|
||||
internal fun withLaunchArgs(sidecar: StoreGameSidecar, args: List<String>): StoreGameSidecar {
|
||||
val previous = sidecar.extra[LAUNCH_ARGS]?.split('\n')?.filter { it.isNotEmpty() }.orEmpty()
|
||||
val kept = sidecar.args.filterNot { it in previous }
|
||||
val next = kept + args.filterNot { it in kept }
|
||||
val extra = LinkedHashMap(sidecar.extra).apply { if (args.isEmpty()) remove(LAUNCH_ARGS) else put(LAUNCH_ARGS, args.joinToString("\n")) }
|
||||
if (next == sidecar.args && extra == sidecar.extra) return sidecar
|
||||
return sidecar.copy(args = next, extra = extra)
|
||||
}
|
||||
|
||||
private fun ownershipToken(token: String, install: Install): Boolean? =
|
||||
runCatching { EpicApiClient.getCustomAttribute(token, install.namespace, install.catalogItemId, "OwnershipToken") }
|
||||
.getOrNull()?.trim()?.lowercase()?.let { it == "true" }
|
||||
|
||||
@@ -166,7 +166,8 @@ synchronous on the calling thread (network calls block: call them off the main t
|
||||
`cloud.read` (`url`) → the file. `null` = failed. `nativeSend` op: `cloud.write` (`url`) with the
|
||||
body → `{"ok": true}` or an error. `nativeInspect` parses manifest bytes: `{"op":"summary"}` →
|
||||
`buildVersion`, `launchExe`, `prereqName`, `prereqPath`, `prereqRead`, `files[]` (`path`, `size`,
|
||||
`tags`); `{"op":"select","tags":[…]}` → `indices[]` of the files an install with those tags gets.
|
||||
`tags`); `{"op":"select","tags":[…]}` → `indices[]` of the files an install with those tags gets;
|
||||
`{"op":"launch"}` → the manifest's `command` line and its `args[]`.
|
||||
|
||||
### `nativeInstall`
|
||||
|
||||
|
||||
@@ -39,10 +39,50 @@ pub fn arguments(d: &LaunchData) -> Vec<String> {
|
||||
args
|
||||
}
|
||||
|
||||
pub fn split_command(command: &str) -> Vec<String> {
|
||||
let mut args = Vec::new();
|
||||
let mut current = String::new();
|
||||
let mut quoted = false;
|
||||
let mut started = false;
|
||||
for c in command.chars().map(|c| if c == '\t' { ' ' } else { c }).filter(|&c| c >= ' ' && c != '\u{7f}') {
|
||||
match c {
|
||||
'"' => {
|
||||
quoted = !quoted;
|
||||
started = true;
|
||||
}
|
||||
' ' if !quoted => {
|
||||
if started {
|
||||
args.push(std::mem::take(&mut current));
|
||||
started = false;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
current.push(c);
|
||||
started = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if started {
|
||||
args.push(current);
|
||||
}
|
||||
args.retain(|a| !a.is_empty());
|
||||
args
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn launch_command_splits_like_a_command_line() {
|
||||
assert_eq!(split_command("-PCStore=EGS"), vec!["-PCStore=EGS"]);
|
||||
assert_eq!(
|
||||
split_command(" -a\t-b=\"c d\" \"-e f\" \"\" -g\r\n"),
|
||||
vec!["-a", "-b=c d", "-e f", "-g"]
|
||||
);
|
||||
assert!(split_command(" ").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arguments_in_order() {
|
||||
let args = arguments(&LaunchData {
|
||||
|
||||
@@ -68,6 +68,7 @@ pub struct Manifest {
|
||||
pub version: i64,
|
||||
pub build_version: String,
|
||||
pub launch_exe: String,
|
||||
pub launch_command: String,
|
||||
pub prereq_name: String,
|
||||
pub prereq_path: String,
|
||||
pub prereq_read: bool,
|
||||
@@ -279,6 +280,7 @@ fn parse_binary(bytes: &[u8]) -> Result<Manifest, String> {
|
||||
version,
|
||||
build_version: meta.build_version,
|
||||
launch_exe: meta.launch_exe,
|
||||
launch_command: meta.launch_command,
|
||||
prereq_name: meta.prereq_name,
|
||||
prereq_path: meta.prereq_path,
|
||||
prereq_read: meta.complete,
|
||||
@@ -292,6 +294,7 @@ fn parse_binary(bytes: &[u8]) -> Result<Manifest, String> {
|
||||
struct Meta {
|
||||
build_version: String,
|
||||
launch_exe: String,
|
||||
launch_command: String,
|
||||
prereq_name: String,
|
||||
prereq_path: String,
|
||||
complete: bool,
|
||||
@@ -308,7 +311,7 @@ fn read_meta(data: &[u8]) -> Meta {
|
||||
r.fstring()?;
|
||||
meta.build_version = r.fstring()?;
|
||||
meta.launch_exe = normalise_path(&r.fstring()?);
|
||||
r.fstring()?;
|
||||
meta.launch_command = r.fstring()?;
|
||||
let ids = r.count(4)?;
|
||||
for _ in 0..ids {
|
||||
r.fstring()?;
|
||||
@@ -548,6 +551,7 @@ fn parse_json(bytes: &[u8]) -> Result<Manifest, String> {
|
||||
version,
|
||||
build_version: str_field("BuildVersionString"),
|
||||
launch_exe: normalise_path(launch),
|
||||
launch_command: str_field("LaunchCommand"),
|
||||
prereq_name: str_field("PrereqName"),
|
||||
prereq_path: normalise_path(&str_field("PrereqPath")),
|
||||
prereq_read: true,
|
||||
@@ -611,7 +615,7 @@ pub mod testing {
|
||||
fstring(&mut meta, "App");
|
||||
fstring(&mut meta, &m.build);
|
||||
fstring(&mut meta, &m.exe);
|
||||
fstring(&mut meta, "");
|
||||
fstring(&mut meta, "-PCStore=EGS \"-log=a b.txt\"");
|
||||
if let Some((name, path)) = &m.prereq {
|
||||
meta.extend_from_slice(&1i32.to_le_bytes());
|
||||
fstring(&mut meta, "prereq-id");
|
||||
@@ -763,6 +767,7 @@ mod tests {
|
||||
assert_eq!(m.chunk_folder(), "ChunksV4");
|
||||
assert_eq!(m.build_version, "1.2.3-CL-99");
|
||||
assert_eq!(m.launch_exe, "Binaries/Win64/Game.exe");
|
||||
assert_eq!(m.launch_command, "-PCStore=EGS \"-log=a b.txt\"");
|
||||
assert_eq!(m.prereq_name, "UE4 Prerequisites (x64)");
|
||||
assert_eq!(m.prereq_path, "Engine/Extras/UE4PrereqSetup_x64.exe");
|
||||
assert!(m.prereq_read);
|
||||
@@ -851,6 +856,7 @@ mod tests {
|
||||
let doc = r#"{
|
||||
"ManifestFileVersion": "013000000000",
|
||||
"LaunchExeString": "Bin\\Game.exe",
|
||||
"LaunchCommand": "-PCStore=EGS",
|
||||
"BuildVersionString": "++Game+Release-1.0",
|
||||
"PrereqName": "Redist", "PrereqPath": "Redist\\setup.exe",
|
||||
"ChunkHashList": {
|
||||
@@ -872,6 +878,7 @@ mod tests {
|
||||
assert_eq!(m.version, 13);
|
||||
assert_eq!(m.chunk_folder(), "ChunksV3");
|
||||
assert_eq!(m.launch_exe, "Bin/Game.exe");
|
||||
assert_eq!(m.launch_command, "-PCStore=EGS");
|
||||
assert!(m.prereq_read);
|
||||
assert_eq!(m.prereq_path, "Redist/setup.exe");
|
||||
assert_eq!(m.chunks.len(), 2);
|
||||
|
||||
@@ -160,6 +160,7 @@ pub fn inspect(bytes: &[u8], request: &str) -> String {
|
||||
.map(|a| a.iter().filter_map(|t| t.as_str()).map(str::to_string).collect());
|
||||
json!({ "indices": locale::select(&m.files, tags.as_deref()) })
|
||||
}
|
||||
"launch" => json!({ "command": m.launch_command, "args": launch::split_command(&m.launch_command) }),
|
||||
_ => json!({
|
||||
"buildVersion": m.build_version,
|
||||
"launchExe": m.launch_exe,
|
||||
@@ -210,6 +211,9 @@ mod tests {
|
||||
assert_eq!(v["files"].as_array().unwrap().len(), 2);
|
||||
let v: Value = serde_json::from_str(&inspect(&bytes, r#"{"op":"select","tags":["English"]}"#)).unwrap();
|
||||
assert_eq!(v["indices"], json!([0]));
|
||||
let v: Value = serde_json::from_str(&inspect(&bytes, r#"{"op":"launch"}"#)).unwrap();
|
||||
assert_eq!(v["command"], "-PCStore=EGS \"-log=a b.txt\"");
|
||||
assert_eq!(v["args"], json!(["-PCStore=EGS", "-log=a b.txt"]));
|
||||
let v: Value = serde_json::from_str(&inspect(b"nonsense", "{}")).unwrap();
|
||||
assert!(v["error"].is_string());
|
||||
}
|
||||
|
||||
@@ -285,6 +285,23 @@ class EpicClientTest {
|
||||
assertTrue(EpicClient.loopback("http://localhost:5/launcher/authorized?code=1"))
|
||||
}
|
||||
|
||||
@Test fun theManifestLaunchCommandJoinsTheGameArguments() {
|
||||
val store = com.droiddeck.launcher.stores.Store.EPIC
|
||||
val epicArgs = listOf("-EpicPortal", "-epicapp=Fig", "-epicenv=Prod")
|
||||
val installed = com.droiddeck.launcher.stores.StoreGameSidecar(store, "Fig", "Fig Game", exe = "Fig.exe", args = epicArgs)
|
||||
val first = EpicClientLibrary.withLaunchArgs(installed, listOf("-PCStore=EGS"))
|
||||
assertEquals(epicArgs + "-PCStore=EGS", first.args)
|
||||
assertTrue(EpicClientLibrary.withLaunchArgs(first, listOf("-PCStore=EGS")) === first)
|
||||
val updated = EpicClientLibrary.withLaunchArgs(first, listOf("-PCStore=EGS", "-log=a b.txt"))
|
||||
assertEquals(epicArgs + listOf("-PCStore=EGS", "-log=a b.txt"), updated.args)
|
||||
val dropped = EpicClientLibrary.withLaunchArgs(updated, emptyList())
|
||||
assertEquals(epicArgs, dropped.args)
|
||||
assertFalse(dropped.extra.containsKey("launchArgs"))
|
||||
val reinstalled = first.copy(args = epicArgs)
|
||||
assertEquals(epicArgs + "-PCStore=EGS", EpicClientLibrary.withLaunchArgs(reinstalled, listOf("-PCStore=EGS")).args)
|
||||
assertTrue(EpicClientLibrary.withLaunchArgs(installed, emptyList()) === installed)
|
||||
}
|
||||
|
||||
@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",
|
||||
|
||||
Reference in new issue
Block a user