From 5414507e3afedb36d9e84c9bf3e530d6a21540f5 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 18 Jan 2003 19:56:45 +0000 Subject: [PATCH] Don't allow the resource bundles to attempt to access their resource jar files until they are known to be safely updated and ready to go. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2185 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/resource/ResourceBundle.java | 35 ++++++++++++++++--- .../threerings/resource/ResourceManager.java | 23 +++++++++++- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/java/com/threerings/resource/ResourceBundle.java b/src/java/com/threerings/resource/ResourceBundle.java index 19412418b..5ad6aaab0 100644 --- a/src/java/com/threerings/resource/ResourceBundle.java +++ b/src/java/com/threerings/resource/ResourceBundle.java @@ -1,5 +1,5 @@ // -// $Id: ResourceBundle.java,v 1.7 2003/01/14 02:51:40 mdb Exp $ +// $Id: ResourceBundle.java,v 1.8 2003/01/18 19:56:45 mdb Exp $ package com.threerings.resource; @@ -32,7 +32,6 @@ public class ResourceBundle public ResourceBundle (File source) { _source = source; - _sourceLastMod = source.lastModified(); } /** @@ -44,6 +43,16 @@ public class ResourceBundle return _source; } + /** + * Called by the resource manager once it has ensured that our + * resource jar file is up to date and ready for reading. + */ + public void sourceIsReady () + { + // make a note of our source's last modification time + _sourceLastMod = _source.lastModified(); + } + /** * Fetches the named resource from this bundle. The path should be * specified as a relative, platform independent path (forward @@ -79,7 +88,9 @@ public class ResourceBundle public File getResourceFile (String path) throws IOException { - resolveJarFile(); + if (resolveJarFile()) { + return null; + } // compute the path to our temporary file String tpath = StringUtil.md5hex(_source.getPath() + "%" + path); @@ -93,6 +104,7 @@ public class ResourceBundle // make sure said resource exists in the first place JarEntry entry = _jarSource.getJarEntry(path); if (entry == null) { +// Log.info("Couldn't locate " + path + " in " + _jarSource + "."); return null; } @@ -116,7 +128,9 @@ public class ResourceBundle public boolean containsResource (String path) { try { - resolveJarFile(); + if (resolveJarFile()) { + return false; + } return (_jarSource.getJarEntry(path) != null); } catch (IOException ioe) { return false; @@ -143,14 +157,25 @@ public class ResourceBundle * antics until and unless doing so is required, and because the * resource manager would like to be able to create bundles before the * associated files have been fully downloaded. + * + * @return true if the jar file could not yet be resolved because we + * haven't yet heard from the resource manager that it is ready for us + * to access, false if all is cool. */ - protected void resolveJarFile () + protected boolean resolveJarFile () throws IOException { + // if we don't yet have our resource bundle's last mod time, we + // have not yet been notified that it is ready + if (_sourceLastMod == 0) { + return true; + } + try { if (_jarSource == null) { _jarSource = new JarFile(_source); } + return false; } catch (IOException ioe) { throw new NestableIOException( diff --git a/src/java/com/threerings/resource/ResourceManager.java b/src/java/com/threerings/resource/ResourceManager.java index 32a426aed..90162cd28 100644 --- a/src/java/com/threerings/resource/ResourceManager.java +++ b/src/java/com/threerings/resource/ResourceManager.java @@ -1,5 +1,5 @@ // -// $Id: ResourceManager.java,v 1.20 2003/01/16 22:50:29 mdb Exp $ +// $Id: ResourceManager.java,v 1.21 2003/01/18 19:56:45 mdb Exp $ package com.threerings.resource; @@ -18,6 +18,7 @@ import java.net.URLConnection; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.StringTokenizer; @@ -249,6 +250,7 @@ public class ResourceManager // wake things up as the download is finished lock.notify(); } + bundlesDownloaded(); } } @@ -295,6 +297,9 @@ public class ResourceManager } public void downloadProgress (int percent, long remaining) { + if (percent == 100) { + bundlesDownloaded(); + } obs.downloadProgress(percent, remaining); } @@ -304,6 +309,22 @@ public class ResourceManager }); } + /** + * Called when our resource bundle downloads have completed. + */ + protected void bundlesDownloaded () + { + // let our bundles know that it's ok for them to access their + // resource files + Iterator iter = _sets.values().iterator(); + while (iter.hasNext()) { + ResourceBundle[] bundles = (ResourceBundle[])iter.next(); + for (int ii = 0; ii < bundles.length; ii++) { + bundles[ii].sourceIsReady(); + } + } + } + /** * Loads up the most recent version of the resource manager * configuration.