Extract FileResourceBundle into a separate subclass and hide it away from the
rest of the world. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@312 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -29,27 +29,24 @@ import java.io.ObjectInputStream;
|
||||
import com.samskivert.io.StreamUtil;
|
||||
|
||||
import com.threerings.cast.Log;
|
||||
import com.threerings.resource.FileResourceBundle;
|
||||
import com.threerings.resource.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Utility functions related to creating and manipulating component
|
||||
* bundles.
|
||||
* Utility functions related to creating and manipulating component bundles.
|
||||
*/
|
||||
public class BundleUtil
|
||||
{
|
||||
/** The path in the metadata bundle to the serialized action table. */
|
||||
public static final String ACTIONS_PATH = "actions.dat";
|
||||
|
||||
/** The path in the metadata bundle to the serialized action tile sets
|
||||
* table. */
|
||||
/** The path in the metadata bundle to the serialized action tile sets table. */
|
||||
public static final String ACTION_SETS_PATH = "action_sets.dat";
|
||||
|
||||
/** The path in the metadata bundle to the serialized component class
|
||||
* table. */
|
||||
/** The path in the metadata bundle to the serialized component class table. */
|
||||
public static final String CLASSES_PATH = "classes.dat";
|
||||
|
||||
/** The path in the component bundle to the serialized component id to
|
||||
* class/type mapping. */
|
||||
/** The path in the component bundle to the serialized component id to class/type mapping. */
|
||||
public static final String COMPONENTS_PATH = "components.dat";
|
||||
|
||||
/** The file extension of our action tile images. */
|
||||
@@ -59,22 +56,19 @@ public class BundleUtil
|
||||
public static final String TILESET_EXTENSION = ".dat";
|
||||
|
||||
/**
|
||||
* Attempts to load an object from the supplied resource bundle with
|
||||
* the specified path.
|
||||
* Attempts to load an object from the supplied resource bundle with the specified path.
|
||||
*
|
||||
* @param wipeBundleOnFailure if there is an error reading the object
|
||||
* from the bundle and this parameter is true, we will instruct the
|
||||
* bundle to delete its underlying jar file before propagating the
|
||||
* exception with the expectation that it will be redownloaded and
|
||||
* repaired the next time the application is run.
|
||||
* @param wipeOnFailure if there is an error reading the object from the bundle and this
|
||||
* parameter is true, we will instruct the bundle to delete its underlying jar file before
|
||||
* propagating the exception with the expectation that it will be redownloaded and repaired the
|
||||
* next time the application is run.
|
||||
*
|
||||
* @return the unserialized object in question.
|
||||
*
|
||||
* @exception IOException thrown if an I/O error occurs while reading
|
||||
* the object from the bundle.
|
||||
* @exception IOException thrown if an I/O error occurs while reading the object from the
|
||||
* bundle.
|
||||
*/
|
||||
public static Object loadObject (ResourceBundle bundle, String path,
|
||||
boolean wipeBundleOnFailure)
|
||||
public static Object loadObject (ResourceBundle bundle, String path, boolean wipeOnFailure)
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
InputStream bin = null;
|
||||
@@ -86,20 +80,19 @@ public class BundleUtil
|
||||
return new ObjectInputStream(bin).readObject();
|
||||
|
||||
} catch (InvalidClassException ice) {
|
||||
Log.warning("Aiya! Serialized object is hosed " +
|
||||
"[bundle=" + bundle.getSource().getPath() +
|
||||
", element=" + path +
|
||||
", error=" + ice.getMessage() + "].");
|
||||
Log.warning("Aiya! Serialized object is hosed [bundle=" + bundle +
|
||||
", element=" + path + ", error=" + ice.getMessage() + "].");
|
||||
return null;
|
||||
|
||||
} catch (IOException ioe) {
|
||||
Log.warning("Error reading resource from bundle " +
|
||||
"[bundle=" + bundle + ", path=" + path +
|
||||
", wiping?=" + wipeBundleOnFailure + "].");
|
||||
if (wipeBundleOnFailure) {
|
||||
Log.warning("Error reading resource from bundle [bundle=" + bundle + ", path=" + path +
|
||||
", wiping?=" + wipeOnFailure + "].");
|
||||
if (wipeOnFailure) {
|
||||
StreamUtil.close(bin);
|
||||
bin = null;
|
||||
bundle.wipeBundle(false);
|
||||
if (bundle instanceof FileResourceBundle) {
|
||||
((FileResourceBundle)bundle).wipeBundle(false);
|
||||
}
|
||||
}
|
||||
throw ioe;
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.samskivert.util.IntIntMap;
|
||||
import com.samskivert.util.Predicate;
|
||||
import com.samskivert.util.Tuple;
|
||||
|
||||
import com.threerings.resource.FileResourceBundle;
|
||||
import com.threerings.resource.ResourceBundle;
|
||||
import com.threerings.resource.ResourceManager;
|
||||
|
||||
@@ -270,7 +271,7 @@ public class BundledComponentRepository
|
||||
// from interface ImageDataProvider
|
||||
public String getIdent ()
|
||||
{
|
||||
return "bcr:" + _bundle.getSource();
|
||||
return "bcr:" + _bundle.getIdent();
|
||||
}
|
||||
|
||||
// from interface ImageDataProvider
|
||||
@@ -331,8 +332,8 @@ public class BundledComponentRepository
|
||||
!StandardActions.SHADOW_TYPE.equals(type)) {
|
||||
Log.warning("Unable to locate tileset for action '" + imgpath + "' " +
|
||||
component + ".");
|
||||
if (_wipeOnFailure) {
|
||||
_bundle.wipeBundle(false);
|
||||
if (_wipeOnFailure && _bundle instanceof FileResourceBundle) {
|
||||
((FileResourceBundle)_bundle).wipeBundle(false);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -29,8 +29,9 @@ import java.util.Map;
|
||||
import com.samskivert.util.HashIntMap;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.resource.ResourceBundle;
|
||||
import com.threerings.cast.bundle.BundleUtil;
|
||||
import com.threerings.resource.FileResourceBundle;
|
||||
import com.threerings.resource.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Dumps the contents of a component bundle to stdout.
|
||||
@@ -48,7 +49,7 @@ public class DumpBundle
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
File file = new File(args[i]);
|
||||
try {
|
||||
ResourceBundle bundle = new ResourceBundle(file);
|
||||
ResourceBundle bundle = new FileResourceBundle(file);
|
||||
|
||||
HashMap actions = (HashMap)BundleUtil.loadObject(
|
||||
bundle, BundleUtil.ACTIONS_PATH, false);
|
||||
|
||||
Reference in New Issue
Block a user