improved the button for adding associations
This commit is contained in:
@@ -2741,17 +2741,43 @@ class WineHelperGUI(QMainWindow):
|
||||
QMessageBox.warning(self, "Ошибка", "Сначала выберите префикс.")
|
||||
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:
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
self.command_dialog = QDialog(self)
|
||||
@@ -2777,16 +2803,14 @@ class WineHelperGUI(QMainWindow):
|
||||
self.command_process.readyReadStandardOutput.connect(self._handle_command_output)
|
||||
self.command_process.finished.connect(
|
||||
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.insert("WINEPREFIX", prefix_path)
|
||||
# Устанавливаем новую переменную окружения для скрипта
|
||||
env.insert("WH_XDG_OPEN", new_associations)
|
||||
# Переменная WH_XDG_OPEN теперь читается из измененного last.conf
|
||||
self.command_process.setProcessEnvironment(env)
|
||||
|
||||
# Вызываем init-prefix, который теперь прочитает правильное значение из last.conf
|
||||
args = ["init-prefix"]
|
||||
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)
|
||||
|
Reference in New Issue
Block a user