Some tidying and commenting.

This commit is contained in:
Michael Bayne
2015-08-22 12:33:43 -07:00
parent 4edcdce102
commit c38ddc2305
3 changed files with 69 additions and 60 deletions
@@ -5,18 +5,8 @@
package com.threerings.getdown.data;
import com.samskivert.io.StreamUtil;
import com.samskivert.text.MessageUtil;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.RandomUtil;
import com.samskivert.util.RunAnywhere;
import com.samskivert.util.StringUtil;
import com.threerings.getdown.launcher.RotatingBackgrounds;
import com.threerings.getdown.util.*;
import org.apache.commons.codec.binary.Base64;
import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.Rectangle;
import java.io.*;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
@@ -29,11 +19,23 @@ import java.nio.channels.OverlappingFileLockException;
import java.security.*;
import java.security.cert.Certificate;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JApplet;
import com.samskivert.io.StreamUtil;
import com.samskivert.text.MessageUtil;
import com.samskivert.util.ArrayUtil;
import com.samskivert.util.RandomUtil;
import com.samskivert.util.RunAnywhere;
import com.samskivert.util.StringUtil;
import org.apache.commons.codec.binary.Base64;
import com.threerings.getdown.launcher.RotatingBackgrounds;
import com.threerings.getdown.util.*;
import static com.threerings.getdown.Log.log;
/**
@@ -594,8 +596,8 @@ public class Application
_txtJvmArgs.clear();
// parse our code resources
if (ConfigUtil.getMultiValue(cdata, "code") == null
&& ConfigUtil.getMultiValue(cdata, "ucode") == null) {
if (ConfigUtil.getMultiValue(cdata, "code") == null &&
ConfigUtil.getMultiValue(cdata, "ucode") == null) {
throw new IOException("m.missing_code");
}
parseResources(cdata, "code", false, _codes);
@@ -984,7 +986,7 @@ public class Application
for (String assignment : envvar) {
envAssignments.add(processArg(assignment));
}
for (Entry<String, String> environmentEntry : System.getenv().entrySet()) {
for (Map.Entry<String, String> environmentEntry : System.getenv().entrySet()) {
envAssignments.add(environmentEntry.getKey() + "=" + environmentEntry.getValue());
}
String[] envp = envAssignments.toArray(new String[envAssignments.size()]);
@@ -5,11 +5,6 @@
package com.threerings.getdown.data;
import com.samskivert.io.StreamUtil;
import com.samskivert.util.FileUtil;
import com.samskivert.util.StringUtil;
import com.threerings.getdown.util.ProgressObserver;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -22,6 +17,12 @@ import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.samskivert.io.StreamUtil;
import com.samskivert.util.StringUtil;
import com.threerings.getdown.util.FileUtil;
import com.threerings.getdown.util.ProgressObserver;
import static com.threerings.getdown.Log.log;
/**
@@ -37,17 +38,18 @@ public class Resource
_path = path;
_remote = remote;
_local = local;
_marker = new File(_local.getPath() + "v");
String lpath = _local.getPath();
_marker = new File(lpath + "v");
_unpack = unpack;
_isJar = _local.getPath().endsWith(".jar");
_isPacked200Jar = _local.getPath().endsWith(".jar.pack") || _local.getPath().endsWith(".jar.pack.gz");
if(_unpack && _isJar){
_isJar = lpath.endsWith(".jar");
_isPacked200Jar = (lpath.endsWith(".jar.pack") || lpath.endsWith(".jar.pack.gz"));
if (_unpack && _isJar) {
_unpacked = _local.getParentFile();
} else if(_unpack && _isPacked200Jar){
String jarExtension = ".jar";
_unpacked = new File(_local.getParent(),
_local.getName().substring(0, _local.getName().lastIndexOf(jarExtension) + jarExtension.length()));
} else if(_unpack && _isPacked200Jar) {
String dotJar = ".jar", lname = _local.getName();
String uname = lname.substring(0, lname.lastIndexOf(dotJar) + dotJar.length());
_unpacked = new File(_local.getParent(), uname);
}
}
@@ -68,21 +70,19 @@ public class Resource
}
/**
* Returns the location of the unpacked resource
* Returns the location of the unpacked resource.
*/
public File getUnpacked(){
public File getUnpacked ()
{
return _unpacked;
}
/**
* Returns the final target of this resource, wheter it has been unpacked or not
* Returns the final target of this resource, whether it has been unpacked or not.
*/
public File getFinalTarget(){
if(shouldUnpack()){
return getUnpacked();
} else{
return getLocal();
}
public File getFinalTarget ()
{
return shouldUnpack() ? getUnpacked() : getLocal();
}
/**
@@ -162,10 +162,10 @@ public class Resource
return false;
}
try {
if(_isJar){
if (_isJar) {
return FileUtil.unpackJar(new JarFile(_local), _unpacked);
} else{
return com.threerings.getdown.util.FileUtil.unpackPacked200Jar(_local, _unpacked);
return FileUtil.unpackPacked200Jar(_local, _unpacked);
}
} catch (IOException ioe) {
log.warning("Failed to create JarFile from '" + _local + "': " + ioe);
@@ -174,8 +174,8 @@ public class Resource
}
/**
* Wipes this resource file along with any "validated" marker file
* that may be associated with it.
* Wipes this resource file along with any "validated" marker file that may be associated with
* it.
*/
public void erase ()
{
@@ -5,8 +5,6 @@
package com.threerings.getdown.util;
import com.samskivert.io.StreamUtil;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
@@ -14,12 +12,14 @@ import java.util.jar.JarOutputStream;
import java.util.jar.Pack200;
import java.util.zip.GZIPInputStream;
import com.samskivert.io.StreamUtil;
import static com.threerings.getdown.Log.log;
/**
* File related utilities.
*/
public class FileUtil
public class FileUtil extends com.samskivert.util.FileUtil
{
/**
* Gets the specified source file to the specified destination file by hook or crook. Windows
@@ -94,27 +94,34 @@ public class FileUtil
return lines;
}
public static boolean unpackPacked200Jar(File packedJar, File target){
InputStream packedJarIs = null;
FileOutputStream extractedJarFileOs = null;
/**
* Unpacks a pack200 packed jar file from {@code packedJar} into {@code target}. If {@code
* packedJar} has a {@code .gz} extension, it will be gunzipped first.
*/
public static boolean unpackPacked200Jar (File packedJar, File target)
{
InputStream packedJarIn = null;
FileOutputStream extractedJarFileOut = null;
JarOutputStream jarOutputStream = null;
try{
extractedJarFileOs = new FileOutputStream(target);
jarOutputStream = new JarOutputStream(extractedJarFileOs);
packedJarIs = new FileInputStream(packedJar);
if(packedJar.getName().endsWith(".gz")){
packedJarIs = new GZIPInputStream(packedJarIs);
try {
extractedJarFileOut = new FileOutputStream(target);
jarOutputStream = new JarOutputStream(extractedJarFileOut);
packedJarIn = new FileInputStream(packedJar);
if (packedJar.getName().endsWith(".gz")) {
packedJarIn = new GZIPInputStream(packedJarIn);
}
Pack200.Unpacker unpacker = Pack200.newUnpacker();
unpacker.unpack(packedJarIs, jarOutputStream);
unpacker.unpack(packedJarIn, jarOutputStream);
return true;
} catch(IOException e){
} catch (IOException e) {
log.warning("Failed to unpack packed 200 jar file", "jar", packedJar, "error", e);
return false;
} finally {
StreamUtil.close(jarOutputStream);
StreamUtil.close(extractedJarFileOs);
StreamUtil.close(packedJarIs);
StreamUtil.close(extractedJarFileOut);
StreamUtil.close(packedJarIn);
}
}
}