From 8edb723f090a4645ab6c99ba51e3cb4c15d62fea Mon Sep 17 00:00:00 2001 From: Taeyeon Mori Date: Thu, 25 Jun 2020 19:01:19 +0200 Subject: [PATCH] python/steamutil,steamsync: Add windows support --- bin/sync_savegames | 5 +++-- lib/python/steamsync.py | 10 ++++++---- lib/python/steamutil.py | 32 +++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/bin/sync_savegames b/bin/sync_savegames index 39777f3..d9fc768 100755 --- a/bin/sync_savegames +++ b/bin/sync_savegames @@ -19,8 +19,9 @@ sync = SteamSync(Path("~/Nextcloud/Misc/Savegames").expanduser()) @sync.by_name("zanzarah") def zanzarah(op): with op.game_directory.prefix("Save") as set: - set += "*" - set.execute() + set += "*.dat" + if set.show_confirm(): + set.execute() #@sync.by_id(787860) def fs19(op): diff --git a/lib/python/steamsync.py b/lib/python/steamsync.py index 80c402e..d54051e 100644 --- a/lib/python/steamsync.py +++ b/lib/python/steamsync.py @@ -10,7 +10,7 @@ import shutil from pathlib import Path from typing import Tuple, Dict, List, Union, Set, Callable, Any -from steamutil import Steam, App, CachedProperty +from steamutil import Steam, App, CachedProperty, MalformedManifestError class AppNotFoundType: @@ -137,9 +137,11 @@ class SyncSet: print(" Target is newer: ", ", ".join(map(str, self.files_from_target))) print(" Unmodified: ", ", ".join(map(str, self.files_unmodified))) - print("Press enter to continue") - input() - return True # TODO: Proper thingey + print("Continue? ", end="") + resp = input().strip() + if resp.lower() in ("y", "yes", ""): + return True + return False def execute(self, *, make_inconsistent=False) -> bool: operations = [] diff --git a/lib/python/steamutil.py b/lib/python/steamutil.py index 2a08a24..5dc680f 100644 --- a/lib/python/steamutil.py +++ b/lib/python/steamutil.py @@ -77,6 +77,12 @@ class DictPathProperty(DictPathRoProperty): _vdf = VdfParser() +class MalformedManifestError(Exception): + @property + def filename(self): + return self.args[1] + + class App: steam: 'Steam' library_folder: 'LibraryFolder' @@ -95,6 +101,9 @@ class App: self.manifest = _vdf.parse(f) else: self.manifest = manifest_data + + if "AppState" not in self.manifest: + raise MalformedManifestError("App manifest doesn't have AppState key", self.manifest_path) def __repr__(self): return "" % (self.appid, self.name, self.install_path) @@ -185,7 +194,11 @@ class LibraryFolder: @property def apps(self) -> Iterable[App]: - return (App(self, mf) for mf in self.appmanifests) + for mf in self.appmanifests: + try: + yield App(self, mf) + except MalformedManifestError as e: + print("Warning: Malformed app manifest:", e.filename) def get_app(self, appid: int) -> Optional[App]: manifest = self.steamapps_path / ("appmanifest_%d.acf" % appid) @@ -309,6 +322,23 @@ class Steam: steamroot = path / name if steamroot.exists(): return steamroot + elif sys.platform.startswith("win"): + try: + import winreg + key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Valve\\Steam") + path, t = winreg.QueryValueEx(key, "steampath") + if (t == winreg.REG_SZ): + return Path(path) + except WindowsError: + pass + # try PROGRAMFILES + pfiles = (os.environ.get("ProgramFiles(x86)", "C:\Program Files (x86)"), + os.environ.get("ProgramFiles", "C:\Program Files")) + for path in pfiles: + if path.exists(): + path /= "Steam" + if path.exists(): + return path # Various paths @property