From 823d672c2c8863a5dc3ddaa6208f2ee991cffcd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= <34034631+CommandMC@users.noreply.github.com> Date: Sun, 29 May 2022 18:17:16 +0200 Subject: [PATCH] [lfs] Check if AppData/ProgramData paths exist (#421) --- legendary/lfs/egl.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/legendary/lfs/egl.py b/legendary/lfs/egl.py index 88c4cfa..5311e8a 100644 --- a/legendary/lfs/egl.py +++ b/legendary/lfs/egl.py @@ -34,12 +34,18 @@ class EPCLFS: 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) @@ -47,6 +53,10 @@ class EPCLFS: 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')) @@ -71,6 +81,9 @@ class EPCLFS: 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')