-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
AAS.py
113 lines (102 loc) · 3.25 KB
/
AAS.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
import shutil
def MakeStaticStr():
fsrc = open("./Assets/AltAppSwitcherConfig.txt", "r")
if not os.path.exists("./Sources/Config/_Generated"):
os.makedirs("./Sources/Config/_Generated")
fdst = open("./Sources/Config/_Generated/ConfigStr.h", "w")
fdst.write("static const char ConfigStr[] =\n" )
for line in fsrc:
fdst.write("\"")
fdst.write(line.strip("\n").replace('"', r'\"'))
fdst.write(r"\n")
fdst.write("\"")
fdst.write("\n")
fdst.write(";")
def MakeDirIfNeeded(dir):
if not os.path.exists(dir):
os.makedirs(dir)
def Clean():
if os.path.exists("./Output"):
shutil.rmtree("./Output");
def CopyDirStructure(src, dst):
for x in os.listdir(src):
px = os.path.join(src, x)
if not os.path.isdir(px):
continue
dstpx = os.path.join(dst, x)
MakeDirIfNeeded(dstpx)
CopyDirStructure(px, dstpx)
def MakeDirs(conf, arch):
MakeDirIfNeeded("./Output")
MakeDirIfNeeded(f"./Output/{conf}_{arch}")
MakeDirIfNeeded(f"./Output/{conf}_{arch}/Objects")
MakeDirIfNeeded(f"./Output/{conf}_{arch}/AAS")
MakeDirIfNeeded(f"./Output/{conf}_{arch}/Installer")
MakeDirIfNeeded(f"./Output/{conf}_{arch}/Deploy")
CopyDirStructure("./Sources", f"./Output/{conf}_{arch}/Objects")
def Copy(src, dst):
if os.path.exists(dst):
os.remove(dst)
shutil.copy(src, dst)
def MakeCompileCommands(file, args):
outf = open(file, 'w')
outf.write("[\n")
for fname in args:
inf = open(fname, 'r')
content = inf.read()
# if last element removes ",\n"
if fname == args[-1]:
outf.write(content[0:-2])
else:
outf.write(content)
outf.write("\n]")
outf.close()
def EmbedAndDeleteManifest(exePath):
if not os.path.exists(f"{exePath}.manifest"):
return
os.system(f"mt.exe -manifest \"{exePath}.manifest\" -outputresource:\"{exePath}\"")
os.remove(f"{exePath}.manifest")
def MakeArchive(srcDir, dstZip):
tempDir = f"{dstZip}".replace(".zip", "")
if os.path.exists(tempDir):
shutil.rmtree(tempDir)
shutil.copytree(srcDir, tempDir)
for x in os.listdir(tempDir):
if x.endswith(".exe"):
EmbedAndDeleteManifest(os.path.join(tempDir, x))
shutil.make_archive(tempDir, "zip", tempDir)
shutil.rmtree(tempDir)
def BinToC(src, dst):
fi = open(src, 'rb')
fo = open(dst, 'w')
fo.write("const unsigned char AASZip[] = {")
i = 0
for byte in fi.read():
fo.write(f" {hex(byte)},")
i += 1
if i == 25:
i = 0
fo.write("\n")
fo.write("};\n")
fo.write("const unsigned int SizeOfAASZip = sizeof(AASZip);\n")
fo.close()
fi.close()
import sys
if __name__ == "__main__":
args = sys.argv[1:]
fn = args[0]
if fn == "Copy":
Copy(args[1], args[2])
elif fn == "MakeDirs":
MakeDirs(args[1], args[2])
elif fn == "Clean":
Clean()
elif fn == "MakeCompileCommands":
MakeCompileCommands(args[1], args[2:])
elif fn == "MakeArchive":
MakeArchive(args[1], args[2])
elif fn == "BinToC":
BinToC(args[1], args[2])
elif fn == "EmbedManifest":
EmbedAndDeleteManifest(args[1])