fix(battlenet): games installed inside the runtime stay listed after a native session (#3148)

* fix(battlenet): games installed inside the runtime stay listed after a native session

* test(battlenet): expect the shared folder for a lone Forever install

---------

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
Co-authored-by: maxjivi05 <maxjividen@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-11-24 21:12:33 -05:00
1 parent 238ef76c5c
commit 4b289a4802
4 files changed
+87 -2

No files matched your search

@@ -244,6 +244,11 @@ object BattleNet {
"/" + rootfs.relativize(resolved).joinToString("/") "/" + rootfs.relativize(resolved).joinToString("/")
} }
}.trimEnd('/') }.trimEnd('/')
if (mapped?.startsWith("/") == true) {
val host = File("$target/$relative")
val rootfs = LinuxRuntime.rootDir(context)
if (runCatching { host.canonicalFile.startsWith(rootfs.canonicalFile) }.getOrDefault(false)) return host
}
return com.droiddeck.launcher.frontend.AddedGames.hostPath(context, "$target/$relative") return com.droiddeck.launcher.frontend.AddedGames.hostPath(context, "$target/$relative")
} }
@@ -216,6 +216,26 @@ class BattleNetTest {
assertNull(BattleNet.hostFolder(context, "G:\\etc\\passwd")) assertNull(BattleNet.hostFolder(context, "G:\\etc\\passwd"))
} }
@Test fun aDriveAtTheAppDataFolderHoldingTheRuntimeListsTheGamesInside() {
val root = LinuxRuntime.rootDir(context)
val data = context.filesDir.parentFile!!
val pfx = File(BattleNet.prefix(context), "pfx")
val devices = File(pfx, "dosdevices").apply { mkdirs() }
java.nio.file.Files.createSymbolicLink(File(devices, "d:").toPath(), data.absoluteFile.toPath())
java.nio.file.Files.createSymbolicLink(File(devices, "e:").toPath(), java.nio.file.Paths.get("/root/Games/Card"))
val wow = File(root, "root/Games/Stores/Battle.net/World of Warcraft").apply { mkdirs() }
File(wow, "_forever_").mkdirs()
val drive = "D:/" + data.absoluteFile.toPath().relativize(wow.absoluteFile.toPath()).joinToString("/")
File(pfx, "drive_c/ProgramData/Battle.net/Agent").mkdirs()
File(pfx, "drive_c/ProgramData/Battle.net/Agent/product.db").writeBytes(message(
field(1, message(field(1, "wowf"), field(2, "wowf"), field(3, message(field(1, drive))))),
))
assertEquals(wow, BattleNet.hostFolder(context, drive))
assertEquals(wow, BattleNet.games(context).single().folder)
assertEquals(File(root, "root/Games/Card/Battle.net/X"), BattleNet.hostFolder(context, "E:\\Battle.net\\X"))
assertNull(BattleNet.hostFolder(context, "D:\\..\\etc"))
}
@Test fun wowForeverIsListedBesideRetailInTheSharedWorldOfWarcraftFolder() { @Test fun wowForeverIsListedBesideRetailInTheSharedWorldOfWarcraftFolder() {
val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() } val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() }
@@ -299,6 +299,27 @@ def map_drive(root, volume):
return None return None
def rootfs():
host = os.environ.get("DDNATV_ROOT")
return os.path.realpath(host) if host else None
def guest_path(path):
host = rootfs()
if not host or not inside(path, host):
return None
return "/" + path[len(host):].strip("/")
def rootfs_drive(root, text):
found = re.match(r"(?i)^([abd-y]):[\\/]", text)
host = rootfs()
if not found or not host:
return False
link = os.path.join(dosdevices(root), found.group(1).lower() + ":")
return os.path.islink(link) and inside(host, os.path.realpath(link))
def install_path(root, library): def install_path(root, library):
library = library.rstrip("/") or "/" library = library.rstrip("/") or "/"
try: try:
@@ -308,6 +329,9 @@ def install_path(root, library):
return "Z:" + library return "Z:" + library
if volume == "/": if volume == "/":
return "Z:" + library return "Z:" + library
host = rootfs()
if host and inside(host, volume):
return "Z:" + (guest_path(path) or library)
drive = mapped_drive(root, path, volume) drive = mapped_drive(root, path, volume)
if drive is None and not wine_processes(os.path.join(prefix(root), "pfx")): if drive is None and not wine_processes(os.path.join(prefix(root), "pfx")):
drive = map_drive(root, volume) drive = map_drive(root, volume)
@@ -586,11 +610,15 @@ def drive_folder(root, value):
text = value.decode("utf-8") text = value.decode("utf-8")
except UnicodeDecodeError: except UnicodeDecodeError:
return value return value
if not re.match(r"(?i)^z:[\\/]", text): holds_root = rootfs_drive(root, text)
if not holds_root and not re.match(r"(?i)^z:[\\/]", text):
return value return value
folder = windows_path(root, text) folder = windows_path(root, text)
if not folder or not os.path.isdir(folder): if not folder or not os.path.isdir(folder):
return value return value
if holds_root:
guest = guest_path(os.path.realpath(folder))
return value if guest is None else ("Z:" + guest).encode("utf-8")
moved = install_path(root, folder) moved = install_path(root, folder)
return value if moved.startswith("Z:") else moved.replace("\\", "/").encode("utf-8") return value if moved.startswith("Z:") else moved.replace("\\", "/").encode("utf-8")
@@ -725,7 +753,7 @@ def configure(root, library=None):
return return
try: try:
if move_installs(root): if move_installs(root):
say("Battle.net's installed games on a mapped volume now use its Wine drive") say("Battle.net's installed games now use the Wine drive of their volume")
except OSError as error: except OSError as error:
say("Battle.net's installed games not moved to their Wine drive: %s" % error) say("Battle.net's installed games not moved to their Wine drive: %s" % error)
try: try:
+32
View File
@@ -376,6 +376,38 @@ class DriveTest(Temp):
self.assertEqual(os.readlink(self.devices / "d:"), str(self.card)) self.assertEqual(os.readlink(self.devices / "d:"), str(self.card))
self.assertFalse(BNET["move_installs"](self.root)) self.assertFalse(BNET["move_installs"](self.root))
def test_the_volume_holding_the_native_rootfs_gets_no_drive(self):
rootfs = self.card / "files/linuxfs"
library = rootfs / "root/Games/Stores/Battle.net"
library.mkdir(parents=True)
with mock.patch.dict(os.environ, {"DDNATV_ROOT": str(rootfs)}):
self.assertEqual(BNET["install_path"](self.root, str(library)), "Z:/root/Games/Stores/Battle.net")
self.assertEqual(BNET["install_path"](self.root, str(self.library)), "Z:" + str(self.library))
self.assertFalse(self.devices.exists())
self.assertEqual(BNET["install_path"](self.root, str(self.library)), "D:\\Games\\Battle.net")
def test_games_moved_to_a_drive_holding_the_native_rootfs_go_back_to_the_root_drive(self):
rootfs = self.card / "files/linuxfs"
game = rootfs / "root/Games/Stores/Battle.net/World of Warcraft"
game.mkdir(parents=True)
card = self.tmp / "sd"
(card / "Diablo").mkdir(parents=True)
self.devices.mkdir(parents=True)
os.symlink(str(self.card), self.devices / "d:")
os.symlink(str(card), self.devices / "e:")
client = self.product("battle.net", "C:/Program Files (x86)/Battle.net")
sd = self.product("d3", "E:/Diablo")
gone = self.product("gone", "D:/files/linuxfs/root/Games/Missing")
path = self.database(client, self.product("wowf", "D:/files/linuxfs/root/Games/Stores/Battle.net/World of Warcraft"), sd, gone)
before = path.read_bytes()
self.assertFalse(BNET["move_installs"](self.root))
self.assertEqual(path.read_bytes(), before)
with mock.patch.dict(os.environ, {"DDNATV_ROOT": str(rootfs)}):
self.assertTrue(BNET["move_installs"](self.root))
self.assertEqual(path.read_bytes(), client + self.product("wowf", "Z:/root/Games/Stores/Battle.net/World of Warcraft")
+ sd + gone + self.field(7, b"tail"))
self.assertFalse(BNET["move_installs"](self.root))
def test_registrations_stay_while_the_prefix_runs_or_the_database_is_unreadable(self): def test_registrations_stay_while_the_prefix_runs_or_the_database_is_unreadable(self):
game = self.library / "World of Warcraft" game = self.library / "World of Warcraft"
game.mkdir() game.mkdir()