fix: keep manifest launch arguments to the installed build and their own additions

The manifest's arguments apply only when its build matches the installed version, only arguments the merge inserted are tracked as its own, escaped quotes split like a Windows command line, and the REDprelauncher rule needs Cyberpunk2077.exe beside it.
This commit is contained in:
maxjivi05 authored and MaxsTechReview committed 2026-10-23 23:59:37 -04:00
1 parent 8209a707f4
commit 42026b382f
7 files changed
+56 -18

No files matched your search

@@ -384,15 +384,19 @@ internal object EpicClientLibrary {
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
val launch = EpicNative.inspect(manifest.readBytes(), JSONObject().put("op", "launch")) ?: return null
val build = launch.optString("buildVersion")
if (install.version.isNotEmpty() && build.isNotEmpty() && build != install.version) return null
val args = 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")) }
val added = args.filterNot { it in kept }
val next = kept + added
val extra = LinkedHashMap(sidecar.extra).apply { if (added.isEmpty()) remove(LAUNCH_ARGS) else put(LAUNCH_ARGS, added.joinToString("\n")) }
if (next == sidecar.args && extra == sidecar.extra) return sidecar
return sidecar.copy(args = next, extra = extra)
}
+1 -1
View File
@@ -167,7 +167,7 @@ synchronous on the calling thread (network calls block: call them off the main t
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;
`{"op":"launch"}` → the manifest's `command` line and its `args[]`.
`{"op":"launch"}` → the manifest's `buildVersion`, its `command` line and the `args[]` split from it.
### `nativeInstall`
+29 -12
View File
@@ -44,24 +44,37 @@ pub fn split_command(command: &str) -> Vec<String> {
let mut current = String::new();
let mut quoted = false;
let mut started = false;
let mut slashes = 0usize;
for c in command.chars().map(|c| if c == '\t' { ' ' } else { c }).filter(|&c| c >= ' ' && c != '\u{7f}') {
match c {
'"' => {
if c == '\\' {
slashes += 1;
started = true;
continue;
}
if c == '"' {
current.extend(std::iter::repeat('\\').take(slashes / 2));
if slashes % 2 == 1 {
current.push('"');
} else {
quoted = !quoted;
started = true;
}
' ' if !quoted => {
if started {
args.push(std::mem::take(&mut current));
started = false;
}
}
_ => {
current.push(c);
started = true;
slashes = 0;
started = true;
continue;
}
current.extend(std::iter::repeat('\\').take(slashes));
slashes = 0;
if c == ' ' && !quoted {
if started {
args.push(std::mem::take(&mut current));
started = false;
}
} else {
current.push(c);
started = true;
}
}
current.extend(std::iter::repeat('\\').take(slashes));
if started {
args.push(current);
}
@@ -80,6 +93,10 @@ mod tests {
split_command(" -a\t-b=\"c d\" \"-e f\" \"\" -g\r\n"),
vec!["-a", "-b=c d", "-e f", "-g"]
);
assert_eq!(
split_command(r#"-name="a\" b" -dir=C:\Games\ "-q=\\" -r"#),
vec![r#"-name=a" b"#, r"-dir=C:\Games\", r"-q=\", "-r"]
);
assert!(split_command(" ").is_empty());
}
+6 -1
View File
@@ -160,7 +160,11 @@ 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) }),
"launch" => json!({
"buildVersion": m.build_version,
"command": m.launch_command,
"args": launch::split_command(&m.launch_command),
}),
_ => json!({
"buildVersion": m.build_version,
"launchExe": m.launch_exe,
@@ -212,6 +216,7 @@ mod tests {
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["buildVersion"], "b");
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();
@@ -300,6 +300,11 @@ class EpicClientTest {
val reinstalled = first.copy(args = epicArgs)
assertEquals(epicArgs + "-PCStore=EGS", EpicClientLibrary.withLaunchArgs(reinstalled, listOf("-PCStore=EGS")).args)
assertTrue(EpicClientLibrary.withLaunchArgs(installed, emptyList()) === installed)
val own = installed.copy(args = epicArgs + "-PCStore=EGS")
assertTrue(EpicClientLibrary.withLaunchArgs(own, listOf("-PCStore=EGS")) === own)
val ownUpdated = EpicClientLibrary.withLaunchArgs(own, listOf("-PCStore=EGS", "-log=a b.txt"))
assertEquals(epicArgs + listOf("-PCStore=EGS", "-log=a b.txt"), ownUpdated.args)
assertEquals(epicArgs + "-PCStore=EGS", EpicClientLibrary.withLaunchArgs(ownUpdated, emptyList()).args)
}
@Test fun itemsDescribeTheInstallForTheLauncher() {