-
Notifications
You must be signed in to change notification settings - Fork 1
/
vtfunswapper.py
90 lines (60 loc) · 2.26 KB
/
vtfunswapper.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
"""
vtfunswapper.py
By DKY
Version 0.0.0
Given a VDF-formatted file mapping names to swapped names, this program undoes
the texture carnage caused by vtfswapper.py
"""
import os
import sys
import vdfutils
_DEFAULT_REMAP_FILE_NAME = 'vtfRemap.txt'
def un_rename_vtfs(remapDict):
""" Given a dictionary mapping original names to remapped names, this
function renames the files so that they are back to how they were
originally.
"""
def underscored(path):
''' Returns the name of the file at the given path, except with an
underscore prepended to the filename. The returned value is also a
full path to that file.
'''
fileName = os.path.basename(path)
fileDir = os.path.dirname(path)
return os.path.join(fileDir, '_{}'.format(fileName))
# Prepend all of the existing filenames with underscores, to prevent
# renaming conflicts.
for vtfPath in remapDict:
os.rename(vtfPath, underscored(vtfPath))
print "\t... Pass 1 complete."
# Rename all the files back to their original names.
for originalName, vtfPath in remapDict.iteritems():
os.rename(underscored(vtfPath), originalName)
print "\t... Pass 2 complete."
def main(argv):
try:
remapFileName = argv[1]
except IndexError:
print "No remap file provided. Trying '{}' by default...".format(
_DEFAULT_REMAP_FILE_NAME
)
remapFileName = _DEFAULT_REMAP_FILE_NAME
print "Reading file {}...".format(remapFileName)
here = os.getcwd()
remapFilePath = os.path.join(here, remapFileName)
try:
with open(remapFilePath, 'r') as f:
remapDict = vdfutils.parse_vdf(f.read())['remap']
except IOError:
sys.stderr.write(
"File {} not found! Aborting...\n".format(remapFileName)
)
return 1
print "Found {} remap entries.".format(len(remapDict))
print "Un-renaming VTF files..."
un_rename_vtfs(remapDict)
print "Done! Enjoy your un-FUBAR'd textures!"
raw_input("Press [ENTER] to continue...")
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))