From e70baa78d2ade1386b14a7b96cbf8930b1cb0a4f Mon Sep 17 00:00:00 2001 From: Timi007 Date: Fri, 29 Dec 2023 19:50:49 +0100 Subject: [PATCH] Add script to create links to the addons needed for file patching --- .gitignore | 8 +- .hemtt/project.toml | 5 ++ .vscode/settings.json | 9 ++- .vscode/tasks.json | 2 +- build.bat | 2 +- tools/setup.py | 119 ------------------------------ tools/setup_filepatching_links.py | 94 +++++++++++++++++++++++ 7 files changed, 111 insertions(+), 128 deletions(-) delete mode 100644 tools/setup.py create mode 100644 tools/setup_filepatching_links.py diff --git a/.gitignore b/.gitignore index 5f6f8a1..9e7860c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -release/* *.cache *.pbo texHeaders.bin @@ -9,10 +8,11 @@ Thumbs.db *.sqfc *.exe -## Added by HEMTT +#### HEMTT hemtt hemtt.exe -releases/* -keys/* +release/ +releases/ +keys/ .hemttout/ #### diff --git a/.hemtt/project.toml b/.hemtt/project.toml index 74cd815..2165a8a 100644 --- a/.hemtt/project.toml +++ b/.hemtt/project.toml @@ -34,3 +34,8 @@ preset = "Hemtt" [hemtt.release] folder = "Metis_Presentation" + +[hemtt.launch.default] +workshop = [ + "450814997", # CBA_A3's Workshop ID +] diff --git a/.vscode/settings.json b/.vscode/settings.json index 0796667..9ec009d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,7 +10,6 @@ "**/*.exe": true, "**/keys": true, "**/release": true, - "**/__pycache__": true, }, "files.associations": { "**/*.hpp": "ext", @@ -21,10 +20,14 @@ "init*.hpp": "sqf", }, "search.exclude": { - "**/venv": true, + ".hemttout/dev": true, + ".hemttout/build": true, + ".hemttout/release": true, }, "explorer.autoRevealExclude": { - "**/venv": true + ".hemttout/dev": true, + ".hemttout/build": true, + ".hemttout/release": true, }, "sqf.enableACE3": false, "sqf.enableCBA": true, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bef2126..dd4a1e4 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,7 @@ "detail": "Build Arma addon with HEMTT in debug mode.", "type": "process", "command": "hemtt", - "args": ["build"], + "args": ["dev"], "group": "build", "presentation": { "close": true, diff --git a/build.bat b/build.bat index 34e67d1..d82070d 100644 --- a/build.bat +++ b/build.bat @@ -1,3 +1,3 @@ @echo off -hemtt build +hemtt dev pause diff --git a/tools/setup.py b/tools/setup.py deleted file mode 100644 index 9534f3d..0000000 --- a/tools/setup.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env python3 - -######################## -# Metis Setup Script # -######################## - -import os -import sys -import shutil -import platform -import subprocess -import winreg - -######## GLOBALS ######### -MAINDIR = "z" -PROJECTDIR = "mts_presentation" -CBA = "P:\\x\\cba" -########################## - -def main(): - FULLDIR = "{}\\{}".format(MAINDIR,PROJECTDIR) - print(""" - ####################################### - # Metis Development Environment Setup # - ####################################### - - This script will create your Metis dev environment for you. - - Before you run this, you should already have: - - The Arma 3 Tools installed properly via Steam - - A properly set up P-drive - - If you have not done those things yet, please abort this script in the next step and do so first. - - This script will create two hard links on your system, both pointing to your Metis project folder: - [Arma 3 installation directory]\\{} => Metis project folder - P:\\{} => Metis project folder - - It will also copy the required CBA includes to {}, if you do not have the CBA source code already.""".format(FULLDIR,FULLDIR,CBA)) - print("\n") - - try: - reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) - key = winreg.OpenKey(reg, - r"SOFTWARE\Wow6432Node\bohemia interactive\arma 3") - armapath = winreg.EnumValue(key,1)[1] - except: - print("Failed to determine Arma 3 Path.") - return 1 - - if not os.path.exists("P:\\"): - print("No P-drive detected.") - return 2 - - scriptpath = os.path.realpath(__file__) - projectpath = os.path.dirname(os.path.dirname(scriptpath)) - - print("# Detected Paths:") - print(" Arma Path: {}".format(armapath)) - print(" Project Path: {}".format(projectpath)) - - repl = input("\nAre these correct? (y/n): ") - if repl.lower() != "y": - return 3 - - print("\n# Creating links ...") - - if os.path.exists("P:\\{}\\{}".format(MAINDIR,PROJECTDIR)): - print("Link on P: already exists. Please finish the setup manually.") - return 4 - - if os.path.exists(os.path.join(armapath, MAINDIR, PROJECTDIR)): - print("Link in Arma directory already exists. Please finish the setup manually.") - return 5 - - try: - if not os.path.exists("P:\\{}".format(MAINDIR)): - os.makedirs("P:\\{}".format(MAINDIR)) - if not os.path.exists(os.path.join(armapath, MAINDIR)): - os.makedirs(os.path.join(armapath, MAINDIR)) - - subprocess.call(["cmd", "/c", "mklink", "/J", "P:\\{}\\{}".format(MAINDIR,PROJECTDIR), projectpath]) - subprocess.call(["cmd", "/c", "mklink", "/J", os.path.join(armapath, MAINDIR, PROJECTDIR), projectpath]) - except: - raise - print("Something went wrong during the link creation. Please finish the setup manually.") - return 6 - - print("# Links created successfully.") - - - print("\n# Copying required CBA includes ...") - - if os.path.exists(CBA): - print("{} already exists, skipping.".format(CBA)) - return -1 - - try: - shutil.copytree(os.path.join(projectpath, "include", "x", "cba"), CBA) - except: - raise - print("Something went wrong while copying CBA includes. Please copy include\\x\\cba to {} manually.".format(CBA)) - return 7 - - print("# CBA includes copied successfully to {}.".format(CBA)) - - return 0 - - -if __name__ == "__main__": - exitcode = main() - - if exitcode > 0: - print("\nSomething went wrong during the setup. Make sure you run this script as administrator. If these issues persist, please follow the instructions on the Metis wiki to perform the setup manually.") - else: - print("\nSetup successfully completed.") - - input("\nPress enter to exit ...") - sys.exit(exitcode) diff --git a/tools/setup_filepatching_links.py b/tools/setup_filepatching_links.py new file mode 100644 index 0000000..48dd23f --- /dev/null +++ b/tools/setup_filepatching_links.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python3 + +######################## +# Metis Setup Script # +######################## + +import os +import sys +import winreg +import _winapi + +######## GLOBALS ######### +MAINDIR = "z" +PROJECTDIR = "mts_presentation" +########################## + +def main(): + FULLDIR = f"{MAINDIR}\\{PROJECTDIR}" + print(f""" + ####################################### + # Metis Development Environment Setup # + ####################################### + + This script will create your Metis dev environment for you. + + Before you run this, you should already have: + - The Arma 3 Tools installed properly via Steam + - A properly set up P-drive + + If you have not done those things yet, please abort this script in the next step and do so first. + + This script will create two hard links on your system, both pointing to your Metis project folder: + [Arma 3 installation directory]\\{FULLDIR} => Metis project HEMTT dev build folder + P:\\{FULLDIR} => Metis project HEMTT dev build folder""") + print("\n") + + try: + reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) + key = winreg.OpenKey(reg, r"SOFTWARE\Wow6432Node\bohemia interactive\arma 3") + armapath = winreg.EnumValue(key,1)[1] + except: + print("Failed to determine Arma 3 Path.") + return 2 + + if not os.path.exists("P:\\"): + print("No P-drive detected.") + return 3 + + scriptpath = os.path.realpath(__file__) + projectpath = os.path.dirname(os.path.dirname(scriptpath)) + devpath = os.path.join(projectpath, '.hemttout', 'dev') + + print("# Detected Paths:") + print(f" Arma path: {armapath}") + print(f" Project path: {projectpath}") + print(f" HEMTT dev build path: {devpath}") + + repl = input("\nAre these correct? (y/n): ") + if repl.lower() != "y": + return 4 + + print("\n# Creating links ...") + try: + os.makedirs(devpath, exist_ok=True) + + if not os.path.exists(os.path.join("P:", MAINDIR, PROJECTDIR)): + os.makedirs(os.path.join("P:", MAINDIR), exist_ok=True) + _winapi.CreateJunction(devpath, os.path.join("P:", MAINDIR, PROJECTDIR)) + else: + print("Link on P: already exists. Skipping it.") + + if not os.path.exists(os.path.join(armapath, MAINDIR, PROJECTDIR)): + os.makedirs(os.path.join(armapath, MAINDIR), exist_ok=True) + _winapi.CreateJunction(devpath, os.path.join(armapath, MAINDIR, PROJECTDIR)) + else: + print("Link in Arma directory already exists. Skipping it.") + except: + print("Something went wrong during the link creation. Please finish the setup manually.") + raise + + print("# Links created successfully.") + + return 0 + + +if __name__ == "__main__": + exitcode = main() + + if exitcode > 0: + print("\nSomething went wrong during the setup. If these issues persist, please follow the instructions on the Metis wiki to perform the setup manually.") + else: + print("\nSetup successfully completed.") + + sys.exit(exitcode)