mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
Stores: cloud saves recognise GOG games, wait for a new prefix, never overwrite blindly
On device nothing ran for ELDERBORN: a GOG game without arguments has no launcher .bat, Steam runs its exe, and droiddeck-store-launch only looked for the .bat. It now recognises the exe too, looking through the folders above it for the sidecar, and every path logs a result line. A first launch has no prefix yet: the download is answered as deferred and runs once Proton has made the prefix's user folder, within a minute, without holding the launch. Uploads are safe now. CloudPlan decides per file against this device's baseline - the local and cloud state at the last sync: no upload before a download has completed once, the first download lets the cloud win, and a file changed on both sides is a conflict that Manage saves offers to settle with Keep cloud or Keep local. The cloud copy is backed up before an upload replaces it, as the local folder is before a download.
This commit is contained in:
1 parent
b323a0b33e
commit
41422407c4
11 files changed
+464
-87
No files matched your search
@@ -47,20 +47,39 @@ def log(line):
|
||||
print("droiddeck-store-launch: " + line, file=sys.stderr, flush=True)
|
||||
|
||||
|
||||
MAX_DEPTH = 6
|
||||
|
||||
|
||||
def sidecar_at(folder):
|
||||
try:
|
||||
sidecar = json.loads((folder / SIDECAR).read_text())
|
||||
except (OSError, ValueError):
|
||||
return None
|
||||
if not isinstance(sidecar, dict) or not sidecar.get("store") or not sidecar.get("id"):
|
||||
return None
|
||||
return sidecar
|
||||
|
||||
|
||||
def find_store_game(argv):
|
||||
"""The (folder, sidecar) of the store launcher among [argv], or None when this is not one."""
|
||||
"""
|
||||
The (folder, sidecar) of a store game among [argv], or None when this is not one. Steam passes
|
||||
the shortcut's target: the launcher .bat when the game has one (Epic, Amazon, a GOG game with
|
||||
arguments), else the game's exe itself (most GOG games), which may sit in a subfolder - so the
|
||||
folders above it are looked through too, up to MAX_DEPTH, for the sidecar.
|
||||
"""
|
||||
for raw in argv:
|
||||
arg = raw.strip().strip('"').strip("'")
|
||||
if not arg.lower().endswith(LAUNCHER):
|
||||
arg = raw.strip().strip('"').strip("'").replace("\\", "/")
|
||||
low = arg.lower()
|
||||
if not (low.endswith(LAUNCHER) or low.endswith(".exe") or low.endswith(".bat")) or "/" not in arg:
|
||||
continue
|
||||
folder = Path(arg.replace("\\", "/")).parent
|
||||
try:
|
||||
sidecar = json.loads((folder / SIDECAR).read_text())
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
if not isinstance(sidecar, dict) or not sidecar.get("store") or not sidecar.get("id"):
|
||||
continue
|
||||
return folder, sidecar
|
||||
folder = Path(arg).parent
|
||||
for _ in range(MAX_DEPTH):
|
||||
sidecar = sidecar_at(folder)
|
||||
if sidecar is not None:
|
||||
return folder, sidecar
|
||||
if folder.parent == folder:
|
||||
break
|
||||
folder = folder.parent
|
||||
return None
|
||||
|
||||
|
||||
@@ -275,6 +294,8 @@ def main(argv):
|
||||
log("epic launch id=%s code=%s reason=%s" % (game, "yes" if got else "no", answer.get("reason", "")))
|
||||
log("epic prefix=%s %s" % (prefix_id or "?", provision_prefix(compat_data)))
|
||||
if not cloud_on(sidecar):
|
||||
if store in CLOUD_STORES:
|
||||
log("cloud %s %s down result=skipped reason=off" % (store, game))
|
||||
return 0
|
||||
if launch_dir:
|
||||
# The cloud copy where it is newer, before the game reads its saves; bounded, then on regardless.
|
||||
@@ -282,7 +303,9 @@ def main(argv):
|
||||
if answer is None:
|
||||
log("cloud %s %s down result=timeout" % (store, game))
|
||||
else:
|
||||
log("cloud %s %s down files=%s result=%s" % (store, game, answer.get("files", 0), answer.get("reason", "")))
|
||||
log("cloud %s %s down result=%s files=%s reason=%s" % (store, game, answer.get("result", "?"), answer.get("files", 0), answer.get("reason", "")))
|
||||
else:
|
||||
log("cloud %s %s down result=skipped reason=no-channel" % (store, game))
|
||||
return STORE_GAME
|
||||
|
||||
|
||||
|
||||
@@ -55,7 +55,9 @@ class Detection(unittest.TestCase):
|
||||
def test_anything_else_is_left_alone(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root)
|
||||
self.assertIsNone(store.find_store_game([str(folder / 'Metalstorm.exe')]))
|
||||
# The exe of a store game is one too (a GOG game without a launcher); a stray file is not.
|
||||
self.assertEqual(folder, store.find_store_game([str(folder / 'Metalstorm.exe')])[0])
|
||||
self.assertIsNone(store.find_store_game([str(Path(root) / 'elsewhere/readme.txt')]))
|
||||
(folder / '.droiddeck-store.json').unlink()
|
||||
self.assertIsNone(store.find_store_game([str(folder / '.droiddeck-launch.bat')]))
|
||||
|
||||
@@ -193,6 +195,20 @@ class Browser(unittest.TestCase):
|
||||
self.assertEqual('https://www.epicgames.com', xdg.where('https://www.epicgames.com/activate?code=SECRET'))
|
||||
|
||||
|
||||
class ExeTarget(unittest.TestCase):
|
||||
def test_a_game_started_by_its_exe_is_found_from_a_subfolder(self):
|
||||
# Most GOG games have no launcher .bat: Steam runs the exe, which may sit in a subfolder.
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='1207664643')
|
||||
(folder / 'bin/x64').mkdir(parents=True)
|
||||
exe = folder / 'bin/x64/ELDERBORN.exe'
|
||||
exe.write_text('MZ')
|
||||
found = store.find_store_game(['"%s"' % exe])
|
||||
self.assertEqual(folder, found[0])
|
||||
self.assertEqual('gog', found[1]['store'])
|
||||
self.assertIsNone(store.find_store_game(['/root/Games/Other/x.exe']))
|
||||
|
||||
|
||||
class CloudHooks(unittest.TestCase):
|
||||
def test_a_store_game_with_cloud_saves_asks_before_and_after(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
|
||||
Reference in new issue
Block a user