The check_unpacked setting will now to version checks so that unpacking can occur if an update is

done by an external source outside of getdown.
This commit is contained in:
Mark Johnson
2012-12-10 13:05:22 -08:00
parent 6b85340ed4
commit 557dcca4ac
3 changed files with 114 additions and 15 deletions
@@ -84,6 +84,7 @@ import com.threerings.getdown.util.FileUtil;
import com.threerings.getdown.util.LaunchUtil;
import com.threerings.getdown.util.MetaProgressObserver;
import com.threerings.getdown.util.ProgressObserver;
import com.threerings.getdown.util.VersionUtil;
import static com.threerings.getdown.Log.log;
@@ -1131,19 +1132,9 @@ public class Application
// and/or check the latest config URL for a newer version
if (_version != -1) {
File vfile = getLocalPath(VERSION_FILE);
FileInputStream fin = null;
long fileVersion = -1;
try {
fin = new FileInputStream(vfile);
BufferedReader bin = new BufferedReader(new InputStreamReader(fin));
String vstr = bin.readLine();
if (!StringUtil.isBlank(vstr)) {
_targetVersion = fileVersion = Long.parseLong(vstr);
}
} catch (Exception e) {
log.info("Unable to read version file: " + e.getMessage());
} finally {
StreamUtil.close(fin);
long fileVersion = VersionUtil.readVersion(vfile);
if (fileVersion != -1) {
_targetVersion = fileVersion;
}
if (_latest != null) {
@@ -1285,6 +1276,15 @@ public class Application
clearValidationMarkers(getAllResources().iterator());
}
/**
* Returns the version number for the application. Should only be called after successful
* return of verifyMetadata.
*/
public long getVersion ()
{
return _version;
}
/**
* Creates a versioned application base URL for the specified version.
*/
@@ -88,6 +88,7 @@ import com.threerings.getdown.util.ConfigUtil;
import com.threerings.getdown.util.LaunchUtil;
import com.threerings.getdown.util.MetaProgressObserver;
import com.threerings.getdown.util.ProgressObserver;
import com.threerings.getdown.util.VersionUtil;
import static com.threerings.getdown.Log.log;
@@ -462,12 +463,25 @@ public abstract class Getdown extends Thread
// not have unpacked all of our resources yet
if (Boolean.getBoolean("check_unpacked")) {
File ufile = _app.getLocalPath("unpacked.dat");
long version = -1;
long aversion = _app.getVersion();
if (!ufile.exists()) {
log.info("Performing initial unpack.");
ufile.createNewFile();
} else {
version = VersionUtil.readVersion(ufile);
}
if (version < aversion) {
log.info("Performing unpack.",
"version", version, "aversion", aversion);
setStep(Step.UNPACK);
updateStatus("m.validating");
_app.unpackResources(_progobs, unpacked);
ufile.createNewFile();
try {
VersionUtil.writeVersion(ufile, aversion);
} catch (IOException ioe) {
log.warning("Failed to update unpacked version", ioe);
}
}
}
@@ -0,0 +1,85 @@
//
// $Id$
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2010 Three Rings Design, Inc.
// http://code.google.com/p/getdown/
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.threerings.getdown.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Reader;
import com.samskivert.io.StreamUtil;
import com.samskivert.util.StringUtil;
import static com.threerings.getdown.Log.log;
/**
* Version related utilities.
*/
public class VersionUtil
{
/**
* Reads a version number from a file.
*/
public static long readVersion (File vfile)
{
FileInputStream fin = null;
long fileVersion = -1;
try {
fin = new FileInputStream(vfile);
BufferedReader bin = new BufferedReader(new InputStreamReader(fin));
String vstr = bin.readLine();
if (!StringUtil.isBlank(vstr)) {
fileVersion = Long.parseLong(vstr);
}
} catch (Exception e) {
log.info("Unable to read version file: " + e.getMessage());
} finally {
StreamUtil.close(fin);
}
return fileVersion;
}
/**
* Writes a version number to a file.
*/
public static void writeVersion (File vfile, long version)
throws IOException
{
PrintStream out = new PrintStream(new FileOutputStream(vfile));
try {
out.println(version);
} catch (Exception e) {
log.warning("Unable to write version file: " + e.getMessage());
} finally {
StreamUtil.close(out);
}
}
}