6 class WadException(Exception):
11 wadinfo_size = calcsize (wadinfo_t)
13 filelump_size = calcsize (filelump_t)
19 for (handle, pos, size, name) in self.lumps:
23 def AddFile(self, filename):
24 (base, ext) = os.path.splitext (filename)
25 fileHandle = open (filename, 'rb')
28 if ext.lower() == '.wad':
30 (id, numLumps, infoTable) = unpack (wad.wadinfo_t, fileHandle.read(wad.wadinfo_size))
32 if id != 'IWAD' and id != 'PWAD':
33 raise WadException("Wad file %s doesn't have IWAD or PWAD id" % filename)
35 fileHandle.seek (infoTable)
37 for i in range (0, numLumps):
38 lumpinfo.append (unpack (wad.filelump_t, fileHandle.read(wad.filelump_size)))
40 # single file, boring.
41 size = os.stat (filename).st_size
42 lumpinfo.append ((0, size, base.upper()[:8]))
44 # Dump the info into our table of accumulated crap.
45 for (start, len, name) in lumpinfo:
46 self.lumps.append ((fileHandle, start, len, name))
48 def InitMultipleFiles (self, filenames):
52 def InitFile (self, filename):
56 return len (self.lumps)
58 def CheckNumForName (self, name):
59 # meh sucky in-place crappy way to do
61 searchName = name.upper()[:8]
62 searchLumps = [x for (x, y, z, w) in self.lumps]
66 lumpIndex = searchLumps.index(searchName)
71 def GetNumForName (self, name):
72 return self.CheckNumForName (name)
74 def LumpLength (self, lump):
75 (handle, start, len, name) = self.lumps[lump]
78 def ReadLump (self, lump, dest):
79 (handle, start, len, name) = self.lumps[lump]
81 dest.write (handle.read (len))
83 def CacheLumpNum (self, lump, tag):
86 def CacheLumpName (self, name, tag):
87 return self.CacheLumpNum (self.GetNumForName (name), tag)