generated from gottyduke/SF_PluginTemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathproject_setup.py
83 lines (64 loc) · 2.6 KB
/
project_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import re
import shutil
import stat
import subprocess
import json
cwd = os.path.dirname(os.path.abspath(__file__))
vcpkg_repo = "https://github.com/microsoft/vcpkg"
clibsf_repo = "https://github.com/Starfield-Reverse-Engineering/Starfield-RE-vcpkg"
process1 = subprocess.Popen(["git", "ls-remote", vcpkg_repo], stdout=subprocess.PIPE)
process2 = subprocess.Popen(["git", "ls-remote", clibsf_repo], stdout=subprocess.PIPE)
stdout, stderr = process1.communicate()
sha = re.split(r"\t+", stdout.decode("ascii"))[0]
vcpkg_sha = sha
stdout, stderr = process2.communicate()
sha = re.split(r"\t+", stdout.decode("ascii"))[0]
clibsf_sha = sha
def onexc(func, path, exc_info):
if not os.access(path, os.W_OK):
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise
if os.path.isdir(os.path.join(cwd, ".git")):
shutil.rmtree(os.path.join(cwd, ".git"), onexc=onexc)
if os.path.isdir(os.path.join(cwd, ".vs")):
shutil.rmtree(os.path.join(cwd, ".vs"), onexc=onexc)
os.remove(os.path.join(cwd, "README.md"))
project_name = input("Enter project name: ")
author = input("Enter author: ")
pattern = re.compile(r"(?<!^)(?=[A-Z])")
with open(os.path.join(cwd, "vcpkg.json"), "r", encoding="utf-8") as vcpkg_json_file:
vcpkg_json = json.load(vcpkg_json_file)
name = pattern.sub("-", project_name).lower()
vcpkg_json["name"] = name
vcpkg_json["version-semver"] = "1.0.0"
vcpkg_json["vcpkg-configuration"]["default-registry"]["baseline"] = vcpkg_sha
vcpkg_json["vcpkg-configuration"]["registries"][0]["baseline"] = clibsf_sha
with open(os.path.join(cwd, "vcpkg.json"), "w", encoding="utf-8") as vcpkg_json_file:
json.dump(vcpkg_json, vcpkg_json_file, indent=2)
with open(
os.path.join(cwd, "CMakeLists.txt"), "r", encoding="utf-8"
) as cmakelists_file:
cmakelists = cmakelists_file.read()
cmakelists = cmakelists.replace("PluginName", project_name)
cmakelists = cmakelists.replace("AuthorName", author)
cmakelists = cmakelists.replace("0.0.1", "1.0.0")
with open(
os.path.join(cwd, "CMakeLists.txt"), "w", encoding="utf-8"
) as cmakelists_file:
cmakelists_file.write(cmakelists)
os.rename(
os.path.join(cwd, "contrib", "Config", "PluginName.ini"),
os.path.join(cwd, "contrib", "Config", f"{project_name}.ini"),
)
with open(
os.path.join(cwd, "src", "Settings.cpp"), "r", encoding="utf-8"
) as settings_cpp_file:
settings_cpp = settings_cpp_file.read()
settings_cpp = settings_cpp.replace("PluginName.ini", f"{project_name}.ini")
with open(
os.path.join(cwd, "src", "Settings.cpp"), "w", encoding="utf-8"
) as settings_cpp_file:
settings_cpp_file.write(settings_cpp)