mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
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:
parent
266e69a6ce
commit
6d0dbd4d1c
@ -832,8 +832,6 @@ class KneeboardGenerator(MissionInfoGenerator):
|
|||||||
page_path = aircraft_dir / f"page{idx:02}.png"
|
page_path = aircraft_dir / f"page{idx:02}.png"
|
||||||
page.write(page_path)
|
page.write(page_path)
|
||||||
self.mission.add_aircraft_kneeboard(aircraft.dcs_unit_type, 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():
|
for type in kneeboards_dir().iterdir():
|
||||||
if type.is_dir():
|
if type.is_dir():
|
||||||
for kneeboard in type.iterdir():
|
for kneeboard in type.iterdir():
|
||||||
|
|||||||
@ -124,6 +124,12 @@ class MigrationUnpickler(pickle.Unpickler):
|
|||||||
# fmt: on
|
# 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:
|
def setup(user_folder: str, prefer_liberation_payloads: bool, port: int) -> None:
|
||||||
global _dcs_saved_game_folder
|
global _dcs_saved_game_folder
|
||||||
global _prefer_liberation_payloads
|
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
|
_dcs_saved_game_folder = user_folder
|
||||||
_prefer_liberation_payloads = prefer_liberation_payloads
|
_prefer_liberation_payloads = prefer_liberation_payloads
|
||||||
_server_port = port
|
_server_port = port
|
||||||
if not save_dir().exists():
|
_create_dir_if_needed(save_dir())
|
||||||
save_dir().mkdir(parents=True)
|
|
||||||
|
|
||||||
|
|
||||||
def base_path() -> Path:
|
def base_path() -> Path:
|
||||||
global _dcs_saved_game_folder
|
global _dcs_saved_game_folder
|
||||||
assert _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:
|
def debug_dir() -> Path:
|
||||||
return base_path() / "Retribution" / "Debug"
|
return _create_dir_if_needed(base_path() / "Retribution" / "Debug")
|
||||||
|
|
||||||
|
|
||||||
def groups_dir() -> Path:
|
def groups_dir() -> Path:
|
||||||
return base_path() / "Retribution" / "Groups"
|
return _create_dir_if_needed(base_path() / "Retribution" / "Groups")
|
||||||
|
|
||||||
|
|
||||||
def layouts_dir() -> Path:
|
def layouts_dir() -> Path:
|
||||||
return base_path() / "Retribution" / "Layouts"
|
return _create_dir_if_needed(base_path() / "Retribution" / "Layouts")
|
||||||
|
|
||||||
|
|
||||||
def waypoint_debug_directory() -> Path:
|
def waypoint_debug_directory() -> Path:
|
||||||
return debug_dir() / "Waypoints"
|
return _create_dir_if_needed(debug_dir() / "Waypoints")
|
||||||
|
|
||||||
|
|
||||||
def settings_dir() -> Path:
|
def settings_dir() -> Path:
|
||||||
return base_path() / "Retribution" / "Settings"
|
return _create_dir_if_needed(base_path() / "Retribution" / "Settings")
|
||||||
|
|
||||||
|
|
||||||
def airwing_dir() -> Path:
|
def airwing_dir() -> Path:
|
||||||
return base_path() / "Retribution" / "AirWing"
|
return _create_dir_if_needed(base_path() / "Retribution" / "AirWing")
|
||||||
|
|
||||||
|
|
||||||
def kneeboards_dir() -> Path:
|
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:
|
def payloads_dir(backup: bool = False) -> Path:
|
||||||
payloads = base_path() / "MissionEditor" / "UnitPayloads"
|
payloads = base_path() / "MissionEditor" / "UnitPayloads"
|
||||||
if backup:
|
if backup:
|
||||||
return payloads / "_retribution_backups"
|
return _create_dir_if_needed(payloads / "_retribution_backups")
|
||||||
return payloads
|
return _create_dir_if_needed(payloads)
|
||||||
|
|
||||||
|
|
||||||
def prefer_liberation_payloads() -> bool:
|
def prefer_liberation_payloads() -> bool:
|
||||||
@ -182,15 +187,15 @@ def prefer_liberation_payloads() -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def user_custom_weapon_injections_dir() -> Path:
|
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:
|
def save_dir() -> Path:
|
||||||
return base_path() / "Retribution" / "Saves"
|
return _create_dir_if_needed(base_path() / "Retribution" / "Saves")
|
||||||
|
|
||||||
|
|
||||||
def pre_pretense_backups_dir() -> Path:
|
def pre_pretense_backups_dir() -> Path:
|
||||||
return save_dir() / "PrePretenseBackups"
|
return _create_dir_if_needed(save_dir() / "PrePretenseBackups")
|
||||||
|
|
||||||
|
|
||||||
def server_port() -> int:
|
def server_port() -> int:
|
||||||
|
|||||||
@ -61,7 +61,6 @@ class PretenseMissionGenerator(MissionGenerator):
|
|||||||
def generate_miz(self, output: Path) -> UnitMap:
|
def generate_miz(self, output: Path) -> UnitMap:
|
||||||
game_backup_pickle = pickle.dumps(self.game)
|
game_backup_pickle = pickle.dumps(self.game)
|
||||||
path = pre_pretense_backups_dir()
|
path = pre_pretense_backups_dir()
|
||||||
path.mkdir(parents=True, exist_ok=True)
|
|
||||||
path /= f".pre-pretense-backup.retribution"
|
path /= f".pre-pretense-backup.retribution"
|
||||||
try:
|
try:
|
||||||
with open(path, "wb") as f:
|
with open(path, "wb") as f:
|
||||||
|
|||||||
@ -818,8 +818,6 @@ class AirWingConfigurationDialog(QDialog):
|
|||||||
|
|
||||||
def save_config(self) -> None:
|
def save_config(self) -> None:
|
||||||
awd = airwing_dir()
|
awd = airwing_dir()
|
||||||
if not awd.exists():
|
|
||||||
awd.mkdir()
|
|
||||||
fd = QFileDialog(
|
fd = QFileDialog(
|
||||||
caption="Save Air Wing", directory=str(awd), filter="*.yaml;*.yml"
|
caption="Save Air Wing", directory=str(awd), filter="*.yaml;*.yml"
|
||||||
)
|
)
|
||||||
@ -876,8 +874,6 @@ class AirWingConfigurationDialog(QDialog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
awd = airwing_dir()
|
awd = airwing_dir()
|
||||||
if not awd.exists():
|
|
||||||
awd.mkdir()
|
|
||||||
fd = QFileDialog(
|
fd = QFileDialog(
|
||||||
caption="Load Air Wing", directory=str(awd), filter="*.yaml;*.yml"
|
caption="Load Air Wing", directory=str(awd), filter="*.yaml;*.yml"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -332,7 +332,6 @@ class QLiberationWindow(QMainWindow):
|
|||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
date_time = now.strftime("%Y-%d-%mT%H_%M_%S")
|
date_time = now.strftime("%Y-%d-%mT%H_%M_%S")
|
||||||
path = pre_pretense_backups_dir()
|
path = pre_pretense_backups_dir()
|
||||||
path.mkdir(parents=True, exist_ok=True)
|
|
||||||
tgt = path / f"pre-pretense-backup_{date_time}.retribution"
|
tgt = path / f"pre-pretense-backup_{date_time}.retribution"
|
||||||
path /= f".pre-pretense-backup.retribution"
|
path /= f".pre-pretense-backup.retribution"
|
||||||
if path.exists():
|
if path.exists():
|
||||||
|
|||||||
@ -86,8 +86,6 @@ class QLoadoutEditor(QGroupBox):
|
|||||||
return
|
return
|
||||||
backup_folder = payloads_dir(backup=True)
|
backup_folder = payloads_dir(backup=True)
|
||||||
backup_file = backup_folder / f"{ac_id}.lua"
|
backup_file = backup_folder / f"{ac_id}.lua"
|
||||||
if not backup_folder.exists():
|
|
||||||
backup_folder.mkdir()
|
|
||||||
copyfile(payload_file, backup_file)
|
copyfile(payload_file, backup_file)
|
||||||
QMessageBox.information(
|
QMessageBox.information(
|
||||||
QWidget(),
|
QWidget(),
|
||||||
@ -105,7 +103,6 @@ class QLoadoutEditor(QGroupBox):
|
|||||||
ac_id = ac_type.id
|
ac_id = ac_type.id
|
||||||
payloads_folder = payloads_dir()
|
payloads_folder = payloads_dir()
|
||||||
payload_file = payloads_folder / f"{ac_id}.lua"
|
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(
|
ac_type.payloads[payload_name] = DcsPayload.from_flight_member(
|
||||||
self.flight_member, payload_name
|
self.flight_member, payload_name
|
||||||
).to_dict()
|
).to_dict()
|
||||||
|
|||||||
@ -539,8 +539,6 @@ class QSettingsWidget(QtWidgets.QWizardPage, SettingsContainer):
|
|||||||
|
|
||||||
def load_settings(self):
|
def load_settings(self):
|
||||||
sd = settings_dir()
|
sd = settings_dir()
|
||||||
if not sd.exists():
|
|
||||||
sd.mkdir()
|
|
||||||
fd = QFileDialog(caption="Load Settings", directory=str(sd), filter="*.zip")
|
fd = QFileDialog(caption="Load Settings", directory=str(sd), filter="*.zip")
|
||||||
if fd.exec_():
|
if fd.exec_():
|
||||||
zipfilename = fd.selectedFiles()[0]
|
zipfilename = fd.selectedFiles()[0]
|
||||||
@ -555,8 +553,6 @@ class QSettingsWidget(QtWidgets.QWizardPage, SettingsContainer):
|
|||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
sd = settings_dir()
|
sd = settings_dir()
|
||||||
if not sd.exists():
|
|
||||||
sd.mkdir()
|
|
||||||
fd = QFileDialog(caption="Save Settings", directory=str(sd), filter="*.zip")
|
fd = QFileDialog(caption="Save Settings", directory=str(sd), filter="*.zip")
|
||||||
fd.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
|
fd.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
|
||||||
if fd.exec_():
|
if fd.exec_():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user