def get_env(self, os_env=True): """Return environment variables used by the game""" # Always false to runner.get_env, the default value # of os_env is inverted in the wine class, # the OS env is read later. env = super(wine, self).get_env(False) if os_env: env.update(os.environ.copy()) show_debug = self.runner_config.get("show_debug", "-all") if show_debug != "inherit": env["WINEDEBUG"] = show_debug env["WINEARCH"] = self.wine_arch env["WINE"] = self.get_executable() if self.prefix_path: env["WINEPREFIX"] = self.prefix_path if not ("WINEFSYNC" in env and env["WINEFSYNC"] == "1" and ("WINEESYNC" not in env or env["WINEESYNC"] == "0")): if self.runner_config.get("esync") == "fsync": env["WINEESYNC"] = "0" env["WINEFSYNC"] = "1" else: env["WINEFSYNC"] = "0" elif not ("WINEESYNC" in env and env["WINEESYNC"] == "1"): if self.runner_config.get("esync") == "esync": env["WINEESYNC"] = "1" env["WINEFSYNC"] = "0" else: env["WINEESYNC"] = "0" overrides = self.get_dll_overrides() if overrides: env["WINEDLLOVERRIDES"] = get_overrides_env(overrides) return env
def get_env(self, os_env=False): """Return environment variables used by the game""" # Always false to runner.get_env, the default value # of os_env is inverted in the wine class, # the OS env is read later. env = super(wine, self).get_env(False) if os_env: env.update(os.environ.copy()) show_debug = self.runner_config.get("show_debug", "-all") if show_debug != "inherit": env["WINEDEBUG"] = show_debug env["WINEARCH"] = self.wine_arch env["WINE"] = self.get_executable() if self.prefix_path: env["WINEPREFIX"] = self.prefix_path if "WINEESYNC" not in env or env["WINEESYNC"] != "1": env["WINEESYNC"] = "1" if self.runner_config.get("esync") else "0" if "WINEFSYNC" not in env or env["WINEFSYNC"] != "1": env["WINEFSYNC"] = "1" if self.runner_config.get("fsync") else "0" # On AMD, mimic the video memory management behavior of Windows DX12 # drivers more closely, otherwise d3d12 games will crash and have other # funky issues. if self.runner_config.get("dxvk") and drivers.is_amd(): env["RADV_DEBUG"] = "zerovram" overrides = self.get_dll_overrides() if overrides: self.dll_overrides.update(overrides) env["WINEDLLOVERRIDES"] = get_overrides_env(self.dll_overrides) return env
def get_env(self, os_env=False): """Return environment variables used by the game""" # Always false to runner.get_env, the default value # of os_env is inverted in the wine class, # the OS env is read later. env = super().get_env(False) if os_env: env.update(os.environ.copy()) show_debug = self.runner_config.get("show_debug", "-all") if show_debug != "inherit": env["WINEDEBUG"] = show_debug if show_debug == "-all": env["DXVK_LOG_LEVEL"] = "none" env["WINEARCH"] = self.wine_arch env["WINE"] = self.get_executable() env["WINE_MONO_CACHE_DIR"] = os.path.join(WINE_DIR, self.get_version(), "mono") env["WINE_GECKO_CACHE_DIR"] = os.path.join(WINE_DIR, self.get_version(), "gecko") if is_gstreamer_build(self.get_executable()): path_64 = os.path.join(WINE_DIR, self.get_version(), "lib64/gstreamer-1.0/") path_32 = os.path.join(WINE_DIR, self.get_version(), "lib/gstreamer-1.0/") if os.path.exists(path_64) or os.path.exists(path_32): env["GST_PLUGIN_SYSTEM_PATH_1_0"] = path_64 + ":" + path_32 if self.prefix_path: env["WINEPREFIX"] = self.prefix_path if not ("WINEESYNC" in env and env["WINEESYNC"] == "1"): env["WINEESYNC"] = "1" if self.runner_config.get("esync") else "0" if not ("WINEFSYNC" in env and env["WINEFSYNC"] == "1"): env["WINEFSYNC"] = "1" if self.runner_config.get("fsync") else "0" if self.runner_config.get("fsr"): env["WINE_FULLSCREEN_FSR"] = "1" if self.runner_config.get("dxvk_nvapi"): env["DXVK_NVAPIHACK"] = "0" if self.runner_config.get("battleye"): env["PROTON_BATTLEYE_RUNTIME"] = os.path.join( settings.RUNTIME_DIR, "battleye_runtime") overrides = self.get_dll_overrides() if overrides: self.dll_overrides.update(overrides) env["WINEDLLOVERRIDES"] = get_overrides_env(self.dll_overrides) return env
def get_env(self, os_env=False): """Return environment variables used by the game""" # Always false to runner.get_env, the default value # of os_env is inverted in the wine class, # the OS env is read later. env = super(wine, self).get_env(False) if os_env: env.update(os.environ.copy()) show_debug = self.runner_config.get("show_debug", "-all") if show_debug != "inherit": env["WINEDEBUG"] = show_debug env["WINEARCH"] = self.wine_arch env["WINE"] = self.get_executable() if is_gstreamer_build(self.get_executable()): path_64 = os.path.join(WINE_DIR, self.get_version(), "lib64/gstreamer-1.0/") path_32 = os.path.join(WINE_DIR, self.get_version(), "lib/gstreamer-1.0/") if os.path.exists(path_64) or os.path.exists(path_32): env["GST_PLUGIN_SYSTEM_PATH_1_0"] = path_64 + ":" + path_32 if self.prefix_path: env["WINEPREFIX"] = self.prefix_path if not ("WINEESYNC" in env and env["WINEESYNC"] == "1"): env["WINEESYNC"] = "1" if self.runner_config.get("esync") else "0" if not ("WINEFSYNC" in env and env["WINEFSYNC"] == "1"): env["WINEFSYNC"] = "1" if self.runner_config.get("fsync") else "0" # On AMD, mimic the video memory management behavior of Windows DX12 # drivers more closely, otherwise d3d12 games will crash and have other # funky issues. # RADV_DEBUG is a comma separated list. If it is already set, we want to # append to it. if self.runner_config.get("dxvk") and drivers.is_amd(): if "RADV_DEBUG" not in env or not env["RADV_DEBUG"]: env["RADV_DEBUG"] = "zerovram" elif "zerovram" not in env["RADV_DEBUG"]: env["RADV_DEBUG"] += ",zerovram" overrides = self.get_dll_overrides() if overrides: self.dll_overrides.update(overrides) env["WINEDLLOVERRIDES"] = get_overrides_env(self.dll_overrides) return env
def get_env(self, os_env=True): """Return environment variables used by the game""" # Always false to runner.get_env, the default value # of os_env is inverted in the wine class, # the OS env is read later. env = super(wine, self).get_env(False) if os_env: env.update(os.environ.copy()) show_debug = self.runner_config.get("show_debug", "-all") if show_debug != "inherit": env["WINEDEBUG"] = show_debug env["WINEARCH"] = self.wine_arch env["WINE"] = self.get_executable() if self.prefix_path: env["WINEPREFIX"] = self.prefix_path if not ("WINEESYNC" in env and env["WINEESYNC"] == "1"): env["WINEESYNC"] = "1" if self.runner_config.get("esync") else "0" overrides = self.get_dll_overrides() if overrides: env["WINEDLLOVERRIDES"] = get_overrides_env(overrides) return env
def create_prefix( prefix, wine_path=None, arch=WINE_DEFAULT_ARCH, overrides={}, install_gecko=None, install_mono=None, ): """Create a new Wine prefix.""" if not prefix: raise ValueError("No Wine prefix path given") logger.info("Creating a %s prefix in %s", arch, prefix) # Follow symlinks, don't delete existing ones as it would break some setups if os.path.islink(prefix): prefix = os.readlink(prefix) # Avoid issue of 64bit Wine refusing to create win32 prefix # over an existing empty folder. if os.path.isdir(prefix) and not os.listdir(prefix): os.rmdir(prefix) if not wine_path: wine = import_runner("wine") wine_path = wine().get_executable() if not wine_path: logger.error("Wine not found, can't create prefix") return wineboot_path = os.path.join(os.path.dirname(wine_path), "wineboot") if not system.path_exists(wineboot_path): logger.error( "No wineboot executable found in %s, " "your wine installation is most likely broken", wine_path, ) return if install_gecko == "False": overrides["mshtml"] = "disabled" if install_mono == "False": overrides["mscoree"] = "disabled" wineenv = { "WINEARCH": arch, "WINEPREFIX": prefix, "WINEDLLOVERRIDES": get_overrides_env(overrides), } system.execute([wineboot_path], env=wineenv) for loop_index in range(50): time.sleep(0.25) if system.path_exists(os.path.join(prefix, "user.reg")): break if loop_index == 20: logger.warning( "Wine prefix creation is taking longer than expected...") if not os.path.exists(os.path.join(prefix, "user.reg")): logger.error("No user.reg found after prefix creation. " "Prefix might not be valid") return logger.info("%s Prefix created in %s", arch, prefix) prefix_manager = WinePrefixManager(prefix) prefix_manager.setup_defaults() if 'steamapps/common' in prefix.lower(): from lutris.runners.winesteam import winesteam runner = winesteam() logger.info( "Transfering Steam information from default prefix to new prefix") dest_path = '/tmp/steam.reg' default_prefix = runner.get_default_prefix(runner.default_arch) wineexec("regedit", args=r"/E '%s' 'HKEY_CURRENT_USER\Software\Valve\Steam'" % dest_path, prefix=default_prefix) set_regedit_file(dest_path, wine_path=wine_path, prefix=prefix, arch=arch) try: os.remove(dest_path) except FileNotFoundError: logger.error("File %s was already removed", dest_path) steam_drive_path = os.path.join(prefix, 'dosdevices', 's:') if not system.path_exists(steam_drive_path): logger.info("Linking Steam default prefix to drive S:") os.symlink(os.path.join(default_prefix, 'drive_c'), steam_drive_path)
def wineexec( executable, args="", wine_path=None, prefix=None, arch=None, # pylint: disable=too-many-locals working_dir=None, winetricks_wine="", blocking=False, config=None, include_processes=[], exclude_processes=[], disable_runtime=False, env={}, overrides=None, ): """ Execute a Wine command. Args: executable (str): wine program to run, pass None to run wine itself args (str): program arguments wine_path (str): path to the wine version to use prefix (str): path to the wine prefix to use arch (str): wine architecture of the prefix working_dir (str): path to the working dir for the process winetricks_wine (str): path to the wine version used by winetricks blocking (bool): if true, do not run the process in a thread config (LutrisConfig): LutrisConfig object for the process context watch (list): list of process names to monitor (even when in a ignore list) Returns: Process results if the process is running in blocking mode or MonitoredCommand instance otherwise. """ executable = str(executable) if executable else "" if isinstance(include_processes, str): include_processes = shlex.split(include_processes) if isinstance(exclude_processes, str): exclude_processes = shlex.split(exclude_processes) if not wine_path: wine = import_runner("wine") wine_path = wine().get_executable() if not wine_path: raise RuntimeError("Wine is not installed") if not working_dir: if os.path.isfile(executable): working_dir = os.path.dirname(executable) executable, _args, working_dir = get_real_executable( executable, working_dir) if _args: args = '{} "{}"'.format(_args[0], _args[1]) # Create prefix if necessary if arch not in ("win32", "win64"): arch = detect_arch(prefix, wine_path) if not detect_prefix_arch(prefix): wine_bin = winetricks_wine if winetricks_wine else wine_path create_prefix(prefix, wine_path=wine_bin, arch=arch) wineenv = {"WINEARCH": arch} if winetricks_wine: wineenv["WINE"] = winetricks_wine else: wineenv["WINE"] = wine_path if prefix: wineenv["WINEPREFIX"] = prefix wine_config = config or LutrisConfig(runner_slug="wine") disable_runtime = disable_runtime or wine_config.system_config[ "disable_runtime"] if use_lutris_runtime(wine_path=wineenv["WINE"], force_disable=disable_runtime): if WINE_DIR in wine_path: wine_root_path = os.path.dirname(os.path.dirname(wine_path)) elif WINE_DIR in winetricks_wine: wine_root_path = os.path.dirname(os.path.dirname(winetricks_wine)) else: wine_root_path = None wineenv["LD_LIBRARY_PATH"] = ":".join( runtime.get_paths( prefer_system_libs=wine_config. system_config["prefer_system_libs"], wine_path=wine_root_path, )) if overrides: wineenv["WINEDLLOVERRIDES"] = get_overrides_env(overrides) wineenv.update(env) command_parameters = [wine_path] if executable: command_parameters.append(executable) command_parameters += shlex.split(args) if blocking: return system.execute(command_parameters, env=wineenv, cwd=working_dir) wine = import_runner("wine") command = MonitoredCommand( command_parameters, runner=wine(), env=wineenv, cwd=working_dir, include_processes=include_processes, exclude_processes=exclude_processes, ) command.start() return command
def create_prefix( # noqa: C901 prefix, wine_path=None, arch=WINE_DEFAULT_ARCH, overrides=None, install_gecko=None, install_mono=None, ): """Create a new Wine prefix.""" # pylint: disable=too-many-locals if overrides is None: overrides = {} if not prefix: raise ValueError("No Wine prefix path given") logger.info("Creating a %s prefix in %s", arch, prefix) # Follow symlinks, don't delete existing ones as it would break some setups if os.path.islink(prefix): prefix = os.readlink(prefix) # Avoid issue of 64bit Wine refusing to create win32 prefix # over an existing empty folder. if os.path.isdir(prefix) and not os.listdir(prefix): os.rmdir(prefix) if not wine_path: wine = import_runner("wine") wine_path = wine().get_executable() if not wine_path: logger.error("Wine not found, can't create prefix") return wineboot_path = os.path.join(os.path.dirname(wine_path), "wineboot") if not system.path_exists(wineboot_path): logger.error( "No wineboot executable found in %s, " "your wine installation is most likely broken", wine_path, ) return if install_gecko == "False": overrides["mshtml"] = "disabled" if install_mono == "False": overrides["mscoree"] = "disabled" wineenv = { "WINEARCH": arch, "WINEPREFIX": prefix, "WINEDLLOVERRIDES": get_overrides_env(overrides), } system.execute([wineboot_path], env=wineenv) for loop_index in range(60): time.sleep(0.5) if system.path_exists(os.path.join(prefix, "user.reg")): break if loop_index == 30: logger.warning( "Wine prefix creation is taking longer than expected...") if not os.path.exists(os.path.join(prefix, "user.reg")): logger.error("No user.reg found after prefix creation. " "Prefix might not be valid") return logger.info("%s Prefix created in %s", arch, prefix) prefix_manager = WinePrefixManager(prefix) prefix_manager.setup_defaults()
def create_prefix( prefix, wine_path=None, arch=WINE_DEFAULT_ARCH, overrides={}, install_gecko=None, install_mono=None, ): """Create a new Wine prefix.""" if not prefix: raise ValueError("No Wine prefix path given") logger.info("Creating a %s prefix in %s", arch, prefix) # Follow symlinks, don't delete existing ones as it would break some setups if os.path.islink(prefix): prefix = os.readlink(prefix) # Avoid issue of 64bit Wine refusing to create win32 prefix # over an existing empty folder. if os.path.isdir(prefix) and not os.listdir(prefix): os.rmdir(prefix) if not wine_path: wine = import_runner("wine") wine_path = wine().get_executable() if not wine_path: logger.error("Wine not found, can't create prefix") return wineboot_path = os.path.join(os.path.dirname(wine_path), "wineboot") if not system.path_exists(wineboot_path): logger.error( "No wineboot executable found in %s, " "your wine installation is most likely broken", wine_path, ) return if install_gecko == "False": overrides["mshtml"] = "disabled" if install_mono == "False": overrides["mscoree"] = "disabled" wineenv = { "WINEARCH": arch, "WINEPREFIX": prefix, "WINEDLLOVERRIDES": get_overrides_env(overrides), } system.execute([wineboot_path], env=wineenv) for loop_index in range(50): time.sleep(0.25) if system.path_exists(os.path.join(prefix, "user.reg")): break if loop_index == 20: logger.warning("Wine prefix creation is taking longer than expected...") if not os.path.exists(os.path.join(prefix, "user.reg")): logger.error( "No user.reg found after prefix creation. " "Prefix might not be valid" ) return logger.info("%s Prefix created in %s", arch, prefix) prefix_manager = WinePrefixManager(prefix) prefix_manager.setup_defaults() if 'steamapps/common' in prefix.lower(): from lutris.runners.winesteam import winesteam runner = winesteam() logger.info("Transfering Steam information from default prefix to new prefix") dest_path = '/tmp/steam.reg' default_prefix = runner.get_default_prefix(runner.default_arch) wineexec( "regedit", args=r"/E '%s' 'HKEY_CURRENT_USER\Software\Valve\Steam'" % dest_path, prefix=default_prefix ) set_regedit_file( dest_path, wine_path=wine_path, prefix=prefix, arch=arch ) try: os.remove(dest_path) except FileNotFoundError: logger.error("File %s was already removed", dest_path) steam_drive_path = os.path.join(prefix, 'dosdevices', 's:') if not system.path_exists(steam_drive_path): logger.info("Linking Steam default prefix to drive S:") os.symlink(os.path.join(default_prefix, 'drive_c'), steam_drive_path)
def wineexec( executable, args="", wine_path=None, prefix=None, arch=None, # pylint: disable=too-many-locals working_dir=None, winetricks_wine="", blocking=False, config=None, include_processes=[], exclude_processes=[], disable_runtime=False, env={}, overrides=None, ): """ Execute a Wine command. Args: executable (str): wine program to run, pass None to run wine itself args (str): program arguments wine_path (str): path to the wine version to use prefix (str): path to the wine prefix to use arch (str): wine architecture of the prefix working_dir (str): path to the working dir for the process winetricks_wine (str): path to the wine version used by winetricks blocking (bool): if true, do not run the process in a thread config (LutrisConfig): LutrisConfig object for the process context watch (list): list of process names to monitor (even when in a ignore list) Returns: Process results if the process is running in blocking mode or MonitoredCommand instance otherwise. """ executable = str(executable) if executable else "" if isinstance(include_processes, str): include_processes = shlex.split(include_processes) if isinstance(exclude_processes, str): exclude_processes = shlex.split(exclude_processes) if not wine_path: wine = import_runner("wine") wine_path = wine().get_executable() if not wine_path: raise RuntimeError("Wine is not installed") if not working_dir: if os.path.isfile(executable): working_dir = os.path.dirname(executable) executable, _args, working_dir = get_real_executable(executable, working_dir) if _args: args = '{} "{}"'.format(_args[0], _args[1]) # Create prefix if necessary if arch not in ("win32", "win64"): arch = detect_arch(prefix, wine_path) if not detect_prefix_arch(prefix): wine_bin = winetricks_wine if winetricks_wine else wine_path create_prefix(prefix, wine_path=wine_bin, arch=arch) wineenv = {"WINEARCH": arch} if winetricks_wine: wineenv["WINE"] = winetricks_wine else: wineenv["WINE"] = wine_path if prefix: wineenv["WINEPREFIX"] = prefix wine_config = config or LutrisConfig(runner_slug="wine") disable_runtime = disable_runtime or wine_config.system_config["disable_runtime"] if use_lutris_runtime(wine_path=wineenv["WINE"], force_disable=disable_runtime): if WINE_DIR in wine_path: wine_root_path = os.path.dirname(os.path.dirname(wine_path)) elif WINE_DIR in winetricks_wine: wine_root_path = os.path.dirname(os.path.dirname(winetricks_wine)) else: wine_root_path = None wineenv["LD_LIBRARY_PATH"] = ":".join( runtime.get_paths( prefer_system_libs=wine_config.system_config["prefer_system_libs"], wine_path=wine_root_path, ) ) if overrides: wineenv["WINEDLLOVERRIDES"] = get_overrides_env(overrides) wineenv.update(env) command_parameters = [wine_path] if executable: command_parameters.append(executable) command_parameters += shlex.split(args) if blocking: return system.execute(command_parameters, env=wineenv, cwd=working_dir) wine = import_runner("wine") command = MonitoredCommand( command_parameters, runner=wine(), env=wineenv, cwd=working_dir, include_processes=include_processes, exclude_processes=exclude_processes, ) command.start() return command