python/steamutil,steamsync: Add windows support

master
Taeyeon Mori 5 years ago
parent 71f3810b0e
commit 8edb723f09
  1. 5
      bin/sync_savegames
  2. 10
      lib/python/steamsync.py
  3. 32
      lib/python/steamutil.py

@ -19,8 +19,9 @@ sync = SteamSync(Path("~/Nextcloud/Misc/Savegames").expanduser())
@sync.by_name("zanzarah") @sync.by_name("zanzarah")
def zanzarah(op): def zanzarah(op):
with op.game_directory.prefix("Save") as set: with op.game_directory.prefix("Save") as set:
set += "*" set += "*.dat"
set.execute() if set.show_confirm():
set.execute()
#@sync.by_id(787860) #@sync.by_id(787860)
def fs19(op): def fs19(op):

@ -10,7 +10,7 @@ import shutil
from pathlib import Path from pathlib import Path
from typing import Tuple, Dict, List, Union, Set, Callable, Any 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: class AppNotFoundType:
@ -137,9 +137,11 @@ class SyncSet:
print(" Target is newer: ", ", ".join(map(str, self.files_from_target))) print(" Target is newer: ", ", ".join(map(str, self.files_from_target)))
print(" Unmodified: ", ", ".join(map(str, self.files_unmodified))) print(" Unmodified: ", ", ".join(map(str, self.files_unmodified)))
print("Press enter to continue") print("Continue? <Y/n> ", end="")
input() resp = input().strip()
return True # TODO: Proper thingey if resp.lower() in ("y", "yes", ""):
return True
return False
def execute(self, *, make_inconsistent=False) -> bool: def execute(self, *, make_inconsistent=False) -> bool:
operations = [] operations = []

@ -77,6 +77,12 @@ class DictPathProperty(DictPathRoProperty):
_vdf = VdfParser() _vdf = VdfParser()
class MalformedManifestError(Exception):
@property
def filename(self):
return self.args[1]
class App: class App:
steam: 'Steam' steam: 'Steam'
library_folder: 'LibraryFolder' library_folder: 'LibraryFolder'
@ -95,6 +101,9 @@ class App:
self.manifest = _vdf.parse(f) self.manifest = _vdf.parse(f)
else: else:
self.manifest = manifest_data 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): def __repr__(self):
return "<steamutil.App %d '%s' @ \"%s\">" % (self.appid, self.name, self.install_path) return "<steamutil.App %d '%s' @ \"%s\">" % (self.appid, self.name, self.install_path)
@ -185,7 +194,11 @@ class LibraryFolder:
@property @property
def apps(self) -> Iterable[App]: 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]: def get_app(self, appid: int) -> Optional[App]:
manifest = self.steamapps_path / ("appmanifest_%d.acf" % appid) manifest = self.steamapps_path / ("appmanifest_%d.acf" % appid)
@ -309,6 +322,23 @@ class Steam:
steamroot = path / name steamroot = path / name
if steamroot.exists(): if steamroot.exists():
return steamroot 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 # Various paths
@property @property

Loading…
Cancel
Save