mirror of
https://github.com/lutris/lutris
synced 2024-07-01 06:34:26 +00:00
Implement get_app_states
This commit is contained in:
parent
12cfb0035a
commit
885fd8a391
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user