8 print("usage: texrename <in_dir> <out_dir> [<crcmap_file>]")
13 mapfname
= "crcmap.txt"
15 mapfname
= sys
.argv
[3]
17 # catalog the original texture pack
19 imgexts
= frozenset(['.png', '.bmp', '.jpg', '.tga', '.gif'])
21 for root
, dirs
, files
in os
.walk(inpath
):
23 ffull
= os
.path
.join(root
, f
)
24 [fpath
, fname
] = os
.path
.split(f
)
25 ext
= os
.path
.splitext(fname
)[1].lower()
26 if fname
[0] == '.' or not (ext
in imgexts
):
30 if '#' in fname
: # rice pack format: "GAME NAME#hash#whatever"
31 crc
= int(fname
.split('#')[1], 16)
32 else: # just the crc probably
33 crc
= int(os
.path
.splitext(fname
)[0], 16)
35 print('unknown filename format: {0}'.format(ffull
))
39 print('error opening {0}: {1}'.format(inpath
, e
))
45 with
open(mapfname
, 'r') as f
:
48 if line
== '' or line
[0] == '#':
51 crcstr
= tok
[0].strip()
52 if crcstr
.startswith('0x'):
53 crc
= int(crcstr
[2:], 16)
56 crcmap
.append((crc
, os
.path
.join(outpath
, 'gfx', tok
[1].strip())))
58 print('could not open {0}: {1}'.format(mapfname
, e
))
59 except ValueError as e
:
60 print('invalid integer in {0}: {1}'.format(mapfname
, e
))
63 # copy the files to the correct locations
64 for (crc
, path
) in crcmap
:
65 if not (crc
in texmap
):
66 print('unmatched CRC: {0} ({1})'.format(crc
, path
))
68 [fpath
, fname
] = os
.path
.split(path
)
69 if not os
.path
.exists(fpath
):
71 shutil
.copy2(texmap
[crc
], path
)