Compare commits

..
Author SHA1 Message Date
The412Banner 77fbc3abb4 fix(diagnostics): the session report names the firmware build date 2026-11-30 20:03:52 +00:00
MaxsTechReview 5f129fb4db fix(native): allocated getcwd and realpath results name the guest mount (#3481)
getcwd(NULL, ...) and realpath(path, NULL) returned the host path of a
session mount whenever its guest path was longer than the host path,
because the translation had to fit the buffer the C library allocated.
Shells export that host path as PWD, and Wine prefers a valid PWD, so a
program started from an added game folder on a removable card got a
working directory it could not open and started in the Windows folder.
Grow the allocated result to fit the guest path.
2026-11-30 14:24:10 -05:00
MaxsTechReview 7404fba5a3 fix(battlenet): an install folder chosen in Battle.net on the library's drive is kept (#3479)
* fix(battlenet): an install folder chosen in Battle.net on the library's drive is kept

Every open set Battle.net's default install folder back to the library folder whenever the two differed, so a folder the user picked in Battle.net on the same drive was replaced on the next open. The folder is now only moved to the library when it is unset, missing, or on another drive.

* fix(battlenet): check the trimmed folder against the rootfs drives
2026-11-30 14:24:05 -05:00
12 changed files with 126 additions and 74 deletions

No files matched your search

@@ -27,6 +27,7 @@ import java.io.File
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.TimeZone
object DeviceReport {
private const val TAG = "DeviceReport"
@@ -36,6 +37,10 @@ object DeviceReport {
.map { it.substringAfter(':').trim().split(Regex("\\s+")).filter(String::isNotEmpty).joinToString(" ") }
.filter(String::isNotEmpty).distinct().joinToString(" | ").ifEmpty { "not reported" }
internal fun buildDate(millis: Long): String? = millis.takeIf { it > 0 }?.let {
SimpleDateFormat("yyyy-MM-dd HH:mm 'UTC'", Locale.US).apply { timeZone = TimeZone.getTimeZone("UTC") }.format(Date(it))
}
fun write(context: Context, target: File, mode: String) {
try {
target.writeText(build(context, mode))
@@ -129,6 +134,7 @@ object DeviceReport {
k("Android", "${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})")
k("Security patch", Build.VERSION.SECURITY_PATCH)
k("Build", Build.DISPLAY)
k("Build date", buildDate(Build.TIME))
k("Fingerprint", Build.FINGERPRINT)
k("Kernel", System.getProperty("os.version"))
k("ABIs", Build.SUPPORTED_ABIS.joinToString(", "))
@@ -0,0 +1,16 @@
package com.droiddeck.launcher.core
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class DeviceReportBuildDateTest {
@Test fun theFirmwareBuildTimeIsShownInUtc() {
assertEquals("2024-11-08 17:47 UTC", DeviceReport.buildDate(1_731_088_027_000L))
}
@Test fun anUnsetBuildTimeIsUnknown() {
assertNull(DeviceReport.buildDate(0L))
assertNull(DeviceReport.buildDate(-1L))
}
}
@@ -350,6 +350,17 @@ def keeps_open(root):
return isinstance(client, dict) and LAUNCH_BEHAVIOR[0] in client and client[LAUNCH_BEHAVIOR[0]] != LAUNCH_BEHAVIOR[1]
def chosen_folder(root, current, library):
current = current.strip()
folder = windows_path(root, current) if current else None
if not folder or rootfs_drive(root, current) or not os.path.isdir(folder):
return False
try:
return volume_root(os.path.realpath(folder)) == volume_root(os.path.realpath(library))
except OSError:
return False
def write_config(root, library=None):
path = os.path.join(drive_c(root), *CONFIG)
key, value = LAUNCH_BEHAVIOR
@@ -374,6 +385,7 @@ def write_config(root, library=None):
client["HardwareAcceleration"] = "false"
changes.append("acceleration")
if library and isinstance(client.setdefault("Install", {}), dict) \
and not chosen_folder(root, str(client["Install"].get("DefaultInstallPath", "")), library) \
and str(client["Install"].get("DefaultInstallPath", "")).rstrip("/\\") != install_path(root, library).rstrip("\\"):
client["Install"]["DefaultInstallPath"] = install_path(root, library)
changes.append("library")
@@ -251,7 +251,7 @@ dd_game_cpus() {
fi
[ -n "${DD_GAME_CPUS:-}" ] || return 0
command -v taskset >/dev/null 2>&1 || return 0
DD_TASKSET=(bash -c 'taskset -cp "$1" "$$" >/dev/null 2>&1 || printf "droiddeck-proton: CPU affinity refused; using inherited cores\n" >&2; shift; exec "$@"' -- "$DD_GAME_CPUS")
DD_TASKSET="taskset -c $DD_GAME_CPUS"
echo "droiddeck-proton: game cores $DD_GAME_CPUS" >&2
}
"""
@@ -470,7 +470,7 @@ if [ -n "$depot" ]; then
DD_STORE_PROTON="$depot/proton"; export DD_STORE_PROTON
dd_store_launch "$@"
DD_STORE_ARGS=("$@")
dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env "$depot/proton" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env "$depot/proton" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
fi
echo "droiddeck-proton: no ARM64 Proton depot yet - the client downloads one as this tool's dependency; retry the launch once it has" >&2
exit 1
@@ -525,7 +525,7 @@ dd_libpath
DD_STORE_PROTON="$here/%s"; export DD_STORE_PROTON
dd_store_launch "$@"
DD_STORE_ARGS=("$@")
dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env "$DD_STORE_PROTON" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env "$DD_STORE_PROTON" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
"""
@@ -581,9 +581,9 @@ esac
""" + DD_DESKTOP_GPU_SETUP + DD_GAME_CPUS_SETUP + """
dd_game_cpus
if [ -x /usr/local/bin/droiddeck-steamvr-flat ] && /usr/local/bin/droiddeck-steamvr-flat "$verb"; then
exec /usr/local/bin/droiddeck-steamvr-game "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-fex steam "$verb" "$@"
exec /usr/local/bin/droiddeck-steamvr-game ${DD_TASKSET:-} /usr/local/bin/droiddeck-fex steam "$verb" "$@"
fi
exec "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-fex steam "$verb" "$@"
exec ${DD_TASKSET:-} /usr/local/bin/droiddeck-fex steam "$verb" "$@"
"""
+4 -5
View File
@@ -739,10 +739,8 @@ char *getcwd(char *buf, size_t size) {
static char *(*orig_getcwd)(char *, size_t) = NULL;
if (!orig_getcwd) orig_getcwd = (char *(*)(char *, size_t))dlsym(RTLD_NEXT, "getcwd");
char *res = orig_getcwd ? orig_getcwd(buf, size) : NULL;
if (res) {
size_t len = strlen(res);
guest_path_of_mount_source(res, len, buf ? size : len + 1, NULL);
}
if (res && !buf) return guest_path_of_allocated_mount_source(res);
if (res) guest_path_of_mount_source(res, strlen(res), size, NULL);
return res;
}
@@ -790,7 +788,8 @@ char *realpath(const char *path, char *resolved_path) {
}
}
}
if (res) guest_path_of_mount_source(res, strlen(res), resolved_path ? PATH_MAX : strlen(res) + 1, NULL);
if (res && !resolved_path) return guest_path_of_allocated_mount_source(res);
if (res) guest_path_of_mount_source(res, strlen(res), PATH_MAX, NULL);
return res;
}
+14
View File
@@ -975,6 +975,20 @@ static size_t guest_path_of_mount_source(char *buf, size_t len, size_t cap, int
return best->dst_len + rest;
}
static char *guest_path_of_allocated_mount_source(char *res) {
size_t len = strlen(res);
char tmp[PATH_MAX];
if (len >= sizeof(tmp)) return res;
memcpy(tmp, res, len + 1);
int converted = 0;
size_t n = guest_path_of_mount_source(tmp, len, sizeof(tmp), &converted);
if (!converted) return res;
char *grown = realloc(res, n + 1);
if (!grown) return res;
memcpy(grown, tmp, n + 1);
return grown;
}
static ssize_t postprocess_readlink(const char *linkpath, char *buf, ssize_t ret, size_t bufsiz) {
if (ret <= 0) return ret;
if ((size_t)ret < bufsiz) {
+31
View File
@@ -295,6 +295,37 @@ class DriveTest(Temp):
self.assertEqual(BNET["install_path"](self.root, str(self.card)), "D:\\")
self.assertEqual(sorted(os.listdir(self.devices)), ["d:"])
def test_a_folder_chosen_in_battlenet_on_the_library_drive_is_kept(self):
path = Path(BNET["drive_c"](self.root)).joinpath(*BNET["CONFIG"])
BNET["write_config"](self.root)
self.assertEqual(BNET["write_config"](self.root, str(self.library)), "library")
(self.card / "Battle.net").mkdir()
config = json.loads(path.read_text())
config["Client"]["Install"]["DefaultInstallPath"] = "D:\\Battle.net"
path.write_text(json.dumps(config))
self.assertIsNone(BNET["write_config"](self.root, str(self.library)))
self.assertEqual(json.loads(path.read_text())["Client"]["Install"]["DefaultInstallPath"], "D:\\Battle.net")
def test_a_chosen_folder_inside_the_native_rootfs_is_not_kept_whatever_its_spacing(self):
BNET["write_config"](self.root, str(self.library))
rootfs = self.card / "files/linuxfs"
(rootfs / "Games").mkdir(parents=True)
with mock.patch.dict(os.environ, {"DDNATV_ROOT": str(rootfs)}):
for current in ("D:\\files\\linuxfs\\Games", " D:\\files\\linuxfs\\Games"):
self.assertFalse(BNET["chosen_folder"](self.root, current, str(self.library)))
def test_a_folder_on_another_drive_or_missing_moves_to_the_library(self):
path = Path(BNET["drive_c"](self.root)).joinpath(*BNET["CONFIG"])
BNET["write_config"](self.root, str(self.library))
internal = self.tmp / "root/Games/Stores/Battle.net"
internal.mkdir(parents=True)
for current in ("Z:" + str(internal), "D:\\Gone"):
config = json.loads(path.read_text())
config["Client"]["Install"]["DefaultInstallPath"] = current
path.write_text(json.dumps(config))
self.assertEqual(BNET["write_config"](self.root, str(self.library)), "library")
self.assertEqual(json.loads(path.read_text())["Client"]["Install"]["DefaultInstallPath"], "D:\\Games\\Battle.net")
def test_drives_in_use_and_the_ones_proton_owns_are_left_alone(self):
self.devices.mkdir(parents=True)
os.symlink("/somewhere/else", self.devices / "d:")
+9 -28
View File
@@ -1571,34 +1571,15 @@ class AppInfoTest(unittest.TestCase):
tool, bin_dir = Path(tmp) / "droiddeck-fex", Path(tmp) / "bin"
self.COMPAT["build_fex_tool"](str(tool))
bin_dir.mkdir()
real_taskset = shutil.which("taskset")
self.assertIsNotNone(real_taskset)
inherited = sorted(os.sched_getaffinity(0))
self.assertGreater(len(inherited), 1)
chosen = str(inherited[0])
(bin_dir / "taskset").symlink_to(real_taskset)
fex = bin_dir / "fex"
fex.write_text('#!' + sys.executable + '\nimport json, os, sys\nprint(json.dumps([sorted(os.sched_getaffinity(0)), sys.argv[1:]]))\nsys.exit(37)\n')
fex.chmod(0o755)
launcher = tool / "droiddeck-fex-tool"
launcher.write_text(launcher.read_text().replace("/usr/local/bin/droiddeck-fex", str(fex)))
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(PATH="%s:%s" % (bin_dir, os.environ.get("PATH", "")), DD_GAME_CPUS=chosen)
for refused in (False, True):
with self.subTest(refused=refused):
if refused:
(bin_dir / "taskset").unlink()
(bin_dir / "taskset").write_text("#!/bin/sh\nexit 1\n")
(bin_dir / "taskset").chmod(0o755)
run = subprocess.run([str(launcher), "waitforexitandrun", "/games/a game", "", "*; argument"],
env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(run.returncode, 37, run.stderr)
self.assertEqual(json.loads(run.stdout),
[inherited if refused else [inherited[0]],
["steam", "waitforexitandrun", "/games/a game", "", "*; argument"]])
self.assertIn("game cores " + chosen, run.stderr)
self.assertEqual("CPU affinity refused" in run.stderr, refused)
self.assertIn('exec /usr/local/bin/droiddeck-steamvr-game "${DD_TASKSET[@]}" '
(bin_dir / "taskset").write_text('#!/bin/sh\necho "taskset $*"\n')
(bin_dir / "taskset").chmod(0o755)
env = dict(os.environ, PATH="%s:%s" % (bin_dir, os.environ.get("PATH", "")), DD_GAME_CPUS="2-7")
run = subprocess.run([str(tool / "droiddeck-fex-tool"), "waitforexitandrun", "/games/a/game"],
env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(run.stdout,
"taskset -c 2-7 /usr/local/bin/droiddeck-fex steam waitforexitandrun /games/a/game\n")
self.assertIn("game cores 2-7", run.stderr)
self.assertIn('exec /usr/local/bin/droiddeck-steamvr-game ${DD_TASKSET:-} '
'/usr/local/bin/droiddeck-fex steam "$verb" "$@"', self.COMPAT["FEX_LAUNCHER_SH"])
+1 -33
View File
@@ -1,10 +1,7 @@
import json
import os
from pathlib import Path
import runpy
import shutil
import subprocess
import sys
import tempfile
import unittest
@@ -30,41 +27,12 @@ class LiveGameCpusTest(unittest.TestCase):
if live is not None:
self.live.write_bytes(live.encode())
setup = COMPAT["DD_GAME_CPUS_SETUP"].replace("/root/.config/droiddeck/game-cores", str(self.live))
script = setup + '\ndd_game_cpus\nif (( ${#DD_TASKSET[@]} )); then echo "taskset=taskset -c ${DD_TASKSET[4]}"; else echo "taskset="; fi\necho "cpus=${DD_GAME_CPUS-unset}"\n'
script = setup + '\ndd_game_cpus\necho "taskset=${DD_TASKSET:-}"\necho "cpus=${DD_GAME_CPUS-unset}"\n'
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(PATH=self.path, **extra)
result = subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, check=True)
return result.stdout.splitlines()
def test_launched_program_receives_requested_or_inherited_affinity(self):
real_taskset = shutil.which("taskset")
self.assertIsNotNone(real_taskset)
inherited = sorted(os.sched_getaffinity(0))
self.assertGreater(len(inherited), 1)
chosen = str(inherited[0])
taskset = Path(self.path.split(os.pathsep)[0]) / "taskset"
probe = Path(self.temp.name) / "probe.py"
probe.write_text('import json, os, sys\nprint(json.dumps([sorted(os.sched_getaffinity(0)), sys.argv[1:]]))\nsys.exit(37)\n')
setup = COMPAT["DD_GAME_CPUS_SETUP"].replace("/root/.config/droiddeck/game-cores", str(self.live))
script = setup + '\ndd_game_cpus\n"${DD_TASKSET[@]}" "$@"\n'
for refused in (False, True):
with self.subTest(refused=refused):
taskset.unlink()
if refused:
taskset.write_text("#!/bin/sh\nexit 1\n")
taskset.chmod(0o755)
else:
taskset.symlink_to(real_taskset)
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(PATH=self.path, DD_GAME_CPUS=chosen)
result = subprocess.run(["bash", "-c", script, "--", sys.executable, str(probe),
"first argument", "", "*; second"],
env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 37, result.stderr)
self.assertEqual(json.loads(result.stdout),
[inherited if refused else [inherited[0]], ["first argument", "", "*; second"]])
self.assertEqual("CPU affinity refused" in result.stderr, refused)
def test_a_change_made_during_the_session_wins_over_the_session_value(self):
self.assertEqual(self.run_setup("6,7\n", DD_GAME_CPUS="3,4,5,6,7"),
["taskset=taskset -c 6,7", "cpus=6,7"])
+1 -1
View File
@@ -2615,7 +2615,7 @@ class GameEnvironmentTest(unittest.TestCase):
self.assertIn('dd_directaudio "$here" "$@"', COMPAT["EXTRA_WRAPPER_SH"] % "proton")
for script in (COMPAT["LAUNCHER_SH"], COMPAT["EXTRA_WRAPPER_SH"] % "proton"):
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
self.assertIn('dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env', script)
self.assertIn('dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', script)
def test_both_proton_wrappers_answer_steams_driver_query_without_wine(self):
scripts = (COMPAT["launcher_sh"](), COMPAT["extra_wrapper_sh"]("proton"))
+25
View File
@@ -88,6 +88,18 @@ int main(int argc, char **argv) {
printf("%s\t%s\n", argv[i], ok ? cwd : "-");
continue;
}
if (strncmp(argv[i], "cdnull:", 7) == 0) {
char *got = chdir(argv[i] + 7) == 0 ? getcwd(NULL, 0) : NULL;
printf("%s\t%s\n", argv[i], got ? got : "-");
free(got);
continue;
}
if (strncmp(argv[i], "realnull:", 9) == 0) {
char *got = realpath(argv[i] + 9, NULL);
printf("%s\t%s\n", argv[i], got ? got : "-");
free(got);
continue;
}
if (strncmp(argv[i], "lstat:", 6) == 0) {
int ok = lstat(argv[i] + 6, &st) == 0;
printf("%s\t%d\t%d\n", argv[i], ok, ok && S_ISLNK(st.st_mode));
@@ -324,6 +336,19 @@ class NativeHookMountTest(unittest.TestCase):
arg = f"cd:/pfx/native/dosdevices/z:{GAME}/"
self.assertEqual(self.run_probe(arg)[arg], [GAME])
def test_allocated_working_directory_and_real_path_name_a_longer_guest_mount(self):
guest = "/root/Games/" + "g" * len(str(self.library))
binds = f"{self.library}:{guest}"
args = [f"cd:{guest}/Some Game", f"cdnull:{guest}/Some Game", f"realnull:{guest}/Some Game/game.txt"]
result = self.run_probe(*args, binds=binds)
self.assertEqual(result[args[0]], [f"{guest}/Some Game"])
self.assertEqual(result[args[1]], [f"{guest}/Some Game"])
self.assertEqual(result[args[2]], [f"{guest}/Some Game/game.txt"])
def test_allocated_working_directory_names_a_shorter_guest_mount(self):
arg = f"cdnull:{GAME}"
self.assertEqual(self.run_probe(arg)[arg], [GAME])
def test_rootfs_path_under_a_mount_point_reaches_the_mount(self):
path = f"{self.root}{GAME}/game.txt"
self.assertEqual(self.run_probe(path)[path], ["1", "library"])
+2 -2
View File
@@ -379,8 +379,8 @@ class CloudHooks(unittest.TestCase):
def test_both_launchers_wait_for_proton_only_for_a_store_game(self):
for sh in (compat.LAUNCHER_SH, compat.EXTRA_WRAPPER_SH):
self.assertIn('dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env', sh)
self.assertNotIn('exec "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env', sh)
self.assertIn('dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertNotIn('exec ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertIn('[ $rc -eq 10 ] && DD_STORE_EXIT=1', compat.DD_STORE_SETUP)
self.assertIn('droiddeck-store-launch --exited --code "$rc" "${DD_STORE_ARGS[@]}"', compat.DD_STORE_SETUP)
self.assertIn('exec "$@"', compat.DD_STORE_SETUP)