[models] Migrate app info to dataclasses, split platforms

This commit is contained in:
derrod 2021-12-01 20:46:10 +01:00
parent d0d37c40e7
commit ee3f9a3e07
2 changed files with 85 additions and 58 deletions

View file

@ -134,8 +134,8 @@ class EGLManifest:
tmp.app_version_string = igame.version tmp.app_version_string = igame.version
tmp.base_urls = igame.base_urls tmp.base_urls = igame.base_urls
tmp.build_label = 'Live' tmp.build_label = 'Live'
tmp.catalog_item_id = game.asset_info.catalog_item_id tmp.catalog_item_id = game.asset_infos['Windows'].catalog_item_id
tmp.namespace = game.asset_info.namespace tmp.namespace = game.asset_infos['Windows'].namespace
tmp.display_name = igame.title tmp.display_name = igame.title
tmp.install_location = igame.install_path tmp.install_location = igame.install_path
tmp.install_size = igame.install_size tmp.install_size = igame.install_size

View file

@ -1,17 +1,23 @@
# coding: utf-8 # coding: utf-8
from datetime import datetime
from dataclasses import dataclass, field from dataclasses import dataclass, field
from enum import Enum from enum import Enum
from typing import Optional, List, Dict
@dataclass
class GameAsset: class GameAsset:
def __init__(self): """
self.app_name = '' App asset data
self.asset_id = '' """
self.build_version = '' app_name: str = ''
self.catalog_item_id = '' asset_id: str = ''
self.label_name = '' build_version: str = ''
self.namespace = '' catalog_item_id: str = ''
self.metadata = dict() label_name: str = ''
namespace: str = ''
metadata: Dict = field(default_factory=dict)
@classmethod @classmethod
def from_egs_json(cls, json): def from_egs_json(cls, json):
@ -38,15 +44,22 @@ class GameAsset:
return tmp return tmp
@dataclass
class Game: class Game:
def __init__(self, app_name='', app_title='', asset_info=None, app_version='', metadata=None): """
self.metadata = dict() if metadata is None else metadata # store metadata from EGS Combination of app asset and app metadata as stored on disk
self.asset_info = asset_info if asset_info else GameAsset() # asset info from EGS """
app_name: str
app_title: str
self.app_version = app_version asset_infos: Dict[str, GameAsset] = field(default_factory=dict)
self.app_name = app_name base_urls: List[str] = field(default_factory=list)
self.app_title = app_title metadata: Dict = field(default_factory=dict)
self.base_urls = [] # base urls for download, only really used when cached manifest is current
def app_version(self, platform='Windows'):
if platform not in self.asset_infos:
return None
return self.asset_infos[platform].build_version
@property @property
def is_dlc(self): def is_dlc(self):
@ -64,57 +77,63 @@ class Game:
@classmethod @classmethod
def from_json(cls, json): def from_json(cls, json):
tmp = cls() tmp = cls(
app_name=json.get('app_name', ''),
app_title=json.get('app_title', ''),
)
tmp.metadata = json.get('metadata', dict()) tmp.metadata = json.get('metadata', dict())
tmp.asset_info = GameAsset.from_json(json.get('asset_info', dict())) if 'asset_infos' in json:
tmp.app_name = json.get('app_name', 'undefined') tmp.asset_infos = {k: GameAsset.from_json(v) for k, v in json['asset_infos'].items()}
tmp.app_title = json.get('app_title', 'undefined') else:
tmp.app_version = json.get('app_version', 'undefined') # Migrate old asset_info to new asset_infos
tmp.asset_infos['Windows'] = GameAsset.from_json(json.get('asset_info', dict()))
tmp.base_urls = json.get('base_urls', list()) tmp.base_urls = json.get('base_urls', list())
return tmp return tmp
@property @property
def __dict__(self): def __dict__(self):
"""This is just here so asset_info gets turned into a dict as well""" """This is just here so asset_infos gets turned into a dict as well"""
return dict(metadata=self.metadata, asset_info=self.asset_info.__dict__, assets_dictified = {k: v.__dict__ for k, v in self.asset_infos.items()}
app_name=self.app_name, app_title=self.app_title, return dict(metadata=self.metadata, asset_infos=assets_dictified, app_name=self.app_name,
app_version=self.app_version, base_urls=self.base_urls) app_title=self.app_title, base_urls=self.base_urls)
@dataclass
class InstalledGame: class InstalledGame:
def __init__(self, app_name='', title='', version='', manifest_path='', base_urls=None, """
install_path='', executable='', launch_parameters='', prereq_info=None, Local metadata for an installed app
can_run_offline=False, requires_ot=False, is_dlc=False, save_path=None, """
needs_verification=False, install_size=0, egl_guid='', install_tags=None): app_name: str
self.app_name = app_name install_path: str
self.title = title title: str
self.version = version version: str
self.manifest_path = manifest_path base_urls: List[str] = field(default_factory=list)
self.base_urls = list() if not base_urls else base_urls can_run_offline: bool = False
self.install_path = install_path egl_guid: str = ''
self.executable = executable executable: str = ''
self.launch_parameters = launch_parameters install_size: int = 0
self.prereq_info = prereq_info install_tags: List[str] = field(default_factory=list)
self.can_run_offline = can_run_offline is_dlc: bool = False
self.requires_ot = requires_ot launch_parameters: str = ''
self.is_dlc = is_dlc manifest_path: str = ''
self.save_path = save_path needs_verification: bool = False
self.needs_verification = needs_verification platform: str = 'Windows'
self.install_size = install_size prereq_info: Optional[Dict] = None
self.egl_guid = egl_guid requires_ot: bool = False
self.install_tags = install_tags if install_tags else [] save_path: Optional[str] = None
@classmethod @classmethod
def from_json(cls, json): def from_json(cls, json):
tmp = cls() tmp = cls(
tmp.app_name = json.get('app_name', '') app_name=json.get('app_name', ''),
tmp.version = json.get('version', '') install_path=json.get('install_path', ''),
tmp.title = json.get('title', '') title=json.get('title', ''),
version=json.get('version', ''),
)
tmp.manifest_path = json.get('manifest_path', '')
tmp.base_urls = json.get('base_urls', list()) tmp.base_urls = json.get('base_urls', list())
tmp.install_path = json.get('install_path', '')
tmp.executable = json.get('executable', '') tmp.executable = json.get('executable', '')
tmp.launch_parameters = json.get('launch_parameters', '') tmp.launch_parameters = json.get('launch_parameters', '')
tmp.prereq_info = json.get('prereq_info', None) tmp.prereq_info = json.get('prereq_info', None)
@ -123,19 +142,24 @@ class InstalledGame:
tmp.requires_ot = json.get('requires_ot', False) tmp.requires_ot = json.get('requires_ot', False)
tmp.is_dlc = json.get('is_dlc', False) tmp.is_dlc = json.get('is_dlc', False)
tmp.save_path = json.get('save_path', None) tmp.save_path = json.get('save_path', None)
tmp.manifest_path = json.get('manifest_path', '')
tmp.needs_verification = json.get('needs_verification', False) is True tmp.needs_verification = json.get('needs_verification', False) is True
tmp.platform = json.get('platform', 'Windows')
tmp.install_size = json.get('install_size', 0) tmp.install_size = json.get('install_size', 0)
tmp.egl_guid = json.get('egl_guid', '') tmp.egl_guid = json.get('egl_guid', '')
tmp.install_tags = json.get('install_tags', []) tmp.install_tags = json.get('install_tags', [])
return tmp return tmp
@dataclass
class SaveGameFile: class SaveGameFile:
def __init__(self, app_name='', filename='', manifest='', datetime=None): """
self.app_name = app_name Metadata for a cloud save manifest
self.filename = filename """
self.manifest_name = manifest app_name: str
self.datetime = datetime filename: str
manifest_name: str
datetime: Optional[datetime] = None
class SaveGameStatus(Enum): class SaveGameStatus(Enum):
@ -154,6 +178,9 @@ class VerifyResult(Enum):
@dataclass @dataclass
class LaunchParameters: class LaunchParameters:
"""
Parameters for launching a game
"""
# game-supplied parameters # game-supplied parameters
game_parameters: list = field(default_factory=list) game_parameters: list = field(default_factory=list)
game_executable: str = '' game_executable: str = ''