From 93a0db3112bbb06bfd88f8de9a09ea6ca579da7a Mon Sep 17 00:00:00 2001
From: RndName
Date: Sat, 22 Jan 2022 13:05:04 +0100
Subject: [PATCH] Add otion to ignore the empty install dir warning message
Adds a do not show again checkbox to the empty install dir warning popup on lib start. This only appears when the install dir is empty to prevent mission scripting replacement.
Also adds a warning message to the log when the dir is empty. Will help to identify this in bug reports.
---
qt_ui/liberation_install.py | 18 ++++++++++++++++
qt_ui/main.py | 42 ++++++++++++++++++++++++-------------
2 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/qt_ui/liberation_install.py b/qt_ui/liberation_install.py
index 341cd45a..8ffbc30c 100644
--- a/qt_ui/liberation_install.py
+++ b/qt_ui/liberation_install.py
@@ -22,6 +22,7 @@ def init():
global __dcs_saved_game_directory
global __dcs_installation_directory
global __last_save_file
+ global __ignore_empty_install_directory
if PREFERENCES_PATH.exists():
try:
@@ -31,14 +32,19 @@ def init():
__dcs_saved_game_directory = pref_data["saved_game_dir"]
__dcs_installation_directory = pref_data["dcs_install_dir"]
__last_save_file = pref_data.get("last_save_file", "")
+ __ignore_empty_install_directory = pref_data.get(
+ "ignore_empty_install_directory", False
+ )
is_first_start = False
except KeyError:
__dcs_saved_game_directory = ""
__dcs_installation_directory = ""
__last_save_file = ""
+ __ignore_empty_install_directory = False
is_first_start = True
else:
__last_save_file = ""
+ __ignore_empty_install_directory = False
try:
__dcs_saved_game_directory = (
dcs.installation.get_dcs_saved_games_directory()
@@ -76,10 +82,12 @@ def save_config():
global __dcs_saved_game_directory
global __dcs_installation_directory
global __last_save_file
+ global __ignore_empty_install_directory
pref_data = {
"saved_game_dir": __dcs_saved_game_directory,
"dcs_install_dir": __dcs_installation_directory,
"last_save_file": __last_save_file,
+ "ignore_empty_install_directory": __ignore_empty_install_directory,
}
PREFERENCES_PATH.parent.mkdir(exist_ok=True, parents=True)
with PREFERENCES_PATH.open("w") as prefs:
@@ -96,6 +104,16 @@ def get_saved_game_dir():
return __dcs_saved_game_directory
+def ignore_empty_install_directory():
+ global __ignore_empty_install_directory
+ return __ignore_empty_install_directory
+
+
+def set_ignore_empty_install_directory(value: bool):
+ global __ignore_empty_install_directory
+ __ignore_empty_install_directory = value
+
+
def get_last_save_file():
global __last_save_file
print(__last_save_file)
diff --git a/qt_ui/main.py b/qt_ui/main.py
index 2032c8f6..9ef9dfc5 100644
--- a/qt_ui/main.py
+++ b/qt_ui/main.py
@@ -9,7 +9,7 @@ from typing import Optional
from PySide2 import QtWidgets
from PySide2.QtCore import Qt
from PySide2.QtGui import QPixmap
-from PySide2.QtWidgets import QApplication, QSplashScreen
+from PySide2.QtWidgets import QApplication, QSplashScreen, QCheckBox
from dcs.payloads import PayloadDirectories
from game import Game, VERSION, persistency
@@ -99,20 +99,29 @@ def run_ui(game: Optional[Game]) -> None:
# Show warning if no DCS Installation directory was set
if liberation_install.get_dcs_install_directory() == "":
- QtWidgets.QMessageBox.warning(
- splash,
- "No DCS installation directory.",
- "The DCS Installation directory is not set correctly. "
- "This will prevent DCS Liberation to work properly as the MissionScripting "
- "file will not be modified."
- "
To solve this problem, you can set the Installation directory "
- "within the preferences menu. You can also manually edit or replace the "
- "following file:"
- "
<dcs_installation_directory>/Scripts/MissionScripting.lua"
- "
The easiest way to do it is to replace the original file with the file in dcs-liberation distribution (<dcs_liberation_installation>/resources/scripts/MissionScripting.lua)."
- "
You can find more information on how to manually change this file in the Liberation Wiki (Page: Dedicated Server Guide) on GitHub.
",
- QtWidgets.QMessageBox.StandardButton.Ok,
+ logging.warning(
+ "DCS Installation directory is empty. MissionScripting file will not be replaced!"
)
+ if not liberation_install.ignore_empty_install_directory():
+ ignore_checkbox = QCheckBox("Do not show again")
+ ignore_checkbox.stateChanged.connect(set_ignore_empty_install_directory)
+ message_box = QtWidgets.QMessageBox(parent=splash)
+ message_box.setIcon(QtWidgets.QMessageBox.Icon.Warning)
+ message_box.setWindowTitle("No DCS installation directory.")
+ message_box.setText(
+ "The DCS Installation directory is not set correctly. "
+ "This will prevent DCS Liberation to work properly as the MissionScripting "
+ "file will not be modified."
+ "
To solve this problem, you can set the Installation directory "
+ "within the preferences menu. You can also manually edit or replace the "
+ "following file:"
+ "
<dcs_installation_directory>/Scripts/MissionScripting.lua"
+ "
The easiest way to do it is to replace the original file with the file in dcs-liberation distribution (<dcs_liberation_installation>/resources/scripts/MissionScripting.lua)."
+ "
You can find more information on how to manually change this file in the Liberation Wiki (Page: Dedicated Server Guide) on GitHub."
+ )
+ message_box.setDefaultButton(QtWidgets.QMessageBox.StandardButton.Ok)
+ message_box.setCheckBox(ignore_checkbox)
+ message_box.exec_()
# Replace DCS Mission scripting file to allow DCS Liberation to work
try:
liberation_install.replace_mission_scripting_file()
@@ -274,6 +283,11 @@ def create_game(
return game
+def set_ignore_empty_install_directory(value: bool) -> None:
+ liberation_install.set_ignore_empty_install_directory(value)
+ liberation_install.save_config()
+
+
def lint_all_weapon_data() -> None:
for weapon in WeaponGroup.named("Unknown").weapons:
logging.warning(f"No weapon data for {weapon}: {weapon.clsid}")