Compare commits

...
Author SHA1 Message Date
The412Banner 2b2c3da358 fix(game-env): remove Wine libraries another Proton left in the prefix that this Proton does not ship 2026-11-30 18:39:56 +00:00
MaxsTechReview 54ca518553 fix(storage): a card library the session cannot open by its raw path is opened by its storage path (#3475)
A game storage folder saved as a raw volume path is opened through the volume's /storage path when only that one is usable, and its private directories are kept under either path. Battle.net is only given a library folder when the configured one is attached, so a missing card no longer moves its install folder to internal storage.
2026-11-30 12:00:05 -05:00
8 changed files with 255 additions and 7 deletions

No files matched your search

@@ -59,13 +59,18 @@ object GameStorage {
return when {
pref == SessionPrefs.GAME_STORAGE_OFF -> null
pref.isEmpty() -> options(context).firstOrNull()?.let { Option(it.name, it.path) }
else -> Option(SessionPrefs.gameStorageLabel(context), pref).takeIf { attached(File(pref)) }
else -> reachable(pref).let { path -> Option(SessionPrefs.gameStorageLabel(context), path).takeIf { attached(File(path)) } }
}
}
fun disconnected(context: Context): Boolean {
val pref = SessionPrefs.gameStorage(context)
return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(pref))
return pref.isNotEmpty() && pref != SessionPrefs.GAME_STORAGE_OFF && !attached(File(reachable(pref)))
}
internal fun reachable(path: String, usable: (File) -> Boolean = { it.isDirectory && it.canWrite() }): String {
val alias = UsbLink.storagePath(path)
return if (alias != path && !usable(File(path)) && usable(File(alias))) alias else path
}
internal fun attached(
@@ -46,7 +46,16 @@ object SecondaryLibrary {
}
fun privateRoot(files: File, library: File): File {
val digest = MessageDigest.getInstance("SHA-256").digest(library.canonicalPath.toByteArray())
val own = privateDir(files, library.canonicalPath)
if (own.exists()) return own
val raw = UsbLink.rawPath(library.absolutePath)
val alias = if (raw != library.absolutePath) raw else UsbLink.storagePath(library.absolutePath)
if (alias == library.absolutePath) return own
return privateDir(files, runCatching { File(alias).canonicalPath }.getOrDefault(alias)).takeIf { it.exists() } ?: own
}
private fun privateDir(files: File, path: String): File {
val digest = MessageDigest.getInstance("SHA-256").digest(path.toByteArray())
.joinToString("") { "%02x".format(it.toInt() and 255) }
return File(files, "steam-libraries/$digest")
}
@@ -7,6 +7,7 @@ import com.droiddeck.launcher.R
import com.droiddeck.launcher.frontend.AddedGames
import com.droiddeck.launcher.runtime.BattleNet
import com.droiddeck.launcher.runtime.LinuxRuntime
import com.droiddeck.launcher.session.GameStorage
import com.droiddeck.launcher.stores.CatalogItem
import com.droiddeck.launcher.stores.InstalledStoreGame
import com.droiddeck.launcher.stores.Store
@@ -130,13 +131,13 @@ object BattleNetClient {
StoresState.post { opener?.invoke(args) }
}
fun library(context: Context, root: File = preferred(context)): List<String> =
AddedGames.guestPath(context, StoreInstallRoot.storeDir(root, Store.BATTLENET))?.let { listOf("--library", it) }.orEmpty()
fun library(context: Context, root: File? = preferred(context)): List<String> =
root?.let { AddedGames.guestPath(context, StoreInstallRoot.storeDir(it, Store.BATTLENET)) }?.let { listOf("--library", it) }.orEmpty()
internal fun preferred(context: Context): File {
internal fun preferred(context: Context): File? {
val second = StoreInstallRoot.libraryRoot(context)?.absolutePath
return StoreInstallRoot.targets(context).firstOrNull { it.root.absolutePath == second && (it.root.isDirectory || it.root.mkdirs()) }?.root
?: StoreInstallRoot.internalRoot(context)
?: StoreInstallRoot.internalRoot(context).takeIf { second == null && !GameStorage.disconnected(context) }
}
fun installGame(context: Context, uid: String, root: File) {
@@ -114,6 +114,19 @@ class GameStorageTest {
assertFalse(GameStorage.disconnected(app))
}
@Test fun aRawCardPathTheProcessCannotUseFallsBackToItsStoragePath() {
val usable = setOf("/storage/A042-9B16/Games")
assertEquals("/storage/A042-9B16/Games", GameStorage.reachable("/mnt/media_rw/A042-9B16/Games") { it.path in usable })
}
@Test fun aUsableRawPathAndOtherPathsAreKept() {
assertEquals("/mnt/media_rw/A042-9B16/Games", GameStorage.reachable("/mnt/media_rw/A042-9B16/Games") { true })
assertEquals("/mnt/media_rw/0000-0000/Games", GameStorage.reachable("/mnt/media_rw/0000-0000/Games") { false })
assertEquals("/storage/A042-9B16/Games", GameStorage.reachable("/storage/A042-9B16/Games") { false })
val folder = tmp.newFolder("library").path
assertEquals(folder, GameStorage.reachable(folder) { false })
}
@Test fun onlyAVfatMountCountsAsFat32() {
val mounts = """
/dev/fuse /storage/emulated fuse rw 0 0
@@ -21,6 +21,24 @@ class SecondaryLibraryTest {
assertFalse(SecondaryLibrary.privateRoot(files, content).exists())
}
@Test fun aCardReachedThroughItsOtherPathKeepsItsPrivateDirectories() {
val files = tmp.newFolder("files")
val raw = SecondaryLibrary.privateRoot(files, File("/mnt/media_rw/A042-9B16/Games")).apply { mkdirs() }
assertEquals(raw, SecondaryLibrary.privateRoot(files, File("/storage/A042-9B16/Games")))
val storage = SecondaryLibrary.privateRoot(files, File("/storage/B2BD-BCFC/Games")).apply { mkdirs() }
assertEquals(storage, SecondaryLibrary.privateRoot(files, File("/mnt/media_rw/B2BD-BCFC/Games")))
}
@Test fun aLibraryWithItsOwnPrivateDirectoriesKeepsThem() {
val files = tmp.newFolder("files")
val own = SecondaryLibrary.privateRoot(files, File("/storage/A042-9B16/Games")).apply { mkdirs() }
val raw = File(own.parentFile, SecondaryLibrary.privateRoot(tmp.newFolder("other"), File("/mnt/media_rw/A042-9B16/Games")).name)
raw.mkdirs()
assertEquals(own, SecondaryLibrary.privateRoot(files, File("/storage/A042-9B16/Games")))
assertEquals(raw, SecondaryLibrary.privateRoot(files, File("/mnt/media_rw/A042-9B16/Games")))
assertFalse(SecondaryLibrary.privateRoot(files, File("/storage/emulated/0/Games")).exists())
}
@Test fun aWritableAliasIsSelectedAndItsProbeIsRemoved() {
val library = tmp.newFolder("shared")
val candidate = File(tmp.root, "direct")
@@ -0,0 +1,34 @@
package com.droiddeck.launcher.stores.battlenet
import com.droiddeck.launcher.session.SessionPrefs
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class BattleNetLibraryTest {
private val app get() = RuntimeEnvironment.getApplication()
@get:Rule val tmp = TemporaryFolder()
@Test fun aMissingLibraryLeavesBattleNetsInstallFolderAlone() {
SessionPrefs.setGameStorage(app, "/storage/0000-0000/Games", "SD card")
assertTrue(BattleNetClient.library(app).isEmpty())
}
@Test fun anAttachedLibraryIsHandedToBattleNet() {
SessionPrefs.setGameStorage(app, tmp.newFolder("card").path, "SD card")
assertEquals("--library", BattleNetClient.library(app).firstOrNull())
}
@Test fun internalStorageIsHandedToBattleNetWhenItIsTheChoice() {
SessionPrefs.setGameStorage(app, SessionPrefs.GAME_STORAGE_OFF, "")
assertEquals("--library", BattleNetClient.library(app).firstOrNull())
}
}
@@ -1121,6 +1121,11 @@ WINE_DLL_DIRS = ("/lib/wine/i386-windows", "/lib/wine/x86_64-windows", "/lib/win
"/lib/wine/fakedlls", "/lib64/wine", "/lib64/wine/fakedlls", "/lib64/wine/x86_64-windows")
WINE_BUILTIN_MARKS = (b"Wine builtin DLL", b"Wine placeholder DLL")
WINE_LIBRARY_SUFFIXES = (".acm", ".ax", ".dll", ".drv", ".ocx")
PREFIX_SYSTEM_DIRS = ("system32", "syswow64")
FOREIGN_SUFFIX = ".foreign-arch"
WINE_SD = "user.wine.sd"
SHARED_DATA = "pfx/drive_c/ProgramData"
@@ -1223,6 +1228,66 @@ def repair_foreign_system_dlls(prefix, proton, env=None):
return repaired
def is_wine_builtin(path):
if is_wine_dll_link(path):
return True
try:
with open(path, "rb") as image:
image.seek(0x40)
return image.read(20).startswith(WINE_BUILTIN_MARKS)
except OSError:
return False
def listed_names(folder):
try:
return {name.lower() for name in os.listdir(folder)}
except OSError:
return set()
def proton_library_names(proton, env=None):
files = Path(proton).parent / "files"
prefixes = [pfx / "drive_c/windows" for pfx in sorted((files / "share").glob("default_pfx*"))]
if not any((windows / "system32/kernel32.dll").is_file() for windows in prefixes):
return None
names = set()
for windows in prefixes:
for folder in PREFIX_SYSTEM_DIRS:
names |= listed_names(windows / folder)
roots = [files / "lib/wine"]
roots.extend(Path(entry) for entry in (env or {}).get("WINEDLLPATH", "").split(":") if entry)
for root in roots:
for folder in (root, *sorted(root.glob("*-windows"))):
for name in listed_names(folder):
names.add(name[:-2] if name.endswith("16") else name)
return names
def remove_other_wine_builtins(prefix, proton, env=None):
names = proton_library_names(proton, env)
if names is None:
return []
windows = Path(prefix) / "pfx/drive_c/windows"
removed = []
for folder in PREFIX_SYSTEM_DIRS:
try:
entries = sorted(os.listdir(windows / folder))
except OSError:
continue
for name in entries:
path = windows / folder / name
lower = name.lower()
if not lower.endswith(WINE_LIBRARY_SUFFIXES) or lower in names or not is_wine_builtin(path):
continue
try:
os.unlink(path)
except OSError:
continue
removed.append("%s/%s" % (folder, name))
return removed
def wine_user_sid():
try:
with open(MACHINE_ID, "rb") as handle:
@@ -1687,6 +1752,11 @@ def main():
except OSError as error:
restored = fixed = []
print("droiddeck-game-env: prefix system DLL check skipped (%s)" % error, file=sys.stderr)
try:
stale = remove_other_wine_builtins(prefix_path, command[0], effective_env)
except OSError as error:
stale = []
print("droiddeck-game-env: prefix Wine library check skipped (%s)" % error, file=sys.stderr)
try:
unlocked, cleared = heal_shared_data(prefix_path)
except OSError as error:
@@ -1701,6 +1771,9 @@ def main():
if fixed:
print("droiddeck-game-env: replaced foreign-architecture system DLLs with this Proton's own: %s" % ", ".join(fixed),
file=sys.stderr)
if stale:
print("droiddeck-game-env: removed Wine libraries another Proton left that this Proton does not ship: %s"
% ", ".join(stale), file=sys.stderr)
scripts = mark_install_scripts(command, effective_env)
if scripts and install_scripts_done(scripts, env):
print("droiddeck-game-env: install scripts already run in this prefix; evaluator skipped", file=sys.stderr)
+95
View File
@@ -3935,6 +3935,101 @@ class ForeignSystemDllTest(unittest.TestCase):
self.assertEqual([], self.run_repair(Path(tmp) / "missing", proton))
def wine_image(mark=b"Wine builtin DLL"):
return pe_image(0xAA64)[:64] + mark + pe_image(0xAA64)[64 + len(mark):]
class OtherWineBuiltinTest(unittest.TestCase):
def tool(self, root, name, libraries=("kernel32.dll", "winedmo.dll"), default_pfx=True):
proton = Path(root) / name / "proton"
lib = proton.parent / "files/lib/wine"
for libdir in ("aarch64-windows", "i386-windows"):
(lib / libdir).mkdir(parents=True)
for library in libraries:
(lib / libdir / library).write_bytes(wine_image())
if default_pfx:
for folder in ("system32", "syswow64"):
system = proton.parent / "files/share/default_pfx_arm64/drive_c/windows" / folder
system.mkdir(parents=True)
for library in libraries:
(system / library).write_bytes(wine_image())
return proton
def prefix(self, tmp):
compat = Path(tmp) / "compat"
windows = compat / "pfx/drive_c/windows"
for folder in ("system32", "syswow64"):
(windows / folder).mkdir(parents=True)
return compat, windows
def run_removal(self, compat, proton, env=None):
return MODULE["remove_other_wine_builtins"](str(compat), str(proton), env)
def test_libraries_another_proton_left_are_removed(self):
with tempfile.TemporaryDirectory() as tmp:
proton = self.tool(tmp, "DroidDeck-Proton")
other = self.tool(tmp, "GE-Proton", ("kernel32.dll", "winedmo.dll", "mpg4c32.dll", "ir50_32.dll"))
compat, windows = self.prefix(tmp)
other_lib = other.parent / "files/lib/wine"
(windows / "system32/mpg4c32.dll").write_bytes(wine_image())
(windows / "syswow64/mpg4c32.dll").symlink_to(other_lib / "i386-windows/mpg4c32.dll")
(windows / "system32/IR50_32.DLL").symlink_to(Path(tmp) / "removed/files/lib/wine/aarch64-windows/ir50_32.dll")
(windows / "syswow64/ir50_32.dll").write_bytes(wine_image(b"Wine placeholder DLL"))
self.assertEqual(["system32/IR50_32.DLL", "system32/mpg4c32.dll", "syswow64/ir50_32.dll", "syswow64/mpg4c32.dll"],
self.run_removal(compat, proton))
for folder in ("system32", "syswow64"):
self.assertEqual([], os.listdir(windows / folder))
self.assertTrue((other_lib / "i386-windows/mpg4c32.dll").is_file())
self.assertEqual([], self.run_removal(compat, proton))
def test_own_native_and_unrelated_files_are_kept(self):
with tempfile.TemporaryDirectory() as tmp:
proton = self.tool(tmp, "DroidDeck-Proton")
files = proton.parent / "files"
(files / "lib/wine/i386-windows/winsock.dll16").write_bytes(wine_image())
(files / "share/default_pfx_arm64/drive_c/windows/syswow64/libvkd3d-1.dll").write_bytes(wine_image())
compat, windows = self.prefix(tmp)
kept = {
"system32/winedmo.dll": wine_image(),
"system32/KERNEL32.DLL": wine_image(),
"syswow64/winsock.dll": wine_image(b"Wine placeholder DLL"),
"syswow64/libvkd3d-1.dll": wine_image(),
"system32/xgameruntime.dll": wine_image(b"DroidDeck native"),
"system32/game_plugin.dll": pe_image(0x8664),
"system32/mpg4c32.dll.foreign-arch": wine_image(),
"system32/helper.exe": wine_image(),
"system32/notes.txt": b"Wine builtin DLL",
}
for name, data in kept.items():
(windows / name).write_bytes(data)
(windows / "system32/d3d11.dll").symlink_to(Path(tmp) / "dxvk/x64/d3d11.dll")
self.assertEqual([], self.run_removal(compat, proton))
for name, data in kept.items():
self.assertEqual(data, (windows / name).read_bytes())
self.assertTrue((windows / "system32/d3d11.dll").is_symlink())
def test_libraries_on_the_wine_dll_path_are_kept(self):
with tempfile.TemporaryDirectory() as tmp:
proton = self.tool(tmp, "DroidDeck-Proton")
audio = Path(tmp) / "directaudio/lib/wine"
(audio / "aarch64-windows").mkdir(parents=True)
(audio / "aarch64-windows/winedirectaudio.drv").write_bytes(wine_image())
compat, windows = self.prefix(tmp)
link = windows / "system32/winedirectaudio.drv"
link.symlink_to(audio / "aarch64-windows/winedirectaudio.drv")
self.assertEqual([], self.run_removal(compat, proton, {"WINEDLLPATH": "%s:/missing" % audio}))
self.assertTrue(link.is_symlink())
def test_proton_without_a_default_prefix_leaves_the_prefix_alone(self):
with tempfile.TemporaryDirectory() as tmp:
proton = self.tool(tmp, "Unbuilt-Proton", default_pfx=False)
compat, windows = self.prefix(tmp)
(windows / "system32/mpg4c32.dll").write_bytes(wine_image())
self.assertEqual([], self.run_removal(compat, proton))
self.assertTrue((windows / "system32/mpg4c32.dll").is_file())
self.assertEqual([], self.run_removal(Path(tmp) / "missing", self.tool(tmp, "DroidDeck-Proton")))
class SharedDataHealTest(unittest.TestCase):
CURRENT = (21, 0x1234abcd, 0x5678ef01, os.getuid(), 1000)
STALE = (21, 0x0badf00d, 0x0ddba11, 10122, 1000)