diff --git a/steam_utils.py b/steam_utils.py index a1d72f8..84ad7b7 100644 --- a/steam_utils.py +++ b/steam_utils.py @@ -3,6 +3,7 @@ # Code greatly inspired by https://github.com/LostDragonist/steam-library-setup-tool import os +import sys import winreg # type: ignore from pathlib import Path @@ -28,23 +29,25 @@ class LibraryFolder: self.games = [] for filename in os.listdir(os.path.join(path, "steamapps")): if filename.startswith("appmanifest"): - with open( - os.path.join(path, "steamapps", filename), "r", encoding="utf-8" - ) as fp: - i, n = None, None - for line in fp: - line = line.strip() + filepath = os.path.join(path, "steamapps", filename) + try: + with open(filepath, "r", encoding="utf-8") as fp: + i, n = None, None + for line in fp: + line = line.strip() - if line.startswith('"appid"'): - i = line.replace('"appid"', "").strip()[1:-1] - if line.startswith('"installdir"'): - n = line.replace('"installdir"', "").strip()[1:-1] + if line.startswith('"appid"'): + i = line.replace('"appid"', "").strip()[1:-1] + if line.startswith('"installdir"'): + n = line.replace('"installdir"', "").strip()[1:-1] - if i is not None and n is not None: - break - if i is None or n is None: - continue - self.games.append(SteamGame(i, n)) + if i is not None and n is not None: + break + if i is None or n is None: + continue + self.games.append(SteamGame(i, n)) + except UnicodeDecodeError: + print('Unable to parse file "{}"'.format(filepath), file=sys.stderr) def __repr__(self): return str(self)