from os import listdir class ResourceFile(object): def __init__(fileName, buf=None): # Ooooh, what does this button do? # name(fileName) if buf: buffer = buf ownBuffer = False else: buffer = Buffer() ownBuffer = true try: with open(fileName, 'rb') as f: try: sign = f.read(4) if sign[0] != 'C' \ or sign[1] != 'R' \ or sign[2] != 'F' \ or sign[3]: raise IOError("Failover") major = f.unpack('i', 4) minor = f.unpack('i', 4) priority = f.unpack('i', 4) if major != 2 or minor < 0: raise Exception("Incompatible version of resource file '" + name + "'") except IOError: raise Exception("Invalid resource file '" + name + "'") # How to reproduce this? # int readed = stream.gcount(); except IOError: raise Exception("Error loading resource file '" + name + "'") class ResourcesCollection: def __init__(self, directories): self.__files = [] self.__buffer = None self.loadResourceFiles(directories) processFiles() def loadResourceFiles(self, directories): for directory in directories: try: for name in listdir(directory): if not name.startswith('.') and name.endswith('.res'): self.__files.append(ResourceFile(directory + '/' + name, self.__buffer)); except OSError: pass