From 885fd8a3914aea49b3f3dce1b46f848596a054a4 Mon Sep 17 00:00:00 2001 From: Mathieu Comandon Date: Sat, 5 Sep 2015 15:50:33 -0700 Subject: [PATCH] Implement get_app_states --- docs/steam.rst | 44 ++++++++++++++++++------------------- lutris/util/steam.py | 52 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 71 insertions(+), 25 deletions(-) diff --git a/docs/steam.rst b/docs/steam.rst index 31007dae2..875a9fda4 100644 --- a/docs/steam.rst +++ b/docs/steam.rst @@ -3,25 +3,25 @@ AppState -------- :: - StateInvalid = 0, - StateUninstalled, - StateUpdateRequired, - StateFullyInstalled = 4, - StateEncrypted = 8, - StateLocked = 16, - StateFilesMissing = 32, - StateFilesCorrupt = 128, - StateAppRunning = 64, - StateBackupRunning = 4096, - StateUpdateRunning = 256, - StateUpdateStopping = 8388608, - StateUpdatePaused = 512, - StateUpdateStarted = 1024, - StateReconfiguring = 65536, - StateAddingFiles = 262144, - StateDownloading = 1048576, - StateStaging = 2097152, - StateCommitting = 4194304, - StateUninstalling = 2048, - StatePreallocating = 524288, - StateValidating = 131072 + StateInvalid 0 + StateUninstalled 1 + StateUpdateRequired 2 + StateFullyInstalled 4 + StateEncrypted 8 + StateLocked 16 + StateFilesMissing 32 + StateAppRunning 64 + StateFilesCorrupt 128 + StateUpdateRunning 256 + StateUpdatePaused 512 + StateUpdateStarted 1024 + StateUninstalling 2048 + StateBackupRunning 4096 + StateReconfiguring 65536 + StateValidating 131072 + StateAddingFiles 262144 + StatePreallocating 524288 + StateDownloading 1048576 + StateStaging 2097152 + StateCommitting 4194304 + StateUpdateStopping 8388608 diff --git a/lutris/util/steam.py b/lutris/util/steam.py index 26f103e8b..4f661848d 100644 --- a/lutris/util/steam.py +++ b/lutris/util/steam.py @@ -3,6 +3,32 @@ from lutris.util.log import logger from collections import OrderedDict +APP_STATE_FLAGS = [ + "Invalid", + "Uninstalled", + "Update Required", + "Fully Installed", + "Encrypted", + "Locked", + "Files Missing", + "AppRunning", + "Files Corrupt", + "Update Running", + "Update Paused", + "Update Started", + "Uninstalling", + "Backup Running", + "Reconfiguring", + "Validating", + "Adding Files", + "Preallocating", + "Downloading", + "Staging", + "Committing", + "Update Stopping" +] + + def get_default_acf(appid, name): userconfig = OrderedDict() userconfig['name'] = name @@ -70,7 +96,9 @@ def read_config(path_prefix): return config -def get_path_from_appmanifest(steamapps_path, appid): +def get_manifest_info(steamapps_path, appid): + """Given the steam apps path and appid, return the corresponding appmanifest + info.""" if not steamapps_path: raise ValueError("steamapps_path is mandatory") if not os.path.exists(steamapps_path): @@ -81,11 +109,29 @@ def get_path_from_appmanifest(steamapps_path, appid): "appmanifest_%s.acf" % appid) if not os.path.exists(appmanifest_path): return - with open(appmanifest_path, "r") as appmanifest_file: config = vdf_parse(appmanifest_file, {}) + return config + + +def get_path_from_appmanifest(steamapps_path, appid): + """Return the path where a Steam game is installed""" + config = get_manifest_info(steamapps_path, appid) + if not config: + return installdir = config.get('AppState', {}).get('installdir') - logger.debug("Game %s should be in %s", appid, installdir) install_path = os.path.join(steamapps_path, "common", installdir) if installdir and os.path.exists(install_path): return install_path + + +def get_app_states(steamapps_path, appid): + """Return the states of a Steam game""" + manifest_info = get_manifest_info(steamapps_path, appid) + state_flags = manifest_info.get('AppState', {}).get('StateFlags') + state_flags = bin(state_flags)[:1:-1] + states = [] + for index, flag in enumerate(state_flags): + if flag == '1': + states.append(APP_STATE_FLAGS[index]) + return states