Moved the creation of the shutdown hook into the same static block that

creates the temp cache directory so that it is only registered once even
if multiple resource managers are created by the JVM (which happens in ant
builds).


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2544 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-05-05 18:02:37 +00:00
parent 56df0d29f5
commit 456dc57129
2 changed files with 11 additions and 13 deletions
@@ -1,5 +1,5 @@
//
// $Id: ResourceBundle.java,v 1.12 2003/04/28 18:21:47 mdb Exp $
// $Id: ResourceBundle.java,v 1.13 2003/05/05 18:02:37 mdb Exp $
package com.threerings.resource;
@@ -15,6 +15,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.samskivert.io.NestableIOException;
import com.samskivert.util.FileUtil;
import com.samskivert.util.StringUtil;
import org.apache.commons.io.StreamUtils;
@@ -238,5 +239,13 @@ public class ResourceBundle
Log.info("Creating narya temp cache directory '" + _tmpdir + "'.");
_tmpdir.mkdirs();
}
// add a hook to blow away the temp directory when we exit
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run () {
Log.info("Clearing narya temp cache '" + _tmpdir + "'.");
FileUtil.recursiveDelete(_tmpdir);
}
});
}
}
@@ -1,5 +1,5 @@
//
// $Id: ResourceManager.java,v 1.27 2003/05/03 00:51:13 ray Exp $
// $Id: ResourceManager.java,v 1.28 2003/05/05 18:02:37 mdb Exp $
package com.threerings.resource;
@@ -27,7 +27,6 @@ import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.MemoryCacheImageInputStream;
import com.samskivert.util.FileUtil;
import com.samskivert.util.StringUtil;
import com.threerings.resource.DownloadManager.DownloadDescriptor;
@@ -172,16 +171,6 @@ public class ResourceManager
"won't be able to create our cache directory " +
"either. [error=" + se + "].");
}
// Add a hook to blow away the temp directory when we exit
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run ()
{
File dir = ResourceBundle.getCacheDir();
Log.info("Deleting narya temp cache directory '" + dir + "'.");
FileUtil.recursiveDelete(dir);
}
});
}
/**