Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions rare/components/tabs/settings/widgets/wine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from logging import getLogger
from typing import Optional
from typing import Optional, Tuple

from PySide6.QtCore import QSignalBlocker, Qt, Signal, Slot
from PySide6.QtGui import QShowEvent
Expand Down Expand Up @@ -31,11 +31,7 @@ def __init__(self, settings: RareAppSettings, rcore: RareCore, parent=None):
self.wine_prefix_edit = PathEdit(
path="",
file_mode=QFileDialog.FileMode.Directory,
edit_func=lambda path: (
os.path.isdir(path) or not path,
path,
IndicatorReasonsCommon.DIR_NOT_EXISTS,
),
edit_func=self._wine_prefix_edit,
save_func=self.save_prefix,
)

Expand Down Expand Up @@ -94,8 +90,10 @@ def compat_tool_enabled(self, enabled: bool, path: str):
else:
self.settings.remove(f"{self.app_name}/wine_execut")
self.settings.remove(f"{self.app_name}/wine_prefix")
self.wine_execut_edit.setText(old_wine_execut)
self.wine_prefix_edit.setText(old_wine_prefix)
if old_wine_execut is not None:
self.wine_execut_edit.setText(old_wine_execut)
if old_wine_prefix is not None:
self.wine_prefix_edit.setText(old_wine_prefix)
lgd_config.remove_option(self.app_name, "no_wine")
self.setDisabled(enabled)

Expand All @@ -104,6 +102,23 @@ def load_prefix(self) -> str:
raise RuntimeError
return lgd_config.get_wine_prefix(self.app_name, "")

@staticmethod
def _wine_prefix_edit(text: str) -> Tuple[bool, str, int]:
if not text:
return True, text, IndicatorReasonsCommon.VALID
if os.path.isdir(text):
dir_list = os.listdir(text)
if not dir_list:
return True, text, IndicatorReasonsCommon.VALID
if any(
(x in dir_list) for x in
("dosdevices", "drive_c", "system.reg", "user.reg", "userdef.reg")
):
return True, text, IndicatorReasonsCommon.VALID
return False, text, IndicatorReasonsCommon.DIR_NOT_EMPTY
else:
return False, text, IndicatorReasonsCommon.DIR_NOT_EXISTS

def save_prefix(self, path: str) -> None:
if self.app_name is None:
raise RuntimeError
Expand Down