fix(battlenet): drop the unused runtime drive and list its games under the runtime path (#3188)

* fix(battlenet): drop the unused runtime drive and list its games under the runtime path

* fix(battlenet): read product.db paths decoded and keep alias-saved folders

* fix(battlenet): keep drives for paths that climb out of the runtime

* fix(battlenet): keep a drive referenced with any separator spelling

* fix(battlenet): check decoded config values before dropping a drive
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-24 23:29:32 -05:00
1 parent 1b80b506cb
commit 19d8819137
4 files changed
+244 -5

No files matched your search

@@ -636,11 +636,115 @@ def move_installs(root):
return False
except (OSError, ValueError):
return False
write_bytes(path, moved)
return True
def rootfs_drives(root):
host = rootfs()
folder = dosdevices(root)
if not host:
return {}
try:
names = sorted(os.listdir(folder))
except OSError:
return {}
drives = {}
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(host, target):
drives[name[0].lower()] = host[len(target):].strip("/")
return drives
def write_bytes(path, data):
with open(path + ".tmp", "wb") as f:
f.write(moved)
f.write(data)
shutil.copymode(path, path + ".tmp")
os.replace(path + ".tmp", path)
return True
def install_folders(root):
try:
with open(os.path.join(drive_c(root), *PRODUCT_DB), "rb") as f:
data = f.read()
except FileNotFoundError:
return []
folders = []
rewrite_field(data, INSTALL_FOLDER, lambda value: folders.append(value) or value)
return folders
def json_strings(value):
if isinstance(value, str):
yield value
elif isinstance(value, dict):
for key, item in value.items():
yield key
yield from json_strings(item)
elif isinstance(value, list):
for item in value:
yield from json_strings(item)
def escapes(tail):
depth = 0
for part in re.split(rb"[\\/]+", tail):
if part == b"..":
depth -= 1
if depth < 0:
return True
elif part and part != b".":
depth += 1
return False
def drop_rootfs_drives(root):
pfx = os.path.join(prefix(root), "pfx")
drives = rootfs_drives(root)
if not drives or wine_processes(pfx):
return []
try:
folders = install_folders(root)
except ValueError:
return []
texts = {}
for path in (os.path.join(pfx, "system.reg"), os.path.join(pfx, "user.reg"), os.path.join(drive_c(root), *CONFIG)):
try:
with open(path, "rb") as f:
texts[path] = f.read()
except FileNotFoundError:
pass
sep = rb"(?:\\\\|/)"
changed = dict(texts)
for letter, rest in drives.items():
head = rb"(?<![A-Za-z0-9])[" + letter.encode() + letter.upper().encode() + rb"]:"
inner = b"".join(sep + re.escape(part.encode()) for part in rest.split("/") if part)
for path in changed:
changed[path] = re.sub(head + inner + rb"(?=(" + sep + rb"[^\"\r\n]*))",
lambda m: m.group(0) if escapes(m.group(1)) else b"Z:", changed[path])
for path, data in changed.items():
if data != texts[path]:
write_bytes(path, data)
seen = list(changed.values())
config = os.path.join(drive_c(root), *CONFIG)
if config in changed:
try:
seen += [text.encode("utf-8", "replace") for text in json_strings(json.loads(changed[config].decode("utf-8-sig")))]
except ValueError:
return []
dropped = []
for letter in sorted(drives):
drive = letter.encode() + letter.upper().encode()
used = rb"(?<![A-Za-z0-9])[" + drive + rb"]:[\\/]"
if any(re.match(rb"[" + drive + rb"]:[\\/]", folder.lstrip()) for folder in folders):
continue
if not any(re.search(used, data) for data in seen):
os.unlink(os.path.join(dosdevices(root), letter + ":"))
dropped.append(letter)
return dropped
def wow_folders(root):
@@ -756,6 +860,11 @@ def configure(root, library=None):
say("Battle.net's installed games now use the Wine drive of their volume")
except OSError as error:
say("Battle.net's installed games not moved to their Wine drive: %s" % error)
try:
for letter in drop_rootfs_drives(root):
say("Wine drive %s: held the runtime and is no longer used; removed" % letter.upper())
except OSError as error:
say("Battle.net's unused runtime drive not removed: %s" % error)
try:
wallpaper(root)
except OSError as error: