X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FRes.java;h=b9569315257c8925d7c380a0edc76fac0c850fbb;hb=38786988d12f2c48a314ee37c326965ff0bcadb6;hp=f0b25bf9c6eee37c3493f4f0395b62b8916df050;hpb=55c3195af733f3de6b7894f4c4a96f7b50f58c11;p=org.ibex.core.git diff --git a/src/org/xwt/Res.java b/src/org/xwt/Res.java index f0b25bf..b956931 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Res.java @@ -14,7 +14,17 @@ public abstract class Res extends JS { public final InputStream getInputStream() throws IOException { return getInputStream(""); } public Res graft(Object newResource) { throw new JS.Exn("cannot graft onto this resource"); } - public Object get(Object key) { return new Ref(this, key); } + + private Hash refCache = null; + public Object get(Object key) { + Object ret = refCache == null ? null : refCache.get(key); + if (ret != null) return ret; + ret = new Ref(this, key); + if (refCache == null) refCache = new Hash(); + refCache.put(key, ret); + return ret; + } + public void put(Object key, Object val) { throw new JS.Exn("cannot put to a resource"); } public Object[] keys() { throw new JS.Exn("cannot enumerate a resource"); } @@ -103,15 +113,22 @@ public abstract class Res extends JS { return ((i & 0xff) << 24) | ((i & 0xff00) << 8) | ((i & 0xff0000) >>> 8) | (i >>> 24); } public InputStream getInputStream(String path) throws IOException { - InputStream is = new InputStream(parent.getInputStream()); + InputStream is = parent.getInputStream(); byte[] scan = new byte[4]; - while(scan[0] != 'M' || scan[1] != 'S' || scan[2] != 'C' || scan[3] != 'F') { - System.arraycopy(scan, 1, scan, 0, 3); - int read = is.read(); - if (read == -1) throw new JS.Exn("MSCF header tag not found in file"); - scan[3] = (byte)read; + int ofs = 0; + for(int i=0; i<2; i++) { + // wierdly, .exe files have three MSCF's + while(scan[0] != 'M' || scan[1] != 'S' || scan[2] != 'C' || scan[3] != 'F') { + System.arraycopy(scan, 1, scan, 0, 3); + int read = is.read(); + if (read == -1) throw new JS.Exn("MSCF header tag not found in file"); + scan[3] = (byte)read; + ofs++; + } + scan[0] = 0; } - return org.xwt.util.CAB.getFileInputStream(is, path); + Log.log(this, "found MSCF header at offset " + ofs); + return org.xwt.util.CAB.getFileInputStream(is, path, true); } }