-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.py
More file actions
92 lines (79 loc) · 3.27 KB
/
build.py
File metadata and controls
92 lines (79 loc) · 3.27 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
82
83
84
85
86
87
88
89
90
91
92
# coding:UTF-8
# run in python3
# code by yzddMr6
import os
import sys
import base64
import time
import shutil
import subprocess
import platform
import re
# csc路径
cscpath = r'C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe'
pathsep = os.pathsep
distDir = "./dist/"
tempDir = "./temp/"
if os.path.exists(distDir):
shutil.rmtree(distDir)
if os.path.exists(tempDir):
shutil.rmtree(tempDir)
if not os.path.exists(tempDir):
os.mkdir(tempDir)
shutil.copytree("./template/", distDir)
codeDir = ['BASE', 'CMD', 'FM', 'DB']
for root, dirs, files in os.walk('.'):
for f in files:
for d in codeDir:
if d in root:
if f.endswith(".cs") and '_' in f:
print(
'------------------------------------------------------------')
spath = os.path.join(root, f)
print("before: "+spath)
with open(spath, "r", encoding="UTF-8") as sf:
source = sf.read()
#dist = re.sub(r"public\ class\ (.*)","public class Run", source) # 统一替换类名为Run
path = os.path.join(tempDir, f).replace("/", "\\")
with open(path, "w", encoding="UTF-8") as df:
df.write(source)
print("after: "+path)
targetdll = path.replace('.cs', '.dll')
cmd = '"{cscpath}" /optimize+ /target:library /out:{targetdll} {path} '.format(
cscpath=cscpath,
targetdll=targetdll,
path=path,
)
print("cmd: "+cmd)
p = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True
)
out, err = p.communicate()
print("err: "+err.decode())
if os.path.exists(targetdll):
with open(targetdll, 'rb') as dll:
content = dll.read()
res = str(base64.b64encode(content), "UTF-8")
packname = f.split("_")[0]
funcname = f.split("_")[1].split(".")[0]
if packname == "BASE":
distFile = "base.js"
elif packname == "CMD":
distFile = "command.js"
elif packname == "FM":
distFile = "filemanager.js"
elif packname == "DB":
distFile = "./database/" + \
funcname.lower()+".js"
funcname = "DATABASE"
dispath = os.path.join(distDir, distFile)
print("template: "+dispath)
with open(dispath, encoding="UTF-8") as disp:
result = disp.read().replace('###'+funcname+'###', res)
with open(dispath, mode="w", encoding="UTF-8") as disp:
disp.write(result)
else:
print("error")