Bugfix if settings directory doesn't exist (#432)

* bugfix if settings directory doesnt exist

* Create directories in persistency

---------

Co-authored-by: Raffson <Raffson@users.noreply.github.com>
This commit is contained in:
Druss99 2024-12-21 11:44:31 -05:00 committed by GitHub
parent 266e69a6ce
commit 6d0dbd4d1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 20 additions and 30 deletions

View File

@ -832,8 +832,6 @@ class KneeboardGenerator(MissionInfoGenerator):
page_path = aircraft_dir / f"page{idx:02}.png"
page.write(page_path)
self.mission.add_aircraft_kneeboard(aircraft.dcs_unit_type, page_path)
if not kneeboards_dir().exists():
return
for type in kneeboards_dir().iterdir():
if type.is_dir():
for kneeboard in type.iterdir():

View File

@ -124,6 +124,12 @@ class MigrationUnpickler(pickle.Unpickler):
# fmt: on
def _create_dir_if_needed(path: Path) -> Path:
if not path.exists():
path.mkdir(755, parents=True)
return path
def setup(user_folder: str, prefer_liberation_payloads: bool, port: int) -> None:
global _dcs_saved_game_folder
global _prefer_liberation_payloads
@ -131,49 +137,48 @@ def setup(user_folder: str, prefer_liberation_payloads: bool, port: int) -> None
_dcs_saved_game_folder = user_folder
_prefer_liberation_payloads = prefer_liberation_payloads
_server_port = port
if not save_dir().exists():
save_dir().mkdir(parents=True)
_create_dir_if_needed(save_dir())
def base_path() -> Path:
global _dcs_saved_game_folder
assert _dcs_saved_game_folder
return Path(_dcs_saved_game_folder)
return _create_dir_if_needed(Path(_dcs_saved_game_folder))
def debug_dir() -> Path:
return base_path() / "Retribution" / "Debug"
return _create_dir_if_needed(base_path() / "Retribution" / "Debug")
def groups_dir() -> Path:
return base_path() / "Retribution" / "Groups"
return _create_dir_if_needed(base_path() / "Retribution" / "Groups")
def layouts_dir() -> Path:
return base_path() / "Retribution" / "Layouts"
return _create_dir_if_needed(base_path() / "Retribution" / "Layouts")
def waypoint_debug_directory() -> Path:
return debug_dir() / "Waypoints"
return _create_dir_if_needed(debug_dir() / "Waypoints")
def settings_dir() -> Path:
return base_path() / "Retribution" / "Settings"
return _create_dir_if_needed(base_path() / "Retribution" / "Settings")
def airwing_dir() -> Path:
return base_path() / "Retribution" / "AirWing"
return _create_dir_if_needed(base_path() / "Retribution" / "AirWing")
def kneeboards_dir() -> Path:
return base_path() / "Retribution" / "Kneeboards"
return _create_dir_if_needed(base_path() / "Retribution" / "Kneeboards")
def payloads_dir(backup: bool = False) -> Path:
payloads = base_path() / "MissionEditor" / "UnitPayloads"
if backup:
return payloads / "_retribution_backups"
return payloads
return _create_dir_if_needed(payloads / "_retribution_backups")
return _create_dir_if_needed(payloads)
def prefer_liberation_payloads() -> bool:
@ -182,15 +187,15 @@ def prefer_liberation_payloads() -> bool:
def user_custom_weapon_injections_dir() -> Path:
return base_path() / "Retribution" / "WeaponInjections"
return _create_dir_if_needed(base_path() / "Retribution" / "WeaponInjections")
def save_dir() -> Path:
return base_path() / "Retribution" / "Saves"
return _create_dir_if_needed(base_path() / "Retribution" / "Saves")
def pre_pretense_backups_dir() -> Path:
return save_dir() / "PrePretenseBackups"
return _create_dir_if_needed(save_dir() / "PrePretenseBackups")
def server_port() -> int:

View File

@ -61,7 +61,6 @@ class PretenseMissionGenerator(MissionGenerator):
def generate_miz(self, output: Path) -> UnitMap:
game_backup_pickle = pickle.dumps(self.game)
path = pre_pretense_backups_dir()
path.mkdir(parents=True, exist_ok=True)
path /= f".pre-pretense-backup.retribution"
try:
with open(path, "wb") as f:

View File

@ -818,8 +818,6 @@ class AirWingConfigurationDialog(QDialog):
def save_config(self) -> None:
awd = airwing_dir()
if not awd.exists():
awd.mkdir()
fd = QFileDialog(
caption="Save Air Wing", directory=str(awd), filter="*.yaml;*.yml"
)
@ -876,8 +874,6 @@ class AirWingConfigurationDialog(QDialog):
return
awd = airwing_dir()
if not awd.exists():
awd.mkdir()
fd = QFileDialog(
caption="Load Air Wing", directory=str(awd), filter="*.yaml;*.yml"
)

View File

@ -332,7 +332,6 @@ class QLiberationWindow(QMainWindow):
now = datetime.now()
date_time = now.strftime("%Y-%d-%mT%H_%M_%S")
path = pre_pretense_backups_dir()
path.mkdir(parents=True, exist_ok=True)
tgt = path / f"pre-pretense-backup_{date_time}.retribution"
path /= f".pre-pretense-backup.retribution"
if path.exists():

View File

@ -86,8 +86,6 @@ class QLoadoutEditor(QGroupBox):
return
backup_folder = payloads_dir(backup=True)
backup_file = backup_folder / f"{ac_id}.lua"
if not backup_folder.exists():
backup_folder.mkdir()
copyfile(payload_file, backup_file)
QMessageBox.information(
QWidget(),
@ -105,7 +103,6 @@ class QLoadoutEditor(QGroupBox):
ac_id = ac_type.id
payloads_folder = payloads_dir()
payload_file = payloads_folder / f"{ac_id}.lua"
payloads_folder.mkdir(parents=True, exist_ok=True)
ac_type.payloads[payload_name] = DcsPayload.from_flight_member(
self.flight_member, payload_name
).to_dict()

View File

@ -539,8 +539,6 @@ class QSettingsWidget(QtWidgets.QWizardPage, SettingsContainer):
def load_settings(self):
sd = settings_dir()
if not sd.exists():
sd.mkdir()
fd = QFileDialog(caption="Load Settings", directory=str(sd), filter="*.zip")
if fd.exec_():
zipfilename = fd.selectedFiles()[0]
@ -555,8 +553,6 @@ class QSettingsWidget(QtWidgets.QWizardPage, SettingsContainer):
def save_settings(self):
sd = settings_dir()
if not sd.exists():
sd.mkdir()
fd = QFileDialog(caption="Save Settings", directory=str(sd), filter="*.zip")
fd.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
if fd.exec_():