Merge pull request #28 from LostDragonist/corrupt_manifest

Add robustness to reading Steam manifest files
This commit is contained in:
Mikaël Capelle
2021-01-09 21:14:08 +01:00
committed by GitHub
+18 -15
View File
@@ -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)