mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-01 18:45:42 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b2c3da358 |
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user