Added support for conditionally including or excluding parameters based on

the client operating system.
This commit is contained in:
Michael Bayne
2004-07-30 02:23:52 +00:00
parent 8f8ee94dc1
commit 9be3283e4a
6 changed files with 54 additions and 20 deletions
@@ -1,5 +1,5 @@
//
// $Id: Application.java,v 1.23 2004/07/30 00:27:39 mdb Exp $
// $Id: Application.java,v 1.24 2004/07/30 02:23:52 mdb Exp $
package com.threerings.getdown.data;
@@ -166,20 +166,20 @@ public class Application
* @exception IOException thrown if there is an error reading the file
* or an error encountered during its parsing.
*/
public UpdateInterface init ()
public UpdateInterface init (boolean checkPlatform)
throws IOException
{
// parse our configuration file
HashMap cdata = null;
try {
cdata = ConfigUtil.parseConfig(_config);
cdata = ConfigUtil.parseConfig(_config, checkPlatform);
} catch (FileNotFoundException fnfe) {
// thanks to funny windows bullshit, we have to do this backup
// file fiddling in case we got screwed while updating our
// very critical getdown config file
File cbackup = getLocalPath(CONFIG_FILE + "_old");
if (cbackup.exists()) {
cdata = ConfigUtil.parseConfig(cbackup);
cdata = ConfigUtil.parseConfig(cbackup, checkPlatform);
} else {
throw fnfe;
}
@@ -516,7 +516,7 @@ public class Application
// if the new copy validates, reinitialize ourselves;
// otherwise report baffling hoseage
if (_digest.validateResource(crsrc, null)) {
init();
init(true);
}
}
@@ -1,5 +1,5 @@
//
// $Id: Digest.java,v 1.5 2004/07/28 01:28:55 mdb Exp $
// $Id: Digest.java,v 1.6 2004/07/30 02:23:52 mdb Exp $
package com.threerings.getdown.data;
@@ -41,7 +41,8 @@ public class Digest
{
// parse and validate our digest file contents
StringBuffer data = new StringBuffer();
List pairs = ConfigUtil.parsePairs(new File(appdir, DIGEST_FILE));
File dfile = new File(appdir, DIGEST_FILE);
List pairs = ConfigUtil.parsePairs(dfile, false);
for (Iterator iter = pairs.iterator(); iter.hasNext(); ) {
String[] pair = (String[])iter.next();
if (pair[0].equals(DIGEST_FILE)) {
@@ -1,5 +1,5 @@
//
// $Id: Getdown.java,v 1.23 2004/07/30 00:27:19 mdb Exp $
// $Id: Getdown.java,v 1.24 2004/07/30 02:23:52 mdb Exp $
package com.threerings.getdown.launcher;
@@ -78,12 +78,12 @@ public class Getdown extends Thread
try {
// first parses our application deployment file
try {
_ifc = _app.init();
_ifc = _app.init(true);
} catch (IOException ioe) {
Log.warning("Failed to parse 'getdown.txt': " + ioe);
_app.attemptRecovery(this);
// and re-initalize
_ifc = _app.init();
_ifc = _app.init(true);
// now force our UI to be recreated with the updated info
createInterface(true);
}
@@ -177,7 +177,7 @@ public class Getdown extends Thread
// finally update our metadata files...
_app.updateMetadata();
// ...and reinitialize the application
_ifc = _app.init();
_ifc = _app.init(true);
}
/**
@@ -1,5 +1,5 @@
//
// $Id: Differ.java,v 1.5 2004/07/28 02:25:49 mdb Exp $
// $Id: Differ.java,v 1.6 2004/07/30 02:23:52 mdb Exp $
package com.threerings.getdown.tools;
@@ -74,13 +74,13 @@ public class Differ
}
Application oapp = new Application(ovdir);
oapp.init();
oapp.init(false);
ArrayList orsrcs = new ArrayList();
orsrcs.addAll(oapp.getCodeResources());
orsrcs.addAll(oapp.getResources());
Application napp = new Application(nvdir);
napp.init();
napp.init(false);
ArrayList nrsrcs = new ArrayList();
nrsrcs.addAll(napp.getCodeResources());
nrsrcs.addAll(napp.getResources());
@@ -1,5 +1,5 @@
//
// $Id: DigesterTask.java,v 1.2 2004/07/13 17:43:52 mdb Exp $
// $Id: DigesterTask.java,v 1.3 2004/07/30 02:23:52 mdb Exp $
package com.threerings.getdown.tools;
@@ -44,7 +44,7 @@ public class DigesterTask extends Task
// create our application and instruct it to parse its business
Application app = new Application(_appdir);
try {
app.init();
app.init(false);
} catch (IOException ioe) {
throw new BuildException("Error parsing getdown.txt: " +
ioe.getMessage(), ioe);
@@ -1,5 +1,5 @@
//
// $Id: ConfigUtil.java,v 1.2 2004/07/02 15:22:49 mdb Exp $
// $Id: ConfigUtil.java,v 1.3 2004/07/30 02:23:52 mdb Exp $
package com.threerings.getdown.util;
@@ -17,6 +17,8 @@ import java.util.List;
import com.samskivert.io.StreamUtil;
import com.samskivert.util.StringUtil;
import com.threerings.getdown.Log;
/**
* Parses a file containing key/value pairs and returns a {@link HashMap}
* with the values. Keys may be repeated, in which case they will be made
@@ -31,10 +33,12 @@ public class ConfigUtil
* @return a list of <code>String[]</code> instances containing the
* key/value pairs in the order they were parsed from the file.
*/
public static List parsePairs (File config)
public static List parsePairs (File config, boolean checkPlatform)
throws IOException
{
ArrayList pairs = new ArrayList();
String osname = System.getProperty("os.name");
osname = (osname == null) ? "" : osname.toLowerCase();
// parse our configuration file
FileInputStream fin = null;
@@ -67,6 +71,35 @@ public class ConfigUtil
pair[1] = "";
}
// allow a value to have a [Linux]
if (pair[1].startsWith("[")) {
cidx = pair[1].indexOf("]");
if (cidx == -1) {
Log.warning("Bogus platform specifier [key=" + pair[0] +
", value=" + pair[1] + "].");
} else {
String platform = pair[1].substring(1, cidx);
platform = platform.trim().toLowerCase();
pair[1] = pair[1].substring(cidx+1).trim();
if (checkPlatform) {
if (platform.startsWith("!")) {
platform = platform.substring(1);
if (osname.indexOf(platform) != -1) {
Log.info("Skipping [platform=!" + platform +
", key=" + pair[0] +
", value=" + pair[1] + "].");
continue;
}
} else if (osname.indexOf(platform) == -1) {
Log.info("Skipping [platform=" + platform +
", key=" + pair[0] +
", value=" + pair[1] + "].");
continue;
}
}
}
}
pairs.add(pair);
}
@@ -85,10 +118,10 @@ public class ConfigUtil
* of strings if more than one key/value pair in the config file was
* associated with the same key.
*/
public static HashMap parseConfig (File config)
public static HashMap parseConfig (File config, boolean checkPlatform)
throws IOException
{
List pairs = parsePairs(config);
List pairs = parsePairs(config, checkPlatform);
HashMap data = new HashMap();
for (Iterator iter = pairs.iterator(); iter.hasNext(); ) {