1
0
Fork 0
mirror of synced 2024-06-26 18:20:50 +12:00

Wine,WineResolver: Add more logging

This commit is contained in:
loathingKernel 2023-09-03 14:47:44 +03:00
parent 9a941e3001
commit ba65ffa905
No known key found for this signature in database
GPG key ID: CE0C72D0B53821FD
2 changed files with 39 additions and 19 deletions

View file

@ -98,17 +98,23 @@ class OriginWineWorker(QRunnable):
# lk: this is the alternative way of getting the path by using wine itself # lk: this is the alternative way of getting the path by using wine itself
install_dir = wine.query_reg_key(wine_exec, wine_env, f"HKLM\\{reg_path}", reg_key) install_dir = wine.query_reg_key(wine_exec, wine_env, f"HKLM\\{reg_path}", reg_key)
logger.debug("Found Wine install directory %s", install_dir)
if install_dir: if install_dir:
logger.debug("Found Wine install directory %s", install_dir)
install_dir = wine.convert_to_unix_path(wine_exec, wine_env, install_dir) install_dir = wine.convert_to_unix_path(wine_exec, wine_env, install_dir)
logger.debug("Found Unix install directory %s", install_dir) if install_dir:
logger.debug("Found Unix install directory %s", install_dir)
else:
logger.info("Could not find Unix install directory for %s", rgame.title)
else:
logger.info("Could not find Wine install directory for %s", rgame.title)
if install_dir: if install_dir:
if os.path.isdir(install_dir): if os.path.isdir(install_dir):
install_size = path_size(install_dir) install_size = path_size(install_dir)
rgame.set_origin_attributes(install_dir, install_size) rgame.set_origin_attributes(install_dir, install_size)
logger.debug(f"Origin game {rgame.title} ({install_dir}, {format_size(install_size)})") logger.info("Origin game %s (%s, %s)", rgame.title, install_dir, format_size(install_size))
else: else:
logger.warning(f"Origin game {rgame.title} ({install_dir} does not exist)") logger.warning("Origin game %s (%s does not exist)", rgame.title, install_dir)
logger.info(f"Origin worker finished in {time.time() - t}s") else:
logger.info("Origin game %s is not installed", rgame.title)
logger.info("Origin worker finished in %ss", time.time() - t)

View file

@ -28,17 +28,20 @@ def execute(cmd: List, wine_env: Mapping) -> Tuple[str, str]:
for name, value in wine_env.items(): for name, value in wine_env.items():
flatpak_cmd.append(f"--env={name}={value}") flatpak_cmd.append(f"--env={name}={value}")
cmd = flatpak_cmd + cmd cmd = flatpak_cmd + cmd
proc = subprocess.Popen( try:
cmd, proc = subprocess.Popen(
stdout=subprocess.PIPE, cmd,
stderr=subprocess.PIPE, stdout=subprocess.PIPE,
# Use the current environment if we are in flatpak or our own if we are on host stderr=subprocess.PIPE,
# In flatpak our environment is passed through `flatpak-spawn` arguments # Use the current environment if we are in flatpak or our own if we are on host
env=os.environ.copy() if os.environ.get("container") == "flatpak" else wine_env, # In flatpak our environment is passed through `flatpak-spawn` arguments
shell=False, env=os.environ.copy() if os.environ.get("container") == "flatpak" else wine_env,
text=True, shell=False,
) text=True,
res = proc.communicate() )
res = proc.communicate()
except (FileNotFoundError, PermissionError) as e:
res = ("", str(e))
return res return res
@ -49,7 +52,11 @@ def resolve_path(wine_exec: str, wine_env: Mapping, path: str) -> str:
# lk: if path exists and needs a case-sensitive interpretation form # lk: if path exists and needs a case-sensitive interpretation form
# cmd = [wine_cmd, 'cmd', '/c', f'cd {path} & cd'] # cmd = [wine_cmd, 'cmd', '/c', f'cd {path} & cd']
out, err = execute(cmd, wine_env) out, err = execute(cmd, wine_env)
return out.strip().strip('"') out, err = out.strip(), err.strip()
if not out:
logger.error("Failed to resolve wine path due to \"%s\"", err)
return out
return out.strip('"')
def query_reg_path(wine_exec: str, wine_env: Mapping, reg_path: str): def query_reg_path(wine_exec: str, wine_env: Mapping, reg_path: str):
@ -59,6 +66,10 @@ def query_reg_path(wine_exec: str, wine_env: Mapping, reg_path: str):
def query_reg_key(wine_exec: str, wine_env: Mapping, reg_path: str, reg_key) -> str: def query_reg_key(wine_exec: str, wine_env: Mapping, reg_path: str, reg_key) -> str:
cmd = [wine_exec, "reg", "query", reg_path, "/v", reg_key] cmd = [wine_exec, "reg", "query", reg_path, "/v", reg_key]
out, err = execute(cmd, wine_env) out, err = execute(cmd, wine_env)
out, err = out.strip(), err.strip()
if not out:
logger.error("Failed to query registry key due to \"%s\"", err)
return out
lines = out.split("\n") lines = out.split("\n")
keys: Dict = {} keys: Dict = {}
for line in lines: for line in lines:
@ -76,7 +87,10 @@ def convert_to_unix_path(wine_exec: str, wine_env: Mapping, path: str) -> str:
path = path.strip().strip('"') path = path.strip().strip('"')
cmd = [wine_exec, "winepath.exe", "-u", path] cmd = [wine_exec, "winepath.exe", "-u", path]
out, err = execute(cmd, wine_env) out, err = execute(cmd, wine_env)
return os.path.realpath(out.strip()) out, err = out.strip(), err.strip()
if not out:
logger.error("Failed to convert to unix path due to \"%s\"", err)
return os.path.realpath(out) if (out := out.strip()) else out
def wine(core: LegendaryCore, app_name: str = "default") -> str: def wine(core: LegendaryCore, app_name: str = "default") -> str: