-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumper.py
65 lines (60 loc) · 2.36 KB
/
dumper.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
# SPDX-License-Identifier: WTFPL
import os
import glob
import bsp_tool # https://github.com/srcwr/bsp_tool
import gzip
import csv
from pathlib import Path
ignored = {}
with open("ignore.csv") as f:
for line in f:
stuff = line.split(",")
ignored[stuff[0]] = stuff[1]
ignored_pak = ignored.copy()
with open("ignore_pak.csv") as f:
for line in f:
stuff = line.split(",")
ignored_pak[stuff[0]] = stuff[1]
os.environ["EDITF"] = "ignore.csv"
for filename in glob.iglob("../hashed/*.bsp"):
maphash = Path(filename).stem
if maphash in ignored:
continue
newents = "entities/" + maphash + ".cfg"
if os.path.exists(f"entitiesgz/{maphash}.cfg.gz"): # should read dir once & check the dict tbh... don't care... i'd rather leave this comment instead...
continue
print(maphash)
os.environ["MAPHASH"] = maphash # used by my edits to bsp_tool to auto-add broken maps to ignore.csv...
bsp = bsp_tool.load_bsp(filename)
if "ENTITIES" in bsp.headers:
ents = bsp.ENTITIES.as_bytes()[:-1] # -1 to remove trailing null byte
with open(newents, "wb") as f:
f.write(ents)
with gzip.open(f"entitiesgz/{maphash}.cfg.gz", "wb") as f:
f.write(ents)
#break
os.environ["EDITF"] = "ignore_pak.csv"
for filename in glob.iglob("../hashed/*.bsp"):
maphash = Path(filename).stem
if maphash in ignored_pak and not ignored_pak[maphash].startswith("warning"):
continue
newents = "filelist/" + maphash + ".csv"
if os.path.exists(newents): # should read dir once & check the dict tbh... don't care... i'd rather leave this comment instead...
continue
print(maphash)
os.environ["MAPHASH"] = maphash # used by my edits to bsp_tool to auto-add broken maps to ignore_pak.csv...
bsp = bsp_tool.load_bsp(filename)
if "PAKFILE" in bsp.headers:
try:
files = bsp.PAKFILE.infolist()
except:
print(" error")
with open("ignore_pak.csv", "a") as f:
f.write(f"{maphash},error (no infolist)\n")
continue
#print(files)
with open(newents, "w", newline="", encoding="utf-8") as csvfile:
mycsv = csv.writer(csvfile)
mycsv.writerow(["filename","size","compressed"])
for x in files:
mycsv.writerow([x.filename, x.file_size, x.compress_size])