mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
Windows components: restore bundle parts, wait for restores and keep older picks (#1788)
This commit is contained in:
1 parent
5d6f9c7d74
commit
ee3876b965
5 files changed
+209
-15
No files matched your search
@@ -563,16 +563,30 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
held = set()
|
||||
saved_overrides = state.get("overrides") if isinstance(state.get("overrides"), dict) else {}
|
||||
saved_requires = state.get("requires") if isinstance(state.get("requires"), dict) else {}
|
||||
recorded = [c for c in state.get("components", []) if isinstance(c, str) and valid_id(c)]
|
||||
owners = set(state["files"].values())
|
||||
registry_owners = {r.get("cid") for r in (state.get("registry") or {}).values() if isinstance(r, dict)}
|
||||
inferred = set()
|
||||
guessed = set(state.get("guessed") or []) if "requires" in state else set(ids)
|
||||
loose = [c for c in recorded if c not in ids and (c in owners or c in registry_owners)]
|
||||
for cid in ids:
|
||||
if cid in guessed and component(store, cid) is None and cid in recorded:
|
||||
saved_requires = dict(saved_requires, **{cid: loose})
|
||||
inferred.add(cid)
|
||||
kept_overrides, kept_requires = {}, {}
|
||||
for cid in expand(store, ids, saved_requires):
|
||||
found = component(store, cid)
|
||||
if found is None:
|
||||
if cid in saved_requires or any(owner == cid for owner in state["files"].values()):
|
||||
if cid in saved_requires or cid in recorded or cid in owners or cid in registry_owners:
|
||||
held.add(cid)
|
||||
names = [n for n in saved_overrides.get(cid, []) if isinstance(n, str)]
|
||||
if cid in saved_overrides:
|
||||
names = [n for n in saved_overrides.get(cid, []) if isinstance(n, str)]
|
||||
else:
|
||||
names = sorted({Path(rel).stem.lower() for rel, owner in state["files"].items()
|
||||
if owner == cid and rel.lower().endswith(".dll")})
|
||||
overrides += names
|
||||
kept_overrides[cid] = names
|
||||
if isinstance(saved_requires.get(cid), list):
|
||||
if isinstance(saved_requires.get(cid), list) and cid not in inferred:
|
||||
kept_requires[cid] = saved_requires[cid]
|
||||
notes.append("%s is not in the store; kept the files it placed until it is installed again" % cid)
|
||||
else:
|
||||
@@ -613,6 +627,8 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
|
||||
compat.mkdir(parents=True, exist_ok=True)
|
||||
new_state = {"files": keep, "components": installed + sorted(held), "overrides": kept_overrides,
|
||||
"requires": kept_requires, "registry": state.get("registry", {})}
|
||||
if inferred:
|
||||
new_state["guessed"] = sorted(inferred)
|
||||
written = 0
|
||||
if values or new_state["registry"]:
|
||||
written, registry_notes = apply_registry(pfx, values, new_state, held)
|
||||
|
||||
@@ -150,6 +150,76 @@ class WinComponentsTest(unittest.TestCase):
|
||||
self.assertFalse((self.pfx / "syswow64/dmband.dll").exists())
|
||||
self.assertFalse((self.pfx / "syswow64/openal32.dll").exists())
|
||||
|
||||
def test_state_from_before_the_update_keeps_a_missing_bundles_parts(self):
|
||||
self.component("dmband", ["dmband"], {"syswow64/dmband.dll": b"band"})
|
||||
meta = self.store / "directmusic"
|
||||
meta.mkdir(parents=True)
|
||||
(meta / "component.json").write_text(json.dumps({"id": "directmusic", "overrides": [], "requires": ["dmband"]}))
|
||||
self.pick("directmusic")
|
||||
self.apply()
|
||||
state_file = self.compat / ".droiddeck-wincomponents.json"
|
||||
state = json.loads(state_file.read_text())
|
||||
rel = next(iter(state["files"]))
|
||||
state_file.write_text(json.dumps({"files": state["files"], "components": state["components"], "registry": {}}))
|
||||
for cid in ("dmband", "directmusic"):
|
||||
for path in sorted((self.store / cid).rglob("*"), reverse=True):
|
||||
path.rmdir() if path.is_dir() else path.unlink()
|
||||
(self.store / cid).rmdir()
|
||||
dll = self.compat / "pfx" / rel
|
||||
for _ in range(2):
|
||||
names, notes = self.apply()
|
||||
self.assertEqual(MODULE["overrides_value"](names), "dmband=n,b")
|
||||
self.assertEqual(dll.read_bytes(), b"band")
|
||||
self.assertEqual(len(notes), 2)
|
||||
saved = json.loads(state_file.read_text())
|
||||
self.assertEqual(saved["guessed"], ["directmusic"])
|
||||
self.assertNotIn("directmusic", saved["requires"])
|
||||
self.component("dmband", ["dmband"], {"syswow64/dmband.dll": b"band2"})
|
||||
names, _ = self.apply()
|
||||
self.assertEqual(MODULE["overrides_value"](names), "dmband=n,b")
|
||||
self.assertEqual(dll.read_bytes(), b"band2")
|
||||
self.assertEqual(json.loads(state_file.read_text())["guessed"], ["directmusic"])
|
||||
self.pick()
|
||||
self.apply()
|
||||
self.assertFalse(dll.exists())
|
||||
|
||||
def test_a_missing_legacy_bundle_with_its_own_files_keeps_its_parts_and_their_registry(self):
|
||||
self.pfx.parent.mkdir(parents=True)
|
||||
user = self.compat / "pfx/user.reg"
|
||||
user.write_text('WINE REGISTRY Version 2\n\n[Software\\\\Test] 1700000000\n"Mode"="ours"\n')
|
||||
ident = "HKCU\tsoftware\\test\tmode"
|
||||
own = self.compat / "pfx/drive_c/windows/syswow64/bundle.dll"
|
||||
part = self.compat / "pfx/drive_c/windows/syswow64/part.dll"
|
||||
for path in (own, part):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(b"x")
|
||||
self.compat.joinpath(".droiddeck-wincomponents.json").write_text(json.dumps({
|
||||
"files": {"drive_c/windows/syswow64/bundle.dll": "bundle", "drive_c/windows/syswow64/part.dll": "part"},
|
||||
"components": ["bundle", "part", "tweak"],
|
||||
"registry": {ident: {"prev": None, "cid": "tweak", "hive": "HKCU", "key": "Software\\Test", "name": "Mode"}}}))
|
||||
self.pick("bundle")
|
||||
names, _ = self.apply()
|
||||
self.assertEqual(set(MODULE["overrides_value"](names).split(";")), {"bundle=n,b", "part=n,b"})
|
||||
self.assertTrue(own.exists() and part.exists())
|
||||
self.assertIn('"Mode"="ours"', user.read_text())
|
||||
saved = json.loads((self.compat / ".droiddeck-wincomponents.json").read_text())
|
||||
self.assertEqual(saved["guessed"], ["bundle"])
|
||||
self.assertIn(ident, saved["registry"])
|
||||
|
||||
def test_a_missing_component_that_only_set_registry_values_keeps_them(self):
|
||||
self.pfx.parent.mkdir(parents=True)
|
||||
user = self.compat / "pfx/user.reg"
|
||||
user.write_text('WINE REGISTRY Version 2\n\n[Software\\\\Test] 1700000000\n"Mode"="ours"\n')
|
||||
ident = "HKCU\tsoftware\\test\tmode"
|
||||
self.compat.joinpath(".droiddeck-wincomponents.json").write_text(json.dumps({
|
||||
"files": {}, "components": ["tweak"], "requires": {}, "overrides": {"tweak": []},
|
||||
"registry": {ident: {"prev": None, "cid": "tweak", "hive": "HKCU", "key": "Software\\Test", "name": "Mode"}}}))
|
||||
self.pick("tweak")
|
||||
_, notes = self.apply()
|
||||
self.assertIn('"Mode"="ours"', user.read_text())
|
||||
self.assertIn("tweak is not in the store; kept the files it placed until it is installed again", notes)
|
||||
self.assertIn(ident, json.loads((self.compat / ".droiddeck-wincomponents.json").read_text())["registry"])
|
||||
|
||||
def test_no_selection_touches_nothing(self):
|
||||
self.assertEqual(self.apply(), ([], []))
|
||||
self.assertFalse(self.compat.exists())
|
||||
|
||||
Reference in new issue
Block a user