mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 01:45:28 +00:00
[lfs] Cache overlay info in memory to avoid unnecessary reads
This commit is contained in:
parent
4a743dc1ca
commit
b5120fa99d
|
@ -34,8 +34,9 @@ class LGDLFS:
|
||||||
self._game_metadata = dict()
|
self._game_metadata = dict()
|
||||||
# Legendary update check info
|
# Legendary update check info
|
||||||
self._update_info = None
|
self._update_info = None
|
||||||
# EOS Overlay update check info
|
# EOS Overlay install/update check info
|
||||||
self._overlay_update_info = None
|
self._overlay_update_info = None
|
||||||
|
self._overlay_install_info = None
|
||||||
# Config with game specific settings (e.g. start parameters, env variables)
|
# Config with game specific settings (e.g. start parameters, env variables)
|
||||||
self.config = LGDConf(comment_prefixes='/', allow_no_value=True)
|
self.config = LGDConf(comment_prefixes='/', allow_no_value=True)
|
||||||
|
|
||||||
|
@ -386,19 +387,23 @@ class LGDLFS:
|
||||||
indent=2, sort_keys=True)
|
indent=2, sort_keys=True)
|
||||||
|
|
||||||
def get_overlay_install_info(self):
|
def get_overlay_install_info(self):
|
||||||
try:
|
if not self._overlay_install_info:
|
||||||
data = json.load(open(os.path.join(self.path, f'overlay_install.json')))
|
try:
|
||||||
return InstalledGame.from_json(data)
|
data = json.load(open(os.path.join(self.path, f'overlay_install.json')))
|
||||||
except Exception as e:
|
self._overlay_install_info = InstalledGame.from_json(data)
|
||||||
self.log.debug(f'Failed to load overlay install data: {e!r}')
|
except Exception as e:
|
||||||
return None
|
self.log.debug(f'Failed to load overlay install data: {e!r}')
|
||||||
|
|
||||||
|
return self._overlay_install_info
|
||||||
|
|
||||||
def set_overlay_install_info(self, igame: InstalledGame):
|
def set_overlay_install_info(self, igame: InstalledGame):
|
||||||
|
self._overlay_install_info = igame
|
||||||
json.dump(vars(igame), open(os.path.join(self.path, 'overlay_install.json'), 'w'),
|
json.dump(vars(igame), open(os.path.join(self.path, 'overlay_install.json'), 'w'),
|
||||||
indent=2, sort_keys=True)
|
indent=2, sort_keys=True)
|
||||||
|
|
||||||
def remove_overlay_install_info(self):
|
def remove_overlay_install_info(self):
|
||||||
try:
|
try:
|
||||||
|
self._overlay_install_info = None
|
||||||
os.remove(os.path.join(self.path, 'overlay_install.json'))
|
os.remove(os.path.join(self.path, 'overlay_install.json'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.debug(f'Failed to delete overlay install data: {e!r}')
|
self.log.debug(f'Failed to delete overlay install data: {e!r}')
|
||||||
|
|
Loading…
Reference in a new issue