1
0
Fork 0
mirror of synced 2024-06-02 10:44:40 +12:00
Rare/rare/models/pathspec.py
loathingKernel af6d7c5055 Various WIP
* Use `vars()` instead of directly accessing `__dict__`
* Remove `auto_update` from RareGame's metadata
* Correct check for updating the Steam App ID (We want to keep any changes from the user)
* Collect both Wine and Proton prefixes when removing overlay registry keys.
* Add few convenience functions in config_helper and paths.
2024-02-12 21:52:07 +02:00

74 lines
2.3 KiB
Python

import os
from typing import Union, List
from legendary.core import LegendaryCore
from legendary.models.game import InstalledGame
from rare.utils.config_helper import get_prefixes
class PathSpec:
@staticmethod
def egl_appdata() -> str:
return r"%LOCALAPPDATA%\EpicGamesLauncher\Saved\Config\Windows"
@staticmethod
def egl_programdata() -> str:
return r"%PROGRAMDATA%\Epic\EpicGamesLauncher\Data\Manifests"
@staticmethod
def wine_programdata() -> str:
return r"ProgramData"
@staticmethod
def wine_egl_programdata() -> str:
return PathSpec.egl_programdata(
).replace(
"\\", "/"
).replace(
"%PROGRAMDATA%", PathSpec.wine_programdata()
)
@staticmethod
def prefix_egl_programdata(prefix: str) -> str:
return os.path.join(prefix, "dosdevices/c:", PathSpec.wine_egl_programdata())
@staticmethod
def wine_egl_prefixes(results: int = 0) -> Union[List[str], str]:
possible_prefixes = get_prefixes()
prefixes = []
for prefix in possible_prefixes:
if os.path.exists(os.path.join(prefix, PathSpec.wine_egl_programdata())):
prefixes.append(prefix)
if not prefixes:
return ""
if not results:
return prefixes
elif results == 1:
return prefixes[0]
else:
return prefixes[:results]
def __init__(self, core: LegendaryCore = None, igame: InstalledGame = None):
self.__egl_path_vars = {
"{appdata}": os.path.expandvars("%LOCALAPPDATA%"),
"{userdir}": os.path.expandvars("%USERPROFILE%/Documents"),
"{userprofile}": os.path.expandvars("%userprofile%"), # possibly wrong
"{usersavedgames}": os.path.expandvars("%USERPROFILE%/Saved Games"),
}
if core is not None:
self.__egl_path_vars.update({
"{epicid}": core.lgd.userdata["account_id"]
})
if igame is not None:
self.__egl_path_vars.update({
"{installdir}": igame.install_path,
})
def resolve_egl_path_vars(self, path: str) -> str:
cooked_path = [self.__egl_path_vars.get(p.lower(), p) for p in path.split("/")]
return os.path.join(*cooked_path)