Commits

clach04 committed 3de89e8 Draft

start of class.

  • Participants
  • Parent commits 3611cb7

Comments (0)

Files changed (1)

     result = b2ui4(buf)
     return result
 
+class TreFile(object):
+    def __init__(self, tre_filename):
+        f = open(tre_filename, 'rb')
+        
+        # Longbow 2 MOVIES2.TRE file from cd2
+        buf = f.read(4)
+        assert buf == 'SKNK', "doesn't appear to be a Longbow2 TRE file. Got %r" % buf
+        buf = f.read(4)
+        assert buf == 'TREE', "doesn't appear to be a Longbow2 TRE file. Got %r" % buf
+        buf = f.read(4)
+        assert buf == '010A', "wrong version, possibly not a Longbow2 TRE file. Got %r" % buf
+        
+        num_files = read_ui4(f)
+        print repr(num_files)
+        print '%d files' % num_files
+        
+        header_size = read_ui4(f)
+        print '%d' % header_size
+        
+        start_offset = []
+        for x in range(num_files):
+            start_offset.append(read_ui4(f))
+        
+        size1 = []
+        for x in range(num_files):
+            size1.append(read_ui4(f))
+        
+        size2 = []
+        for x in range(num_files):
+            size2.append(read_ui4(f))
+        
+        zero_buf = []
+        for x in range(num_files):
+            zero_buf.append(read_ui4(f))
+        
+        print start_offset
+        print size1
+        print size2
+        print zero_buf
+        
+
+        filenames = []
+        for x in range(num_files):
+            filename = []
+            while 1:
+                b = f.read(1)
+                if b == '\x00':
+                    break
+                else:
+                    filename.append(b)
+            filename = ''.join(filename)
+            filename_list = filename.split('\\')  # Windows/DOS seperator
+            if filename_list[0] == '..':
+                del(filename_list[0])
+            top_f = filename_list[0]
+            bot_f = filename_list[1:]
+            filename = os.path.join(top_f, *bot_f)
+            filenames.append(filename)
+        print filenames
+        #buf = f.read(4096)
+        #print repr(buf)
+        
+        self.f = f
+
 def doit(tre_filename):
-    f = open(tre_filename, 'rb')
-    
-    # Longbow 2 MOVIES2.TRE file from cd2
-    buf = f.read(4)
-    assert buf == 'SKNK', "doesn't appear to be a Longbow2 TRE file. Got %r" % buf
-    buf = f.read(4)
-    assert buf == 'TREE', "doesn't appear to be a Longbow2 TRE file. Got %r" % buf
-    buf = f.read(4)
-    assert buf == '010A', "wrong version, possibly not a Longbow2 TRE file. Got %r" % buf
-    
-    num_files = read_ui4(f)
-    print repr(num_files)
-    print '%d files' % num_files
-    
-    header_size = read_ui4(f)
-    print '%d' % header_size
-    
-    start_offset = []
-    for x in range(num_files):
-        start_offset.append(read_ui4(f))
-    
-    size1 = []
-    for x in range(num_files):
-        size1.append(read_ui4(f))
-    
-    size2 = []
-    for x in range(num_files):
-        size2.append(read_ui4(f))
-    
-    zero_buf = []
-    for x in range(num_files):
-        zero_buf.append(read_ui4(f))
-    
-    print start_offset
-    print size1
-    print size2
-    print zero_buf
-    
-
-    filenames = []
-    for x in range(num_files):
-        filename = []
-        while 1:
-            b = f.read(1)
-            if b == '\x00':
-                break
-            else:
-                filename.append(b)
-        filename = ''.join(filename)
-        filename_list = filename.split('\\')  # Windows/DOS seperator
-        if filename_list[0] == '..':
-            del(filename_list[0])
-        top_f = filename_list[0]
-        bot_f = filename_list[1:]
-        filename = os.path.join(top_f, *bot_f)
-        filenames.append(filename)
-    print filenames
-    #buf = f.read(4096)
-    #print repr(buf)
-    
-    
-    f.close()
-
+    TreFile(tre_filename)
 
 def main(argv=None):
     if argv is None: