2022-07-27 02:41:23 +12:00
|
|
|
import os
|
|
|
|
from dataclasses import dataclass
|
2023-01-28 09:05:39 +13:00
|
|
|
from datetime import datetime, timedelta
|
2023-12-11 09:43:31 +13:00
|
|
|
from typing import List, Optional, Dict, Tuple
|
2022-07-27 02:41:23 +12:00
|
|
|
|
|
|
|
from legendary.models.downloading import AnalysisResult, ConditionCheckResult
|
|
|
|
from legendary.models.game import Game, InstalledGame
|
|
|
|
|
2022-10-27 14:00:48 +13:00
|
|
|
from rare.lgndr.downloader.mp.manager import DLManager
|
2022-08-03 11:33:50 +12:00
|
|
|
|
2022-07-27 02:41:23 +12:00
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class InstallOptionsModel:
|
|
|
|
app_name: str
|
|
|
|
base_path: str = ""
|
|
|
|
shared_memory: int = 1024
|
|
|
|
max_workers: int = os.cpu_count() * 2
|
|
|
|
force: bool = False
|
|
|
|
platform: str = "Windows"
|
|
|
|
install_tag: Optional[List[str]] = None
|
|
|
|
order_opt: bool = False
|
|
|
|
repair_mode: bool = False
|
|
|
|
repair_and_update: bool = False
|
|
|
|
no_install: bool = False
|
|
|
|
ignore_space: bool = False
|
2023-08-01 18:50:51 +12:00
|
|
|
reset_sdl: bool = False
|
2022-08-09 02:25:50 +12:00
|
|
|
skip_dlcs: bool = False
|
|
|
|
with_dlcs: bool = False
|
2022-07-27 02:41:23 +12:00
|
|
|
# Rare's internal arguments
|
|
|
|
# FIXME: Do we really need all of these?
|
|
|
|
create_shortcut: bool = True
|
|
|
|
overlay: bool = False
|
|
|
|
update: bool = False
|
|
|
|
silent: bool = False
|
2023-12-08 05:53:34 +13:00
|
|
|
install_prereqs: bool = False
|
2022-07-27 02:41:23 +12:00
|
|
|
|
|
|
|
def as_install_kwargs(self) -> Dict:
|
|
|
|
return {
|
|
|
|
k: getattr(self, k)
|
2023-12-06 21:04:25 +13:00
|
|
|
for k in vars(self)
|
2022-09-01 20:49:42 +12:00
|
|
|
if k not in ["update", "silent", "create_shortcut", "overlay", "install_prereqs"]
|
2022-07-27 02:41:23 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class InstallDownloadModel:
|
2022-08-09 06:06:58 +12:00
|
|
|
dlm: DLManager
|
2022-07-27 02:41:23 +12:00
|
|
|
analysis: AnalysisResult
|
|
|
|
igame: InstalledGame
|
|
|
|
game: Game
|
|
|
|
repair: bool
|
|
|
|
repair_file: str
|
|
|
|
res: ConditionCheckResult
|
|
|
|
|
|
|
|
|
|
|
|
class InstallQueueItemModel:
|
2023-01-28 09:05:39 +13:00
|
|
|
def __init__(self, options: InstallOptionsModel, download: InstallDownloadModel = None):
|
|
|
|
self.options: Optional[InstallOptionsModel] = options
|
|
|
|
# lk: internal attribute holders
|
|
|
|
self.__download: Optional[InstallDownloadModel] = None
|
|
|
|
self.__date: Optional[datetime] = None
|
|
|
|
|
|
|
|
self.download = download
|
|
|
|
|
|
|
|
@property
|
|
|
|
def download(self) -> Optional[InstallDownloadModel]:
|
|
|
|
return self.__download
|
|
|
|
|
|
|
|
@download.setter
|
|
|
|
def download(self, download: Optional[InstallDownloadModel]):
|
|
|
|
self.__download = download
|
|
|
|
if download is not None:
|
|
|
|
self.__date = datetime.now()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def expired(self) -> bool:
|
|
|
|
return datetime.now() > (self.__date + timedelta(minutes=30))
|
2022-07-27 02:41:23 +12:00
|
|
|
|
|
|
|
def __bool__(self):
|
2023-01-28 09:05:39 +13:00
|
|
|
return (self.download is not None) and (self.options is not None) and (not self.expired)
|
2023-01-25 23:59:00 +13:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class UninstallOptionsModel:
|
|
|
|
app_name: str
|
2023-01-28 09:05:39 +13:00
|
|
|
accepted: bool = None
|
2023-01-25 23:59:00 +13:00
|
|
|
keep_files: bool = None
|
|
|
|
keep_config: bool = None
|
2023-09-09 04:38:39 +12:00
|
|
|
keep_overlay_keys: bool = None
|
2023-01-25 23:59:00 +13:00
|
|
|
|
|
|
|
def __bool__(self):
|
|
|
|
return (
|
|
|
|
bool(self.app_name)
|
2023-01-28 09:05:39 +13:00
|
|
|
and (self.accepted is not None)
|
2023-01-25 23:59:00 +13:00
|
|
|
and (self.keep_files is not None)
|
|
|
|
and (self.keep_config is not None)
|
2023-09-09 04:38:39 +12:00
|
|
|
and (self.keep_overlay_keys is not None)
|
2023-01-25 23:59:00 +13:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
2023-09-09 04:38:39 +12:00
|
|
|
def values(self) -> Tuple[bool, bool, bool, bool]:
|
2023-01-26 03:43:06 +13:00
|
|
|
"""
|
|
|
|
This model's options
|
|
|
|
|
|
|
|
:return:
|
2024-01-03 10:11:47 +13:00
|
|
|
Tuple of `accepted` `keep_files` `keep_config` `keep_overlay_keys`
|
2023-01-26 03:43:06 +13:00
|
|
|
"""
|
2023-09-09 04:38:39 +12:00
|
|
|
return self.accepted, self.keep_config, self.keep_files, self.keep_overlay_keys
|
2023-01-25 23:59:00 +13:00
|
|
|
|
|
|
|
@values.setter
|
2023-09-09 04:38:39 +12:00
|
|
|
def values(self, values: Tuple[bool, bool, bool, bool]):
|
2023-01-26 03:43:06 +13:00
|
|
|
"""
|
|
|
|
Set this model's options
|
|
|
|
|
|
|
|
:param values:
|
2024-01-03 10:11:47 +13:00
|
|
|
Tuple of `accepted` `keep_files` `keep_config` `keep_overlay_keys`
|
2023-01-26 03:43:06 +13:00
|
|
|
:return:
|
|
|
|
"""
|
2023-01-28 09:05:39 +13:00
|
|
|
self.accepted = values[0]
|
2023-01-25 23:59:00 +13:00
|
|
|
self.keep_files = values[1]
|
2023-05-30 00:12:13 +12:00
|
|
|
self.keep_config = values[2]
|
2023-09-09 04:38:39 +12:00
|
|
|
self.keep_overlay_keys = values[3]
|
2023-12-20 07:53:21 +13:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class SelectiveDownloadsModel:
|
|
|
|
app_name: str
|
|
|
|
accepted: bool = None
|
|
|
|
install_tag: Optional[List[str]] = None
|
2023-12-26 11:05:11 +13:00
|
|
|
|
|
|
|
def __bool__(self):
|
|
|
|
return (
|
|
|
|
bool(self.app_name)
|
|
|
|
and (self.accepted is not None)
|
|
|
|
and (self.install_tag is not None)
|
|
|
|
)
|
|
|
|
|
2024-01-03 10:11:47 +13:00
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class MoveGameModel:
|
|
|
|
app_name: str
|
|
|
|
accepted: bool = None
|
|
|
|
target_path: Optional[str] = None
|
|
|
|
|
|
|
|
def __bool__(self):
|
|
|
|
return (
|
|
|
|
bool(self.app_name)
|
|
|
|
and (self.accepted is not None)
|
|
|
|
and (self.target_path is not None)
|
|
|
|
)
|