[lfs] Check if AppData/ProgramData paths exist (#421)

This commit is contained in:
Mathis Dröge 2022-05-29 18:17:16 +02:00 committed by GitHub
parent a12238e4ef
commit 823d672c2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,12 +34,18 @@ class EPCLFS:
if not self.appdata_path: if not self.appdata_path:
raise ValueError('EGS AppData path is not set') 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') self.config.read(os.path.join(self.appdata_path, 'GameUserSettings.ini'), encoding='utf-8')
def save_config(self): def save_config(self):
if not self.appdata_path: if not self.appdata_path:
raise ValueError('EGS AppData path is not set') 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: with open(os.path.join(self.appdata_path, 'GameUserSettings.ini'), 'w', encoding='utf-8') as f:
self.config.write(f, space_around_delimiters=False) self.config.write(f, space_around_delimiters=False)
@ -47,6 +53,10 @@ class EPCLFS:
if not self.programdata_path: if not self.programdata_path:
raise ValueError('EGS ProgramData path is not set') 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): for f in os.listdir(self.programdata_path):
if f.endswith('.item'): if f.endswith('.item'):
data = json.load(open(os.path.join(self.programdata_path, f), encoding='utf-8')) 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: if not self.programdata_path:
raise ValueError('EGS ProgramData path is not set') 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() manifest_data = manifest.to_json()
self.manifests[manifest.app_name] = manifest_data self.manifests[manifest.app_name] = manifest_data
_path = os.path.join(self.programdata_path, f'{manifest.installation_guid}.item') _path = os.path.join(self.programdata_path, f'{manifest.installation_guid}.item')