-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_workshop.py
More file actions
68 lines (49 loc) · 2.04 KB
/
build_workshop.py
File metadata and controls
68 lines (49 loc) · 2.04 KB
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
"""
Builds an instance of the mod locally in the workshop folder
mainly for network testing, does NOT upload the build to the workshop
"""
import os
import shutil
import winreg
ROOT: str = os.getcwd()
BUILD_FOLDER: str = os.path.join(ROOT, "Build")
def get_workshop_path() -> str:
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Valve\\Steam")
value, type = winreg.QueryValueEx(key, "InstallPath")
workshop_path = os.path.join(value, "steamapps", "workshop", "content", "301650")
if not os.path.exists(workshop_path):
raise RuntimeError("Couldn't find steam directory, do you have steam installed?")
except Exception as e:
print(f"An error occured: {e}")
return workshop_path
def set_local_dll_path(reloaded_path) -> None:
reloaded = os.path.join(reloaded_path, "reloaded.lua")
with open(reloaded, 'r+') as f:
lines = f.readlines()
f.seek(0)
f.truncate()
for line in lines:
f.write(line)
if line.strip() == 'RequireFix.Initialize("3522264415")':
f.write('\n')
f.write("-- Code generated by workshop build script, sets local module search path\n")
f.write('RequireFix.Initialize("reloaded")\n')
def build_workshop() -> None:
if not os.path.exists(BUILD_FOLDER):
raise FileNotFoundError("Couldn't find workshop build folder, make sure to run squish first")
workshop_path: str = get_workshop_path()
reloaded_path = os.path.join(workshop_path, "reloaded")
if os.path.exists(reloaded_path):
shutil.rmtree(reloaded_path)
os.mkdir(reloaded_path)
for path, _, files in os.walk(BUILD_FOLDER):
for file in files:
shutil.copyfile(os.path.join(path, file), os.path.join(reloaded_path, file))
set_local_dll_path(reloaded_path)
print(f"Built workshop at {reloaded_path}")
if __name__ == "__main__":
try:
build_workshop()
except Exception as e:
print(f"An error occurred: {e}")