-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxmlFixer.py
142 lines (100 loc) · 3.63 KB
/
xmlFixer.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'''
WoT randomizer XML fixer written by KptKosmit91
does changes to Source XML files to work with the randomizer
update tool only - used for updating the randomizer for new WoT versions
'''
import xml.etree.ElementTree as ET
import xmlMethods as xml
from configLoader import Config as conf
import os
import fileMethods as fm
# maps = []
# def loadMaps():
# folder = conf.mapsPath
# for n in os.listdir(folder):
# if n.lower() != "_default_.xml" and n.lower() != "_list_.xml" and n.lower() != "hangar_v3.xml" and n.lower() != "1002_ai_test.xml":
# maps.append(folder+n)
# loadMaps()
# for m in maps:
# f = open(m, "r")
# mapName = m.replace(conf.mapsPath, "").replace(" ","")
# text=f.read()
# text = text.replace(mapName,"root")
# f.close()
# f = open(m, "w")
# f.write(text)
# f.close()
def getTankFilePaths():
tanks = []
for f in conf.countryFolders:
folder = conf.tanksPath+conf.countryFolders[f]+"/"
if os.path.exists(folder):
for n in os.listdir(folder):
if n.lower() != "components" and n.lower() != "customization.xml" and n.lower() != "list.xml":
tanks.append(folder+n)
folder = conf.tanksPath.replace("Source/", "SourceOverrides/")+conf.countryFolders[f]+"/"
if os.path.exists(folder):
for n in os.listdir(folder):
if n.lower() != "components" and n.lower() != "customization.xml" and n.lower() != "list.xml":
tanks.append(folder+n)
return tanks
def getCustomizationFilePaths():
files = []
folder = conf.customizationPath
# KK91: this code is stupid, i'm not gonna lie
if os.path.exists(folder):
for n in os.listdir(folder):
if n.endswith(".xml"):
files.append(folder + n)
else:
for n2 in os.listdir(folder + n):
if n2.endswith(".xml"):
files.append(folder + n + "/" + n2)
return files
def work(tank):
print(f"Post-processing {tank}")
tree = ET.parse(tank)
root = tree.getroot()
chassis = root.find("chassis").findall("*")
xml.insertElement(xml.IsWheeledTag, "false", root)
for c in chassis:
nonTrack = c.find("wheels").find("wheel").find("nonTrack")
if nonTrack != None and nonTrack.text.lower() == "true":
xml.insertElement(xml.IsWheeledTag, "true", root)
break
for t in root.find("turrets0").findall("*"):
for g in t.find("guns").findall("*"):
if xml.elementExists("multiGunEffects", g):
xml.insertElement(xml.IsDoubleGunTag, "true", g)
else:
xml.insertElement(xml.IsDoubleGunTag, "false", g)
newtree = ET.ElementTree(root)
newtree.write(tank)
print("Running Randomizer XML fixer")
print("\nWill fix tank XMLs. This may take a while")
tanks = getTankFilePaths()
print("Start Pre-processing")
for t in tanks:
print(f"Pre-processing {t}")
f = open(t, "r")
text=f.read()
text = text.replace(" ","").replace("<xmlns:xmlref>http://bwt/xmlref</xmlns:xmlref>","")
f.close()
f = open(t, "w")
f.write(text)
f.close()
print("\nStart Post-processing")
for t in tanks:
work(t)
customization = getCustomizationFilePaths()
print("\nStart Fixing Customization files")
for t in customization:
print(f"Fixing Customization file {t}")
f = open(t, "r")
text = f.read()
text = text.replace(" ", "").replace("<xmlns:xmlref>http://bwt/xmlref</xmlns:xmlref>", "")
f.close()
f = open(t, "w")
f.write(text)
f.close()
print("\nFixing files complete")