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
This commit is contained in:
Michael Bayne
2006-04-04 19:22:43 +00:00
parent ead3a989b2
commit 8177c1d410
@@ -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.