mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Possible to setup custom saved game and installation directory.
This commit is contained in:
@@ -1,132 +0,0 @@
|
||||
"""
|
||||
This utility classes provides methods to check players installed DCS environment.
|
||||
|
||||
TODO : add method 'is_using_open_beta', 'is_using_stable'
|
||||
TODO : [NICE to have] add method to check list of installed DCS modules (could be done either through window registry, or through filesystem analysis)
|
||||
"""
|
||||
|
||||
import winreg
|
||||
import os
|
||||
|
||||
|
||||
def is_using_dcs_steam_edition():
|
||||
"""
|
||||
Check if DCS World : Steam Edition version is installed on this computer
|
||||
:return True if DCS Steam edition is installed,
|
||||
-1 if DCS Steam Edition is registered in Steam apps but not installed,
|
||||
False if never installed in Steam
|
||||
"""
|
||||
try:
|
||||
# Note : Steam App ID for DCS World is 223750
|
||||
dcs_steam_app_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Valve\\Steam\\Apps\\223750")
|
||||
installed = winreg.QueryValueEx(dcs_steam_app_key, "Installed")
|
||||
winreg.CloseKey(dcs_steam_app_key)
|
||||
if installed[0] == 1:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except FileNotFoundError as fnfe:
|
||||
return False
|
||||
|
||||
|
||||
def is_using_dcs_standalone_edition():
|
||||
"""
|
||||
Check if DCS World standalone edition is installed on this computer
|
||||
:return True if Standalone is installed, False if it is not
|
||||
"""
|
||||
try:
|
||||
dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World")
|
||||
winreg.CloseKey(dcs_path_key)
|
||||
return True
|
||||
except FileNotFoundError as fnfe:
|
||||
return False
|
||||
|
||||
|
||||
def _find_steam_directory():
|
||||
"""
|
||||
Get the Steam install directory for this computer from registry
|
||||
:return Steam installation path
|
||||
"""
|
||||
try:
|
||||
steam_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Valve\\Steam")
|
||||
path = winreg.QueryValueEx(steam_key, "SteamPath")[0]
|
||||
winreg.CloseKey(steam_key)
|
||||
return path
|
||||
except FileNotFoundError as fnfe:
|
||||
print(fnfe)
|
||||
return ""
|
||||
|
||||
|
||||
def _get_steam_library_folders():
|
||||
"""
|
||||
Get the installation directory for Steam games
|
||||
:return List of Steam library folders where games can be installed
|
||||
"""
|
||||
try:
|
||||
steam_dir = _find_steam_directory()
|
||||
"""
|
||||
For reference here is what the vdf file is supposed to look like :
|
||||
|
||||
"LibraryFolders"
|
||||
{
|
||||
"TimeNextStatsReport" "1561832478"
|
||||
"ContentStatsID" "-158337411110787451"
|
||||
"1" "D:\\Games\\Steam"
|
||||
"2" "E:\\Steam"
|
||||
}
|
||||
"""
|
||||
vdf_file_location = steam_dir + os.path.sep + "steamapps" + os.path.sep + "libraryfolders.vdf"
|
||||
with open(vdf_file_location) as adf_file:
|
||||
paths = [l.split("\"")[3] for l in adf_file.readlines()[1:] if ':\\\\' in l]
|
||||
return paths
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return []
|
||||
|
||||
|
||||
def _find_steam_dcs_directory():
|
||||
"""
|
||||
Find the DCS install directory for DCS World Steam Edition
|
||||
:return: Install directory as string, empty string if not found
|
||||
"""
|
||||
for library_folder in _get_steam_library_folders():
|
||||
folder = library_folder + os.path.sep + "steamapps" + os.path.sep + "common" + os.path.sep + "DCSWorld"
|
||||
if os.path.isdir(folder):
|
||||
return folder + os.path.sep
|
||||
return ""
|
||||
|
||||
|
||||
def get_dcs_install_directory():
|
||||
"""
|
||||
Get the DCS World install directory for this computer
|
||||
:return DCS World install directory
|
||||
"""
|
||||
if is_using_dcs_standalone_edition():
|
||||
try:
|
||||
dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World")
|
||||
path = winreg.QueryValueEx(dcs_path_key, "Path")
|
||||
dcs_dir = path[0] + os.path.sep
|
||||
winreg.CloseKey(dcs_path_key)
|
||||
return dcs_dir
|
||||
except Exception as e:
|
||||
print("Couldn't detect DCS World installation folder")
|
||||
return ""
|
||||
elif is_using_dcs_steam_edition():
|
||||
return _find_steam_dcs_directory()
|
||||
else:
|
||||
print("Couldn't detect any installed DCS World version")
|
||||
|
||||
|
||||
def get_dcs_saved_games_directory():
|
||||
"""
|
||||
Get the save game directory for DCS World
|
||||
:return: Save game directory as string
|
||||
"""
|
||||
return os.path.join(os.path.expanduser("~"), "Saved Games", "DCS")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Using STEAM Edition : " + str(is_using_dcs_steam_edition()))
|
||||
print("Using Standalone Edition : " + str(is_using_dcs_standalone_edition()))
|
||||
print("DCS Installation directory : " + get_dcs_install_directory())
|
||||
print("DCS saved games directory : " + get_dcs_saved_games_directory())
|
||||
99
userdata/liberation_install.py
Normal file
99
userdata/liberation_install.py
Normal file
@@ -0,0 +1,99 @@
|
||||
import json
|
||||
import os
|
||||
from shutil import copyfile
|
||||
|
||||
import dcs
|
||||
|
||||
from userdata import persistency
|
||||
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
|
||||
PREFERENCES_FILE_PATH = "liberation_preferences.json"
|
||||
|
||||
def init():
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
|
||||
if os.path.isfile(PREFERENCES_FILE_PATH):
|
||||
try:
|
||||
with(open(PREFERENCES_FILE_PATH)) as prefs:
|
||||
pref_data = json.loads(prefs.read())
|
||||
__dcs_saved_game_directory = pref_data["saved_game_dir"]
|
||||
__dcs_installation_directory = pref_data["dcs_install_dir"]
|
||||
is_first_start = False
|
||||
except:
|
||||
__dcs_saved_game_directory = ""
|
||||
__dcs_installation_directory = ""
|
||||
is_first_start = True
|
||||
else:
|
||||
try:
|
||||
__dcs_saved_game_directory = dcs.installation.get_dcs_saved_games_directory()
|
||||
if os.path.exists(__dcs_saved_game_directory + ".openbeta"):
|
||||
__dcs_saved_game_directory = dcs.installation.get_dcs_saved_games_directory() + ".openbeta"
|
||||
except:
|
||||
__dcs_saved_game_directory = ""
|
||||
try:
|
||||
__dcs_installation_directory = dcs.installation.get_dcs_install_directory()
|
||||
except:
|
||||
__dcs_installation_directory = ""
|
||||
|
||||
is_first_start = True
|
||||
persistency.setup(__dcs_saved_game_directory)
|
||||
return is_first_start
|
||||
|
||||
|
||||
def setup(saved_game_dir, install_dir):
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
__dcs_saved_game_directory = saved_game_dir
|
||||
__dcs_installation_directory = install_dir
|
||||
persistency.setup(__dcs_saved_game_directory)
|
||||
|
||||
|
||||
def save_config():
|
||||
global __dcs_saved_game_directory
|
||||
global __dcs_installation_directory
|
||||
pref_data = {"saved_game_dir": __dcs_saved_game_directory,
|
||||
"dcs_install_dir": __dcs_installation_directory}
|
||||
with(open(PREFERENCES_FILE_PATH, "w")) as prefs:
|
||||
prefs.write(json.dumps(pref_data))
|
||||
|
||||
|
||||
def get_dcs_install_directory():
|
||||
global __dcs_installation_directory
|
||||
return __dcs_installation_directory
|
||||
|
||||
|
||||
def get_saved_game_dir():
|
||||
global __dcs_saved_game_directory
|
||||
return __dcs_saved_game_directory
|
||||
|
||||
|
||||
def replace_mission_scripting_file():
|
||||
install_dir = get_dcs_install_directory()
|
||||
mission_scripting_path = os.path.join(install_dir, "Scripts", "MissionScripting.lua")
|
||||
liberation_scripting_path = "./resources/scripts/MissionScripting.lua"
|
||||
backup_scripting_path = "./resources/scripts/MissionScripting.original.lua"
|
||||
if os.path.isfile(mission_scripting_path):
|
||||
with open(mission_scripting_path, "r") as ms:
|
||||
current_file_content = ms.read()
|
||||
with open(liberation_scripting_path, "r") as libe_ms:
|
||||
liberation_file_content = libe_ms.read()
|
||||
|
||||
# Save original file
|
||||
if current_file_content != liberation_file_content:
|
||||
copyfile(mission_scripting_path, backup_scripting_path)
|
||||
|
||||
# Replace DCS file
|
||||
copyfile(liberation_scripting_path, mission_scripting_path)
|
||||
|
||||
|
||||
def restore_original_mission_scripting():
|
||||
install_dir = get_dcs_install_directory()
|
||||
mission_scripting_path = os.path.join(install_dir, "Scripts", "MissionScripting.lua")
|
||||
backup_scripting_path = "./resources/scripts/MissionScripting.original.lua"
|
||||
|
||||
if os.path.isfile(backup_scripting_path) and os.path.isfile(mission_scripting_path):
|
||||
copyfile(backup_scripting_path, mission_scripting_path)
|
||||
|
||||
@@ -2,9 +2,6 @@ import logging
|
||||
import os
|
||||
import pickle
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from dcs import installation
|
||||
|
||||
_dcs_saved_game_folder = None # type: str
|
||||
|
||||
@@ -17,12 +14,7 @@ def setup(user_folder: str):
|
||||
def base_path() -> str:
|
||||
global _dcs_saved_game_folder
|
||||
assert _dcs_saved_game_folder
|
||||
|
||||
openbeta_path = _dcs_saved_game_folder + ".openbeta"
|
||||
if os.path.exists(openbeta_path):
|
||||
return openbeta_path # For standalone openbeta users
|
||||
else:
|
||||
return _dcs_saved_game_folder # For standalone stable users & steam users (any branch)
|
||||
return _dcs_saved_game_folder
|
||||
|
||||
|
||||
def _save_file() -> str:
|
||||
|
||||
Reference in New Issue
Block a user