Skip to content

Commit

Permalink
[lfs] Check if AppData/ProgramData paths exist (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
CommandMC committed May 29, 2022
1 parent a12238e commit 823d672
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions legendary/lfs/egl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,29 @@ def read_config(self):
if not self.appdata_path:
raise ValueError('EGS AppData path is not set')

if not os.path.isdir(self.appdata_path):
raise ValueError('EGS AppData path does not exist')

self.config.read(os.path.join(self.appdata_path, 'GameUserSettings.ini'), encoding='utf-8')

def save_config(self):
if not self.appdata_path:
raise ValueError('EGS AppData path is not set')

if not os.path.isdir(self.appdata_path):
raise ValueError('EGS AppData path does not exist')

with open(os.path.join(self.appdata_path, 'GameUserSettings.ini'), 'w', encoding='utf-8') as f:
self.config.write(f, space_around_delimiters=False)

def read_manifests(self):
if not self.programdata_path:
raise ValueError('EGS ProgramData path is not set')

if not os.path.isdir(self.programdata_path):
# Not sure if we should `raise` here as well
return

for f in os.listdir(self.programdata_path):
if f.endswith('.item'):
data = json.load(open(os.path.join(self.programdata_path, f), encoding='utf-8'))
Expand All @@ -71,6 +81,9 @@ def set_manifest(self, manifest: EGLManifest):
if not self.programdata_path:
raise ValueError('EGS ProgramData path is not set')

if not os.path.isdir(self.programdata_path):
raise ValueError('EGS ProgramData path does not exist')

manifest_data = manifest.to_json()
self.manifests[manifest.app_name] = manifest_data
_path = os.path.join(self.programdata_path, f'{manifest.installation_guid}.item')
Expand Down

0 comments on commit 823d672

Please sign in to comment.