2003/09/28 00:43:30
[org.ibex.core.git] / src / org / xwt / translators / MSPack.java
diff --git a/src/org/xwt/translators/MSPack.java b/src/org/xwt/translators/MSPack.java
new file mode 100644 (file)
index 0000000..00316de
--- /dev/null
@@ -0,0 +1,40 @@
+package org.xwt.translators;
+import org.xwt.*;
+import org.xwt.util.*;
+import java.io.*;
+import java.util.zip.*;
+
+public class MSPack {
+
+    MSPack() { }
+
+    private static org.xwt.mips.Interpreter vm = null;
+
+    public static synchronized void unpack(InputStream theCabFile) {
+        try {           
+            if (vm == null) {
+                InputStream bis = Platform.getBuiltinInputStream();
+                ZipInputStream zis = new ZipInputStream(bis);
+                for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("libmspack.mips"); ze = zis.getNextEntry()) { }
+                byte[] image = InputStreamToByteArray.convert(zis);
+                vm = new org.xwt.mips.Interpreter(image);
+                vm.start(new String[]{ "libmspack.mips" });
+                vm.execute();
+            }
+
+            int CAB_RESERVED = 256*1024;
+            int baseAddr = vm.sbrk(CAB_RESERVED);
+            
+            byte[] cabstream = InputStreamToByteArray.convert(theCabFile);
+            vm.copyout(cabstream, baseAddr, cabstream.length);
+            vm.setUserInfo(0, baseAddr);
+            vm.setUserInfo(1, cabstream.length);
+            
+            vm.execute();
+            // FIXME: do more stuff here
+
+        } catch (Exception e) {
+            Log.log(MSPack.class, e);
+        }
+    }
+}