fix: games on an SD card install faster and Battle.net can read the card's volume (#2379)

A Battle.net library on another volume is reached through its own drive letter, so the Agent's volume query succeeds. The proot fast path keeps folder handles for FUSE-backed libraries. Supersedes #2377.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-11 19:10:49 -05:00
1 parent 1d247d212b
commit 3b6d13a8d7
6 files changed
+883 -36

No files matched your search

@@ -41,6 +41,9 @@ FEX_WAIT = 120
START_GRACE = 90
POLL = 2
STOP_WAIT = 5
DRIVES = "defghijklmnopqruvwxy"
PRODUCT_DB = ("ProgramData", "Battle.net", "Agent", "product.db")
INSTALL_FOLDER = (1, 3, 1)
CLOSE_GRACE = 15
HANDOFF_WAIT = 120
GAME_SETTLE = 20
@@ -123,7 +126,7 @@ function install() {
save(".form", form);
if (form.indexOf('"' + lang + '"') < 0) lang = "enUS";
var locale = lang.toLowerCase();
call("POST", "/install/" + uid, '{"account_country":"' + country + '","finalized":true,"game_dir":"' + dir + '","geo_ip_country":"' +
call("POST", "/install/" + uid, '{"account_country":"' + country + '","finalized":true,"game_dir":"' + dir.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '","geo_ip_country":"' +
region + '","language":["' + locale + '"],"selected_asset_locale":"' + locale + '","selected_locale":"' + locale +
'","shortcut":"none","tome_torrent":""}');
watch("/install/" + uid);
@@ -226,8 +229,72 @@ def installed(root):
return os.path.isfile(launcher(root))
def install_path(library):
return "Z:" + library.rstrip("/")
def dosdevices(root):
return os.path.join(prefix(root), "pfx", "dosdevices")
def volume_root(path):
device = os.stat(path).st_dev
while path != "/":
parent = os.path.dirname(path)
if os.stat(parent).st_dev != device:
break
path = parent
return path
def inside(path, folder):
return path == folder or path.startswith(folder.rstrip("/") + "/")
def mapped_drive(root, path, volume):
folder = dosdevices(root)
try:
names = sorted(os.listdir(folder))
except OSError:
return None
for name in names:
link = os.path.join(folder, name)
if len(name) == 2 and name[0].lower() in DRIVES and name[1] == ":" and os.path.islink(link):
target = os.path.realpath(link)
if inside(target, volume) and inside(path, target):
return name[0].lower(), target
return None
def map_drive(root, volume):
folder = dosdevices(root)
for letter in DRIVES:
link = os.path.join(folder, letter + ":")
if not os.path.lexists(link):
try:
os.makedirs(folder, exist_ok=True)
os.symlink(volume, link)
except OSError as error:
say("%s not mapped to a Wine drive: %s" % (volume, error))
return None
say("Wine drive %s: is %s" % (letter.upper(), volume))
return letter, volume
say("%s not mapped to a Wine drive: every letter is taken" % volume)
return None
def install_path(root, library):
library = library.rstrip("/") or "/"
try:
path = os.path.realpath(library)
volume = volume_root(path)
except OSError:
return "Z:" + library
if volume == "/":
return "Z:" + library
drive = mapped_drive(root, path, volume)
if drive is None and not wine_processes(os.path.join(prefix(root), "pfx")):
drive = map_drive(root, volume)
if drive is None:
return "Z:" + library
letter, target = drive
return letter.upper() + ":\\" + path[len(target):].strip("/").replace("/", "\\")
def write_config(root, library=None):
@@ -254,8 +321,8 @@ def write_config(root, library=None):
client["HardwareAcceleration"] = "false"
changes.append("acceleration")
if library and isinstance(client.setdefault("Install", {}), dict) \
and str(client["Install"].get("DefaultInstallPath", "")).rstrip("/\\") != install_path(library):
client["Install"]["DefaultInstallPath"] = install_path(library)
and str(client["Install"].get("DefaultInstallPath", "")).rstrip("/\\") != install_path(root, library).rstrip("\\"):
client["Install"]["DefaultInstallPath"] = install_path(root, library)
changes.append("library")
games = config.setdefault("Games", {})
for uid in CLIENT_32_BIT if isinstance(games, dict) else ():
@@ -417,13 +484,106 @@ def wallpaper(root):
def windows_path(root, path):
found = re.match(r"(?i)^([cz]):[\\/](.*)$", path.strip())
found = re.match(r"(?i)^([a-z]):[\\/](.*)$", path.strip())
if not found:
return None
parts = [part for part in re.split(r"[\\/]+", found.group(2)) if part]
if not parts or ".." in parts:
if ".." in parts:
return None
return os.path.join(drive_c(root) if found.group(1).lower() == "c" else "/", *parts)
letter = found.group(1).lower()
link = os.path.join(dosdevices(root), letter + ":")
if letter == "c":
target = drive_c(root)
elif os.path.islink(link):
target = os.path.realpath(link)
elif letter == "z":
target = "/"
else:
return None
return os.path.join(target, *parts)
def varint(data, at):
value = shift = 0
while at < len(data) and shift < 64:
byte = data[at]
at += 1
value |= (byte & 0x7F) << shift
if not byte & 0x80:
return value, at
shift += 7
raise ValueError("varint")
def encode_varint(value):
out = bytearray()
while value > 0x7F:
out.append(value & 0x7F | 0x80)
value >>= 7
out.append(value)
return bytes(out)
def rewrite_field(data, path, change):
out, at = bytearray(), 0
while at < len(data):
start = at
tag, at = varint(data, at)
kind = tag & 7
if kind == 0:
at = varint(data, at)[1]
elif kind == 1:
at += 8
elif kind == 5:
at += 4
elif kind == 2:
size, body = varint(data, at)
at = body + size
else:
raise ValueError("wire type")
if at > len(data):
raise ValueError("length")
if kind == 2 and tag >> 3 == path[0]:
value = data[body:at]
value = change(value) if len(path) == 1 else rewrite_field(value, path[1:], change)
out += encode_varint(tag) + encode_varint(len(value)) + value
else:
out += data[start:at]
return bytes(out)
def drive_folder(root, value):
try:
text = value.decode("utf-8")
except UnicodeDecodeError:
return value
if not re.match(r"(?i)^z:[\\/]", text):
return value
folder = windows_path(root, text)
if not folder or not os.path.isdir(folder):
return value
moved = install_path(root, folder)
return value if moved.startswith("Z:") else moved.replace("\\", "/").encode("utf-8")
def move_installs(root):
path = os.path.join(drive_c(root), *PRODUCT_DB)
try:
with open(path, "rb") as f:
data = f.read()
moved = rewrite_field(data, INSTALL_FOLDER, lambda value: drive_folder(root, value))
if moved == data or wine_processes(os.path.join(prefix(root), "pfx")):
return False
with open(path, "rb") as f:
if f.read() != data:
return False
except (OSError, ValueError):
return False
with open(path + ".tmp", "wb") as f:
f.write(moved)
shutil.copymode(path, path + ".tmp")
os.replace(path + ".tmp", path)
return True
def wow_folders(root):
@@ -533,6 +693,11 @@ def configure(root, library=None):
except OSError as error:
say("Battle.net's config not written: %s" % error)
return
try:
if move_installs(root):
say("Battle.net's installed games on a mapped volume now use its Wine drive")
except OSError as error:
say("Battle.net's installed games not moved to their Wine drive: %s" % error)
try:
wallpaper(root)
except OSError as error:
@@ -1227,7 +1392,6 @@ def agent_job(root, action, uid, product="", folder="", locale="enUS", country="
say("%s not made: %s" % (folder, error))
emit("ERROR", "folder")
return 2
windows = "Z:" + folder
told = None
while True:
processes = wine_processes(pfx)
@@ -1244,6 +1408,8 @@ def agent_job(root, action, uid, product="", folder="", locale="enUS", country="
time.sleep(POLL if poll is None else poll)
with lock:
stop_leftovers(pfx)
if action == "install":
windows = install_path(root, folder)
emit("STATE", "starting")
base = os.path.join(CACHE, "agent-%s" % uid)
for suffix in (".json", ".game", ".form", ".error"):