From 91a217879fe81e2e9158fe4827b1d9ce87f1562d Mon Sep 17 00:00:00 2001 From: visail Date: Sun, 15 Nov 2026 23:51:05 +0800 Subject: [PATCH] fix: surface Battle.net's own reason when it refuses a game folder (#1661) * fix: surface Battle.net's own reason when it refuses a game folder watch() treated any "error": in the Agent's status JSON as fatal. The install form carries nested errors of its own - language.error 704 when the requested locale is not offered, game_dir.error when the folder is unusable - so the loop ended before the install started and agent_job reported "exit 0". A form with a non-zero game_dir.error now fails with that reason (800 reads as "the game folder already holds a game"); otherwise the wait continues, and only a top-level error still ends the loop. * fix: move the form-failure regression out of the crowded test block Keep the driver behavior unchanged; this only relocates the new regression case so the branch can be merged with current main without a test-file conflict. * fix: sync the agent-error change onto current main Bring the two touched files up to the current main versions and apply the form failure handling on top. This keeps the PR limited to the driver and its test without pulling workflow files into the branch. --------- Co-authored-by: visail Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> --- .../overlay/usr/local/bin/droiddeck-battlenet | 16 +++++++++++++++- tools/tests/test_battlenet.py | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet index 313dc57f57..1e76859e04 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-battlenet @@ -122,6 +122,17 @@ function field(text, name) { return m ? m[1] : ""; } +function object(text, name) { + var start = new RegExp('"' + name + '"\\s*:\\s*\\{').exec(text); + if (!start) return ""; + var from = start.index + start[0].length, depth = 0; + for (var i = from - 1; i < text.length; i++) { + if (text.charAt(i) == "{") depth++; + else if (text.charAt(i) == "}" && --depth == 0) return text.substring(from, i); + } + return ""; +} + function job(text) { if (/"error"\s*:\s*[1-9]/.test(text)) return false; var bare = text.replace(/"extended_status"\s*:\s*\{[^}]*\}/, ""); @@ -147,7 +158,10 @@ function watch(path) { for (var i = 0; ; i++) { var s = call("GET", path); save(".json", s); - if (/"error"\s*:\s*[1-9]/.test(s)) break; + if (/"form"\s*:\s*\{/.test(s)) { + var refused = /"error"\s*:\s*(\d+)/.exec(object(s, "game_dir")); + if (refused && +refused[1] != 0) throw new Error(+refused[1] == 800 ? "the game folder already holds a game" : "Battle.net refused the game folder (error " + refused[1] + ")"); + } else if (/"error"\s*:\s*[1-9]/.test(s)) break; var state = /"state"\s*:\s*(\d+)/.exec(s.replace(/"extended_status"\s*:\s*\{[^}]*\}/, "")), complete = /"download_complete"\s*:\s*true/.test(s); state = state ? +state[1] : 0; if (state == 1000 || state == 1003 || job(s) && !complete) started = true; diff --git a/tools/tests/test_battlenet.py b/tools/tests/test_battlenet.py index ec29a48c56..40c16bfcd4 100644 --- a/tools/tests/test_battlenet.py +++ b/tools/tests/test_battlenet.py @@ -1709,5 +1709,12 @@ class AgentJobTest(Harness): self.assertEqual(calls, [("install", "gryphon", "gryphon", "/g/Rumble", "enUS", "USA", "US"), ("update", "wow_classic")]) +class BattleNetFormTest(Temp): + def test_the_driver_waits_on_the_install_form_and_names_a_folder_that_is_taken(self): + script = BNET["AGENT_SCRIPT"] + self.assertIn(r'if (/"form"\s*:\s*\{/.test(s)) {', script) + self.assertIn("the game folder already holds a game", script) + + if __name__ == "__main__": unittest.main()