From 8177c1d410f56098b6701107e112ca059f8e57fc Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 4 Apr 2006 19:22:43 +0000 Subject: [PATCH] Initialize our resource directory in the constructor so that clients that use the resource_dir system property can start loading resources based on that before they call initBundles(). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3999 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/resource/ResourceManager.java | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/java/com/threerings/resource/ResourceManager.java b/src/java/com/threerings/resource/ResourceManager.java index 0ed2069d4..1b4f436de 100644 --- a/src/java/com/threerings/resource/ResourceManager.java +++ b/src/java/com/threerings/resource/ResourceManager.java @@ -176,6 +176,9 @@ public class ResourceManager _rootPath = resourceRoot; _loader = loader; + // get our resource directory from resource_dir if possible + initResourceDir(null); + // set up a URL handler so that things can be loaded via urls // with the 'resource' protocol AccessController.doPrivileged(new PrivilegedAction() { @@ -210,20 +213,9 @@ public class ResourceManager String resourceDir, String configPath, InitObserver initObs) throws IOException { - // if the resource directory wasn't provided, we try to figure it - // out for ourselves - if (resourceDir == null) { - try { - // first look for the explicit system property - resourceDir = System.getProperty("resource_dir"); - // if that doesn't work, fall back to the current directory - if (resourceDir == null) { - resourceDir = System.getProperty("user.dir"); - } - - } catch (SecurityException se) { - resourceDir = File.separator; - } + // reinitialize our resource dir if it was specified + if (resourceDir != null) { + initResourceDir(resourceDir); } // check to see if we're in developer mode in which case we won't @@ -231,12 +223,6 @@ public class ResourceManager _unpack = !"true".equalsIgnoreCase( System.getProperty("no_unpack_resources")); - // make sure there's a trailing slash - if (!resourceDir.endsWith(File.separator)) { - resourceDir += File.separator; - } - _rdir = new File(resourceDir); - // load up our configuration Properties config = new Properties(); try { @@ -555,6 +541,29 @@ public class ResourceManager return (ResourceBundle[])_sets.get(name); } + protected void initResourceDir (String resourceDir) + { + if (resourceDir == null) { + try { + // first look for the explicit system property + resourceDir = System.getProperty("resource_dir"); + // if that doesn't work, fall back to the current directory + if (resourceDir == null) { + resourceDir = System.getProperty("user.dir"); + } + + } catch (SecurityException se) { + resourceDir = File.separator; + } + } + + // make sure there's a trailing slash + if (!resourceDir.endsWith(File.separator)) { + resourceDir += File.separator; + } + _rdir = new File(resourceDir); + } + /** * Loads up a resource set based on the supplied definition * information.