1
0
Fork 0
mirror of synced 2024-06-26 10:11:19 +12:00
Rare/rare/components/tabs/games/game_info/game_settings.py

250 lines
12 KiB
Python
Raw Normal View History

2021-03-10 09:57:54 +13:00
import os
import platform
2021-10-11 21:41:01 +13:00
from typing import Tuple
2021-03-10 09:57:54 +13:00
2021-04-10 21:27:40 +12:00
from PyQt5.QtCore import QSettings
from PyQt5.QtWidgets import QWidget, QFileDialog
2021-03-10 09:57:54 +13:00
from legendary.core import LegendaryCore
from legendary.models.game import InstalledGame, Game
2021-04-08 08:42:30 +12:00
from rare.components.tabs.settings.linux import LinuxSettings
from rare.ui.components.tabs.games.game_info.game_settings import Ui_GameSettings
2021-04-08 08:39:23 +12:00
from rare.utils.extra_widgets import PathEdit
2021-03-10 09:57:54 +13:00
def find_proton_wrappers():
possible_proton_wrappers = []
2021-05-02 02:15:43 +12:00
compatibilitytools_dirs = [
os.path.expanduser("~/.steam/steam/steamapps/common"),
"/usr/share/steam/compatibilitytools.d",
2021-06-25 09:38:08 +12:00
os.path.expanduser("~/.steam/compatibilitytools.d"),
os.path.expanduser("~/.steam/root/compatibilitytools.d")
2021-05-02 02:15:43 +12:00
]
for c in compatibilitytools_dirs:
if os.path.exists(c):
for i in os.listdir(c):
proton = os.path.join(c, i, "proton")
compatibilitytool = os.path.join(c, i, "compatibilitytool.vdf")
toolmanifest = os.path.join(c, i, "toolmanifest.vdf")
if os.path.exists(proton) and (os.path.exists(compatibilitytool) or os.path.exists(toolmanifest)):
wrapper = '"' + proton + '" run'
possible_proton_wrappers.append(wrapper)
2021-05-02 02:15:43 +12:00
if not possible_proton_wrappers:
print("Unable to find any Proton version")
return possible_proton_wrappers
class GameSettings(QWidget, Ui_GameSettings):
2021-03-10 09:57:54 +13:00
game: Game
igame: InstalledGame
2021-04-10 21:27:40 +12:00
# variable to no update when changing game
2021-03-11 23:59:12 +13:00
change = False
def __init__(self, core: LegendaryCore, parent):
super(GameSettings, self).__init__(parent=parent)
self.setupUi(self)
2021-03-10 09:57:54 +13:00
self.core = core
2021-04-10 21:27:40 +12:00
self.settings = QSettings()
self.offline.currentIndexChanged.connect(
lambda x: self.update_combobox(x, "offline")
)
self.skip_update.currentIndexChanged.connect(
lambda x: self.update_combobox(x, "skip_update_check")
)
self.cloud_sync.stateChanged.connect(
lambda: self.settings.setValue(f"{self.game.app_name}/auto_sync_cloud", self.cloud_sync.isChecked())
)
self.launch_params.textChanged.connect(lambda: self.launch_params_button.setEnabled(True))
self.launch_params_button.clicked.connect(
lambda: self.save_line_edit("start_params", self.launch_params.text())
)
self.launch_params_button.setEnabled(False)
self.wrapper.textChanged.connect(lambda: self.wrapper_button.setEnabled(True))
self.wrapper_button.clicked.connect(
lambda: self.save_line_edit("wrapper", self.wrapper.text())
)
self.wrapper_button.setEnabled(False)
2021-03-27 06:04:29 +13:00
if platform.system() != "Windows":
self.possible_proton_wrappers = find_proton_wrappers()
2021-03-27 06:04:29 +13:00
self.proton_wrapper.addItems(self.possible_proton_wrappers)
self.proton_wrapper.currentIndexChanged.connect(self.change_proton)
self.proton_prefix = PathEdit(
file_type=QFileDialog.DirectoryOnly,
edit_func=self.proton_prefix_edit,
save_func=self.proton_prefix_save
)
self.proton_prefix_layout.addWidget(self.proton_prefix)
2021-10-08 07:19:24 +13:00
self.linux_settings = LinuxAppSettings()
self.linux_layout.addWidget(self.linux_settings)
2021-05-22 02:22:30 +12:00
else:
self.proton_groupbox.setVisible(False)
2021-03-10 09:57:54 +13:00
# startparams, skip_update_check
2021-03-10 09:57:54 +13:00
2021-04-10 22:34:45 +12:00
def save_line_edit(self, option, value):
if value:
if self.game.app_name not in self.core.lgd.config.sections():
2021-04-10 22:34:45 +12:00
self.core.lgd.config.add_section(self.game.app_name)
self.core.lgd.config.set(self.game.app_name, option, value)
2021-03-27 06:04:29 +13:00
else:
2021-06-16 09:50:51 +12:00
if self.core.lgd.config.has_section(self.game.app_name) and self.core.lgd.config.get(
f"{self.game.app_name}", option, fallback=None) is not None:
2021-04-10 22:34:45 +12:00
self.core.lgd.config.remove_option(self.game.app_name, option)
2021-06-16 09:50:51 +12:00
if not self.core.lgd.config[self.game.app_name]:
self.core.lgd.config.remove_section(self.game.app_name)
2021-03-27 06:04:29 +13:00
self.core.lgd.save_config()
self.sender().setEnabled(False)
2021-03-27 06:04:29 +13:00
2021-04-08 21:09:17 +12:00
def update_combobox(self, i, option):
if self.change:
# remove section
if i:
if self.game.app_name not in self.core.lgd.config.sections():
self.core.lgd.config.add_section(self.game.app_name)
if i == 1:
self.core.lgd.config.set(self.game.app_name, option, "true")
if i == 2:
self.core.lgd.config.set(self.game.app_name, option, "false")
else:
if self.game.app_name in self.core.lgd.config.sections():
2021-05-08 20:07:00 +12:00
if self.core.lgd.config.get(f"{self.game.app_name}", option, fallback=False):
2021-04-08 21:09:17 +12:00
self.core.lgd.config.remove_option(self.game.app_name, option)
if not self.core.lgd.config[self.game.app_name]:
self.core.lgd.config.remove_section(self.game.app_name)
self.core.lgd.save_config()
2021-03-10 09:57:54 +13:00
def change_proton(self, i):
2021-03-11 23:59:12 +13:00
if self.change:
# Dont use Proton
2021-03-10 09:57:54 +13:00
if i == 0:
if f"{self.game.app_name}" in self.core.lgd.config.sections():
2021-05-08 20:07:00 +12:00
if self.core.lgd.config.get(f"{self.game.app_name}", "wrapper", fallback=False):
2021-03-10 09:57:54 +13:00
self.core.lgd.config.remove_option(self.game.app_name, "wrapper")
2021-05-08 20:07:00 +12:00
if self.core.lgd.config.get(f"{self.game.app_name}", "no_wine", fallback=False):
2021-03-10 09:57:54 +13:00
self.core.lgd.config.remove_option(self.game.app_name, "no_wine")
2021-05-08 20:07:00 +12:00
if not self.core.lgd.config[self.game.app_name]:
2021-03-10 09:57:54 +13:00
self.core.lgd.config.remove_section(self.game.app_name)
if f"{self.game.app_name}.env" in self.core.lgd.config.sections():
2021-05-08 20:07:00 +12:00
if self.core.lgd.config.get(f"{self.game.app_name}.env", "STEAM_COMPAT_DATA_PATH", fallback=False):
2021-03-10 09:57:54 +13:00
self.core.lgd.config.remove_option(f"{self.game.app_name}.env", "STEAM_COMPAT_DATA_PATH")
2021-05-08 20:07:00 +12:00
if not self.core.lgd.config[self.game.app_name + ".env"]:
2021-03-10 09:57:54 +13:00
self.core.lgd.config.remove_section(self.game.app_name + ".env")
self.proton_prefix.setEnabled(False)
# lk: TODO: This has to be fixed properly.
# lk: It happens because of the widget update. Mask it for now behind disabling the save button
self.wrapper.setText(self.core.lgd.config.get(f"{self.game.app_name}", "wrapper", fallback=""))
self.wrapper_button.setDisabled(True)
self.wrapper_widget.setEnabled(True)
self.linux_settings.wine_groupbox.setEnabled(True)
2021-03-10 09:57:54 +13:00
else:
self.proton_prefix.setEnabled(True)
self.wrapper_widget.setEnabled(False)
self.linux_settings.wine_groupbox.setEnabled(False)
2021-03-11 23:59:12 +13:00
wrapper = self.possible_proton_wrappers[i - 1]
2021-05-08 20:07:00 +12:00
if self.game.app_name not in self.core.lgd.config.sections():
2021-03-10 09:57:54 +13:00
self.core.lgd.config[self.game.app_name] = {}
2021-05-08 20:07:00 +12:00
if self.game.app_name + ".env" not in self.core.lgd.config.sections():
2021-03-10 09:57:54 +13:00
self.core.lgd.config[self.game.app_name + ".env"] = {}
self.core.lgd.config.set(self.game.app_name, "wrapper", wrapper)
self.core.lgd.config.set(self.game.app_name, "no_wine", "true")
2021-03-11 23:59:12 +13:00
self.core.lgd.config.set(self.game.app_name + ".env", "STEAM_COMPAT_DATA_PATH",
os.path.expanduser("~/.proton"))
self.proton_prefix.setText(os.path.expanduser("~/.proton"))
2021-03-11 23:59:12 +13:00
# Dont use Wine
self.linux_settings.wine_exec.setText("")
2021-10-11 21:41:01 +13:00
self.linux_settings.save_setting(self.linux_settings.wine_exec.text(), "wine_exec")
self.linux_settings.wine_prefix.setText("")
2021-10-11 21:41:01 +13:00
self.linux_settings.save_setting(self.linux_settings.wine_prefix.text(), "wine_prefix")
2021-03-11 23:59:12 +13:00
self.core.lgd.save_config()
2021-03-10 09:57:54 +13:00
2021-10-11 21:41:01 +13:00
def proton_prefix_edit(self, text: str) -> Tuple[bool, str]:
2021-05-08 20:07:00 +12:00
if not text:
2021-03-10 09:57:54 +13:00
text = os.path.expanduser("~/.proton")
2021-10-11 21:41:01 +13:00
return True, text
parent = os.path.dirname(text)
return os.path.exists(parent), text
2021-03-10 09:57:54 +13:00
2021-10-11 21:41:01 +13:00
def proton_prefix_save(self, text: str):
2021-03-11 23:59:12 +13:00
self.core.lgd.config.set(self.game.app_name + ".env", "STEAM_COMPAT_DATA_PATH", text)
2021-03-10 09:57:54 +13:00
self.core.lgd.save_config()
def update_game(self, game: Game):
2021-03-11 23:59:12 +13:00
self.change = False
self.game = game
self.igame = self.core.get_installed_game(game.app_name)
app_name = game.app_name
if self.igame:
if self.igame.can_run_offline:
offline = self.core.lgd.config.get(self.game.app_name, "offline", fallback="unset")
if offline == "true":
self.offline.setCurrentIndex(1)
elif offline == "false":
self.offline.setCurrentIndex(2)
else:
self.offline.setCurrentIndex(0)
self.offline.setEnabled(True)
else:
self.offline.setEnabled(False)
else:
self.offline.setEnabled(False)
skip_update = self.core.lgd.config.get(self.game.app_name, "skip_update_check", fallback="unset")
if skip_update == "true":
self.skip_update.setCurrentIndex(1)
elif skip_update == "false":
self.skip_update.setCurrentIndex(2)
else:
self.skip_update.setCurrentIndex(0)
2021-03-27 06:04:29 +13:00
wrapper = self.core.lgd.config.get(self.game.app_name, "wrapper", fallback="")
self.wrapper.setText(wrapper)
2021-09-11 02:36:26 +12:00
self.game_title.setText(f"<h2>{self.game.app_title}</h2>")
if platform.system() != "Windows":
2021-03-10 09:57:54 +13:00
self.linux_settings.update_game(app_name)
self.linux_settings.dxvk.update_settings(app_name)
2021-03-10 09:57:54 +13:00
proton = self.core.lgd.config.get(f"{app_name}", "wrapper", fallback="").replace('"', "")
if proton != "":
self.proton_prefix.setEnabled(True)
self.proton_wrapper.setCurrentText(f'"{proton.replace(" run", "")}" run')
2021-03-10 09:57:54 +13:00
proton_prefix = self.core.lgd.config.get(f"{app_name}.env", "STEAM_COMPAT_DATA_PATH",
2021-03-11 23:59:12 +13:00
fallback=self.tr(
"Please select path for proton prefix"))
self.proton_prefix.setText(proton_prefix)
self.wrapper_widget.setEnabled(False)
2021-03-10 09:57:54 +13:00
else:
self.proton_wrapper.setCurrentIndex(0)
self.proton_prefix.setEnabled(False)
self.wrapper_widget.setEnabled(True)
2021-04-10 21:27:40 +12:00
if not self.game.supports_cloud_saves:
self.cloud_sync.setEnabled(False)
2021-04-10 21:27:40 +12:00
else:
self.cloud_sync.setEnabled(True)
2021-04-10 21:27:40 +12:00
sync_cloud = self.settings.value(f"{self.game.app_name}/auto_sync_cloud", True, bool)
self.cloud_sync.setChecked(sync_cloud)
2021-04-10 22:34:45 +12:00
self.launch_params.setText(self.core.lgd.config.get(self.game.app_name, "start_params", fallback=""))
2021-03-11 23:59:12 +13:00
self.change = True
2021-03-10 09:57:54 +13:00
class LinuxAppSettings(LinuxSettings):
2021-10-08 07:19:24 +13:00
def __init__(self):
super(LinuxAppSettings, self).__init__("app")
2021-03-10 09:57:54 +13:00
def update_game(self, app_name):
self.name = app_name
self.wine_prefix.setText(self.core.lgd.config.get(self.name, "wine_prefix", fallback=""))
self.wine_exec.setText(self.core.lgd.config.get(self.name, "wine_executable", fallback=""))
self.dxvk.name = app_name
self.dxvk.more_settings_widget.name = app_name