mirror of
https://github.com/ModOrganizer2/modorganizer-basic_games.git
synced 2026-07-27 14:07:29 -07:00
Merge pull request #28 from LostDragonist/corrupt_manifest
Add robustness to reading Steam manifest files
This commit is contained in:
+18
-15
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user