-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUpdateLookup.py
More file actions
executable file
·149 lines (120 loc) · 4.31 KB
/
UpdateLookup.py
File metadata and controls
executable file
·149 lines (120 loc) · 4.31 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
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
143
144
145
146
147
148
149
from pathlib import Path
import os
import re
import sys
LookupFile = "./lookup.csv"
ModToolsPath = "/mnt/hdd1/BF2_ModTools"
namelist = set()
def AddToList(item):
# strip first
item = item.strip()
# ignore template project stuff and comments
if item and not item.startswith('@') and not item.startswith("--") and not item.startswith("//") and not item.startswith(r"\\") and not item.startswith("#"):
# Neither the hash function, nor windows, nor the game
# cares about case sensitivity. So lowercase just everything
# to avoid case sensitive duplicates
namelist.add(item.lower())
# read current list, so we can actually add stuff manually to the
# lookup file that doesn't get deleted once this script is run
if Path(LookupFile).is_file():
for i, line in enumerate(open(LookupFile)):
AddToList(line)
# Grab all ODF file names without extension and additionally
# crawl them for property names
propertyReg = re.compile(r"^(\w*)\s*=\s*.*$")
count = 0
count2 = 0
for path in Path(ModToolsPath).rglob("*.odf"):
name = os.path.basename(path).replace(".odf", "")
AddToList(name)
count += 1
try:
for i, line in enumerate(open(path)):
for match in propertyReg.finditer(line):
found = match.group(1)
AddToList(match.group(1))
count2 += 1
except Exception as e:
print(f"Error for '{path}': {e}")
print("Found %d ODF files" % count)
print("Found %d Property Names in ODF files" % count2)
# Grab all req files and extract strings
count = 0
count2 = 0
stringReg = re.compile(r"\"(.*)\"")
for path in Path(ModToolsPath).rglob("*.req"):
name = os.path.basename(path).replace(".req", "")
AddToList(name)
count += 1
try:
for i, line in enumerate(open(path)):
for match in stringReg.finditer(line):
AddToList(match.group(1))
count2 += 1
except Exception as e:
print(f"Error for '{path}': {e}")
print("Found %d REQ files" % count)
print("Found %d strings in REQ files" % count2)
# Grab all MSH files in assets\Animations without extension
count = 0
for path in Path(ModToolsPath + "\\assets\\Animations").rglob("*.msh"):
name = os.path.basename(path).replace(".msh", "")
AddToList(name)
count += 1
print("Found %d Animation MSH files" % count)
# Grab all .snd files and extract names from Name() and Sample() declarations
nameReg = re.compile(r"Name\(\"(.*)\"\)")
sampleReg = re.compile(r"Sample\(\"(.*)\"")
count = 0
count2 = 0
for path in Path(ModToolsPath).rglob("*.snd"):
name = os.path.basename(path).replace(".snd", "")
AddToList(name)
count += 1
try:
for i, line in enumerate(open(path)):
for match in nameReg.finditer(line):
AddToList(match.group(1))
count2 += 1
for match in sampleReg.finditer(line):
AddToList(match.group(1))
count2 += 1
except Exception as e:
print(f"Error for '{path}': {e}")
print("Found %d SND files" % count)
print("Found %d Names and Samples in SND files" % count2)
# Grab all wld (world) files
count = 0
for path in Path(ModToolsPath).rglob("*.wld"):
name = os.path.basename(path).replace(".wld", "")
AddToList(name)
count += 1
print("Found %d WLD files" % count)
# Grab all lyr (world layer) files
count = 0
for path in Path(ModToolsPath).rglob("*.lyr"):
name = os.path.basename(path).replace(".lyr", "")
AddToList(name)
count += 1
print("Found %d LYR files" % count)
# Grab all .ldx files and extract names from Layer() and GameMode() declarations
layerReg = re.compile(r"Layer\(\"(.*)\"")
gameModeReg = re.compile(r"GameMode\(\"(.*)\"")
count = 0
for path in Path(ModToolsPath).rglob("*.ldx"):
try:
for i, line in enumerate(open(path)):
for match in layerReg.finditer(line):
AddToList(match.group(1))
count += 1
for match in gameModeReg.finditer(line):
AddToList(match.group(1))
count += 1
except Exception as e:
print(f"Error for '{path}': {e}")
print("Found %d Layer and GameMode Names in LDX files" % count)
file = open(LookupFile, "w")
namelist = sorted(namelist, key=lambda s: s.lower())
for name in namelist:
file.write(name + "\n")
file.close()