diff --git a/lutris/api.py b/lutris/api.py index ae20e70ef..807396cf9 100644 --- a/lutris/api.py +++ b/lutris/api.py @@ -19,7 +19,6 @@ from lutris.util.log import logger API_KEY_FILE_PATH = os.path.join(settings.CACHE_DIR, "auth-token") USER_INFO_FILE_PATH = os.path.join(settings.CACHE_DIR, "user.json") -USER_ICON_FILE_PATH = os.path.join(settings.CACHE_DIR, "user.png") def read_api_key(): @@ -95,7 +94,7 @@ def get_runners(runner_name): @functools.lru_cache() -def get_default_runner_version(runner_name, version=None): +def get_default_runner_version(runner_name: str, version: str = ""): """Get the appropriate version for a runner Params: diff --git a/lutris/runtime.py b/lutris/runtime.py index 402a0ed9c..d54ba2025 100644 --- a/lutris/runtime.py +++ b/lutris/runtime.py @@ -1,5 +1,6 @@ """Runtime handling module""" import concurrent.futures +import json import os import time @@ -12,11 +13,11 @@ from lutris.util.downloader import Downloader from lutris.util.extract import extract_archive from lutris.util.linux import LINUX_SYSTEM from lutris.util.log import logger -from lutris.util.wine.dxvk import DXVKManager -from lutris.util.wine.vkd3d import VKD3DManager from lutris.util.wine.d3d_extras import D3DExtrasManager from lutris.util.wine.dgvoodoo2 import dgvoodoo2Manager +from lutris.util.wine.dxvk import DXVKManager from lutris.util.wine.dxvk_nvapi import DXVKNVAPIManager +from lutris.util.wine.vkd3d import VKD3DManager RUNTIME_DISABLED = os.environ.get("LUTRIS_RUNTIME", "").lower() in ("0", "off") DEFAULT_RUNTIME = "Ubuntu-18.04" @@ -29,6 +30,7 @@ DLL_MANAGERS = { "dxvk_nvapi": DXVKNVAPIManager, } + class Runtime: """Class for manipulating runtime folders""" @@ -222,14 +224,13 @@ class RuntimeUpdater: update_functions = [] downloaders = {} - def __init__(self, pci_ids=None, force=False): - + def __init__(self, pci_ids:list=None, force:bool=False): self.force = force self.pci_ids = pci_ids or [] - self.runtime_versions = None + self.runtime_versions = {} self.add_update("runtime", self._update_runtime_components, hours=12) - def add_update(self, key, update_function, hours): + def add_update(self, key:str, update_function, hours): """__init__ calls this to register each update. This function only registers the update if it hasn't been tried in the last 'hours' hours. This is trakced in 'updates.json', and identified @@ -239,14 +240,29 @@ class RuntimeUpdater: self.update_functions.append((key, update_function)) @property - def has_updates(self): + def has_updates(self)->bool: """Returns True if there are any updates to perform.""" return len(self.update_functions) > 0 + def download_runtime_versions(self): + """Download runtime versions from Lutris.net""" + self.runtime_versions = get_runtime_versions(self.pci_ids) + with open(os.path.join(settings.RUNTIME_VERSIONS_PATH, "w"), encoding="utf-8") as runtime_file: + json.dump(self.runtime_versions, runtime_file) + return self.runtime_versions + + def load_runtime_versions(self)->dict: + """Load runtime versions from json file""" + if not system.path_exists(settings.RUNTIME_VERSIONS_PATH): + return {} + with open(os.path.join(settings.RUNTIME_VERSIONS_PATH, "r"), encoding="utf-8") as runtime_file: + self.runtime_versions = json.load(runtime_file) + return self.runtime_versions + def update_runtimes(self): """Performs all the registered updates. If 'self.cancel()' is called, it will immediately stop.""" - self.runtime_versions = get_runtime_versions(self.pci_ids) + self.download_runtime_versions() for key, func in self.update_functions: if self.cancelled: break diff --git a/lutris/settings.py b/lutris/settings.py index c8f7f45f6..eeafc848a 100644 --- a/lutris/settings.py +++ b/lutris/settings.py @@ -29,6 +29,7 @@ GAME_CONFIG_DIR = os.path.join(CONFIG_DIR, "games") SHADER_CACHE_DIR = os.path.join(CACHE_DIR, "shaders") BANNER_PATH = os.path.join(CACHE_DIR, "banners") COVERART_PATH = os.path.join(CACHE_DIR, "coverart") +RUNTIME_VERSIONS_PATH = os.path.join(CACHE_DIR, "versions.json") ICON_PATH = os.path.join(GLib.get_user_data_dir(), "icons", "hicolor", "128x128", "apps") if "nosetests" in sys.argv[0] or "nose2" in sys.argv[0] or "pytest" in sys.argv[0]: