improved the button for adding associations

This commit is contained in:
Sergey Palcheh
2025-09-27 12:19:11 +06:00
parent 165c4ee110
commit 7f64378670

View File

@@ -2741,17 +2741,43 @@ class WineHelperGUI(QMainWindow):
QMessageBox.warning(self, "Ошибка", "Сначала выберите префикс.") QMessageBox.warning(self, "Ошибка", "Сначала выберите префикс.")
return return
current_associations = self._get_prefix_component_version(prefix_name, "WH_XDG_OPEN") or "" current_associations = self._get_prefix_component_version(prefix_name, "WH_XDG_OPEN") or "0"
dialog = FileAssociationsDialog(current_associations, self) dialog = FileAssociationsDialog(current_associations if current_associations != "0" else "", self)
if dialog.exec_() == QDialog.Accepted: if dialog.exec_() == QDialog.Accepted:
new_associations = dialog.new_associations new_associations = dialog.new_associations
# Запускаем обновление, только если значение изменилось # Запускаем обновление, только если значение изменилось
if new_associations != current_associations: if new_associations != (current_associations if current_associations != "0" else "0"):
self.run_update_associations_command(prefix_name, new_associations) self.run_update_associations_command(prefix_name, new_associations)
def run_update_associations_command(self, prefix_name, new_associations): def run_update_associations_command(self, prefix_name, new_associations):
"""Выполняет команду обновления ассоциаций файлов.""" """Выполняет команду обновления ассоциаций файлов."""
# --- Прямое редактирование last.conf, чтобы обойти перезапись переменных в winehelper ---
last_conf_path = os.path.join(Var.USER_WORK_PATH, "prefixes", prefix_name, "last.conf")
if not os.path.exists(last_conf_path):
QMessageBox.critical(self, "Ошибка", f"Файл конфигурации last.conf не найден для префикса '{prefix_name}'.")
return
try:
with open(last_conf_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
updated = False
for i, line in enumerate(lines):
if line.strip().startswith("export WH_XDG_OPEN="):
lines[i] = f'export WH_XDG_OPEN="{new_associations}"\n'
updated = True
break
if not updated:
lines.append(f'export WH_XDG_OPEN="{new_associations}"\n')
with open(last_conf_path, 'w', encoding='utf-8') as f:
f.writelines(lines)
except IOError as e:
QMessageBox.critical(self, "Ошибка записи", f"Не удалось обновить файл last.conf: {e}")
return
prefix_path = os.path.join(Var.USER_WORK_PATH, "prefixes", prefix_name) prefix_path = os.path.join(Var.USER_WORK_PATH, "prefixes", prefix_name)
self.command_dialog = QDialog(self) self.command_dialog = QDialog(self)
@@ -2777,16 +2803,14 @@ class WineHelperGUI(QMainWindow):
self.command_process.readyReadStandardOutput.connect(self._handle_command_output) self.command_process.readyReadStandardOutput.connect(self._handle_command_output)
self.command_process.finished.connect( self.command_process.finished.connect(
lambda exit_code, exit_status: self._handle_component_install_finished( lambda exit_code, exit_status: self._handle_component_install_finished(
prefix_name, exit_code, exit_status prefix_name, exit_code, exit_status))
)
)
env = QProcessEnvironment.systemEnvironment() env = QProcessEnvironment.systemEnvironment()
env.insert("WINEPREFIX", prefix_path) env.insert("WINEPREFIX", prefix_path)
# Устанавливаем новую переменную окружения для скрипта # Переменная WH_XDG_OPEN теперь читается из измененного last.conf
env.insert("WH_XDG_OPEN", new_associations)
self.command_process.setProcessEnvironment(env) self.command_process.setProcessEnvironment(env)
# Вызываем init-prefix, который теперь прочитает правильное значение из last.conf
args = ["init-prefix"] args = ["init-prefix"]
self.command_log_output.append(f"Выполнение: {shlex.quote(self.winehelper_path)} {' '.join(shlex.quote(a) for a in args)}") self.command_log_output.append(f"Выполнение: {shlex.quote(self.winehelper_path)} {' '.join(shlex.quote(a) for a in args)}")
self.command_process.start(self.winehelper_path, args) self.command_process.start(self.winehelper_path, args)