1
0
mirror of https://github.com/lutris/lutris synced 2024-07-05 16:38:42 +00:00

Implement get_app_states

This commit is contained in:
Mathieu Comandon 2015-09-05 15:50:33 -07:00
parent 12cfb0035a
commit 885fd8a391
2 changed files with 71 additions and 25 deletions

View File

@ -3,25 +3,25 @@ AppState
-------- --------
:: ::
StateInvalid = 0, StateInvalid 0
StateUninstalled, StateUninstalled 1
StateUpdateRequired, StateUpdateRequired 2
StateFullyInstalled = 4, StateFullyInstalled 4
StateEncrypted = 8, StateEncrypted 8
StateLocked = 16, StateLocked 16
StateFilesMissing = 32, StateFilesMissing 32
StateFilesCorrupt = 128, StateAppRunning 64
StateAppRunning = 64, StateFilesCorrupt 128
StateBackupRunning = 4096, StateUpdateRunning 256
StateUpdateRunning = 256, StateUpdatePaused 512
StateUpdateStopping = 8388608, StateUpdateStarted 1024
StateUpdatePaused = 512, StateUninstalling 2048
StateUpdateStarted = 1024, StateBackupRunning 4096
StateReconfiguring = 65536, StateReconfiguring 65536
StateAddingFiles = 262144, StateValidating 131072
StateDownloading = 1048576, StateAddingFiles 262144
StateStaging = 2097152, StatePreallocating 524288
StateCommitting = 4194304, StateDownloading 1048576
StateUninstalling = 2048, StateStaging 2097152
StatePreallocating = 524288, StateCommitting 4194304
StateValidating = 131072 StateUpdateStopping 8388608

View File

@ -3,6 +3,32 @@ from lutris.util.log import logger
from collections import OrderedDict 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): def get_default_acf(appid, name):
userconfig = OrderedDict() userconfig = OrderedDict()
userconfig['name'] = name userconfig['name'] = name
@ -70,7 +96,9 @@ def read_config(path_prefix):
return config 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: if not steamapps_path:
raise ValueError("steamapps_path is mandatory") raise ValueError("steamapps_path is mandatory")
if not os.path.exists(steamapps_path): if not os.path.exists(steamapps_path):
@ -81,11 +109,29 @@ def get_path_from_appmanifest(steamapps_path, appid):
"appmanifest_%s.acf" % appid) "appmanifest_%s.acf" % appid)
if not os.path.exists(appmanifest_path): if not os.path.exists(appmanifest_path):
return return
with open(appmanifest_path, "r") as appmanifest_file: with open(appmanifest_path, "r") as appmanifest_file:
config = vdf_parse(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') 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) install_path = os.path.join(steamapps_path, "common", installdir)
if installdir and os.path.exists(install_path): if installdir and os.path.exists(install_path):
return 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