-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack.py
More file actions
81 lines (65 loc) · 2.94 KB
/
pack.py
File metadata and controls
81 lines (65 loc) · 2.94 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
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import sys
import shutil
import xml.etree.ElementTree as ET
addonName = "ImportantCasts"
def main(args):
AddonDesc = ""
with open("AddonDesc.(UIAddon).xdb", "r", encoding="UTF-8") as f:
AddonDesc = f.read()
# delete _out folder if exists
if os.path.exists(addonName):
shutil.rmtree(addonName)
os.makedirs(f"{addonName}/compiled")
AddonDesc = AddonDesc.replace("<Item href=\"src/", "<Item href=\"compiled/").replace(".lua", ".luac")
AddonDesc = AddonDesc.replace("settings.luac", "settings.lua")
AddonDesc = AddonDesc.replace("SampleAddonBase.luac", "SampleAddonBase.lua")
AddonDesc = AddonDesc.replace("compiled/mainscript.luac", "mainscript.luac")
# copy ./info folder to _out/info
shutil.copytree("info", f"{addonName}/info")
shutil.copytree("ClientTextures", f"{addonName}/ClientTextures")
shutil.copytree("UI", f"{addonName}/UI")
# copy from . to _out
extrafiles = [
"CustomIcons.(UIRelatedTextures).xdb",
"RelatedTextures.(UIRelatedTextures).xdb",
"settings.lua",
]
for file in extrafiles:
shutil.copy(file, f"{addonName}/{file}")
# write AddonDesc to _out/AddonDesc.(UIAddon).xdb
with open(f"{addonName}/AddonDesc.(UIAddon).xdb", "w", encoding="UTF-8") as f:
f.write(AddonDesc)
exceptions = ["settings.lua"]
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
if name.endswith(".lua") and name not in exceptions:
newPath = os.path.join(root, name[:-4]).replace('src', f'{addonName}\compiled') + ".luac"
newPath = os.path.abspath(newPath)
os.makedirs(os.path.dirname(newPath), exist_ok=True)
command = f"luajit.exe -b \"{os.path.abspath(os.path.join(root, name))}\" \"{newPath}\""
prev = os.getcwd()
os.chdir("C:\\AO\\tools\\compile\\x86")
os.system(command)
os.chdir(prev)
# move _out/compiled/mainscript.luac to _out/mainscript.luac
shutil.move(f"{addonName}/compiled/mainscript.luac", f"{addonName}/mainscript.luac")
# open /_out/info/name.txt and remove "Dev " from the first line
with open(f"{addonName}/info/name.txt", "r", encoding="UTF-16 LE") as f:
lines = f.readlines()
lines[0] = lines[0].replace("Dev ", "")
with open(f"{addonName}/info/name.txt", "w", encoding="UTF-16 LE") as f:
f.writelines(lines)
if os.path.exists("_pak/Mods/Addons"):
shutil.rmtree("_pak/Mods/Addons")
if os.path.exists(f"{addonName}.pak"):
os.remove(f"{addonName}.pak")
if os.path.exists(f"{addonName}.zip"):
os.remove(f"{addonName}.zip")
os.makedirs("_pak/Mods/Addons")
shutil.move(addonName, "_pak/Mods/Addons")
shutil.make_archive(addonName, 'zip', "_pak")
os.rename(f"{addonName}.zip", f"{addonName}.pak")
shutil.rmtree("_pak")
if __name__ == "__main__":
main(sys.argv[1:])