diff --git a/src/java/com/threerings/resource/ResourceBundle.java b/src/java/com/threerings/resource/ResourceBundle.java index 62da0fc0..4e98655a 100644 --- a/src/java/com/threerings/resource/ResourceBundle.java +++ b/src/java/com/threerings/resource/ResourceBundle.java @@ -373,7 +373,7 @@ public class ResourceBundle _tmpdir = new File(tmpdir, "narcache_" + rando); if (!_tmpdir.exists()) { if (_tmpdir.mkdirs()) { - Log.info("Created narya temp cache directory '" + _tmpdir + "'."); + Log.debug("Created narya temp cache directory '" + _tmpdir + "'."); } else { Log.warning("Failed to create temp cache directory '" + _tmpdir + "'."); } diff --git a/src/java/com/threerings/resource/ResourceManager.java b/src/java/com/threerings/resource/ResourceManager.java index 6098f1b2..795a426f 100644 --- a/src/java/com/threerings/resource/ResourceManager.java +++ b/src/java/com/threerings/resource/ResourceManager.java @@ -52,29 +52,23 @@ import com.samskivert.util.ResultListener; import com.samskivert.util.StringUtil; /** - * The resource manager is responsible for maintaining a repository of - * resources that are synchronized with a remote source. This is - * accomplished in the form of sets of jar files (resource bundles) that - * contain resources and that are updated from a remote resource - * repository via HTTP. These resource bundles are organized into - * resource sets. A resource set contains one or more resource bundles and - * is defined much like a classpath. + * The resource manager is responsible for maintaining a repository of resources that are + * synchronized with a remote source. This is accomplished in the form of sets of jar files + * (resource bundles) that contain resources and that are updated from a remote resource repository + * via HTTP. These resource bundles are organized into resource sets. A resource set contains one + * or more resource bundles and is defined much like a classpath. * - *
The resource manager can load resources from the default resource - * set, and can make available named resource sets to entities that wish - * to do their own resource loading. If the resource manager fails to - * locate a resource in the default resource set, it falls back to loading - * the resource via the classloader (which will search the classpath). + *
The resource manager can load resources from the default resource set, and can make + * available named resource sets to entities that wish to do their own resource loading. If the + * resource manager fails to locate a resource in the default resource set, it falls back to + * loading the resource via the classloader (which will search the classpath). * - *
Applications that wish to make use of resource sets and their - * associated bundles must call {@link #initBundles} after constructing - * the resource manager, providing the path to a resource definition file - * which describes these resource sets. The definition file will be loaded - * and the resource bundles defined within will be loaded relative to the - * resource directory. The bundles will be cached in the user's home - * directory and only reloaded when the source resources have been - * updated. The resource definition file looks something like the - * following: + *
Applications that wish to make use of resource sets and their associated bundles must call + * {@link #initBundles} after constructing the resource manager, providing the path to a resource + * definition file which describes these resource sets. The definition file will be loaded and the + * resource bundles defined within will be loaded relative to the resource directory. The bundles + * will be cached in the user's home directory and only reloaded when the source resources have + * been updated. The resource definition file looks something like the following: * *
* resource.set.default = sets/misc/config.jar: \ @@ -89,39 +83,35 @@ import com.samskivert.util.StringUtil; * /global/resources/sounds/music.jar ** - *
All resource set definitions are prefixed with
- * resource.set. and all text following that string is
- * considered to be the name of the resource set. The resource set named
- * default is the default resource set and is the one that is
- * searched for resources is a call to {@link #getResource}.
+ *
All resource set definitions are prefixed with resource.set. and all text
+ * following that string is considered to be the name of the resource set. The resource set named
+ * default is the default resource set and is the one that is searched for resources
+ * is a call to {@link #getResource}.
*
- *
When a resource is loaded from a resource set, the set is searched - * in the order that entries are specified in the definition. + *
When a resource is loaded from a resource set, the set is searched in the order that entries
+ * are specified in the definition.
*/
public class ResourceManager
{
/**
- * Provides facilities for notifying an observer of the resource
- * unpacking process.
+ * Provides facilities for notifying an observer of the resource unpacking process.
*/
public interface InitObserver
{
/**
- * Indicates a percent completion along with an estimated time
- * remaining in seconds.
+ * Indicates a percent completion along with an estimated time remaining in seconds.
*/
public void progress (int percent, long remaining);
/**
- * Indicates that there was a failure unpacking our resource
- * bundles.
+ * Indicates that there was a failure unpacking our resource bundles.
*/
public void initializationFailed (Exception e);
}
/**
- * An adapter that wraps an {@link InitObserver} and routes all method
- * invocations to the AWT thread.
+ * An adapter that wraps an {@link InitObserver} and routes all method invocations to the AWT
+ * thread.
*/
public static class AWTInitObserver implements InitObserver
{
@@ -149,17 +139,15 @@ public class ResourceManager
}
/**
- * Constructs a resource manager which will load resources via the
- * classloader, prepending resourceRoot to their path.
+ * Constructs a resource manager which will load resources via the classloader, prepending
+ * resourceRoot to their path.
*
- * @param resourceRoot the path to prepend to resource paths prior to
- * attempting to load them via the classloader. When resources are
- * bundled into the default resource bundle, they don't need this
- * prefix, but if they're to be loaded from the classpath, it's likely
- * that they'll live in some sort of resources directory
- * to isolate them from the rest of the files in the classpath. This
- * is not a platform dependent path (forward slash is always used to
- * separate path elements).
+ * @param resourceRoot the path to prepend to resource paths prior to attempting to load them
+ * via the classloader. When resources are bundled into the default resource bundle, they don't
+ * need this prefix, but if they're to be loaded from the classpath, it's likely that they'll
+ * live in some sort of resources directory to isolate them from the rest of the
+ * files in the classpath. This is not a platform dependent path (forward slash is always used
+ * to separate path elements).
*/
public ResourceManager (String resourceRoot)
{
@@ -178,9 +166,16 @@ public class ResourceManager
// 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
+ /**
+ * Registers a protocol handler with URL to handle resource: URLs. The URLs take
+ * the form:
resource://bundle_name/resource_pathResources from the default bundle + * can be loaded via:
resource:///resource_path+ */ + public void activateResourceProtocol () + { + // set up a URL handler so that things can be loaded via urls with the 'resource' protocol try { AccessController.doPrivileged(new PrivilegedAction() { public Object run () { @@ -201,6 +196,16 @@ public class ResourceManager _localePrefix = prefix; } + /** + * Configures whether we unpack our resource bundles or not. This must be called before {@link + * #initBundles}. One can also pass the
-Dno_unpack_resources=true system property
+ * to disable resource unpacking.
+ */
+ public void setUnpackResources (boolean unpackResources)
+ {
+ _unpack = unpackResources;
+ }
+
/**
* Initializes the bundle sets to be made available by this resource
* manager. Applications that wish to make use of resource bundles
@@ -221,8 +226,7 @@ public class ResourceManager
* @exception IOException thrown if we are unable to read our resource
* manager configuration.
*/
- public void initBundles (
- String resourceDir, String configPath, InitObserver initObs)
+ public void initBundles (String resourceDir, String configPath, InitObserver initObs)
throws IOException
{
// reinitialize our resource dir if it was specified
@@ -230,11 +234,6 @@ public class ResourceManager
initResourceDir(resourceDir);
}
- // check to see if we're in developer mode in which case we won't
- // unpack our resources
- _unpack = !"true".equalsIgnoreCase(
- System.getProperty("no_unpack_resources"));
-
// load up our configuration
Properties config = new Properties();
try {
@@ -331,8 +330,7 @@ public class ResourceManager
public boolean checkBundle (String path)
{
File bfile = getResourceFile(path);
- return (bfile == null) ? false :
- new ResourceBundle(bfile, true, _unpack).isUnpacked();
+ return (bfile == null) ? false : new ResourceBundle(bfile, true, _unpack).isUnpacked();
}
/**
@@ -667,8 +665,7 @@ public class ResourceManager
while (tok.hasMoreTokens()) {
String path = tok.nextToken().trim();
- ResourceBundle bundle =
- new ResourceBundle(getResourceFile(path), true, _unpack);
+ ResourceBundle bundle = new ResourceBundle(getResourceFile(path), true, _unpack);
set.add(bundle);
if (bundle.isUnpacked() && bundle.sourceIsReady()) {
continue;
@@ -740,7 +737,7 @@ public class ResourceManager
protected String _rootPath;
/** Whether or not to unpack our resource bundles. */
- protected boolean _unpack;
+ protected boolean _unpack = Boolean.getBoolean("no_unpack_resources");
/** Our default resource set. */
protected ResourceBundle[] _default = new ResourceBundle[0];