mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Persist DCS configuration across installs.
This commit is contained in:
parent
956b9aaf95
commit
92c404fbb6
@ -13,6 +13,7 @@ Saves from 2.5 are not compatible with 3.0.
|
|||||||
* **[Modding]** Campaigns now choose locations for factories to spawn.
|
* **[Modding]** Campaigns now choose locations for factories to spawn.
|
||||||
* **[Modding]** Can now install custom factions to <DCS saved games>/Liberation/Factions instead of the Liberation install directory.
|
* **[Modding]** Can now install custom factions to <DCS saved games>/Liberation/Factions instead of the Liberation install directory.
|
||||||
* **[Performance Settings]** Added a settings to lower the number of smoke effects generated on frontlines. Lowered default settings for frontline smoke generators, so less smoke should be generated by default.
|
* **[Performance Settings]** Added a settings to lower the number of smoke effects generated on frontlines. Lowered default settings for frontline smoke generators, so less smoke should be generated by default.
|
||||||
|
* **[Configuration]** Liberation preferences (DCS install and save game location) are now saved to `%LOCALAPPDATA%/DCSLiberation` to prevent needing to reconfigure each new install.
|
||||||
|
|
||||||
## Fixes
|
## Fixes
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
import dcs
|
import dcs
|
||||||
@ -10,7 +12,10 @@ global __dcs_saved_game_directory
|
|||||||
global __dcs_installation_directory
|
global __dcs_installation_directory
|
||||||
global __last_save_file
|
global __last_save_file
|
||||||
|
|
||||||
PREFERENCES_FILE_PATH = "liberation_preferences.json"
|
|
||||||
|
USER_PATH = Path(os.environ["LOCALAPPDATA"]) / "DCSLiberation"
|
||||||
|
|
||||||
|
PREFERENCES_PATH = USER_PATH / "liberation_preferences.json"
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
@ -18,18 +23,16 @@ def init():
|
|||||||
global __dcs_installation_directory
|
global __dcs_installation_directory
|
||||||
global __last_save_file
|
global __last_save_file
|
||||||
|
|
||||||
if os.path.isfile(PREFERENCES_FILE_PATH):
|
if PREFERENCES_PATH.exists():
|
||||||
try:
|
try:
|
||||||
with (open(PREFERENCES_FILE_PATH)) as prefs:
|
logging.debug("Loading Liberation preferences from %s", PREFERENCES_PATH)
|
||||||
pref_data = json.loads(prefs.read())
|
with PREFERENCES_PATH.open() as prefs:
|
||||||
__dcs_saved_game_directory = pref_data["saved_game_dir"]
|
pref_data = json.load(prefs)
|
||||||
__dcs_installation_directory = pref_data["dcs_install_dir"]
|
__dcs_saved_game_directory = pref_data["saved_game_dir"]
|
||||||
if "last_save_file" in pref_data:
|
__dcs_installation_directory = pref_data["dcs_install_dir"]
|
||||||
__last_save_file = pref_data["last_save_file"]
|
__last_save_file = pref_data.get("last_save_file", "")
|
||||||
else:
|
|
||||||
__last_save_file = ""
|
|
||||||
is_first_start = False
|
is_first_start = False
|
||||||
except:
|
except KeyError:
|
||||||
__dcs_saved_game_directory = ""
|
__dcs_saved_game_directory = ""
|
||||||
__dcs_installation_directory = ""
|
__dcs_installation_directory = ""
|
||||||
__last_save_file = ""
|
__last_save_file = ""
|
||||||
@ -78,8 +81,9 @@ def save_config():
|
|||||||
"dcs_install_dir": __dcs_installation_directory,
|
"dcs_install_dir": __dcs_installation_directory,
|
||||||
"last_save_file": __last_save_file,
|
"last_save_file": __last_save_file,
|
||||||
}
|
}
|
||||||
with (open(PREFERENCES_FILE_PATH, "w")) as prefs:
|
PREFERENCES_PATH.parent.mkdir(exist_ok=True, parents=True)
|
||||||
prefs.write(json.dumps(pref_data))
|
with PREFERENCES_PATH.open("w") as prefs:
|
||||||
|
json.dump(pref_data, prefs, indent=" ")
|
||||||
|
|
||||||
|
|
||||||
def get_dcs_install_directory():
|
def get_dcs_install_directory():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user