Mo' better progress. Code and media resource validation partially in
place. Next up the download manager.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Application.java,v 1.2 2004/07/02 15:22:49 mdb Exp $
|
// $Id: Application.java,v 1.3 2004/07/02 17:03:33 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.getdown.data;
|
package com.threerings.getdown.data;
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ import java.security.MessageDigest;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.samskivert.io.NestableIOException;
|
import com.samskivert.io.NestableIOException;
|
||||||
@@ -193,14 +194,6 @@ public class Application
|
|||||||
_appargs.add(appargs[ii]);
|
_appargs.add(appargs[ii]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log.info("Parsed application " + _appbase);
|
|
||||||
// Log.info("Version: " + _version);
|
|
||||||
// Log.info("Class: " + _class);
|
|
||||||
// Log.info("Code: " + StringUtil.toString(_codes.iterator()));
|
|
||||||
// Log.info("Resources: " + StringUtil.toString(_resources.iterator()));
|
|
||||||
// Log.info("JVM Args: " + StringUtil.toString(_jvmargs.iterator()));
|
|
||||||
// Log.info("App Args: " + StringUtil.toString(_appargs.iterator()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,6 +231,14 @@ public class Application
|
|||||||
public boolean verifyMetadata ()
|
public boolean verifyMetadata ()
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
Log.info("Verifying application: " + _appbase);
|
||||||
|
Log.info("Version: " + _version);
|
||||||
|
Log.info("Class: " + _class);
|
||||||
|
// Log.info("Code: " + StringUtil.toString(_codes.iterator()));
|
||||||
|
// Log.info("Resources: " + StringUtil.toString(_resources.iterator()));
|
||||||
|
// Log.info("JVM Args: " + StringUtil.toString(_jvmargs.iterator()));
|
||||||
|
// Log.info("App Args: " + StringUtil.toString(_appargs.iterator()));
|
||||||
|
|
||||||
// create our digester which will read in the contents of the
|
// create our digester which will read in the contents of the
|
||||||
// digest file and validate itself
|
// digest file and validate itself
|
||||||
try {
|
try {
|
||||||
@@ -293,6 +294,45 @@ public class Application
|
|||||||
return _version != _targetVersion;
|
return _version != _targetVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies the code and media resources associated with this
|
||||||
|
* application. A list of resources that do not exist or fail the
|
||||||
|
* verification process will be returned. If all resources are ready
|
||||||
|
* to go, null will be returned and the application is considered
|
||||||
|
* ready to run.
|
||||||
|
*/
|
||||||
|
public List verifyResources ()
|
||||||
|
{
|
||||||
|
ArrayList failures = new ArrayList();
|
||||||
|
verifyResources(_codes.iterator(), failures);
|
||||||
|
verifyResources(_resources.iterator(), failures);
|
||||||
|
return (failures.size() == 0) ? null : failures;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A helper function used by {@link #verifyResources()}. */
|
||||||
|
protected void verifyResources (Iterator rsrcs, List failures)
|
||||||
|
{
|
||||||
|
while (rsrcs.hasNext()) {
|
||||||
|
Resource rsrc = (Resource)rsrcs.next();
|
||||||
|
if (rsrc.isMarkedValid()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (_digest.validateResource(rsrc)) {
|
||||||
|
// make a note that this file is kosher
|
||||||
|
rsrc.markAsValid();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.info("Failure validating resource [rsrc=" + rsrc +
|
||||||
|
", error=" + e + "]. Requesting redownload...");
|
||||||
|
}
|
||||||
|
failures.add(rsrc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads a new copy of the specified control file and, if the
|
* Downloads a new copy of the specified control file and, if the
|
||||||
* download is successful, moves it over the old file on the
|
* download is successful, moves it over the old file on the
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Resource.java,v 1.2 2004/07/02 15:22:49 mdb Exp $
|
// $Id: Resource.java,v 1.3 2004/07/02 17:03:33 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.getdown.data;
|
package com.threerings.getdown.data;
|
||||||
|
|
||||||
@@ -9,11 +9,12 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
|
import com.threerings.getdown.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Models a single file resource used by an {@link Application}.
|
* Models a single file resource used by an {@link Application}.
|
||||||
*/
|
*/
|
||||||
@@ -27,6 +28,7 @@ public class Resource
|
|||||||
_path = path;
|
_path = path;
|
||||||
_remote = remote;
|
_remote = remote;
|
||||||
_local = local;
|
_local = local;
|
||||||
|
_marker = new File(_local.getPath() + "v");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,19 +56,65 @@ public class Resource
|
|||||||
return StringUtil.hexlate(md.digest());
|
return StringUtil.hexlate(md.digest());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this resource has an associated "validated" marker
|
||||||
|
* file.
|
||||||
|
*/
|
||||||
|
public boolean isMarkedValid ()
|
||||||
|
{
|
||||||
|
return _marker.exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a "validated" marker file for this resource to indicate
|
||||||
|
* that its MD5 hash has been computed and compared with the value in
|
||||||
|
* the digest file.
|
||||||
|
*
|
||||||
|
* @throws IOException if we fail to create the marker file.
|
||||||
|
*/
|
||||||
|
public void markAsValid ()
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
_marker.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes any "validated" marker file associated with this resource.
|
||||||
|
*/
|
||||||
|
public void clearMarker ()
|
||||||
|
{
|
||||||
|
if (_marker.exists()) {
|
||||||
|
if (!_marker.delete()) {
|
||||||
|
Log.warning("Failed to erase marker file '" + _marker + "'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wipes this resource file along with any "validated" marker file
|
||||||
|
* that may be associated with it.
|
||||||
|
*/
|
||||||
|
public void erase ()
|
||||||
|
{
|
||||||
|
clearMarker();
|
||||||
|
if (_local.exists()) {
|
||||||
|
if (!_local.delete()) {
|
||||||
|
Log.warning("Failed to erase resource '" + _local + "'.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string representation of this instance.
|
* Returns a string representation of this instance.
|
||||||
*/
|
*/
|
||||||
public String toString ()
|
public String toString ()
|
||||||
{
|
{
|
||||||
// return _path;
|
return _path;
|
||||||
// return _netloc.toString();
|
|
||||||
return _local.getPath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String _path;
|
protected String _path;
|
||||||
protected URL _remote;
|
protected URL _remote;
|
||||||
protected File _local;
|
protected File _local, _marker;
|
||||||
|
|
||||||
protected final static int DIGEST_BUFFER_SIZE = 5 * 1025;
|
protected final static int DIGEST_BUFFER_SIZE = 5 * 1025;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
//
|
//
|
||||||
// $Id: Getdown.java,v 1.2 2004/07/02 15:22:49 mdb Exp $
|
// $Id: Getdown.java,v 1.3 2004/07/02 17:03:33 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.getdown.launcher;
|
package com.threerings.getdown.launcher;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.io.TeeOutputStream;
|
||||||
|
|
||||||
import com.threerings.getdown.Log;
|
import com.threerings.getdown.Log;
|
||||||
import com.threerings.getdown.data.Application;
|
import com.threerings.getdown.data.Application;
|
||||||
@@ -26,8 +33,15 @@ public class Getdown
|
|||||||
|
|
||||||
if (_app.verifyMetadata()) {
|
if (_app.verifyMetadata()) {
|
||||||
Log.info("Application requires update.");
|
Log.info("Application requires update.");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.info("Metadata verified.");
|
Log.info("Metadata verified.");
|
||||||
|
List failures = _app.verifyResources();
|
||||||
|
if (failures == null) {
|
||||||
|
Log.info("Resources verified.");
|
||||||
|
} else {
|
||||||
|
Log.info(failures.size() + " resources require update.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -50,6 +64,18 @@ public class Getdown
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // tee our output into a file in the application directory
|
||||||
|
// File log = new File(appDir, "getdown.log");
|
||||||
|
// try {
|
||||||
|
// FileOutputStream fout = new FileOutputStream(log);
|
||||||
|
// System.setOut(new PrintStream(
|
||||||
|
// new TeeOutputStream(System.out, fout)));
|
||||||
|
// System.setErr(new PrintStream(
|
||||||
|
// new TeeOutputStream(System.err, fout)));
|
||||||
|
// } catch (IOException ioe) {
|
||||||
|
// Log.warning("Unable to redirect output to '" + log + "': " + ioe);
|
||||||
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Getdown app = new Getdown(appDir);
|
Getdown app = new Getdown(appDir);
|
||||||
app.run();
|
app.run();
|
||||||
|
|||||||
Reference in New Issue
Block a user